decompiler
1.0.0
|
A helper class for describing the similarity of the boolean condition between 2 CBRANCH operations. More...
#include <condexe.hh>
Public Member Functions | |
ConditionMarker (void) | |
Constructor. | |
~ConditionMarker (void) | |
Destructor. More... | |
bool | verifyCondition (PcodeOp *op, PcodeOp *iop) |
Perform the correlation test on two CBRANCH operations. | |
int4 | getMultiSlot (void) const |
Get the MULTIEQUAL slot in the critical path. | |
bool | getFlip (void) const |
Return true is the expressions are anti-correlated. | |
Static Public Member Functions | |
static bool | varnodeSame (Varnode *a, Varnode *b) |
Do the given Varnodes hold the same value, possibly as constants. More... | |
static bool | varnodeComplement (Varnode *a, Varnode *b) |
Do the given boolean Varnodes always hold complementary values. More... | |
Private Member Functions | |
void | setupInitOp (PcodeOp *op) |
Map out the root boolean expression. More... | |
Varnode * | findMatch (PcodeOp *op) |
Find a matching Varnode in the root expression producing the given CBRANCH boolean. More... | |
bool | sameOpComplement (PcodeOp *bin1op, PcodeOp *bin2op) |
Test if two operations with same opcode produce complementary boolean values. More... | |
bool | andOrComplement (PcodeOp *bin1op, PcodeOp *bin2op) |
Check if given p-code ops are complements where one is an BOOL_AND and the other is an BOOL_OR. More... | |
bool | finalJudgement (Varnode *vn) |
Determine if the two boolean expressions always produce the same or complementary values. More... | |
Private Attributes | |
PcodeOp * | initop |
The root CBRANCH operation to compare against. | |
Varnode * | basevn |
The boolean Varnode on which the root CBRANCH keys. | |
Varnode * | boolvn |
If basevn is defined by BOOL_NEGATE, this is the unnegated Varnode. | |
Varnode * | bool2vn |
If the first param to binaryop is defined by BOOL_NEGATE, this is the unnegated Varnode. | |
Varnode * | bool3vn |
If the second param to binaryop is defined by BOOL_NEGATE, this is the unnegated Varnode. | |
PcodeOp * | binaryop |
The binary operator producing the root boolean (if non-null) | |
bool | matchflip |
True if the compared CBRANCH keys on the opposite boolean value of the root. | |
int4 | state |
Depth of critical path. | |
PcodeOp * | opstate [2] |
p-code operations along the critical path | |
bool | flipstate [2] |
Boolean negation along the critical path. | |
int4 | slotstate [2] |
Input Varnode to follow to stay on critical path. | |
bool | multion |
True if MULTIEQUAL used in condition. | |
bool | binon |
True if a binary operator is used in condition. | |
int4 | multislot |
Input slot of MULTIEQUAL on critical path, -1 if no MULTIEQUAL. | |
A helper class for describing the similarity of the boolean condition between 2 CBRANCH operations.
This class determines if two CBRANCHs share the same condition. It also determines if the conditions are complements of each other, and/or they are shared along only one path.
The expression computing the root boolean value for one CBRANCH is marked out by setupInitOp(). For the other CBRANCH, findMatch() tries to find common Varnode in its boolean expression and then maps a critical path from the Varnode to the final boolean. Assuming the common Varnode exists, the method finalJudgement() decides if the two boolean values are the same, uncorrelated, or complements of one another.
ghidra::ConditionMarker::~ConditionMarker | ( | void | ) |
Destructor.
Any marks on Varnodes in the root expression are cleared.
References basevn, binaryop, bool2vn, bool3vn, boolvn, ghidra::Varnode::clearMark(), and ghidra::PcodeOp::getIn().
Check if given p-code ops are complements where one is an BOOL_AND and the other is an BOOL_OR.
bin1op | is the first PcodeOp |
bin2op | is the second |
References ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_OR, ghidra::PcodeOp::getIn(), and varnodeComplement().
Referenced by finalJudgement().
|
private |
Determine if the two boolean expressions always produce the same or complementary values.
A common Varnode in the two expressions is given. If the boolean expressions are uncorrelated, false is returned, otherwise true is returned. If the expressions are correlated but always hold opposite values, the field matchflip is set to true.
vn | is the common Varnode |
References andOrComplement(), basevn, binaryop, binon, boolvn, ghidra::PcodeOp::code(), ghidra::PcodeOp::getIn(), initop, ghidra::PcodeOp::isBooleanFlip(), ghidra::PcodeOp::isBoolOutput(), matchflip, opstate, sameOpComplement(), state, and varnodeSame().
Referenced by verifyCondition().
Find a matching Varnode in the root expression producing the given CBRANCH boolean.
Walk the tree rooted at the given p-code op, looking for things marked in the tree rooted at initop. Trim everything but BOOL_NEGATE operations, one MULTIEQUAL, and one binary boolean operation. If there is a Varnode in common with the root expression, this is returned, and the tree traversal state holds the path from the boolean value to the common Varnode.
op | is the given CBRANCH op to compare |
References ghidra::PcodeOp::binary, binon, ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_MULTIEQUAL, flipstate, ghidra::Varnode::getDef(), ghidra::PcodeOp::getEvalType(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::isBooleanFlip(), ghidra::PcodeOp::isBoolOutput(), ghidra::Varnode::isMark(), ghidra::Varnode::isWritten(), matchflip, multion, ghidra::PcodeOp::numInput(), opstate, slotstate, and state.
Referenced by verifyCondition().
Test if two operations with same opcode produce complementary boolean values.
This only tests for cases where the opcode is INT_LESS or INT_SLESS and one of the inputs is constant.
bin1op | is the first p-code op to compare |
bin2op | is the second p-code op to compare |
References ghidra::PcodeOp::code(), ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_SLESS, ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Varnode::isConstant(), and varnodeSame().
Referenced by finalJudgement().
|
private |
Map out the root boolean expression.
Starting with the CBRANCH, the key Varnodes in the expression producing the boolean value are marked. BOOL_NEGATE operations are traversed, but otherwise only one level of operator is walked.
op | is the root CBRANCH operation |
References basevn, ghidra::PcodeOp::binary, binaryop, bool2vn, bool3vn, boolvn, ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::Varnode::getDef(), ghidra::PcodeOp::getEvalType(), ghidra::PcodeOp::getIn(), initop, ghidra::PcodeOp::isBoolOutput(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), and ghidra::Varnode::setMark().
Referenced by verifyCondition().
Do the given boolean Varnodes always hold complementary values.
Test if they are constants, 1 and 0, or if one is the direct BOOL_NEGATE of the other.
References ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), and ghidra::Varnode::isWritten().
Referenced by andOrComplement(), and getFlip().
Do the given Varnodes hold the same value, possibly as constants.
References ghidra::Varnode::getOffset(), and ghidra::Varnode::isConstant().
Referenced by finalJudgement(), getFlip(), and sameOpComplement().