Add Jar2ASM & loadJar method

This commit is contained in:
Lucaskyy 2022-03-18 23:08:41 +01:00
parent d297a3dbf6
commit be18b837ba
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89
4 changed files with 37 additions and 7 deletions

View file

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

View file

@ -6,5 +6,4 @@ class PatternScanner(signatures: Array<Signature>) {
fun resolve() {
TODO("Not yet implemented")
}
}

View file

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

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