天天看點

android Smali靜态分析(二)

循環語句

示例1:

:goto_0
invoke-interface {}, Ljava/util/Iterator;->hasNext()Z
...
invoke-interface {}, Ljava/util/Iterator;->next()Ljava/lang/Object;
...
goto :goto_0
           

示例2:

.local v1, i:I # 初始化v1為0
:goto_0
if-lt v1, v5, :cond_0 # 如果v1小于v5,則跳轉到cond_0處
...
:cond_0
invoke-interface {v0, v1}, Ljava/util/List;->get(I)Ljava/lang/Object;
...
add-int/lit8 v1, v1,  # 下一個索引
goto :goto_0
           

switch分支

示例1:

packed-switch p1, :pswitch_data_0
const-string v0, "she is a person" # default分支
:goto_0 # 所有case的出口
return-object v0 # 傳回v0
:pswitch_0 # case 0
const-string v0, "she is a baby"
goto :goto_0
:pswitch_1 # case 1
const-string v0, "she is a girl"
goto :goto_0
nop
:pswitch_data_0
.packed-switch  # case區域,從0開始,依次遞增
    :pswitch_0 # case 0
    :pswitch_1 # case 1
.end packed-switch
           

示例2:

sparse-switch p1, :sswitch_data_0 # sparse-switch分支, sswtich_data_0
const-string v0, "he is person" # default case
:goto_0 # case 出口
return-object v0
:sswtich_0 # case 5
const-string v0, "he is a baby" 
goto :goto_0
:sswitch_1 # case 15
const-string v0, "he is girl"
goto :goto_0
nop
:sswtich_data_0
.sparse-switch
     -> : sswtich_0
     -> : sswtich_1
.end sparse-switch
           

try-catch語句

示例:

:try_start_0 # 第一個try開始

invoke-static {p}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

:try_end_0 # 第一個try結束

.catch Ljava/lang/NumberFormatException;{:try_start_0 .. :try_end_0}:catch_1

:goto_0
return-void

:catch_1
move-exception v
.local v, e:Ljava/lang/NumberFormatException;
invoke-virtual {v}, Ljava/lang/NumberFormatException;->printStackTrace()V
goto :goto_0