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

A class that solves for stack-pointer changes across unknown sub-functions. More...

Public Member Functions

void solve (void)
 Solve the system of equations.
 
void build (const Funcdata &data, AddrSpace *id, int4 spcbase)
 Build the system of equations. More...
 
int4 getNumVariables (void) const
 Get the number of variables in the system.
 
VarnodegetVariable (int4 i) const
 Get the i-th Varnode variable.
 
int4 getCompanion (int4 i) const
 Get the i-th variable's companion index.
 
int4 getSolution (int4 i) const
 Get the i-th variable's solution.
 

Private Member Functions

void duplicate (void)
 Duplicate each equation, multiplying by -1.
 
void propagate (int4 varnum, int4 val)
 Propagate solution for one variable to other variables. More...
 

Private Attributes

vector< StackEqneqs
 Known equations based on operations that explicitly change the stack-pointer.
 
vector< StackEqnguess
 Guessed equations for underdetermined systems.
 
vector< Varnode * > vnlist
 The indexed set of variables, one for each reference to the stack-pointer.
 
vector< int4 > companion
 Index of companion input for variable produced by CPUI_INDIRECT.
 
Address spacebase
 Starting address of the stack-pointer.
 
vector< int4 > soln
 Collected solutions (corresponding to array of variables)
 
int4 missedvariables
 Number of variables for which we are missing an equation.
 

Detailed Description

A class that solves for stack-pointer changes across unknown sub-functions.

Member Function Documentation

◆ build()

void StackSolver::build ( const Funcdata data,
AddrSpace id,
int4  spcbase 
)

Build the system of equations.

Collect references to the stack-pointer as variables, and examine their defining PcodeOps to determine equations and coefficient.

Parameters
datais the function being analyzed
idis the stack address space
spcbaseis the index, relative to the stack space, of the stack pointer

References Funcdata::beginLoc(), PcodeOp::code(), companion, Varnode::comparePointers(), CPUI_COPY, CPUI_INDIRECT, CPUI_INT_ADD, CPUI_INT_AND, CPUI_MULTIEQUAL, Funcdata::endLoc(), eqs, ProtoModel::extrapop_unknown, Varnode::getAddr(), Funcdata::getCallSpecs(), Varnode::getDef(), PcodeOp::getIn(), Varnode::getOffset(), PcodeOp::getOpFromConst(), Varnode::getSpace(), AddrSpace::getSpacebase(), AddrSpace::getType(), guess, IPTR_IOP, Varnode::isConstant(), missedvariables, PcodeOp::numInput(), StackEqn::rhs, spacebase, StackEqn::var1, StackEqn::var2, and vnlist.

Referenced by ActionStackPtrFlow::analyzeExtraPop().

◆ propagate()

void StackSolver::propagate ( int4  varnum,
int4  val 
)
private

Propagate solution for one variable to other variables.

Given a solution for one variable, look for equations containing the variable and attempt to solve for the other variable. Continue propagating new solutions to other equations to find even more solutions. Populate the soln array with the solutions.

Parameters
varnumis the index of the initial variable
valis the solution for the variable

References StackEqn::compare(), eqs, soln, and StackEqn::var1.

Referenced by solve().


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