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

An XML based decoder. More...

#include <marshal.hh>

Inheritance diagram for ghidra::XmlDecode:
ghidra::Decoder

Public Member Functions

 XmlDecode (const AddrSpaceManager *spc, const Element *root)
 Constructor with preparsed root.
 
 XmlDecode (const AddrSpaceManager *spc)
 Constructor for use with ingestStream.
 
const ElementgetCurrentXmlElement (void) const
 Get pointer to underlying XML element object.
 
virtual void ingestStream (istream &s)
 Prepare to decode a given stream. More...
 
virtual uint4 peekElement (void)
 Peek at the next child element of the current parent, without traversing in (opening) it. More...
 
virtual uint4 openElement (void)
 Open (traverse into) the next child element of the current parent. More...
 
virtual uint4 openElement (const ElementId &elemId)
 Open (traverse into) the next child element, which must be of a specific type. More...
 
virtual void closeElement (uint4 id)
 Close the current element. More...
 
virtual void closeElementSkipping (uint4 id)
 Close the current element, skipping any child elements that have not yet been parsed. More...
 
virtual void rewindAttributes (void)
 Reset attribute traversal for the current element. More...
 
virtual uint4 getNextAttributeId (void)
 Get the next attribute id for the current element. More...
 
virtual uint4 getIndexedAttributeId (const AttributeId &attribId)
 Get the id for the (current) attribute, assuming it is indexed. More...
 
virtual bool readBool (void)
 Parse the current attribute as a boolean value. More...
 
virtual bool readBool (const AttributeId &attribId)
 Find and parse a specific attribute in the current element as a boolean value. More...
 
virtual intb readSignedInteger (void)
 Parse the current attribute as a signed integer value. More...
 
virtual intb readSignedInteger (const AttributeId &attribId)
 Find and parse a specific attribute in the current element as a signed integer. More...
 
virtual intb readSignedIntegerExpectString (const string &expect, intb expectval)
 Parse the current attribute as either a signed integer value or a string. More...
 
virtual intb readSignedIntegerExpectString (const AttributeId &attribId, const string &expect, intb expectval)
 Find and parse a specific attribute in the current element as either a signed integer or a string. More...
 
virtual uintb readUnsignedInteger (void)
 Parse the current attribute as an unsigned integer value. More...
 
virtual uintb readUnsignedInteger (const AttributeId &attribId)
 Find and parse a specific attribute in the current element as an unsigned integer. More...
 
virtual string readString (void)
 Parse the current attribute as a string. More...
 
virtual string readString (const AttributeId &attribId)
 Find the specific attribute in the current element and return it as a string. More...
 
virtual AddrSpacereadSpace (void)
 Parse the current attribute as an address space. More...
 
virtual AddrSpacereadSpace (const AttributeId &attribId)
 Find the specific attribute in the current element and return it as an address space. More...
 
- Public Member Functions inherited from ghidra::Decoder
 Decoder (const AddrSpaceManager *spc)
 Base constructor.
 
const AddrSpaceManagergetAddrSpaceManager (void) const
 Get the manager used for address space decoding.
 
virtual ~Decoder (void)
 Destructor.
 
void skipElement (void)
 Skip parsing of the next element. More...
 

Private Member Functions

int4 findMatchingAttribute (const Element *el, const string &attribName)
 Find the attribute index, within the given element, for the given name. More...
 

Private Attributes

Documentdocument
 An ingested XML document, owned by this decoder.
 
const ElementrootElement
 The root XML element to be decoded.
 
vector< const Element * > elStack
 Stack of currently open elements.
 
vector< List::const_iterator > iterStack
 Index of next child for each open element.
 
int4 attributeIndex
 Position of current attribute to parse (in current element)
 

Additional Inherited Members

- Protected Attributes inherited from ghidra::Decoder
const AddrSpaceManagerspcManager
 Manager for decoding address space attributes.
 

Detailed Description

An XML based decoder.

The underlying transfer encoding is an XML document. The decoder can either be initialized with an existing Element as the root of the data to transfer, or the ingestStream() method can be invoked to read the XML document from an input stream, in which case the decoder manages the Document object.

Member Function Documentation

◆ closeElement()

void ghidra::XmlDecode::closeElement ( uint4  id)
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)

Implements ghidra::Decoder.

References ghidra::ElementId::find(), ghidra::Element::getChildren(), and ghidra::Element::getName().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), ghidra::SleighArchitecture::buildSymbols(), ghidra::SleighArchitecture::loadLanguageDescription(), ghidra::LoadImageXml::open(), ghidra::Architecture::parseCompilerConfig(), ghidra::Architecture::parseExtraRules(), ghidra::Architecture::parseProcessorConfig(), and ghidra::Architecture::restoreXml().

◆ closeElementSkipping()

void ghidra::XmlDecode::closeElementSkipping ( uint4  id)
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)

Implements ghidra::Decoder.

References ghidra::ElementId::find(), and ghidra::Element::getName().

Referenced by ghidra::SleighArchitecture::loadLanguageDescription(), and ghidra::Architecture::parseProcessorConfig().

◆ findMatchingAttribute()

int4 ghidra::XmlDecode::findMatchingAttribute ( const Element el,
const string &  attribName 
)
private

Find the attribute index, within the given element, for the given name.

Run through the attributes of the element until we find the one matching the name, or throw an exception otherwise.

Parameters
elis the given element to search
attribNameis the attribute name to search for
Returns
the matching attribute index

References ghidra::Element::getAttributeName(), and ghidra::Element::getNumAttributes().

◆ getIndexedAttributeId()

uint4 ghidra::XmlDecode::getIndexedAttributeId ( const AttributeId attribId)
virtual

Get the id for the (current) attribute, assuming it is indexed.

Assuming the previous call to getNextAttributeId() returned the id of ATTRIB_UNKNOWN, reinterpret the attribute as being an indexed form of the given attribute. If the attribute matches, return this indexed id, otherwise return ATTRIB_UNKNOWN.

Parameters
attribIdis the attribute being indexed
Returns
the indexed id or ATTRIB_UNKNOWN

Implements ghidra::Decoder.

References ghidra::Element::getAttributeName(), ghidra::AttributeId::getId(), ghidra::AttributeId::getName(), and ghidra::Element::getNumAttributes().

◆ getNextAttributeId()

uint4 ghidra::XmlDecode::getNextAttributeId ( void  )
virtual

Get the next attribute id for the current element.

Attributes are automatically set up for traversal using this method, when the element is opened. If all attributes have been traversed (or there are no attributes), 0 is returned.

Returns
the id of the next attribute or 0

Implements ghidra::Decoder.

References ghidra::AttributeId::find(), and ghidra::Element::getAttributeName().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), ghidra::SleighArchitecture::buildSymbols(), ghidra::LoadImageXml::open(), and ghidra::Architecture::restoreXml().

◆ ingestStream()

void ghidra::XmlDecode::ingestStream ( istream &  s)
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

Implements ghidra::Decoder.

References ghidra::xml_tree().

Referenced by ghidra::SleighArchitecture::loadLanguageDescription().

◆ openElement() [1/2]

uint4 ghidra::XmlDecode::openElement ( void  )
virtual

◆ openElement() [2/2]

uint4 ghidra::XmlDecode::openElement ( const ElementId elemId)
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

Implements ghidra::Decoder.

References ghidra::Element::getChildren(), ghidra::ElementId::getId(), ghidra::ElementId::getName(), and ghidra::Element::getName().

◆ peekElement()

uint4 ghidra::XmlDecode::peekElement ( void  )
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

Implements ghidra::Decoder.

References ghidra::ElementId::find(), ghidra::Element::getChildren(), and ghidra::Element::getName().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), ghidra::SleighArchitecture::buildSymbols(), ghidra::SleighArchitecture::loadLanguageDescription(), ghidra::Architecture::parseCompilerConfig(), ghidra::Architecture::parseExtraRules(), ghidra::Architecture::parseProcessorConfig(), and ghidra::Architecture::restoreXml().

◆ readBool() [1/2]

bool ghidra::XmlDecode::readBool ( void  )
virtual

Parse the current attribute as a boolean value.

The last attribute, as returned by getNextAttributeId, is treated as a boolean, and its value is returned.

Returns
the boolean value associated with the current attribute.

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), and ghidra::xml_readbool().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), ghidra::SleighArchitecture::buildSymbols(), ghidra::LoadImageXml::open(), and ghidra::Architecture::restoreXml().

◆ readBool() [2/2]

bool ghidra::XmlDecode::readBool ( const AttributeId attribId)
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

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), ghidra::Element::getContent(), ghidra::AttributeId::getName(), and ghidra::xml_readbool().

◆ readSignedInteger() [1/2]

intb ghidra::XmlDecode::readSignedInteger ( void  )
virtual

Parse the current attribute as a signed integer value.

The last attribute, as returned by getNextAttributeId, is treated as a signed integer, and its value is returned.

Returns
the signed integer value associated with the current attribute.

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), and ghidra::SleighArchitecture::buildSymbols().

◆ readSignedInteger() [2/2]

intb ghidra::XmlDecode::readSignedInteger ( const AttributeId attribId)
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

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), ghidra::Element::getContent(), and ghidra::AttributeId::getName().

◆ readSignedIntegerExpectString() [1/2]

intb ghidra::XmlDecode::readSignedIntegerExpectString ( const string &  expect,
intb  expectval 
)
virtual

Parse the current attribute as either a signed integer value or a string.

If the attribute is an integer, its value is returned. If the attribute is a string, it must match an expected string passed to the method, and a predetermined integer value associated with the string is returned. If the attribute neither matches the expected string nor is an integer, the return value is undefined.

Parameters
expectis the string value to expect if the attribute is encoded as a string
expectvalis the integer value to return if the attribute matches the expected string
Returns
the encoded integer or the integer value associated with the expected string

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue().

◆ readSignedIntegerExpectString() [2/2]

intb ghidra::XmlDecode::readSignedIntegerExpectString ( const AttributeId attribId,
const string &  expect,
intb  expectval 
)
virtual

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

If the attribute is an integer, its value is parsed and returned. If the attribute is encoded as a string, it must match an expected string passed to this method. In this case, a predetermined integer value is passed back, indicating a matching string was parsed. If the attribute neither matches the expected string nor is an integer, the return value is undefined. If there is no attribute matching the id, an exception is thrown.

Parameters
attribIdis the specific attribute id to match
expectis the string to expect, if the attribute is not encoded as an integer
expectvalis the integer value to return if the attribute matches the expected string
Returns
the encoded integer or the integer value associated with the expected string

Implements ghidra::Decoder.

◆ readSpace() [1/2]

AddrSpace * ghidra::XmlDecode::readSpace ( void  )
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.

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue().

Referenced by ghidra::LoadImageXml::open(), and ghidra::Architecture::parseProcessorConfig().

◆ readSpace() [2/2]

AddrSpace * ghidra::XmlDecode::readSpace ( const AttributeId attribId)
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

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), ghidra::Element::getContent(), and ghidra::AttributeId::getName().

◆ readString() [1/2]

string ghidra::XmlDecode::readString ( void  )
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.

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue().

Referenced by ghidra::ArchitectureGhidra::buildSymbols(), ghidra::SleighArchitecture::buildSymbols(), ghidra::LoadImageXml::open(), and ghidra::Architecture::parseCompilerConfig().

◆ readString() [2/2]

string ghidra::XmlDecode::readString ( const AttributeId attribId)
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

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), ghidra::Element::getContent(), and ghidra::AttributeId::getName().

◆ readUnsignedInteger() [1/2]

uintb ghidra::XmlDecode::readUnsignedInteger ( void  )
virtual

Parse the current attribute as an unsigned integer value.

The last attribute, as returned by getNextAttributeId, is treated as an unsigned integer, and its value is returned.

Returns
the unsigned integer value associated with the current attribute.

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue().

◆ readUnsignedInteger() [2/2]

uintb ghidra::XmlDecode::readUnsignedInteger ( const AttributeId attribId)
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

Implements ghidra::Decoder.

References ghidra::Element::getAttributeValue(), ghidra::Element::getContent(), and ghidra::AttributeId::getName().

◆ rewindAttributes()

void ghidra::XmlDecode::rewindAttributes ( void  )
virtual

Reset attribute traversal for the current element.

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

Implements ghidra::Decoder.

Referenced by ghidra::LoadImageXml::open().


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