Closed XhstormR closed 2 years ago
This is the original dex file: origin.classes8.dex.zip
Can you give a brief overview of how you're modifying and writing out the dex file? I think padding the switch payload is handled by MutableMethodImplementation.
This is the sample code:
class MyRewrittenMethod(method: Method) : RewrittenMethod(method) {
override fun getImplementation(): MethodImplementation? {
val methodImplementation = super.getImplementation()
if (methodImplementation != null
&& method.name == "onCreate"
&& method.definingClass == "com.example.MainActivity"
) {
with(methodImplementation) {
val p0 = registerCount - this@MyRewrittenMethod.parameters.size - 1
val testParameters = listOf(ReflectionUtils.javaToDexName("android.app.Activity"))
val testReturnType = ReflectionUtils.javaToDexName("void")
val immutableMethodReference = ImmutableMethodReference("com.example.Test", "testMethod", testParameters, testReturnType)
val immutableInstruction = ImmutableInstruction3rc(Opcode.INVOKE_STATIC_RANGE, p0, 1, immutableMethodReference)
val instructions = instructions.toMutableList()
.apply { add(0, immutableInstruction) }
return ImmutableMethodImplementation(registerCount, instructions, null, null)
}
}
return methodImplementation
}
}
Yeah, if you're just building an ImmutableMethodImplementation directly, you'll need to fix up things like that yourself. I would recommend using a MutableMethodImplementation to modify the method, which should handle things like payload alignment, etc.
Got it, thank you.
I use the dexlib2 library to modify the DEX file, there is no exception error when modifying DEX. But when running the modified APK, java.lang.verifyError error exception occurred:
It looks like this caused by this Switch statement:![剪贴板02](https://user-images.githubusercontent.com/10527522/124874316-29246080-dffa-11eb-995b-2f0a93ebc851.jpg)
I uploaded the modified DEX file. modified.classes8.dex.zip