Android反编译apk(Mac环境)

为什么要反编译?

反编译别人的apk,可以学习别人的项目。就算别人做了代码混淆,你也可以看到里面的资源文件,如布局文件、AndroidManifest.xml等文件,很多东西都是可以借鉴和学习的。

需要下载安装哪些工具?

apktool :https://ibotpeaches.github.io/Apktool/install
dex2jar:https://github.com/pxb1988/dex2jar
jd-gui:http://jd.benow.ca

如果apk做了代码混淆,或者你仅仅是想看别人apk里面的资源文件,用apktool就可以了。如果apk没有做代码混淆,或者你想继续反编译研究别人项目里的代码,就要用到dex2jar和jd-gui。 dex2jar可以将apk文件转成jar文件,而jd-gui可以查看jar文件里面被反编译出来的源代码。运行jd-gui需要你的电脑已经安装了jdk1.8+,但实际上即使你已经安装了jdk1.8+,它还是运行不了,提示需要jdk1.8+的环境,后面再介绍遇到这问题该怎么解决。

apktool安装

按照网页(https://ibotpeaches.github.io/Apktool/install)上面的指引去做就可以了,记得用chmod添加执行权限
chmod +x apktool.jar
chmod +x apktool

macOS:
Download Mac wrapper script (Right click, Save Link As apktool)
Download apktool-2 (find newest here)
Rename downloaded jar to apktool.jar
Move both files (apktool.jar & apktool) to /usr/local/bin (root needed)
Make sure both files are executable (chmod +x)
Try running apktool via cli
Or you can install apktool via Homebrew:

Install Homebrew as described in this page
Execute command brew install apktool in terminal (no root needed). The latest version will be installed in /usr/local/Cellar/apktool/[version]/ and linked to /usr/local/bin/apktool.
Try running apktool via cli

dex2jar安装

到这里https://github.com/pxb1988/dex2jar把项目下载下来,然后按下面的提示去做
In the root directory run: ./gradlew distZip
cd dex-tools/build/distributions
Unzip the file dex-tools-2.1-SNAPSHOT.zip (file size should be ~5 MB)
Run d2j-dex2jar.sh from the unzipped directory

jd-gui

到http://jd.benow.ca下载安装软件就可以,并且要求已经安装了jdk1.8+。但实际上即使你已经安装了jdk1.8+,它还是运行不了,提示需要jdk1.8+的环境,解决办法:https://zhuanlan.zhihu.com/p/453431240

开始使用

随便新建一个文件夹,比如我在桌面上新建一个文件夹叫decompiler,把需要反编译的apk放进去,如test.apk;为了方便,我把dex2jar和jd-gui都一起放到了decompiler这个文件夹。在命令行下cd到decompiler这个文件夹,输入apktool d test.apk,完成后会多出一个test的文件夹(跟apk的文件名一样),里面就是各种资源文件。

260E6334-69AD-4F71-80A4-8BBEDC8D8B5B.png

然后sh d2j-dex2jar.sh -f test.apk (将这里的d2j-dex2jar.sh换成你的实际路径,比如我的是/Users/chen/Desktop/decompiler/dex2jar-2.x/dex-tools/build/distributions/dex-tools-2.2-SNAPSHOT/d2j-dex2jar.sh 当然你也可以先把它加入到环境变量)

完成后会生成test-dex2jar.jar

用jd-gui打开test-dex2jar.jar,就可以看到反编译后的代码了

参考资料

1、Android反编译apk并重新打包签名(Mac环境)

2、https://www.jianshu.com/p/dda9ff90a3c5

你可能感兴趣的:(Android反编译apk(Mac环境))