Categories
Android macOS Technology

Reverse Engineering — Decompiling APK Packages

Once sometimes we want to know the information inside an apk (Android application package) file. Apk files are Android Package files that are saved in zip format. But when we unzip the file, we can’t see the details of xml files and its resources (shows garbled content). Hence, we need some tools to help us decompile the package.

For Mac users there are three tools we can use to examine the contents of an apk file:

  • ApkTool: extract xml files, AndroidManifest.xml, and some pictures.
  • dex2jar: convert dex files back to jar files.
  • JD-GUI: A GUI to browse the jar files contents that we converted.

ApkTool

If you only want to examine xml files, this tool can help you conveniently. You can install the ApkTool from their site and follow the installation guide they provided.

  • Download Mac wrapper script (Right click, Save Link As apktool).
  • Download apktool-2 (find newest here) and rename it to apktool.jar.
  • Move both files (apktool.jar & apktool) to /usr/local/bin (root passoword needed).
  • Make sure both files are executable:
    • chmod +x apktool
    • chmod +x apktool.jar
  • Try running apktool in terminal. You will see the usage information in the output.

Now you can extract the xml information by command:

# move to your working directory
cd ~/work_directory

# decompile
apktool d xxx.apk

This action will generate a folder at your working directory with the same name as your apk file. You can browse the resources and xml files in that folder using “Finder”.

dex2jar

If you want to see the source code in the apk file, you need to convert dex files back to jar files. And dex2jar is the right tool to accomplish that. You can download this package from the official GitHub release site. After downloaded, follow the process to use it:

# Unzip the downloaded file
unzip dex-tools-2.0.zip

# In case there will be a permission issue, add execution permission to d2j_invoke.sh
chmod +x dex2jar-2.0/d2j_invoke.sh

# Prepare the dex files you want to decompile (you can get them by unzipping the apk files)
unzip xxx.apk

# Start decompiling
sh dex2jar-2.0/d2j-dex2jar.sh xxx/class.dex

At this point, you will get the jar file along with the source codes where you execute the commands. You may need the tool introduced in the next section to show the source codes in it.

JD-GUI

This GUI application is a tool to display Java source codes of “.class” files that we just decompiled. You can download this tool from the official site.

After downloading the compressed archive, we need to extract the actual file:

tar -xzvf jd-gui-osx-1.6.6.tar

Now, you can double click on the extracted file and drag the decompiled jar file into JD-GUI’s window to view the source codes.

By 533

♥️•🏊•💪🏻 •🐈•📷
•IG: @53333_ @xᴜɴxᴜɴ_ɢʀᴀᴄᴇ
•TW: @SimonNg533

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.