Package envi :: Class CallingConvention
[hide private]
[frames] | no frames]

Class CallingConvention

source code



Base class for all calling conventions. You must define class locals that
define the fields below.

All offsets defined in the constructor are relative to the stack counter at
function entrypoint.

Provides primitives that support the following situations:
1. You are breakpointed at first instruction inside a function, have not
   executed that instruction, and want to modify the arguments, the return
   address, or the return value.  To modify the arguments or the return
   address, use 'setCallArgsRet'.  To modify the return value and then
   return, use 'execCallReturn'.
2. You are breakpointed on the call to a function, have not executed the
   call instruction, and want to modify the arguments.  To modify the
   arguments use 'setPreCallArgs'.  You cannot change the return address
   from this location because once you step through the call, the processor
   will overwrite whatever you wrote at that location.
3. You want to call a arbitrary function and return to the same location
   you are currently breakpointed at or another arbitrary location.  To
   call an arbitrary function, use 'executeCall'.

Instance Methods [hide private]
 
getNumStackArgs(self, emu, argc)
Returns the number of stack arguments.
source code
 
getPreCallArgs(self, emu, argc)
Returns a list of the arguments passed to the function.
source code
 
getCallArgs(self, emu, argc)
Returns a list of the arguments passed to the function.
source code
 
setPreCallArgs(self, emu, args)
Writes arguments to appropriate locations.
source code
 
setCallArgs(self, emu, args)
Writes arguments to appropriate locations.
source code
 
getReturnAddress(self, emu)
Returns the return address.
source code
 
setReturnAddress(self, emu, ra)
Sets the return address.
source code
 
setReturnValue(self, emu, rv)
Sets the return value.
source code
 
allocateReturnAddress(self, emu)
Allocates space on the stack for the return address.
source code
 
allocateArgSpace(self, emu, argc)
Allocates space on the stack for arguments.
source code
 
allocateCallSpace(self, emu, argc)
Allocates space on the stack for arguments and the return address.
source code
 
_dealloc(self, delta, argc) source code
 
deallocateCallSpace(self, emu, argc)
Removes space on the stack made for the arguments and the return address depending on the flags value of the calling convention.
source code
 
setCallArgsRet(self, emu, args=None, ra=None)
Modifies the arguments and return address.
source code
 
setupCall(self, emu, args=None, ra=None)
Sets up a function with the given args and the specified return address.
source code
 
executeCall(self, emu, va, args=None, ra=None)
Calls setupCall and then directly sets the program counter to the specified address.
source code
 
execCallReturn(self, emu, value, argc)
Forces a function to return the specified value.
source code

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

Class Variables [hide private]
  pad = 0
  align = 4
  delta = 0
  flags = 0
  arg_def = []
  retval_def = CC_STACK, 0
  retaddr_def = CC_STACK, 0
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

getPreCallArgs(self, emu, argc)

source code 

Returns a list of the arguments passed to the function.

Expects to be called at call/jmp to function entrypoint.

getCallArgs(self, emu, argc)

source code 

Returns a list of the arguments passed to the function.

Expects to be called at the function entrypoint.

setPreCallArgs(self, emu, args)

source code 

Writes arguments to appropriate locations. No allocation is performed.

Expects to be called at call/jmp to function entrypoint.

setCallArgs(self, emu, args)

source code 

Writes arguments to appropriate locations. No allocation is performed.

Expects to be called at the function entrypoint.

getReturnAddress(self, emu)

source code 

Returns the return address.

Expects to be called at the function entrypoint.

setReturnAddress(self, emu, ra)

source code 

Sets the return address.

Expects to be called at the function entrypoint.

deallocateCallSpace(self, emu, argc)

source code 

Removes space on the stack made for the arguments and the return address depending on the flags value of the calling convention.

Returns the delta for the stack counter.

setCallArgsRet(self, emu, args=None, ra=None)

source code 

Modifies the arguments and return address. No allocation is performed.

If the return address is None, sets return address to instruction after the address currently set as the return address.

Expects to be called at the function entrypoint.

setupCall(self, emu, args=None, ra=None)

source code 

Sets up a function with the given args and the specified return address. Allocates space for the arguments and the return address, sets the args and return address.

If the return address is None, sets return address to the current program counter.

execCallReturn(self, emu, value, argc)

source code 

Forces a function to return the specified value.

Reads the return address from the stack, deallocates the stack space allocated for the call, sets the return value, and sets the program counter to the previously read return address.

Expects to be called at the function entrypoint.