import json,sys,time,frida
NAMES={52:'EventInfo',53:'EventActive',54:'EventInactive',55:'CompleteAction',56:'SplashVisible',57:'SplashHide',58:'ShowMainPopup',71:'ShowTOU',72:'StartWaitTitles',0:'?'}
JS=r"""
var A=%d;
function ins(){var m=Process.findModuleByName("libil2cpp.so");if(!m)return false;var b=m.base;send({t:"info",m:"base"});
Interceptor.attach(b.add(A),{onEnter:function(a){send({t:"e",e0:a[0].toInt32(),e1:a[1].toInt32(),e2:a[2].toInt32()});}});
return true;}
if(!ins()){var iv=setInterval(function(){if(ins())clearInterval(iv);},200);}
""" % 16439598
dev=frida.get_device_manager().add_remote_device("127.0.0.1:27042")
pid=dev.spawn(["se.foglo.svt"]);s=dev.attach(pid);sc=s.create_script(JS);t0=time.time()
def om(m,d):
    if m["type"]!="send":print("!!",m);return
    p=m["payload"]
    if p["t"]=="e":print("[%6.2fs] OnEvent  a0=%d a1=%d a2=%d  {a1=%s}"%(time.time()-t0,p["e0"],p["e1"],p["e2"],NAMES.get(p["e1"],'?')))
    else:print("[%s]%s"%(p["t"],p.get("m")))
sc.on("message",om);sc.load();dev.resume(pid)
time.sleep(int(sys.argv[1]) if len(sys.argv)>1 else 30)
