Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation and fixed issues #4 and #5. #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# apk2java
A simple Shell script which allows for one stp decompilation of apk file via various decompilers.
A simple Shell script which allows for one step decompilation of apk file via various decompilers. This script was written and tested on Android Tamer project.

## Requirements
Apart from the JRE, following tools should be in your PATH:
* apktool
* enjarify
* jad
* jadx

## Usage
Syntax for running the tool:

```bash
./apk2java <path_to_apk> <path_to_output_dir>
```

Example:

```bash
./apk2java com.whatsapp.apk /tmp/
```

If everything goes fine in above example, this tool will save the source in `/tmp/com.whatsapp.apk_src/` directory. In case the 2nd argument is skipped, the source is saved in current directory.
83 changes: 43 additions & 40 deletions apk2java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# this requires executables besides JRE
# apktool,enjarify,jad, jadx
# Script designed and Tested on Android Tamer (https://androidtamer.com)

echo "APK TO JAVA source code extraction script"
echo "This is a script created by Anant Shrivastava"
echo "http://anantshri.info"
Expand All @@ -10,70 +11,72 @@ echo "This script will work on automating the work of extracting the source code
if [[ $# -eq 0 || $1 == "--help" || $1 == "-help" ]]
then
echo ""
echo "$0 APK_FILE_NAME"
echo "$0 APK_FILE_NAME DESTINATION"
exit
fi
echo "Starting APK Decompile"
echo "[*] Starting APK Decompile"
# JAR KEEP is a variable which allows you to keep jar file converted using dex2jar.
# 0 is off
# 1 is on
JAR_KEEP=1
echo $0 $1
echo "$@"
echo "APK to JAVA/SRC conversion Utility"
APK_NAME=`basename $1`
c=`basename $APK_NAME .apk`
FULL_PTH=`readlink -f $1`
CDIR=`dirname "$FULL_PTH"`
SRC_DIR=$CDIR"/"$APK_NAME"_src/"
SRC_PATH=$CDIR"/"$APK_NAME"_src/"
echo $c
echo $APK_NAME
echo "FULL_PATH"$FULL_PTH
echo "CDIR"$CDIR
if [ $c == `basename $APK_NAME` ]
APK_NAME=`basename "$1"`
c=`basename "$APK_NAME" .apk`
FULL_PTH=`readlink -f "$1"`
APK_DIR_PATH=`dirname "$FULL_PTH"`

if [[ $# -eq 2 ]]
then
if [[ "$2" != /* ]]
then
# Relative path
SRC_DIR="$PWD"/"$2"/"$APK_NAME""_src/"
else
SRC_DIR=$2"/"$APK_NAME"_src/"
fi
else
SRC_DIR="$PWD/$APK_NAME""_src/"
fi

if [[ "$c" == `basename "$APK_NAME"` ]]
then
echo "Only APK's allowed"
echo "[-] Only APK's allowed. Exiting."
exit
fi

#Checks if the file exists.
if [ ! -f "$FULL_PTH" ]
then
echo "File not found."
echo "[-] File not found. Exiting."
exit
fi

echo "Creating Output Directory"
echo "[*] Creating Output Directory"
mkdir -p "$SRC_DIR"
ls -l
echo "Extracting files via APKTool"
apktool decode -f "$CDIR/$APK_NAME" -o "$SRC_DIR"

echo "[*] Extracting files via APKTool"
apktool decode -f "$APK_DIR_PATH/$APK_NAME" -o "$SRC_DIR"

echo "[*] Enjarify for decoding back to java classes."
mkdir -p "$SRC_DIR"jar
# Dex2 JAR was used earlier
#echo "Dex2jar conversion and extraction"
#$PTH/dex2jar.sh $CDIR"/"$APK_NAME
#Removing dex2jar
#d2j-dex2jar.sh $CDIR"/"$APK_NAME
#echo "jar file name is "$c"_dex2jar.jar"
#mv $CDIR"/"$c"_dex2jar.jar" $SRC_DIR"/jar/"
echo "Enjarify for decoding back to java classes"
JAR_FILE=$SRC_DIR"/jar/"$c"_enjarify.jar"
enjarify -f "$CDIR/$APK_NAME" -o "$JAR_FILE"
echo "Decompiling via JADX Decompiler"
JAR_FILE="$SRC_DIR""/jar/""$c""_enjarify.jar"
enjarify -f "$APK_DIR_PATH""/$APK_NAME" -o "$JAR_FILE"

echo "[*] Decompiling via JADX Decompiler"
cd "$SRC_DIR"/jar
mkdir -p ../src/jadx
jadx -d ../src/jadx $SRC_DIR"/jar/"$c"_enjarify.jar"
jar -xf $c"_enjarify.jar"
echo "Source Extraction via JAD from class files"
jadx -d ../src/jadx "$SRC_DIR""/jar/""$c""_enjarify.jar"
jar -xf "$c""_enjarify.jar"

echo "[*] Source Extraction via JAD from class files"
jad -o -r -sjava -d../src/jad './**/*.class'

if [ $JAR_KEEP -eq 0 ]
then
echo "removing jar file"
rm -rf $c"_enjarify.jar"
echo "[*] Removing jar file."
rm -rf "$c""_enjarify.jar"
cd ..
rm -rf ./jar
fi
ls -l "$SRC_DIR"
cd "$CDIR"
echo "All Done"
cd "$APK_DIR_PATH"
echo "[*] All Done"