使用ApkTool反編譯Apk
下載 apktool1.4.3.tar.bz2 、apktool-install-linux-r04-brut1.tar.bz2 兩個包,並解壓到統一個目錄中,解壓後得到aapt apktool apktool.jar 。解壓安裝完成後輸入以下命令解壓:
[plain]
<SPAN xmlns="http://www.w3.org/1999/xhtml">$ ./apktool d apk/xgd_android_test.apk
I: Baksmaling…
I: Loading resource table…
I: Loaded.
I: Loading resource table from file: /home/yangyupeng/apktool/framework/1.apk
I: Loaded.
I: Decoding file-resources…
W: Cant find 9patch chunk in file: "drawable-mdpi/navbar.9.png". Renaming it to *.png.
I: Decoding values*/* XMLs…
I: Done.
I: Copying assets and libs…
</SPAN>
$ ./apktool d apk/xgd_android_test.apk
I: Baksmaling…
I: Loading resource table…
I: Loaded.
I: Loading resource table from file: /home/yangyupeng/apktool/framework/1.apk
I: Loaded.
I: Decoding file-resources…
W: Cant find 9patch chunk in file: "drawable-mdpi/navbar.9.png". Renaming it to *.png.
I: Decoding values*/* XMLs…
I: Done.
I: Copying assets and libs…
顯示如上,註意apktool的參數,d表示decode,b表示build,此時在當前目錄生成apk的解壓文件:
[html]
<SPAN xmlns="http://www.w3.org/1999/xhtml"><SPAN xmlns="http://www.w3.org/1999/xhtml">1/xgd_android_test$ ls
AndroidManifest.xml apktool.yml lib res smali
</SPAN></SPAN>
1/xgd_android_test$ ls
AndroidManifest.xml apktool.yml lib res smali
這裡有apk的源碼(smali)、圖片、xml配置和語言配置等等信息。
使用dex2jar和JD-JUI這兩個工具查看java源碼
下載dex2jar、JD-JUI 兩個包,解壓。
把apk的後綴名改成zip,並解壓得到classes.dex文件,在dex2jar目錄中輸入如下命令得到.jar文件:
[plain]
<SPAN xmlns="http://www.w3.org/1999/xhtml">$ ./dex2jar.sh classes.dex
this cmd is deprecated, use the d2j-dex2jar if possible
dex2jar version: translator-0.0.9.9
dex2jar classes.dex -> classes_dex2jar.jar
Done.
</SPAN>
$ ./dex2jar.sh classes.dex
this cmd is deprecated, use the d2j-dex2jar if possible
dex2jar version: translator-0.0.9.9
dex2jar classes.dex -> classes_dex2jar.jar
Done.
再使用JD-JUI打開該文件就能查看源代碼:
與源代碼對比:
[java]
<SPAN xmlns="http://www.w3.org/1999/xhtml">package xgd.android;
import android.app.Activity;
import android.os.Bundle;
public class ICCardActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.iccard);
}
}
</SPAN>
package xgd.android;
import android.app.Activity;
import android.os.Bundle;
public class ICCardActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.iccard);
}
}