dbgeng-mcp

An MCP server that drives the Windows debugger engine (dbgeng) for dynamic analysis.
git clone https://dittus.dev/git/dbgeng-mcp.git
Log | Files | Refs | README

smoke.py (1640B)


      1 """Live check of the dbgeng binding. Launches a throwaway target, runs a few commands,
      2 reads memory, and tears down. Run with Windows Python:
      3 
      4     python.exe tools/smoke.py
      5 """
      6 
      7 import os
      8 import sys
      9 
     10 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
     11 from dbgeng_mcp import _engine as E  # noqa: E402
     12 from dbgeng_mcp._engine import Engine  # noqa: E402
     13 
     14 STATUS_NAMES = {0: "NO_CHANGE", 1: "GO", 4: "STEP_OVER", 5: "STEP_INTO",
     15                 6: "BREAK", 7: "NO_DEBUGGEE"}
     16 
     17 eng = Engine()
     18 # A windowless, short target. The initial-break option stops it at its first instruction,
     19 # so it never actually pings and nothing shows on screen.
     20 eng.create_process("ping -n 2 127.0.0.1")
     21 hr_event = eng.wait_for_event()
     22 status = eng.execution_status()
     23 print(f"wait_for_event hr=0x{hr_event & 0xFFFFFFFF:08X}  status={STATUS_NAMES.get(status, status)}")
     24 
     25 print("\n== version"); print("  " + "\n  ".join(eng.execute("version").splitlines()[:2]))
     26 print("\n== lm1m (first 6 modules)")
     27 for line in eng.execute("lm1m").splitlines()[:6]:
     28     print("  ", line)
     29 print("\n== registers (first 3 lines)")
     30 for line in eng.execute("r").splitlines()[:3]:
     31     print("  ", line)
     32 
     33 rip = eng.execute("? @rip")
     34 print("\n== ? @rip:", rip.strip())
     35 try:
     36     address = int(rip.split("=")[-1].strip().replace("`", ""), 16)
     37     print(f"== read 16 bytes at {address:#x}:", eng.read_virtual(address, 16).hex())
     38     print("== disassemble:")
     39     for line in eng.execute(f"u {address:#x} L3").splitlines():
     40         print("  ", line)
     41 except ValueError:
     42     print("  (could not parse @rip, no debuggee context)")
     43 
     44 eng.end_session()
     45 print("\n== session ended")