免责声明:内容仅供学习参考,请合法利用知识,禁止进行违法犯罪活动!
内容参考于:图灵Python学院
本人写的内容纯属胡编乱造,全都是合成造假,仅仅只是为了娱乐,请不要盲目相信。
工具下载:
链接:https://pan.baidu.com/s/1rEEJnt85npn7N38Ai0_F2Q?pwd=6tw3
提取码:6tw3
复制这段内容后打开百度网盘手机App,操作更方便哦
上一个内容:38.安卓逆向-壳-smali语法2(条件语句和for循环)
上一个内容里写了java的条件语句和for循环的smali的样子,本次接着继续认识smali
本次是方法调用的smali,下方是smali的关键字
invoke-virtual 主要用于非私有实例方法的调用。实例方法指不是构造方法、父类方法等的属于
这个类的一般方法。
invoke-direct 主要用于构造方法(包括父类的构造方法)和私有方法的调用
invoke-static 主要用于静态方法的调用
invoke-super 主要用于父类成员方法(不包括父类构造方法)的调用
invoke-interface 主要用于接口方法的调用
实例方法调用
invoke-virtual {参数}, 方法所属类的全包名路径->方法名(参数类型)方法返回值类型
当有多个参数时,格式为 {参数1,参数2} ,使用其他关键字调用时相同
下图实例调用非静态方法
.class public Lcom/example/course1/SmailTest;
.super Ljava/lang/Object;
.source "SmailTest.java"
# direct methods
.method public constructor <init>(Ljava/lang/String;)V
.registers 2
.param p1, "a" # Ljava/lang/String;
.prologue
.line 5
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 6
invoke-virtual {p0}, Lcom/example/course1/SmailTest;->getName()Ljava/lang/String;
.line 7
return-void
.end method
# virtual methods
.method public getName()Ljava/lang/String;
.registers 2
.prologue
.line 10
const-string v0, "hello"
return-object v0
.end method
public class SmailTest {
//SmailTest类的构造方法,调用getName方法
public SmailTest(String a){
getName();
}
//非私有实例方法getName()
public String getName(){
return "hello";
}
}
下图实例调用静态方法,没什么好说的,和上方非静态的方法一样,区别如下图红框
.class public Lcom/example/course1/SmailTest;
.super Ljava/lang/Object;
.source "SmailTest.java"
# direct methods
.method public constructor <init>(Ljava/lang/String;)V
.registers 2
.param p1, "a" # Ljava/lang/String;
.prologue
.line 5
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 6
invoke-static {}, Lcom/example/course1/SmailTest;->getNames()Ljava/lang/String;
.line 7
return-void
.end method
.method private static getNames()Ljava/lang/String;
.registers 1
.prologue
.line 14
const-string v0, "hello world"
return-object v0
.end method
# virtual methods
.method public getName()Ljava/lang/String;
.registers 2
.prologue
.line 10
const-string v0, "hello"
return-object v0
.end method
public class SmailTest {
//SmailTest类的构造方法,调用getName方法
public SmailTest(String a){
getNames();
}
//非私有实例方法getName()
public String getName(){
return "hello";
}
private static String getNames(){
return "hello world";
}
}
然后来一个复杂点的方法,如下图红框
对应关系
完整smali代码
.class public Lcom/example/course1/SmailTest; .super Ljava/lang/Object; .source "SmailTest.java" # direct methods .method public constructor <init>(Ljava/lang/String;)V .registers 2 .param p1, "a" # Ljava/lang/String; .prologue .line 13 invoke-direct {p0}, Ljava/lang/Object;-><init>()V .line 14 invoke-static {}, Lcom/example/course1/SmailTest;->func3()V .line 15 invoke-virtual {p0}, Lcom/example/course1/SmailTest;->getName()Ljava/lang/String; .line 16 invoke-static {}, Lcom/example/course1/SmailTest;->getNames()Ljava/lang/String; .line 17 return-void .end method .method public static func3()V .registers 14 .prologue const/4 v10, 0x1 const/4 v9, 0x0 .line 28 const-string v7, "http://appapi.yndaily.com/api/v2/articles/10?pageToken=&size=20&headPageSize=&clientVersionCode=409&pjCode=code_ynrb&device_s ize=1080.0x2236.0&deviceOs=10&channel=qq&deviceModel=Google\u0002Pixel+4&clientVersion=4.0.9&udid=11ec2adac162837a&platform=android" .line 30 .local v7, "url":Ljava/lang/String; new-instance v3, Ljava/util/HashMap; invoke-direct {v3}, Ljava/util/HashMap;-><init>()V .line 31 .local v3, "paramMap":Ljava/util/Map;, "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;" const-string v8, "\\?" invoke-virtual {v7, v8}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String; move-result-object v4 .line 32 .local v4, "parts":[Ljava/lang/String; array-length v8, v4 if-le v8, v10, :cond_41 .line 33 aget-object v8, v4, v10 const-string v10, "&" invoke-virtual {v8, v10}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String; move-result-object v5 .line 34 .local v5, "queries":[Ljava/lang/String; array-length v10, v5 move v8, v9 :goto_1c if-ge v8, v10, :cond_41 aget-object v6, v5, v8 .line 35 .local v6, "query":Ljava/lang/String; const-string v11, "=" invoke-virtual {v6, v11}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String; move-result-object v2 .line 36 .local v2, "kv":[Ljava/lang/String; array-length v11, v2 const/4 v12, 0x2 if-ne v11, v12, :cond_39 .line 38 const/4 v11, 0x0 :try_start_2b aget-object v11, v2, v11 const/4 v12, 0x1 aget-object v12, v2, v12 const-string v13, "UTF-8" invoke-static {v12, v13}, Ljava/net/URLDecoder;->decode(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; move-result-object v12 invoke-interface {v3, v11, v12}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; :try_end_39 .catch Ljava/io/UnsupportedEncodingException; {:try_start_2b .. :try_end_39} :catch_3c .line 34 :cond_39 :goto_39 add-int/lit8 v8, v8, 0x1 goto :goto_1c .line 39 :catch_3c move-exception v0 .line 40 .local v0, "e":Ljava/io/UnsupportedEncodingException; invoke-virtual {v0}, Ljava/io/UnsupportedEncodingException;->printStackTrace()V goto :goto_39 .line 47 .end local v0 # "e":Ljava/io/UnsupportedEncodingException; .end local v2 # "kv":[Ljava/lang/String; .end local v5 # "queries":[Ljava/lang/String; .end local v6 # "query":Ljava/lang/String; :cond_41 invoke-virtual {v3}, Ljava/lang/Object;->toString()Ljava/lang/String; move-result-object v8 invoke-virtual {v8}, Ljava/lang/String;->getBytes()[B move-result-object v8 invoke-static {v8, v9}, Landroid/util/Base64;->encodeToString([BI)Ljava/lang/String; move-result-object v1 .line 48 .local v1, "encodedParams":Ljava/lang/String; const-string v8, "Base64" invoke-static {v8, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I .line 49 return-void .end method .method private static getNames()Ljava/lang/String; .registers 1 .prologue .line 24 const-string v0, "hello world" return-object v0 .end method # virtual methods .method public getName()Ljava/lang/String; .registers 2 .prologue .line 20 const-string v0, "hello" return-object v0 .end method
完整java代码
package com.example.course1; import android.util.Base64; import android.util.Log; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; public class SmailTest { //SmailTest类的构造方法,调用getName方法 public SmailTest(String a){ func3(); getName(); getNames(); } //非私有实例方法getName() public String getName(){ return "hello"; } private static String getNames(){ return "hello world"; } public static void func3() { String url = "http://appapi.yndaily.com/api/v2/articles/10?pageToken=&size=20&headPageSize=&clientVersionCode=409&pjCode=code_ynrb&device_s ize=1080.0x2236.0&deviceOs=10&channel=qq&deviceModel=GooglePixel+4&clientVersion=4.0.9&udid=11ec2adac162837a&platform=android"; // 解析查询参数 Map<String, String> paramMap = new HashMap<>(); String[] parts = url.split("\\?"); if (parts.length > 1) { String[] queries = parts[1].split("&"); for (String query : queries) { String[] kv = query.split("="); if (kv.length == 2) { try { paramMap.put(kv[0], URLDecoder.decode(kv[1], "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } } // 使用Base64编码 String encodedParams = Base64.encodeToString(paramMap.toString().getBytes(), Base64.DEFAULT); Log.d("Base64", encodedParams); } }