Android反编译 for Mac

反编译前需要准备的工具

  1. apktool:反编译APK文件,得到classes.dex文件,同时也能获取到资源文件以及布局文件。
  2. dex2jar:将反编译后的classes.dex文件转化为.jar文件。
  3. jd-gui:用于将.jar文件转换成java代码

step1: 去下载apktool, 或是通过命令 

         open terminal :  然后输入  localhost:~ felix$ brew install apktool  然后回车,等就行了

Android反编译 for Mac

Android反编译 for Mac

然后输入apktool 出现下面界面代表apktool 安装成功

localhost:~ felix$ apktool

Apktool v2.4.1 - a tool for reengineering Android apk files

with smali v2.3.4 and baksmali v2.3.4

Copyright 2014 Ryszard Wiśniewski <[email protected]>

Updated by Connor Tumbleson <[email protected]>

 

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: http://ibotpeaches.github.io/Apktool/ 

For smali/baksmali info, see: https://github.com/JesusFreke/smali

 

step2: 运行apoktool脚本进行反编译

apktool d xxx.apk 回车,等待执行完毕

Android反编译 for Mac

然后我们去看看APK 存在位置会多出一个app-release文件夹

Android反编译 for Mac

但是我们在反编译apk后的文件夹里并没有看到classes.dex文件,这时候就需要在上述命令行添加-s,表示禁止将dex文件解码成smali,这时候我们需要  apktool d -s xxx.apk

稍等,再在终端输入 apktool d -s app-release.apk

localhost:Documents felix$ apktool d  -s app-release.apk

Destination directory (/Users/felix/Documents/app-release) already exists. Use -f switch if you want to overwrite it.

localhost:Documents felix$ apktool d  -f app-release.apk

I: Using Apktool 2.4.1 on app-release.apk

I: Loading resource table...

I: Decoding AndroidManifest.xml with resources...

I: Loading resource table from file: /Users/felix/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: Baksmaling classes3.dex...

I: Copying assets and libs...

I: Copying unknown files...

I: Copying original files...

I: Copying META-INF/services directory

localhost:Documents felix$ apktool d  -s app-release.apk

I: Using Apktool 2.4.1 on app-release.apk

I: Loading resource table...

I: Decoding AndroidManifest.xml with resources...

I: Loading resource table from file: /Users/felix/Library/apktool/framework/1.apk

I: Regular manifest package...

I: Decoding file-resources...

I: Decoding values */* XMLs...

I: Copying raw classes.dex file...

I: Copying raw classes2.dex file...

I: Copying raw classes3.dex file...

I: Copying assets and libs...

I: Copying unknown files...

I: Copying original files...

I: Copying META-INF/services directory

Android反编译 for Mac

终于得到了.dex文件,OK ,我们进行下一步吧.

step2:使用dex2jar工具把classes.dex文件转化成.jar文件

下载dex2jar,

Android反编译 for Mac

然后把classes.dex文件复制到解压后的dex2jar文件夹下,

终端执行命令sh d2j-dex2jar.sh classes.dex,这时候会权限错误

cd dex2jar-2.0/

localhost:dex2jar-2.0 felix$ sh d2j-dex2jar.sh classes.dex

d2j-dex2jar.sh: line 36: ./d2j_invoke.sh: Permission denied

localhost:dex2jar-2.0 felix$ sudo chmod +x d2j_invoke.sh

Password:  

更改权限继续生成 classes-dex2jar.dex

Android反编译 for Mac

Android反编译 for Mac

step3:使用JD-GUI软件查看jar包下的java源码

1、下载jd-gui 

Android反编译 for Mac

2. 打开安装好的JD-GUI,直接把第二步生成的.jar文件拖进去,就能看到反编译出来的java源码了

打开工具并把jar托运进去

Android反编译 for Mac

 

Android反编译 for Mac

到此,反编译过程完成,可以看源码了,是不是很开心