Xor swap rule

This commit is contained in:
caheckman 2020-09-10 18:01:26 -04:00
parent 662c7043c6
commit a25b7d2178
3 changed files with 45 additions and 0 deletions

View file

@ -5018,6 +5018,7 @@ void ActionDatabase::universalAction(Architecture *conf)
actprop->addRule( new RulePiece2Zext("analysis") );
actprop->addRule( new RulePiece2Sext("analysis") );
actprop->addRule( new RulePopcountBoolXor("analysis") );
actprop->addRule( new RuleXorSwap("analysis") );
actprop->addRule( new RuleSubvarAnd("subvar") );
actprop->addRule( new RuleSubvarSubpiece("subvar") );
actprop->addRule( new RuleSplitFlow("subvar") );

View file

@ -9081,3 +9081,35 @@ int4 RulePiecePathology::applyOp(PcodeOp *op,Funcdata &data)
return tracePathologyForward(op, data);
}
void RuleXorSwap::getOpList(vector<uint4> &oplist) const
{
oplist.push_back(CPUI_INT_XOR);
}
int4 RuleXorSwap::applyOp(PcodeOp *op,Funcdata &data)
{
for(int4 i=0;i<2;++i) {
Varnode *vn = op->getIn(i);
if (!vn->isWritten()) continue;
PcodeOp *op2 = vn->getDef();
if (op2->code() != CPUI_INT_XOR) continue;
Varnode *othervn = op->getIn(1-i);
Varnode *vn0 = op2->getIn(0);
Varnode *vn1 = op2->getIn(1);
if (othervn == vn0 && !vn1->isFree()) {
data.opRemoveInput(op, 1);
data.opSetOpcode(op, CPUI_COPY);
data.opSetInput(op, vn1, 0);
return 1;
}
else if (othervn == vn1 && !vn0->isFree()) {
data.opRemoveInput(op, 1);
data.opSetOpcode(op, CPUI_COPY);
data.opSetInput(op, vn0, 0);
return 1;
}
}
return 0;
}

View file

@ -1477,4 +1477,16 @@ public:
virtual void getOpList(vector<uint4> &oplist) const;
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
};
class RuleXorSwap : public Rule {
public:
RuleXorSwap(const string &g) : Rule(g,0,"xorswap") {} ///< Constructor
virtual Rule *clone(const ActionGroupList &grouplist) const {
if (!grouplist.contains(getGroup())) return (Rule *)0;
return new RuleXorSwap(getGroup());
}
virtual void getOpList(vector<uint4> &oplist) const;
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
};
#endif