Ghidra Decompiler Analysis Engine
ghidra_translate.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 __TRANSLATE_GHIDRA__
20 #define __TRANSLATE_GHIDRA__
21 
22 #include "translate.hh"
23 #include "ghidra_arch.hh"
24 
34 class GhidraTranslate : public Translate {
35  ArchitectureGhidra *glb;
36  mutable map<string,VarnodeData> nm2addr;
37  mutable map<VarnodeData,string> addr2nm;
38  const VarnodeData &cacheRegister(const string &nm,const VarnodeData &data) const;
39  void restoreXml(const Element *el);
40 public:
41  GhidraTranslate(ArchitectureGhidra *g) { glb = g; }
42 
43  virtual void initialize(DocumentStorage &store);
44  virtual void addRegister(const string &nm,AddrSpace *base,uintb offset,int4 size) {
45  throw LowlevelError("Cannot add register name into GHIDRA through this interface"); }
46  virtual const VarnodeData &getRegister(const string &nm) const;
47  virtual string getRegisterName(AddrSpace *base,uintb off,int4 size) const;
48  virtual void getAllRegisters(map<VarnodeData,string> &reglist) const {
49  throw LowlevelError("Cannot currently get all registers through this interface"); }
50  virtual void getUserOpNames(vector<string> &res) const;
51  virtual int4 oneInstruction(PcodeEmit &emit,const Address &baseaddr) const;
52  virtual int4 instructionLength(const Address &baseaddr) const {
53  throw LowlevelError("Cannot currently get instruction length through this interface"); }
54  virtual int4 printAssembly(AssemblyEmit &emit,const Address &baseaddr) const {
55  throw LowlevelError("Cannot dump assembly through this interface"); }
56 };
57 
58 #endif
PcodeEmit
Abstract class for emitting pcode to an application.
Definition: translate.hh:76
ghidra_arch.hh
Ghidra specific architecture information and connection to a Ghidra client.
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
GhidraTranslate::getAllRegisters
virtual void getAllRegisters(map< VarnodeData, string > &reglist) const
Get a list of all register names and the corresponding location.
Definition: ghidra_translate.hh:48
LowlevelError
The lowest level error generated by the decompiler.
Definition: error.hh:44
translate.hh
Classes for disassembly and pcode generation.
AssemblyEmit
Abstract class for emitting disassembly to an application.
Definition: translate.hh:118
GhidraTranslate
An implementation of Translate that queries a Ghidra client for p-code information.
Definition: ghidra_translate.hh:34
GhidraTranslate::printAssembly
virtual int4 printAssembly(AssemblyEmit &emit, const Address &baseaddr) const
Disassemble a single machine instruction.
Definition: ghidra_translate.hh:54
GhidraTranslate::addRegister
virtual void addRegister(const string &nm, AddrSpace *base, uintb offset, int4 size)
Add a named register to the model for this processor.
Definition: ghidra_translate.hh:44
GhidraTranslate::initialize
virtual void initialize(DocumentStorage &store)
Initialize the translator given XML configuration documents.
Definition: ghidra_translate.cc:33
GhidraTranslate::instructionLength
virtual int4 instructionLength(const Address &baseaddr) const
Get the length of a machine instruction.
Definition: ghidra_translate.hh:52
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
GhidraTranslate::getRegisterName
virtual string getRegisterName(AddrSpace *base, uintb off, int4 size) const
Get the name of a register given its location.
Definition: ghidra_translate.cc:71
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
GhidraTranslate::getUserOpNames
virtual void getUserOpNames(vector< string > &res) const
Get a list of all user-defined pcode ops.
Definition: ghidra_translate.cc:88
Translate
The interface to a translation engine for a processor.
Definition: translate.hh:294
GhidraTranslate::oneInstruction
virtual int4 oneInstruction(PcodeEmit &emit, const Address &baseaddr) const
Transform a single machine instruction into pcode.
Definition: ghidra_translate.cc:100
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
DocumentStorage
A container for parsed XML documents.
Definition: xml.hh:249
GhidraTranslate::getRegister
virtual const VarnodeData & getRegister(const string &nm) const
Get a register as VarnodeData given its name.
Definition: ghidra_translate.cc:42