How to Decompile an Android .Apk File

Is there a way to get the source code from an APK file?

Simple way: use online tool https://www.decompiler.com/, upload apk and get source code.


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

Step 1:

  1. Make a new folder and copy over the .apk file that you want to decode.

  2. Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.

Step 2:

  1. Now extract this .zip file in the same folder (or NEW FOLDER).

  2. Download dex2jar (Don't download the code, click on the releases button that's on the right then download that) and extract it to the same folder (or NEW FOLDER).

  3. Move the classes.dex file into the dex2jar folder.

  4. Now open command prompt and change directory to that folder (or NEW FOLDER). Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex) and press enter. You now have the classes.dex.dex2jar file in the same folder.

  5. Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.

  6. Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.

Step 3:

Now open another new folder

  1. Put in the .apk file which you want to decode

  2. Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder

  3. Open a command window

  4. Now run command like apktool if framework-res.apk (if you don't have it get it here)and next

  5. apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)

now you get a file folder in that folder and can easily read the apk's xml files.

Step 4:

It's not any step, just copy contents of both folders(in this case, both new folders) to the single one

and enjoy the source code...

How to decompile an APK or DEX file on Android platform?

You need Three Tools to decompile an APK file.

  1. Dex2jar - Tools to work with android .dex and java .class files

  2. ApkTool - A tool for reverse engineering Android apk files

  3. JD-GUI - Java Decompiler is a tools to decompile and analyze Java 5 “byte code” and the later versions.

for more how-to-use-dextojar. Hope this will help You and all! :)

Is it possible to decompile an Android .apk file?

First, an apk file is just a modified jar file. So the real question is can they decompile the dex files inside. The answer is sort of. There are already disassemblers, such as dedexer and smali. You can expect these to only get better, and theoretically it should eventually be possible to decompile to actual Java source (at least sometimes). See the previous question decompiling DEX into Java sourcecode.

What you should remember is obfuscation never works. Choose a good license and do your best to enforce it through the law. Don't waste time with unreliable technical measures.

Is there a way to decompile multiple android apk at the same time?

This should be fairly easy to do with the standard "find" tool.

cd directory_with_apks
find . -iname "*.apk" -exec apktool d -o {}_out {} \;

Reverse engineering from an APK file to a project

There are two useful tools which will generate Java code (rough but good enough) from an unknown APK file.

  1. Download dex2jar tool from dex2jar.

  2. Use the tool to convert the APK file to JAR:
    Windows:

     $ d2j-dex2jar.bat demo.apk
    dex2jar demo.apk -> ./demo-dex2jar.jar

    MacOS / Linux:

     $ d2j-dex2jar.sh -f demo.apk -o demo.jar
  3. Once the JAR file is generated, use JD-GUI to open the JAR file. You will see the Java files.

The output will be similar to:

JD GUI

Then you can use other tools to retrieve the AndroidManifest.xml and resource files (like images, translations, etc...) from the APK file.

  • Apktool

     $ java -jar apktool.jar -q decode -f demo.apk -o outputDir
  • AXMLParser

     $ apkinfo demo.apk
  • NinjaDroid

     $ ninjadroid demo.apk --all --extract

Android - How to decode and decompile any APK file?

To decompile APK Use APKTool.

You can learn how APKTool works on http://www.decompileandroid.com/ or by reading the documentation.

How to correctly re-compile an apk file?

The following is for your reference


Compile, decompile and sign APK using apktool utility.

  1. Download latest apktool version.

  2. Download the batch file and aapt.exe.

  3. Create a folder anywhere in the PC and put all the apktool.jar, aapt.exe and the batch script in that folder.

  4. Open command prompt.

  5. Navigate to the folder where you placed apktool.jar, batch script and the aapt.exe.

  6. Now, you need to install the file using the " IF " command.

  7. Type the following command.

    apktool if name-of-the-app.apk

  8. For decompiling use the command "d". The "d" stands for decompile.

    apktool d name-of-the-app.apk

  9. After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mode's.

  10. To recompile the app use the following command " B ". The "b" simply means recompile.

    apktool b name-of-the-app-folder

  11. The final modded app will be in the "dist" folder located inside the original app folder created by apktool.

Signing the apk

  1. open a new command prompt and change into the sign-apk directory using cmd

  2. move the modified-unsigned apk into this folder

  3. then type the following command -

    java -jar signapk.jar certificate.pem key.pk8 path-of-the-folder-contaning-the-apk.apk path-of-the-new-signed-apk.apk

  4. Once compiled, the signed apk will be found in the same folder.

How to Decompiling Apk files that Generated By Android Studio

To decompile the XML files you can use the following tools:

  1. JadX - https://github.com/skylot/jadx
  2. Apktool - https://github.com/iBotPeaches/Apktool

Remember the apktool which you are using is probably a very old version. Download the latest version of apktool.jar from https://github.com/iBotPeaches/Apktool/releases/download/2.1.1/apktool_2.1.1.jar

Below are the two process through which you can get the xml files.

Apktool Method:

  1. Download the latest apktool jar from https://github.com/iBotPeaches/Apktool/releases/download/2.1.1/apktool_2.1.1.jar
  2. Run it using java -jar apktool.jar d <apkfile.apk> without the angular brackets and substituting apkfile.apk with the actual path to the apk file

Jadx method:

  1. Download the latest release of jadx from https://github.com/skylot/jadx/releases
  2. Unzip the file and then goto bin/ folder
  3. Windows user can double click the jadx-gui.bat file
  4. Linux/Mac users can run the shell script ./jadx-gui
  5. This will open jadx gui through which you can open the apk file.

Reference: Jadx open dialogue

Sample Image



Related Topics



Leave a reply



Submit