# Usage: decompile.jar.sh some.jar [-d]
# clean target folders
function clean_target {
rm -rf $unjar $src $jad_log
}
# clean all debug stuff
function clean_stuff {
rm -rf $unjar $jad_log
}
# the main function
function work {
jar=$1
unjar=`basename $jar.unjar`
src=`basename $jar.src`
jad_log=jad.log
clean_target
unzip -q $jar -d $unjar
jad -d $src -ff -r -lnc -o -s java $unjar/**/*.class > $jad_log 2>&1
if [ ! $debug ]; then
clean_stuff
fi
if [ -d $src ]
then
echo "$jar has been decompiled to $src"
else
echo "Got some problems check output or run in debug mode"
fi
}
function usage {
echo "This script extract and decompile JAR file"
echo "Usage: $0 some.jar [-d]"
echo " where: some.jar is the target to decompile"
echo " use -d for debug mode"
}
# check params
if [ -n "$1" ]
then
if [ "$2" == "-d" ]; then
debug=true
set -x
fi
work $1
else
usage
fi