Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new registers on Dalvik bytecode

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.

like image 876
user3496149 Avatar asked Apr 04 '14 02:04

user3496149


People also ask

What is Dalvik bytecode?

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 .

What is the difference between bytecode instructions and Dalvik bytecode instructions in Java?

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.

What is Smali code?

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.

How will you convert the Java bytecode into Dalvik bytecode?

Answer is "Dex compiler"


1 Answers

Registers are not interchangable. Some instructions accept only registers 0-15, others 0-255, so this approach wouldn't work.

like image 94
Stepan Yakovenko Avatar answered Sep 22 '22 15:09

Stepan Yakovenko