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

Concatenating structure pieces gets printed as explicit write statements. More...

Inheritance diagram for ghidra::RulePieceStructure:
ghidra::Rule

Public Member Functions

 RulePieceStructure (const string &g)
 Constructor.
 
virtual Ruleclone (const ActionGroupList &grouplist) const
 Clone the Rule. More...
 
virtual void getOpList (vector< uint4 > &oplist) const
 List of op codes this rule operates on. More...
 
virtual int4 applyOp (PcodeOp *op, Funcdata &data)
 Attempt to apply this Rule. More...
 
- Public Member Functions inherited from ghidra::Rule
 Rule (const string &g, uint4 fl, const string &nm)
 Construct given group, properties name. More...
 
virtual ~Rule (void)
 Destructor.
 
const string & getName (void) const
 Return the name of this Rule.
 
const string & getGroup (void) const
 Return the group this Rule belongs to.
 
uint4 getNumTests (void)
 Get number of attempted applications.
 
uint4 getNumApply (void)
 Get number of successful applications.
 
void setBreak (uint4 tp)
 Set a breakpoint on this Rule.
 
void clearBreak (uint4 tp)
 Clear a breakpoint on this Rule.
 
void clearBreakPoints (void)
 Clear all breakpoints on this Rule.
 
void turnOnWarnings (void)
 Enable warnings for this Rule.
 
void turnOffWarnings (void)
 Disable warnings for this Rule.
 
bool isDisabled (void) const
 Return true if this Rule is disabled.
 
void setDisable (void)
 Disable this Rule (within its pool)
 
void clearDisable (void)
 Enable this Rule (within its pool)
 
bool checkActionBreak (void)
 Check if an action breakpoint is turned on. More...
 
uint4 getBreakPoint (void) const
 Return breakpoint toggles.
 
virtual void reset (Funcdata &data)
 Reset this Rule. More...
 
virtual void resetStats (void)
 Reset Rule statistics. More...
 
virtual void printStatistics (ostream &s) const
 Print statistics for this Rule. More...
 

Static Private Member Functions

static DatatypedetermineDatatype (Varnode *vn, int4 &baseOffset)
 Markup for Varnodes pieced together into structure/array. More...
 
static bool spanningRange (Datatype *ct, int4 off, int4 size)
 For a structured data-type, determine if the given range spans multiple elements. More...
 
static bool convertZextToPiece (PcodeOp *zext, Datatype *structuredType, int4 offset, Funcdata &data)
 Convert an INT_ZEXT operation to a PIECE with a zero constant as the first parameter. More...
 
static bool findReplaceZext (vector< PieceNode > &stack, Datatype *structuredType, Funcdata &data)
 Search for leaves in the CONCAT tree defined by an INT_ZEXT operation and convert them to PIECE. More...
 
static bool separateSymbol (Varnode *root, Varnode *leaf)
 Return true if the two given root and leaf should be part of different symbols. More...
 

Additional Inherited Members

- Public Types inherited from ghidra::Rule
enum  typeflags { type_disable = 1, rule_debug = 2, warnings_on = 4, warnings_given = 8 }
 Properties associated with a Rule. More...
 

Detailed Description

Concatenating structure pieces gets printed as explicit write statements.

Set properties so that a CONCAT expression like v = CONCAT(CONCAT(v1,v2),CONCAT(v3,v4)) gets rendered as a sequence of separate write statements. v.field1 = v1; v.field2 = v2; v.field3 = v3; v.field4 = v4;

Member Function Documentation

◆ applyOp()

int4 ghidra::RulePieceStructure::applyOp ( PcodeOp op,
Funcdata data 
)
virtual

Attempt to apply this Rule.

This method contains the main logic for applying the Rule. It must use a given PcodeOp as the point at which the Rule applies. If it does apply, changes are made directly to the function and 1 (non-zero) is returned, otherwise 0 is returned.

Parameters
opis the given PcodeOp where the Rule may apply
datais the function to which to apply

Reimplemented from ghidra::Rule.

References ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_PIECE, ghidra::AddTreeState::ct, ghidra::AddTreeState::data, ghidra::Funcdata::deleteVarnode(), ghidra::PieceNode::gatherPieces(), ghidra::PcodeOp::getAddr(), ghidra::Varnode::getAddr(), ghidra::Funcdata::getArch(), ghidra::Varnode::getDef(), ghidra::TypeFactory::getExactPiece(), ghidra::Funcdata::getMerge(), ghidra::PieceNode::getOp(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getSlot(), ghidra::PieceNode::getSlot(), ghidra::Varnode::getType(), ghidra::PieceNode::getTypeOffset(), ghidra::PieceNode::getVarnode(), ghidra::Funcdata::inheritResolution(), ghidra::Varnode::isAddrTied(), ghidra::PieceNode::isLeaf(), ghidra::PcodeOp::isPartialRoot(), ghidra::Varnode::isProtoPartial(), ghidra::Varnode::loneDescend(), ghidra::Datatype::needsResolution(), ghidra::Funcdata::newOp(), ghidra::Funcdata::newVarnode(), ghidra::Funcdata::newVarnodeOut(), ghidra::Funcdata::opInsertBefore(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Funcdata::opSetOutput(), ghidra::Merge::registerProtoPartialRoot(), ghidra::Address::renormalize(), ghidra::Datatype::resolveInFlow(), ghidra::PcodeOp::setPartialRoot(), ghidra::Varnode::setProtoPartial(), ghidra::Architecture::types, and ghidra::Varnode::updateType().

◆ clone()

virtual Rule* ghidra::RulePieceStructure::clone ( const ActionGroupList grouplist) const
inlinevirtual

Clone the Rule.

If this Rule is a member of one of the groups in the grouplist, this returns a clone of the Rule, otherwise NULL is returned.

Parameters
grouplistis the list of groups being cloned
Returns
the cloned Rule or NULL

Implements ghidra::Rule.

References ghidra::ActionGroupList::contains().

◆ convertZextToPiece()

bool ghidra::RulePieceStructure::convertZextToPiece ( PcodeOp zext,
Datatype ct,
int4  offset,
Funcdata data 
)
staticprivate

Convert an INT_ZEXT operation to a PIECE with a zero constant as the first parameter.

The caller provides a parent data-type and an offset into it corresponding to the output of the INT_ZEXT. The op is converted to a PIECE with a 0 Varnode, which will be assigned a data-type based on the parent data-type and a computed offset.

Parameters
zextis the INT_ZEXT operation
ctis the parent data-type
offsetis the byte offset of the output within the parent data-type
datais the function containing the operation
Returns
true if the INT_ZEXT was successfully converted

References ghidra::CPUI_PIECE, ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::Varnode::getSpace(), ghidra::Datatype::getSubType(), ghidra::Varnode::getType(), ghidra::Funcdata::inheritResolution(), ghidra::AddrSpace::isBigEndian(), ghidra::Varnode::isConstant(), ghidra::Datatype::needsResolution(), ghidra::Funcdata::newConstant(), ghidra::AddTreeState::offset, ghidra::Funcdata::opInsertInput(), ghidra::Funcdata::opSetOpcode(), and ghidra::Varnode::updateType().

◆ determineDatatype()

Datatype * ghidra::RulePieceStructure::determineDatatype ( Varnode vn,
int4 &  baseOffset 
)
staticprivate

Markup for Varnodes pieced together into structure/array.

Find the base structure or array data-type that the given Varnode is part of.

If the Varnode's data-type is already a structure or array, return that data-type. If the Varnode is part of a known symbol, use that data-type. The starting byte offset of the given Varnode within the structure or array is passed back.

Parameters
vnis the given Varnode
baseOffsetis used to pass back the starting offset
Returns
the structure or array data-type, or null otherwise

References ghidra::AddTreeState::ct, ghidra::SymbolEntry::getAddr(), ghidra::Varnode::getAddr(), ghidra::SymbolEntry::getOffset(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::Varnode::getStructuredType(), ghidra::Datatype::getSubType(), ghidra::Varnode::getSymbolEntry(), ghidra::Datatype::isPieceStructured(), and ghidra::Address::overlap().

◆ findReplaceZext()

bool ghidra::RulePieceStructure::findReplaceZext ( vector< PieceNode > &  stack,
Datatype structuredType,
Funcdata data 
)
staticprivate

Search for leaves in the CONCAT tree defined by an INT_ZEXT operation and convert them to PIECE.

The CONCAT tree can be extended through an INT_ZEXT, if the extensions output crosses multiple fields of the parent data-type. We check this and replace the INT_ZEXT with PIECE if appropriate.

Parameters
stackis the node container for the CONCAT tree
structuredTypeis the parent data-type for the tree
datais the function containing the tree
Returns
true if any INT_ZEXT replacement was performed

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ZEXT, ghidra::AddTreeState::data, ghidra::Varnode::getDef(), ghidra::Varnode::getSize(), ghidra::PieceNode::getTypeOffset(), ghidra::PieceNode::getVarnode(), ghidra::PieceNode::isLeaf(), and ghidra::Varnode::isWritten().

◆ getOpList()

void ghidra::RulePieceStructure::getOpList ( vector< uint4 > &  oplist) const
virtual

List of op codes this rule operates on.

Populate the given array with all possible OpCodes this Rule might apply to. By default, this method returns all possible OpCodes

Parameters
oplistis the array to populate

Reimplemented from ghidra::Rule.

References ghidra::CPUI_INT_ZEXT, and ghidra::CPUI_PIECE.

◆ separateSymbol()

bool ghidra::RulePieceStructure::separateSymbol ( Varnode root,
Varnode leaf 
)
staticprivate

Return true if the two given root and leaf should be part of different symbols.

A leaf in a CONCAT tree can be in a separate from the root if it is a parameter or a separate root.

Parameters
rootis the root of the CONCAT tree
leafis the given leaf Varnode
Returns
true if the two Varnodes should be in different symbols

References ghidra::PcodeOp::code(), ghidra::CPUI_PIECE, ghidra::Varnode::getDef(), ghidra::Varnode::getSymbolEntry(), ghidra::Varnode::getType(), ghidra::Varnode::isAddrTied(), ghidra::PcodeOp::isMarker(), ghidra::Datatype::isPieceStructured(), ghidra::Varnode::isProtoPartial(), and ghidra::Varnode::isWritten().

◆ spanningRange()

bool ghidra::RulePieceStructure::spanningRange ( Datatype ct,
int4  offset,
int4  size 
)
staticprivate

For a structured data-type, determine if the given range spans multiple elements.

Return true unless the range falls within a single non-structured element.

Parameters
ctis the structured data-type
offsetis the start of the given range
sizeis the number of bytes in the range
Returns
true if the range spans multiple elements

References ghidra::Datatype::getSize(), ghidra::Datatype::getSubType(), ghidra::Datatype::isPieceStructured(), and ghidra::AddTreeState::offset.


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