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

Class EventHandler

source code


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
source code
 
__setApiHooksForDll(self, event)
Hook the requested API calls (in self.apiHooks).
source code
 
__call__(self, event)
Dispatch debug events.
source code
 
event(self, event)
Handler for events not handled by any other defined method.
source code

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

Class Variables [hide private]
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)

source code 

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

Overrides: object.__init__
(inherited documentation)

__setApiHooksForDll(self, event)

source code 

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

This method is called automatically whenever a DLL is loaded.

__call__(self, event)
(Call operator)

source code 

Dispatch debug events.

Parameters:
  • event (Event) - Event object.

event(self, event)

source code 

Handler for events not handled by any other defined method.

Parameters:
  • event (Event) - Event object.

Class Variable Details [hide private]

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:
{}