decompiler 1.0.0
Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ghidra::BooleanExpressionMatch Class Reference

A helper class for describing the similarity of the boolean condition between 2 CBRANCH operations. More...

#include <condexe.hh>

Public Member Functions

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 if the expressions are anti-correlated.
 

Private Types

enum  { same = 1 , complementary = 2 , uncorrelated = 3 }
 

Static Private Member Functions

static bool sameOpComplement (PcodeOp *bin1op, PcodeOp *bin2op)
 Test if two operations with same opcode produce complementary boolean values. More...
 
static bool varnodeSame (Varnode *a, Varnode *b)
 Do the given Varnodes hold the same value, possibly as constants. More...
 
static int4 evaluate (Varnode *vn1, Varnode *vn2, int4 depth)
 Determine if two boolean Varnodes hold related values. More...
 

Private Attributes

bool matchflip
 True if the compared CBRANCH keys on the opposite boolean value of the root.
 

Static Private Attributes

static const int4 maxDepth = 1
 Maximum depth to trace a boolean expression.
 

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.

Traverse (upto a specific depth) the two boolean expressions consisting of BOOL_AND, BOOL_OR, and BOOL_XOR operations. Leaf operators in the expression can be other operators with boolean output (INT_LESS, INT_SLESS, etc.).

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
same 

Pair always hold the same value.

complementary 

Pair always hold complementary values.

uncorrelated 

Pair values are uncorrelated.

Member Function Documentation

◆ evaluate()

int4 ghidra::BooleanExpressionMatch::evaluate ( Varnode vn1,
Varnode vn2,
int4  depth 
)
staticprivate

Determine if two boolean Varnodes hold related values.

The values may be the same, or opposite of each other (complementary). Otherwise the values are uncorrelated. The trees constructing each Varnode are examined up to a maximum depth. If this is exceeded uncorrelated is returned.

Parameters
vn1is the first boolean Varnode
vn2is the second boolean Varnode
depthis the maximum depth to traverse in the evaluation
Returns
the correlation class

References ghidra::PcodeOp::code(), complementary, ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::CPUI_BOOL_XOR, ghidra::CPUI_MAX, evaluate(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::isBoolOutput(), ghidra::Varnode::isWritten(), same, sameOpComplement(), uncorrelated, and varnodeSame().

Referenced by evaluate(), and verifyCondition().

◆ sameOpComplement()

bool ghidra::BooleanExpressionMatch::sameOpComplement ( PcodeOp bin1op,
PcodeOp bin2op 
)
staticprivate

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

◆ varnodeSame()

bool ghidra::BooleanExpressionMatch::varnodeSame ( Varnode a,
Varnode b 
)
staticprivate

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 evaluate(), and sameOpComplement().


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