40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Frida RPC 真机测试;参数全部来自当前扫码设备,禁止硬编码旧手机。"""
|
|
|
|
import os
|
|
|
|
import frida
|
|
import pytest
|
|
|
|
|
|
TEST_SCRIPT = """
|
|
rpc.exports = {
|
|
ping: function() { return 'pong_test'; },
|
|
getProfile: function() { return {success: true, nickname: 'test'}; },
|
|
sendMessage: function(params) { return {success: true, params: params}; },
|
|
};
|
|
"""
|
|
|
|
|
|
def test_frida_rpc_exports_on_current_scanned_device():
|
|
endpoint = os.getenv("WORKPHONE_FRIDA_ENDPOINT", "").strip()
|
|
pid = os.getenv("WORKPHONE_WECHAT_PID", "").strip()
|
|
if not endpoint or not pid:
|
|
pytest.skip("扫码设备上报 Frida endpoint 和微信 PID 后执行真机 RPC")
|
|
|
|
manager = frida.get_device_manager()
|
|
device = manager.add_remote_device(endpoint)
|
|
session = device.attach(int(pid))
|
|
script = session.create_script(TEST_SCRIPT)
|
|
try:
|
|
script.load()
|
|
exports = script.exports_sync
|
|
assert exports.ping() == "pong_test"
|
|
assert exports.get_profile()["success"] is True
|
|
result = exports.send_message({"to_id": "test", "content": "hello"})
|
|
assert result["success"] is True
|
|
assert result["params"]["content"] == "hello"
|
|
finally:
|
|
script.unload()
|
|
session.detach()
|