-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_debugger.py
More file actions
80 lines (63 loc) · 3.43 KB
/
ui_debugger.py
File metadata and controls
80 lines (63 loc) · 3.43 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
import subprocess
import xml.etree.ElementTree as ET
import cv2
# Function to extract bounds from the node attributes
def extract_bounds(node):
bounds_str = node.get("bounds")
if bounds_str:
bounds_str = bounds_str.replace("[", "").replace("]", ",")
bounds = [int(coord) for coord in bounds_str.strip(",").split(",")]
return bounds
return None
# Set to keep track of processed bounds
processed_bounds = set()
while True:
result = subprocess.run('adb devices', shell=True, capture_output=True, text=True)
devices_info = result.stdout.strip().split('\n')[1:]
if len(devices_info) > 0:
device_id = devices_info[0].split('\t')[0]
# Command to capture UI hierarchy
ui_capture_command = f'adb -s {device_id} shell uiautomator dump /sdcard/snapchat_ui.xml'
subprocess.run(ui_capture_command, shell=True)
# Command to pull the UI file from the device
pull_command = f'adb -s {device_id} pull /sdcard/snapchat_ui.xml snapchat_ui.xml'
subprocess.run(pull_command, shell=True)
tree = ET.parse('snapchat_ui.xml')
root = tree.getroot()
# Find all nodes with bounds and print their positions
print("Nodes with Bounds:")
for idx, node in enumerate(root.iter()):
bounds = extract_bounds(node)
if bounds:
print(f"{idx+1}. Bounds: {bounds}")
# Capture screenshot of the current app window
screenshot_command = f'adb -s {device_id} shell screencap -p /sdcard/snapchat_screenshot.png'
subprocess.run(screenshot_command, shell=True)
# Pull the screenshot from the device
pull_screenshot_command = f'adb -s {device_id} pull /sdcard/snapchat_screenshot.png snapchat_screenshot.png'
subprocess.run(pull_screenshot_command, shell=True)
# Read the screenshot
screenshot = cv2.imread('snapchat_screenshot.png')
# Write numbers on the screenshot corresponding to node positions
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1
font_color = (0, 0, 0) # Black color
thickness = 2
# Define the offset for the outline
offset = 2
# Draw the white outline and write numbers
for idx, node in enumerate(root.iter()):
bounds = extract_bounds(node)
if bounds:
if tuple(bounds) not in processed_bounds:
processed_bounds.add(tuple(bounds))
x = bounds[0] + 10
y = bounds[1] + 30
cv2.putText(screenshot, str(idx+1), (x - offset, y), font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
cv2.putText(screenshot, str(idx+1), (x + offset, y), font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
cv2.putText(screenshot, str(idx+1), (x, y - offset), font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
cv2.putText(screenshot, str(idx+1), (x, y + offset), font, font_scale, (255, 255, 255), thickness, cv2.LINE_AA)
cv2.putText(screenshot, str(idx+1), (x, y), font, font_scale, font_color, thickness, cv2.LINE_AA)
# Save the modified screenshot
cv2.imwrite('annotated_screenshot.png', screenshot)
break