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"))
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 {

View file

@ -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
}
}

View file

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

View file

@ -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 {

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
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("")
}
}
}