I was wondering if it was possible to create a python script that is able to capture and replay the instructions executed by a windows program for in depth analysis.

  • It's probably possible, if you could control the time-travel debugging feature of WinDbgX via Python. But could you explain what you have already tried and what you are stuck on? This sounds like a very broad question. And the answer is: probably yes. But I doubt that's the answer you are looking for. So What is it you are looking for?
    – 0xC0000022L
    Jan 19 at 14:08

1 Answer 1


Here is an example of how you could use the pyDbg library in Python to create a basic script that captures and replays the instructions executed by a Windows program:

import pydbg

def main():
    # Create a new instance of the pydbg class
dbg = pydbg()

# Attach to the process of the target program
pid = dbg.attach("program.exe")

# Set a breakpoint at the entry point of the program
entry_point = dbg.func_resolve("program.exe", "main")

# Start the debugging loop

# Once the program has exited, print the instructions that were executed
print("Instructions executed:")
for instruction in dbg.instructions:
    print("0x%08x: %s %s" % (instruction[0], instruction[1], instruction[2]))

if __name__ == "__main__":

As the program runs, the script will capture the executed instructions and save them in a list. Once the program has exited, the script will print out the executed instructions. Note that this is just a very basic example, and it is not robust enough for a real-world use case. In a real-world application, you need to consider factors such as handling multiple threads, exceptions and system calls, and more.

  • Hi and welcome to RE.SE. This looks and sounds very much like an AI-generated answer (flagging as such). Is it? As a side-note: pydbg from Pedram Amini and all continuations/successor projects I found is for Python 2.7, which is out of support. I used pydbg myself back in the day. If you are aware of a modern Python-3.x-enabled continuation or successor, please add a link, too.
    – 0xC0000022L
    Jan 19 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.