mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
TIL CodeWithMe is ass!
This commit is contained in:
parent
fc41a84aa1
commit
7b40d53bd3
6 changed files with 29 additions and 9 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package net.revanced.patcher.patch
|
||||
|
||||
|
||||
class Patch(val fn: () -> PatchResult) {
|
||||
fun execute(): PatchResult {
|
||||
return fn()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package net.revanced.patcher.store
|
||||
|
||||
object MethodStore {
|
||||
val methods: Map<String, MethodNode> = mutableMapOf()
|
||||
}
|
|
@ -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("")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue