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 ghidra::Range::getLast(), ghidra::FuncProto::getLocalRange(), ghidra::FuncProto::getParamRange(), and ghidra::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 ghidra::Scope::fd, ghidra::Funcdata::getFuncProto(), ghidra::ScopeLocal::space, and ghidra::AddrSpace::stackGrowsNegative().
Referenced by ghidra::ActionActiveParam::apply(), and ghidra::MapState::gatherOpen().
|
static |
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 ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_SUB, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_SEGMENTOP, ghidra::Varnode::endDescend(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::Varnode::isConstant(), ghidra::Varnode::isMark(), and ghidra::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 ghidra::AddrSpace::addressToByte(), ghidra::Scope::fd, ghidra::Funcdata::findSpacebaseInput(), ghidra::AddrSpace::getWordSize(), and ghidra::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 ghidra::calc_mask(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_SUB, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_SEGMENTOP, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), and ghidra::Varnode::isConstant().
bool ghidra::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 ghidra::Varnode::getOffset(), ghidra::Varnode::getSpace(), and ghidra::ScopeLocal::space.
Referenced by ghidra::FuncCallSpecs::checkInputTrialUse().