everyone. I met a problem on instrumentation on Dalvik bytecode.
The origin bytecode is:
virtual methods
.method public onClick(Landroid/view/View;)V
.locals 12
.param p1, "v" # Landroid/view/View;
...
return-void
.end method
To print something, I need to add 4 new registers. However, 12(local)+2(arguments)+4(new)>16 which will lead to problem for some instruction.
So, I think of a idea in blew way:
The number of whole registers are 20. v0-v11 are local, v18-v19 are arguments.
Move the v18-v19 to v12-v13 at first and arguments registers are within v15. In addition,
we need to modify p0 to v12, p1 to v13.
If we want to use 4 new registers, move v0-v3 to v14-17. After handling 4 new registers, move v14-v17 to v0-v3 back.
The new bytecode becomes:
virtual methods
.method public onClick(Landroid/view/View;)V
.locals 18
.param p1, "v" # Landroid/view/View;
move v12, v18
move v13, v19
...
//want to use 4 new registers
move v14, v0
move v15, v1
move v16, v2
move v17, v3
//use 4 new registers
move v0, v14
move v1, v15
move v2, v16
move v3, v17
return-void
.end method
Unfortunately, I met Java.lang.VerifyError
. Could anyone help me? Thank you.
Dalvik programs are written in Java using the Android application programming interface (API), compiled to Java bytecode, and converted to Dalvik instructions as necessary. A tool called dx is used to convert Java . class files into the . dex format. Multiple classes are included in a single .
the JVM is stack-based, Dalvik is register-based. JVM bytecode was originally designed for interpretation, although most JVMs nowadays actually have compilers, whereas Dalvik bytecode was originally designed for compilation, although in the first versions it actually was interpreted.
Smali is intended to serve as a basis for further analysis of Android applications and security implementation techniques. Android applications are mainly written in Java. The Java source code is first compiled into a Java Virtual Machine (JVM) bytecode using a standard Java compiler called Javac.
Answer is "Dex compiler"
Registers are not interchangable. Some instructions accept only registers 0-15, others 0-255, so this approach wouldn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With