Last active
June 4, 2021 17:50
-
-
Save cspinetta/f88007249bd54092094443c5cd8dd1eb to your computer and use it in GitHub Desktop.
An script to decompile multiple java classes with CFR Java Decompiler: http://www.benf.org/other/cfr/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# USAGE: ./decompile-java-classes.sh -d {cfr jar} -i {input directory} -n {fiel name pattern} -o {output directory} | |
# Output directory and file name is optional | |
# File name accepts wildcard such as '*' | |
OUTPUTDIR="/tmp/decompiled-classes/" | |
FILE_NAME="*" | |
SCRIPT_USAGE="USAGE: ./decompile-java-classes.sh -d {cfr jar} -i {input directory} -n {fiel name pattern} -o {output directory}" | |
export PROCESSED_FILES=0 | |
while getopts "d:i:o:n:" opt; do | |
case "$opt" in | |
d) | |
DECOMPILER=$OPTARG | |
;; | |
i) | |
INPUTDIR=$OPTARG | |
;; | |
n) | |
FILE_NAME=$OPTARG | |
;; | |
o) | |
OUTPUTDIR=$OPTARG | |
esac | |
done | |
function decompileFile() { | |
decompiler="$1" | |
file=$2 | |
outputdir=$3 | |
java -jar ${decompiler} ${file} --outputdir ${outputdir} | |
returnValue=$? | |
if [ $returnValue -eq 0 ] ; then | |
echo -n "." | |
else | |
return $returnValue | |
fi | |
} | |
export -f decompileFile | |
if [ -z "$INPUTDIR" ] ; | |
then | |
echo "No input directory supplied"; | |
echo $SCRIPT_USAGE; | |
exit 1; | |
elif [ -z "$DECOMPILER" ] ; then | |
echo "No decompiler supplied"; | |
echo $SCRIPT_USAGE; | |
exit 1; | |
else | |
FILES_COUNT=$(find ${INPUTDIR} -type f -name "${FILE_NAME}.class" | wc -l) | |
echo "There are $FILES_COUNT files to process" | |
find ${INPUTDIR} -type f -name "${FILE_NAME}.class" \ | |
-exec bash -c 'decompileFile "$0" "$1" "$2"' ${DECOMPILER} {} ${OUTPUTDIR} \; | |
returnValueFind=$? | |
if [ $returnValueFind -eq 0 ] ; then | |
echo -ne "\nFiles successfully decompiled in '${OUTPUTDIR}'\n\n" | |
else | |
echo -ne "\nCFR Decompile failed =(\n\n" | |
fi | |
exit $returnValueFind; | |
fi |
👍
Minor changes to see on the console the accepted parameters.
find . -type f -name "*.class" -exec bash -c 'java -jar cfr-0.151.jar $0 --outputdir decompiled' {} \;
🤷
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como tarda mucho tiempo cuando procesas muchos archivos, le agregué algunas boludeces que te indica que está procesando, y no que se colgó en alguna decompilación.