decompiler 1.0.0
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ghidra::Override Class Reference

A container of commands that override the decompiler's default behavior for a single function. More...

#include <override.hh>

Classes

class  Branch
 Override a CALL, CALLIND, or RETURN to become a BRANCH or BRANCHIND. More...
 
class  Call
 Override a BRANCH, BRANCHIND, or RETURN to become a CALL or CALLIND operation. More...
 
class  CallCall
 Convert CALL or CALLIND into a CALL with a new destination address. More...
 
class  CallotherBranch
 Convert a CALLOTHER to a BRANCH. More...
 
class  CallotherCall
 Convert a CALLOTHER to a direct CALL. More...
 
class  CallReturn
 Override a BRANCH, BRANCHIND, or RETURN to become a CALL or CALLIND, followed by a RETURN. More...
 
class  Record
 Abstract class performing an override of p-code on an instruction. More...
 
class  Return
 Override a BRANCHIND or CALLIND to become a RETURN. 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 insertDeindirect (const Address &callPoint, const Address &directAddr)
 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, const string &type)
 Mark a branch instruction with a different flow type. More...
 
void insertDestinationOverride (const Address &addr, const Address &dest, const string &type)
 Change a CALL, CALLIND, or CALLOTHER instruction into a CALL with the specified destination address. 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 hasPCodeOverride (void) const
 Are there any flow overrides.
 
const Record * getPCodeOverride (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 encode (Encoder &encoder, Architecture *glb) const
 Encode the override commands to a stream. More...
 
void decode (Decoder &decoder, Architecture *glb)
 Parse and <override> element containing override commands. 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, Record * > pcodeover
 Raw p-code overrides for instructions.
 
map< Address, Address > forcegoto
 Force goto on jump at targetpc to destpc.
 
vector< int4 > deadcodedelay
 Delay count indexed by address space.
 
map< Address, Address > deindirect
 Convert CALLIND into CALL with recovered direct addr.
 
map< Address, FuncProto * > protoover
 Override prototype at call-point.
 
vector< Address > multistagejump
 Addresses of indirect jumps that need multistage recovery.
 

Detailed Description

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.

Member Function Documentation

◆ applyDeadCodeDelay()

void ghidra::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

Parameters
datais the function

References deadcodedelay, ghidra::Funcdata::getArch(), ghidra::AddrSpaceManager::getSpace(), and ghidra::Funcdata::setDeadCodeDelay().

Referenced by ghidra::Funcdata::startProcessing().

◆ applyForceGoto()

void ghidra::Override::applyForceGoto ( Funcdata &  data) const

Push all the force-goto overrides into the function.

Parameters
datais the function

References ghidra::Funcdata::forceGoto(), and forcegoto.

Referenced by ghidra::ActionForceGoto::apply().

◆ applyIndirect()

void ghidra::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

Parameters
datais (calling) function
fspecsis a reference to the call specification

References deindirect, ghidra::PcodeOp::getAddr(), ghidra::FuncCallSpecs::getOp(), and ghidra::FuncCallSpecs::setAddress().

Referenced by ghidra::FlowInfo::setupCallindSpecs().

◆ applyPrototype()

void ghidra::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

Parameters
datais the (calling) function
fspecsis a reference to the call specification

References ghidra::FuncProto::copy(), ghidra::PcodeOp::getAddr(), ghidra::FuncCallSpecs::getOp(), and protoover.

Referenced by ghidra::FlowInfo::setupCallindSpecs(), and ghidra::FlowInfo::setupCallSpecs().

◆ decode()

void ghidra::Override::decode ( Decoder &  decoder,
Architecture *  glb 
)

◆ encode()

void ghidra::Override::encode ( Encoder &  encoder,
Architecture *  glb 
) const

Encode the override commands to a stream.

All the commands are written as children of a root <override> element.

Parameters
encoderis the stream encoder
glbis the Architecture

References ghidra::Encoder::closeElement(), deadcodedelay, deindirect, forcegoto, ghidra::AddrSpaceManager::getSpace(), multistagejump, ghidra::Encoder::openElement(), pcodeover, protoover, ghidra::Encoder::writeSignedInteger(), and ghidra::Encoder::writeSpace().

Referenced by ghidra::Funcdata::encode().

◆ generateDeadcodeDelayMessage()

string ghidra::Override::generateDeadcodeDelayMessage ( int4  index,
Architecture *  glb 
)
staticprivate

Generate warning message related to a dead code delay.

This is triggered by the insertDeadcodeDelay() command on a specific address space

Parameters
indexis the index of the address space
glbis the Architecture object
Returns
the generated message

References ghidra::AddrSpace::getName(), and ghidra::AddrSpaceManager::getSpace().

Referenced by generateOverrideMessages().

◆ generateOverrideMessages()

void ghidra::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

Parameters
messagelistwill hold the generated list of messages
glbis the Architecture

References deadcodedelay, and generateDeadcodeDelayMessage().

Referenced by ghidra::ActionPrototypeWarnings::apply().

◆ getPCodeOverride()

const Override::Record * ghidra::Override::getPCodeOverride ( const Address &  addr) const

Return the particular flow override at a given address.

Parameters
addris the address of a branch instruction
Returns
the override record or null if there is no override

References pcodeover.

Referenced by ghidra::FlowInfo::processInstruction().

◆ hasDeadcodeDelay()

bool ghidra::Override::hasDeadcodeDelay ( AddrSpace *  spc) const

Check if a delay override is already installed for an address space.

Parameters
spcis the address space
Returns
true if an override has already been installed

References deadcodedelay, ghidra::AddrSpace::getDeadcodeDelay(), and ghidra::AddrSpace::getIndex().

Referenced by ghidra::Heritage::bumpDeadcodeDelay().

◆ insertDeadcodeDelay()

void ghidra::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.

Parameters
spcis the address space to modify
delayis the size of the delay (in passes)

References deadcodedelay, and ghidra::AddrSpace::getIndex().

Referenced by ghidra::Heritage::bumpDeadcodeDelay(), decode(), and ghidra::IfcDeadcodedelay::execute().

◆ insertDeindirect()

void ghidra::Override::insertDeindirect ( const Address &  callPoint,
const Address &  directAddr 
)

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

Parameters
callPointis the address of the indirect call
directAddris the target address of the direct call

References deindirect.

Referenced by ghidra::FuncCallSpecs::deindirect().

◆ insertDestinationOverride()

void ghidra::Override::insertDestinationOverride ( const Address &  addr,
const Address &  dest,
const string &  type 
)

Change a CALL, CALLIND, or CALLOTHER instruction into a CALL with the specified destination address.

Parameters
addris the address of the instruction
destis the new destination address
typeis the type of override to force

References ghidra::Override::Record::allocateCallDest(), and pcodeover.

Referenced by ghidra::Architecture::decodeFlowOverride(), and ghidra::IfcDestinationOverride::execute().

◆ insertFlowOverride()

void ghidra::Override::insertFlowOverride ( const Address &  addr,
const string &  type 
)

Mark a branch instruction with a different flow type.

Change the interpretation of a BRANCH, CALL, or RETURN

Parameters
addris the address of the branch instruction
typeis the type of flow that should be forced

References ghidra::Override::Record::allocateFlow(), and pcodeover.

Referenced by ghidra::Architecture::decodeFlowOverride(), and ghidra::IfcFlowOverride::execute().

◆ insertForceGoto()

void ghidra::Override::insertForceGoto ( const Address &  targetpc,
const Address &  destpc 
)

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

Parameters
targetpcis the address of the branch instruction
destpcis the destination address of the branch

References forcegoto.

Referenced by decode(), and ghidra::IfcForcegoto::execute().

◆ insertMultistageJump()

void ghidra::Override::insertMultistageJump ( const Address &  addr)

Flag an indirect jump for multistage analysis.

Parameters
addris the address of the indirect jump

References multistagejump.

Referenced by decode(), and ghidra::JumpTable::matchModel().

◆ insertProtoOverride()

void ghidra::Override::insertProtoOverride ( const Address &  callpoint,
FuncProto *  p 
)

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).

Parameters
callpointis the address of the call instruction
pis the overriding function prototype

References protoover, and ghidra::FuncProto::setOverride().

Referenced by decode(), ghidra::IfcProtooverride::execute(), and ghidra::FuncCallSpecs::forceSet().

◆ printRaw()

void ghidra::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

Parameters
sis the output stream
glbis the Architecture

References deadcodedelay, deindirect, forcegoto, ghidra::AddrSpace::getName(), ghidra::AddrSpaceManager::getSpace(), pcodeover, and protoover.

Referenced by ghidra::IfcListOverride::execute().

◆ queryMultistageJumptable()

bool ghidra::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

Parameters
addris the address of the indirect jump

References multistagejump.

Referenced by ghidra::JumpTable::checkForMultistage().


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