decompiler
1.0.0
|
A light-weight class for analyzing pointers and aliasing on the stack. More...
#include <varmap.hh>
Classes | |
struct | AddBase |
A helper class holding a Varnode pointer reference and a possible index added to it. More... | |
Public Member Functions | |
AliasChecker () | |
Constructor. | |
void | gather (const Funcdata *f, AddrSpace *spc, bool defer) |
Gather Varnodes that point on the stack. More... | |
bool | hasLocalAlias (Varnode *vn) const |
Return true if it looks like the given Varnode is aliased by a pointer. More... | |
void | sortAlias (void) const |
Sort the alias starting offsets. | |
const vector< AddBase > & | getAddBase (void) const |
Get the collection of pointer Varnodes. | |
const vector< uintb > & | getAlias (void) const |
Get the list of alias starting offsets. | |
Static Public Member Functions | |
static void | gatherAdditiveBase (Varnode *startvn, vector< AddBase > &addbase) |
Gather result Varnodes for all sums that the given starting Varnode is involved in. More... | |
static uintb | gatherOffset (Varnode *vn) |
If the given Varnode is a sum result, return the constant portion of this sum. More... | |
Private Member Functions | |
void | deriveBoundaries (const FuncProto &proto) |
Set up basic boundaries for the stack layout. More... | |
void | gatherInternal (void) const |
Run through Varnodes looking for pointers into the stack. More... | |
Private Attributes | |
const Funcdata * | fd |
Function being searched for aliases. | |
AddrSpace * | space |
AddressSpace in which to search. | |
vector< AddBase > | addBase |
Collection of pointers into the AddressSpace. | |
vector< uintb > | alias |
List of aliased addresses (as offsets) | |
bool | calculated |
Have aliases been calculated. | |
uintb | localExtreme |
Largest possible offset for a local variable. | |
uintb | localBoundary |
Boundary offset separating locals and parameters. | |
uintb | aliasBoundary |
Shallowest alias. | |
int4 | direction |
1=stack grows negative, -1=positive | |
A light-weight class for analyzing pointers and aliasing on the stack.
The gather() method looks for pointer references into a specific AddressSpace (usually the stack). Then hasLocalAlias() checks if a specific Varnode within the AddressSpace is (possibly) aliased by one of the gathered pointer references.
|
private |
Set up basic boundaries for the stack layout.
Set up basic offset boundaries for what constitutes a local variable or a parameter on the stack. This can be informed by the ProtoModel if available.
proto | is the function prototype to use as a prototype model |
References Range::getLast(), FuncProto::getLocalRange(), FuncProto::getParamRange(), and FuncProto::hasModel().
Gather Varnodes that point on the stack.
For the given function and address space, gather all Varnodes that are pointers into the address space. The actual calculation can be deferred until the first time hasLocalAlias() is called.
f | is the given function |
spc | is the given address space |
defer | is true is gathering is deferred |
References Scope::fd, Funcdata::getFuncProto(), ScopeLocal::space, and AddrSpace::stackGrowsNegative().
Referenced by ActionActiveParam::apply(), and MapState::gatherOpen().
Gather result Varnodes for all sums that the given starting Varnode is involved in.
For every sum that involves startvn, collect the final result Varnode of the sum. A sum is any expression involving only the additive operators INT_ADD, INT_SUB, PTRADD, PTRSUB, and SEGMENTOP. The routine traverses forward recursively through all descendants of vn that are additive operations and collects all the roots of the traversed trees.
startvn | is the Varnode to trace |
addbase | will contain all the collected roots |
References Varnode::beginDescend(), PcodeOp::code(), CPUI_COPY, CPUI_INT_ADD, CPUI_INT_SUB, CPUI_PTRADD, CPUI_PTRSUB, CPUI_SEGMENTOP, Varnode::endDescend(), PcodeOp::getIn(), PcodeOp::getOut(), Varnode::isConstant(), Varnode::isMark(), and Varnode::setMark().
|
private |
Run through Varnodes looking for pointers into the stack.
If there is an AddrSpace (stack) pointer, find its input Varnode, and look for additive uses of it. Once all these Varnodes are accumulated, calculate specific offsets that start a region being aliased.
References AddrSpace::addressToByte(), Scope::fd, Funcdata::findSpacebaseInput(), AddrSpace::getWordSize(), and ScopeLocal::space.
|
static |
If the given Varnode is a sum result, return the constant portion of this sum.
Treat vn as the result of a series of ADD operations. Examine all the constant terms of this sum and add them together by traversing the syntax tree rooted at vn, backwards, only through additive operations.
vn | is the given Varnode to gather off of |
References calc_mask(), PcodeOp::code(), CPUI_COPY, CPUI_INT_ADD, CPUI_INT_SUB, CPUI_PTRADD, CPUI_PTRSUB, CPUI_SEGMENTOP, Varnode::getDef(), PcodeOp::getIn(), Varnode::getOffset(), Varnode::getSize(), and Varnode::isConstant().
bool AliasChecker::hasLocalAlias | ( | Varnode * | vn | ) | const |
Return true if it looks like the given Varnode is aliased by a pointer.
This is gives a rough analysis of whether the given Varnode might be aliased by another pointer in the function. If false is returned, the Varnode is not likely to have an alias. If true is returned, the Varnode might have an alias.
vn | is the given Varnode |
References Varnode::getOffset(), Varnode::getSpace(), and ScopeLocal::space.
Referenced by FuncCallSpecs::checkInputTrialUse().