文章目录
算数运算
public void numCtrl(int b){
int a = b;
boolean b1 = true;
Log.d(“MainActivity”, "a+b = "+(a+b));
Log.d(“MainActivity”, "a-b = "+(a-b));
Log.d(“MainActivity”, "a/b = "+(a/b));
Log.d(“MainActivity”, "ab = "+(ab));
Log.d(“MainActivity”, "a%b = "+(a%b));
}
对应的java程序反编译后的smali代码:
.method public numCtrl(I)V
.locals 5
.param pl,"b" #I
. prologue #代码开始
.line 30
move v0, p1 #数据变量赋值
.line 31
.local v0,"a" :I #定义局部变量
const/4 v1, 0x1 #数据常量赋值
line 32
.local v1,"b1":Z #定义局部变量,布尔变量
const-string v2,"MainActivity" #定义字符串变量
new-instance v3, Ljava/lang/StringBuilder ; #创建StringBuilder对象
#new-instance vx, 类型ID :根据类型ID或者类型新建一个对象实例,并将新建对象的引用存入vx
Invoke-direct {v3}, Ljava/lang/StringBuilder; --→<init>()V #调用构造函数
#v3这里指的是this实例(指针);Ljava/lang/StringBuilder;这里指的是调用这个类的<init>方法;
#invoke-direct{参数},方法名
#不解析直接调用参数的,通常私有方法调用此指令
const-string v4, "a + b ="
#调用虚方法, v3.append(v4)
#调用成员函数,第一个参数为this参数
invoke-virtual {v3,v4},Ljava/lange/StringBuilder;--→append(Ljava/lang/String;)Ljava/lang/StringBuilder;
#调用实例的虚方法,通常成员对象的实例的方法都以该指令调用
#返回值放入v3
move-result-object v3
#v4 = v0 + p1
add-int v4,v0,p1
#v3.append(v4)
invoke-virtual {v3 ,v4},Ljava/lang/StringBuilder;-→append(I) Ljava/lang/StringBuilder;
mov-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;-→toString() Ljava/lang/String;
move-result-object v3
#调用静态方法
invoke-static {v2,v3},Landroid/uti/Log;-→d(Ljava/lang/String;Ljava/lang/String) I
#(I为返回值)方法名为d,其归属于Landroid/uti/Log 这种类型;
.line 33
const-string v2,"MainACtivity"
new-instance v3, Ljava/lang/StringBuilder ; #创建StringBuilder对象
#new-instance vx, 类型ID :根据类型ID或者类型新建一个对象实例,并将新建对象的引用存入vx
Invoke-direct {v3}, Ljava/lang/StringBuilder; --→<init>()V #调用构造函数
const-string v4, "a - b ="
invoke-virtual {v3,v4},Ljava/lange/StringBuilder;--→append(Ljava/lang/String;)Ljava/lang/StringBuilder;
#调用成员函数,第一个参数为this(v3)参数
#调用实例的虚方法,通常成员对象的实例的方法都以该指令(invoke-virtual)调用
#返回值放入v3
move-result-object v3
#v4 = v0 - p1
sub-int v4,v0,p1
#v3.append(v4)
invoke-virtual {v3 ,v4},Ljava/lang/StringBuilder;-→append(I) Ljava/lang/StringBuilder;
#返回值放入v3
move-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;-→toString() Ljava/lang/String;
#返回值放入v3
move-result-object v3
#调用静态方法
invoke-static {v2,v3},Landroid/uti/Log;-→d(Ljava/lang/String;Ljava/lang/String) I
#(I为返回值)方法名为d,其归属于Landroid/uti/Log 这种类型;
.line 34
const-string v2,"MainACtivity"
new-instance v3, Ljava/lang/StringBuilder ; #创建StringBuilder对象
#new-instance vx, 类型ID :根据类型ID或者类型新建一个对象实例,并将新建对象的引用存入vx
Invoke-direct {v3}, Ljava/lang/StringBuilder; --→<init>()V #调用构造函数
const-string v4, "a / b ="
invoke-virtual {v3,v4},Ljava/lange/StringBuilder;--→append(Ljava/lang/String;)Ljava/lang/StringBuilder;
#调用成员函数,第一个参数为this(v3)参数
#调用实例的虚方法,通常成员对象的实例的方法都以该指令(invoke-virtual)调用
#返回值放入v3
move-result-object v3
#v4 = v0 / p1
div-int v4,v0,p1
#v3.append(v4)
invoke-virtual {v3 ,v4},Ljava/lang/StringBuilder;-→append(I) Ljava/lang/StringBuilder;
#返回值放入v3
move-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;-→toString() Ljava/lang/String;
#返回值放入v3
move-result-object v3
#调用静态方法即:Log.d(v2,v3)
invoke-static {v2,v3},Landroid/uti/Log;-→d(Ljava/lang/String;Ljava/lang/String) I
#(I为返回值)方法名为d,其归属于Landroid/uti/Log 这种类型;
.line 35
const-string v2,"MainActivity" #定义字符串变量
new-instance v3, Ljava/lang/StringBuilder ; #创建StringBuilder对象
#new-instance vx, 类型ID :根据类型ID或者类型新建一个对象实例,并将新建对象的引用存入vx
Invoke-direct {v3}, Ljava/lang/StringBuilder; --→<init>()V #调用构造函数
#v3这里指的是this实例(指针);Ljava/lang/StringBuilder;这里指的是调用这个类的<init>方法;
#invoke-direct{参数},方法名
#不解析直接调用参数的,通常私有方法调用此指令
const-string v4, "a * b ="
#调用虚方法, v3.append(v4)
#调用成员函数,第一个参数为this参数
invoke-virtual {v3,v4},Ljava/lange/StringBuilder;--→append(Ljava/lang/String;)Ljava/lang/StringBuilder;
#调用实例的虚方法,通常成员对象的实例的方法都以该指令调用
#返回值放入v3
move-result-object v3
#v4 = v0 *p1
mul-int v4,v0,p1
#v3.append(v4)
invoke-virtual {v3 ,v4},Ljava/lang/StringBuilder;-→append(I) Ljava/lang/StringBuilder;
mov-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;-→toString() Ljava/lang/String;
move-result-object v3
#调用静态方法
invoke-static {v2,v3},Landroid/uti/Log;-→d(Ljava/lang/String;Ljava/lang/String) I
#(I为返回值)方法名为d,其归属于Landroid/uti/Log 这种类型;
.line 36
const-string v2,"MainActivity" #定义字符串变量
new-instance v3, Ljava/lang/StringBuilder ; #创建StringBuilder对象
#new-instance vx, 类型ID :根据类型ID或者类型新建一个对象实例,并将新建对象的引用存入vx
Invoke-direct {v3}, Ljava/lang/StringBuilder; --→<init>()V #调用构造函数
#v3这里指的是this实例(指针);Ljava/lang/StringBuilder;这里指的是调用这个类的<init>方法;
#invoke-direct{参数},方法名
#不解析直接调用参数的,通常私有方法调用此指令
const-string v4, "a % b ="
#调用虚方法, v3.append(v4)
#调用成员函数,第一个参数为this参数
invoke-virtual {v3,v4},Ljava/lange/StringBuilder;--→append(Ljava/lang/String;)Ljava/lang/StringBuilder;
#调用实例的虚方法,通常成员对象的实例的方法都以该指令调用
#返回值放入v3
move-result-object v3
#v4 = v0 %p1
rem-int v4,v0,p1
#v3.append(v4)
invoke-virtual {v3 ,v4},Ljava/lang/StringBuilder;-→append(I) Ljava/lang/StringBuilder;
mov-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;-→toString() Ljava/lang/String;
move-result-object v3
#调用静态方法
invoke-static {v2,v3},Landroid/uti/Log;-→d(Ljava/lang/String;Ljava/lang/String) I
#(I为返回值)方法名为d,其归属于Landroid/uti/Log 这种类型;