TIL CodeWithMe is ass!

This commit is contained in:
Lucaskyy 2022-03-18 21:52:00 +01:00
parent fc41a84aa1
commit 7b40d53bd3
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
6 changed files with 29 additions and 9 deletions

View File

@ -15,6 +15,9 @@ dependencies {
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
implementation("org.ow2.asm:asm:9.2") 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 { tasks.test {

View File

@ -1,10 +1,10 @@
package net.revanced.patcher package net.revanced.patcher
import net.revanced.patcher.patch.Patch import net.revanced.patcher.patch.Patch
import net.revanced.patcher.patch.PatchResult
import net.revanced.patcher.signature.Signature import net.revanced.patcher.signature.Signature
import net.revanced.patcher.store.PatchStore import net.revanced.patcher.store.PatchStore
import net.revanced.patcher.store.SignatureStore import net.revanced.patcher.store.SignatureStore
import org.objectweb.asm.Opcodes
import java.io.InputStream import java.io.InputStream
class Patcher( class Patcher(
@ -17,9 +17,12 @@ class Patcher(
PatchStore.addPatches(*patches) PatchStore.addPatches(*patches)
} }
fun patch() { fun patch(): String? {
PatchStore.patches.forEach { for (patch in PatchStore.patches) {
val result = patch.execute()
if (result.isSuccess()) continue
return result.error()!!.errorMessage()
} }
return null
} }
} }

View File

@ -1,8 +1,9 @@
package net.revanced.patcher.patch package net.revanced.patcher.patch
class Patch(val fn: () -> PatchResult) { class Patch(val fn: () -> PatchResult) {
fun execute(): PatchResult { fun execute(): PatchResult {
return fn() return fn()
} }
} }

View File

@ -7,12 +7,21 @@ interface PatchResult {
} }
return null return null
} }
fun success(): PatchResultSuccess? { fun success(): PatchResultSuccess? {
if (this is PatchResultSuccess) { if (this is PatchResultSuccess) {
return this return this
} }
return null return null
} }
fun isError(): Boolean {
return this is PatchResultError
}
fun isSuccess(): Boolean {
return this is PatchResultSuccess
}
} }
class PatchResultError(private val errorMessage: String) : PatchResult { class PatchResultError(private val errorMessage: String) : PatchResult {

View File

@ -0,0 +1,5 @@
package net.revanced.patcher.store
object MethodStore {
val methods: Map<String, MethodNode> = mutableMapOf()
}

View File

@ -1,16 +1,15 @@
package net.revanced.patcher package net.revanced.patcher
import net.revanced.patcher.patch.Patch import net.revanced.patcher.patch.Patch
import net.revanced.patcher.patch.PatchResult
import net.revanced.patcher.patch.PatchResultError import net.revanced.patcher.patch.PatchResultError
import net.revanced.patcher.patch.PatchResultSuccess
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
internal class PatcherTest { internal class PatcherTest {
@Test @Test
fun template() { fun template() {
val adRemoverPatch = Patch {
PatchResultError("")
}
} }
} }