decompiler 1.0.0
Public Member Functions | Protected Attributes | List of all members
Decoder Class Referenceabstract

A class for reading structured data from a stream. More...

#include <marshal.hh>

Inheritance diagram for Decoder:
PackedDecode XmlDecode

Public Member Functions

 Decoder (const AddrSpaceManager *spc)
 Base constructor.
 
const AddrSpaceManagergetAddrSpaceManager (void) const
 Get the manager used for address space decoding.
 
virtual ~Decoder (void)
 Destructor.
 
virtual void ingestStream (istream &s)=0
 Prepare to decode a given stream. More...
 
virtual uint4 peekElement (void)=0
 Peek at the next child element of the current parent, without traversing in (opening) it. More...
 
virtual uint4 openElement (void)=0
 Open (traverse into) the next child element of the current parent. More...
 
virtual uint4 openElement (const ElementId &elemId)=0
 Open (traverse into) the next child element, which must be of a specific type. More...
 
virtual void closeElement (uint4 id)=0
 Close the current element. More...
 
virtual void closeElementSkipping (uint4 id)=0
 Close the current element, skipping any child elements that have not yet been parsed. More...
 
virtual uint4 getNextAttributeId (void)=0
 Get the next attribute id for the current element. More...
 
virtual void rewindAttributes (void)=0
 Reset attribute traversal for the current element. More...
 
virtual bool readBool (void)=0
 Parse the current attribute as a boolean value. More...
 
virtual bool readBool (const AttributeId &attribId)=0
 Find and parse a specific attribute in the current element as a boolean value. More...
 
virtual intb readSignedInteger (void)=0
 Parse the current attribute as a signed integer value. More...
 
virtual intb readSignedInteger (const AttributeId &attribId)=0
 Find and parse a specific attribute in the current element as a signed integer. More...
 
virtual uintb readUnsignedInteger (void)=0
 Parse the current attribute as an unsigned integer value. More...
 
virtual uintb readUnsignedInteger (const AttributeId &attribId)=0
 Find and parse a specific attribute in the current element as an unsigned integer. More...
 
virtual string readString (void)=0
 Parse the current attribute as a string. More...
 
virtual string readString (const AttributeId &attribId)=0
 Find the specific attribute in the current element and return it as a string. More...
 
virtual AddrSpacereadSpace (void)=0
 Parse the current attribute as an address space. More...
 
virtual AddrSpacereadSpace (const AttributeId &attribId)=0
 Find the specific attribute in the current element and return it as an address space. More...
 
void skipElement (void)
 Skip parsing of the next element. More...
 

Protected Attributes

const AddrSpaceManagerspcManager
 Manager for decoding address space attributes.
 

Detailed Description

A class for reading structured data from a stream.

All data is loosely structured as with an XML document. A document contains a nested set of elements, with labels corresponding to the ElementId class. A single element can hold zero or more attributes and zero or more child elements. An attribute holds a primitive data element (bool, integer, string) and is labeled by an AttributeId. The document is traversed using a sequence of openElement() and closeElement() calls, intermixed with read*() calls to extract the data. The elements are traversed in a depth first order. Attributes within an element can be traversed in order using repeated calls to the getNextAttributeId() method, followed by a calls to one of the read*(void) methods to extract the data. Alternately a read*(AttributeId) call can be used to extract data for an attribute known to be in the element. There is a special content attribute whose data can be extracted using a read*(AttributeId) call that is passed the special ATTRIB_CONTENT id. This attribute will not be traversed by getNextAttribute().

Member Function Documentation

◆ closeElement()

virtual void Decoder::closeElement ( uint4  id)
pure virtual

Close the current element.

The data for the current element is considered fully processed. If the element has additional children, an exception is thrown. The stream must indicate the end of the element in some way.

Parameters
idis the id of the element to close (which must be the current element)

Implemented in XmlDecode, and PackedDecode.

Referenced by Scope::addMapSym(), SeqNum::decode(), Range::decode(), RangeProperties::decode(), RangeList::decode(), Comment::decode(), CommentDatabaseInternal::decode(), ConstantPoolInternal::CheapSorter::decode(), SymbolEntry::decode(), Symbol::decode(), FunctionSymbol::decode(), EquateSymbol::decode(), UnionFacetSymbol::decode(), LabSymbol::decode(), ExternRefSymbol::decode(), ScopeInternal::decode(), Database::decode(), ProtoModel::decode(), ProtoModelMerged::decode(), Funcdata::decode(), GhidraTranslate::decode(), TrackedContext::decode(), ContextInternal::decode(), InjectCallotherGhidra::decode(), LoadTable::decode(), JumpBasicOverride::decode(), JumpTable::decode(), OptionDatabase::decode(), VarnodeData::decode(), CompilerTag::decode(), LanguageDescription::decode(), AddrSpace::decode(), OverlaySpace::decode(), StringManager::decode(), LanedRegister::decode(), TruncationTag::decode(), SpacebaseSpace::decode(), TypeFactory::decode(), SegmentOp::decode(), JumpAssistOp::decode(), Override::decode(), BlockEdge::decode(), FlowBlock::decode(), ParamEntry::decode(), PcodeOpRaw::decode(), ProtoStoreInternal::decode(), CPoolRecord::decode(), ConstantPoolInternal::decode(), TypeEnum::decode(), TypePointerRel::decode(), ParamListStandard::decode(), Architecture::decodeAggressiveTrim(), BlockGraph::decodeBody(), ScopeInternal::decodeCollision(), ContextInternal::decodeContext(), TypeFactory::decodeCoreTypes(), TypeFactory::decodeDataOrganization(), Architecture::decodeDeadcodeDelay(), Architecture::decodeDefaultProto(), Architecture::decodeDynamicRule(), Architecture::decodeFlowOverride(), ContextInternal::decodeFromSpec(), Architecture::decodeFuncPtrAlign(), Architecture::decodeGlobal(), ScopeInternal::decodeHole(), ScopeGhidra::decodeHole(), Architecture::decodeIncidentalCopy(), Architecture::decodeInferPtrBounds(), Funcdata::decodeJumpTable(), Architecture::decodeLaneSizes(), Architecture::decodeNoHighPtr(), OptionDatabase::decodeOne(), PcodeEmit::decodeOp(), InjectPayload::decodeParameter(), Architecture::decodePreferSplit(), Architecture::decodeProtoEval(), Architecture::decodeReadOnly(), Architecture::decodeReturnAddress(), Database::decodeScope(), Architecture::decodeSpacebase(), AddrSpaceManager::decodeSpaces(), Architecture::decodeStackPointer(), TypeFactory::decodeType(), TypeFactory::decodeTypeNoRef(), TypeFactory::decodeTypeWithCodeFlags(), Architecture::decodeVolatile(), ScopeGhidra::dump2Cache(), TypeFactory::parseEnumConfig(), ParamListStandard::parseGroup(), Database::parseParentTag(), and TypeField::TypeField().

◆ closeElementSkipping()

virtual void Decoder::closeElementSkipping ( uint4  id)
pure virtual

Close the current element, skipping any child elements that have not yet been parsed.

This closes the given element, which must be current. If there are child elements that have not been parsed, this is not considered an error, and they are skipped over in the parse.

Parameters
idis the id of the element to close (which must be the current element)

Implemented in XmlDecode, and PackedDecode.

Referenced by InjectPayloadGhidra::decode(), InjectCallfixupGhidra::decode(), InjectCallotherGhidra::decode(), ExecutablePcodeGhidra::decode(), LanguageDescription::decode(), TypeFactory::decodeDataOrganization(), and skipElement().

◆ getNextAttributeId()

virtual uint4 Decoder::getNextAttributeId ( void  )
pure virtual

◆ ingestStream()

virtual void Decoder::ingestStream ( istream &  s)
pure virtual

Prepare to decode a given stream.

Called once before any decoding. Currently this is assumed to make an internal copy of the stream data, i.e. the input stream is cleared before any decoding takes place.

Parameters
sis the given input stream to be decode
Returns
true if the stream was fully ingested

Implemented in XmlDecode, and PackedDecode.

Referenced by ArchitectureGhidra::readStringStream().

◆ openElement() [1/2]

virtual uint4 Decoder::openElement ( const ElementId elemId)
pure virtual

Open (traverse into) the next child element, which must be of a specific type.

The child becomes the current parent, and its attributes are initialized for use with getNextAttributeId. The child must match the given element id or an exception is thrown.

Parameters
elemIdis the given element id to match
Returns
the id of the child element

Implemented in XmlDecode, and PackedDecode.

◆ openElement() [2/2]

virtual uint4 Decoder::openElement ( void  )
pure virtual

Open (traverse into) the next child element of the current parent.

The child becomes the current parent. The list of attributes is initialized for use with getNextAttributeId.

Returns
the id of the child element

Implemented in XmlDecode, and PackedDecode.

Referenced by Scope::addMapSym(), SeqNum::decode(), Range::decode(), RangeProperties::decode(), RangeList::decode(), Comment::decode(), CommentDatabaseInternal::decode(), ConstantPoolInternal::CheapSorter::decode(), SymbolEntry::decode(), Symbol::decode(), FunctionSymbol::decode(), EquateSymbol::decode(), UnionFacetSymbol::decode(), LabSymbol::decode(), ExternRefSymbol::decode(), ScopeInternal::decode(), Database::decode(), ProtoModel::decode(), ProtoModelMerged::decode(), Funcdata::decode(), GhidraTranslate::decode(), TrackedContext::decode(), ContextInternal::decode(), InjectPayloadGhidra::decode(), InjectCallfixupGhidra::decode(), InjectCallotherGhidra::decode(), ExecutablePcodeGhidra::decode(), LoadTable::decode(), JumpBasicOverride::decode(), JumpTable::decode(), OptionDatabase::decode(), VarnodeData::decode(), CompilerTag::decode(), LanguageDescription::decode(), AddrSpace::decode(), OverlaySpace::decode(), StringManager::decode(), LanedRegister::decode(), TruncationTag::decode(), SpacebaseSpace::decode(), TypeFactory::decode(), SegmentOp::decode(), JumpAssistOp::decode(), FuncProto::decode(), Override::decode(), BlockEdge::decode(), FlowBlock::decode(), ParamEntry::decode(), PcodeOpRaw::decode(), ProtoStoreInternal::decode(), CPoolRecord::decode(), ConstantPoolInternal::decode(), TypeEnum::decode(), TypePointerRel::decode(), ParamListStandard::decode(), Architecture::decodeAggressiveTrim(), BlockGraph::decodeBody(), ScopeInternal::decodeCollision(), ContextInternal::decodeContext(), TypeFactory::decodeCoreTypes(), TypeFactory::decodeDataOrganization(), Architecture::decodeDeadcodeDelay(), Architecture::decodeDefaultProto(), Architecture::decodeDynamicRule(), Architecture::decodeFlowOverride(), ContextInternal::decodeFromSpec(), Architecture::decodeFuncPtrAlign(), Architecture::decodeGlobal(), ScopeInternal::decodeHole(), ScopeGhidra::decodeHole(), Architecture::decodeIncidentalCopy(), Architecture::decodeInferPtrBounds(), Funcdata::decodeJumpTable(), Architecture::decodeLaneSizes(), Architecture::decodeNoHighPtr(), OptionDatabase::decodeOne(), PcodeEmit::decodeOp(), InjectPayload::decodeParameter(), Architecture::decodePreferSplit(), Architecture::decodeProtoEval(), Architecture::decodeReadOnly(), Architecture::decodeReturnAddress(), Database::decodeScope(), Architecture::decodeSpacebase(), AddrSpaceManager::decodeSpaces(), Architecture::decodeStackPointer(), TypeFactory::decodeType(), TypeFactory::decodeTypeNoRef(), TypeFactory::decodeTypeWithCodeFlags(), Architecture::decodeVolatile(), ScopeGhidra::dump2Cache(), TypeFactory::parseEnumConfig(), ParamListStandard::parseGroup(), Database::parseParentTag(), skipElement(), and TypeField::TypeField().

◆ peekElement()

virtual uint4 Decoder::peekElement ( void  )
pure virtual

Peek at the next child element of the current parent, without traversing in (opening) it.

The element id is returned, which can be compared to ElementId labels. If there are no remaining child elements to traverse, 0 is returned.

Returns
the element id or 0

Implemented in XmlDecode, and PackedDecode.

Referenced by Scope::addMapSym(), RangeList::decode(), Comment::decode(), CommentDatabaseInternal::decode(), SymbolEntry::decode(), FunctionSymbol::decode(), ScopeInternal::decode(), Database::decode(), ProtoModel::decode(), Funcdata::decode(), GhidraTranslate::decode(), JumpTable::decode(), OptionDatabase::decode(), LanguageDescription::decode(), TypeFactory::decode(), SegmentOp::decode(), JumpAssistOp::decode(), PcodeOpRaw::decode(), ConstantPoolInternal::decode(), ParamListStandard::decode(), BlockGraph::decodeBody(), TypeFactory::decodeCoreTypes(), Architecture::decodeDefaultProto(), FlowBlock::decodeEdges(), TypeStruct::decodeFields(), TypeUnion::decodeFields(), Architecture::decodeGlobal(), Architecture::decodeIncidentalCopy(), Architecture::decodeInferPtrBounds(), Funcdata::decodeJumpTable(), Architecture::decodeLaneSizes(), Architecture::decodeNoHighPtr(), InjectPayload::decodePayloadParams(), Architecture::decodePreferSplit(), Architecture::decodeProto(), TypeCode::decodePrototype(), Architecture::decodeReadOnly(), Architecture::decodeReturnAddress(), AddrSpaceManager::decodeSpace(), AddrSpaceManager::decodeSpaces(), TypeCode::decodeStub(), ContextDatabase::decodeTracked(), TypeFactory::decodeType(), Architecture::decodeVolatile(), ScopeGhidra::dump2Cache(), and ParamListStandard::parseGroup().

◆ readBool() [1/2]

virtual bool Decoder::readBool ( const AttributeId attribId)
pure virtual

Find and parse a specific attribute in the current element as a boolean value.

The set of attributes for the current element is searched for a match to the given attribute id. This attribute is then parsed as a boolean and its value returned. If there is no attribute matching the id, an exception is thrown. Parsing via getNextAttributeId is reset.

Parameters
attribIdis the specific attribute id to match
Returns
the boolean value

Implemented in XmlDecode, and PackedDecode.

◆ readBool() [2/2]

virtual bool Decoder::readBool ( void  )
pure virtual

◆ readSignedInteger() [1/2]

virtual intb Decoder::readSignedInteger ( const AttributeId attribId)
pure virtual

Find and parse a specific attribute in the current element as a signed integer.

The set of attributes for the current element is searched for a match to the given attribute id. This attribute is then parsed as a signed integer and its value returned. If there is no attribute matching the id, an exception is thrown. Parsing via getNextAttributeId is reset.

Parameters
attribIdis the specific attribute id to match
Returns
the signed integer value

Implemented in XmlDecode, and PackedDecode.

◆ readSignedInteger() [2/2]

virtual intb Decoder::readSignedInteger ( void  )
pure virtual

◆ readSpace() [1/2]

virtual AddrSpace * Decoder::readSpace ( const AttributeId attribId)
pure virtual

Find the specific attribute in the current element and return it as an address space.

Search attributes from the current element for a match to the given attribute id. Return this attribute as an address space. If there is no attribute matching the id, an exception is thrown. Parse via getNextAttributeId is reset.

Parameters
attribIdis the specific attribute id to match
Returns
the address space associated with the attribute

Implemented in XmlDecode, and PackedDecode.

◆ readSpace() [2/2]

virtual AddrSpace * Decoder::readSpace ( void  )
pure virtual

Parse the current attribute as an address space.

The last attribute, as returned by getNextAttributeId, is returned as an address space.

Returns
the address space associated with the current attribute.

Implemented in XmlDecode, and PackedDecode.

Referenced by OverlaySpace::decode(), SpacebaseSpace::decode(), SegmentOp::decode(), Override::decode(), PcodeOpRaw::decode(), TypePointer::decode(), TypePointerRel::decode(), TypeSpacebase::decode(), Architecture::decodeDeadcodeDelay(), Range::decodeFromAttributes(), VarnodeData::decodeFromAttributes(), Architecture::decodeSpacebase(), Architecture::decodeStackPointer(), and ScopeLocal::decodeWrappingAttributes().

◆ readString() [1/2]

virtual string Decoder::readString ( const AttributeId attribId)
pure virtual

Find the specific attribute in the current element and return it as a string.

The set of attributes for the current element is searched for a match to the given attribute id. This attribute is then returned as a string. If there is no attribute matching the id, and exception is thrown. Parse via getNextAttributeId is reset.

Parameters
attribIdis the specific attribute id to match
Returns
the string associated with the attribute

Implemented in XmlDecode, and PackedDecode.

◆ readString() [2/2]

virtual string Decoder::readString ( void  )
pure virtual

Parse the current attribute as a string.

The last attribute, as returned by getNextAttributeId, is returned as a string.

Returns
the string associated with the current attribute.

Implemented in XmlDecode, and PackedDecode.

Referenced by RangeProperties::decode(), Comment::decode(), FunctionSymbol::decode(), ExternRefSymbol::decode(), Database::decode(), ProtoModel::decode(), ProtoModelMerged::decode(), Funcdata::decode(), InjectCallfixupGhidra::decode(), InjectCallotherGhidra::decode(), CompilerTag::decode(), LanguageDescription::decode(), OverlaySpace::decode(), StringManager::decode(), LanedRegister::decode(), TruncationTag::decode(), SegmentOp::decode(), JumpAssistOp::decode(), FuncProto::decode(), Override::decode(), ParamEntry::decode(), ProtoStoreInternal::decode(), CPoolRecord::decode(), TypeEnum::decode(), JoinSpace::decodeAttributes(), Datatype::decodeBasic(), AddrSpace::decodeBasicAttributes(), BlockGraph::decodeBody(), ScopeInternal::decodeCollision(), ContextInternal::decodeContext(), Architecture::decodeDynamicRule(), Architecture::decodeFlowOverride(), Range::decodeFromAttributes(), VarnodeData::decodeFromAttributes(), Symbol::decodeHeader(), OptionDatabase::decodeOne(), InjectPayload::decodeParameter(), InjectPayload::decodePayloadAttributes(), Architecture::decodePreferSplit(), Architecture::decodeProtoEval(), Architecture::decodeSpacebase(), AddrSpaceManager::decodeSpaces(), Architecture::decodeStackPointer(), TypeFactory::decodeType(), TypeFactory::decodeTypedef(), TypeFactory::decodeTypeNoRef(), UserOpManage::decodeVolatile(), and TypeField::TypeField().

◆ readUnsignedInteger() [1/2]

virtual uintb Decoder::readUnsignedInteger ( const AttributeId attribId)
pure virtual

Find and parse a specific attribute in the current element as an unsigned integer.

The set of attributes for the current element is searched for a match to the given attribute id. This attribute is then parsed as an unsigned integer and its value returned. If there is no attribute matching the id, an exception is thrown. Parsing via getNextAttributeId is reset.

Parameters
attribIdis the specific attribute id to match
Returns
the unsigned integer value

Implemented in XmlDecode, and PackedDecode.

◆ readUnsignedInteger() [2/2]

virtual uintb Decoder::readUnsignedInteger ( void  )
pure virtual

◆ rewindAttributes()

virtual void Decoder::rewindAttributes ( void  )
pure virtual

Reset attribute traversal for the current element.

Attributes for a single element can be traversed more than once using the getNextAttributeId method.

Implemented in XmlDecode, and PackedDecode.

Referenced by ContextInternal::decode(), LanedRegister::decode(), TypePointer::decode(), TypeArray::decode(), TypePointerRel::decode(), VarnodeData::decodeFromAttributes(), ScopeInternal::decodeHole(), ScopeGhidra::decodeHole(), and TypeFactory::decodeTypeNoRef().

◆ skipElement()

void Decoder::skipElement ( void  )
inline

Skip parsing of the next element.

The element skipped is the one that would be opened by the next call to openElement.

References closeElementSkipping(), and openElement().

Referenced by ScopeInternal::decode(), ContextGhidra::decode(), and ContextGhidra::decodeFromSpec().


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