"""让设备上的内核自己报:它加载的 doubao_entry 是哪个文件、有没有新符号。""" import json import sys import urllib.request try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass URL = "http://127.0.0.1:15199" def call(path, payload=None, method="POST", timeout=90): data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None req = urllib.request.Request( URL + path, data=data, method=method, headers={"Content-Type": "application/json; charset=utf-8"}, ) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8")) # ★ 用 python_run 跑不了(那是子进程,看不到内核进程里已加载的模块)。 # 所以用一个**临时工具**:内核会 import 它,它就能看到内核进程的 sys.modules。 probe_src = ''' import os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) TOOL = {"name": "probe_loaded", "description": "探内核加载了什么", "parameters": {"type": "object", "properties": {}}} def run(args): out = {} mod = sys.modules.get("doubao_entry") out["doubao_entry_file"] = getattr(mod, "__file__", None) if mod else None out["has_src_hash"] = hasattr(mod, "_src_hash") if mod else None out["has_new_seed"] = None if mod: import inspect try: src = inspect.getsource(mod._seed_tools) out["seed_src_len"] = len(src) out["seed_has_fingerprint"] = "doubao-seed.json" in src except Exception as e: out["seed_src_error"] = f"{type(e).__name__}: {e}" # 内嵌源码里 show_ui 有没有 wait try: import bundled_tool_sources s = bundled_tool_sources.sources().get("show_ui.py", "") out["bundled_show_ui_len"] = len(s) out["bundled_show_ui_has_wait"] = "wait" in s except Exception as e: out["bundled_error"] = f"{type(e).__name__}: {e}" return out ''' # 写到可写工具目录里 import base64 b64 = base64.b64encode(probe_src.encode("utf-8")).decode() write_js = ( "import base64,os;" "d='/storage/emulated/0/Android/data/com.doubao.lynxclone/files/tools';" "open(os.path.join(d,'probe_loaded.py'),'wb').write(base64.b64decode('%s'));" "print('written')" % b64 ) r = call("/api/tools/run", {"name": "python_run", "args": {"code": write_js, "timeout": 30}}, timeout=90) print("写探针:", (r.get("result") or {}).get("stdout", "").strip()) # 让内核重新发现工具再执行 r = call("/api/tools/run", {"name": "probe_loaded", "args": {}}, timeout=90) print(json.dumps((r or {}).get("result"), ensure_ascii=False, indent=1))