#!/usr/bin/env python3
import frida, time, subprocess
ADB="/opt/android-sdk/platform-tools/adb"
JS=r"""
function ins(){var m=Process.findModuleByName("libil2cpp.so");if(!m)return false;var b=m.base;
 function T(f){try{f();}catch(e){send({w:""+e});}}
 var dep=0;
 T(function(){Interceptor.attach(b.add(0xd34fb9),{onEnter:function(a){dep++;this.rb=a[0];send({g:"== DecodeResponse ENTER"});},onLeave:function(){dep--;try{var f=[];for(var o=0;o<=0x10;o+=4)f.push(this.rb.add(o).readPointer());send({g:"== LEAVE ret="+f.join(" "));}catch(e){}}});});
 [[0xd35738,"build-persona"],[0xd354d5,"HandleServerAssert"],[0xd357e1,"TAIL(matchId)"],[0xd358e6,"CATCH"]].forEach(function(x){
   T(function(){Interceptor.attach(b.add(x[0]),{onEnter:function(){if(dep>0)send({g:"  "+x[1]});}});});});
 T(function(){Interceptor.attach(b.add(0xd3c44a),{onEnter:function(){send({g:">> OnResponse"});}});});
 T(function(){Interceptor.attach(b.add(0xd3c799),{onEnter:function(){send({g:">> Count call reached"});}});});
 T(function(){Interceptor.attach(b.add(0xd3c895),{onEnter:function(){send({g:">> AssemblePlayerList reached (past Count!)"});}});});
 T(function(){var ab=Process.findModuleByName("libc.so").findExportByName("abort");Interceptor.attach(ab,{onEnter:function(){send({g:"*** ABORT"});}});});
 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(43)
subprocess.run([ADB,"shell","input","tap","700","730"]); time.sleep(3)
subprocess.run([ADB,"shell","input","tap","700","730"]); time.sleep(4)
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(1)
subprocess.run([ADB,"shell","input","tap","1355","970"]); time.sleep(3)
subprocess.run([ADB,"shell","input","tap","1355","970"]); time.sleep(14)
print("=== done ===",flush=True)
