Flag: Tornado! Hurricane!

Blogs >> pedram's Blog

Created: Friday, January 6 2006 14:12.41 CST Modified: Friday, January 6 2006 14:12.41 CST
Printer Friendly ...
Debugger Debugging Madness
Author: pedram # Views: 4279

It took a few days of (interspersed) debugging but I finally got memory breakpoints implemented in the Python Win32 debugging engine I wrote last weekend. It's built on the Python ctypes module, which I'm very fond of. Many thanks to the people I leaned on at various times while pulling my hair out trying to figure out what was wrong (hoglund, spoon, skape, drew ...). I'll make it available at some point, it's currently way too ugly but very functional:

    def attach (self, pid):
    def bp_del (self, address):
    def bp_del_mem (self, address):
    def bp_is_ours (self, address_to_check):
    def bp_is_ours_mem (self, address_to_check):
    def bp_set (self, address, description="", restore=True):
    def bp_set_mem (self, address, size, description=""):
    def cleanup (self):
    def debug_event_loop (self):
    def detach (self):
    def disasm (self, address):
    def dump_context (self, context=None):
    def enumerate_threads (self):
    def exception_handler_breakpoint (self, dbg, context):
    def exception_handler_guard_page (self, dbg, context):
    def exception_handler_single_step (self, dbg, context):
    def func_resolve (self, dll, function):
    def get_thread_context (self, thread_handle, thread_id=0):
    def hex_dump (self, data):
    def hide_debugger (self):
    def is_address_on_stack (self, address, context=None):
    def is_printable_ascii (self, data):
    def is_printable_unicode (self, data):
    def little_endian (self, dword):
    def load (self, path_to_file, command_line=0):
    def process_restore (self):
    def process_snapshot (self):
    def read_process_memory (self, address, length):
    def resume_thread (self, thread_id):
    def set_callback (self, exception_code, callback_func):
    def set_register (self, register, value):
    def set_thread_context (self, thread_handle, context, thread_id=0):
    def single_step (self, enable):
    def smart_dereference (self, address):
    def stack_range (self, context=None):
    def suspend_thread (self, thread_id):
    def terminate_process (self, exit_code=0):
    def virtual_protect (self, base_address, size, protection):
    def virtual_query (self, address):
    def write_process_memory (self, address, data, data_length=0):

It's interesting being able to quickly prototype various debugging based ideas in Python:

    pydbg = pydbg()
    
    pydbg.set_callback(EXCEPTION_BREAKPOINT,       handler_breakpoint)
    pydbg.set_callback(EXCEPTION_ACCESS_VIOLATION, handler_access_violation)
    
    try:
        pydbg.attach(pid)
    
        winsock_recv     = pydbg.func_resolve("ws2_32",  "recv")
        winsock_recvfrom = pydbg.func_resolve("ws2_32",  "recvfrom")
    
        pydbg.bp_set(winsock_recv)
        pydbg.bp_set(winsock_recvfrom)
    
        pydbg.debug_event_loop()
    except pdx, x:
        sys.stderr.write(x.__str__() + "\n")

There is still an oustanding question of how exactly Windows deals with guard pages. I put that question up in the forums so people can respond to it:

http://www.openrce.org/forums/posts/110




Add New Comment
Comment:









There are 31,311 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
hi!
Jul/01
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit