import frida, time, subprocess
ADB="/opt/android-sdk/platform-tools/adb"
JS=r"""
function ins(){var lc=Process.findModuleByName("libc.so");if(!lc)return false;
 var errno_loc=lc.findExportByName("__errno");
 var ep=errno_loc?new NativeFunction(errno_loc,'pointer',[]):null;
 Interceptor.attach(lc.findExportByName("connect"),{onEnter:function(a){this.t=null;try{var sa=a[1];if(sa.readU16()==2){var port=(sa.add(2).readU8()<<8)|sa.add(3).readU8();if(port==5058){var ip=sa.add(4).readU8()+"."+sa.add(5).readU8()+"."+sa.add(6).readU8()+"."+sa.add(7).readU8();this.t=ip+":"+port;this.fd=a[0].toInt32();}}}catch(e){}},onLeave:function(r){if(this.t){var er=0;try{if(ep)er=ep().readS32();}catch(e){}send({g:"connect("+this.t+" fd="+this.fd+") ret="+r.toInt32()+" errno="+er});}}});
 send({g:"__ready"});return true;}
if(!ins()){var iv=setInterval(function(){if(ins())clearInterval(iv);},120);}
"""
subprocess.run([ADB,"shell","am","force-stop","se.foglo.svt"]); time.sleep(3)
subprocess.run([ADB,"shell","monkey","-p","se.foglo.svt","-c","android.intent.category.LAUNCHER","1"],stdout=-3,stderr=-3)
time.sleep(8)
dev=frida.get_usb_device(timeout=10)
pid=int(subprocess.run([ADB,"shell","pidof","se.foglo.svt"],capture_output=True,text=True).stdout.split()[0])
s=dev.attach(pid); sc=s.create_script(JS)
sc.on("message",lambda m,d: print(m.get("payload",m),flush=True)); sc.load(); time.sleep(34)
for c in [("690","730"),("690","730"),("1350","960"),("1350","960")]:
    subprocess.run([ADB,"shell","input","tap",c[0],c[1]]); time.sleep(4)
time.sleep(10); print("done")
