Android Apk 反編譯,Apk 內容修改
通過dex2jar和jd我們可以反編譯apk中的dex,可以比較完美的查看java源文件;通過apktool可以反編譯apk中的xml等資源文件,然后通過apk-sign簽名,可以制作成修改版的可發布apk文件。
1.dex2jar反編譯dex文件:
a.下載文件見附件:apktool-1.3.1.tar.bz2,jd-gui.zip,解壓;
b. 把apk文件后綴名改為.zip,然后解壓縮其中的class.dex文件,它是java文件編譯再通過dx工具打包成的,所以現在我們就用上述提到的2個工具來逆方向導出java源文件;
c.把class.dex拷貝到dex2jar.bat所在目錄,運行dex2jar.bat class.dex,生成classes.dex.dex2jar.jar ;
d.運行jd-gui工具(綠色無須安裝),打開上面生成的jar文件,即可看到源代碼;
2.Android反編譯工具:Apktool,支持Linux 、Windows。
Android apktool是一個用來處理APK文件的工具,可以對APK進行反編譯生成程序的源代碼和圖片、XML配置、語言資源等文件,也可以添加新的功能到APK文件中。用該工具來漢化Android軟件然后重新打包發布是相當簡單的。
1.安裝
1).首先安裝需要JAVA環境,先下載JDK/JRE,請下載,已經有JAVA環境的可跳過此步
2).到code.google上下載apktool.jar以及相關文件:http://code.google.com/p/android-apktool/downloads/list
點擊下載apktool-1.0.0.tar.bz2 和apktool-install-windows-2.1_r01-1.zip
3).解壓apktool-install-windows.zip到任意文件夾,然后解壓apktool.jar 到apktool-install-windows.zip所在的文件夾下。
4).點擊開始菜單,運行,輸入CMD回車,用cd命令轉到剛剛解壓apktool-install-windows所在的文件夾,輸入apktool,出現一些命令說明即成功安裝。
C:\android\android-apktool\apktool-install-windows-r04-brut1>apktool.bat
Apktool v1.4.1 - a tool for reengineering Android apk files
Copyright 2010 Ryszard Wi?niewski <brut.alll@gmail.com>
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Usage: apktool [-v|--verbose] COMMAND [...] -- 熟悉dos命令的很容易可以看懂
COMMANDs are:
d[ecode] [OPTS] <file.apk> [<dir>]
Decode <file.apk> to <dir>.
OPTS:
-s, --no-src
Do not decode sources.
-r, --no-res
Do not decode resources.
-d, --debug
Decode in debug mode. Check project page for more info.
-f, --force
Force delete destination directory.
-t <tag>, --frame-tag <tag>
Try to use framework files tagged by <tag>.
--keep-broken-res
Use if there was an error and some resources were dropped, e.g.:
"Invalid config flags detected. Dropping resources", but you
want to decode them anyway, even with errors. You will have to
fix them manually before building.
b[uild] [OPTS] [<app_path>] [<out_file>]
Build an apk from already decoded application located in <app_path>.
It will automatically detect, whether files was changed and perform
needed steps only.
If you omit <app_path> then current directory will be used.
If you omit <out_file> then <app_path>/dist/<name_of_original.apk> -- 這個需要注意,生成新的apk所在的目錄
will be used.
OPTS:
-f, --force-all
Skip changes detection and build all files.
-d, --debug
Build in debug mode. Check project page for more info.
if|install-framework <framework.apk> [<tag>]
Install framework file to your system.
For additional info, see: http://code.google.com/p/android-apktool/
2、使用
apktool d XXX.apk ABC 反編譯XXX.apk到文件夾ABC
apktool b ABC 從文件夾ABC重建APK,輸出到ABC/dist/out.apk
例子:
C:\android\android-apktool\apktool-install-windows-r04-brut1>apktool d C:\android\參考\simple.apk SIMPLE
I: Baksmaling...
testI: Loading resource table...
I: Loaded.
I: Loading resource table from file: C:\Documents and Settings\Administrator\apk
tool\framework\1.apk
I: Loaded.
I: Decoding file-resources...
I: Decoding values*/* XMLs...
I: Done.
I: Copying assets and libs...
C:\android\android-apktool\apktool-install-windows-r04-brut1>apktool b SIMPLE
I: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
OK, 這樣包就重新打好了,可能你并沒有直接看到什么東西產生,不過這個時候你看一下 SIMPLE\dist 文件夾的SIMPLE\dist里,已經產生了一個我們修改后的APK,就是它了,但是這個文件目前還不能安裝,需要一個簽名!下一步就是關于軟件簽名的,早在09年就已經有老外研究過了,我們現在用的只是人家當年的技術了。
4 D/ z/ U H4 C) d! r4 A
簽名程序名為 Autosign ,你可以自己去google搜索.這個的安裝很簡單吧,原作者都寫了,其實你要做的就是解壓,然后使用就OK,當然如果你跟我一樣使用Ubuntu/FreeBSD等系統,就執行下面的命令
java -jar signapk.jar (網上有教程)v& }+ B6 H. k" j
Windows用戶只要雙擊exe執行即可,操作已經很簡單,不必多說了。Ubuntu/FreeBSD用戶可以自己寫一個小腳本,很簡單也不用多說了。
好了,經過了以上的操作,你的作品就可以公布了。
3.apk-sign簽名apk文件:
1). 下載文件件附件apk-sign.rar,解壓到任意文件夾;
2).將XXX.apk文件解壓到XXX文件夾,然后將XXX文件夾直接拖到apk-sign文件中的sign_pack.bat批處理文件上以執行,彈出cmd執行窗口,等待執行完即可;
3).生成新文件夾XXX_signed中的apk文件即為已簽名;
4)在apk-sign文件夾中會多出一個文件夾,里面就是簽名過的Apk