Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Last active July 4, 2018 22:59
Show Gist options
  • Save dweinstein/88e1389dfdc59c7b68e6 to your computer and use it in GitHub Desktop.
Save dweinstein/88e1389dfdc59c7b68e6 to your computer and use it in GitHub Desktop.
tools for deodex android--must download the .jar files separately (smali/baksmali: https://bitbucket.org/JesusFreke/smali/downloads | apktool: https://bitbucket.org/iBotPeaches/apktool/downloads)

A few utilities to help with de-odexing.

You'll need to download baksmali/smali/apktool jars and link/rename the jars as appropriate (e.g., apktool.jar, smali.jar, baksmali.jar) in the directory with these scripts.

You can grab the utilities (currently) from bitucket:

#!/bin/bash
prog="$0"
while [ -h "${prog}" ]; do
newProg=`/bin/ls -ld "${prog}"`
echo ${newProg}
newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
if expr "x${newProg}" : 'x/' >/dev/null; then
prog="${newProg}"
else
progdir=`dirname "${prog}"`
prog="${progdir}/${newProg}"
fi
done
oldwd=`pwd`
progdir=`dirname "${prog}"`
cd "${progdir}"
progdir=`pwd`
prog="${progdir}"/`basename "${prog}"`
cd "${oldwd}"
jarfile=apktool.jar
libdir="$progdir"
if [ ! -r "$libdir/$jarfile" ]
then
echo `basename "$prog"`": can't find $jarfile"
exit 1
fi
javaOpts=""
# If you want DX to have more memory when executing, uncomment the following
# line and adjust the value accordingly. Use "java -X" for a list of options
# you can pass here.
#
javaOpts="-Xmx256M"
# Alternatively, this will extract any parameter "-Jxxx" from the command line
# and pass them to Java (instead of to dx). This makes it possible for you to
# add a command-line parameter such as "-JXmx256M" in your ant scripts, for
# example.
while expr "x$1" : 'x-J' >/dev/null; do
opt=`expr "$1" : '-J\(.*\)'`
javaOpts="${javaOpts} -${opt}"
shift
done
if [ "$OSTYPE" = "cygwin" ] ; then
jarpath=`cygpath -w "$libdir/$jarfile"`
else
jarpath="$libdir/$jarfile"
fi
exec java $javaOpts -jar "$jarpath" "$@"
#!/bin/bash
#
# Copyright (C) 2007 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# As per the Apache license requirements, this file has been modified
# from its original state.
#
# Such modifications are Copyright (C) 2010 Ben Gruver, and are released
# under the original license
# This script is a wrapper around baksmali.jar, so you can simply call
# "baksmali", instead of java -jar baksmali.jar. It is heavily based on
# the "dx" script from the Android SDK
# Set up prog to be the path of this script, including following symlinks,
# and set up progdir to be the fully-qualified pathname of its directory.
prog="$0"
while [ -h "${prog}" ]; do
newProg=`/bin/ls -ld "${prog}"`
echo ${newProg}
newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
if expr "x${newProg}" : 'x/' >/dev/null; then
prog="${newProg}"
else
progdir=`dirname "${prog}"`
prog="${progdir}/${newProg}"
fi
done
oldwd=`pwd`
progdir=`dirname "${prog}"`
cd "${progdir}"
progdir=`pwd`
prog="${progdir}"/`basename "${prog}"`
cd "${oldwd}"
jarfile=baksmali.jar
libdir="$progdir"
if [ ! -r "$libdir/$jarfile" ]
then
echo `basename "$prog"`": can't find $jarfile"
exit 1
fi
javaOpts=""
# If you want DX to have more memory when executing, uncomment the following
# line and adjust the value accordingly. Use "java -X" for a list of options
# you can pass here.
#
javaOpts="-Xmx256M"
# Alternatively, this will extract any parameter "-Jxxx" from the command line
# and pass them to Java (instead of to dx). This makes it possible for you to
# add a command-line parameter such as "-JXmx256M" in your ant scripts, for
# example.
while expr "x$1" : 'x-J' >/dev/null; do
opt=`expr "$1" : '-J\(.*\)'`
javaOpts="${javaOpts} -${opt}"
shift
done
if [ "$OSTYPE" = "cygwin" ] ; then
jarpath=`cygpath -w "$libdir/$jarfile"`
else
jarpath="$libdir/$jarfile"
fi
exec java $javaOpts -jar "$jarpath" "$@"
#!/bin/bash
if [ -z "$1" ]
then
echo "Error: Specify system app to deodex"
exit -1
fi
APP="$1"
TMPDIR=tmp_for_deodex
if [ -z "`which baksmali`" ]
then
echo "Error: Can not find baksmali"
exit -1
fi
if [ -z "`which apktool`" ]
then
echo "Error: Can not find apktool"
exit -1
fi
if [ -z "`which smali`" ]
then
echo "Error: Can not find smali"
exit -1
fi
mkdir -p $TMPDIR || { echo "Failed to mkdir $TMPDIR"; exit -4; }
cd $TMPDIR
echo "Pulling all framework and app files from phone..."
NAME_NOEXT=$(echo -ne "${APP}" | cut -d '.' -f1)
if [ -z "${NAME_NOEXT}" ]
then
echo "Error: couldn't parse app name"
exit -1
fi
#adb pull /system/framework framework
adb pull /system/app/${APP} ${APP}
adb pull /system/app/${NAME_NOEXT}.odex ${NAME_NOEXT}.odex
apktool if framework/framework-res.apk
apktool d -f ${APP} -o ${NAME_NOEXT}
SDK=`echo -n $(aapt d badging ${APP} | grep "targetSdkVersion:" | cut -d ':' -f2 | cut -d "'" -f2) `
echo "SDK: ${SDK}"
baksmali -a ${SDK} -x ${NAME_NOEXT}.odex -d framework -o ${NAME_NOEXT}/smali
apktool b ${NAME_NOEXT}
#jarsigner -sigalg MD5withRSA -digestalg SHA1 -keystore my-release-key.keystore foo.apk my_key
#zipalign 4 ${NAME_NOEXT}-deodexed.apk ${NAME_NOEXT}-deodexed-aligned.apk
#echo "Left all local files at $TMPDIR, and delete it manually if desired"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment