import frida, sys, time
JS=r"""
function rd(p){ try{if(p.isNull())return null;var l=p.add(8).readS32();if(l<0||l>256)return null;return p.add(0xc).readUtf16String(l);}catch(e){return "<e>";} }
function ins(){ var m=Process.findModuleByName("libil2cpp.so"); if(!m) return false;
 var b=m.base;
 // CreateSection(this,name) @0x10ec2e8 ; name = [esp+0x34] at entry (cdecl arg2)
 Interceptor.attach(b.add(0x10ec2e8),{
   onEnter:function(a){ this.nm = rd(this.context.esp.add(0x34).readPointer()); },
   onLeave:function(rv){ var par=null,leaf=null; try{ if(!rv.isNull()){ par=rd(rv.add(0x10).readPointer()); leaf=rd(rv.add(0xc).readPointer()); } }catch(e){}
     send("CreateSection name="+JSON.stringify(this.nm)+" -> leaf="+JSON.stringify(leaf)+" parent="+JSON.stringify(par)); }
 });
 // DataSection::Get(section,key,...) @0x10e7edd ; key=a[1]
 var seen={};
 Interceptor.attach(b.add(0x10e7edd),{onEnter:function(a){ var k=rd(a[1]); if(k && !seen[k]){seen[k]=1; send("GetKey "+k);} }});
 send("__ready"); return true; }
if(!ins()){var iv=setInterval(function(){if(ins())clearInterval(iv);},100);}
"""
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()
out=[]
def om(m,d):
    p=m.get("payload",str(m)); print("[%5.1f] %s"%(time.time()-t0,p),flush=True); out.append(p)
sc.on("message",om)
try:
    sc.load(); dev.resume(pid); time.sleep(20)
except Exception as e:
    print("EXC",e,flush=True)
open("/tmp/cstrace.out","w").write("\n".join(out))
