Package winappdbg :: Module event :: Class EventHandler
[hide private]
[frames] | no frames]

Class EventHandler


Base class for debug event handlers.

Your program should subclass it to implement it's own event handling.

The signature for event handlers is the following:

   def event_handler(self, event):

Where event is an Event object.

Each event handler is named after the event they handle. This is the list of all valid event handler names:

This is the list of all valid exception handler names (they all receive an ExceptionEvent object):

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__setApiHooksForDll(self, event)
Hook the requested API calls (in self.apiHooks).
 
__call__(self, event)
Dispatch debug events.
 
event(self, event)
Handler for events not handled by any other defined method.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
dict( int → str ) __eventCallbackName = {1: 'exception', 2: 'create_thread', 3: ...
Map of event code constants to the names of the user-defined methods.
dict( int → str ) __exceptionCallbackName = {1073807365: 'debug_control_c', 1080...
Map of exception code constants to the names of the user-defined methods.
dict( str → tuple( str, int ) ) apiHooks = {}
Dictionary that maps module names to tuples of ( procedure name, parameter count ).
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__setApiHooksForDll(self, event)

 

Hook the requested API calls (in self.apiHooks).

This method is called automatically whenever a DLL is loaded.

__call__(self, event)
(Call operator)

 

Dispatch debug events.

Parameters:
  • event (Event) - Event object.

event(self, event)

 

Handler for events not handled by any other defined method.

Parameters:
  • event (Event) - Event object.

Class Variable Details [hide private]

__eventCallbackName

Map of event code constants to the names of the user-defined methods. Unknown codes go to 'unknown_event'.
Type:
dict( int → str )
Value:
{1: 'exception',
 2: 'create_thread',
 3: 'create_process',
 4: 'exit_thread',
 5: 'exit_process',
 6: 'load_dll',
 7: 'unload_dll',
 8: 'output_string',
...

__exceptionCallbackName

Map of exception code constants to the names of the user-defined methods. Unknown codes go to 'unknown_exception'.
Type:
dict( int → str )
Value:
{1073807365: 'debug_control_c',
 1080890248: 'ms_vc_exception',
 2147483649: 'guard_page',
 2147483650: 'datatype_misalignment',
 2147483651: 'breakpoint',
 2147483652: 'single_step',
 3221225477: 'access_violation',
 3221225478: 'in_page_error',
...

apiHooks

Dictionary that maps module names to tuples of ( procedure name, parameter count ).

All procedures listed here will be hooked for calls from the debuguee. When this happens, the corresponding event handler is notified both when the procedure is entered and when it's left by the debugee.

For example, if the procedure name is "LoadLibraryEx" the event handler routines must be defined as "pre_LoadLibraryEx" and "post_LoadLibraryEx" in your class.

The signature for the routines can be something like this:

   def pre_LoadLibraryEx(event, *params):
       ra   = params[0]        # return address
       argv = params[1:]       # function parameters

       # (...)

   def post_LoadLibrary(event, return_value):

       # (...)

But since you can also specify the number of arguments, this signature works too (four arguments in this case):

   def pre_LoadLibraryEx(event, ra, lpFilename, hFile, dwFlags):
       szFilename = event.get_process().peek_string(lpFilename)

       # (...)

Note that the number of parameters to pull from the stack includes the return address. The apiHooks dictionary for the example above would look like this:

   apiHook = {

       "kernel32.dll" : (

           #   Procedure name      Parameter count
           (   "LoadLibraryEx",    4 ),

           # (more procedures can go here...)
       ),

       # (more libraries can go here...)
   }

For a more complete support of API hooking, you can also check out Universal Hooker at http://oss.coresecurity.com/projects/uhooker.htm

Type:
dict( str → tuple( str, int ) )
Value:
{}