我们经常会在如下的情况使用反编译
.dex文件简介
dex2jar使用方法(转载自官方):
资源文件反编译
android-apktool简介
android-apktool安装方法
Quick Check
- Apktool 2.x (Versions after 1.5.2)
- Is Java 1.7 installed?
- Does executing java -version on command line / command prompt return 1.7?
- If not, please install Java 7 and make it the default.
- Is Java 1.6 or higher installed?
- Does executing java -version on command line / command prompt return 1.6 or above?
- If not, please install Java 6 or Java 7.
Installation for Apktool 2.x
- Windows:
- Download Windows wrapper script (Right click, Save Link As apktool.bat)
- Download apktool-2 (find newest here)
- Rename downloaded jar to apktool.jar
- Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
- 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.
- Try running apktool via command prompt
- Linux:
- Download Linux 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
- Mac OS X:
- 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
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.