test_worker.py (1505B)
1 """Drives the worker the way the MCP server will: spawn Windows Python on worker.py and 2 exchange line-delimited JSON. Run under WSL Python: python3 tools/test_worker.py 3 """ 4 5 import json 6 import re 7 import subprocess 8 import os 9 10 HERE = os.path.dirname(os.path.abspath(__file__)) 11 WORKER = os.path.join(HERE, "..", "src", "dbgeng_mcp", "worker.py") 12 WORKER_WIN = subprocess.check_output(["wslpath", "-w", WORKER], text=True).strip() 13 14 proc = subprocess.Popen(["python.exe", WORKER_WIN], stdin=subprocess.PIPE, 15 stdout=subprocess.PIPE, text=True, bufsize=1) 16 17 counter = iter(range(1, 1000)) 18 19 20 def call(cmd, **args): 21 proc.stdin.write(json.dumps({"id": next(counter), "cmd": cmd, "args": args}) + "\n") 22 proc.stdin.flush() 23 reply = json.loads(proc.stdout.readline()) 24 assert reply["ok"], f"{cmd} failed: {reply.get('error')}" 25 return reply["result"] 26 27 28 print("ping:", call("ping")) 29 print("open:", call("open", mode="launch", target="ping -n 2 127.0.0.1")) 30 31 regs = call("registers")["output"] 32 rip = int(re.search(r"rip=([0-9a-f]+)", regs).group(1), 16) 33 print(f"rip = {rip:#018x}") 34 35 mem = call("read_memory", address=rip, size=8) 36 print("read_memory @rip:", mem["hex"]) 37 38 print("disasm:", call("execute", command=f"u {rip:#x} L1")["output"].strip().splitlines()[-1].strip()) 39 print("step into:", call("step", kind="into")) 40 print("step into:", call("step", kind="into")) 41 print("close:", call("close")) 42 43 proc.stdin.close() 44 proc.wait(timeout=10) 45 print("worker exited", proc.returncode)