Android applications are packed inside a APK file, which is just a ZIP file containing among other things a compact Dalvik Executable (.dex) file.
First step is to extract the “classes.dex” file from the APK:
$ unzip program.apk classes.dex Archive: program.apk inflating: classes.dex
Now, we use the tool dex2jar to convert the classes.dex file to Java .class files:
$ bash dex2jar/dex2jar.sh ./classes.dex version:0.0.7.8-SNAPSHOT 2 [main] INFO pxb.android.dex2jar.v3.Main - dex2jar ./classes.dex -> ./classes.dex.dex2jar.jar Done.
From here we obtain the file “classes.dex.dex2jar.jar”, now we can use the java decompiler JD-GUI to extract the source code:
$ ./jd-gui classes.dex.dex2jar.jar
Now just go to “File -> Save all sources” and it will generate the zip file “classes.dex.dex2jar.src.zip” containing all the decompiled Java source code
To exctract the original “AndroidManifest.xml” from the APK you can use axml2xml or AXMLPrinter.
There is also the ‘aapt’ tool in the SDK which allows to read the manifest from any APK:
$ aapt d xmltree program.apk AndroidManifest.xml
please tell me how to change classes.dex to classes.dex.dex2jar.jar
Also you can use jad (Java Decompiler), for transform .class files into .jad and work with any editor or “understand” application from “sci tools” lab for a better code comprehension.
Regards!
Hi, Great Stuff. I got it working, but can anybody suggest a way . how i can able to get the XML files.(Layouting files).
Thank you
download apktool from google extract to the same file in the apk file. then go to command prompt and select ur folder dirctory then type apktool d filename.apk ./filename
that solve u got xml file and all resource files
@Nandagopal you can automate the whole process and get the XML files by using http://apkdecompile.com
unzip program.apk classes.dex
creates no output. What is the problem?wrong apk file? try renaming it to .zip and see if you can unzip it
When i extract the apk file as you mentioned i got some of unwanted codes and also the original code was slightly modified. How can i resolve this
probably the classes are obfuscated with proguard, as it comes enabled by default on newer versions of the SDK, that’s why you see differences between the original code and the decompiled one.
To make your reversing life easier, you can use programs like sci tools understand as pointed earlier by 0xroot.
Sir, After the de-compilation there is some problem in code… like most of the arguments hav changed into numbers…. So can u pls tell me how to decompile such that there is no such problem….
Hi to all,
I have tried accordingly what u said but i am not getting exact same java file. Is any one getting exact same java file. I used apktool to extract it but got smali file. But got xml file which is correct one but java file is in smali format. I used dex2jar to convert it into jar. And from jar i got the java file but it is not in proper way. There was so many changes. That means i can’t do if i have big project. Is any one can help to how to get java file from apk.
Thanks,
pankaj
Hi.,
Once you downloaded your APK file , You need to do the following steps to get a editable java code/document.
1 -> Convert your apk file to zip (while start your download don’t go with “save” option , just go with “save as” and mention your extension as .zip) by doing like this you may avoid APKTOOL…
2 -> Extract the zip file , there you can find somefilename.dex. so now we need to convert dex -> .class
3 -> To do that, you need “dex2jar”(you can download it from http://code.google.com/p/dex2jar/ , after extracted, in command prompt you have to mention like, [D:\dex2jar-0.09>dex2jar somefile.dex] (Keep in mind that your somefilename.dex must be inside the same folder where you have keep your dex2jar.)
4 -> Download jad from http://www.viralpatel.net/blogs/download/jad/jad.zip and extract it. Once extracted you can see two files like “jad.exe” and “Readme.txt” (sometimes “jad.txt” may there instead of “jad.exe”, so just rename its extension as.exe to run)
5 -> Finally, in command prompt you have to mention like [D:\jad>jad -sjava yourfilename.class] it will parse your class file into editable java document.
Thanks
Please send me your email to discuss the issue.
sanjay
WHEN JAVA DECOMPILER IS MAKING THE ZIP ARHIVE, THE APPLICATION CRUSHES…”jd-gui.exe has encountered a problem and needs to close. We are sorry for the inconvenience.”ANY IDEAS?
AndroChef successfully decompiles obfuscated Java 6 and Java 7 .class and .jar files. It is simple but powerful tool that allows you to decompile Java and Dalvik bytecode (DEX, APK) into readable Java source.
http://www.neshkov.com/ac_decompiler.html
For my project requirement i need to get the Andorid version installed on device(mobile) and also the apk version of perticular application installed on the device. Please help.
Thanks in advance.
when i open the dex2jar.. the command prompt pop-out but it gones fast…
Hello Sir,
i did all what you said but when i run command – bash dex2jar/dex2jar.sh ./classes.dex i got ->
‘bash’ is not recognized as internal or external command, operable program or batch file. what should i do?
If I am not mistaken the screenshots are from a Linux O.S. If you are using Windows, you don’t need to use bash.
Hi,
I want to see XML files and datas in apk file.
it shows data as some decode type.
Please guide me
Thanks in advance.
How to combine source code retrieved from apk.. Plz help me out
Hi!
How to return to .dex file after editing .java source code?
Help please
sir,after the completion of all the steps where can i will see the xml code
Thank you! It works like a charm!