-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathsubmit_model.py
90 lines (80 loc) · 3.11 KB
/
submit_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# https://github.com/Hawcett/XiaoYuanKouSuan_Frida_hook
# 应注意可能有某个页面也被hook到了,可能有也肯能没有
# 输出的json不一定格式正确,比如如果某个值是None,则不会加引号导致json格式错误无法加载网页
"""
修改提交试题答案
"""
import json
import os
import frida
import sys
import base64
import subprocess
# 使用 adb 获取 com.fenbi.android.leo 包名的 PID
def _get_pid_from_adb(package_name):
import subprocess
try:
# 使用 adb 获取进程列表,并查找目标应用的 PID
result = subprocess.run(['adb', 'shell', 'ps | grep ' + package_name],
capture_output=True, text=True)
output = result.stdout.strip()
if output:
# 从 adb 输出中提取 PID
pid = int(output.split()[1])
print(f"通过 adb 找到 PID: {pid}")
return pid
else:
print("adb 没有找到该应用的 PID")
return None
except Exception as e:
print(f"adb 获取 PID 时出错: {e}")
return None
# 获取 PID
pid = _get_pid_from_adb("com.fenbi.android.leo")
# 通过链接到虚拟机frida-server
device = frida.get_usb_device()
# 附加到已有进程的PID
session = device.attach(pid)
# 加载js文件
with open("submit_model.js", encoding='utf-8') as f:
script = session.create_script(f.read())
# 设置控制台消息处理程序
def on_message(message, data):
if message['type'] == 'send':
# 复制粘贴 https://github.com/Hawcett/XiaoYuanKouSuan_Frida_hook 的代码
bytes_obj = bytes.fromhex(message['payload'])
string = bytes_obj.decode('utf-8')
string = string.replace(r'\"', "%")
# 修正null不加引号导致的错误
string = string.replace("null", '"null"')
# 万一null已经有引号, 再删掉
string = string.replace('""null""', '"null"')
print("字符串: ", string)
json_data = json.loads(string)
print(json_data)
print('原始花费时间:', json_data['costTime'])
# TODO 时间不要修改为0 最低为1 否则会有难以解决的错误
# targetCostTime - 10 稳赢 此处仅适合好友对战,如果不是请将下面的 int(targetCostTime) - 10修改为其他数值,需要与domatchV2byData联合使用
os.chdir("..")
with open("test.txt","r") as f:
ttime = f.read()
f.close()
print(ttime)
targetCostTime = int(ttime)
if(targetCostTime<=10):
targetCostTime = 11
json_data['costTime'] = targetCostTime - 10
print('现在花费时间:', json_data['costTime'])
print(json_data)
data = str(json_data).replace('%', r'\"')
data = str(data).replace('\'', '\"')
data = str(data).replace(' ', '')
script.post({'type': 'send', 'my_data': data})
else:
print("[{}] {}".format(message['type'], message['description']))
# 设置消息处理程序
script.on('message', on_message)
# 加载js文件并获取脚本输出的信息
script.load()
# 保持脚本运行
sys.stdin.read()