Restructure patcher

This commit is contained in:
oSumAtrIX
2022-03-17 21:52:44 +01:00
parent 8ab86312bf
commit 76008acef6
3 changed files with 38 additions and 20 deletions

View File

@@ -1,26 +1,35 @@
package net.revanced.patcher
import net.revanced.patcher.version.YTVersion
import net.revanced.patcher.patch.Patch
import net.revanced.patcher.signatures.Signature
import net.revanced.patcher.sigscan.SignatureScanner
import org.jf.dexlib2.DexFileFactory
import org.jf.dexlib2.dexbacked.DexBackedDexFile
import org.jf.dexlib2.dexbacked.DexBackedMethod
import org.jf.dexlib2.iface.DexFile
import java.io.File
import kotlin.math.sign
/**
* Creates a patcher.
*
* @param input the input dex file
* @param output the output dex file
* @param version the YT version of this dex file
*/
class Patcher(private val input: File, private val output: File, private val version: YTVersion) {
// setting opcodes to null causes it to autodetect, perfect!
private val dexFile = DexFileFactory.loadDexFile(input, null)
class Patcher(private val dexFilePath: File) {
private lateinit var patches: MutableList<Patch>;
private lateinit var methodCache: List<DexBackedMethod>;
/**
* Runs the patcher.
*/
fun run() {
private var dexFile: DexFile = DexFileFactory.loadDexFile(dexFilePath, null);
fun writeDexFile(path: String) {
DexFileFactory.writeDexFile(path, dexFile)
}
}
fun addPatch(patch: Patch) {
patches.add(patch)
}
fun addSignatures(vararg signatures: Signature) {
methodCache = SignatureScanner(dexFile.classes.flatMap { classDef -> classDef.methods }).resolve(signatures)
}
fun execute() {
patches.forEach{ patch ->
patch.Execute();
}
}
}

View File

@@ -0,0 +1,7 @@
package net.revanced.patcher.patch
class Patch {
fun Execute(){
TODO()
}
}

View File

@@ -1,10 +1,12 @@
package net.revanced.patcher.sigscan
import net.revanced.patcher.signatures.Signature
import org.jf.dexlib2.iface.ClassDef
import org.jf.dexlib2.dexbacked.DexBackedMethod
import org.jf.dexlib2.iface.Method
class SignatureScanner(signature: Signature) {
fun scan(classes: Array<ClassDef>) {
class SignatureScanner(methods: List<Method>) {
fun resolve(signature: Array<out Signature>) : List<DexBackedMethod> {
TODO()
}
}