# -*- coding: utf-8 -*-
import frida
import sys
import time

PKG = "ph.seabank.seabank"
d = frida.get_usb_device(10)
pid = None
for app in d.enumerate_applications():
    if app.identifier == PKG and app.pid and app.pid > 0:
        print("found", app.name, app.pid)
        pid = app.pid
        break
if not pid:
    sys.exit("MariBank not running")

s = d.attach(pid)
src = open(__file__.replace("test_attach.py", "trace_maribank_register.js"), encoding="utf-8").read()

def on_m(msg, data):
    print(msg)

sc = s.create_script(src)
sc.on("message", on_m)
sc.load()
print("loaded, waiting 15s for hooks...")
time.sleep(15)
print("done test")
