Crawler/APP/main.py

64 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import frida
import time
import sys
# 保证输出UTF-8编码
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
APP_PACKAGE_NAME = "com.lmhl.yituoke"
SCRIPT_FILE = "./hookjs/dexclass.js"
def on_message(message, data):
if message['type'] == 'send':
print(f"[消息] {message['payload']}")
elif message['type'] == 'error':
print(f"[错误] {message['stack']}")
def main():
try:
# 连接设备
device = frida.get_usb_device(timeout=5)
print(f"[连接成功] 已连接到设备:{device.name}")
# 启动应用spawn
print(f"[启动应用] 准备启动应用:{APP_PACKAGE_NAME}")
pid = device.spawn([APP_PACKAGE_NAME])
# 附加到新进程
session = device.attach(pid)
print(f"[附加成功] 已附加到应用PID: {pid}")
# 加载脚本
with open(SCRIPT_FILE, encoding="utf-8") as f: # 保证读取脚本不会出编码问题
script = session.create_script(f.read())
script.on('message', on_message)
script.load()
print(f"[脚本加载成功] {SCRIPT_FILE} 脚本已成功加载!")
# 恢复应用运行
device.resume(pid)
print(f"[应用恢复] 应用已恢复运行,可以开始操作了。")
# 保持运行状态
print("[保持运行] 按 Ctrl+C 退出...")
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\n[退出] 正在断开连接...")
try:
session.detach()
except:
pass
sys.exit(0)
except Exception as e:
import traceback
print(f"[出现异常] {e}")
traceback.print_exc()
if __name__ == '__main__':
main()