pykd: Python WinDbg Extension

0.3.4.15 · active · verified Fri Apr 17

pykd is a Python extension for WinDbg, providing scripting capabilities for Windows kernel and user-mode debugging. It allows users to automate debugging tasks, analyze crash dumps, and extend WinDbg functionality with Python. The current version is 0.3.4.15. Its release cadence is irregular, typically tied to WinDbg updates and community contributions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic interaction with the WinDbg debugger through pykd, such as retrieving process information, reading register values, and executing debugger commands. This code is intended to be executed within a WinDbg session after loading the pykd extension.

import pykd

try:
    # Get the current process ID if a user-mode debuggee is attached
    pid = pykd.getCurrentProcessId()
    print(f"Current Process ID: {pid}")

    # Read a register value (e.g., EAX for 32-bit, RAX for 64-bit)
    # This assumes a debuggee is running and registers are available.
    register_name = "eax" if pykd.is32Bit() else "rax"
    reg_value = pykd.reg(register_name)
    print(f"{register_name.upper()} register value: 0x{reg_value:x}")

    # Execute a simple WinDbg command and print its output
    output = pykd.dbgCommand("!peb")
    print("\nOutput of '!peb':")
    print(output[:200] + "..." if len(output) > 200 else output) # Truncate for display
except pykd.BaseException as e:
    print(f"pykd error encountered: {e}")
    print("This script must be run within a WinDbg session with a debuggee attached.")

view raw JSON →