mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-2157 Marshaling refactor. Decompiler side.
This commit is contained in:
parent
672c1f11e2
commit
d8c10bf229
97 changed files with 5313 additions and 3733 deletions
|
@ -34,6 +34,28 @@ class Database;
|
|||
class Symbol;
|
||||
class PrintLanguage;
|
||||
|
||||
extern AttributeId ATTRIB_CAT; ///< Marshaling attribute "cat"
|
||||
extern AttributeId ATTRIB_FIELD; ///< Marshaling attribute "field"
|
||||
extern AttributeId ATTRIB_MERGE; ///< Marshaling attribute "merge"
|
||||
extern AttributeId ATTRIB_SCOPEIDBYNAME; ///< Marshaling attribute "scopeidbyname"
|
||||
extern AttributeId ATTRIB_VOLATILE; ///< Marshaling attribute "volatile"
|
||||
|
||||
extern ElementId ELEM_COLLISION; ///< Marshaling element \<collision>
|
||||
extern ElementId ELEM_DB; ///< Marshaling element \<db>
|
||||
extern ElementId ELEM_EQUATESYMBOL; ///< Marshaling element \<equatesymbol>
|
||||
extern ElementId ELEM_EXTERNREFSYMBOL; ///< Marshaling element \<externrefsymbol>
|
||||
extern ElementId ELEM_FACETSYMBOL; ///< Marshaling element \<facetsymbol>
|
||||
extern ElementId ELEM_FUNCTIONSHELL; ///< Marshaling element \<functionshell>
|
||||
extern ElementId ELEM_HASH; ///< Marshaling element \<hash>
|
||||
extern ElementId ELEM_HOLE; ///< Marshaling element \<hole>
|
||||
extern ElementId ELEM_LABELSYM; ///< Marshaling element \<labelsym>
|
||||
extern ElementId ELEM_MAPSYM; ///< Marshaling element \<mapsym>
|
||||
extern ElementId ELEM_PARENT; ///< Marshaling element \<parent>
|
||||
extern ElementId ELEM_PROPERTY_CHANGEPOINT; ///< Marshaling element \<property_changepoint>
|
||||
extern ElementId ELEM_RANGEEQUALSSYMBOLS; ///< Marshaling element \<rangeequalssymbols>
|
||||
extern ElementId ELEM_SCOPE; ///< Marshaling element \<scope>
|
||||
extern ElementId ELEM_SYMBOLLIST; ///< Marshaling element \<symbollist>
|
||||
|
||||
/// \brief A storage location for a particular Symbol
|
||||
///
|
||||
/// Where a Symbol is stored, as a byte address and a size, is of particular importance
|
||||
|
@ -134,8 +156,8 @@ public:
|
|||
bool updateType(Varnode *vn) const; ///< Update a Varnode data-type from \b this
|
||||
Datatype *getSizedType(const Address &addr,int4 sz) const; ///< Get the data-type associated with (a piece of) \b this
|
||||
void printEntry(ostream &s) const; ///< Dump a description of \b this to a stream
|
||||
void saveXml(ostream &s) const; ///< Save \b this to an XML stream
|
||||
List::const_iterator restoreXml(List::const_iterator iter,const AddrSpaceManager *manage); ///< Restore \b this from an XML stream
|
||||
void encode(Encoder &encoder) const; ///< Encode \b this to a stream
|
||||
void decode(Decoder &decoder,const AddrSpaceManager *manage); ///< Decode \b this from a stream
|
||||
};
|
||||
typedef rangemap<SymbolEntry> EntryMap; ///< A rangemap of SymbolEntry
|
||||
|
||||
|
@ -192,7 +214,7 @@ public:
|
|||
};
|
||||
|
||||
Symbol(Scope *sc,const string &nm,Datatype *ct); ///< Construct given a name and data-type
|
||||
Symbol(Scope *sc); ///< Construct for use with restoreXml()
|
||||
Symbol(Scope *sc); ///< Construct for use with decode()
|
||||
const string &getName(void) const { return name; } ///< Get the local name of the symbol
|
||||
Datatype *getType(void) const { return type; } ///< Get the data-type
|
||||
uint8 getId(void) const { return symbolId; } ///< Get a unique id for the symbol
|
||||
|
@ -219,12 +241,12 @@ public:
|
|||
SymbolEntry *getMapEntry(int4 i) const { return &(*mapentry[i]); } ///< Return the i-th SymbolEntry for \b this Symbol
|
||||
int4 getMapEntryPosition(const SymbolEntry *entry) const; ///< Position of given SymbolEntry within \b this multi-entry Symbol
|
||||
int4 getResolutionDepth(const Scope *useScope) const; ///< Get number of scope names needed to resolve \b this symbol
|
||||
void saveXmlHeader(ostream &s) const; ///< Save basic Symbol properties as XML attributes
|
||||
void restoreXmlHeader(const Element *el); ///< Restore basic Symbol properties from XML
|
||||
void saveXmlBody(ostream &s) const; ///< Save details of the Symbol to XML
|
||||
void restoreXmlBody(List::const_iterator iter); ///< Restore details of the Symbol from XML
|
||||
virtual void saveXml(ostream &s) const; ///< Save \b this Symbol to an XML stream
|
||||
virtual void restoreXml(const Element *el); ///< Restore \b this Symbol from an XML stream
|
||||
void encodeHeader(Encoder &encoder) const; ///< Encode basic Symbol properties as attributes
|
||||
void decodeHeader(Decoder &decoder); ///< Decode basic Symbol properties from a \<symbol> element
|
||||
void encodeBody(Encoder &encoder) const; ///< Encode details of the Symbol to a stream
|
||||
void decodeBody(Decoder &decoder); ///< Decode details of the Symbol from a \<symbol> element
|
||||
virtual void encode(Encoder &encoder) const; ///< Encode \b this Symbol to a stream
|
||||
virtual void decode(Decoder &decoder); ///< Decode \b this Symbol from a stream
|
||||
virtual int4 getBytesConsumed(void) const; ///< Get number of bytes consumed within the address->symbol map
|
||||
static uint8 ID_BASE; ///< Base of internal ID's
|
||||
};
|
||||
|
@ -259,10 +281,10 @@ class FunctionSymbol : public Symbol {
|
|||
void buildType(void); ///< Build the data-type associated with \b this Symbol
|
||||
public:
|
||||
FunctionSymbol(Scope *sc,const string &nm,int4 size); ///< Construct given the name
|
||||
FunctionSymbol(Scope *sc,int4 size); ///< Constructor for use with restoreXml
|
||||
FunctionSymbol(Scope *sc,int4 size); ///< Constructor for use with decode
|
||||
Funcdata *getFunction(void); ///< Get the underlying Funcdata object
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
virtual int4 getBytesConsumed(void) const { return consumeSize; }
|
||||
};
|
||||
|
||||
|
@ -275,21 +297,21 @@ class EquateSymbol : public Symbol {
|
|||
uintb value; ///< Value of the constant being equated
|
||||
public:
|
||||
EquateSymbol(Scope *sc,const string &nm,uint4 format,uintb val); ///< Constructor
|
||||
EquateSymbol(Scope *sc) : Symbol(sc) { value = 0; category = equate; } ///< Constructor for use with restoreXml
|
||||
EquateSymbol(Scope *sc) : Symbol(sc) { value = 0; category = equate; } ///< Constructor for use with decode
|
||||
uintb getValue(void) const { return value; } ///< Get the constant value
|
||||
bool isValueClose(uintb op2Value,int4 size) const; ///< Is the given value similar to \b this equate
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
};
|
||||
|
||||
class UnionFacetSymbol : public Symbol {
|
||||
int4 fieldNum; ///< Particular field to associate with Symbol access
|
||||
public:
|
||||
UnionFacetSymbol(Scope *sc,const string &nm,Datatype *unionDt,int4 fldNum); ///< Constructor from components
|
||||
UnionFacetSymbol(Scope *sc) : Symbol(sc) { fieldNum = -1; category = union_facet; } ///< Constructor for restoreXml
|
||||
UnionFacetSymbol(Scope *sc) : Symbol(sc) { fieldNum = -1; category = union_facet; } ///< Constructor for decode
|
||||
int4 getFieldNumber(void) const { return fieldNum; } ///< Get the particular field associate with \b this
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
};
|
||||
|
||||
/// \brief A Symbol that labels code internal to a function
|
||||
|
@ -297,9 +319,9 @@ class LabSymbol : public Symbol {
|
|||
void buildType(void); ///< Build placeholder data-type
|
||||
public:
|
||||
LabSymbol(Scope *sc,const string &nm); ///< Construct given name
|
||||
LabSymbol(Scope *sc); ///< Constructor for use with restoreXml
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
LabSymbol(Scope *sc); ///< Constructor for use with decode
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
};
|
||||
|
||||
/// \brief A function Symbol referring to an external location
|
||||
|
@ -314,10 +336,10 @@ class ExternRefSymbol : public Symbol {
|
|||
virtual ~ExternRefSymbol(void) {}
|
||||
public:
|
||||
ExternRefSymbol(Scope *sc,const Address &ref,const string &nm); ///< Construct given a \e placeholder address
|
||||
ExternRefSymbol(Scope *sc) : Symbol(sc) {} ///< For use with restoreXml
|
||||
ExternRefSymbol(Scope *sc) : Symbol(sc) {} ///< For use with decode
|
||||
const Address &getRefAddr(void) const { return refaddr; } ///< Return the \e placeholder address
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
};
|
||||
|
||||
/// \brief Comparator for sorting Symbol objects by name
|
||||
|
@ -391,6 +413,17 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// \brief Exception thrown when a function is added more than once to the database
|
||||
///
|
||||
/// Stores off the address of the function, so a handler can recover from the exception
|
||||
/// and pick up the original symbol.
|
||||
struct DuplicateFunctionError : public RecovError {
|
||||
Address address; ///< Address of function causing the error
|
||||
string functionName; ///< Name of the function
|
||||
DuplicateFunctionError(const Address &addr,const string &nm) : RecovError("Duplicate Function") {
|
||||
address = addr; functionName = nm; } ///< Constructor
|
||||
};
|
||||
|
||||
typedef map<uint8,Scope *> ScopeMap; ///< A map from id to Scope
|
||||
|
||||
/// \brief A collection of Symbol objects within a single (namespace or functional) scope
|
||||
|
@ -661,8 +694,9 @@ public:
|
|||
/// \return return a unique version of the name
|
||||
virtual string makeNameUnique(const string &nm) const=0;
|
||||
|
||||
virtual void saveXml(ostream &s) const=0; ///< Write out \b this as a \<scope> XML tag
|
||||
virtual void restoreXml(const Element *el)=0; ///< Restore \b this Scope from a \<scope> XML tag
|
||||
virtual void encode(Encoder &encoder) const=0; ///< Encode \b this as a \<scope> element
|
||||
virtual void decode(Decoder &decoder)=0; ///< Decode \b this Scope from a \<scope> element
|
||||
virtual void decodeWrappingAttributes(Decoder &decoder) {} ///< Restore attributes for \b this Scope from wrapping element
|
||||
virtual void printEntries(ostream &s) const=0; ///< Dump a description of all SymbolEntry objects to a stream
|
||||
|
||||
/// \brief Get the number of Symbols in the given category
|
||||
|
@ -709,8 +743,8 @@ public:
|
|||
Scope *discoverScope(const Address &addr,int4 sz,const Address &usepoint); ///< Find the owning Scope of a given memory range
|
||||
ScopeMap::const_iterator childrenBegin() const { return children.begin(); } ///< Beginning iterator of child scopes
|
||||
ScopeMap::const_iterator childrenEnd() const { return children.end(); } ///< Ending iterator of child scopes
|
||||
void saveXmlRecursive(ostream &s,bool onlyGlobal) const; ///< Save all contained scopes as an XML stream
|
||||
void overrideSizeLockType(Symbol *sym,Datatype *ct); ///< Change the data-type of a Symbol that is \e sizelocked
|
||||
void encodeRecursive(Encoder &encoder,bool onlyGlobal) const; ///< Encode all contained scopes to a stream
|
||||
void overrideSizeLockType(Symbol *sym,Datatype *ct); ///< Change the data-type of a Symbol that is \e sizelocked
|
||||
void resetSizeLockType(Symbol *sym); ///< Clear a Symbol's \e size-locked data-type
|
||||
void setThisPointer(Symbol *sym,bool val) { sym->setThisPointer(val); } ///< Toggle the given Symbol as the "this" pointer
|
||||
bool isSubScope(const Scope *scp) const; ///< Is this a sub-scope of the given Scope
|
||||
|
@ -722,7 +756,7 @@ public:
|
|||
Symbol *addSymbol(const string &nm,Datatype *ct); ///< Add a new Symbol \e without mapping it to an address
|
||||
SymbolEntry *addMapPoint(Symbol *sym,const Address &addr,
|
||||
const Address &usepoint); ///< Map a Symbol to a specific address
|
||||
Symbol *addMapSym(const Element *el); ///< Add a mapped Symbol from a \<mapsym> XML tag
|
||||
Symbol *addMapSym(Decoder &decoder); ///< Parse a mapped Symbol from a \<mapsym> element
|
||||
FunctionSymbol *addFunction(const Address &addr,const string &nm);
|
||||
ExternRefSymbol *addExternalRef(const Address &addr,const Address &refaddr,const string &nm);
|
||||
LabSymbol *addCodeLabel(const Address &addr,const string &nm);
|
||||
|
@ -740,8 +774,8 @@ public:
|
|||
/// a set of Symbol objects (the set owns the Symbol objects). It also implements
|
||||
/// a \b maptable, which is a list of rangemaps that own the SymbolEntry objects.
|
||||
class ScopeInternal : public Scope {
|
||||
void processHole(const Element *el);
|
||||
void processCollision(const Element *el);
|
||||
void decodeHole(Decoder &decoder);
|
||||
void decodeCollision(Decoder &decoder);
|
||||
void insertNameTree(Symbol *sym);
|
||||
SymbolNameTree::const_iterator findFirstByName(const string &nm) const;
|
||||
protected:
|
||||
|
@ -799,8 +833,8 @@ public:
|
|||
Datatype *ct,int4 &index,uint4 flags) const;
|
||||
virtual string buildUndefinedName(void) const;
|
||||
virtual string makeNameUnique(const string &nm) const;
|
||||
virtual void saveXml(ostream &s) const;
|
||||
virtual void restoreXml(const Element *el);
|
||||
virtual void encode(Encoder &encoder) const;
|
||||
virtual void decode(Decoder &decoder);
|
||||
virtual void printEntries(ostream &s) const;
|
||||
virtual int4 getCategorySize(int4 cat) const;
|
||||
virtual Symbol *getCategorySymbol(int4 cat,int4 ind) const;
|
||||
|
@ -867,7 +901,7 @@ class Database {
|
|||
void clearResolve(Scope *scope); ///< Clear the \e ownership ranges associated with the given Scope
|
||||
void clearReferences(Scope *scope); ///< Clear any map references to the given Scope and its children
|
||||
void fillResolve(Scope *scope); ///< Add the \e ownership ranges of the given Scope to the map
|
||||
Scope *parseParentTag(const Element *el); ///< Figure out parent scope given \<parent> tag.
|
||||
Scope *parseParentTag(Decoder &decoder); ///< Figure out parent scope given \<parent> tag.
|
||||
public:
|
||||
Database(Architecture *g,bool idByName); ///< Constructor
|
||||
~Database(void); ///< Destructor
|
||||
|
@ -891,9 +925,9 @@ public:
|
|||
void setPropertyRange(uint4 flags,const Range &range); ///< Set boolean properties over a given memory range
|
||||
void setProperties(const partmap<Address,uint4> &newflags) { flagbase = newflags; } ///< Replace the property map
|
||||
const partmap<Address,uint4> &getProperties(void) const { return flagbase; } ///< Get the entire property map
|
||||
void saveXml(ostream &s) const; ///< Save the whole Database to an XML stream
|
||||
void restoreXml(const Element *el); ///< Recover the whole database from XML
|
||||
void restoreXmlScope(const Element *el,Scope *newScope); ///< Register and fill out a single Scope from an XML \<scope> tag
|
||||
void encode(Encoder &encoder) const; ///< Encode the whole Database to a stream
|
||||
void decode(Decoder &decoder); ///< Decode the whole database from a stream
|
||||
void decodeScope(Decoder &decoder,Scope *newScope); ///< Register and fill out a single Scope from an XML \<scope> tag
|
||||
};
|
||||
|
||||
/// \param sc is the scope containing the new symbol
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue