decompiler  1.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::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 *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...
 
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()

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

Member Function Documentation

◆ andOrComplement()

bool ghidra::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 ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_OR, ghidra::PcodeOp::getIn(), and varnodeComplement().

Referenced by finalJudgement().

◆ finalJudgement()

bool ghidra::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, ghidra::PcodeOp::code(), ghidra::PcodeOp::getIn(), initop, ghidra::PcodeOp::isBooleanFlip(), ghidra::PcodeOp::isBoolOutput(), matchflip, opstate, sameOpComplement(), state, and varnodeSame().

Referenced by verifyCondition().

◆ findMatch()

Varnode * ghidra::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 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().

◆ sameOpComplement()

bool ghidra::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 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().

◆ setupInitOp()

void ghidra::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, 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().

◆ varnodeComplement()

bool ghidra::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 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().

◆ varnodeSame()

bool ghidra::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 ghidra::Varnode::getOffset(), and ghidra::Varnode::isConstant().

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


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