-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
502 lines (420 loc) · 17.2 KB
/
Copy pathGUI.py
File metadata and controls
502 lines (420 loc) · 17.2 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
import sys
import subprocess
import json
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QTextEdit, QLabel, QComboBox, QSpinBox, QLineEdit,
QGridLayout, QGroupBox, QScrollArea, QMessageBox
)
from PyQt6.QtCore import Qt, QThread, pyqtSignal
from PyQt6.QtGui import QFont, QColor
from PyQt6.QtCore import QSize
class ADBCommandWorker(QThread):
"""Worker thread to execute ADB commands without freezing the UI"""
command_output = pyqtSignal(str)
command_error = pyqtSignal(str)
def __init__(self, command):
super().__init__()
self.command = command
def run(self):
try:
# Execute the ADB command and capture output
result = subprocess.run(
self.command,
shell=True,
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
self.command_output.emit(result.stdout if result.stdout else "Command executed successfully!")
else:
self.command_error.emit(result.stderr if result.stderr else f"Command failed with return code {result.returncode}")
except subprocess.TimeoutExpired:
self.command_error.emit("Command timed out (exceeded 30 seconds)")
except Exception as e:
self.command_error.emit(f"Error: {str(e)}")
class AndroidADBShellGUI(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
self.worker = None
def init_ui(self):
"""Initialize the user interface"""
self.setWindowTitle("Android ADB Shell Executor")
self.setGeometry(100, 100, 1200, 800)
self.setStyleSheet("""
QMainWindow {
background-color: #f0f0f0;
}
QPushButton {
background-color: #007bff;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
font-weight: bold;
}
QPushButton:hover {
background-color: #0056b3;
}
QPushButton:pressed {
background-color: #003d82;
}
QGroupBox {
border: 2px solid #007bff;
border-radius: 5px;
margin-top: 10px;
padding-top: 10px;
font-weight: bold;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px 0 3px;
}
QTextEdit {
background-color: #1e1e1e;
color: #00ff00;
font-family: Courier New;
font-size: 10pt;
border: 1px solid #007bff;
border-radius: 4px;
}
QLineEdit {
padding: 5px;
border: 1px solid #007bff;
border-radius: 4px;
}
""")
# Main widget and layout
main_widget = QWidget()
self.setCentralWidget(main_widget)
main_layout = QHBoxLayout(main_widget)
# Left panel - Buttons
left_panel = QWidget()
left_layout = QVBoxLayout(left_panel)
# Scroll area for buttons
scroll_area = QScrollArea()
scroll_area.setWidgetResizable(True)
scroll_widget = QWidget()
scroll_layout = QVBoxLayout(scroll_widget)
# Device Management Group
device_group = self.create_device_group()
scroll_layout.addWidget(device_group)
# Camera Group
camera_group = self.create_camera_group()
scroll_layout.addWidget(camera_group)
# Screen Group
screen_group = self.create_screen_group()
scroll_layout.addWidget(screen_group)
# Installation Group
install_group = self.create_installation_group()
scroll_layout.addWidget(install_group)
# System Info Group
system_group = self.create_system_info_group()
scroll_layout.addWidget(system_group)
# Device Control Group
control_group = self.create_device_control_group()
scroll_layout.addWidget(control_group)
# Custom Command Group
custom_group = self.create_custom_command_group()
scroll_layout.addWidget(custom_group)
scroll_layout.addStretch()
scroll_area.setWidget(scroll_widget)
left_layout.addWidget(scroll_area)
# Right panel - Output
right_panel = QWidget()
right_layout = QVBoxLayout(right_panel)
output_label = QLabel("Command Output:")
output_label.setFont(QFont("Arial", 10, QFont.Weight.Bold))
right_layout.addWidget(output_label)
self.output_text = QTextEdit()
self.output_text.setReadOnly(True)
right_layout.addWidget(self.output_text)
# Clear button
clear_btn = QPushButton("Clear Output")
clear_btn.clicked.connect(self.output_text.clear)
right_layout.addWidget(clear_btn)
# Add panels to main layout
main_layout.addWidget(left_panel, 1)
main_layout.addWidget(right_panel, 1)
self.show()
def create_device_group(self):
"""Create Device Management group box"""
group = QGroupBox("Device Management")
layout = QVBoxLayout()
# List connected devices
list_devices_btn = QPushButton("List Connected Devices")
list_devices_btn.clicked.connect(lambda: self.execute_adb_command("adb devices"))
layout.addWidget(list_devices_btn)
# Get device info
device_info_btn = QPushButton("Get Device Information")
device_info_btn.clicked.connect(lambda: self.execute_adb_command("adb shell getprop"))
layout.addWidget(device_info_btn)
# Reboot device
reboot_btn = QPushButton("Reboot Device")
reboot_btn.clicked.connect(lambda: self.execute_adb_command("adb reboot"))
layout.addWidget(reboot_btn)
# Reboot to bootloader
bootloader_btn = QPushButton("Reboot to Bootloader")
bootloader_btn.clicked.connect(lambda: self.execute_adb_command("adb reboot bootloader"))
layout.addWidget(bootloader_btn)
# Reboot to recovery
recovery_btn = QPushButton("Reboot to Recovery")
recovery_btn.clicked.connect(lambda: self.execute_adb_command("adb reboot recovery"))
layout.addWidget(recovery_btn)
group.setLayout(layout)
return group
def create_camera_group(self):
"""Create Camera Control group box"""
group = QGroupBox("Camera Control")
layout = QVBoxLayout()
# Open camera
open_camera_btn = QPushButton("📷 Open Camera")
open_camera_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell am start -a android.media.action.IMAGE_CAPTURE"
))
layout.addWidget(open_camera_btn)
# Open video recorder
video_recorder_btn = QPushButton("🎥 Open Video Recorder")
video_recorder_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell am start -a android.media.action.VIDEO_CAPTURE"
))
layout.addWidget(video_recorder_btn)
# List cameras
list_cameras_btn = QPushButton("List Cameras")
list_cameras_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell pm list features | grep camera"
))
layout.addWidget(list_cameras_btn)
group.setLayout(layout)
return group
def create_screen_group(self):
"""Create Screen Control group box"""
group = QGroupBox("Screen Control")
layout = QVBoxLayout()
# Take screenshot
screenshot_btn = QPushButton("📸 Take Screenshot")
screenshot_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell screencap -p /sdcard/screenshot.png && adb pull /sdcard/screenshot.png"
))
layout.addWidget(screenshot_btn)
# Record screen
record_btn = QPushButton("🎬 Record Screen (10 sec)")
record_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell screenrecord --time-limit=10 /sdcard/recording.mp4 && adb pull /sdcard/recording.mp4"
))
layout.addWidget(record_btn)
# Turn on screen
screen_on_btn = QPushButton("Turn Screen On")
screen_on_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell input keyevent 224"
))
layout.addWidget(screen_on_btn)
# Turn off screen
screen_off_btn = QPushButton("Turn Screen Off")
screen_off_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell input keyevent 223"
))
layout.addWidget(screen_off_btn)
# Lock screen
lock_btn = QPushButton("Lock Screen")
lock_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell input keyevent 26"
))
layout.addWidget(lock_btn)
group.setLayout(layout)
return group
def create_installation_group(self):
"""Create App Installation group box"""
group = QGroupBox("App Installation")
layout = QVBoxLayout()
# List installed packages
list_apps_btn = QPushButton("List Installed Apps")
list_apps_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell pm list packages"
))
layout.addWidget(list_apps_btn)
# Install APK (requires file path)
install_layout = QHBoxLayout()
self.apk_path_input = QLineEdit()
self.apk_path_input.setPlaceholderText("Path to APK file")
install_layout.addWidget(self.apk_path_input)
install_apk_btn = QPushButton("Install APK")
install_apk_btn.clicked.connect(self.install_apk)
install_layout.addWidget(install_apk_btn)
layout.addLayout(install_layout)
# Uninstall app (requires package name)
uninstall_layout = QHBoxLayout()
self.package_name_input = QLineEdit()
self.package_name_input.setPlaceholderText("Package name (e.g., com.example.app)")
uninstall_layout.addWidget(self.package_name_input)
uninstall_btn = QPushButton("Uninstall App")
uninstall_btn.clicked.connect(self.uninstall_app)
uninstall_layout.addWidget(uninstall_btn)
layout.addLayout(uninstall_layout)
# Clear app cache
clear_cache_layout = QHBoxLayout()
self.cache_package_input = QLineEdit()
self.cache_package_input.setPlaceholderText("Package name")
clear_cache_layout.addWidget(self.cache_package_input)
clear_cache_btn = QPushButton("Clear App Cache")
clear_cache_btn.clicked.connect(self.clear_app_cache)
clear_cache_layout.addWidget(clear_cache_btn)
layout.addLayout(clear_cache_layout)
group.setLayout(layout)
return group
def create_system_info_group(self):
"""Create System Information group box"""
group = QGroupBox("System Information")
layout = QVBoxLayout()
# Get Android version
version_btn = QPushButton("Get Android Version")
version_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell getprop ro.build.version.release"
))
layout.addWidget(version_btn)
# Get device model
model_btn = QPushButton("Get Device Model")
model_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell getprop ro.product.model"
))
layout.addWidget(model_btn)
# Get battery info
battery_btn = QPushButton("Get Battery Info")
battery_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell dumpsys battery"
))
layout.addWidget(battery_btn)
# Get storage info
storage_btn = QPushButton("Get Storage Info")
storage_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell df -h"
))
layout.addWidget(storage_btn)
# Get memory info
memory_btn = QPushButton("Get Memory Info")
memory_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell free -h"
))
layout.addWidget(memory_btn)
group.setLayout(layout)
return group
def create_device_control_group(self):
"""Create Device Control group box"""
group = QGroupBox("Device Control")
layout = QVBoxLayout()
# Open settings
settings_btn = QPushButton("⚙️ Open Settings")
settings_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell am start -a android.settings.SETTINGS"
))
layout.addWidget(settings_btn)
# Open home
home_btn = QPushButton("🏠 Go Home")
home_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell input keyevent 3"
))
layout.addWidget(home_btn)
# Open recent apps
recent_btn = QPushButton("📱 Open Recent Apps")
recent_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell input keyevent 187"
))
layout.addWidget(recent_btn)
# Clear all notifications
clear_notif_btn = QPushButton("Clear Notifications")
clear_notif_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell service call notification 1"
))
layout.addWidget(clear_notif_btn)
# Enable WiFi
wifi_on_btn = QPushButton("Enable WiFi")
wifi_on_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell svc wifi enable"
))
layout.addWidget(wifi_on_btn)
# Disable WiFi
wifi_off_btn = QPushButton("Disable WiFi")
wifi_off_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell svc wifi disable"
))
layout.addWidget(wifi_off_btn)
# Enable Bluetooth
bt_on_btn = QPushButton("Enable Bluetooth")
bt_on_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell service call bluetooth_manager 6"
))
layout.addWidget(bt_on_btn)
# Disable Bluetooth
bt_off_btn = QPushButton("Disable Bluetooth")
bt_off_btn.clicked.connect(lambda: self.execute_adb_command(
"adb shell service call bluetooth_manager 8"
))
layout.addWidget(bt_off_btn)
group.setLayout(layout)
return group
def create_custom_command_group(self):
"""Create Custom Command group box"""
group = QGroupBox("Custom Command")
layout = QVBoxLayout()
self.custom_command_input = QLineEdit()
self.custom_command_input.setPlaceholderText("Enter custom ADB command (e.g., adb shell ls /sdcard)")
layout.addWidget(self.custom_command_input)
execute_btn = QPushButton("Execute Custom Command")
execute_btn.clicked.connect(self.execute_custom_command)
layout.addWidget(execute_btn)
group.setLayout(layout)
return group
def execute_adb_command(self, command):
"""Execute an ADB command in a separate thread"""
self.output_text.append(f"\n{'='*60}\n>>> Executing: {command}\n{'='*60}\n")
self.worker = ADBCommandWorker(command)
self.worker.command_output.connect(self.on_command_output)
self.worker.command_error.connect(self.on_command_error)
self.worker.start()
def execute_custom_command(self):
"""Execute a custom command from the input field"""
command = self.custom_command_input.text().strip()
if command:
self.execute_adb_command(command)
self.custom_command_input.clear()
else:
self.on_command_error("Please enter a command to execute")
def install_apk(self):
"""Install an APK file"""
apk_path = self.apk_path_input.text().strip()
if apk_path:
command = f"adb install \"{apk_path}\""
self.execute_adb_command(command)
else:
self.on_command_error("Please enter the APK file path")
def uninstall_app(self):
"""Uninstall an app by package name"""
package_name = self.package_name_input.text().strip()
if package_name:
command = f"adb uninstall {package_name}"
self.execute_adb_command(command)
else:
self.on_command_error("Please enter the package name")
def clear_app_cache(self):
"""Clear app cache"""
package_name = self.cache_package_input.text().strip()
if package_name:
command = f"adb shell pm clear {package_name}"
self.execute_adb_command(command)
else:
self.on_command_error("Please enter the package name")
def on_command_output(self, output):
"""Handle successful command output"""
self.output_text.append(f"✓ {output}\n")
def on_command_error(self, error):
"""Handle command error"""
self.output_text.append(f"✗ ERROR: {error}\n")
def main():
app = QApplication(sys.argv)
gui = AndroidADBShellGUI()
sys.exit(app.exec())
if __name__ == "__main__":
main()