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

A (putative) switch variable Varnode and a constraint imposed by a CBRANCH. More...

#include <jumptable.hh>

Public Member Functions

 GuardRecord (PcodeOp *bOp, PcodeOp *rOp, int4 path, const CircleRange &rng, Varnode *v, bool unr=false)
 Constructor. More...
 
bool isUnrolled (void) const
 Is this guard duplicated across multiple blocks.
 
PcodeOpgetBranch (void) const
 Get the CBRANCH associated with this guard.
 
PcodeOpgetReadOp (void) const
 Get the PcodeOp immediately causing the restriction.
 
int4 getPath (void) const
 Get the specific path index going towards the switch.
 
const CircleRangegetRange (void) const
 Get the range of values causing the switch path to be taken.
 
void clear (void)
 Mark this guard as unused.
 
int4 valueMatch (Varnode *vn2, Varnode *baseVn2, int4 bitsPreserved2) const
 Determine if this guard applies to the given Varnode. More...
 

Static Public Member Functions

static int4 oneOffMatch (PcodeOp *op1, PcodeOp *op2)
 Return 1 if the two given PcodeOps produce exactly the same value, 0 if otherwise. More...
 
static VarnodequasiCopy (Varnode *vn, int4 &bitsPreserved)
 Compute the source of a quasi-COPY chain for the given Varnode. More...
 

Private Attributes

PcodeOpcbranch
 PcodeOp CBRANCH the branches around the switch.
 
PcodeOpreadOp
 The immediate PcodeOp causing the restriction.
 
Varnodevn
 The Varnode being restricted.
 
VarnodebaseVn
 Value being (quasi)copied to the Varnode.
 
int4 indpath
 Specific CBRANCH path going to the switch.
 
int4 bitsPreserved
 Number of bits copied (all other bits are zero)
 
CircleRange range
 Range of values causing the CBRANCH to take the path to the switch.
 
bool unrolled
 true if guarding CBRANCH is duplicated across multiple blocks
 

Detailed Description

A (putative) switch variable Varnode and a constraint imposed by a CBRANCH.

The record constrains a specific Varnode. If the associated CBRANCH is followed along the path that reaches the switch's BRANCHIND, then we have an explicit description of the possible values the Varnode can hold.

Constructor & Destructor Documentation

◆ GuardRecord()

ghidra::GuardRecord::GuardRecord ( PcodeOp bOp,
PcodeOp rOp,
int4  path,
const CircleRange rng,
Varnode v,
bool  unr = false 
)

Constructor.

Parameters
bOpis the CBRANCH guarding the switch
rOpis the PcodeOp immediately reading the Varnode
pathis the specific branch to take from the CBRANCH to reach the switch
rngis the range of values causing the switch path to be taken
vis the Varnode holding the value controlling the CBRANCH
unris true if the guard is duplicated across multiple blocks

Member Function Documentation

◆ oneOffMatch()

int4 ghidra::GuardRecord::oneOffMatch ( PcodeOp op1,
PcodeOp op2 
)
static

Return 1 if the two given PcodeOps produce exactly the same value, 0 if otherwise.

We up through only one level of PcodeOp calculation and only for certain binary ops where the second parameter is a constant.

Parameters
op1is the first given PcodeOp to test
op2is the second given PcodeOp
Returns
1 if the same value is produced, 0 otherwise

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_XOR, ghidra::CPUI_SUBPIECE, and ghidra::PcodeOp::getIn().

◆ quasiCopy()

Varnode * ghidra::GuardRecord::quasiCopy ( Varnode vn,
int4 &  bitsPreserved 
)
static

Compute the source of a quasi-COPY chain for the given Varnode.

A value is a quasi-copy if a sequence of PcodeOps producing it always hold the value as the least significant bits of their output Varnode, but the sequence may put other non-zero values in the upper bits. This method computes the earliest ancestor Varnode for which the given Varnode can be viewed as a quasi-copy.

Parameters
vnis the given Varnode
bitsPreservedwill hold the number of least significant bits preserved by the sequence
Returns
the earliest source of the quasi-copy, which may just be the given Varnode

References ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_SEXT, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_PIECE, ghidra::CPUI_SUBPIECE, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getNZMask(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), and ghidra::Varnode::isConstant().

Referenced by ghidra::JumpBasic::calcRange(), and ghidra::JumpBasic::markFoldableGuards().

◆ valueMatch()

int4 ghidra::GuardRecord::valueMatch ( Varnode vn2,
Varnode baseVn2,
int4  bitsPreserved2 
) const

Determine if this guard applies to the given Varnode.

The guard applies if we know the given Varnode holds the same value as the Varnode attached to the guard. So we return:

  • 0, if the two Varnodes do not clearly hold the same value.
  • 1, if the two Varnodes clearly hold the same value.
  • 2, if the two Varnode clearly hold the same value, pending no writes between their defining op.
Parameters
vn2is the given Varnode being tested against this guard
baseVn2is the earliest Varnode from which the given Varnode is quasi-copied.
bitsPreserved2is the number of potentially non-zero bits in the given Varnode
Returns
the matching code 0, 1, or 2

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_LOAD, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), and ghidra::Varnode::isWritten().

Referenced by ghidra::JumpBasic::calcRange(), and ghidra::JumpBasic::markFoldableGuards().


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