【玩转Ubuntu】 Ubuntu上安装apktool
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ ls
apktool1.5.2.tar.bz2 apktool-install-linux-r05-ibot.tar.bz2 book.pdf spark_2.4_h5.apk
# 解压bz2文件的方法1,先使用bunzip2转成tar文件,再使用tar xvf 进行解压
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ bunzip2 apktool1.5.2.tar.bz2
bunzip2: apktool1.5.2.tar.bz2: trailing garbage after EOF ignored
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ ls
apktool1.5.2.tar apktool-install-linux-r05-ibot.tar.bz2 book.pdf spark_2.4_h5.apk
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ tar xvf apktool1.5.2.tar
apktool1.5.2/
apktool1.5.2/apktool.jar
# 解压bz2文件的方法2,直接解压:tar jxvf 文件.bz2
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ tar jxvf apktool-install-linux-r05-ibot.tar.bz2
apktool-install-linux-r05-ibot/aapt
bzip2: (stdin): trailing garbage after EOF ignored
apktool-install-linux-r05-ibot/
apktool-install-linux-r05-ibot/apktool
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载$ ls -al
总用量 11740
drwxr-xr-x 4 bixiaopeng bixiaopeng 4096 10月 12 10:42 .
drwxr-xr-x 35 bixiaopeng bixiaopeng 4096 10月 12 10:38 ..
drwxrwxr-x 2 bixiaopeng bixiaopeng 4096 2月 3 2013 apktool1.5.2
-rw------- 1 bixiaopeng bixiaopeng 2658304 10月 12 10:37 apktool1.5.2.tar
drwxrwxr-x 2 bixiaopeng bixiaopeng 4096 12月 23 2012 apktool-install-linux-r05-ibot
-rw-rw-r-- 1 bixiaopeng bixiaopeng 419840 10月 12 10:37 apktool-install-linux-r05-ibot.tar.bz2
-rw-rw-r-- 1 bixiaopeng bixiaopeng 943231 10月 12 09:13 book.pdf
-rw-rw-r-- 1 bixiaopeng bixiaopeng 7963744 10月 11 15:21 spark_2.4_h5.apk
#将解压后得到的三个文件apktool.jar /aapt /apktool copy 到 /usr/local/bin/目录下
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/下载/apktool-install-linux-r05-ibot$ cd /usr/local/bin/
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:/usr/local/bin$ ls -al
- 总用量 3704
- drwxr-xr-x 2 root root 4096 10月 12 10:51 .
- drwxr-xr-x 10 root root 4096 4月 25 01:11 ..
- -rwxr-x--- 1 root root 1119899 10月 12 10:51 aapt
- -rwxr-xr-x 1 root root 2320 10月 12 10:51 apktool
- -rw-r--r-- 1 root root 2655843 10月 12 10:50 apktool.jar
#下面就可以直接使用apktool了,先查看一下帮助文件
- bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ apktool
- Apktool v1.5.2 - a tool for reengineering Android apk files
- Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
- with smali v1.4.1, and baksmali v1.4.1
- Updated by @iBotPeaches <connor.tumbleson@gmail.com>
- Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND [...]
- 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.
- -b, --no-debug-info
- Baksmali -- don't write out debug info (.local, .param, .line, etc.)
- -f, --force
- Force delete destination directory.
- -t <tag>, --frame-tag <tag>
- Try to use framework files tagged by <tag>.
- --frame-path <dir>
- Use the specified directory for framework files
- --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>
- 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.
- -a, --aapt
- Loads aapt from specified location.
- if|install-framework <framework.apk> [<tag>] --frame-path [<location>]
- Install framework file to your system.
- For additional info, see: http://code.google.com/p/android-apktool/
- For smali/baksmali info, see: http://code.google.com/p/smali/
至于如何使用apktool,请参考我的另一篇博客http://blog.csdn.net/wirelessqa/article/details/8997168
二、利用dex2jar反编译
首先要下载两个工具:dex2jar和JD-GUI
前者是将apk中的classes.dex转化成Jar文件,而JD-GUI是一个反编译工具,可以直接查看Jar包的源代码。以下是下载地址:
dex2jar:http://code.google.com/p/dex2jar/downloads/list
JD-GUI:http://laichao.googlecode.com/files/jdgui.zip
具体步骤:
首先将apk文件,将后缀改为zip,解压,得到其中的classes.dex,它就是java文件编译再通过dx工具打包而成的;
解压下载的dex2jar,将classes.dex复制到dex2jar.bat所在目录。在命令行下定位到dex2jar.bat所在目录
运行
dex2jar.bat classes.dex
生成
classes.dex.dex2jar.jar
生成jar文件的截图如下:
运行JD-GUI(jd-gui.exe),打开上面生成的jar包,即可看到源代码了
HelloAndroid源码(编译前的apk源码对照)如下: