mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-12 01:54:24 +02:00
Add Jar2ASM & loadJar method
This commit is contained in:
parent
d297a3dbf6
commit
be18b837ba
@ -2,36 +2,47 @@ package net.revanced.patcher
|
|||||||
|
|
||||||
import net.revanced.patcher.patch.Patch
|
import net.revanced.patcher.patch.Patch
|
||||||
import net.revanced.patcher.signature.Signature
|
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.store.PatchStore
|
||||||
|
import net.revanced.patcher.util.Jar2ASM
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.lang.IllegalStateException
|
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(
|
class Patcher(
|
||||||
private val input: InputStream,
|
input: InputStream,
|
||||||
private val signatures: Array<Signature>,
|
private val signatures: Array<Signature>,
|
||||||
patches: Array<Patch>,
|
patches: Array<Patch>,
|
||||||
) {
|
) {
|
||||||
private val patchStore = PatchStore()
|
private val patchStore = PatchStore()
|
||||||
private val methodStore = MethodStore()
|
private val asmStore = ASMStore()
|
||||||
|
|
||||||
private val scanned = false
|
private val scanned = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
patchStore.addPatches(*patches)
|
patchStore.addPatches(*patches)
|
||||||
|
loadJar(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scan() {
|
fun scan() {
|
||||||
// methodStore.methods = PatternScanner(signatures).resolve()
|
val methods = PatternScanner(signatures).resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun patch(): String? {
|
fun patch(): String? {
|
||||||
if (!scanned) throw IllegalStateException("Pattern scanner not yet ran")
|
if (!scanned) throw IllegalStateException("Pattern scanner not yet ran")
|
||||||
for (patch in patchStore.patches) {
|
for ((_, patch) in patchStore.patches) {
|
||||||
val result = patch.execute()
|
val result = patch.execute()
|
||||||
if (result.isSuccess()) continue
|
if (result.isSuccess()) continue
|
||||||
return result.error()!!.errorMessage()
|
return result.error()!!.errorMessage()
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadJar(input: InputStream) {
|
||||||
|
asmStore.classes.putAll(Jar2ASM.jar2asm(input))
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,5 +6,4 @@ class PatternScanner(signatures: Array<Signature>) {
|
|||||||
fun resolve() {
|
fun resolve() {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package net.revanced.patcher.store
|
package net.revanced.patcher.store
|
||||||
|
|
||||||
|
import org.objectweb.asm.tree.ClassNode
|
||||||
import org.objectweb.asm.tree.MethodNode
|
import org.objectweb.asm.tree.MethodNode
|
||||||
|
|
||||||
class MethodStore {
|
class ASMStore {
|
||||||
|
val classes: MutableMap<String, ClassNode> = mutableMapOf()
|
||||||
val methods: MutableMap<String, MethodNode> = 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…
x
Reference in New Issue
Block a user