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 *initop) |
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.
ConditionMarker::~ConditionMarker | ( | void | ) |
Destructor.
Any marks on Varnodes in the root expression are cleared.
References basevn, binaryop, bool2vn, bool3vn, boolvn, Varnode::clearMark(), and 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 PcodeOp::code(), CPUI_BOOL_AND, CPUI_BOOL_OR, 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, PcodeOp::code(), get_booleanflip(), PcodeOp::getIn(), initop, PcodeOp::isBooleanFlip(), 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 PcodeOp::binary, binon, PcodeOp::code(), CPUI_BOOL_NEGATE, CPUI_MULTIEQUAL, flipstate, Varnode::getDef(), PcodeOp::getEvalType(), PcodeOp::getIn(), PcodeOp::isBooleanFlip(), PcodeOp::isBoolOutput(), Varnode::isMark(), Varnode::isWritten(), matchflip, multion, 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 PcodeOp::code(), CPUI_INT_LESS, CPUI_INT_SLESS, PcodeOp::getIn(), Varnode::getOffset(), Varnode::getSize(), Varnode::isConstant(), signbit_negative(), 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, PcodeOp::binary, binaryop, bool2vn, bool3vn, boolvn, PcodeOp::code(), CPUI_BOOL_NEGATE, Varnode::getDef(), PcodeOp::getEvalType(), PcodeOp::getIn(), initop, PcodeOp::isBoolOutput(), Varnode::isConstant(), Varnode::isWritten(), and 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 PcodeOp::code(), CPUI_BOOL_NEGATE, Varnode::getDef(), PcodeOp::getIn(), Varnode::getOffset(), Varnode::isConstant(), and Varnode::isWritten().
Referenced by andOrComplement(), and getFlip().
Do the given Varnodes hold the same value, possibly as constants.
References Varnode::getOffset(), and Varnode::isConstant().
Referenced by finalJudgement(), getFlip(), and sameOpComplement().