from pydbg import *
from pydbg.defines import *

import fuzzutils

def handler_accessviolation (pydbg):
    print fuzzutils.context["currentsignature"]
    outstring = "[DBG] Called from thread %d \n" % pydbg.dbg.dwThreadId
    outstring = outstring + "[DBG] %08x \n" % pydbg.exception_address

    outstring = outstring +  pydbg.process_snapshot().dump_context()
    fuzzutils.context["fuzzinglog"].insert(fuzzutils.context["fuzzinglog"].get_end_iter(),outstring)
    
    #return DBG_CONTINUE
    return DBG_EXCEPTION_NOT_HANDLED


def handler_breakpoint (pydbg):
# ignore the first windows driven breakpoint.
    if pydbg.first_breakpoint:
        return DBG_CONTINUE
    
    outstring =  "[DBG] Called from thread %d \n" % pydbg.dbg.dwThreadId
    outstring = outstring +  "[DBG] %08x \n" % pydbg.exception_address

    outstring = outstring +  pydbg.process_snapshot().dump_context()
    fuzzutils.context["fuzzinglog"].insert(fuzzutils.context["fuzzinglog"].get_end_iter(),outstring)
    #return DBG_CONTINUE
    return DBG_EXCEPTION_NOT_HANDLED
    
def handler_new_thread (pydbg):
    outstring = " [DBG] Called from thread %d \n" % pydbg.dbg.dwThreadId
    fuzzutils.context["fuzzinglog"].insert(fuzzutils.context["fuzzinglog"].get_end_iter(),outstring)
    return DBG_CONTINUE
   




