diff --git a/build.gradle.kts b/build.gradle.kts index 76ce09d..23bfa04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,9 @@ dependencies { testImplementation(kotlin("test")) implementation("org.ow2.asm:asm:9.2") + implementation("org.ow2.asm:asm-util:9.2") + implementation("org.ow2.asm:asm-tree:9.2") + implementation("org.ow2.asm:asm-commons:9.2") } tasks.test { diff --git a/src/main/kotlin/net/revanced/patcher/Patcher.kt b/src/main/kotlin/net/revanced/patcher/Patcher.kt index 77d9b0e..e4450a1 100644 --- a/src/main/kotlin/net/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/net/revanced/patcher/Patcher.kt @@ -1,10 +1,10 @@ package net.revanced.patcher import net.revanced.patcher.patch.Patch -import net.revanced.patcher.patch.PatchResult import net.revanced.patcher.signature.Signature import net.revanced.patcher.store.PatchStore import net.revanced.patcher.store.SignatureStore +import org.objectweb.asm.Opcodes import java.io.InputStream class Patcher( @@ -17,9 +17,12 @@ class Patcher( PatchStore.addPatches(*patches) } - fun patch() { - PatchStore.patches.forEach { - + fun patch(): String? { + for (patch in PatchStore.patches) { + val result = patch.execute() + if (result.isSuccess()) continue + return result.error()!!.errorMessage() } + return null } } \ No newline at end of file diff --git a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt index b1bd57a..d671687 100644 --- a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt +++ b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt @@ -1,8 +1,9 @@ package net.revanced.patcher.patch - class Patch(val fn: () -> PatchResult) { fun execute(): PatchResult { return fn() } } + + diff --git a/src/main/kotlin/net/revanced/patcher/patch/PatchResult.kt b/src/main/kotlin/net/revanced/patcher/patch/PatchResult.kt index 8bc239f..73c93b4 100644 --- a/src/main/kotlin/net/revanced/patcher/patch/PatchResult.kt +++ b/src/main/kotlin/net/revanced/patcher/patch/PatchResult.kt @@ -7,12 +7,21 @@ interface PatchResult { } return null } + fun success(): PatchResultSuccess? { if (this is PatchResultSuccess) { return this } return null } + + fun isError(): Boolean { + return this is PatchResultError + } + + fun isSuccess(): Boolean { + return this is PatchResultSuccess + } } class PatchResultError(private val errorMessage: String) : PatchResult { diff --git a/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt b/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt new file mode 100644 index 0000000..19504da --- /dev/null +++ b/src/main/kotlin/net/revanced/patcher/store/MethodStore.kt @@ -0,0 +1,5 @@ +package net.revanced.patcher.store + +object MethodStore { + val methods: Map = mutableMapOf() +} \ No newline at end of file diff --git a/src/test/kotlin/net/revanced/patcher/PatcherTest.kt b/src/test/kotlin/net/revanced/patcher/PatcherTest.kt index a72dea8..aab519e 100644 --- a/src/test/kotlin/net/revanced/patcher/PatcherTest.kt +++ b/src/test/kotlin/net/revanced/patcher/PatcherTest.kt @@ -1,16 +1,15 @@ package net.revanced.patcher import net.revanced.patcher.patch.Patch -import net.revanced.patcher.patch.PatchResult import net.revanced.patcher.patch.PatchResultError -import net.revanced.patcher.patch.PatchResultSuccess import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.* - internal class PatcherTest { @Test fun template() { + val adRemoverPatch = Patch { + PatchResultError("") + } } } \ No newline at end of file