Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
ghidra::PackedEncode Class Reference

A byte-based encoder designed to marshal from the decompiler efficiently. More...

#include <marshal.hh>

Inheritance diagram for ghidra::PackedEncode:
[legend]
Collaboration diagram for ghidra::PackedEncode:
[legend]

Public Member Functions

 PackedEncode (ostream &s)
 Construct from a stream.
 
virtual void openElement (const ElementId &elemId)
 Begin a new element in the encoding.
 
virtual void closeElement (const ElementId &elemId)
 End the current element in the encoding.
 
virtual void writeBool (const AttributeId &attribId, bool val)
 Write an annotated boolean value into the encoding.
 
virtual void writeSignedInteger (const AttributeId &attribId, intb val)
 Write an annotated signed integer value into the encoding.
 
virtual void writeUnsignedInteger (const AttributeId &attribId, uintb val)
 Write an annotated unsigned integer value into the encoding.
 
virtual void writeString (const AttributeId &attribId, const string &val)
 Write an annotated string into the encoding.
 
virtual void writeStringIndexed (const AttributeId &attribId, uint4 index, const string &val)
 Write an annotated string, using an indexed attribute, into the encoding.
 
virtual void writeSpace (const AttributeId &attribId, const AddrSpace *spc)
 Write an address space reference into the encoding.
 
virtual void writeOpcode (const AttributeId &attribId, OpCode opc)
 Write a p-code operation opcode into the encoding, associating it with the given annotation.
 
- Public Member Functions inherited from ghidra::Encoder
virtual ~Encoder (void)
 Destructor.
 

Private Member Functions

void writeHeader (uint1 header, uint4 id)
 Write a header, element or attribute, to stream.
 
void writeInteger (uint1 typeByte, uint8 val)
 Write an integer value to the stream.
 

Private Attributes

ostream & outStream
 The stream receiving the encoded data.
 

Detailed Description

A byte-based encoder designed to marshal from the decompiler efficiently.

See PackedDecode for details of the encoding format.

Member Function Documentation

◆ closeElement()

◆ openElement()

◆ writeBool()

void ghidra::PackedEncode::writeBool ( const AttributeId attribId,
bool  val 
)
virtual

Write an annotated boolean value into the encoding.

The boolean data is associated with the given AttributeId annotation and the current open element.

Parameters
attribIdis the given AttributeId annotation
valis boolean value to encode

Implements ghidra::Encoder.

References ghidra::PackedFormat::ATTRIBUTE, ghidra::AttributeId::getId(), outStream, ghidra::PackedFormat::TYPECODE_BOOLEAN, ghidra::PackedFormat::TYPECODE_SHIFT, and writeHeader().

◆ writeHeader()

void ghidra::PackedEncode::writeHeader ( uint1  header,
uint4  id 
)
inlineprivate

Write a header, element or attribute, to stream.

Parameters
headeris the type of header
idis the id associated with the element or attribute

References ghidra::PackedFormat::HEADEREXTEND_MASK, outStream, ghidra::PackedFormat::RAWDATA_BITSPERBYTE, ghidra::PackedFormat::RAWDATA_MARKER, and ghidra::PackedFormat::RAWDATA_MASK.

Referenced by closeElement(), openElement(), writeBool(), writeOpcode(), writeSignedInteger(), writeSpace(), writeString(), writeStringIndexed(), and writeUnsignedInteger().

◆ writeInteger()

void ghidra::PackedEncode::writeInteger ( uint1  typeByte,
uint8  val 
)
private

Write an integer value to the stream.

The value is either an unsigned integer, an address space index, or (the absolute value of) a signed integer. A type header is passed in with the particular type code for the value already filled in. This method then fills in the length code, outputs the full type header and the encoded bytes of the integer.

Parameters
typeByteis the type header
valis the integer value

References outStream, ghidra::PackedFormat::RAWDATA_BITSPERBYTE, ghidra::PackedFormat::RAWDATA_MARKER, and ghidra::PackedFormat::RAWDATA_MASK.

Referenced by writeOpcode(), writeSignedInteger(), writeSpace(), writeString(), writeStringIndexed(), and writeUnsignedInteger().

◆ writeOpcode()

void ghidra::PackedEncode::writeOpcode ( const AttributeId attribId,
OpCode  opc 
)
virtual

Write a p-code operation opcode into the encoding, associating it with the given annotation.

Parameters
attribIdis the given annotation
opcis the opcode

Implements ghidra::Encoder.

References ghidra::PackedFormat::ATTRIBUTE, ghidra::AttributeId::getId(), ghidra::PackedFormat::TYPECODE_SHIFT, ghidra::PackedFormat::TYPECODE_SIGNEDINT_POSITIVE, writeHeader(), and writeInteger().

◆ writeSignedInteger()

void ghidra::PackedEncode::writeSignedInteger ( const AttributeId attribId,
intb  val 
)
virtual

◆ writeSpace()

◆ writeString()

void ghidra::PackedEncode::writeString ( const AttributeId attribId,
const string &  val 
)
virtual

◆ writeStringIndexed()

void ghidra::PackedEncode::writeStringIndexed ( const AttributeId attribId,
uint4  index,
const string &  val 
)
virtual

Write an annotated string, using an indexed attribute, into the encoding.

Multiple attributes with a shared name can be written to the same element by calling this method multiple times with a different index value. The encoding will use attribute ids up to the base id plus the maximum index passed in. Implementors must be careful to not use other attributes with ids bigger than the base id within the element taking the indexed attribute.

Parameters
attribIdis the shared AttributeId
indexis the unique index to associated with the string
valis the string to encode

Implements ghidra::Encoder.

References ghidra::PackedFormat::ATTRIBUTE, ghidra::AttributeId::getId(), outStream, ghidra::PackedFormat::TYPECODE_SHIFT, ghidra::PackedFormat::TYPECODE_STRING, writeHeader(), and writeInteger().

◆ writeUnsignedInteger()

void ghidra::PackedEncode::writeUnsignedInteger ( const AttributeId attribId,
uintb  val 
)
virtual

Write an annotated unsigned integer value into the encoding.

The integer is associated with the given AttributeId annotation and the current open element.

Parameters
attribIdis the given AttributeId annotation
valis the unsigned integer value to encode

Implements ghidra::Encoder.

References ghidra::PackedFormat::ATTRIBUTE, ghidra::AttributeId::getId(), ghidra::PackedFormat::TYPECODE_SHIFT, ghidra::PackedFormat::TYPECODE_UNSIGNEDINT, writeHeader(), and writeInteger().

Referenced by ghidra::ArchitectureGhidra::getComments(), ghidra::ArchitectureGhidra::getCPoolRef(), ghidra::ArchitectureGhidra::getNamespacePath(), ghidra::ArchitectureGhidra::getStringData(), ghidra::ArchitectureGhidra::isNameUsed(), and ghidra::GetSignatureSettings::rawAction().


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