decompiler
1.0.0
|
Fill-in CPUI_CAST p-code ops as required by the casting strategy. More...
#include <coreaction.hh>
Public Member Functions | |
ActionSetCasts (const string &g) | |
Constructor. | |
virtual Action * | clone (const ActionGroupList &grouplist) const |
Clone the Action. More... | |
virtual int4 | apply (Funcdata &data) |
Make a single attempt to apply this Action. More... | |
Public Member Functions inherited from ghidra::Action | |
Action (uint4 f, const string &nm, const string &g) | |
Base constructor for an Action. More... | |
virtual | ~Action (void) |
Destructor. | |
virtual void | printStatistics (ostream &s) const |
Dump statistics to stream. More... | |
int4 | perform (Funcdata &data) |
Perform this action (if necessary) More... | |
bool | setBreakPoint (uint4 tp, const string &specify) |
Set a breakpoint on this action. More... | |
virtual void | clearBreakPoints (void) |
Clear all breakpoints set on this Action. | |
bool | setWarning (bool val, const string &specify) |
Set a warning on this action. More... | |
bool | disableRule (const string &specify) |
Disable a specific Rule within this. More... | |
bool | enableRule (const string &specify) |
Enable a specific Rule within this. More... | |
const string & | getName (void) const |
Get the Action's name. | |
const string & | getGroup (void) const |
Get the Action's group. | |
uint4 | getStatus (void) const |
Get the current status of this Action. | |
uint4 | getNumTests (void) |
Get the number of times apply() was invoked. | |
uint4 | getNumApply (void) |
virtual void | reset (Funcdata &data) |
Reset the Action for a new function. More... | |
virtual void | resetStats (void) |
Reset all the counts to zero. More... | |
virtual int4 | print (ostream &s, int4 num, int4 depth) const |
Print a description of this Action to stream. More... | |
virtual void | printState (ostream &s) const |
Print status to stream. More... | |
virtual Action * | getSubAction (const string &specify) |
Retrieve a specific sub-action by name. More... | |
virtual Rule * | getSubRule (const string &specify) |
Retrieve a specific sub-rule by name. More... | |
Static Private Member Functions | |
static void | checkPointerIssues (PcodeOp *op, Varnode *vn, Funcdata &data) |
Check if the data-type of the given value being used as a pointer makes sense. More... | |
static bool | testStructOffset0 (Varnode *vn, PcodeOp *op, Datatype *ct, CastStrategy *castStrategy) |
Test if the given cast conflict can be resolved by passing to the first structure field. More... | |
static bool | tryResolutionAdjustment (PcodeOp *op, int4 slot, Funcdata &data) |
Try to adjust the input and output Varnodes to eliminate a CAST. More... | |
static bool | isOpIdentical (Datatype *ct1, Datatype *ct2) |
Test if two data-types are operation identical. More... | |
static int4 | resolveUnion (PcodeOp *op, int4 slot, Funcdata &data) |
If the given op reads a pointer to a union, insert the CPUI_PTRSUB that resolves the union. More... | |
static int4 | castOutput (PcodeOp *op, Funcdata &data, CastStrategy *castStrategy) |
Insert cast to output Varnode type after given PcodeOp if it is necessary. More... | |
static int4 | castInput (PcodeOp *op, int4 slot, Funcdata &data, CastStrategy *castStrategy) |
Insert cast to produce the input Varnode to a given PcodeOp if necessary. More... | |
static PcodeOp * | insertPtrsubZero (PcodeOp *op, int4 slot, Datatype *ct, Funcdata &data) |
Insert a PTRSUB with offset 0 that accesses a field of the given data-type. More... | |
Additional Inherited Members | |
Public Types inherited from ghidra::Action | |
enum | ruleflags { rule_repeatapply = 4, rule_onceperfunc = 8, rule_oneactperfunc = 16, rule_debug = 32, rule_warnings_on = 64, rule_warnings_given = 128 } |
Boolean behavior properties governing this particular Action. More... | |
enum | statusflags { status_start =1, status_breakstarthit =2, status_repeat =4, status_mid =8, status_end =16, status_actionbreak =32 } |
Boolean properties describing the status of an action. More... | |
enum | breakflags { break_start = 1, tmpbreak_start = 2, break_action = 4, tmpbreak_action = 8 } |
Break points associated with an Action. More... | |
Protected Member Functions inherited from ghidra::Action | |
void | issueWarning (Architecture *glb) |
Warn that this Action has applied. More... | |
bool | checkStartBreak (void) |
Check start breakpoint. More... | |
bool | checkActionBreak (void) |
Check action breakpoint. More... | |
void | turnOnWarnings (void) |
Enable warnings for this Action. | |
void | turnOffWarnings (void) |
Disable warnings for this Action. | |
Protected Attributes inherited from ghidra::Action | |
int4 | lcount |
Changes not including last call to apply() | |
int4 | count |
Number of changes made by this action so far. | |
uint4 | status |
Current status. | |
uint4 | breakpoint |
Breakpoint properties. | |
uint4 | flags |
Behavior properties. | |
uint4 | count_tests |
Number of times apply() has been called. | |
uint4 | count_apply |
Number of times apply() made changes. | |
string | name |
Name of the action. | |
string | basegroup |
Base group this action belongs to. | |
Fill-in CPUI_CAST p-code ops as required by the casting strategy.
Setting the casts is complicated by type inference and implied variables. By the time this Action is run, the type inference algorithm has labeled every Varnode with what it thinks the type should be. This casting algorithm tries to get the code to legally match this inference result by adding casts. Following the data flow, it tries the best it can to get each token to match the inferred type. For implied variables, the type is completely determined by the syntax of the output language, so implied casts won't work in this case. For most of these cases, the algorithm just changes the type to that dictated by syntax and gets back on track at the next explicit variable in the flow. It tries to avoid losing pointer types however because any CPUI_PTRADD mst have a pointer input. In this case, it casts to the necessary pointer type immediately.
|
virtual |
Make a single attempt to apply this Action.
This is the main entry point for applying changes to a function that are specific to this Action. The method can inspect whatever it wants to decide if the Action does or does not apply. Changes are indicated by incrementing the count field.
data | is the function to inspect/modify |
Implements ghidra::Action.
References ghidra::AddrSpace::addressToByteInt(), ghidra::BlockBasic::beginOp(), ghidra::PcodeOp::code(), ghidra::CPUI_CAST, ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_LOAD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_STORE, ghidra::BlockBasic::endOp(), ghidra::Funcdata::getArch(), ghidra::Funcdata::getBasicBlocks(), ghidra::PrintLanguage::getCastStrategy(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::TypePointer::getPtrTo(), ghidra::Datatype::getSize(), ghidra::TypePointer::getWordSize(), ghidra::Datatype::isPtrsubMatching(), ghidra::PcodeOp::notPrinted(), ghidra::PcodeOp::numInput(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Funcdata::opUndoPtradd(), ghidra::Architecture::print, ghidra::Funcdata::startCastPhase(), and ghidra::TYPE_PTR.
|
staticprivate |
Insert cast to produce the input Varnode to a given PcodeOp if necessary.
This method can also mark a Varnode as an explicit integer constant. Guard against chains of casts.
op | is the given PcodeOp |
slot | is the slot of the input Varnode |
data | is the function being analyzed |
castStrategy | is used to determine if a cast is necessary |
References ghidra::PcodeOp::code(), ghidra::CPUI_CAST, ghidra::Funcdata::forceFacingType(), ghidra::PcodeOp::getAddr(), ghidra::Funcdata::getArch(), ghidra::Varnode::getDef(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::TypeOp::getInputCast(), ghidra::PcodeOp::getOpcode(), ghidra::Varnode::getSize(), ghidra::HighVariable::getType(), ghidra::Varnode::getType(), ghidra::Funcdata::inheritResolution(), ghidra::Varnode::isConstant(), ghidra::Varnode::isImplied(), ghidra::Varnode::isWritten(), ghidra::Varnode::loneDescend(), ghidra::CastStrategy::markExplicitLongSize(), ghidra::CastStrategy::markExplicitUnsigned(), ghidra::Datatype::needsResolution(), ghidra::Funcdata::newOp(), ghidra::Funcdata::newUniqueOut(), ghidra::Funcdata::opInsertBefore(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Varnode::setImplied(), and ghidra::Varnode::updateType().
|
staticprivate |
Insert cast to output Varnode type after given PcodeOp if it is necessary.
op | is the given PcodeOp |
data | is the function being analyzed |
castStrategy | is used to determine if the cast is necessary |
References ghidra::CastStrategy::castStandard(), ghidra::PcodeOp::code(), ghidra::CPUI_CAST, ghidra::CPUI_RETURN, ghidra::Datatype::findResolve(), ghidra::Funcdata::forceFacingType(), ghidra::PcodeOp::getAddr(), ghidra::Funcdata::getArch(), ghidra::Varnode::getHigh(), ghidra::Varnode::getHighTypeDefFacing(), ghidra::Datatype::getMetatype(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::getOut(), ghidra::TypeOp::getOutputToken(), ghidra::Varnode::getSize(), ghidra::HighVariable::getType(), ghidra::Varnode::getType(), ghidra::Funcdata::inheritResolution(), ghidra::Varnode::isImplied(), ghidra::Varnode::isTypeLock(), ghidra::Varnode::loneDescend(), ghidra::Datatype::needsResolution(), ghidra::Funcdata::newOp(), ghidra::Funcdata::newUnique(), ghidra::Funcdata::opInsertAfter(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Funcdata::opSetOutput(), ghidra::Datatype::resolveInFlow(), ghidra::Varnode::setImplied(), ghidra::Funcdata::setUnionField(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, and ghidra::Varnode::updateType().
|
staticprivate |
Check if the data-type of the given value being used as a pointer makes sense.
If the data-type is a pointer make sure:
If any of the conditions are violated, a warning is added to the output.
op | is the LOAD/STORE acting on a pointer |
vn | is the given value being used as a pointer |
data | is the function containing the PcodeOp |
References ghidra::PcodeOp::getAddr(), ghidra::AddrSpace::getContain(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::TypeOp::getName(), ghidra::AddrSpace::getName(), ghidra::PcodeOp::getOpcode(), ghidra::Varnode::getSize(), ghidra::Varnode::getSpaceFromConst(), ghidra::TYPE_PTR, and ghidra::Funcdata::warning().
|
inlinevirtual |
Clone the Action.
If this Action is a member of one of the groups in the grouplist, this returns a clone of the Action, otherwise NULL is returned.
grouplist | is the list of groups being cloned |
Implements ghidra::Action.
References ghidra::ActionStart::apply(), ghidra::ActionGroupList::contains(), and ghidra::Action::getGroup().
|
staticprivate |
Insert a PTRSUB with offset 0 that accesses a field of the given data-type.
The data-type can be a structure, in which case the field at offset zero is being accessed. The data-type can reference a union, in which case a specific field is being accessed as indicated by Funcdata::getUnionField. The PTRSUB is inserted right before the given PcodeOp. The indicated input Varnode becomes the PTRSUB input, and the PTRSUB output replaces the Varnode in the PcodeOp.
op | is the given PcodeOp where the PTRSUB is inserted |
slot | is the slot corresponding to the indicated Varnode |
ct | is the data-type produced by the PTRSUB |
data | is containing Function |
References ghidra::CPUI_PTRSUB, ghidra::PcodeOp::getAddr(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getSize(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::newOp(), ghidra::Funcdata::newUniqueOut(), ghidra::Funcdata::opInsertBefore(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Varnode::setImplied(), and ghidra::Varnode::updateType().
Test if two data-types are operation identical.
If, at a source code level, a variable with data-type ct1 can be legally substituted for another variable with data-type ct2, return true. The substitution must be allowed for all possible operations the variable may be involved in.
ct1 | is the first data-type |
ct2 | is the second data-type |
References ghidra::Datatype::getMetatype(), ghidra::Datatype::getTypedef(), and ghidra::TYPE_PTR.
|
staticprivate |
If the given op reads a pointer to a union, insert the CPUI_PTRSUB that resolves the union.
op | is the given PcodeOp |
slot | is index of the input slot being read |
data | is the containing function |
References ghidra::ResolvedUnion::getDatatype(), ghidra::Varnode::getDef(), ghidra::ResolvedUnion::getFieldNum(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::HighVariable::getType(), ghidra::Varnode::getType(), ghidra::Funcdata::getUnionField(), ghidra::Varnode::isAnnotation(), ghidra::Varnode::isImplied(), ghidra::Varnode::isWritten(), ghidra::Datatype::needsResolution(), ghidra::Datatype::resolveInFlow(), ghidra::Varnode::setImpliedField(), ghidra::Funcdata::setUnionField(), and ghidra::TYPE_PTR.
|
staticprivate |
Test if the given cast conflict can be resolved by passing to the first structure field.
Test if the given Varnode data-type is a pointer to a structure and if interpreting the data-type as a pointer to the structure's first field will get it to match the desired data-type.
vn | is the given Varnode |
op | is the PcodeOp reading the Varnode |
ct | is the desired data-type |
castStrategy | is used to determine if the data-types are compatible |
References ghidra::TypeStruct::beginField(), ghidra::CastStrategy::castStandard(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::Datatype::getMetatype(), ghidra::TypeStruct::numDepend(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, and ghidra::TYPE_STRUCT.
|
staticprivate |
Try to adjust the input and output Varnodes to eliminate a CAST.
If input/output data-types are different, it may be due to late merges. For unions, the CAST can sometimes be eliminated by adjusting the data-type resolutions of the Varnodes relative to the PcodeOp
op | is the PcodeOp reading the input Varnode and writing the output Varnode |
slot | is the index of the input Varnode |
data | is the function |
References ghidra::Datatype::findCompatibleResolve(), ghidra::Funcdata::getArch(), ghidra::Datatype::getDepend(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::HighVariable::getType(), ghidra::Datatype::needsResolution(), ghidra::Funcdata::setUnionField(), and ghidra::Architecture::types.