-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkgDroid.sh
244 lines (192 loc) · 6.16 KB
/
pkgDroid.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
GREEN='\033[1;32m'
ORANGE='\033[38;5;214m'
PURPLE='\033[38;5;140m'
PEACH='\033[38;2;255;204;153m'
BLUE='\033[1;34m'
RED='\033[31m'
NC='\033[0m'
print_banner() {
echo "******************************************"
echo "* pkgDroid *"
echo "* The Ultimate Android APK Tool *"
echo "* v1.2.1 *"
echo "* ---------------------------- *"
echo "* by @ImKKingshuk *"
echo "* Github- https://github.com/ImKKingshuk *"
echo "******************************************"
echo
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
ensure_tools_installed() {
local tools=("apktool" "diff" "zipalign" "apksigner" "aapt")
for tool in "${tools[@]}"; do
if ! command_exists "$tool"; then
echo -e "${RED}Error: $tool is not installed.${NC}"
exit 1
fi
done
}
select_apk_file() {
local prompt="$1"
echo -e "${ORANGE}$prompt${NC}"
select apk_file in *.apk; do
if [ -f "$apk_file" ]; then
echo -e "${GREEN}You selected: $apk_file${NC}"
echo ""
sleep 2
echo "$apk_file"
return
else
echo -e "${RED}Invalid selection! Enter the right choice:${NC}"
echo ""
fi
done
}
compare_apks() {
local first_dir="$1"
local second_dir="$2"
local choice="$3"
local log_file="$4"
local output=""
case $choice in
1)
echo -e "${BLUE}Comparing resources...${NC}"
output=$(diff --color=always -r "$first_dir/res" "$second_dir/res")
;;
2)
echo -e "${BLUE}Comparing smali files...${NC}"
output=$(diff --color=always -r "$first_dir/smali" "$second_dir/smali")
;;
3)
echo -e "${BLUE}Comparing manifest files...${NC}"
output=$(diff --color=always -r "$first_dir/AndroidManifest.xml" "$second_dir/AndroidManifest.xml")
;;
4)
echo -e "${BLUE}Comparing everything...${NC}"
output=$(diff --color=always -r "$first_dir" "$second_dir")
;;
*)
echo -e "${RED}Invalid input${NC}"
return 1
;;
esac
if [ -z "$output" ]; then
echo -e "${BLUE}No changes were found${NC}"
else
echo "$output" | tee "$log_file"
echo -e "${GREEN}The comparison result's logs are saved. You can find them here:${NC}"
echo "$log_file"
fi
}
decompile_apk() {
local apk_file="$1"
local output_dir="$2"
echo -e "${GREEN}Decompiling $apk_file...${NC}"
apktool d -f -o "$output_dir" "$apk_file" >/dev/null 2>&1
}
get_apk_info() {
local apk_file="$1"
echo -e "${ORANGE}Information for $apk_file:${NC}"
aapt dump badging "$apk_file" | grep -E "package:|launchable-activity:|application-label:|sdkVersion:|targetSdkVersion:|uses-permission:"
echo ""
}
rebuild_apk() {
local dir="$1"
echo -e "${GREEN}Rebuilding APK from $dir...${NC}"
apktool b "$dir" -o "${dir}_rebuild.apk" >/dev/null 2>&1
echo -e "${GREEN}Rebuilt APK saved as ${dir}_rebuild.apk${NC}"
}
sign_apk() {
local apk_file="$1"
local keystore="$2"
local alias="$3"
local storepass="$4"
local keypass="$5"
echo -e "${GREEN}Signing $apk_file...${NC}"
zipalign -v -p 4 "$apk_file" "${apk_file}_aligned.apk" >/dev/null 2>&1
apksigner sign --ks "$keystore" --ks-key-alias "$alias" --ks-pass pass:"$storepass" --key-pass pass:"$keypass" --out "${apk_file}_signed.apk" "${apk_file}_aligned.apk"
echo -e "${GREEN}Signed APK saved as ${apk_file}_signed.apk${NC}"
}
apk_comparison_menu() {
local first_apk second_apk log_file
first_apk=$(select_apk_file "Please select the first apk file:")
second_apk=$(select_apk_file "Please select the second apk file:")
log_file="$dir/$(date +%Y-%m-%d_%H-%M-%S).log"
decompile_apk "$first_apk" "first_apk_dir"
decompile_apk "$second_apk" "second_apk_dir"
echo -e "${ORANGE}Which changes do you want to compare?${NC}"
echo "1. Resources"
echo "2. Smali"
echo "3. Manifest"
echo "4. Everything"
read -p "Enter your choice: " choice
echo ""
echo -e "${PEACH}Here is the comparison result:${NC}"
compare_apks "first_apk_dir" "second_apk_dir" "$choice" "$log_file"
comparison_result=$?
if [ $comparison_result -eq 0 ]; then
rm -rf first_apk_dir second_apk_dir
fi
}
apk_rebuild_menu() {
local apk_file apk_dir
apk_file=$(select_apk_file "Please select the apk file to rebuild:")
decompile_apk "$apk_file" "apk_rebuild_dir"
rebuild_apk "apk_rebuild_dir"
rm -rf apk_rebuild_dir
}
apk_signing_menu() {
local apk_file keystore alias storepass keypass
apk_file=$(select_apk_file "Please select the apk file to sign:")
read -p "Enter keystore path: " keystore
read -p "Enter keystore alias: " alias
read -sp "Enter keystore password: " storepass
echo ""
read -sp "Enter key password: " keypass
echo ""
sign_apk "$apk_file" "$keystore" "$alias" "$storepass" "$keypass"
}
apk_extraction_menu() {
local apk_file
apk_file=$(select_apk_file "Please select the apk file to extract information from:")
get_apk_info "$apk_file"
}
main_menu() {
while true; do
echo -e "${PURPLE}pkgDroid:${NC}"
echo "1. APK Compare"
echo "2. APK Rebuild"
echo "3. APK Sign"
echo "4. APK Extract"
echo "5. Exit"
read -p "Enter your choice: " main_choice
echo ""
case $main_choice in
1)
apk_comparison_menu
;;
2)
apk_rebuild_menu
;;
3)
apk_signing_menu
;;
4)
apk_extraction_menu
;;
5)
echo -e "${GREEN}Exiting...${NC}"
exit 0
;;
*)
echo -e "${RED}Invalid input. Please enter a number between 1 and 5.${NC}"
;;
esac
done
}
print_banner
ensure_tools_installed
main_menu