mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
added RuleOrConsume
This commit is contained in:
parent
992d32dd87
commit
40d840085f
3 changed files with 40 additions and 0 deletions
|
@ -4482,6 +4482,7 @@ void universal_action(Architecture *conf)
|
||||||
actprop->addRule( new RuleIdentityEl("analysis") );
|
actprop->addRule( new RuleIdentityEl("analysis") );
|
||||||
actprop->addRule( new RuleOrMask("analysis") );
|
actprop->addRule( new RuleOrMask("analysis") );
|
||||||
actprop->addRule( new RuleAndMask("analysis") );
|
actprop->addRule( new RuleAndMask("analysis") );
|
||||||
|
actprop->addRule( new RuleOrConsume("analysis") );
|
||||||
actprop->addRule( new RuleOrCollapse("analysis") );
|
actprop->addRule( new RuleOrCollapse("analysis") );
|
||||||
actprop->addRule( new RuleAndOrLump("analysis") );
|
actprop->addRule( new RuleAndOrLump("analysis") );
|
||||||
actprop->addRule( new RuleShiftBitops("analysis") );
|
actprop->addRule( new RuleShiftBitops("analysis") );
|
||||||
|
|
|
@ -390,6 +390,35 @@ int4 RuleAndMask::applyOp(PcodeOp *op,Funcdata &data)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \class RuleOrConsume
|
||||||
|
/// \brief Simply OR with unconsumed input: `V = A | B => V = B if nzm(A) & consume(V) == 0
|
||||||
|
void RuleOrConsume::getOpList(vector<uint4> &oplist) const
|
||||||
|
|
||||||
|
{
|
||||||
|
oplist.push_back(CPUI_INT_OR);
|
||||||
|
oplist.push_back(CPUI_INT_XOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
int4 RuleOrConsume::applyOp(PcodeOp *op,Funcdata &data)
|
||||||
|
|
||||||
|
{
|
||||||
|
Varnode *outvn = op->getOut();
|
||||||
|
int4 size = outvn->getSize();
|
||||||
|
if (size > sizeof(uintb)) return 0; // FIXME: uintb should be arbitrary precision
|
||||||
|
uintb consume = outvn->getConsume();
|
||||||
|
if ((consume & op->getIn(0)->getNZMask()) == 0) {
|
||||||
|
data.opRemoveInput(op,0);
|
||||||
|
data.opSetOpcode(op, CPUI_COPY);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if ((consume & op->getIn(1)->getNZMask()) == 0) {
|
||||||
|
data.opRemoveInput(op,1);
|
||||||
|
data.opSetOpcode(op, CPUI_COPY);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// \class RuleOrCollapse
|
/// \class RuleOrCollapse
|
||||||
/// \brief Collapse unnecessary INT_OR
|
/// \brief Collapse unnecessary INT_OR
|
||||||
///
|
///
|
||||||
|
|
|
@ -128,6 +128,16 @@ public:
|
||||||
virtual void getOpList(vector<uint4> &oplist) const;
|
virtual void getOpList(vector<uint4> &oplist) const;
|
||||||
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
|
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
|
||||||
};
|
};
|
||||||
|
class RuleOrConsume : public Rule {
|
||||||
|
public:
|
||||||
|
RuleOrConsume(const string &g) : Rule(g, 0, "orconsume") {} ///< Constructor
|
||||||
|
virtual Rule *clone(const ActionGroupList &grouplist) const {
|
||||||
|
if (!grouplist.contains(getGroup())) return (Rule *)0;
|
||||||
|
return new RuleOrConsume(getGroup());
|
||||||
|
}
|
||||||
|
virtual void getOpList(vector<uint4> &oplist) const;
|
||||||
|
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
|
||||||
|
};
|
||||||
class RuleOrCollapse : public Rule {
|
class RuleOrCollapse : public Rule {
|
||||||
public:
|
public:
|
||||||
RuleOrCollapse(const string &g) : Rule(g, 0, "orcollapse") {} ///< Constructor
|
RuleOrCollapse(const string &g) : Rule(g, 0, "orcollapse") {} ///< Constructor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue