Ghidra Decompiler Analysis Engine
sleigh_arch.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __SLEIGH_ARCH__
20 #define __SLEIGH_ARCH__
21 
22 #include "filemanage.hh"
23 #include "architecture.hh"
24 #include "sleigh.hh"
25 
29 class CompilerTag {
30  string name;
31  string spec;
32  string id;
33 public:
34  CompilerTag(void) {}
35  void restoreXml(const Element *el);
36  const string &getName(void) const { return name; }
37  const string &getSpec(void) const { return spec; }
38  const string &getId(void) const { return id; }
39 };
40 
50  string processor;
51  bool isbigendian;
52  int4 size;
53  string variant;
54  string version;
55  string slafile;
56  string processorspec;
57  string id;
58  string description;
59  bool deprecated;
60  vector<CompilerTag> compilers;
61  vector<TruncationTag> truncations;
62 public:
63  LanguageDescription(void) {}
64  void restoreXml(const Element *el);
65  const string &getProcessor(void) const { return processor; }
66  bool isBigEndian(void) const { return isbigendian; }
67  int4 getSize(void) const { return size; }
68  const string &getVariant(void) const { return variant; }
69  const string &getVersion(void) const { return version; }
70  const string &getSlaFile(void) const { return slafile; }
71  const string &getProcessorSpec(void) const { return processorspec; }
72  const string &getId(void) const { return id; }
73  const string &getDescription(void) const { return description; }
74  bool isDeprecated(void) const { return deprecated; }
75  const CompilerTag &getCompiler(const string &nm) const;
76  int4 numTruncations(void) const { return truncations.size(); }
77  const TruncationTag &getTruncation(int4 i) const { return truncations[i]; }
78 };
79 
90  static Sleigh *last_sleigh;
91  static int4 last_languageindex;
92  static vector<LanguageDescription> description;
93  int4 languageindex;
94  string filename;
95  string target;
96  static void loadLanguageDescription(const string &specfile,ostream &errs);
97  bool isTranslateReused(void);
98 protected:
99  ostream *errorstream;
100  // buildLoader must be filled in by derived class
101  static void collectSpecFiles(ostream &errs);
102  virtual Translate *buildTranslator(DocumentStorage &store);
104  virtual void buildSpecFile(DocumentStorage &store);
105  virtual void modifySpaces(Translate *trans);
106  virtual void resolveArchitecture(void);
107 public:
108  SleighArchitecture(const string &fname,const string &targ,ostream *estream);
109  const string &getFilename(void) const { return filename; }
110  const string &getTarget(void) const { return target; }
111  void saveXmlHeader(ostream &s) const;
112  void restoreXmlHeader(const Element *el);
113  virtual void printMessage(const string &message) const { *errorstream << message << endl; }
114  virtual ~SleighArchitecture(void);
115  virtual string getDescription(void) const;
116 
117  static string normalizeProcessor(const string &nm);
118  static string normalizeEndian(const string &nm);
119  static string normalizeSize(const string &nm);
120  static string normalizeArchitecture(const string &nm);
121  static void scanForSleighDirectories(const string &rootpath);
122  static void shutdown(void);
124 };
125 
126 #endif
SleighArchitecture::restoreXmlHeader
void restoreXmlHeader(const Element *el)
Restore from XML basic attributes of an executable.
Definition: sleigh_arch.cc:322
SleighArchitecture::buildPcodeInjectLibrary
virtual PcodeInjectLibrary * buildPcodeInjectLibrary(void)
Build the injection library.
Definition: sleigh_arch.cc:162
SleighArchitecture::collectSpecFiles
static void collectSpecFiles(ostream &errs)
Gather specification files in normal locations.
Definition: sleigh_arch.cc:301
SleighArchitecture::normalizeEndian
static string normalizeEndian(const string &nm)
Try to recover a language id endianess field.
Definition: sleigh_arch.cc:345
SleighArchitecture::normalizeArchitecture
static string normalizeArchitecture(const string &nm)
Try to recover a language id string.
Definition: sleigh_arch.cc:379
SleighArchitecture::shutdown
static void shutdown(void)
Shutdown this SleighArchitecture and free all resources.
Definition: sleigh_arch.cc:463
FileManage
Definition: filemanage.hh:29
SleighArchitecture::modifySpaces
virtual void modifySpaces(Translate *trans)
Modify address spaces as required by this Architecture.
Definition: sleigh_arch.cc:273
PcodeInjectLibrary
A collection of p-code injection payloads.
Definition: pcodeinject.hh:162
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
LanguageDescription
Contents of the <language> tag in a .ldefs file.
Definition: sleigh_arch.hh:49
Sleigh
A full SLEIGH engine.
Definition: sleigh.hh:158
SleighArchitecture::specpaths
static FileManage specpaths
Known directories that contain .ldefs files.
Definition: sleigh_arch.hh:123
TruncationTag
Object for describing how a space should be truncated.
Definition: translate.hh:63
SleighArchitecture::resolveArchitecture
virtual void resolveArchitecture(void)
Figure out the processor and compiler of the target executable.
Definition: sleigh_arch.cc:171
CompilerTag::restoreXml
void restoreXml(const Element *el)
Restore the record from an XML stream.
Definition: sleigh_arch.cc:27
sleigh.hh
Classes and utilities for the main SLEIGH engine.
SleighArchitecture::buildSpecFile
virtual void buildSpecFile(DocumentStorage &store)
Load any relevant specification files.
Definition: sleigh_arch.cc:202
architecture.hh
Architecture and associated classes that help manage a single processor architecture and load image.
SleighArchitecture
An Architecture that uses the decompiler's native SLEIGH translation engine.
Definition: sleigh_arch.hh:89
SleighArchitecture::printMessage
virtual void printMessage(const string &message) const
Print an error message to console.
Definition: sleigh_arch.hh:113
Translate
The interface to a translation engine for a processor.
Definition: translate.hh:294
SleighArchitecture::errorstream
ostream * errorstream
Error stream associated with this SleighArchitecture.
Definition: sleigh_arch.hh:99
SleighArchitecture::scanForSleighDirectories
static void scanForSleighDirectories(const string &rootpath)
Scan directories for SLEIGH specification files.
Definition: sleigh_arch.cc:422
LanguageDescription::restoreXml
void restoreXml(const Element *el)
Read the XML tag from stream.
Definition: sleigh_arch.cc:37
LanguageDescription::getCompiler
const CompilerTag & getCompiler(const string &nm) const
Get compiler specification of the given name.
Definition: sleigh_arch.cc:75
DocumentStorage
A container for parsed XML documents.
Definition: xml.hh:249
SleighArchitecture::normalizeProcessor
static string normalizeProcessor(const string &nm)
Try to recover a language id processor field.
Definition: sleigh_arch.cc:333
SleighArchitecture::SleighArchitecture
SleighArchitecture(const string &fname, const string &targ, ostream *estream)
Construct given executable file.
Definition: sleigh_arch.cc:288
SleighArchitecture::buildTranslator
virtual Translate * buildTranslator(DocumentStorage &store)
Build the Translator object.
Definition: sleigh_arch.cc:148
SleighArchitecture::saveXmlHeader
void saveXmlHeader(ostream &s) const
Write out (as XML) basic attributes of the active executable.
Definition: sleigh_arch.cc:314
CompilerTag
Contents of a <compiler> tag in a .ldefs file.
Definition: sleigh_arch.hh:29
SleighArchitecture::normalizeSize
static string normalizeSize(const string &nm)
Try to recover a language id size field.
Definition: sleigh_arch.cc:359