Android documentation decompile
Made by Li Wendong [email protected]
2010-12-13 Monday in Beijing
A, decompile flowchart
Second, tools to use (command)
Suppose I am working directory for the $ AndroidDecompile, first of all to system.img in (or compiled from source code) of several important odex files are copied to the working directory, they are: core.odex, ext.odex, framework . odex, android.policy.odex, services.odex (also can be placed in another directory, by setting BOOTCLASSPATH specified, the default is the current directory, please refer to baksmali on BOOTCLASSPATH help information.)
Download the following tools to $ AndroidDecompile in:
JD-GUI (Java Decompile GUI):
http://java.decompiler.free.fr/?q=jdgui <!--[ if! supportNestedAnchors ]--><!--[ endif] ->
Suppose we have an application, compile the class file after it took out alone, that there are two files app.apk and app.odex, place them on the next $ AndroidDecompile.
1. Odex file using baksmali.jar the document is divided into smali
$ Java-jar baksmali-1.2.5.jar-x app.odex
If successful, will generate a $ AndroidDecompile out directory, which are to ". Smali" for the file name suffix, in this role does not go into these files.
2. Use smali.jar the out / directory smali files into classes.dex
$ Java-Xmx512M-jar smali-1.2.5.jar out-o classes.dex
classes.dex Dalvik VM is used in the compiled class file format, in the normal apk file will have.
3. Use dex2jar classes.dex decompiled the jar file
After the download dex2jar compressed codecs, which will have dex2jar.sh (and dex2jar.bat) files, documents and dex2jar.sh if classes.dex in the same directory, use the following ways classes.dex decompiled jar File:
$ Dex2jar.sh classes.dex
If successful, it will generate in the current directory, compiled files anti-classes.dex.dex2jar.jar.
dex2jar dex files that can be manipulated, you can directly manipulate apk file, it uses rules:
dex2jar file1.dexORapk file2.dexORapk ...
4. Using the JD-GUI view the anti-compiled jar file
JD-GUI is a visual Java decompiler code viewer, it can be real-time anti-compiled java class file to view the file. Jd-gui extract the downloaded file, perform directory jd-gui executable file to start and then load the previous step in the anti-compiled classes.dex.dex2jar.jar files.
5. From odex classes.dex anti-compiled files and other resources re-packaged into a complete apk
We assume that the above situation is the application compiled class files from apk file is stripped out, here is how to do the steps above to get the classes.dex and apk file in other re-packaged into a usable apk.
First, the anti-compiled classes.dex and original app.apk (excluding classes.dex) re-compressed into a complete app.apk (apk file compression tools available to open), into the app that will classes.dex . apk in.
Unzip the downloaded file AutoSign, you can see signapk.jar (there are a Sign.bat) file, execute the following command to app.apk file signature, to generate a working apk file.
$ Java-jar signapk.jar testkey.x509.pem testkey.pk8 app.apk app_signed.apk
6. Apktool use
There is a tool the Internet is apktool, apk can be resolved, de-compile the resource file, and parse the class file into smali documents; while the files can be parsed into a re-packaged apk. Several features and tools described above is similar to its use as follows:
apktool d app.apk and decompile app.apk to the folder and
apktool b app from the app folder, re-APK, output to ABC \ dist \ out.apk
The specific use will not go, please refer to the official website, or:
7. My $ AndroidDecompile screenshot files directory
Third, a number of tools to help information
1. Baksmali help information
usage: java-jar baksmali.jar [options] <dex-file>
disassembles and / or dumps a dex file
-?,-- Help Prints the help message then exits.
-B, - no-debug-info Specify twice for debug options
don't write out debug info (. local,
. Param,. Line, etc.)
-C, - bootclasspath <BOOTCLASSPATH> The bootclasspath jars to use, for
analysis. Defaults to
core.jar: ext.jar: framework.jar: andro
id.policy.jar: services.jar. If the
value begins with a:, it will be
appended to the default
bootclasspath instead of replacing it
-D, - bootclasspath-dir <DIR> The base folder to look for the
bootclasspath files in. Defaults to
the current directory
-F, - code-offsets Add comments to the disassembly
containing the code offset for each address
-L, - use-locals Output the. Locals directive with
the number of non-parameter
registers, rather than the. register
-O, - output <DIR> Directive with the total number of register
the directory where the disassembled
files will be placed. The default is out
-P, - no-parameter-registers Use the v <n> syntax instead of the
p <n> syntax for registers mapped to
-R, - register-info <REGISTER_INFO_TYPES> Print the specificed type (s) of
register information for each
instruction. "ARGS, DEST" is the
default if no types are specified.
Valid values are:
ALL: all pre-and post-instruction registers.
ALLPRE: all pre-instruction registers
ALLPOST: all post-instruction registers
ARGS: any pre-instruction registers
used as arguments to the instruction
DEST: the post-instruction
destination register, if any
MERGE: Any pre-instruction register
has been merged from more than 1
different post-instruction register
from its predecessors
FULLMERGE: For each register that
would be printed by MERGE, also show
the incoming register types that
-S, - sequential-labels Create label names using a
sequential numbering scheme per
label type, rather than using the
-V, - version Prints the version then exits
-X, - deodex Deodex the given odex file. This
option is ignored if the input file
is not an odex file
2. Smali help information
usage: java-jar smali.jar [options] [-] [<smali-file> | folder] *
assembles a set of smali files into a dex file
-?,-- Help prints the help message then exits. Specify twice for
-O, - output <FILE> the name of the dex file that will be written. The default
-V, - version prints the version then exits
3. Auto-sign with the help of information
SignApk.jar is a tool included with the Android platform source bundle.
testkey.pk8 is the private key that is compatible with the recovery image included in this zip file
testkey.x509.pem is the corresponding certificate / public key
java-jar signapk.jar testkey.x509.pem testkey.pk8 update.zip update_signed.zip
4. Apktool help information
Apktool v1.3.2 - a tool for reengineering Android apk files
Copyright 2010 Ryszard Wi? Niewski <[email protected]>
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Usage: apktool [-v | - verbose] COMMAND [...]
d [ecode] [OPTS] <file.apk> [<dir>]
Decode <file.apk> to <dir>.
-S, - no-src
Do not decode sources.
-R, - no-res
Do not decode resources.
-D, - debug
Decode in debug mode. Check project page for more info.
-F, - force
Force delete destination directory.
-T <tag>, - frame-tag <tag>
Try to use framework files tagged by <tag>.
Use if there was an error and some resources were dropped, eg:
"Invalid config flags detected. Dropping resources", but you
want to decode them anyway, even with errors. You will have to
fix them manually before building.
b [uild] [OPTS] [<app_path>] [<out_file>]
Build an apk from already decoded application located in <app_path>.
It will automatically detect, whether files was changed and perform
needed steps only.
If you omit <app_path> then current directory will be used.
If you omit <out_file> then <app_path> / dist / <name_of_original.apk>
will be used.
-F, - force-all
Skip changes detection and build all files.
-D, - debug
Build in debug mode. Check project page for more info.
if | install-framework <framework.apk> [<tag>]
Install framework file to your system.
Additional info for, See: http://code.google.com/p/android-apktool/