-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecompile.sh
More file actions
149 lines (129 loc) · 4.99 KB
/
decompile.sh
File metadata and controls
149 lines (129 loc) · 4.99 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# Function to display banner
show_banner() {
echo "=============================================================================>>>"
echo "
@@@@@@@@ @@@ @@@ @@@@@@@ @@@@@@@ @@@@@@ @@@ @@@ @@@ @@@@@@@ @@@ @@@
@@@@@@@@ @@@@ @@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@@ @@@ @@@@@@@ @@@ @@@
@@! @@!@!@@@ @@! @@@ @@! @@@ @@! @@@ @@! @@!@!@@@ @@! @@! !@@
!@! !@!!@!@! !@! @!@ !@! @!@ !@! @!@ !@! !@!!@!@! !@! !@! @!!
@!!!:! @!@ !!@! @!@ !@! @!@@!@! @!@ !@! !!@ @!@ !!@! @!------!@@!@=============>>>
!!!!!: !@! !!! !@! !!! !!@!!! !@! !!! !!! !@! !!! !!! @!!!==========>>
!!: !!: !!! !!: !!! !!: !!: !!! !!: !!: !!! !!: !: :!!
:!: :!: !:! :!: !:! :!: :!: !:! :!: :!: !:! :!: :!: !:!
:: :::: :: :: :::: :: :: ::::: :: :: :: :: :: :: :::"
echo "==================================================================================>>>"
echo "============================================================================>>"
}
# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Function to decompile using jadx
decompile_jadx() {
if ! command -v jadx &> /dev/null; then
echo "jadx could not be found"
exit 1
fi
jadx -d "$OUTPUT_DIR" "$APK_FILE" || { echo "jadx decompilation failed"; move_jobf; exit 1; }
}
# Function to decompile using apktool
decompile_apktool() {
if ! command -v apktool &> /dev/null; then
echo "apktool could not be found"
exit 1
fi
timeout 300 apktool d -f -o "$OUTPUT_DIR" "$APK_FILE" || { echo "apktool decompilation failed"; move_jobf; exit 1; }
}
# Function to decompile using dex2jar
decompile_dex2jar() {
DEX2JAR_CMD=$(command -v d2j-dex2jar)
if [ -z "$DEX2JAR_CMD" ]; then
echo "dex2jar could not be found"
exit 1
fi
mkdir -p "$OUTPUT_DIR/classes"
$DEX2JAR_CMD --force -o "$OUTPUT_DIR/classes-dex2jar.jar" "$APK_FILE" || { echo "dex2jar conversion failed"; move_jobf; exit 1; }
unzip -o "$OUTPUT_DIR/classes-dex2jar.jar" -d "$OUTPUT_DIR/classes" || { echo "unzip failed"; move_jobf; exit 1; }
}
# Function to decompile using all methods
decompile_all() {
decompile_jadx
decompile_apktool
decompile_dex2jar
}
# Function to search for endpoints
search_endpoints() {
mkdir -p output
OUTPUT_FILE="output/endpoints.txt"
ENDPOINTS_ONLY_FILE="output/endpoints_only.txt"
JSON_FILE="output/endpoints.json"
grep -rEo 'http[s]?://[^"]+|www\.[^"]+|\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' "$OUTPUT_DIR" > "$OUTPUT_FILE"
sort -u "$OUTPUT_FILE" -o "$OUTPUT_FILE"
grep -rEo 'http[s]?://[^"]+|www\.[^"]+|\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' "$OUTPUT_FILE" > "$ENDPOINTS_ONLY_FILE"
sort -u "$ENDPOINTS_ONLY_FILE" -o "$ENDPOINTS_ONLY_FILE"
jq -R -s -c 'split("\n") | map(select(length > 0))' "$OUTPUT_FILE" > "$JSON_FILE"
echo "Endpoints have been extracted to $OUTPUT_FILE, $ENDPOINTS_ONLY_FILE, and $JSON_FILE"
}
# Function to move jobf file to output directory
move_jobf() {
JOBF_FILE=$(find $APK_DIR -type f -name "*.jobf")
if [[ -n $JOBF_FILE ]]; then
mv "$JOBF_FILE" output/
echo "Moved $JOBF_FILE to output directory"
fi
}
# Function to cleanup
cleanup() {
rm -rf "$OUTPUT_DIR"
echo "Cleaned up $OUTPUT_DIR"
}
# Function to display menu
show_menu() {
echo "Choose decompilation method:"
echo "1. jadx"
echo "2. apktool"
echo "3. dex2jar"
echo "4. All methods"
echo "5. Bulk decompile all APKs"
echo "6. List APKs and select one"
read -p "Enter choice [1-6]: " choice
}
# Function to list APKs and select one
select_apk() {
APK_FILES=($APK_DIR/*.apk)
echo "Available APKs:"
for i in "${!APK_FILES[@]}"; do
echo "$((i+1)). ${APK_FILES[$i]}"
done
read -p "Select APK by number: " apk_choice
APK_FILE=${APK_FILES[$((apk_choice-1))]}
}
# Main script execution
show_banner
APK_DIR="apk"
DEFAULT_APK_FILE=$(find $APK_DIR -type f -name "*.apk" | head -n 1)
if [[ -z $DEFAULT_APK_FILE ]]; then
echo "No APK files found in the 'apk' directory."
exit 1
fi
show_menu
if [[ $choice -eq 6 ]]; then
select_apk
OUTPUT_DIR=$(basename "$APK_FILE" .apk)_decompiled
show_menu
else
APK_FILE=$DEFAULT_APK_FILE
OUTPUT_DIR=$(basename "$APK_FILE" .apk)_decompiled
fi
case $choice in
1) decompile_jadx; search_endpoints; move_jobf; cleanup ;;
2) decompile_apktool; search_endpoints; move_jobf; cleanup ;;
3) decompile_dex2jar; search_endpoints; move_jobf; cleanup ;;
4) decompile_all; search_endpoints; move_jobf; cleanup ;;
5) for apk in $APK_DIR/*.apk; do
APK_FILE=$apk; OUTPUT_DIR=$(basename "$APK_FILE" .apk)_decompiled; decompile_all; search_endpoints; move_jobf; cleanup;
done ;;
*) echo "Invalid choice" ; exit 1 ;;
esac