Skip to content

Instantly share code, notes, and snippets.

@mustafakibar
Forked from nstarke/android-decompile.sh
Created January 29, 2020 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafakibar/8f53e340ed72729763dd8365423bea5e to your computer and use it in GitHub Desktop.
Save mustafakibar/8f53e340ed72729763dd8365423bea5e to your computer and use it in GitHub Desktop.
Android APK Decompile Script
#!/bin/bash
APK=$1
# Linux only right now.
if [ ! -d "$HOME/.android-decompile-tools" ]; then
mkdir "$HOME/.android-decompile-tools"
fi
# Install apktool
# https://ibotpeaches.github.io/Apktool/install/
if [ ! -d "$HOME/.android-decompile-tools/apktool" ]; then
# make directory for apktool
mkdir "$HOME/.android-decompile-tools/apktool"
# Grab wrapper script
wget "https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool" -O "$HOME/.android-decompile-tools/apktool/apktool"
# Grab JAR
wget "https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.2.0.jar" -O "$HOME/.android-decompile-tools/apktool/apktool.jar"
# Make both files executable as per instructions
chmod +x $HOME/.android-decompile-tools/apktool/*
fi
# Install dex2jar
# https://github.com/pxb1988/dex2jar
if [ ! -d "$HOME/.android-decompile-tools/dex2jar-2.0" ]; then
# Grab zip release
wget "https://github.com/pxb1988/dex2jar/releases/download/2.0/dex-tools-2.0.zip" -O "/tmp/dex-tools.zip"
# Unzip release
unzip "/tmp/dex-tools.zip" -d "$HOME/.android-decompile-tools"
# Clean up zip release
rm "/tmp/dex-tools.zip"
# Make all sh files executable
chmod +x $HOME/.android-decompile-tools/dex2jar-2.0/*.sh
fi
# Install JD-CMD
# https://github.com/kwart/jd-cmd
if [ ! -d "$HOME/.android-decompile-tools/jd-cmd" ]; then
# Make directory
mkdir "$HOME/.android-decompile-tools/jd-cmd"
# Get final release
wget "https://github.com/kwart/jd-cmd/releases/download/jd-cmd-0.9.1.Final/jd-cli-0.9.1.Final-dist.tar.gz" -O "/tmp/jd-cli.tar.gz"
# untar final release
tar xzf "/tmp/jd-cli.tar.gz" -C "$HOME/.android-decompile-tools/jd-cmd"
# rm final release
rm "/tmp/jd-cli.tar.gz"
fi
if [ -d "$(pwd)/android-decompiled-output" ]; then
echo "There is already decompiled output in this directory"
exit 1
fi
# Make output directories
mkdir -p "$(pwd)/android-decompiled-output/dex2jar"
mkdir -p "$(pwd)/android-decompiled-output/jd-cli"
# Run decompilation tools
# Run apktool to grab resources
$HOME/.android-decompile-tools/apktool/apktool d $APK -o "$(pwd)/android-decompiled-output/apktool"
# Run dex2jar to disassemble smali
$HOME/.android-decompile-tools/dex2jar-2.0/d2j-dex2jar.sh -o "$(pwd)/android-decompiled-output/dex2jar/dex2jar-output.jar" $APK
# Run jd-cli to decompile disassembled smali
$HOME/.android-decompile-tools/jd-cmd/jd-cli -od "$(pwd)/android-decompiled-output/jd-cli" "$(pwd)/android-decompiled-output/dex2jar/dex2jar-output.jar"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment