smali入门之packed_switch

packed-switch是smali的switch语句中的一种,主要用来做整数的条件分支语句。

这个例子比较简单,根据输入的参数输出不同的字符串:

.class public Lcom/alipay/helloworld/MainActivity;
.super Landroid/app/Activity;
.source "MainActivity.java"


# direct methods
.method public constructor ()V
    .locals 0
    .prologue
    .line 7
    invoke-direct {p0}, Landroid/app/Activity;->()V
    return-void
.end method


# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
    .locals 3
    .parameter "savedInstanceState"

    .prologue
    .line 11
    invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V

    .line 12
    const/high16 v2, 0x7f03

    invoke-virtual {p0, v2}, Lcom/alipay/helloworld/MainActivity;->setContentView(I)V

    const v0, 0x02
    .local v0, msgIndex:I
    invoke-virtual {p0, v0} , Lcom/alipay/helloworld/MainActivity;->getMsgString(I)Ljava/lang/String;
    move-result-object v0

    .local v0, msg:Ljava/lang/String;
    invoke-virtual {p0, v0}, Lcom/alipay/helloworld/MainActivity;->showToastMessage(Ljava/lang/String;)V
     
    return-void
.end method

.method public showToastMessage(Ljava/lang/String;)V
    .locals 1
    const/4 v0, 0x01
    invoke-static {p0, p1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;
    move-result-object v0
    invoke-virtual {v0}, Landroid/widget/Toast;->show()V
    return-void
.end method

.method public getMsgString(I)Ljava/lang/String;
    .locals 1
    const-string v0,  "Hello,switch"
    packed-switch p1,  :pswitch_data_0
    :goto_0
	return-object v0
    :pswitch_0
	const-string v0, "Hello,switch 0"
    goto :goto_0
    :pswitch_1
	const-string v0, "Hello,switch 1"
    goto :goto_0
    :pswitch_2
	const-string v0, "Hello,switch 2"
    goto :goto_0
    :pswitch_3
	const-string v0, "Hello,switch 3"
    goto :goto_0
    :pswitch_data_0
    .packed-switch 0x0
	:pswitch_0  #0x0
	:pswitch_1  #0x1
	:pswitch_2  #0x2
	:pswitch_3  #0x3
    .end packed-switch
.end method

smali入门之packed_switch_第1张图片



 
 

你可能感兴趣的:(Android逆向破解)