mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
Add Jar2ASM & loadJar method
This commit is contained in:
parent
d297a3dbf6
commit
be18b837ba
4 changed files with 37 additions and 7 deletions
|
@ -2,36 +2,47 @@ package net.revanced.patcher
|
|||
|
||||
import net.revanced.patcher.patch.Patch
|
||||
import net.revanced.patcher.signature.Signature
|
||||
import net.revanced.patcher.store.MethodStore
|
||||
import net.revanced.patcher.store.ASMStore
|
||||
import net.revanced.patcher.store.PatchStore
|
||||
import net.revanced.patcher.util.Jar2ASM
|
||||
import java.io.InputStream
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
/**
|
||||
* The patcher. (docs WIP)
|
||||
*
|
||||
* @param input the input stream to read from, must be a JAR file (for now)
|
||||
*/
|
||||
class Patcher(
|
||||
private val input: InputStream,
|
||||
input: InputStream,
|
||||
private val signatures: Array<Signature>,
|
||||
patches: Array<Patch>,
|
||||
) {
|
||||
private val patchStore = PatchStore()
|
||||
private val methodStore = MethodStore()
|
||||
private val asmStore = ASMStore()
|
||||
|
||||
private val scanned = false
|
||||
|
||||
init {
|
||||
patchStore.addPatches(*patches)
|
||||
loadJar(input)
|
||||
}
|
||||
|
||||
fun scan() {
|
||||
// methodStore.methods = PatternScanner(signatures).resolve()
|
||||
val methods = PatternScanner(signatures).resolve()
|
||||
}
|
||||
|
||||
fun patch(): String? {
|
||||
if (!scanned) throw IllegalStateException("Pattern scanner not yet ran")
|
||||
for (patch in patchStore.patches) {
|
||||
for ((_, patch) in patchStore.patches) {
|
||||
val result = patch.execute()
|
||||
if (result.isSuccess()) continue
|
||||
return result.error()!!.errorMessage()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun loadJar(input: InputStream) {
|
||||
asmStore.classes.putAll(Jar2ASM.jar2asm(input))
|
||||
}
|
||||
}
|
|
@ -6,5 +6,4 @@ class PatternScanner(signatures: Array<Signature>) {
|
|||
fun resolve() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.revanced.patcher.store
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode
|
||||
import org.objectweb.asm.tree.MethodNode
|
||||
|
||||
class MethodStore {
|
||||
class ASMStore {
|
||||
val classes: MutableMap<String, ClassNode> = mutableMapOf()
|
||||
val methods: MutableMap<String, MethodNode> = mutableMapOf()
|
||||
}
|
18
src/main/kotlin/net/revanced/patcher/util/Jar2ASM.kt
Normal file
18
src/main/kotlin/net/revanced/patcher/util/Jar2ASM.kt
Normal file
|
@ -0,0 +1,18 @@
|
|||
package net.revanced.patcher.util
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode
|
||||
import java.io.InputStream
|
||||
import java.util.jar.JarInputStream
|
||||
|
||||
object Jar2ASM {
|
||||
fun jar2asm(input: InputStream): Map<String, ClassNode> {
|
||||
return buildMap {
|
||||
val jar = JarInputStream(input)
|
||||
var e = jar.nextJarEntry
|
||||
while (e != null) {
|
||||
TODO("Read jar file ...")
|
||||
e = jar.nextJarEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue