#!/bin/bash # Written by Levente Farkas 2009 # # Simple script to decode a given android rom into a more readable and comparable # format. it's has one argument the unziped rom's directory and create another # diretory with ".source" name and currently do the following: # - unzip the all .apk into a new subdir # - decode the .dex or .odex files (you can choose between dexdump or dedexer # - decode all sqlite3 xml file into a real xml file # - and some minor modification to easier comparable directories if [ $# -lt 1 ]; then echo "Usage: $0 -noxml -dedexer " echo " the result will be placed into .source directory" echo " --noxml xml files won't be decoded" echo " --dedexer dedexer will be used in stead of dexdump" echo "Requirements:" echo "http://android4me.googlecode.com/files/AXMLPrinter2.jar for xml decode" echo "http://dedexer.sourceforge.net/ for dedexer" echo " http://sourceforge.net/projects/dedexer/files/dedexer/1.8/ddx1.8.jar/download" exit 1 fi set -e # ---------------- Change this part if you wanna configure it ---------------- PALTFORM=1.6 # here i assume adb is in your path if not edit the line bellow DEXDUMP=$(dirname `which adb`)/../platforms/android-$PALTFORM/tools/dexdump DDX=~/lib/ddx.jar AXMLPrinter=~/lib/AXMLPrinter2.jar # ---------------------------------------------------------------------------- # $1 = xml file to decode decode_xml() { FTYPE=`file -b $1` if [[ "$FTYPE" =~ "DBase 3" ]]; then java -jar $AXMLPrinter $1 > $1.decode mv $1.decode $1 fi } # decode classes.dex decode_dex() { case $DEDEXER in dexdump) # drop all positions information since it's modified by zipalign $DEXDUMP classes.dex | \ egrep -v "0x.* line=" | \ sed "s/0x31000 (SYNTHETIC VERIFIED OPTIMIZED)/0x30000 (VERIFIED OPTIMIZED)/g" > classes.dedex ;; ddx) java -jar $DDX -d . classes.dex # drop all lines information since it's modified by zipalign find . -name '*.ddx' -exec sed -i "s/^\.line.*/.line xxx/" {} \; ;; *) echo "Unknown dedexer" exit 2 esac rm classes.dex } # $1 = apk or jar file decode_pkg() { DIR=`dirname $1` FILE=`basename $1` APPNAME=${FILE%.*} pushd $DIR &>/dev/null mkdir $APPNAME unzip -d $APPNAME $FILE [ -f $APPNAME.odex ] && mv $APPNAME.odex $APPNAME/classes.dex pushd $APPNAME &>/dev/null [ -f classes.dex ] && decode_dex rm -rf META-INF for xml in `find . -name '*.xml'`; do [ $XML ] && decode_xml $xml done popd &>/dev/null popd &>/dev/null rm $1 } XML=true DEDEXER=dexdump while true; do case $1 in --noxml) XML=false shift ;; --dedexer) DEDEXER=ddx shift ;; *) break ;; esac done rsync -avP --delete $1/ $1.source/ cd $1.source for pkg in `find . -name '*.apk' -o -name '*.jar'` ; do decode_pkg $pkg done # until i find a way to decode:-( find . -name resources.arsc -delete