smali格式简析

package com.example.anative;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }
    
    private int privateAge;
    private String privateNickName;
    public int publicUserID;
    public String publicUserName;

    private static int staticPrivateIndex;
    public static int staticPublicIndex;

    public void sayHello()
    {
        String message = "say hello: ";
        System.out.println(message);
    }

    public static void static_sayHello_0()
    {
        String message = "static_sayHello_0: ";
        System.out.println(message);
    }

    public static void static_sayHello_1(String strs)
    {
        String message = "static_sayHello_1: ";
        message += strs;
        System.out.println(message);
    }

    public static void static_sayHello_2(String str1, String str2)
    {
        String message = "static_sayHello_2: ";
        message += str1;
        message+=str2;
        System.out.println(message);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView textViewx = findViewById(R.id.sample_text);
        textViewx.setText(stringFromJNI());

        static_sayHello_1("first static method!");
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
}
.class public Lcom/example/anative/MainActivity;      #当前类名
.super Landroidx/appcompat/app/AppCompatActivity;     #父类名称
.source "MainActivity.java"                           #对应的源码文件


# static fields
.field private static staticPrivateIndex:I            #private static int staticPrivateIndex;

.field public static staticPublicIndex:I              #public static int staticPublicIndex;


# instance fields
.field private privateAge:I                           #private int privateAge;

.field private privateNickName:Ljava/lang/String;     #private String privateNickName;

.field public publicUserID:I                          #public publicUserID;

.field public publicUserName:Ljava/lang/String;       #public publicUserName;


# direct methods
.method static constructor <clinit>()V                #class类构造器, 对静态变量、静态代码进行初始化
    .locals 1

    .line 12                                          #.line 表示代码所在的行数,.line 代码可以删除, 重新编译后测试发现,并不影响程序的运行。
    const-string v0, "native-lib"

    invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V

    .line 13
    return-void
.end method

.method public constructor <init>()V                   #instance实例构造器, 对非静态变量解析并初始化
    .locals 0

    .line 8
    invoke-direct {p0}, Landroidx/appcompat/app/AppCompatActivity;-><init>()V

    return-void
.end method

.method public static static_sayHello_0()V              #public static void static_sayHello_0();
    .locals 2

    .line 31
    const-string v0, "static_sayHello_0: "

    .line 32
    .local v0, "message":Ljava/lang/String;
    sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;

    invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 33
    return-void
.end method

.method public static static_sayHello_1(Ljava/lang/String;)V #public static void static_sayHello_1(String strs);
    .locals 2
    .param p0, "strs"    # Ljava/lang/String;                #注意: 静态方法中,若有参数,则参数是从p0开始的;

    .line 37
    const-string v0, "static_sayHello_1: "

    .line 38
    .local v0, "message":Ljava/lang/String;
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 39
    sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;

    invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 40
    return-void
.end method

.method public static static_sayHello_2(Ljava/lang/String;Ljava/lang/String;)V #public static void static_sayHello_1(String str1, String str2);
    .locals 2            # 所使用的本地寄存器最大数量,此处为2,寄存器范围[v0, v1]
    .param p0, "str1"    # Ljava/lang/String;
    .param p1, "str2"    # Ljava/lang/String;
                                                                                                                                                                                                                                                                        #p0指的是左边的参数,而p1指的是右边的参数
    .line 44
    const-string v0, "static_sayHello_2: "

    .line 45
        #v1 = new String(); 
    #v1.append("Native Hello-->sayHello_2: ");
    #v1.append(str1);
    #v0 = v1.toString();

    .local v0, "message":Ljava/lang/String;
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 46
		  #v1 = new String();
    #v1.append(v0); 注意: 此处v0已经不再是"Native Hello-->SayHell0_2"
    #v1.append(str1);
    #v0 = v1.toString();
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 47
    sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;

    invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 48
    return-void
.end method


# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
    .locals 2
    .param p1, "savedInstanceState"    # Landroid/os/Bundle;

    .line 52                           #supper.onCreate,其中p0代表的是本类this寄存器, p1指的是参数
    invoke-super {p0, p1}, Landroidx/appcompat/app/AppCompatActivity;->onCreate(Landroid/os/Bundle;)V

    .line 53
    const v0, 0x7f0a001c
                                       #this.setContentView(0x7f0a001c)V;
    invoke-virtual {p0, v0}, Lcom/example/anative/MainActivity;->setContentView(I)V

    .line 56
    const v0, 0x7f07007e
                                       #v0 = this.findViewById(0x7f07007e)I;
    invoke-virtual {p0, v0}, Lcom/example/anative/MainActivity;->findViewById(I)Landroid/view/View;

    move-result-object v0
                                       #将v0强制转换为TextView;
    check-cast v0, Landroid/widget/TextView;

    .line 57
    .local v0, "textViewx":Landroid/widget/TextView; #此处v0代表的是代码中的tv变量(类型为TextView)
    invoke-virtual {p0}, Lcom/example/anative/MainActivity;->stringFromJNI()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

    .line 59
    const-string v1, "first static method!"

    invoke-static {v1}, Lcom/example/anative/MainActivity;->static_sayHello_1(Ljava/lang/String;)V

    .line 60
    return-void
.end method

.method public sayHello()V
    .locals 2

    .line 25
    const-string v0, "say hello: "

    .line 26
    .local v0, "message":Ljava/lang/String;
    sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;

    invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 27
    return-void
.end method

.method public native stringFromJNI()Ljava/lang/String;
.end method

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值