2013年5月5日 星期日

Decompile APK


Reference: 

http://stackoverflow.com/questions/3593420/android-getting-source-code-from-an-apk-file

Procedure for decoding .apk files, step-by-step method:

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apk file to .zip (eg.: rename from filename.apk to filename.apk.zip) and save it. Now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue.

Step 2:

Now extract this zip apk file in the same folder (or NEW FOLDER). Now download dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (or NEW FOLDER). Now open command prompt and change directory to that folder (or NEW FOLDER). Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder. Then download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

Now open another new folder and put these files
1. put .apk file which you want to decode
2. download apktool v1.x AND apktool install window using google and put in the same folder
3. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
4. Open a command window
5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...

=================================================


Reference:


功能

  1. 集成apktool/dex2jar/jd-gui
  2. 只需执行一步即可反编译出apk所有文件(资源文件和jar等等)
  3. 打开jd-gui反编译jar文件

使用方法

  1. 在Downloads中下载onekey-decompile-apk.zip, 解压缩到类似D:\downloads\onekey-decompile-apk
  2. 将apk文件放到onekey-decompile-apk目录下
  3. 将apk文件拖拽到_onekey-decompile-apk.bat
  4. 执行完成后
    • 会在onekey-decompile-apk目录下生成和apk同名的目录(放置了apktools反编译出来的东西)
    • 会在onekey-decompile-apk目录下生成和apk同名的jar文件(dex2jar反编译出来的class)

运用工具(非常感谢他们)

  1. apktool反编译出apk中的资源文件, 例如AndroidManifest.xml和res
  2.     java -jar apktool.jar d -d xxx.apk
  3. dex2jar反编译出apk中的class
  4.     // dex2jar is deprecated, use the d2j-dex2jar
        d2j-dex2jar xxx.apk
  5. jd-ui/jad反编译class为java源文件
  6. 反编译工具还是jad最强, JD-GUI只是方便反编译/查看整个jar而已, 反编译出来的代码不全, 因此需要jd + jad(或者jadclipse eclipse插件使用更方便)配合才完美

参考

更新

  • 2012-10-24: inject_classes v1.0 将自己写的class混编(注入)到需要反编译的apk(mix/inject classes2apk) Changes
  • 2012-10-22: onekey-decompile-apk v1.0.1 将apktool降到1.4.1(原来是1.4.3), 只有这个版本能进行SmaliDebugging Changes
  • 2012-10-22: 新的一步到位打包apk(签名, 安装)工具(onekey build-sign-install apk). Changes

沒有留言:

張貼留言