背景
近期要抓一个apk的蓝牙包,抓是抓到了,但是命令挺多的,流程方面还得反编译代码会处理快一点,反编译出来有一些代码没有反编译出来,是jvm字节码,要先了解jvm字节码,为此要研究下java反汇编代码,把反汇编用法记录下来。
创建测试代码
public class Math {
public static int xadd(int a, int b){
return a+b;
}
public static void main(String[] args){
int a, b,c ,d,e,f;
a=1;
b=2;
c=(a+b)*10;
f = a*b;
d = xadd(a,b);
e = xadd(1,2);
}
}
编译java程序
在命令行中执行编译,得到class文件
javac Math.java
反编译生成的class文件得到汇编程序
javap -c Math
public class Math {
public Math();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static int xadd(int, int);
Code:
0: iload_0
1: iload_1
2: iadd
3: ireturn
public static void main(java.lang.String[]);
Code:
0: iconst_1
1: istore_1
2: iconst_2
3: istore_2
4: iload_1
5: iload_2
6: iadd
7: bipush 10
9: imul
10: istore_3
11: iload_1
12: iload_2
13: imul
14: istore 6
16: iload_1
17: iload_2
18: invokestatic #2 // Method xadd:(II)I
21: istore 4
23: iconst_1
24: iconst_2
25: invokestatic #2 // Method xadd:(II)I
28: istore 5
30: return
对比java程序和汇编,快速提高看汇编能力
剩下就是对汇编中的入栈出栈,赋值和调用分析了,抛去复杂的程序,可以较为快的对待汇编程序分析了。