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

Class encapsulating the action/behavior of specific pcode opcodes. More...

#include <opbehavior.hh>

Inheritance diagram for ghidra::OpBehavior:
ghidra::OpBehaviorBoolAnd ghidra::OpBehaviorBoolNegate ghidra::OpBehaviorBoolOr ghidra::OpBehaviorBoolXor ghidra::OpBehaviorCopy ghidra::OpBehaviorEqual ghidra::OpBehaviorFloatAbs ghidra::OpBehaviorFloatAdd ghidra::OpBehaviorFloatCeil ghidra::OpBehaviorFloatDiv ghidra::OpBehaviorFloatEqual ghidra::OpBehaviorFloatFloat2Float ghidra::OpBehaviorFloatFloor ghidra::OpBehaviorFloatInt2Float ghidra::OpBehaviorFloatLess ghidra::OpBehaviorFloatLessEqual ghidra::OpBehaviorFloatMult ghidra::OpBehaviorFloatNan ghidra::OpBehaviorFloatNeg ghidra::OpBehaviorFloatNotEqual ghidra::OpBehaviorFloatRound ghidra::OpBehaviorFloatSqrt ghidra::OpBehaviorFloatSub ghidra::OpBehaviorFloatTrunc ghidra::OpBehaviorInt2Comp ghidra::OpBehaviorIntAdd ghidra::OpBehaviorIntAnd ghidra::OpBehaviorIntCarry ghidra::OpBehaviorIntDiv ghidra::OpBehaviorIntLeft ghidra::OpBehaviorIntLess ghidra::OpBehaviorIntLessEqual ghidra::OpBehaviorIntMult ghidra::OpBehaviorIntNegate ghidra::OpBehaviorIntOr ghidra::OpBehaviorIntRem ghidra::OpBehaviorIntRight ghidra::OpBehaviorIntSborrow ghidra::OpBehaviorIntScarry ghidra::OpBehaviorIntSdiv ghidra::OpBehaviorIntSext ghidra::OpBehaviorIntSless ghidra::OpBehaviorIntSlessEqual ghidra::OpBehaviorIntSrem ghidra::OpBehaviorIntSright ghidra::OpBehaviorIntSub ghidra::OpBehaviorIntXor ghidra::OpBehaviorIntZext ghidra::OpBehaviorLzcount ghidra::OpBehaviorNotEqual ghidra::OpBehaviorPiece ghidra::OpBehaviorPopcount ghidra::OpBehaviorSubpiece

Public Member Functions

 OpBehavior (OpCode opc, bool isun)
 A behavior constructor. More...
 
 OpBehavior (OpCode opc, bool isun, bool isspec)
 A special behavior constructor. More...
 
OpCode getOpcode (void) const
 Get the opcode for this pcode operation. More...
 
bool isSpecial (void) const
 Check if this is a special operator. More...
 
bool isUnary (void) const
 Check if operator is unary. More...
 
virtual uintb evaluateUnary (int4 sizeout, int4 sizein, uintb in1) const
 Emulate the unary op-code on an input value. More...
 
virtual uintb evaluateBinary (int4 sizeout, int4 sizein, uintb in1, uintb in2) const
 Emulate the binary op-code on input values. More...
 
virtual uintb recoverInputBinary (int4 slot, int4 sizeout, uintb out, int4 sizein, uintb in) const
 Reverse the binary op-code operation, recovering an input value. More...
 
virtual uintb recoverInputUnary (int4 sizeout, uintb out, int4 sizein) const
 Reverse the unary op-code operation, recovering the input value. More...
 

Static Public Member Functions

static void registerInstructions (vector< OpBehavior *> &inst, const Translate *trans)
 Build all pcode behaviors. More...
 

Private Attributes

OpCode opcode
 the internal enumeration for pcode types
 
bool isunary
 true= use unary interfaces, false = use binary
 
bool isspecial
 Is op not a normal unary or binary op.
 

Detailed Description

Class encapsulating the action/behavior of specific pcode opcodes.

At the lowest level, a pcode op is one of a small set of opcodes that operate on varnodes (address space, offset, size). Classes derived from this base class encapsulate this basic behavior for each possible opcode. These classes describe the most basic behaviors and include:

Constructor & Destructor Documentation

◆ OpBehavior() [1/2]

ghidra::OpBehavior::OpBehavior ( OpCode  opc,
bool  isun 
)
inline

A behavior constructor.

This kind of OpBehavior is associated with a particular opcode and is either unary or binary

Parameters
opcis the opcode of the behavior
isunis true if the behavior is unary, false if binary

Referenced by registerInstructions().

◆ OpBehavior() [2/2]

ghidra::OpBehavior::OpBehavior ( OpCode  opc,
bool  isun,
bool  isspec 
)
inline

A special behavior constructor.

This kind of OpBehavior can be set to special, if it neither unary or binary.

Parameters
opcis the opcode of the behavior
isunis true if the behavior is unary
isspecis true if the behavior is neither unary or binary

Member Function Documentation

◆ evaluateBinary()

uintb ghidra::OpBehavior::evaluateBinary ( int4  sizeout,
int4  sizein,
uintb  in1,
uintb  in2 
) const
virtual

Emulate the binary op-code on input values.

Parameters
sizeoutis the size of the output in bytes
sizeinis the size of the inputs in bytes
in1is the first input value
in2is the second input value
Returns
the output value

Reimplemented in ghidra::OpBehaviorSubpiece, ghidra::OpBehaviorPiece, ghidra::OpBehaviorFloatSub, ghidra::OpBehaviorFloatMult, ghidra::OpBehaviorFloatDiv, ghidra::OpBehaviorFloatAdd, ghidra::OpBehaviorFloatLessEqual, ghidra::OpBehaviorFloatLess, ghidra::OpBehaviorFloatNotEqual, ghidra::OpBehaviorFloatEqual, ghidra::OpBehaviorBoolOr, ghidra::OpBehaviorBoolAnd, ghidra::OpBehaviorBoolXor, ghidra::OpBehaviorIntSrem, ghidra::OpBehaviorIntRem, ghidra::OpBehaviorIntSdiv, ghidra::OpBehaviorIntDiv, ghidra::OpBehaviorIntMult, ghidra::OpBehaviorIntSright, ghidra::OpBehaviorIntRight, ghidra::OpBehaviorIntLeft, ghidra::OpBehaviorIntOr, ghidra::OpBehaviorIntAnd, ghidra::OpBehaviorIntXor, ghidra::OpBehaviorIntSborrow, ghidra::OpBehaviorIntScarry, ghidra::OpBehaviorIntCarry, ghidra::OpBehaviorIntSub, ghidra::OpBehaviorIntAdd, ghidra::OpBehaviorIntLessEqual, ghidra::OpBehaviorIntLess, ghidra::OpBehaviorIntSlessEqual, ghidra::OpBehaviorIntSless, ghidra::OpBehaviorNotEqual, and ghidra::OpBehaviorEqual.

References opcode.

Referenced by ghidra::TypeOp::evaluateBinary(), ghidra::OpBehaviorFloatEqual::evaluateBinary(), ghidra::OpBehaviorFloatNotEqual::evaluateBinary(), ghidra::OpBehaviorFloatLess::evaluateBinary(), ghidra::OpBehaviorFloatLessEqual::evaluateBinary(), ghidra::OpBehaviorFloatAdd::evaluateBinary(), ghidra::OpBehaviorFloatDiv::evaluateBinary(), ghidra::OpBehaviorFloatMult::evaluateBinary(), ghidra::OpBehaviorFloatSub::evaluateBinary(), ghidra::EmulatePcodeOp::executeBinary(), and ghidra::EmulateSnippet::executeBinary().

◆ evaluateUnary()

uintb ghidra::OpBehavior::evaluateUnary ( int4  sizeout,
int4  sizein,
uintb  in1 
) const
virtual

◆ getOpcode()

OpCode ghidra::OpBehavior::getOpcode ( void  ) const
inline

Get the opcode for this pcode operation.

There is an internal enumeration value for each type of pcode operation. This routine returns that value.

Returns
the opcode value

◆ isSpecial()

bool ghidra::OpBehavior::isSpecial ( void  ) const
inline

Check if this is a special operator.

If this function returns false, the operation is a normal unary or binary operation which can be evaluated calling evaluateBinary() or evaluateUnary(). Otherwise, the operation requires special handling to emulate properly

◆ isUnary()

bool ghidra::OpBehavior::isUnary ( void  ) const
inline

Check if operator is unary.

The operated can either be evaluated as unary or binary

Returns
true if the operator is unary

◆ recoverInputBinary()

uintb ghidra::OpBehavior::recoverInputBinary ( int4  slot,
int4  sizeout,
uintb  out,
int4  sizein,
uintb  in 
) const
virtual

Reverse the binary op-code operation, recovering an input value.

If the output value and one of the input values is known, recover the value of the other input.

Parameters
slotis the input slot to recover
sizeoutis the size of the output in bytes
outis the output value
sizeinis the size of the inputs in bytes
inis the known input value
Returns
the input value corresponding to the slot

Reimplemented in ghidra::OpBehaviorIntSright, ghidra::OpBehaviorIntRight, ghidra::OpBehaviorIntLeft, ghidra::OpBehaviorIntSub, and ghidra::OpBehaviorIntAdd.

Referenced by ghidra::TypeOp::recoverInputBinary(), ghidra::OpBehaviorIntLeft::recoverInputBinary(), ghidra::OpBehaviorIntRight::recoverInputBinary(), and ghidra::OpBehaviorIntSright::recoverInputBinary().

◆ recoverInputUnary()

uintb ghidra::OpBehavior::recoverInputUnary ( int4  sizeout,
uintb  out,
int4  sizein 
) const
virtual

Reverse the unary op-code operation, recovering the input value.

If the output value is known, recover the input value.

Parameters
sizeoutis the size of the output in bytes
outis the output value
sizeinis the size of the input in bytes
Returns
the input value

Reimplemented in ghidra::OpBehaviorIntNegate, ghidra::OpBehaviorInt2Comp, ghidra::OpBehaviorIntSext, ghidra::OpBehaviorIntZext, and ghidra::OpBehaviorCopy.

Referenced by ghidra::TypeOp::recoverInputUnary().

◆ registerInstructions()

void ghidra::OpBehavior::registerInstructions ( vector< OpBehavior *> &  inst,
const Translate trans 
)
static

Build all pcode behaviors.

This routine generates a vector of OpBehavior objects indexed by opcode

Parameters
instis the vector of behaviors to be filled
transis the translator object needed by the floating point behaviors

References ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::CPUI_BOOL_XOR, ghidra::CPUI_BRANCH, ghidra::CPUI_BRANCHIND, ghidra::CPUI_CALL, ghidra::CPUI_CALLIND, ghidra::CPUI_CALLOTHER, ghidra::CPUI_CAST, ghidra::CPUI_CBRANCH, ghidra::CPUI_COPY, ghidra::CPUI_CPOOLREF, ghidra::CPUI_EXTRACT, ghidra::CPUI_FLOAT_ABS, ghidra::CPUI_FLOAT_ADD, ghidra::CPUI_FLOAT_CEIL, ghidra::CPUI_FLOAT_DIV, ghidra::CPUI_FLOAT_EQUAL, ghidra::CPUI_FLOAT_FLOAT2FLOAT, ghidra::CPUI_FLOAT_FLOOR, ghidra::CPUI_FLOAT_INT2FLOAT, ghidra::CPUI_FLOAT_LESS, ghidra::CPUI_FLOAT_LESSEQUAL, ghidra::CPUI_FLOAT_MULT, ghidra::CPUI_FLOAT_NAN, ghidra::CPUI_FLOAT_NEG, ghidra::CPUI_FLOAT_NOTEQUAL, ghidra::CPUI_FLOAT_ROUND, ghidra::CPUI_FLOAT_SQRT, ghidra::CPUI_FLOAT_SUB, ghidra::CPUI_FLOAT_TRUNC, ghidra::CPUI_INDIRECT, ghidra::CPUI_INSERT, ghidra::CPUI_INT_2COMP, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_CARRY, ghidra::CPUI_INT_DIV, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_LESSEQUAL, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_NEGATE, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_REM, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SBORROW, ghidra::CPUI_INT_SCARRY, ghidra::CPUI_INT_SDIV, ghidra::CPUI_INT_SEXT, ghidra::CPUI_INT_SLESS, ghidra::CPUI_INT_SLESSEQUAL, ghidra::CPUI_INT_SREM, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_SUB, ghidra::CPUI_INT_XOR, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_LOAD, ghidra::CPUI_LZCOUNT, ghidra::CPUI_MAX, ghidra::CPUI_MULTIEQUAL, ghidra::CPUI_NEW, ghidra::CPUI_PIECE, ghidra::CPUI_POPCOUNT, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_RETURN, ghidra::CPUI_SEGMENTOP, ghidra::CPUI_STORE, ghidra::CPUI_SUBPIECE, and OpBehavior().

Referenced by ghidra::EmulatePcodeCache::EmulatePcodeCache().


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