Category:Architecture/Android/smali

From aldeid
Jump to navigation Jump to search
You are here:
smali
Note
For a more detailed list, refer to this page: https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html

Description

Smali/Baksmali is an assembler/disassembler for the dex format used by dalvik, Android's Java VM implementation.

Common Instructions

const/4

Description
Move the given literal value (sign-extended to 32 bits) into the specified register.
Syntax
const/4 vA, #+B
Arguments
A: destination register (4 bits)
B: signed int (4 bits)
Example
The following code saves the value 0x0 in the 4 bits v8 register
const/4 v8, 0x0

const-string

Description
Move a reference to the string specified by the given index into the specified register.
Syntax
const-string vAA, string@BBBB
Arguments
A: destination register (8 bits)
B: string index
Example
const-string v0, "verifyPass"

goto

Description
Unconditionally jump to the indicated instruction.
Syntax
goto +AA
goto/16 +AAAA
goto/32 +AAAAAAAA
Argument
A: signed branch offset (8 bits, 16 bits or 32 bits)
Example
goto :label_1
[... some code ...]
:label_1
[... some code ...]

if-<test>

Description
Branch to the given destination if the given two registers' values compare as specified.
Note: The branch offset must not be 0. (A spin loop may be legally constructed either by branching around a backward goto or by including a nop as a target before the branch.)
Syntax
if-eq vA, vB, +CCCC
if-ne vA, vB, +CCCC
if-lt vA, vB, +CCCC
if-ge vA, vB, +CCCC
if-gt vA, vB, +CCCC
if-le vA, vB, +CCCC
Arguments
A: first register to test (4 bits)
B: second register to test (4 bits)
C: signed branch offset (16 bits)

if-<test>z

Description
Branch to the given destination if the given register's value compares with 0 as specified.
Note: The branch offset must not be 0. (A spin loop may be legally constructed either by branching around a backward goto or by including a nop as a target before the branch.)
Syntax
if-eqz vAA, +BBBB
if-nez vAA, +BBBB
if-ltz vAA, +BBBB
if-gez vAA, +BBBB
if-gtz vAA, +BBBB
if-lez vAA, +BBBB
Arguments
A: register to test (8 bits)
B: signed branch offset (16 bits)
Examples
if-nez v1, :cond_0

invoke

Description
Call the indicated method. The result (if any) may be stored with an appropriate move-result* variant as the immediately subsequent instruction.
invoke-virtual is used to invoke a normal virtual method (a method that is not private, static, or final, and is also not a constructor).
invoke-super is used to invoke the closest superclass's virtual method (as opposed to the one with the same method_id in the calling class). The same method restrictions hold as for invoke-virtual.
invoke-direct is used to invoke a non-static direct method (that is, an instance method that is by its nature non-overridable, namely either a private instance method or a constructor).
invoke-static is used to invoke a static method (which is always considered a direct method).
invoke-interface is used to invoke an interface method, that is, on an object whose concrete class isn't known, using a method_id that refers to an interface.
Syntax
invoke-direct {vC, vD, vE, vF, vG}, meth@BBBB
invoke-interface {vC, vD, vE, vF, vG}, meth@BBBB
invoke-static {vC, vD, vE, vF, vG}, meth@BBBB
invoke-super {vC, vD, vE, vF, vG}, meth@BBBB
invoke-virtual {vC, vD, vE, vF, vG}, meth@BBBB
Arguments
A: argument word count (4 bits)
B: method reference index (16 bits)
C..G: argument registers (4 bits each)
(methods are documented here, click to the desired method in the left panel)
Examples
invoke-direct {p0, p1}, Lcom/app/ndh/NDHActivity;->print(Ljava/lang/String;)Ljava/lang/String;
invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
invoke-virtual {v1}, Landroid/telephony/TelephonyManager;->getDeviceId()Ljava/lang/String;

move-result-object

Description
Move the object result of the most recent invoke-kind into the indicated register. This must be done as the instruction immediately after an invoke-kind or filled-new-array whose (object) result is not to be ignored; anywhere else is invalid.
Syntax
move-result-object vAA
Arguments
A: destination register (8 bits)
Example
The following move-result-object instruction get the return code from the print statement and save it to the v0 register which, in turn, will be used in the return-object instruction.
invoke-direct {p0, p1}, Lcom/app/ndh/NDHActivity;->print(Ljava/lang/String;)Ljava/lang/String;
move-result-object v0
return-object v0

new-instance

Description
Construct a new instance of the indicated type, storing a reference to it in the destination. The type must refer to a non-array class.
Syntax
new-instance vAA, type@BBBB
Arguments
A: destination register (8 bits)
B: type index
Example
new-instance v4, Landroid/widget/TextView;

return-object

Description
Return from an object-returning method.
Syntax
return-object vAA
Arguments
A: return value register (8 bits)
Example
invoke-direct {p0, p1}, Lcom/app/ndh/NDHActivity;->print(Ljava/lang/String;)Ljava/lang/String;
move-result-object v0
return-object v0

return-void

Description
Return from a void method.
Syntax
return-void
Arguments
None

This category currently contains no pages or media.