#!/usr/bin/env python3
import frida, time, subprocess, hashlib
ADB="/opt/android-sdk/platform-tools/adb"
JS=r"""
function hexb(p,n){try{var u=new Uint8Array(p.readByteArray(n));return Array.prototype.map.call(u,function(x){return('0'+x.toString(16)).slice(-2);}).join('');}catch(e){return"?";}}
function arr(p,mx){try{if(p.isNull())return null;var len=p.add(0xc).readS32();if(len<0||len>4000)return null;return {n:len,h:hexb(p.add(0x10),Math.min(len,mx||300))};}catch(e){return null;}}
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});}}
 T(function(){var a=b.add(0x11f1032);var o=new NativeFunction(a,'int',['pointer','pointer','pointer']);Interceptor.replace(a,new NativeCallback(function(s,p,mi){if(s.isNull())return 0;try{return o(s,p,mi);}catch(e){return 0;}},'int',['pointer','pointer','pointer']));});
 // HashAlgorithm.ComputeHash(this, byte[] input) -> byte[]
 T(function(){Interceptor.attach(b.add(0x25ef6a),{onEnter:function(a){this.d=arr(a[1],120);},onLeave:function(r){if(!this.d)return;if(this.d.n>=48&&this.d.n<=100){var o=arr(r,40);send({g:"SHA IN["+this.d.n+"]="+this.d.h+" OUT="+(o?o.h:"?")});}}});});
 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(42)
subprocess.run([ADB,"shell","input","tap","700","730"]); time.sleep(5)
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(26)
print("=== done ===",flush=True)
