"""直接测:那个工具目录到底能不能写、_seed_tools 报什么错。""" import base64 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" D = "/storage/emulated/0/Android/data/com.doubao.lynxclone/files/tools" 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")) probe = r''' import os, sys, json, traceback D = %r out = {"dir": D} out["isdir"] = os.path.isdir(D) out["writable"] = os.access(D, os.W_OK) # ① 直接写一个测试文件 try: p = os.path.join(D, "_writetest.txt") with open(p, "w", encoding="utf-8") as fh: fh.write("hi") out["direct_write"] = "ok" os.remove(p) except Exception as e: out["direct_write"] = f"{type(e).__name__}: {e}" # ② 内核认为的工具目录是哪个(paths) try: import paths out["paths_tools_dir"] = paths.get().tools_dir out["paths_work_dir"] = getattr(paths.get(), "work_dir", None) out["paths_data_dir"] = paths.get().data_dir except Exception as e: out["paths_err"] = f"{type(e).__name__}: {e}" # ③ 手动调 _seed_tools,把异常抓全 mod = sys.modules.get("doubao_entry") if mod: out["has_src_hash"] = hasattr(mod, "_src_hash") try: n = mod._seed_tools(D) out["seed_wrote"] = n except Exception as e: out["seed_err"] = f"{type(e).__name__}: {e}" out["seed_tb"] = traceback.format_exc()[-1200:] # ④ 看看 wanted 里到底有几个 try: import bundled_tool_sources srcs = bundled_tool_sources.sources() out["bundled_count"] = len(srcs) out["bundled_names"] = sorted(srcs.keys())[:20] wanted = {} for name in mod.BUNDLED_TOOL_FILES: wanted[name] = mod._module_source(name[:-3]) for k, v in srcs.items(): wanted[k] = v out["wanted_nonempty"] = sum(1 for v in wanted.values() if v) out["wanted_total"] = len(wanted) except Exception as e: out["wanted_err"] = f"{type(e).__name__}: {e}" print(json.dumps(out, ensure_ascii=False, indent=1)) ''' % D b64 = base64.b64encode(probe.encode("utf-8")).decode() w = ( "import base64,os;" "open(os.path.join('%s','probe_perm.py'),'wb').write(base64.b64decode('%s'));" "print('ok')" % (D, b64) ) call("/api/tools/run", {"name": "python_run", "args": {"code": w, "timeout": 30}}, timeout=90) try: r = call("/api/tools/run", {"name": "probe_perm", "args": {}}, timeout=120) except Exception as exc: # noqa: BLE001 print("调用 probe_perm 失败:", exc) sys.exit(1) res = (r or {}).get("result") or {} print(res.get("stdout") or json.dumps(r, ensure_ascii=False)[:2000]) if res.get("stderr"): print("--- stderr ---") print(res["stderr"][-1500:])