Ghidra Decompiler Analysis Engine
ghidra_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 __GHIDRA_ARCH__
20 #define __GHIDRA_ARCH__
21 
22 #include "architecture.hh"
23 
33 struct JavaError : public LowlevelError {
34  string type;
35  JavaError(const string &tp,const string &message) : LowlevelError(message) {
36  type = tp; }
37 };
38 
61  istream &sin;
62  ostream &sout;
63  mutable string warnings;
64  string pspecxml;
65  string cspecxml;
66  string tspecxml;
67  string corespecxml;
68  bool sendsyntaxtree;
69  bool sendCcode;
70  bool sendParamMeasures;
71  virtual Scope *buildDatabase(DocumentStorage &store);
72  virtual Translate *buildTranslator(DocumentStorage &store);
73  virtual void buildLoader(DocumentStorage &store);
74  virtual PcodeInjectLibrary *buildPcodeInjectLibrary(void);
75  virtual void buildTypegrp(DocumentStorage &store);
76  virtual void buildCommentDB(DocumentStorage &store);
77  virtual void buildStringManager(DocumentStorage &store);
78  virtual void buildConstantPool(DocumentStorage &store);
79  virtual void buildContext(DocumentStorage &store);
80  virtual void buildSpecFile(DocumentStorage &store);
81  virtual void modifySpaces(Translate *trans) {} // This is handled directly by GhidraTranslate::initialize
82  virtual void postSpecFile(void);
83  virtual void resolveArchitecture(void);
84 public:
85  ArchitectureGhidra(const string &pspec,const string &cspec,const string &tspec,const string &corespec,istream &i,ostream &o);
86  const string &getWarnings(void) const { return warnings; }
87  void clearWarnings(void) { warnings.clear(); }
88  Document *getRegister(const string &regname);
89  string getRegisterName(const VarnodeData &vndata);
90  Document *getTrackedRegisters(const Address &addr);
91  string getUserOpName(int4 index);
92  uint1 *getPcodePacked(const Address &addr);
93  Document *getMappedSymbolsXML(const Address &addr);
94  Document *getExternalRefXML(const Address &addr);
95  Document *getNamespacePath(uint8 id);
96  bool isNameUsed(const string &nm,uint8 startId,uint8 stopId);
97  string getCodeLabel(const Address &addr);
98  Document *getType(const string &name,uint8 id);
99  Document *getComments(const Address &fad,uint4 flags);
100  void getBytes(uint1 *buf,int4 size,const Address &inaddr);
101  Document *getPcodeInject(const string &name,int4 type,const InjectContext &con);
102  Document *getCPoolRef(const vector<uintb> &refs);
103  // Document *getScopeProperties(Scope *newscope);
104 
109  void setSendSyntaxTree(bool val) { sendsyntaxtree = val; }
110 
111  bool getSendSyntaxTree(void) const { return sendsyntaxtree; }
112 
117  void setSendCCode(bool val) { sendCcode = val; }
118 
119  bool getSendCCode(void) const { return sendCcode; }
120 
126  void setSendParamMeasures(bool val) { sendParamMeasures = val; }
127 
128  bool getSendParamMeasures(void) const { return sendParamMeasures; }
129 
130  void getStringData(vector<uint1> &buffer,const Address &addr,Datatype *ct,int4 maxBytes,bool &isTrunc);
131  virtual void printMessage(const string &message) const;
132 
133  static void segvHandler(int4 sig);
134  static int4 readToAnyBurst(istream &s);
135  static bool readBoolStream(istream &s);
136  static void readStringStream(istream &s,string &res);
137  static void writeStringStream(ostream &s,const string &msg);
138  static void readToResponse(istream &s);
139  static void readResponseEnd(istream &s);
140  static Document *readXMLAll(istream &s);
141  static Document *readXMLStream(istream &s);
142  static uint1 *readPackedStream(istream &s);
143  static uint1 *readPackedAll(istream &s);
144  static void passJavaException(ostream &s,const string &tp,const string &msg);
145 
146  static bool isDynamicSymbolName(const string &nm);
147 };
148 
149 #endif
ArchitectureGhidra::readToAnyBurst
static int4 readToAnyBurst(istream &s)
Read the next message protocol marker.
Definition: ghidra_arch.cc:63
ArchitectureGhidra::getCPoolRef
Document * getCPoolRef(const vector< uintb > &refs)
Resolve a constant pool reference.
Definition: ghidra_arch.cc:791
ArchitectureGhidra::readBoolStream
static bool readBoolStream(istream &s)
Read a boolean value from the client.
Definition: ghidra_arch.cc:88
ArchitectureGhidra::segvHandler
static void segvHandler(int4 sig)
Handler for a segment violation (SIGSEGV) signal.
Definition: ghidra_arch.cc:28
ArchitectureGhidra::setSendParamMeasures
void setSendParamMeasures(bool val)
Toggle whether recovered parameter information is emitted as part of the main decompile action.
Definition: ghidra_arch.hh:126
LowlevelError
The lowest level error generated by the decompiler.
Definition: error.hh:44
ArchitectureGhidra::getRegister
Document * getRegister(const string &regname)
Retrieve a register description given a name.
Definition: ghidra_arch.cc:405
JavaError::type
string type
The name of the Java exception class.
Definition: ghidra_arch.hh:34
ArchitectureGhidra::getTrackedRegisters
Document * getTrackedRegisters(const Address &addr)
Retrieve tracked register values at the given address.
Definition: ghidra_arch.cc:447
ArchitectureGhidra::getUserOpName
string getUserOpName(int4 index)
Get the name of a user-defined p-code op.
Definition: ghidra_arch.cc:465
ArchitectureGhidra::getCodeLabel
string getCodeLabel(const Address &addr)
Retrieve a label at the given address.
Definition: ghidra_arch.cc:590
ArchitectureGhidra::readPackedStream
static uint1 * readPackedStream(istream &s)
Read packed p-code op information.
Definition: ghidra_arch.cc:167
Document
A complete in-memory XML document.
Definition: xml.hh:206
ArchitectureGhidra::readXMLAll
static Document * readXMLAll(istream &s)
Read a whole response as an XML document.
Definition: ghidra_arch.cc:237
PcodeInjectLibrary
A collection of p-code injection payloads.
Definition: pcodeinject.hh:162
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
ArchitectureGhidra::readStringStream
static void readStringStream(istream &s, string &res)
Receive a string from the client.
Definition: ghidra_arch.cc:117
JavaError
Exception that mirrors exceptions thrown by the Ghidra client.
Definition: ghidra_arch.hh:33
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
ArchitectureGhidra::isNameUsed
bool isNameUsed(const string &nm, uint8 startId, uint8 stopId)
Is given name used along namespace path.
Definition: ghidra_arch.cc:563
InjectContext
Context needed to emit a p-code injection as a full set of p-code operations.
Definition: pcodeinject.hh:56
ArchitectureGhidra::readResponseEnd
static void readResponseEnd(istream &s)
Read the ending query response protocol marker.
Definition: ghidra_arch.cc:225
ArchitectureGhidra::getPcodeInject
Document * getPcodeInject(const string &name, int4 type, const InjectContext &con)
Retrieve p-code to inject for a specific context.
Definition: ghidra_arch.cc:763
ArchitectureGhidra::getNamespacePath
Document * getNamespacePath(uint8 id)
Get a description of a namespace path.
Definition: ghidra_arch.cc:549
ArchitectureGhidra::getPcodePacked
uint1 * getPcodePacked(const Address &addr)
Get p-code for a single instruction.
Definition: ghidra_arch.cc:488
ArchitectureGhidra::writeStringStream
static void writeStringStream(ostream &s, const string &msg)
Send a string to the client.
Definition: ghidra_arch.cc:196
architecture.hh
Architecture and associated classes that help manage a single processor architecture and load image.
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
ArchitectureGhidra::getComments
Document * getComments(const Address &fad, uint4 flags)
Retrieve comments for a particular function.
Definition: ghidra_arch.cc:635
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
ArchitectureGhidra::passJavaException
static void passJavaException(ostream &s, const string &tp, const string &msg)
Send an exception message to the Ghidra client.
Definition: ghidra_arch.cc:268
ArchitectureGhidra::getExternalRefXML
Document * getExternalRefXML(const Address &addr)
Retrieve a description of an external function.
Definition: ghidra_arch.cc:530
ArchitectureGhidra::isDynamicSymbolName
static bool isDynamicSymbolName(const string &nm)
Check if name is of form FUN_.. or DAT_..
Definition: ghidra_arch.cc:856
ArchitectureGhidra::getMappedSymbolsXML
Document * getMappedSymbolsXML(const Address &addr)
Get symbols associated with the given address.
Definition: ghidra_arch.cc:508
Translate
The interface to a translation engine for a processor.
Definition: translate.hh:294
ArchitectureGhidra::printMessage
virtual void printMessage(const string &message) const
Print an error message to console.
Definition: ghidra_arch.cc:826
VarnodeData
Data defining a specific memory location.
Definition: pcoderaw.hh:33
ArchitectureGhidra
An implementation of the Architecture interface and connection to a Ghidra client.
Definition: ghidra_arch.hh:60
ArchitectureGhidra::getStringData
void getStringData(vector< uint1 > &buffer, const Address &addr, Datatype *ct, int4 maxBytes, bool &isTrunc)
Get string data at a specific address.
Definition: ghidra_arch.cc:705
ArchitectureGhidra::getType
Document * getType(const string &name, uint8 id)
Retrieve a data-type description for the given name and id.
Definition: ghidra_arch.cc:613
ArchitectureGhidra::getBytes
void getBytes(uint1 *buf, int4 size, const Address &inaddr)
Retrieve bytes in the LoadImage at the given address.
Definition: ghidra_arch.cc:658
DocumentStorage
A container for parsed XML documents.
Definition: xml.hh:249
ArchitectureGhidra::setSendCCode
void setSendCCode(bool val)
Toggle whether the recovered source code is emitted as part of the main decompile action.
Definition: ghidra_arch.hh:117
ArchitectureGhidra::readToResponse
static void readToResponse(istream &s)
Read the query response protocol marker.
Definition: ghidra_arch.cc:207
ArchitectureGhidra::readXMLStream
static Document * readXMLStream(istream &s)
Receive an XML document from the client.
Definition: ghidra_arch.cc:145
ArchitectureGhidra::getRegisterName
string getRegisterName(const VarnodeData &vndata)
Retrieve a register name given its storage location.
Definition: ghidra_arch.cc:422
ArchitectureGhidra::readPackedAll
static uint1 * readPackedAll(istream &s)
Read a whole response as packed p-code op information.
Definition: ghidra_arch.cc:251
ArchitectureGhidra::setSendSyntaxTree
void setSendSyntaxTree(bool val)
Toggle whether the data-flow and control-flow is emitted as part of the main decompile action.
Definition: ghidra_arch.hh:109
ArchitectureGhidra::ArchitectureGhidra
ArchitectureGhidra(const string &pspec, const string &cspec, const string &tspec, const string &corespec, istream &i, ostream &o)
Construct given specification files and i/o streams.
Definition: ghidra_arch.cc:840