MAC下反编译APK的工具ApkTool,dex2jar,JD-GUI安装与使用方法

前言

最近打开某个icloud存储的easyClick的项目,竟然发现项目在同步的过程中少了几个重要的文件。尝试各种方法后均无法找回。只得去反编译以前打包过的文件。

一波操作过后,发现并没有得到想要的结果…

安装过程

Apktool下载

选择macOS的脚本,在 wrapper script上右键另存文件。由于该文件在墙外,所以下载还是颇费周折的。经过一番折腾,最后用了另一台windows的笔记本,安装了某个梯子软件后,才得以下载完成。

file

这里面需要避开的坑,就是如果直接打开该脚本网页,复制里面的脚本文件内容,保存为txt文件并重命名去掉后缀。这种方式是不行的。在后面使用“chmod +x apktool”命令,会一直提示找不到该文件“No such file”。

下载 apktool-2xxx.jar,重命名为apktool.jar。

在访达中前往“/usr/local/bin”这个隐藏目录
file

把 apktool.jar 和 apktool 这两个文件,复制或剪切到 /usr/local/bin 目录。

打开终端,依次执行如下命令:

cd /usr/local/bin
chmod +x apktool
chmod +x apktool.jar

如果没有报错,输入 apktool ,查看是否展示apktool的相关信息,有则配置成功。

feiyun@feiyundeMacBook-Pro bin % apktool
Apktool v2.5.0 - a tool for reengineering Android apk files
with smali v2.4.0 and baksmali v2.4.0
Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
Copyright 2010 Connor Tumbleson <connor.tumbleson@gmail.com>

usage: apktool
 -advance,--advanced   prints advance information.
 -version,--version    prints the version then exits
usage: apktool if|install-framework [options] <framework.apk>
 -p,--frame-path <dir>   Stores framework files into <dir>.
 -t,--tag <tag>          Tag frameworks using <tag>.
usage: apktool d[ecode] [options] <file_apk>
 -f,--force              Force delete destination directory.
 -o,--output <dir>       The name of folder that gets written. Default is apk.out
 -p,--frame-path <dir>   Uses framework files located in <dir>.
 -r,--no-res             Do not decode resources.
 -s,--no-src             Do not decode sources.
 -t,--frame-tag <tag>    Uses framework files tagged by <tag>.
usage: apktool b[uild] [options] <app_path>
 -f,--force-all          Skip changes detection and build all files.
 -o,--output <dir>       The name of apk that gets written. Default is dist/name.apk
 -p,--frame-path <dir>   Uses framework files located in <dir>.

For additional info, see: https://ibotpeaches.github.io/Apktool/ 
For smali/baksmali info, see: https://github.com/JesusFreke/smali

初步反编译

将需要反编译的apk文件,复制或剪切到 /usr/local/bin 目录。

在终端输入“apktool d xxx.apk”,xxx为文件名。

feiyun@feiyundeMacBook-Pro bin % apktool d 1.0.2.apk
I: Using Apktool 2.5.0 on 1.0.2.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/feiyun/Library/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

反编译完成后,apk同目录下会生成一个文件夹。
file

其中d是decode的意思,表示我们要对apk文件进行解码。
还可以再加上一些附加参数来控制decode的更多行为:
·f 如果目标文件夹已存在,则强制删除现有文件夹(默认如果目标文件夹已存在,则解码失败)。
·o 指定解码目标文件夹的名称(默认使用APK文件的名字来命名目标文件夹。
·s 不反编译dex文件,也就是说classes.dex文件会被保留(默认会将dex文件解码成smali文件)。
·r 不反编译资源文件,也就是说resources.arsc文件会被保留(默认会将resources.arsc解码成具体的资源文件)。

使用apktool 将APK 文件解析出来,这样能获取到 /res 目录下的资源文件。

解压文件

在apk文件上右键单击,解压文件。
file

解压后得到了若干个dex文件。它是java源代码经过编译,再通过dx工具打包而成。

使用dex2jar

dex2jar下载

将dex文件复制到dex2jar所在的文件夹。
file

执行命令

 sh d2j-dex2jar.sh classes.dex

结果如下,提示“Permission denied”

 feiyun@feiyundeMacBook-Pro dex2jar-2.0 % sh d2j-dex2jar.sh classes.dex
d2j-dex2jar.sh: line 36: ./d2j_invoke.sh: Permission denied

这是文件权限不足导致的。执行如下命令修改权限:

chmod 777 d2j_invoke.sh

然后再执行反编译命令。过程如下:

feiyun@feiyundeMacBook-Pro dex2jar-2.0 % chmod 777 d2j_invoke.sh
feiyun@feiyundeMacBook-Pro dex2jar-2.0 % sh d2j-dex2jar.sh classes.dex
dex2jar classes.dex -> ./classes-dex2jar.jar
Detail Error Information in File ./classes-error.zip
Please report this file to http://code.google.com/p/dex2jar/issues/entry if possible.

完成后,目录下出现了一个名为“classes-dex2jar.jar”的jar包。

怎么处理这个jar包呢?这个时候jd-gui就起作用了。

使用jd-gui

jd-gui下载

下载后得到一个tar文件。双击解压。
file

打开JD-GUI主程序,将jar包拖进主窗口。
file

最后

需要使用的文件已经打包到网盘。

1. 官方交流QQ群,添加多个不批。建议使用安卓手机或电脑申请。
Auto.js学习交流③群:286635606
Auto.js学习交流②群:712194666(满员)
IOS免越狱自动化测试群:691997586
EasyClick学习交流①群:737066890
2. 盗版,破解有损他人权益和违法作为,请各位会员支持正版。
3. 本站部分资源来源于用户上传和网络搜集,如有侵权请提供版权证明并联系站长删除。
4.如未特别申明,本站的技术性文章均为原创,未经授权,禁止转载/搬运等侵权行为。
5.全站所有付费服务均为虚拟商品,购买后自动发货。售出后概不接受任何理由的退、换。注册即为接受此条款。
6.如果站内内容侵犯了您的权益,请联系站长删除。
飞云脚本 » MAC下反编译APK的工具ApkTool,dex2jar,JD-GUI安装与使用方法

企业级大数据智能营销管理系统

了解详情