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

A constant value encountered during SLEIGH parsing. More...

#include <semantics.hh>

Public Types

enum  const_type {
  real =0 , handle =1 , j_start =2 , j_next =3 ,
  j_next2 =4 , j_curspace =5 , j_curspace_size =6 , spaceid =7 ,
  j_relative =8 , j_flowref =9 , j_flowref_size =10 , j_flowdest =11 ,
  j_flowdest_size =12
}
 Types of constant values encountered during SLEIGH parsing. More...
 
enum  v_field { v_space =0 , v_offset =1 , v_size =2 , v_offset_plus =3 }
 For a handle (a value calculated in a sub-constructor), we can sub-select which part of the value to use. More...
 

Public Member Functions

 ConstTpl (void)
 Construct a zero constant.
 
 ConstTpl (const ConstTpl &op2)
 Copy constructor.
 
 ConstTpl (const_type tp, uintb val)
 Constructor for real constants or relative offsets. More...
 
 ConstTpl (const_type tp)
 Constructor for special constants from context. More...
 
 ConstTpl (AddrSpace *sid)
 Constructor for a constant representing an address space. More...
 
 ConstTpl (const_type tp, int4 ht, v_field vf)
 Constructor for a handle constant. More...
 
 ConstTpl (const_type tp, int4 ht, v_field vf, uintb plus)
 Constructor for a handle offset plus a constant. More...
 
bool isConstSpace (void) const
 Return true if this represents the constant address space.
 
bool isUniqueSpace (void) const
 Return true if this represents the unique address space.
 
bool operator== (const ConstTpl &op2) const
 Compare two constants for equality. More...
 
bool operator< (const ConstTpl &op2) const
 Order two constants by type then value. More...
 
uintb getReal (void) const
 Get the literal constant value associated with this.
 
AddrSpace * getSpace (void) const
 Get the address space this is encoding.
 
int4 getHandleIndex (void) const
 Get the index of the sub-constructor computing this.
 
const_type getType (void) const
 Get the constant type.
 
v_field getSelect (void) const
 Get the type of handle piece this is encoding.
 
uintb fix (const ParserWalker &walker) const
 Get the final constant value of this in context. More...
 
AddrSpace * fixSpace (const ParserWalker &walker) const
 Get the final address space this represents in context.
 
void transfer (const vector< HandleTpl * > &params)
 Copy a handle into this based on the handle_index. More...
 
bool isZero (void) const
 Return true if this is a literal zero.
 
void changeHandleIndex (const vector< int4 > &handmap)
 Remap the handle index for this. More...
 
void fillinSpace (FixedHandle &hand, const ParserWalker &walker) const
 Fill in the address space of a FixedHandle, based on this. More...
 
void fillinOffset (FixedHandle &hand, const ParserWalker &walker) const
 Fill in the offset of a FixedHandle, based on this. More...
 
void encode (Encoder &encoder) const
 Encode this SLEIGH constant to an output stream. More...
 
void decode (Decoder &decoder)
 Decode this SLEIGH constant from a stream. More...
 

Private Attributes

const_type type
 The type of constant.
 
union {
   AddrSpace *   spaceid
 Id referring to a registered address space.
 
   int4   handle_index
 For a handle, the index of the specific sub-constructor passing back the value.
 
} value
 Specialized values a ConstTpl can represent.
 
uintb value_real
 An immediate constant value or other constant offset a ConstTpl represents.
 
v_field select
 Assuming ConstTpl is a handle, the part of the handle to use as constant.
 

Detailed Description

A constant value encountered during SLEIGH parsing.

Any offset, size, address space, or literal constant encountered during parsing that ultimately resolves to a constant value when disassembling or generating p-code for a specific instruction. The object holds details about how to calculate the final constant from the SLEIGH context for the instruction.

Member Enumeration Documentation

◆ const_type

Types of constant values encountered during SLEIGH parsing.

Enumerator
real 

A literal constant.

handle 

Placeholder for a value passed back by a sub-constructor.

j_start 

Address offset for the start of the current instruction.

j_next 

Address offset for the start of the next instruction.

j_next2 

Address offset of the instruction immediately after the next instruction.

j_curspace 

Address space containing the current instruction.

j_curspace_size 

Number of bytes encoding the address of the current instruction.

spaceid 

An address space (encoded as a constant)

j_relative 

A relative p-code branch offset.

j_flowref 

Address offset of any call reference at site of p-code injection.

j_flowref_size 

Number of bytes encoding address of call reference.

j_flowdest 

Address offset of call destination being injected.

j_flowdest_size 

Number of bytes encoding address of call destination.

◆ v_field

For a handle (a value calculated in a sub-constructor), we can sub-select which part of the value to use.

Enumerator
v_space 

The address space associated with the handle.

v_offset 

The offset associated with the handle.

v_size 

Number of bytes in the handle.

v_offset_plus 

The offset associated with the handle plus an additional constant offset.

Constructor & Destructor Documentation

◆ ConstTpl() [1/5]

ghidra::ConstTpl::ConstTpl ( const_type  tp,
uintb  val 
)

Constructor for real constants or relative offsets.

Parameters
tpis constant type: either real or j_relative
valis the constant value

References select, type, v_space, value, and value_real.

◆ ConstTpl() [2/5]

ghidra::ConstTpl::ConstTpl ( const_type  tp)

Constructor for special constants from context.

Parameters
tpis the specialized constant type: j_start, j_next, j_next2, j_flowdest, j_curspace, etc.

References type.

◆ ConstTpl() [3/5]

ghidra::ConstTpl::ConstTpl ( AddrSpace *  sid)

Constructor for a constant representing an address space.

Parameters
sidis the address space to encode

References spaceid, type, and value.

◆ ConstTpl() [4/5]

ghidra::ConstTpl::ConstTpl ( const_type  tp,
int4  ht,
v_field  vf 
)

Constructor for a handle constant.

Parameters
tpis the constant type: must be handle
htis the index of the sub-constructor computing the handle value
vfis the part (space, offset, or size) of the computed value to encode as the constant

References handle, select, type, value, and value_real.

◆ ConstTpl() [5/5]

ghidra::ConstTpl::ConstTpl ( const_type  tp,
int4  ht,
v_field  vf,
uintb  plus 
)

Constructor for a handle offset plus a constant.

Parameters
tpis the constant type: must be handle
htis the index of the sub-constructor computing the handle value
vfis the part of the computed value to encode: must be v_offset_plus
plusis the additional constant value to add to the handle offset

References handle, select, type, value, and value_real.

Member Function Documentation

◆ changeHandleIndex()

void ghidra::ConstTpl::changeHandleIndex ( const vector< int4 > &  handmap)

Remap the handle index for this.

This is used to help reorder sub-constructors. If this is a handle, its index is translated by looking up a new value in the given array of indices.

Parameters
handmapis the given array of new handle indices

References handle, type, and value.

Referenced by ghidra::VarnodeTpl::changeHandleIndex(), and ghidra::HandleTpl::changeHandleIndex().

◆ decode()

void ghidra::ConstTpl::decode ( Decoder &  decoder)

◆ encode()

void ghidra::ConstTpl::encode ( Encoder &  encoder) const

◆ fillinOffset()

void ghidra::ConstTpl::fillinOffset ( FixedHandle &  hand,
const ParserWalker &  walker 
) const

Fill in the offset of a FixedHandle, based on this.

First, this is fixed, based on the current context. Then the final fixed value is copied into the FixedHandle. If this itself is a handle, the entire fixed handle is copied into the FixedHandle.

Parameters
handis the FixedHandle to copy into
walkeris the context to fix against

References fix(), ghidra::ParserWalker::getFixedHandle(), handle, ghidra::FixedHandle::offset_offset, ghidra::FixedHandle::offset_size, ghidra::FixedHandle::offset_space, ghidra::FixedHandle::space, ghidra::FixedHandle::temp_offset, ghidra::FixedHandle::temp_space, type, value, and ghidra::AddrSpace::wrapOffset().

Referenced by ghidra::HandleTpl::fix().

◆ fillinSpace()

void ghidra::ConstTpl::fillinSpace ( FixedHandle &  hand,
const ParserWalker &  walker 
) const

Fill in the address space of a FixedHandle, based on this.

If this represents an address space, including if this is the address space piece of a handle, replace the address space portion of the FixedHandle with this.

Parameters
handis the FixedHandle to replace
walkeris the current context

References ghidra::ParserWalker::getCurSpace(), ghidra::ParserWalker::getFixedHandle(), handle, j_curspace, select, ghidra::FixedHandle::space, spaceid, type, v_space, and value.

Referenced by ghidra::HandleTpl::fix().

◆ fix()

uintb ghidra::ConstTpl::fix ( const ParserWalker &  walker) const

◆ operator<()

bool ghidra::ConstTpl::operator< ( const ConstTpl &  op2) const

Order two constants by type then value.

Parameters
op2is the constant to compare with this
Returns
true if this should be ordered before op2

References handle, handle_index, real, select, spaceid, type, value, and value_real.

◆ operator==()

bool ghidra::ConstTpl::operator== ( const ConstTpl &  op2) const

Compare two constants for equality.

The constants must be equal in both value and type.

Parameters
op2is the constant to compare with this
Returns
true if this is equal to op2, false otherwise

References handle, handle_index, real, select, spaceid, type, value, and value_real.

◆ transfer()

void ghidra::ConstTpl::transfer ( const vector< HandleTpl * > &  params)

Copy a handle into this based on the handle_index.

If this is not a handle, do nothing. Otherwise, copy the details of the indexed HandleTpl into this. Copy the piece of the HandleTpl specified by select.

Parameters
paramsis the array of HandleTpl

References ghidra::HandleTpl::getPtrOffset(), ghidra::HandleTpl::getSize(), ghidra::HandleTpl::getSpace(), handle, real, select, type, v_offset, v_offset_plus, v_size, v_space, value, and value_real.

Referenced by ghidra::VarnodeTpl::transfer().


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