#!/usr/bin/env python3
import frida, time, subprocess
ADB="/opt/android-sdk/platform-tools/adb"
JS=r"""
var CN=null,GC=null;
function cnk(k){try{if(k.isNull())return "NULL";return CN(k).readUtf8String();}catch(e){return "?";}}
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});}}
 CN=new NativeFunction(b.add(0xbc61fc),'pointer',['pointer']);
 var dep=0;
 T(function(){Interceptor.attach(b.add(0xd34fb9),{onEnter:function(){dep++;},onLeave:function(){dep--;}});});
 // at 0xd356a7: eax=[esp+0x14] (expected class holder), ebp=[esp+0x3c] (persona value node)
 T(function(){Interceptor.attach(b.add(0xd356a7),{onEnter:function(){if(dep<=0)return;try{
   var sp=this.context.esp;
   var exp=sp.add(0x14).readPointer(); var expcls=exp.readPointer();
   var val=this.context.ebp; var valcls=val.isNull()?ptr(0):val.readPointer();
   send({g:"loop2 typecheck: EXPECTED="+cnk(expcls)+"  personaValue.class="+cnk(valcls)});
 }catch(e){send({g:"e "+e});}}});});
 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)
