decompiler
1.0.0
|
A container of commands that override the decompiler's default behavior for a single function. More...
#include <override.hh>
Public Types | |
enum | { NONE = 0, BRANCH = 1, CALL = 2, CALL_RETURN = 3, RETURN = 4 } |
Enumeration of possible branch overrides. More... | |
Public Member Functions | |
~Override (void) | |
Destructor. | |
void | insertForceGoto (const Address &targetpc, const Address &destpc) |
Force a specific branch instruction to be an unstructured goto. More... | |
void | insertDeadcodeDelay (AddrSpace *spc, int4 delay) |
Override the number of passes that are executed before dead-code elimination starts. More... | |
bool | hasDeadcodeDelay (AddrSpace *spc) const |
Check if a delay override is already installed for an address space. More... | |
void | insertIndirectOverride (const Address &callpoint, const Address &directcall) |
Override an indirect call turning it into a direct call. More... | |
void | insertProtoOverride (const Address &callpoint, FuncProto *p) |
Override the assumed function prototype at a specific call site. More... | |
void | insertMultistageJump (const Address &addr) |
Flag an indirect jump for multistage analysis. More... | |
void | insertFlowOverride (const Address &addr, uint4 type) |
Mark a branch instruction with a different flow type. More... | |
void | applyPrototype (Funcdata &data, FuncCallSpecs &fspecs) const |
Look for and apply a function prototype override. More... | |
void | applyIndirect (Funcdata &data, FuncCallSpecs &fspecs) const |
Look for and apply destination overrides of indirect calls. More... | |
bool | queryMultistageJumptable (const Address &addr) const |
Check for a multistage marker for a specific indirect jump. More... | |
void | applyDeadCodeDelay (Funcdata &data) const |
Apply any dead-code delay overrides. More... | |
void | applyForceGoto (Funcdata &data) const |
Push all the force-goto overrides into the function. More... | |
bool | hasFlowOverride (void) const |
Are there any flow overrides. | |
uint4 | getFlowOverride (const Address &addr) const |
Return the particular flow override at a given address. More... | |
void | printRaw (ostream &s, Architecture *glb) const |
Dump a description of the overrides to stream. More... | |
void | generateOverrideMessages (vector< string > &messagelist, Architecture *glb) const |
Create warning messages that describe current overrides. More... | |
void | saveXml (ostream &s, Architecture *glb) const |
Write the override commands to an XML stream. More... | |
void | restoreXml (const Element *el, Architecture *glb) |
Read in override commands from XML. More... | |
Static Public Member Functions | |
static string | typeToString (uint4 tp) |
Convert a flow override type to a string. More... | |
static uint4 | stringToType (const string &nm) |
Convert a string to a flow override type. More... | |
Private Member Functions | |
void | clear (void) |
Clear the entire set of overrides. | |
Static Private Member Functions | |
static string | generateDeadcodeDelayMessage (int4 index, Architecture *glb) |
Generate warning message related to a dead code delay. More... | |
Private Attributes | |
map< Address, Address > | forcegoto |
Force goto on jump at targetpc to destpc. | |
vector< int4 > | deadcodedelay |
Delay count indexed by address space. | |
map< Address, Address > | indirectover |
Override indirect at call-point into direct to addr. | |
map< Address, FuncProto * > | protoover |
Override prototype at call-point. | |
vector< Address > | multistagejump |
Addresses of indirect jumps that need multistage recovery. | |
map< Address, uint4 > | flowoverride |
Override the CALL <-> BRANCH. | |
A container of commands that override the decompiler's default behavior for a single function.
Information about a particular function that can be overridden includes:
Commands exist independently of the main data-flow, control-flow, and symbol structures and survive decompilation restart. A few analyses, mid transformation, insert a new command to fix a problem that was discovered too late and then force a restart via Funcdata::setRestartPending()
The class accept new commands via the insert* methods. The decompiler applies them by calling the apply* or get* methods.
anonymous enum |
Enumeration of possible branch overrides.
void Override::applyDeadCodeDelay | ( | Funcdata & | data | ) | const |
Apply any dead-code delay overrides.
Look for delays of each address space and apply them to the Heritage object
data | is the function |
References deadcodedelay, Funcdata::getArch(), AddrSpaceManager::getSpace(), and Funcdata::setDeadCodeDelay().
Referenced by Funcdata::startProcessing().
void Override::applyForceGoto | ( | Funcdata & | data | ) | const |
Push all the force-goto overrides into the function.
data | is the function |
References forcegoto, and Funcdata::forceGoto().
Referenced by ActionForceGoto::apply().
void Override::applyIndirect | ( | Funcdata & | data, |
FuncCallSpecs & | fspecs | ||
) | const |
Look for and apply destination overrides of indirect calls.
Given an indirect call, look for any overrides, then copy in the overriding target address of the direct call
data | is (calling) function |
fspecs | is a reference to the call specification |
References PcodeOp::getAddr(), FuncCallSpecs::getOp(), indirectover, and FuncCallSpecs::setAddress().
Referenced by FlowInfo::setupCallindSpecs().
void Override::applyPrototype | ( | Funcdata & | data, |
FuncCallSpecs & | fspecs | ||
) | const |
Look for and apply a function prototype override.
Given a call point, look for a prototype override and copy the call specification in
data | is the (calling) function |
fspecs | is a reference to the call specification |
References FuncProto::copy(), PcodeOp::getAddr(), FuncCallSpecs::getOp(), and protoover.
Referenced by FlowInfo::setupCallindSpecs(), and FlowInfo::setupCallSpecs().
|
staticprivate |
Generate warning message related to a dead code delay.
This is triggered by the insertDeadcodeDelay() command on a specific address space
index | is the index of the address space |
glb | is the Architecture object |
References AddrSpace::getName(), and AddrSpaceManager::getSpace().
Referenced by generateOverrideMessages().
void Override::generateOverrideMessages | ( | vector< string > & | messagelist, |
Architecture * | glb | ||
) | const |
Create warning messages that describe current overrides.
Message are designed to be displayed in the function header comment
messagelist | will hold the generated list of messages |
glb | is the Architecture |
References deadcodedelay, and generateDeadcodeDelayMessage().
Referenced by ActionPrototypeWarnings::apply().
uint4 Override::getFlowOverride | ( | const Address & | addr | ) | const |
Return the particular flow override at a given address.
addr | is the address of a branch instruction |
References flowoverride, and NONE.
Referenced by FlowInfo::processInstruction().
bool Override::hasDeadcodeDelay | ( | AddrSpace * | spc | ) | const |
Check if a delay override is already installed for an address space.
spc | is the address space |
References deadcodedelay, AddrSpace::getDeadcodeDelay(), and AddrSpace::getIndex().
Referenced by Heritage::bumpDeadcodeDelay().
void Override::insertDeadcodeDelay | ( | AddrSpace * | spc, |
int4 | delay | ||
) |
Override the number of passes that are executed before dead-code elimination starts.
Every address space has an assigned delay (which may be zero) before a PcodeOp involving a Varnode in that address space can be eliminated. This command allows the delay for a specific address space to be increased so that new Varnode accesses can be discovered.
spc | is the address space to modify |
delay | is the size of the delay (in passes) |
References deadcodedelay, and AddrSpace::getIndex().
Referenced by Heritage::bumpDeadcodeDelay(), and restoreXml().
void Override::insertFlowOverride | ( | const Address & | addr, |
uint4 | type | ||
) |
Mark a branch instruction with a different flow type.
Change the interpretation of a BRANCH, CALL, or RETURN
addr | is the address of the branch instruction |
type | is the type of flow that should be forced |
References flowoverride.
Referenced by Architecture::restoreFlowOverride(), and restoreXml().
Force a specific branch instruction to be an unstructured goto.
The command is specified as the address of the branch instruction and the destination address of the branch. The decompiler will automatically mark this as a unstructured, when trying to structure the control-flow
targetpc | is the address of the branch instruction |
destpc | is the destination address of the branch |
References forcegoto.
Referenced by restoreXml().
Override an indirect call turning it into a direct call.
The command consists of the address of the indirect call instruction and the target address of the direct address
callpoint | is the address of the indirect call |
directcall | is the target address of the direct call |
References indirectover.
Referenced by FuncCallSpecs::deindirect(), and restoreXml().
void Override::insertMultistageJump | ( | const Address & | addr | ) |
Flag an indirect jump for multistage analysis.
addr | is the address of the indirect jump |
References multistagejump.
Referenced by ActionSwitchNorm::apply(), and restoreXml().
Override the assumed function prototype at a specific call site.
The exact input and output storage locations are overridden for a specific call instruction (direct or indirect).
callpoint | is the address of the call instruction |
p | is the overriding function prototype |
References protoover.
Referenced by FuncCallSpecs::forceSet(), and restoreXml().
void Override::printRaw | ( | ostream & | s, |
Architecture * | glb | ||
) | const |
Dump a description of the overrides to stream.
Give a description of each override, one per line, that is suitable for debug
s | is the output stream |
glb | is the Architecture |
References deadcodedelay, forcegoto, AddrSpace::getName(), AddrSpaceManager::getSpace(), and protoover.
bool Override::queryMultistageJumptable | ( | const Address & | addr | ) | const |
Check for a multistage marker for a specific indirect jump.
Given the address of an indirect jump, look for the multistate command
addr | is the address of the indirect jump |
References multistagejump.
void Override::restoreXml | ( | const Element * | el, |
Architecture * | glb | ||
) |
Read in override commands from XML.
el | is the root <override> element |
glb | is the Architecture |
References Architecture::defaultfp, AddrSpaceManager::getSpaceByName(), TypeFactory::getTypeVoid(), insertDeadcodeDelay(), insertFlowOverride(), insertForceGoto(), insertIndirectOverride(), insertMultistageJump(), insertProtoOverride(), Address::isInvalid(), NONE, Address::restoreXml(), FuncProto::restoreXml(), FuncProto::setInternal(), stringToType(), and Architecture::types.
void Override::saveXml | ( | ostream & | s, |
Architecture * | glb | ||
) | const |
Write the override commands to an XML stream.
All the commands are written as sub-tags of a root <override> tag.
s | is the output stream |
glb | is the Architecture |
References deadcodedelay, flowoverride, forcegoto, AddrSpace::getName(), AddrSpaceManager::getSpace(), indirectover, multistagejump, protoover, and typeToString().
|
static |
Convert a string to a flow override type.
nm | is the override name |
References BRANCH, CALL, CALL_RETURN, NONE, and RETURN.
Referenced by Architecture::restoreFlowOverride(), and restoreXml().
|
static |
Convert a flow override type to a string.
tp | is the override type |
References BRANCH, CALL, CALL_RETURN, and RETURN.
Referenced by saveXml().