Androidアプリケーション(apk)の中には
Dalvik VMの実行形式である
classes.dexファイルが含まれています。今回、このdexファイルのヘッダ情報を取
得したり、
コードセクションを逆コンパイルできるdexdumpを使って、dexファイルを逆アセンブルしてみます。
1.apkファイル
の展開
$ mkdir
HelloAndroid
$ cd
HelloAndroid
$ unzip
../HelloAndroid.apk
2.dexdumpの実行
$
~/android-sdk-linux_x86-1.5_r3/platforms/android-1.5/tools/dexdump \
-d ./classes.dex
Processing './classes.dex'...
Opened './classes.dex', DEX version '035'
Class #0 -
Class descriptor : 'Lcom/example/helloandroid/HelloAndroid;'
Access flags : 0x0001 (PUBLIC)
Superclass : 'Landroid/app/Activity;'
Interfaces -
Static fields -
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/HelloAndroid;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
0002c4: |[0002c4] com.example.helloandroid.HelloAndroid.<init>:()V
0002d4: 7010 0000 0000 |0000: invoke-direct {v0}, Landroid/app/Activity;.<init>:()V // method@0000
0002da: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=6
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/HelloAndroid;
Virtual methods -
#0 : (in Lcom/example/helloandroid/HelloAndroid;)
name : 'onCreate'
type : '(Landroid/os/Bundle;)V'
access : 0x0001 (PUBLIC)
code -
registers : 3
ins : 2
outs : 2
insns size : 9 16-bit code units
0002dc: |[0002dc] com.example.helloandroid.HelloAndroid.onCreate:(Landroid/os/Bundle;)V
0002ec: 6f20 0100 2100 |0000: invoke-super {v1, v2}, Landroid/app/Activity;.onCreate:(Landroid/os/Bundle;)V // method@0001
0002f2: 1500 037f |0003: const/high16 v0, #int 2130903040 // #7f03
0002f6: 6e20 0400 0100 |0005: invoke-virtual {v1, v0}, Lcom/example/helloandroid/HelloAndroid;.setContentView:(I)V // method@0004
0002fc: 0e00 |0008: return-void
catches : (none)
positions :
0x0000 line=10
0x0003 line=11
0x0008 line=12
locals :
0x0000 - 0x0009 reg=1 this Lcom/example/helloandroid/HelloAndroid;
0x0000 - 0x0009 reg=2 savedInstanceState Landroid/os/Bundle;
source_file_idx : 1 (HelloAndroid.java)
Class #1 -
Class descriptor : 'Lcom/example/helloandroid/R$attr;'
Access flags : 0x0011 (PUBLIC FINAL)
Superclass : 'Ljava/lang/Object;'
Interfaces -
Static fields -
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/R$attr;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
000300: |[000300] com.example.helloandroid.R$attr.<init>:()V
000310: 7010 0a00 0000 |0000: invoke-direct {v0}, Ljava/lang/Object;.<init>:()V // method@000a
000316: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=11
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/R$attr;
Virtual methods -
source_file_idx : 15 (R.java)
Class #2 -
Class descriptor : 'Lcom/example/helloandroid/R$drawable;'
Access flags : 0x0011 (PUBLIC FINAL)
Superclass : 'Ljava/lang/Object;'
Interfaces -
Static fields -
#0 : (in Lcom/example/helloandroid/R$drawable;)
name : 'icon'
type : 'I'
access : 0x0019 (PUBLIC STATIC FINAL)
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/R$drawable;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
000318: |[000318] com.example.helloandroid.R$drawable.<init>:()V
000328: 7010 0a00 0000 |0000: invoke-direct {v0}, Ljava/lang/Object;.<init>:()V // method@000a
00032e: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=13
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/R$drawable;
Virtual methods -
source_file_idx : 15 (R.java)
Class #3 -
Class descriptor : 'Lcom/example/helloandroid/R$layout;'
Access flags : 0x0011 (PUBLIC FINAL)
Superclass : 'Ljava/lang/Object;'
Interfaces -
Static fields -
#0 : (in Lcom/example/helloandroid/R$layout;)
name : 'main'
type : 'I'
access : 0x0019 (PUBLIC STATIC FINAL)
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/R$layout;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
000330: |[000330] com.example.helloandroid.R$layout.<init>:()V
000340: 7010 0a00 0000 |0000: invoke-direct {v0}, Ljava/lang/Object;.<init>:()V // method@000a
000346: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=16
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/R$layout;
Virtual methods -
source_file_idx : 15 (R.java)
Class #4 -
Class descriptor : 'Lcom/example/helloandroid/R$string;'
Access flags : 0x0011 (PUBLIC FINAL)
Superclass : 'Ljava/lang/Object;'
Interfaces -
Static fields -
#0 : (in Lcom/example/helloandroid/R$string;)
name : 'app_name'
type : 'I'
access : 0x0019 (PUBLIC STATIC FINAL)
#1 : (in Lcom/example/helloandroid/R$string;)
name : 'hello'
type : 'I'
access : 0x0019 (PUBLIC STATIC FINAL)
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/R$string;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
000348: |[000348] com.example.helloandroid.R$string.<init>:()V
000358: 7010 0a00 0000 |0000: invoke-direct {v0}, Ljava/lang/Object;.<init>:()V // method@000a
00035e: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=19
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/R$string;
Virtual methods -
source_file_idx : 15 (R.java)
Class #5 -
Class descriptor : 'Lcom/example/helloandroid/R;'
Access flags : 0x0011 (PUBLIC FINAL)
Superclass : 'Ljava/lang/Object;'
Interfaces -
Static fields -
Instance fields -
Direct methods -
#0 : (in Lcom/example/helloandroid/R;)
name : '<init>'
type : '()V'
access : 0x10001 (PUBLIC CONSTRUCTOR)
code -
registers : 1
ins : 1
outs : 1
insns size : 4 16-bit code units
000360: |[000360] com.example.helloandroid.R.<init>:()V
000370: 7010 0a00 0000 |0000: invoke-direct {v0}, Ljava/lang/Object;.<init>:()V // method@000a
000376: 0e00 |0003: return-void
catches : (none)
positions :
0x0000 line=10
locals :
0x0000 - 0x0004 reg=0 this Lcom/example/helloandroid/R;
Virtual methods -
source_file_idx : 15 (R.java)
結果、HelloAndroid.apkで使用さ
れているクラスは#0~#5の6つ。
Class #0のVirtual methodsは1つで、名前はonCreate。
メ
ソッド内で、super.onCreate()とsetContentView()をコールしていることがわかります。
これだけ逆
アセンブルできれば十分ですね。