feat: add inline smali compiler

This commit is contained in:
Lucaskyy
2022-04-03 23:51:01 +02:00
parent 45a885dbde
commit dbafe2ab37
4 changed files with 361 additions and 22 deletions

View File

@@ -8,11 +8,15 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.smali.asInstruction
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference
import java.io.File
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
fun main() {
val signatures = arrayOf(
@@ -43,33 +47,49 @@ fun main() {
?: return PatchResultError("Class 'XAdRemover' could not be found")
val xAdRemoverClass = proxy.resolve()
val hideReelMethod = xAdRemoverClass.methods.single { method -> method.name.contains("HideReel") }
val hideReelMethod = xAdRemoverClass.methods.find {
it.name.contains("HideReel")
}!!
val readSettingsMethodRef = ImmutableMethodReference(
"Lfi/razerman/youtube/XGlobals;",
"ReadSettings",
emptyList(),
"V"
)
val instructions = hideReelMethod.implementation!!
val instructions = hideReelMethod.implementation!!.instructions
val readSettingsInstruction = BuilderInstruction35c(
val readInsn =
"invoke-static { }, Lfi/razerman/youtube/XGlobals;->ReadSettings()V"
.asInstruction() as BuilderInstruction35c
val testInsn = BuilderInstruction35c(
Opcode.INVOKE_STATIC,
0,
0,
0,
0,
0,
0,
readSettingsMethodRef
0, 0, 0, 0, 0, 0,
ImmutableMethodReference(
"Lfi/razerman/youtube/XGlobals;",
"ReadSettings",
emptyList(),
"V"
)
)
assertEquals(testInsn.opcode, readInsn.opcode)
assertEquals(testInsn.referenceType, readInsn.referenceType)
assertEquals(testInsn.registerCount, readInsn.registerCount)
assertEquals(testInsn.registerC, readInsn.registerC)
assertEquals(testInsn.registerD, readInsn.registerD)
assertEquals(testInsn.registerE, readInsn.registerE)
assertEquals(testInsn.registerF, readInsn.registerF)
assertEquals(testInsn.registerG, readInsn.registerG)
run {
val tref = testInsn.reference as MethodReference
val rref = readInsn.reference as MethodReference
assertEquals(tref.name, rref.name)
assertEquals(tref.definingClass, rref.definingClass)
assertEquals(tref.returnType, rref.returnType)
assertContentEquals(tref.parameterTypes, rref.parameterTypes)
}
// TODO: figure out control flow
// otherwise the we would still jump over to the original instruction at index 21 instead to our new one
instructions.add(
instructions.addInstruction(
21,
readSettingsInstruction
readInsn
)
return PatchResultSuccess()
}