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 <init>()V
    .locals 0
    .prologue
    .line 7
    invoke-direct {p0}, Landroid/app/Activity;-><init>()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




</pre><pre name="code" class="plain">
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值