我们经常会在如下的情况使用反编译

1、看到别人应用中的酷炫功能,想知道是如何实现的
2、别人应用的素材排版好漂亮,想套用模仿
 
百度一下就已经有一大堆反编译的教程了,我还是坚持学习记录一下。
 
Android导出的APK其实与普通的压缩包没啥区别,我们随意用一个压缩工具打开,我这里用的是WinRAR,即可看到APK的庐山真面目
其中,classes.dex即为整个APK所用到的类。

.dex文件简介

.dex文件是虚拟机可执行格式(Dalvik Executable (.dex/.odex) format),是专门用来给ART(Android runtime
 )执行的。具体参考地址http://source.android.com/devices/tech/dalvik/
想要查看.dex文件的内容,就必须用到一个工具---dex2jar,地址https://code.google.com/p/dex2jar/

dex2jar使用方法(转载自官方):

1、下载dex2jar最新版http://code.google.com/p/dex2jar/downloads/list
2、解压dex2jar-version.zip文件到一个目录. 比方说 /home/panxiaobo/, C:\
unzip -x dex2jar-version.zip -d /home/panxiaobo
3、使用 dex2jar 来生成 .jar 文件. dex2jar会在工作目录下生成一个someApk-dex2jar.jar文件.
   linux sh /home/panxiaobo/dex2jar-version/d2j-dex2jar.sh /home/panxiaobo/someApk.apk
   windows C:\dex2jar-version\d2j-dex2jar.bat someApk.apk
4、使用反编译工具获取查看源代码
就这么简单
 

资源文件反编译

对于图片素材,直接解压APK,在res-》drawable里面,几乎可以直接查看使用。
对于排版XML文件,全部都是乱码,这个时候我们要使用到android-apktool,地址https://code.google.com/p/android-apktool/

android-apktool简介

官方提供的一个逆向工具,最主要还是用来解析资源文件,因为dex2jar已经解决了反编译成jar的问题。
它能够解析APK中资源文件接近到原始状态 (including resources.arsc, XMLs and 9.png files),并且能够重建他们(破解的时候用到)。

android-apktool安装方法

Quick Check

  • Apktool 2.x (Versions after 1.5.2)
    1. Is Java 1.7 installed?
    2. Does executing java -version on command line / command prompt return 1.7?
    3. If not, please install Java 7 and make it the default.
  • Apktool 1.x (Versions prior to 1.5.2)
    1. Is Java 1.6 or higher installed?
    2. Does executing java -version on command line / command prompt return 1.6 or above?
    3. If not, please install Java 6 or Java 7.

Installation for Apktool 2.x

  • Windows:
    1. Download Windows wrapper script (Right click, Save Link As apktool.bat)
    2. Download apktool-2 (find newest here)
    3. Rename downloaded jar to apktool.jar
    4. Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
    5. If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
    6. Try running apktool via command prompt
  • Linux:
    1. Download Linux wrapper script (Right click, Save Link As apktool)
    2. Download apktool-2 (find newest here)
    3. Rename downloaded jar to apktool.jar
    4. Move both files (apktool.jar & apktool) to /usr/local/bin (root needed)
    5. Make sure both files are executable (chmod +x)
    6. Try running apktool via cli
  • Mac OS X:
    1. Download Mac wrapper script (Right click, Save Link As apktool)
    2. Download apktool-2 (find newest here)
    3. Rename downloaded jar to apktool.jar
    4. Move both files (apktool.jar & apktool) to /usr/local/bin (root needed)
    5. Make sure both files are executable (chmod +x)
    6. Try running apktool via cli

Note - Wrapper scripts are not needed, but helpful so you don't have to type java -jar apktool.jar over and over.

 

android-apktool参数介绍

Confused about some of the commands Apktool can do?

Utility Options

-version, --version

Outputs current version. (Ex: 1.5.2)

-v, --verbose

Verbose output. Needed before all other commands.

-q, --quiet

Quiets output. Needed before all other commands.

-advance, --advanced

Prints advance options

Decompile Options

--api <API>

The numeric api-level of the smali files to generate (eg 14 for ICS).

-b, --no-debug-info

Prevents baksmali from writing out debug info (.local, .param, .line, etc). Preferred to use if you are comparing smali from the same APK of different versions. The line numbers and debug will change among versions, which can make DIFF reports a pain.

-d, --debug

Decodes in Debug Mode. Check SmaliDebugging

--debug-line-prefix <prefix>

Smali line prefix when decoding in debug mode. Default "a=0;//"

-f, --force

Force delete destination directory. Use if trying to decompile to a folder that already exists.

--keep-broken-res

If there is an error like "Invalid Config Flags Detected. Dropping Resources...". This means that APK has a different structure then Apktool can handle. This might be a newer Android version or a random APK that doesn't match standards. Running this will allow the decode, but then you have to manually fix the folders with -ERR in them.

-m, --match-original

Keeps files closest as possible to original. Prevents rebuilding, used for analysis"

-o, --output <dir>

The name of the folder that gets written.

-p, --frame-path <dir>

The location where framework files are loaded from / placed.

-r, --no-res

This will prevent the decompile of resources. This keeps the resources.arsc intact without any decompile. If only editing Java (smali) then this is the recommend for faster decompile & rebuild.

-s, --no src

This will prevent the decompile of the java source. This keeps the APK classes.dex file and simply moves it during re-compile. If your only editing the resources. This is recommended for faster decompile & rebuild.

-t, --frame-tag <tag>

Uses framework files tagged by <tag>.

How to Decompile?

Prior to Decompile, you must have frameworks installed. Please read this wiki: FrameworkFiles for more information. Once complete run

apktool d name_of_apk.apk

With any configurations noted above.

Recompile Options

-a, --aapt <file>

Loads aapt from the specified file location, instead of relying on path. Falls back to PATH loading, if no file found.

-c, --copy-original

Copies original AndroidManifest.xml and META-INF folder into built apk.

-d, --debug

Builds in Debug Mode, see SmaliDebugging

-f, --force-all

This overwrites an existing file during rebuild.

-o, --output <dir>

The name of the folder that gets written.

-p, --frame-path <dir>

The location where framework files are loaded from / placed.

How to Recompile?

Prior to Recompile, you must have a decompiled application installed. Once complete run

apktool b folder_of_decoded_apk

With any configurations noted above.

 

工具打包下载~附件列表

反编译android_APK_Attachments.zip

反编译android APK的更多相关文章

  1. 反编译Android APK及防止APK程序被反编译

    怎么逆向工程对Android Apk 进行反编译 google Android开发是开源的,开发过程中有些时候会遇到一些功能,自己不知道该怎么做,然而别的软件里面已经有了,这个时候可以采用反编译的方式 ...

  2. 『原』在Linux下反编译Android .apk文件 使用apktool dex2jar JD-eclipse

    一.使用apktool 将 apk反编译生成程序的源代码和图片.XML配置.语言资源等文件 具体步骤: (1)下载反编译工具包:apktool 官方的打不开 http://apktool.shouji ...

  3. 实例具体解释:反编译Android APK,改动字节码后再回编译成APK

    本文具体介绍了怎样反编译一个未被混淆过的Android APK,改动smali字节码后,再回编译成APK并更新签名,使之可正常安装.破译后的apk不管输入什么样的username和password都能 ...

  4. linux下反编译android apk

    1.所需要的工具 1)apktool,功能:反编译出apk所需要的资源文件和布局设置文件等, 下载地址:https://code.google.com/p/android-apktool/downlo ...

  5. Mac上反编译Android apk安装包

    什么是反编译 我们知道,Android的程序打包后会生成一个APK文件,这个文件可以直接安装到任何Android手机上,因此,反编译就是对这个APK进行反编译.Android的反编译分成两个部分: 一 ...

  6. 只需三步--轻松反编译Android Apk文件

    安卓程序是通过java语言进行编写的,可以很容易进行反编译.很多apk文件被反编译后再二次打包,就成了自己的产品,很是流氓.下面我们来看看如何进行apk的反编译,以及常用的防反编译手段. 一.反编译A ...

  7. mac下反编译android apk

    所需要的工具 http://pan.baidu.com/disk/home#path=%252Fandroid%252Fdecompile%252Fapktool-all apktool用于将资源文件 ...

  8. Mac 下反编译Android APK

    准备工作:安装ApkTool.dex2jar.JD-GUI 安装ApkTool 1.下载ApkTool.大家可以从 https://ibotpeaches.github.io/Apktool/inst ...

  9. 反编译Android的apk包得到源码(使用工具:dex2jar和jd-gui)

    1. 先从 http://download.csdn.net/detail/dingyuming1991/9618125 下载反编译工具dex2jar和jd-gui(当然也可以google搜索下载): ...

随机推荐

  1. 我的第一款windows phone软件

    我的第一个windows phone应用发布成功了,大家支持下,名字叫吕氏春秋,发布人是我的英文名xmfdsh http://www.windowsphone.com/zh-cn/store/app/ ...

  2. UML教程首页(转载)

    UML是一种标准语言,用于指定,可视化,构造和文档的软件系统的文物. UML是OMG在1997年1月提出了创建由对象管理组和UML1.0规范草案. 本教程给出了一个比较完整的学习理解UML,可以方便学 ...

  3. 苹果开发——App内购以及验证store的收据(二)

    原地址:http://zengwu3915.blog.163.com/blog/static/2783489720137605156966?suggestedreading 三. 客户端使用Store ...

  4. POJ 2021 Relative Relatives(map+树的遍历)

    题意: 今天是Ted的100岁生日.凑巧的是,他家族里面每个人都跟他同一天生日,但是年份不同. 现在只给出一些 父亲的名字,孩子的名字,以及孩子出生时父亲的年龄, 要求将Ted以外的家族成员按年龄降序 ...

  5. D&F学数据结构系列——AVL树(平衡二叉树)

    AVL树(带有平衡条件的二叉查找树) 定义:一棵AVL树是其每个节点的左子树和右子树的高度最多差1的二叉查找树. 为什么要使用AVL树(即为什么要给二叉查找树增加平衡条件),已经在我之前的博文中说到过 ...

  6. ida GDB 远程调试

    在看雪上回答的问题,有人问在WinDbg下断KiDebugRoutine或者KdEnterDebugger函数会引发蓝屏!因为是在调试Windows的内核调试引擎,我给出的解决办法是用不依赖Windo ...

  7. Fiddler手机抓包工具如何设置过滤域名?

    fiddler手机抓包工具如何设置过滤域名?如题.fiddler抓包可以完成我们移动开发者的调试测试需求.所以说抓包尤其重要,但是多余的网页请求和手机的其他链接影响我们手机开发的需求.下面我教大家怎么 ...

  8. Appium入门示例(python)

    安装Python依赖 pip3.4 install nose pip3.4 install selenium pip3.4 install Appium-Python-Client 运行测试用例and ...

  9. Java学习笔记之:Java Map集合

    一.介绍 通常来说,Map是一个由键值对组成的数据结构,且在集合中每个键是唯一的. 二.笔记 /** * Map:接口. 不是collection的子类 key -value 键值对 key唯一不能重 ...

  10. delphi中的Label控件背景透明

    Label1.Transparent:=true;你在它的属性窗口把它的Transparent属性改成TRUE就行了 来自为知笔记(Wiz)