From d297a3dbf670ece1ac5af4b303a79440078db5c5 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 18 Mar 2022 22:10:41 +0100 Subject: [PATCH] Adding more features to the patcher (unfinished) --- .idea/.name | 1 - .idea/codeStyles/Project.xml | 10 +++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/runConfigurations.xml | 10 +++++++++ .../kotlin/net/revanced/patcher/Patcher.kt | 21 +++++++++++++------ .../net/revanced/patcher/PatternScanner.kt | 10 +++++++++ .../net/revanced/patcher/patch/Patch.kt | 2 +- .../net/revanced/patcher/store/MethodStore.kt | 6 ++++-- .../net/revanced/patcher/store/PatchStore.kt | 8 ++++--- .../revanced/patcher/store/SignatureStore.kt | 11 ---------- 10 files changed, 60 insertions(+), 24 deletions(-) delete mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 src/main/kotlin/net/revanced/patcher/PatternScanner.kt delete mode 100644 src/main/kotlin/net/revanced/patcher/store/SignatureStore.kt diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 1579b08..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -patcher \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/net/revanced/patcher/Patcher.kt b/src/main/kotlin/net/revanced/patcher/Patcher.kt index e4450a1..6a9acfe 100644 --- a/src/main/kotlin/net/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/net/revanced/patcher/Patcher.kt @@ -2,23 +2,32 @@ package net.revanced.patcher import net.revanced.patcher.patch.Patch import net.revanced.patcher.signature.Signature +import net.revanced.patcher.store.MethodStore import net.revanced.patcher.store.PatchStore -import net.revanced.patcher.store.SignatureStore -import org.objectweb.asm.Opcodes import java.io.InputStream +import java.lang.IllegalStateException class Patcher( private val input: InputStream, - signatures: Array, + private val signatures: Array, patches: Array, ) { + private val patchStore = PatchStore() + private val methodStore = MethodStore() + + private val scanned = false + init { - SignatureStore.addSignatures(*signatures) - PatchStore.addPatches(*patches) + patchStore.addPatches(*patches) + } + + fun scan() { + // methodStore.methods = PatternScanner(signatures).resolve() } fun patch(): String? { - for (patch in PatchStore.patches) { + if (!scanned) throw IllegalStateException("Pattern scanner not yet ran") + for (patch in patchStore.patches) { val result = patch.execute() if (result.isSuccess()) continue return result.error()!!.errorMessage() diff --git a/src/main/kotlin/net/revanced/patcher/PatternScanner.kt b/src/main/kotlin/net/revanced/patcher/PatternScanner.kt new file mode 100644 index 0000000..1d96b2f --- /dev/null +++ b/src/main/kotlin/net/revanced/patcher/PatternScanner.kt @@ -0,0 +1,10 @@ +package net.revanced.patcher + +import net.revanced.patcher.signature.Signature + +class PatternScanner(signatures: Array) { + fun resolve() { + TODO("Not yet implemented") + } + +} diff --git a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt index d671687..d5ae128 100644 --- a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt +++ b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt @@ -1,6 +1,6 @@ package net.revanced.patcher.patch -class Patch(val fn: () -> PatchResult) { +class Patch(val name: String, val fn: () -> PatchResult) { fun execute(): PatchResult { return fn() } diff --git a/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt b/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt index 19504da..a1a0df5 100644 --- a/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt +++ b/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt @@ -1,5 +1,7 @@ package net.revanced.patcher.store -object MethodStore { - val methods: Map = mutableMapOf() +import org.objectweb.asm.tree.MethodNode + +class MethodStore { + val methods: MutableMap = mutableMapOf() } \ No newline at end of file diff --git a/src/main/kotlin/net/revanced/patcher/store/PatchStore.kt b/src/main/kotlin/net/revanced/patcher/store/PatchStore.kt index aef36f2..2e1b101 100644 --- a/src/main/kotlin/net/revanced/patcher/store/PatchStore.kt +++ b/src/main/kotlin/net/revanced/patcher/store/PatchStore.kt @@ -2,10 +2,12 @@ package net.revanced.patcher.store import net.revanced.patcher.patch.Patch -object PatchStore { - val patches: MutableList = mutableListOf() +class PatchStore { + val patches: MutableMap = mutableMapOf() fun addPatches(vararg patches: Patch) { - this.patches.addAll(patches) + for (patch in patches) { + this.patches[patch.name] = patch + } } } \ No newline at end of file diff --git a/src/main/kotlin/net/revanced/patcher/store/SignatureStore.kt b/src/main/kotlin/net/revanced/patcher/store/SignatureStore.kt deleted file mode 100644 index fe06950..0000000 --- a/src/main/kotlin/net/revanced/patcher/store/SignatureStore.kt +++ /dev/null @@ -1,11 +0,0 @@ -package net.revanced.patcher.store - -import net.revanced.patcher.signature.Signature - -object SignatureStore { - private val signatures: MutableList = mutableListOf() - - fun addSignatures(vararg signatures: Signature) { - this.signatures.addAll(signatures) - } -} \ No newline at end of file