import json,sys,time,frida
A=json.load(open('/root/ants/force_addrs.json'))
GI=json.load(open('/root/ants/x86addrs.json')).get('PlayerProfile::get_instance/0')
JS=r"""
var A=%s; var GI=%d; var base=null; var ppThis=null; var awoken=false;
function ins(){var m=Process.findModuleByName('libil2cpp.so'); if(m===null)return false; base=m.base;
 var Awake=new NativeFunction(base.add(A['PlayerProfile::Awake/0']),'void',['pointer','pointer']);
 var GetInst=new NativeFunction(base.add(GI),'pointer',['pointer']);
 Interceptor.attach(base.add(A['PlayerProfile::.ctor/0']),{onEnter:function(a){ppThis=a[0];}});
 var iv=setInterval(function(){if(ppThis!==null&&!awoken){awoken=true;
   Awake(ppThis,ptr(0));
   var r=GetInst(ptr(0));
   send({t:'log',m:'after forced Awake: get_instance='+r+'  (ctor this='+ppThis+')'});
   clearInterval(iv);}},50);
 send({t:'log',m:'ready'}); return true;}
if(!ins()){var t=setInterval(function(){if(ins())clearInterval(t);},100);}
""" % (json.dumps(A),GI)
dev=frida.get_device_manager().add_remote_device('127.0.0.1:27042')
pid=dev.spawn(['se.foglo.svt']); ses=dev.attach(pid); sc=ses.create_script(JS)
def om(m,d):
    if m['type']=='send': print('%7.2fs %s'%(time.time()-t0,m['payload']['m']))
    else: print('!!',m)
sc.on('message',om); sc.load(); t0=time.time(); dev.resume(pid); time.sleep(12)
