import frida, time, subprocess, re
ADB="/opt/android-sdk/platform-tools/adb"
JS=re.search(r'JS=r"""(.*?)"""', open('/root/ants/diag_clean.py').read(), re.S).group(1)
subprocess.run([ADB,"shell","am","force-stop","se.foglo.svt"])
dev=frida.get_usb_device(timeout=10); pid=dev.spawn(["se.foglo.svt"])
s=dev.attach(pid); sc=s.create_script(JS); t0=time.time()
s.on("detached", lambda r,c=None: print("DETACH @%.1f reason=%s"%(time.time()-t0,r),flush=True))
sc.on("message",lambda m,d: print("[%6.1f] %s"%(time.time()-t0,m.get("payload",m)),flush=True))
sc.load(); dev.resume(pid)
# let menu load
time.sleep(30)
subprocess.run([ADB,"shell","screencap","-p","/sdcard/pre.png"])
subprocess.run([ADB,"pull","/sdcard/pre.png","/root/ants/pre_tap.png"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
print("=== TAPPING SNIPER (approx left char) ===",flush=True)
# SNIPER is typically left half; tap lower-left play area. We'll tap several candidate spots.
for (x,y) in [(300,1500),(300,1650),(540,1650)]:
    subprocess.run([ADB,"shell","input","tap",str(x),str(y)])
    time.sleep(3)
subprocess.run([ADB,"shell","screencap","-p","/sdcard/post.png"])
subprocess.run([ADB,"pull","/sdcard/post.png","/root/ants/post_tap.png"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
time.sleep(10)
print("=== DONE ===",flush=True)
