decompiler 1.0.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::AddExpression Class Reference

Class for lightweight matching of two additive expressions. More...

#include <expression.hh>

Classes

class  Term
 A term in the expression. More...
 

Public Member Functions

 AddExpression (void)
 Construct an empty expression.
 
void gatherTwoTermsSubtract (Varnode *a, Varnode *b)
 Walk expression given two roots being subtracted from one another.
 
void gatherTwoTermsAdd (Varnode *a, Varnode *b)
 Walk expression given two roots being added to each other.
 
void gatherTwoTermsRoot (Varnode *root)
 Gather up to 2 terms given root Varnode.
 
bool isEquivalent (const AddExpression &op2) const
 Determine if 2 expressions are equivalent.
 

Private Member Functions

void add (Varnode *vn, uintb coeff)
 Add a term to the expression.
 
void gather (Varnode *vn, uintb coeff, int4 depth)
 Gather terms in the expression from a root point.
 

Private Attributes

uintb constval
 Collected constants in the expression.
 
int4 numTerms
 Number of terms.
 
Term terms [2]
 Terms making up the expression.
 

Detailed Description

Class for lightweight matching of two additive expressions.

Collect (up to 2) terms along with any constants and coefficients.

Member Function Documentation

◆ gather()

void ghidra::AddExpression::gather ( Varnode vn,
uintb  coeff,
int4  depth 
)
private

Gather terms in the expression from a root point.

Recursively collect terms, up to the given depth. INT_ADD either contributes to the constant sum, or it is recursively walked. Term coefficients are collected from INT_MULT with a constant.

Parameters
vnis the root of the (sub)expression
coeffis the current multiplicative coefficient of the subexpression
depthis the current depth

References add(), ghidra::calc_mask(), ghidra::PcodeOp::code(), constval, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_MULT, gather(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Varnode::isConstant(), and ghidra::Varnode::isWritten().

Referenced by gather(), gatherTwoTermsAdd(), gatherTwoTermsRoot(), and gatherTwoTermsSubtract().

◆ gatherTwoTermsAdd()

void ghidra::AddExpression::gatherTwoTermsAdd ( Varnode a,
Varnode b 
)

Walk expression given two roots being added to each other.

Gather up to two non-constant additive terms, given two root Varnodes being added

Parameters
ais the first root
bis the second root being added to the first

References gather(), and ghidra::Varnode::isConstant().

Referenced by ghidra::RuleScarry::applyOp().

◆ gatherTwoTermsRoot()

void ghidra::AddExpression::gatherTwoTermsRoot ( Varnode root)

Gather up to 2 terms given root Varnode.

Gather up to two non-constant additive terms in the expression at the given root.

Parameters
rootis the root Varnode

References gather().

Referenced by ghidra::RuleSborrow::applyOp(), and ghidra::RuleScarry::applyOp().

◆ gatherTwoTermsSubtract()

void ghidra::AddExpression::gatherTwoTermsSubtract ( Varnode a,
Varnode b 
)

Walk expression given two roots being subtracted from one another.

Gather up to two non-constant additive terms, given two root Varnodes that are being subtracted.

Parameters
ais the first root
bis the second root being subtracted from the first

References ghidra::calc_mask(), gather(), ghidra::Varnode::getSize(), and ghidra::Varnode::isConstant().

Referenced by ghidra::RuleSborrow::applyOp().

◆ isEquivalent()

bool ghidra::AddExpression::isEquivalent ( const AddExpression op2) const

Determine if 2 expressions are equivalent.

The value true is returned if it can be proven that the expressions always produce the same value.

Parameters
op2is the other expression to compare with this
Returns
true if the expressions are equivalent

References constval, isEquivalent(), ghidra::AddExpression::Term::isEquivalent(), numTerms, and terms.

Referenced by ghidra::RuleSborrow::applyOp(), ghidra::RuleScarry::applyOp(), and isEquivalent().


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