decompiler  1.0.0
Public Member Functions | Private Attributes | List of all members
JumpModelTrivial Class Reference

A trivial jump-table model, where the BRANCHIND input Varnode is the switch variable. More...

#include <jumptable.hh>

Inheritance diagram for JumpModelTrivial:
JumpModel

Public Member Functions

 JumpModelTrivial (JumpTable *jt)
 Construct given a parent JumpTable.
 
virtual bool isOverride (void) const
 Return true if this model was manually overridden.
 
virtual int4 getTableSize (void) const
 Return the number of entries in the address table.
 
virtual bool recoverModel (Funcdata *fd, PcodeOp *indop, uint4 matchsize, uint4 maxtablesize)
 Attempt to recover details of the model, given a specific BRANCHIND. More...
 
virtual void buildAddresses (Funcdata *fd, PcodeOp *indop, vector< Address > &addresstable, vector< LoadTable > *loadpoints) const
 Construct the explicit list of target addresses (the Address Table) from this model. More...
 
virtual void findUnnormalized (uint4 maxaddsub, uint4 maxleftright, uint4 maxext)
 Recover the unnormalized switch variable. More...
 
virtual void buildLabels (Funcdata *fd, vector< Address > &addresstable, vector< uintb > &label, const JumpModel *orig) const
 Recover case labels associated with the Address table. More...
 
virtual VarnodefoldInNormalization (Funcdata *fd, PcodeOp *indop)
 Do normalization of the given switch specific to this model. More...
 
virtual bool foldInGuards (Funcdata *fd, JumpTable *jump)
 Eliminate any guard code involved in computing the switch destination. More...
 
virtual bool sanityCheck (Funcdata *fd, PcodeOp *indop, vector< Address > &addresstable)
 Perform a sanity check on recovered addresses. More...
 
virtual JumpModelclone (JumpTable *jt) const
 Clone this model.
 
- Public Member Functions inherited from JumpModel
 JumpModel (JumpTable *jt)
 Construct given a parent jump-table.
 
virtual ~JumpModel (void)
 Destructor.
 
virtual void clear (void)
 Clear any non-permanent aspects of the model.
 
virtual void saveXml (ostream &s) const
 Save this model as an XML tag.
 
virtual void restoreXml (const Element *el, Architecture *glb)
 Restore this model from an XML tag.
 

Private Attributes

uint4 size
 Number of addresses in the table as reported by the JumpTable.
 

Additional Inherited Members

- Protected Attributes inherited from JumpModel
JumpTablejumptable
 The jump-table that is building this model.
 

Detailed Description

A trivial jump-table model, where the BRANCHIND input Varnode is the switch variable.

This class treats the input Varnode to the BRANCHIND as the switch variable, and recovers its possible values from the existing block structure. This is used when the flow following fork recovers destination addresses, but the switch normalization action is unable to recover the model.

Member Function Documentation

void JumpModelTrivial::buildAddresses ( Funcdata fd,
PcodeOp indop,
vector< Address > &  addresstable,
vector< LoadTable > *  loadpoints 
) const
virtual

Construct the explicit list of target addresses (the Address Table) from this model.

The addresses produced all come from the BRANCHIND and may not be deduped. Alternate guard destinations are not yet included.

Parameters
fdis the function containing the switch
indopis the root BRANCHIND of the switch
addresstablewill hold the list of Addresses
loadpointsif non-null will hold LOAD table information used by the model

Implements JumpModel.

References FlowBlock::getOut(), PcodeOp::getParent(), BlockBasic::getStart(), and FlowBlock::sizeOut().

void JumpModelTrivial::buildLabels ( Funcdata fd,
vector< Address > &  addresstable,
vector< uintb > &  label,
const JumpModel orig 
) const
virtual

Recover case labels associated with the Address table.

The unnormalized switch variable must already be recovered. Values that the normalized switch value can hold or walked back to obtain the value that the unnormalized switch variable would hold. Labels are returned in the order provided by normalized switch variable iterator JumpValues.

Parameters
fdis the function containing the switch
addresstableis the address table (used to label code blocks with bad or missing labels)
labelwill hold recovered labels in JumpValues order
origis the JumpModel to use for the JumpValues iterator

Implements JumpModel.

virtual void JumpModelTrivial::findUnnormalized ( uint4  maxaddsub,
uint4  maxleftright,
uint4  maxext 
)
inlinevirtual

Recover the unnormalized switch variable.

The normalized switch variable must already be recovered. The amount of normalization between the two switch variables can be restricted.

Parameters
maxaddsubis a restriction on arithmetic operations
maxleftrightis a restriction on shift operations
maxextis a restriction on extension operations

Implements JumpModel.

virtual bool JumpModelTrivial::foldInGuards ( Funcdata fd,
JumpTable jump 
)
inlinevirtual

Eliminate any guard code involved in computing the switch destination.

We now think of the BRANCHIND as encompassing any guard function.

Parameters
fdis the function containing the switch
jumpis the JumpTable owning this model.

Implements JumpModel.

virtual Varnode* JumpModelTrivial::foldInNormalization ( Funcdata fd,
PcodeOp indop 
)
inlinevirtual

Do normalization of the given switch specific to this model.

The PcodeOp machinery is removed so it looks like the CPUI_BRANCHIND simply takes the switch variable as an input Varnode and automatically interprets its values to reach the correct destination.

Parameters
fdis the function containing the switch
indopis the given switch as a CPUI_BRANCHIND
Returns
the Varnode holding the final unnormalized switch variable

Implements JumpModel.

bool JumpModelTrivial::recoverModel ( Funcdata fd,
PcodeOp indop,
uint4  matchsize,
uint4  maxtablesize 
)
virtual

Attempt to recover details of the model, given a specific BRANCHIND.

This generally recovers the normalized switch variable and any guards.

Parameters
fdis the function containing the switch
indopis the given BRANCHIND
matchsizeis the expected number of address table entries to recover, or 0 for no expectation
maxtablesizeis maximum number of address table entries to allow in the model
Returns
true if details of the model were successfully recovered

Implements JumpModel.

References PcodeOp::getParent(), and FlowBlock::sizeOut().

virtual bool JumpModelTrivial::sanityCheck ( Funcdata fd,
PcodeOp indop,
vector< Address > &  addresstable 
)
inlinevirtual

Perform a sanity check on recovered addresses.

Individual addresses are checked against the function or its program to determine if they are reasonable. This method can optionally remove addresses from the table. If it does so, the underlying model is changed to reflect the removal.

Parameters
fdis the function containing the switch
indopis the root BRANCHIND of the switch
addresstableis the list of recovered Addresses, which may be modified
Returns
true if there are (at least some) reasonable addresses in the table

Implements JumpModel.


The documentation for this class was generated from the following files: