【Frida】调试js代码

方法一attach启动

js代码动态注入app,app需要保持运行状态

# coding: utf-8
import sys
import frida

app_name = "猿人学APP" # app的名字
js_file_path = "./demo.js" # js代码的文件位置


def on_message(message, data):
    if message['type'] == 'send':
        print("[*] {0}".format(message['payload']))
    else:
        print(message)
with open(js_file_path,mode="r",encoding="utf8") as f:
    js_demo = f.read()
process = frida.get_usb_device(-1).attach(app_name)
script = process.create_script(js_demo)
script.on('message', on_message)
script.load()
sys.stdin.read()

方法二spawn 启动

重启app,app时就注入hook代码

# coding: utf-8
import sys
import frida

app_packagename = "com.yuanrenxue.challenge" # app的包名
js_file_path = "./demo.js" # js代码的文件位置


def on_message(message, data):
    if message['type'] == 'send':
        print("[*] {0}".format(message['payload']))
    else:
        print(message)
with open(js_file_path,mode="r",encoding="utf8") as f:
    js_demo = f.read()


device = frida.get_usb_device(-1)
pid = device.spawn([app_packagename])
process = device.attach(pid)

script = process.create_script(js_demo)
script.on('message', on_message)
print('[*] Running')
script.load()

device.resume(pid)

sys.stdin.read()

posted @ 2023-02-01 17:38  xsir161  阅读(298)  评论(0编辑  收藏  举报