-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPKTool_GUI.py
More file actions
291 lines (252 loc) · 12.4 KB
/
APKTool_GUI.py
File metadata and controls
291 lines (252 loc) · 12.4 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import subprocess
import threading
class APKToolGUI:
def __init__(self, master):
self.master = master
self.master.title("APKTool GUI")
# Variables for file paths and options
self.apk_file = tk.StringVar()
self.output_dir = tk.StringVar()
self.recompiled_apk_file = tk.StringVar()
self.apktool_jar_path = tk.StringVar()
self.framework_file = tk.StringVar()
self.recompiled_apk_file.set("recompiled.apk")
# Options for decompiling
self.verbose = tk.BooleanVar()
self.force_overwrite = tk.BooleanVar()
self.no_src = tk.BooleanVar()
self.no_res = tk.BooleanVar()
self.no_xml = tk.BooleanVar()
self.decrypt = tk.BooleanVar()
self.no_decrypt = tk.BooleanVar()
# Options for recompiling
self.recompile_verbose = tk.BooleanVar()
self.recompile_force_overwrite = tk.BooleanVar()
self.recompile_no_src = tk.BooleanVar()
self.recompile_no_res = tk.BooleanVar()
# GUI widgets
# File selection
tk.Label(master, text="APK File:").pack()
self.apk_file_entry = tk.Entry(master, textvariable=self.apk_file)
self.apk_file_entry.pack()
self.browse_apk_button = tk.Button(master, text="Browse", command=self.browse_apk_file)
self.browse_apk_button.pack()
tk.Label(master, text="Output Directory:").pack()
self.output_dir_entry = tk.Entry(master, textvariable=self.output_dir)
self.output_dir_entry.pack()
self.browse_output_dir_button = tk.Button(master, text="Browse", command=self.browse_output_dir)
self.browse_output_dir_button.pack()
tk.Label(master, text="Recompiled APK File:").pack()
self.recompiled_apk_file_entry = tk.Entry(master, textvariable=self.recompiled_apk_file)
self.recompiled_apk_file_entry.pack()
self.browse_recompiled_apk_button = tk.Button(master, text="Browse", command=self.browse_recompiled_apk_file)
self.browse_recompiled_apk_button.pack()
# Options for decompiling
tk.Checkbutton(master, text="Verbose (Decompile)", variable=self.verbose).pack()
tk.Checkbutton(master, text="Force Overwrite (Decompile)", variable=self.force_overwrite).pack()
tk.Checkbutton(master, text="No Source Code (Decompile)", variable=self.no_src).pack()
tk.Checkbutton(master, text="No Resources (Decompile)", variable=self.no_res).pack()
tk.Checkbutton(master, text="No XML Parsing (Decompile)", variable=self.no_xml).pack()
tk.Checkbutton(master, text="No Decryption (Decompile)", variable=self.no_decrypt).pack()
# Framework file for decompiling
tk.Label(master, text="Framework File:").pack()
self.framework_file_entry = tk.Entry(master, textvariable=self.framework_file)
self.framework_file_entry.pack()
self.browse_framework_file_button = tk.Button(master, text="Browse", command=self.browse_framework_file)
self.browse_framework_file_button.pack()
# Options for recompiling
tk.Checkbutton(master, text="Verbose (Recompile)", variable=self.recompile_verbose).pack()
tk.Checkbutton(master, text="Force Overwrite (Recompile)", variable=self.recompile_force_overwrite).pack()
tk.Checkbutton(master, text="No Source Code (Recompile)", variable=self.recompile_no_src).pack()
tk.Checkbutton(master, text="No Resources (Recompile)", variable=self.recompile_no_res).pack()
# APKTool jar path
tk.Label(master, text="APKTool Jar Path:").pack()
self.apktool_jar_path_entry = tk.Entry(master, textvariable=self.apktool_jar_path)
self.apktool_jar_path_entry.pack()
self.browse_apktool_jar_button = tk.Button(master, text="Browse", command=self.browse_apktool_jar)
self.browse_apktool_jar_button.pack()
# Buttons for actions
self.decompile_button = tk.Button(master, text="Decompile APK", command=self.decompile_apk)
self.decompile_button.pack()
self.recompile_button = tk.Button(master, text="Recompile APK", command=self.recompile_apk)
self.recompile_button.pack()
self.view_file_button = tk.Button(master, text="View File", command=self.view_file)
self.view_file_button.pack()
self.edit_file_button = tk.Button(master, text="Edit File", command=self.select_file_to_edit)
self.edit_file_button.pack()
# Status and progress
self.status_label = tk.Label(master, text="Ready")
self.status_label.pack()
self.progress_bar = ttk.Progressbar(master, mode='indeterminate')
self.progress_bar.pack()
# Busy flag to prevent multiple operations
self.is_busy = False
def browse_apk_file(self):
file_path = filedialog.askopenfilename(filetypes=[("APK files", "*.apk")])
if file_path:
self.apk_file.set(file_path)
def browse_output_dir(self):
dir_path = filedialog.askdirectory()
if dir_path:
self.output_dir.set(dir_path)
def browse_recompiled_apk_file(self):
file_path = filedialog.asksaveasfilename(defaultextension=".apk")
if file_path:
self.recompiled_apk_file.set(file_path)
def browse_framework_file(self):
file_path = filedialog.askopenfilename(filetypes=[("APK files", "*.apk")])
if file_path:
self.framework_file.set(file_path)
def browse_apktool_jar(self):
file_path = filedialog.askopenfilename(filetypes=[("JAR files", "*.jar")])
if file_path:
self.apktool_jar_path.set(file_path)
def view_file(self):
# Get the output directory
output_dir = self.output_dir.get()
if not output_dir:
messagebox.showerror("Error", "Please select an output directory first.")
return
# Ask to select a file from that directory
file_path = filedialog.askopenfilename(initialdir=output_dir)
if not file_path:
return
# Open a new window with the file content
view_window = tk.Toplevel(self.master)
view_window.title(f"Viewing {file_path}")
text_widget = tk.Text(view_window)
text_widget.pack()
# Read the file content
try:
with open(file_path, 'r') as f:
content = f.read()
text_widget.insert(tk.END, content)
except Exception as e:
messagebox.showerror("Error", f"Failed to read file: {e}")
def select_file_to_edit(self):
# Get the output directory
output_dir = self.output_dir.get()
if not output_dir:
messagebox.showerror("Error", "Please select an output directory first.")
return
# Ask to select a file from that directory
file_path = filedialog.askopenfilename(initialdir=output_dir)
if not file_path:
return
# Open a new window for editing
edit_window = tk.Toplevel(self.master)
edit_window.title(f"Editing {file_path}")
text_widget = tk.Text(edit_window)
text_widget.pack()
# Read the file content
try:
with open(file_path, 'r') as f:
content = f.read()
text_widget.insert(tk.END, content)
except Exception as e:
messagebox.showerror("Error", f"Failed to read file: {e}")
# Save button
save_button = tk.Button(edit_window, text="Save", command=lambda: self.save_edited_file(text_widget.get("1.0", tk.END), file_path))
save_button.pack()
def save_edited_file(self, new_content, file_path):
try:
with open(file_path, 'w') as f:
f.write(new_content)
except Exception as e:
messagebox.showerror("Error", f"Failed to save file: {e}")
def toggle_controls(self, is_enabled):
state = tk.NORMAL if is_enabled else tk.DISABLED
self.apk_file_entry.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.output_dir_entry.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.recompiled_apk_file_entry.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.browse_apk_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.browse_output_dir_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.browse_recompiled_apk_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.decompile_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.recompile_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.view_file_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
self.edit_file_button.config(state=tk.NORMAL if is_enabled else tk.DISABLED)
def decompile_apk(self):
if not self.is_busy:
# Disable controls
self.toggle_controls(is_enabled=False)
self.is_busy = True
threading.Thread(target=self.decompile_apk_thread).start()
def decompile_apk_thread(self):
# Construct the command for decompiling
if self.apktool_jar_path.get():
command = ["java", "-jar", self.apktool_jar_path.get(), "d", self.apk_file.get(), "-o", self.output_dir.get()]
else:
command = ["apktool", "d", self.apk_file.get(), "-o", self.output_dir.get()]
# Add options
if self.verbose.get():
command.append("-v")
if self.force_overwrite.get():
command.append("--force")
if self.no_src.get():
command.append("--no-src")
if self.no_res.get():
command.append("--no-res")
if self.no_xml.get():
command.append("--no-xml")
if self.decrypt.get():
command.append("--decrypt")
if self.no_decrypt.get():
command.append("--no-decrypt")
if self.framework_file.get():
command.extend(["--system", self.framework_file.get()])
# Show progress
self.status_label.config(text="Decompiling...")
self.progress_bar.start()
try:
subprocess.run(command, check=True)
messagebox.showinfo("Success", "Decompilation completed successfully!")
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Decompilation failed: {e}")
finally:
# Enable controls
self.progress_bar.stop()
self.status_label.config(text="Ready")
self.toggle_controls(is_enabled=True)
self.is_busy = False
def recompile_apk(self):
if not self.is_busy:
# Disable controls
self.toggle_controls(is_enabled=False)
self.is_busy = True
threading.Thread(target=self.recompile_apk_thread).start()
def recompile_apk_thread(self):
# Construct the command for recompiling
if self.apktool_jar_path.get():
command = ["java", "-jar", self.apktool_jar_path.get(), "b", self.output_dir.get(), "-o", self.recompiled_apk_file.get()]
else:
command = ["apktool", "b", self.output_dir.get(), "-o", self.recompiled_apk_file.get]
# Add options
if self.recompile_verbose.get():
command.append("-v")
if self.recompile_force_overwrite.get():
command.append("--force")
if self.recompile_no_src.get():
command.append("--no-src")
if self.recompile_no_res.get():
command.append("--no-res")
# Show progress
self.status_label.config(text="Recompiling...")
self.progress_bar.start()
try:
subprocess.run(command, check=True)
messagebox.showinfo("Success", "Recompilation completed successfully!")
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Recompilation failed: {e}")
finally:
# Enable controls
self.progress_bar.stop()
self.status_label.config(text="Ready")
self.toggle_controls(is_enabled=True)
self.is_busy = False
if __name__ == "__main__":
root = tk.Tk()
app = APKToolGUI(root)
root.mainloop()