Adding more features to the patcher (unfinished)

This commit is contained in:
oSumAtrIX 2022-03-18 22:10:41 +01:00
parent 7b40d53bd3
commit d297a3dbf6
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
10 changed files with 60 additions and 24 deletions

View file

@ -1 +0,0 @@
patcher

View file

@ -0,0 +1,10 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View file

@ -2,23 +2,32 @@ 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.PatchStore
import net.revanced.patcher.store.SignatureStore
import org.objectweb.asm.Opcodes
import java.io.InputStream
import java.lang.IllegalStateException
class Patcher(
private val input: InputStream,
signatures: Array<Signature>,
private val signatures: Array<Signature>,
patches: Array<Patch>,
) {
private val patchStore = PatchStore()
private val methodStore = MethodStore()
private val scanned = false
init {
SignatureStore.addSignatures(*signatures)
PatchStore.addPatches(*patches)
patchStore.addPatches(*patches)
}
fun scan() {
// methodStore.methods = PatternScanner(signatures).resolve()
}
fun patch(): String? {
for (patch in PatchStore.patches) {
if (!scanned) throw IllegalStateException("Pattern scanner not yet ran")
for (patch in patchStore.patches) {
val result = patch.execute()
if (result.isSuccess()) continue
return result.error()!!.errorMessage()

View file

@ -0,0 +1,10 @@
package net.revanced.patcher
import net.revanced.patcher.signature.Signature
class PatternScanner(signatures: Array<Signature>) {
fun resolve() {
TODO("Not yet implemented")
}
}

View file

@ -1,6 +1,6 @@
package net.revanced.patcher.patch
class Patch(val fn: () -> PatchResult) {
class Patch(val name: String, val fn: () -> PatchResult) {
fun execute(): PatchResult {
return fn()
}

View file

@ -1,5 +1,7 @@
package net.revanced.patcher.store
object MethodStore {
val methods: Map<String, MethodNode> = mutableMapOf()
import org.objectweb.asm.tree.MethodNode
class MethodStore {
val methods: MutableMap<String, MethodNode> = mutableMapOf()
}

View file

@ -2,10 +2,12 @@ package net.revanced.patcher.store
import net.revanced.patcher.patch.Patch
object PatchStore {
val patches: MutableList<Patch> = mutableListOf()
class PatchStore {
val patches: MutableMap<String, Patch> = mutableMapOf()
fun addPatches(vararg patches: Patch) {
this.patches.addAll(patches)
for (patch in patches) {
this.patches[patch.name] = patch
}
}
}

View file

@ -1,11 +0,0 @@
package net.revanced.patcher.store
import net.revanced.patcher.signature.Signature
object SignatureStore {
private val signatures: MutableList<Signature> = mutableListOf()
fun addSignatures(vararg signatures: Signature) {
this.signatures.addAll(signatures)
}
}