Package envi :: Module codeflow :: Class CodeFlowContext
[hide private]
[frames] | no frames]

Class CodeFlowContext

source code



A CodeFlowContext is used for code-flow (not linear) based disassembly
for an envi MemoryObject (which is responsible for knowing the
implementation of parseOpcode().  The CodeFlowContext will optionally
notify several callback handlers for different events which occur during
disassembly:

self._cb_opcode(va, op, branches) - called for every newly parsed opcode
    NOTE: _cb_opcode must return the desired branches for continued flow

self._cb_function(fva, metadict) - called once for every function

self._cb_branchtable(tabva, ptrva, destva) - called for switch tables
    NOTE: Return False to stop iteration of pointers

Set exptable=True to expand branch tables in this phase
Set persist=True to never disasm the same thing twice
Set recurse=True to automatically code flow to nested functions

Instance Methods [hide private]
 
__init__(self, mem, persist=False, exptable=True, recurse=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_cb_opcode(self, va, op, branches)
Extend CodeFlowContext and implement this method to recieve a callback for every newly discovered opcode.
source code
 
_cb_function(self, fva, fmeta)
Extend CodeFlowContext and implement this method to recieve a callback for every newly discovered function.
source code
 
_cb_noflow(self, va, tva)
Implement this method to receive a callback when a given code branch is skipped due to being in the noflow dictionary.
source code
 
_cb_branchtable(self, tableva, ptrva, destva)
Extend CodeFlowContext and implement this method to receive a callback for every conditional branch in a discovered "branch table" ( think jump/switch cases ).
source code
 
addNoReturnAddr(self, va)
Add a virtual address to the list of VAs that are non-returning procedural branch targets.
source code
 
addNoFlow(self, va, destva)
Add a va->destva no-flow entry which will prevent codeflow from continuing to destva as a result of va ( destva may still be decoded as a result of being reached some other way...
source code
 
getCallsFrom(self, fva) source code
 
addFunctionDef(self, fva, calls_from)
Add a priori knowledge of a function to the code flow stuff...
source code
 
addCodeFlow(self, va, arch=envi.ARCH_DEFAULT)
Do code flow disassembly from the specified address.
source code
 
addEntryPoint(self, va, arch=envi.ARCH_DEFAULT)
Analyze the given procedure entry point and flow downward to find all subsequent code blocks and procedure edges.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, mem, persist=False, exptable=True, recurse=True)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_cb_function(self, fva, fmeta)

source code 

Extend CodeFlowContext and implement this method to recieve a callback for every newly discovered function. Additionally, metadata about the function may be stored in the fmeta dict.

_cb_noflow(self, va, tva)

source code 

Implement this method to receive a callback when a given code branch is skipped due to being in the noflow dictionary. ( likely due to prodedural branch to noreturn address )

_cb_branchtable(self, tableva, ptrva, destva)

source code 

Extend CodeFlowContext and implement this method to receive a callback for every conditional branch in a discovered "branch table" ( think jump/switch cases ). tableva - The base address of the table ptrva - The address of the pointer for this index destva - The destination address (deref of ptrva)

Return False to stop table iteration.

addNoFlow(self, va, destva)

source code 

Add a va->destva no-flow entry which will prevent codeflow from continuing to destva as a result of va ( destva may still be decoded as a result of being reached some other way... )

addCodeFlow(self, va, arch=envi.ARCH_DEFAULT)

source code 

Do code flow disassembly from the specified address. Returnes a list of the procedural branch targets discovered during code flow...

Set persist=True to store 'opdone' and never disassemble the same thing twice

addEntryPoint(self, va, arch=envi.ARCH_DEFAULT)

source code 

Analyze the given procedure entry point and flow downward
to find all subsequent code blocks and procedure edges.

Example:
    cf.addEntryPoint( 0x77c70308 )
    ... callbacks flow along ...