-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursiveDecompile.sh
63 lines (52 loc) · 1.68 KB
/
recursiveDecompile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
doMagic()
{
FILE_NAME=$(basename -- "$1")
FILE_EXTENSION="${FILE_NAME##*.}"
FILE_NAME="${FILE_NAME%.*}"
ARCHIVE_DIRECTORY=$(dirname "$1")
ARCHIVE_OUTPUT_DIRECTORY="$ARCHIVE_DIRECTORY/$FILE_NAME"
FILE_TYPE_MATCH="FALSE"
JAVA_CLASS_TYPES=( "class" )
for fileType in "${JAVA_CLASS_TYPES[@]}"
do
if [[ $1 =~ \.$fileType ]]; then
echo JAVA_CLASS "$1"
java -jar jd-cli.jar -dm -rn -n -od "$ARCHIVE_OUTPUT_DIRECTORY" "$1"
echo "Decompiled $1 to $ARCHIVE_OUTPUT_DIRECTORY"
return
fi
done
JAVA_ARCHIVE_TYPES=( "war" "jar" )
for fileType in "${JAVA_ARCHIVE_TYPES[@]}"
do
if [[ $1 =~ \.$fileType ]]; then
echo JAVA_ARCHIVE "$1"
java -jar jd-cli.jar -dm -rn -n -od "$ARCHIVE_OUTPUT_DIRECTORY" "$1"
echo "Decompiled $1 to $ARCHIVE_OUTPUT_DIRECTORY"
searchDirectory "$ARCHIVE_OUTPUT_DIRECTORY"
return
fi
done
COMPRESSED_ARCHIVE_TYPES=( "zip" "gz" )
for fileType in "${COMPRESSED_ARCHIVE_TYPES[@]}"
do
if [[ $1 =~ \.$fileType ]]; then
echo COMPRESSED_ARCHIVE "$1"
unzip -o -q "$1" -d "$ARCHIVE_OUTPUT_DIRECTORY"
echo "Decompiled $1 to $ARCHIVE_OUTPUT_DIRECTORY"
searchDirectory "$ARCHIVE_OUTPUT_DIRECTORY"
return
fi
done
}
searchDirectory()
{
FILE_EXTENSIONS=( "zip" "gz" "war" "jar" "class" )
for fileType in "${FILE_EXTENSIONS[@]}"
do
find "$1" -name "*.$fileType" -print -type f -exec bash -c 'doMagic "$0"' {} \;
done
}
export -f doMagic
export -f searchDirectory
searchDirectory "$1"