Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
Remove PTRSUB operations with mismatched data-type information. More...
Public Member Functions | |
RulePtrsubUndo (const string &g) | |
Constructor. | |
virtual Rule * | clone (const ActionGroupList &grouplist) const |
Clone the Rule. | |
virtual void | getOpList (vector< uint4 > &oplist) const |
List of op codes this rule operates on. | |
virtual int4 | applyOp (PcodeOp *op, Funcdata &data) |
Attempt to apply this Rule. | |
![]() | |
Rule (const string &g, uint4 fl, const string &nm) | |
Construct given group, properties name. | |
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. | |
uint4 | getBreakPoint (void) const |
Return breakpoint toggles. | |
virtual void | reset (Funcdata &data) |
Reset this Rule. | |
virtual void | resetStats (void) |
Reset Rule statistics. | |
virtual void | printStatistics (ostream &s) const |
Print statistics for this Rule. | |
Static Private Member Functions | |
static int8 | getConstOffsetBack (Varnode *vn, int8 &multiplier, int4 maxLevel) |
Recursively search for additive constants and multiplicative constants. | |
static int8 | getExtraOffset (PcodeOp *op, int8 &multiplier) |
Collect constants and the biggest multiplier in the given PTRSUB expression. | |
static int8 | removeLocalAdds (Varnode *vn, Funcdata &data) |
Remove constants in the additive expression involving the given Varnode. | |
static int8 | removeLocalAddRecurse (PcodeOp *op, int4 slot, int4 maxLevel, Funcdata &data) |
Remove any constants in the additive expression rooted at the given PcodeOp. | |
Static Private Attributes | |
static const int4 | DEPTH_LIMIT = 8 |
The maximum depth of the additive expression to check. | |
Additional Inherited Members | |
![]() | |
enum | typeflags { type_disable = 1 , rule_debug = 2 , warnings_on = 4 , warnings_given = 8 } |
Properties associated with a Rule. More... | |
Remove PTRSUB operations with mismatched data-type information.
Incorrect data-types may be assigned to Varnodes in the middle of simplification. This causes incorrect PTRSUBs, which are discovered later. This rule converts the PTRSUB back to an INT_ADD when the mistake is discovered.
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.
Reimplemented from ghidra::Rule.
References ghidra::calc_mask(), ghidra::PcodeOp::clearStopTypePropagation(), ghidra::CPUI_INT_ADD, getExtraOffset(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::getTypeReadFacing(), ghidra::Funcdata::hasTypeRecoveryStarted(), ghidra::Datatype::isPtrsubMatching(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), and removeLocalAdds().
|
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.
grouplist | is the list of groups being cloned |
Implements ghidra::Rule.
References ghidra::ActionGroupList::contains(), and ghidra::Rule::getGroup().
|
staticprivate |
Recursively search for additive constants and multiplicative constants.
Walking backward from the given Varnode, search for constants being added in and return the sum of all the constants. Additionally pass back the biggest constant coefficient, for any term formed with INT_MULT.
vn | is the given root Varnode of the additive tree |
multiplier | will hold the biggest constant multiplier or 0, if no multiplier is present |
maxLevel | is the maximum depth to search in the tree |
References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_MULT, getConstOffsetBack(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), and ghidra::Varnode::isWritten().
Referenced by getConstOffsetBack(), and getExtraOffset().
|
staticprivate |
Collect constants and the biggest multiplier in the given PTRSUB expression.
Walking the additive expression (INT_ADD, PTRADD, and other PTRSUBs) and calculate any additional constant value being added to the PTRSUB. Additionally pass back the biggest constant coefficient of any multiplicative term in the expression.
op | is the given PTRSUB |
multiplier | will hold the biggest multiplicative coefficient or 0, if no INT_MULT or PTRADD is present. |
References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, DEPTH_LIMIT, getConstOffsetBack(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isConstant(), and ghidra::Varnode::loneDescend().
Referenced by applyOp().
|
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
oplist | is the array to populate |
Reimplemented from ghidra::Rule.
References ghidra::CPUI_PTRSUB.
|
staticprivate |
Remove any constants in the additive expression rooted at the given PcodeOp.
Walking recursively through the expression, any INT_ADD with a constant input is converted to a COPY. The INT_ADD must only contribute to the root expression.
op | is the given root PcodeOp |
slot | is the input slot to walk back from |
maxLevel | is the maximum depth to recurse |
data | is the function containing the expression |
References ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetOpcode(), and removeLocalAddRecurse().
Referenced by removeLocalAddRecurse(), and removeLocalAdds().
Remove constants in the additive expression involving the given Varnode.
Any additional PTRADD, PTRSUB, or INT_ADD that uses the Varnode and adds a constant is converted to a COPY. Additionally any other INT_ADD involved in the expression that adds a constant is also converted to COPY.
vn | is the given Varnode |
data | is the function containing the expression |
References ghidra::PcodeOp::clearStopTypePropagation(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, DEPTH_LIMIT, ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isConstant(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Funcdata::opUndoPtradd(), and removeLocalAddRecurse().
Referenced by applyOp().