Skip to content

Instantly share code, notes, and snippets.

@EdSergeev
Forked from nstarke/android-decompile.sh
Last active May 14, 2020 07:28
Show Gist options
  • Save EdSergeev/fda65ed5e1734735369852f99ab6c26e to your computer and use it in GitHub Desktop.
Save EdSergeev/fda65ed5e1734735369852f99ab6c26e to your computer and use it in GitHub Desktop.
Android APK Decompile Script
#!/bin/bash
APK=$1
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.4.1.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-1.0.1.Final/jd-cli-1.0.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)/output" ]; then
echo "There is already decompiled output in this directory"
exit 1
fi
# Make output directories
mkdir -p "$(pwd)/output/dex2jar"
mkdir -p "$(pwd)/output/jd-cli"
# Run decompilation tools
# Run apktool to grab resources
$HOME/android-decompile-tools/apktool/apktool d $APK -o "$(pwd)/output/apktool"
# Run dex2jar to disassemble smali
$HOME/android-decompile-tools/dex2jar-2.0/d2j-dex2jar.sh -o "$(pwd)/output/dex2jar/dex2jar-output.jar" $APK
# Run jd-cli to decompile disassembled smali
$HOME/android-decompile-tools/jd-cmd/jd-cli -od "$(pwd)/output/jd-cli" "$(pwd)/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