decompiler
1.0.0
|
An Architecture that uses the decompiler's native SLEIGH translation engine. More...
#include <sleigh_arch.hh>
Public Member Functions | |
SleighArchitecture (const string &fname, const string &targ, ostream *estream) | |
Construct given executable file. More... | |
const string & | getFilename (void) const |
Get the executable filename. | |
const string & | getTarget (void) const |
Get the language id of the active processor. | |
void | saveXmlHeader (ostream &s) const |
Write out (as XML) basic attributes of the active executable. More... | |
void | restoreXmlHeader (const Element *el) |
Restore from XML basic attributes of an executable. More... | |
virtual void | printMessage (const string &message) const |
Print an error message to console. More... | |
Public Member Functions inherited from Architecture | |
Architecture (void) | |
Construct an uninitialized Architecture. More... | |
void | init (DocumentStorage &store) |
Load the image and configure architecture. More... | |
ProtoModel * | getModel (const string &nm) const |
Get a specific PrototypeModel. More... | |
bool | hasModel (const string &nm) const |
Does this Architecture have a specific PrototypeModel. More... | |
bool | highPtrPossible (const Address &loc, int4 size) const |
Are pointers possible to the given location? More... | |
AddrSpace * | getSpaceBySpacebase (const Address &loc, int4 size) const |
Get space associated with a spacebase register. More... | |
void | setDefaultModel (const string &nm) |
Set the default PrototypeModel. More... | |
void | clearAnalysis (Funcdata *fd) |
Clear analysis specific to a function. More... | |
void | readLoaderSymbols (void) |
Read any symbols from loader into database. More... | |
void | collectBehaviors (vector< OpBehavior * > &behave) const |
Provide a list of OpBehavior objects. More... | |
bool | hasNearPointers (AddrSpace *spc) const |
Does the given address space support near pointers. More... | |
void | setPrototype (const PrototypePieces &pieces) |
Set the prototype for a particular function. More... | |
void | setPrintLanguage (const string &nm) |
Establish a particular output language. More... | |
void | globalify (void) |
Mark all spaces as global. More... | |
void | restoreFlowOverride (const Element *el) |
Set flow overrides from XML. More... | |
virtual | ~Architecture (void) |
Destructor. More... | |
virtual void | saveXml (ostream &s) const |
Serialize this architecture to XML. More... | |
virtual void | restoreXml (DocumentStorage &store) |
Restore the Architecture state from an XML stream. More... | |
virtual void | nameFunction (const Address &addr, string &name) const |
Pick a default name for a function. More... | |
Public Member Functions inherited from AddrSpaceManager | |
AddrSpaceManager (void) | |
Construct an empty address space manager. More... | |
virtual | ~AddrSpaceManager (void) |
Destroy the manager. More... | |
char | assignShortcut (spacetype tp) const |
Select a shortcut character for a new space. More... | |
int4 | getDefaultSize (void) const |
Get size of addresses for the default space. More... | |
AddrSpace * | getSpaceByName (const string &nm) const |
Get address space by name. More... | |
AddrSpace * | getSpaceByShortcut (char sc) const |
Get address space from its shortcut. More... | |
AddrSpace * | getIopSpace (void) const |
Get the internal pcode op space. More... | |
AddrSpace * | getFspecSpace (void) const |
Get the internal callspec space. More... | |
AddrSpace * | getJoinSpace (void) const |
Get the joining space. More... | |
AddrSpace * | getStackSpace (void) const |
Get the stack space for this processor. More... | |
AddrSpace * | getUniqueSpace (void) const |
Get the temporary register space for this processor. More... | |
AddrSpace * | getDefaultSpace (void) const |
Get the default address space of this processor. More... | |
AddrSpace * | getConstantSpace (void) const |
Get the constant space. More... | |
Address | getConstant (uintb val) const |
Get a constant encoded as an Address. More... | |
Address | createConstFromSpace (AddrSpace *spc) const |
Create a constant address encoding an address space. More... | |
Address | resolveConstant (AddrSpace *spc, uintb val, int4 sz, const Address &point) const |
Resolve native constant to address. | |
int4 | numSpaces (void) const |
Get the number of address spaces for this processor. More... | |
AddrSpace * | getSpace (int4 i) const |
Get an address space via its index. More... | |
AddrSpace * | getNextSpaceInOrder (AddrSpace *spc) const |
Get the next contiguous address space. More... | |
JoinRecord * | findAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize) |
Get (or create) JoinRecord for pieces. More... | |
JoinRecord * | findJoin (uintb offset) const |
Find JoinRecord for offset in the join space. More... | |
void | setDeadcodeDelay (int4 spcnum, int4 delaydelta) |
Set the deadcodedelay for a specific space. More... | |
void | truncateSpace (const TruncationTag &tag) |
Mark a space as truncated from its original size. More... | |
Address | constructFloatExtensionAddress (const Address &realaddr, int4 realsize, int4 logicalsize) |
Build a logically lower precision storage location for a bigger floating point register. More... | |
Address | constructJoinAddress (const Translate *translate, const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz) |
Build a logical whole from register pairs. More... | |
Static Public Member Functions | |
static string | normalizeProcessor (const string &nm) |
Try to recover a language id processor field. More... | |
static string | normalizeEndian (const string &nm) |
Try to recover a language id endianess field. More... | |
static string | normalizeSize (const string &nm) |
Try to recover a language id size field. More... | |
static string | normalizeArchitecture (const string &nm) |
Try to recover a language id string. More... | |
static void | scanForSleighDirectories (const string &rootpath) |
Scan directories for SLEIGH specification files. More... | |
static void | shutdown (void) |
Shutdown this SleighArchitecture and free all resources. | |
Static Public Attributes | |
static FileManage | specpaths |
Known directories that contain .ldefs files. | |
Protected Member Functions | |
virtual Translate * | buildTranslator (DocumentStorage &store) |
Build the Translator object. More... | |
virtual PcodeInjectLibrary * | buildPcodeInjectLibrary (void) |
Build the injection library. More... | |
virtual void | buildSpecFile (DocumentStorage &store) |
Load any relevant specification files. More... | |
virtual void | modifySpaces (Translate *trans) |
Modify address spaces as required by this Architecture. More... | |
virtual void | resolveArchitecture (void) |
Figure out the processor and compiler of the target executable. | |
Protected Member Functions inherited from Architecture | |
void | addSpacebase (AddrSpace *basespace, const string &nm, const VarnodeData &ptrdata, int4 truncSize, bool isreversejustified, bool stackGrowth) |
Create a new space and associated pointer. More... | |
void | addNoHighPtr (const Range &rng) |
Add a new region where pointers do not exist. More... | |
virtual Scope * | buildGlobalScope (void) |
Build the global scope for this executable. More... | |
virtual void | buildLoader (DocumentStorage &store)=0 |
Build the LoadImage object and load the executable image. More... | |
virtual void | buildTypegrp (DocumentStorage &store) |
Build the data-type factory/container. More... | |
virtual void | buildCommentDB (DocumentStorage &store) |
Build the comment database. More... | |
virtual void | buildConstantPool (DocumentStorage &store) |
Build the constant pool. More... | |
virtual void | buildInstructions (DocumentStorage &store) |
Register the p-code operations. More... | |
virtual void | buildAction (DocumentStorage &store) |
Build the Action framework. More... | |
virtual void | buildContext (DocumentStorage &store) |
Build the Context database. More... | |
virtual void | postSpecFile (void) |
Let components initialize after Translate is built. | |
void | restoreFromSpec (DocumentStorage &store) |
Fully initialize the Translate object. More... | |
void | fillinReadOnlyFromLoader (void) |
Load info about read-only sections. More... | |
void | initializeSegments () |
Set up segment resolvers. More... | |
void | parseProcessorConfig (DocumentStorage &store) |
Apply processor specific configuration. More... | |
void | parseCompilerConfig (DocumentStorage &store) |
Apply compiler specific configuration. More... | |
void | parseExtraRules (DocumentStorage &store) |
Apply any Rule tags. More... | |
void | parseDynamicRule (const Element *el) |
Apply details of a dynamic Rule object. More... | |
ProtoModel * | parseProto (const Element *el) |
Build a proto-type model from an XML tag. More... | |
void | parseProtoEval (const Element *el) |
Apply prototype evaluation configuration. More... | |
void | parseDefaultProto (const Element *el) |
Apply default prototype model configuration. More... | |
void | parseGlobal (const Element *el) |
Apply global space configuration. More... | |
void | parseReadOnly (const Element *el) |
Apply read-only region configuration. More... | |
void | parseVolatile (const Element *el) |
Apply volatile region configuration. More... | |
void | parseReturnAddress (const Element *el) |
Apply return address configuration. More... | |
void | parseIncidentalCopy (const Element *el) |
Apply incidental copy configuration. More... | |
void | parseStackPointer (const Element *el) |
Apply stack pointer configuration. More... | |
void | parseDeadcodeDelay (const Element *el) |
Apply dead-code delay configuration. More... | |
void | parseFuncPtrAlign (const Element *el) |
Apply function pointer alignment configuration. More... | |
void | parseSpacebase (const Element *el) |
Create an additional indexed space. More... | |
void | parseNoHighPtr (const Element *el) |
Apply memory alias configuration. More... | |
void | parsePreferSplit (const Element *el) |
Designate registers to be split. More... | |
void | parseAggressiveTrim (const Element *el) |
Designate how to trim extension p-code ops. More... | |
Protected Member Functions inherited from AddrSpaceManager | |
AddrSpace * | restoreXmlSpace (const Element *el, const Translate *trans) |
Add a space to the model based an on XML tag. More... | |
void | restoreXmlSpaces (const Element *el, const Translate *trans) |
Restore address spaces in the model from an XML tag. More... | |
void | setDefaultSpace (int4 index) |
Set the default address space. More... | |
void | setReverseJustified (AddrSpace *spc) |
Set reverse justified property on this space. More... | |
void | insertSpace (AddrSpace *spc) |
Add a new address space to the model. More... | |
void | copySpaces (const AddrSpaceManager *op2) |
Copy spaces from another manager. More... | |
void | addSpacebasePointer (SpacebaseSpace *basespace, const VarnodeData &ptrdata, int4 truncSize, bool stackGrowth) |
Set the base register of a spacebase space. More... | |
void | insertResolver (AddrSpace *spc, AddressResolver *rsolv) |
Override the base resolver for a space. More... | |
Static Protected Member Functions | |
static void | collectSpecFiles (ostream &errs) |
Gather specification files in normal locations. More... | |
Protected Attributes | |
ostream * | errorstream |
Error stream associated with this SleighArchitecture. | |
Private Member Functions | |
bool | isTranslateReused (void) |
Test if last Translate object can be reused. More... | |
Static Private Member Functions | |
static void | loadLanguageDescription (const string &specfile, ostream &errs) |
Read a SLEIGH .ldefs file. More... | |
Private Attributes | |
int4 | languageindex |
Index (within LanguageDescription array) of the active language. | |
string | filename |
Name of active load-image file. | |
string | target |
The language id of the active load-image. | |
Static Private Attributes | |
static Sleigh * | last_sleigh = (Sleigh *)0 |
Last Translate object used by a SleighArchitecture. | |
static int4 | last_languageindex |
Index of the LanguageDescription associated with the last Translate object. | |
static vector< LanguageDescription > | description |
List of languages we know about. | |
Additional Inherited Members | |
Public Attributes inherited from Architecture | |
string | archid |
ID string uniquely describing this architecture. | |
string | description |
Description of architecture. | |
string | version |
Configuration version. | |
int4 | trim_recurse_max |
How many levels to let parameter trims recurse. | |
int4 | max_implied_ref |
Maximum number of references to an implied var. | |
int4 | max_term_duplication |
Max terms duplicated without a new variable. | |
int4 | max_basetype_size |
Maximum size of an "integer" type before creating an array type. | |
int4 | min_funcsymbol_size |
Minimum size of a function symbol. | |
bool | aggressive_ext_trim |
Aggressively trim inputs that look like they are sign extended. | |
bool | readonlypropagate |
true if readonly values should be treated as constants | |
bool | infer_pointers |
True if we should infer pointers from constants that are likely addresses. | |
uintb | pointer_lowerbound |
Zero or lowest value that can be inferred as an address. | |
int4 | funcptr_align |
How many bits of alignment a function ptr has. | |
uint4 | flowoptions |
options passed to flow following engine | |
vector< Rule * > | extra_pool_rules |
Extra rules that go in the main pool (cpu specific, experimental) | |
Database * | symboltab |
Memory map of global variables and functions. | |
ContextDatabase * | context |
Map from addresses to context settings. | |
map< string, ProtoModel * > | protoModels |
Parsed forms of possible prototypes. | |
ProtoModel * | defaultfp |
Parsed form of default prototype. | |
VarnodeData | defaultReturnAddr |
Default storage location of return address (for current function) | |
ProtoModel * | evalfp_current |
Function proto to use when evaluating current function. | |
ProtoModel * | evalfp_called |
Function proto to use when evaluating called functions. | |
TypeFactory * | types |
List of types for this binary. | |
const Translate * | translate |
Translation method for this binary. | |
LoadImage * | loader |
Method for loading portions of binary. | |
PcodeInjectLibrary * | pcodeinjectlib |
Pcode injection manager. | |
RangeList | nohighptr |
Ranges for which high-level pointers are not possible. | |
CommentDatabase * | commentdb |
Comments for this architecture. | |
ConstantPool * | cpool |
Deferred constant values. | |
PrintLanguage * | |
Current high-level language printer. | |
vector< PrintLanguage * > | printlist |
List of high-level language printers supported. | |
OptionDatabase * | options |
Options that can be configured. | |
vector< TypeOp * > | inst |
Registered p-code instructions. | |
UserOpManage | userops |
Specifically registered user-defined p-code ops. | |
vector< PreferSplitRecord > | splitrecords |
registers that we would prefer to see split for this processor | |
ActionDatabase | allacts |
Actions that can be applied in this architecture. | |
bool | loadersymbols_parsed |
True if loader symbols have been read. | |
An Architecture that uses the decompiler's native SLEIGH translation engine.
Any Architecture derived from this knows how to natively read in:
Generally a language id (i.e. x86:LE:64:default) is provided, then this object is able to automatically load in configuration and construct the Translate object.
SleighArchitecture::SleighArchitecture | ( | const string & | fname, |
const string & | targ, | ||
ostream * | estream | ||
) |
Construct given executable file.
Prepare this SleighArchitecture for analyzing the given executable image. Full initialization, including creation of the Translate object, still must be performed by calling the init() method.
fname | is the filename of the given executable image |
targ | is the optional language id or other target information |
estream | is a pointer to an output stream for writing error messages |
References errorstream, filename, and target.
|
protectedvirtual |
Build the injection library.
This creates the container for p-code injections. It is initially empty.
Implements Architecture.
References Translate::getUniqueBase(), and Architecture::translate.
|
protectedvirtual |
Load any relevant specification files.
Processor/architecture specific configuration files are loaded into the XML store
store | is the document store that will hold the configuration |
Implements Architecture.
References Architecture::archid, description, Architecture::description, LowlevelError::explain, LanguageDescription::getCompiler(), LanguageDescription::getDescription(), LanguageDescription::getProcessorSpec(), LanguageDescription::getSlaFile(), LanguageDescription::getVersion(), isTranslateReused(), languageindex, specpaths, and Architecture::version.
|
protectedvirtual |
Build the Translator object.
This builds the main disassembly component for the Architecture This does not initially the engine for a specific processor.
store | may hold configuration information |
Implements Architecture.
References Architecture::context, isTranslateReused(), languageindex, last_languageindex, last_sleigh, and Architecture::loader.
|
staticprotected |
Gather specification files in normal locations.
This is run once when spinning up the decompiler. Look for the root .ldefs files within the normal directories and parse them. Use these to populate the list of language ids that are supported.
errs | is an output stream for writing error messages |
References description, loadLanguageDescription(), and specpaths.
Referenced by XmlArchitecture::buildLoader(), RawBinaryArchitecture::buildLoader(), and BfdArchitecture::buildLoader().
|
private |
Test if last Translate object can be reused.
If the current languageindex matches the last_languageindex, try to reuse the previous Sleigh object, so we don't reload the .sla file.
References languageindex, last_languageindex, and last_sleigh.
Referenced by buildSpecFile(), and buildTranslator().
|
staticprivate |
Read a SLEIGH .ldefs file.
Any <language> tags are added to the LanguageDescription array
specfile | is the filename of the .ldefs file |
errs | is an output stream for printing error messages |
References description.
Referenced by collectSpecFiles().
|
protectedvirtual |
Modify address spaces as required by this Architecture.
If spaces need to be truncated or otherwise changed from processor defaults, this routine performs the modification.
trans | is the processor disassembly object |
Implements Architecture.
References description, LanguageDescription::getTruncation(), languageindex, LanguageDescription::numTruncations(), and AddrSpaceManager::truncateSpace().
|
static |
Try to recover a language id string.
Try to normalize the target string into a valid language id. In general the target string must already look like a language id, but it can drop the compiler field and be a little sloppier in its format.
nm | is the given target string |
References normalizeEndian(), normalizeProcessor(), and normalizeSize().
Referenced by resolveArchitecture().
|
static |
Try to recover a language id endianess field.
Given an architecture target string try to recover an appropriate endianness string for use in a normalized language id.
nm | is the given target string |
Referenced by normalizeArchitecture().
|
static |
Try to recover a language id processor field.
Given an architecture target string try to recover an appropriate processor name for use in a normalized language id.
nm | is the given target string |
Referenced by normalizeArchitecture().
|
static |
Try to recover a language id size field.
Given an architecture target string try to recover an appropriate size string for use in a normalized language id.
nm | is the given target string |
Referenced by normalizeArchitecture().
|
inlinevirtual |
Print an error message to console.
Write the given message to whatever the registered error stream is
message | is the error message |
Implements Architecture.
References errorstream.
Referenced by resolveArchitecture().
void SleighArchitecture::restoreXmlHeader | ( | const Element * | el | ) |
Restore from XML basic attributes of an executable.
el | is the root XML element |
References filename, and target.
Referenced by XmlArchitecture::restoreXml(), RawBinaryArchitecture::restoreXml(), and BfdArchitecture::restoreXml().
void SleighArchitecture::saveXmlHeader | ( | ostream & | s | ) | const |
Write out (as XML) basic attributes of the active executable.
s | is the XML output stream |
References filename, and target.
Referenced by XmlArchitecture::saveXml(), RawBinaryArchitecture::saveXml(), and BfdArchitecture::saveXml().
|
static |
Scan directories for SLEIGH specification files.
This assumes a standard "Ghidra/Processors/*/data/languages" layout. It scans for all matching directories and prepares for reading .ldefs files.
rootpath | is the root path of the Ghidra installation |
References specpaths.