mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-11 05:46:16 +00:00
Restructure patcher
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/main/kotlin/net/revanced/patcher/patch/Patch.kt
Normal file
7
src/main/kotlin/net/revanced/patcher/patch/Patch.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package net.revanced.patcher.patch
|
||||
|
||||
class Patch {
|
||||
fun Execute(){
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user