decompiler  1.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ConditionMarker Class Reference

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...
 
VarnodefindMatch (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

PcodeOpinitop
 The root CBRANCH operation to compare against.
 
Varnodebasevn
 The boolean Varnode on which the root CBRANCH keys.
 
Varnodeboolvn
 If basevn is defined by BOOL_NEGATE, this is the unnegated Varnode.
 
Varnodebool2vn
 If the first param to binaryop is defined by BOOL_NEGATE, this is the unnegated Varnode.
 
Varnodebool3vn
 If the second param to binaryop is defined by BOOL_NEGATE, this is the unnegated Varnode.
 
PcodeOpbinaryop
 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.
 
PcodeOpopstate [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.
 

Detailed Description

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.

Constructor & Destructor Documentation

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().

Member Function Documentation

bool ConditionMarker::andOrComplement ( PcodeOp bin1op,
PcodeOp bin2op 
)
private

Check if given p-code ops are complements where one is an BOOL_AND and the other is an BOOL_OR.

Parameters
bin1opis the first PcodeOp
bin2opis the second
Returns
true if the p-code ops produce complementary values

References PcodeOp::code(), CPUI_BOOL_AND, CPUI_BOOL_OR, PcodeOp::getIn(), and varnodeComplement().

Referenced by finalJudgement().

bool ConditionMarker::finalJudgement ( Varnode vn)
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.

Parameters
vnis the common Varnode
Returns
true if the expressions are correlated

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().

Varnode * ConditionMarker::findMatch ( PcodeOp op)
private

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.

Parameters
opis the given CBRANCH op to compare
Returns
the Varnode in common with the root expression or NULL

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().

bool ConditionMarker::sameOpComplement ( PcodeOp bin1op,
PcodeOp bin2op 
)
private

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.

Parameters
bin1opis the first p-code op to compare
bin2opis the second p-code op to compare
Returns
true if the two operations always produce complementary values

References PcodeOp::code(), CPUI_INT_LESS, CPUI_INT_SLESS, PcodeOp::getIn(), Varnode::getOffset(), Varnode::getSize(), Varnode::isConstant(), signbit_negative(), and varnodeSame().

Referenced by finalJudgement().

void ConditionMarker::setupInitOp ( PcodeOp op)
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.

Parameters
opis 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().

bool ConditionMarker::varnodeComplement ( Varnode a,
Varnode b 
)
static

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.

Parameters
ais the first Varnode to compare
bis the second Varnode to compare
Returns
true if the Varnodes (always) hold complementary values

References PcodeOp::code(), CPUI_BOOL_NEGATE, Varnode::getDef(), PcodeOp::getIn(), Varnode::getOffset(), Varnode::isConstant(), and Varnode::isWritten().

Referenced by andOrComplement(), and getFlip().

bool ConditionMarker::varnodeSame ( Varnode a,
Varnode b 
)
static

Do the given Varnodes hold the same value, possibly as constants.

Parameters
ais the first Varnode to compare
bis the second Varnode
Returns
true if the Varnodes (always) hold the same value

References Varnode::getOffset(), and Varnode::isConstant().

Referenced by finalJudgement(), getFlip(), and sameOpComplement().


The documentation for this class was generated from the following files: