Ghidra Decompiler Analysis Engine
inject_ghidra.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 __INJECT_GHIDRA__
20 #define __INJECT_GHIDRA__
21 
22 #include "pcodeinject.hh"
23 #include "ghidra_arch.hh"
24 
30 public:
31  virtual void saveXml(ostream &s) const;
32 };
33 
40  string source;
41 public:
42  InjectPayloadGhidra(const string &src,const string &nm,int4 tp) : InjectPayload(nm,tp) { source = src; }
43  virtual void inject(InjectContext &context,PcodeEmit &emit) const;
44  virtual void restoreXml(const Element *el) {}
45  virtual void printTemplate(ostream &s) const;
46  virtual string getSource(void) const { return source; }
47 };
48 
51 public:
52  InjectCallfixupGhidra(const string &src,const string &nm);
53  virtual void restoreXml(const Element *el);
54 };
55 
58 public:
59  InjectCallotherGhidra(const string &src,const string &nm);
60  virtual void restoreXml(const Element *el);
61 };
62 
69 public:
70  ExecutablePcodeGhidra(Architecture *g,const string &src,const string &nm);
71  virtual void inject(InjectContext &context,PcodeEmit &emit) const;
72  virtual void restoreXml(const Element *el);
73  virtual void printTemplate(ostream &s) const;
74 };
75 
81  InjectContextGhidra contextCache;
82  vector<OpBehavior *> inst;
83  virtual int4 allocateInject(const string &sourceName,const string &name,int4 type);
84  virtual void registerInject(int4 injectid);
85 public:
87  virtual int4 manualCallFixup(const string &name,const string &snippet);
88  virtual int4 manualCallOtherFixup(const string &name,const string &outname,const vector<string> &inname,
89  const string &snippet);
90  virtual InjectContext &getCachedContext(void) { return contextCache; }
91  virtual const vector<OpBehavior *> &getBehaviors(void);
92 };
93 
94 #endif
InjectCallfixupGhidra::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_ghidra.cc:83
InjectPayloadGhidra
An injection payload that uses a Ghidra client to generate the p-code ops.
Definition: inject_ghidra.hh:39
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.
PcodeInjectLibraryGhidra
A p-code injection library that uses a Ghidra client to generate/compile the injection p-code.
Definition: inject_ghidra.hh:80
ExecutablePcodeGhidra::ExecutablePcodeGhidra
ExecutablePcodeGhidra(Architecture *g, const string &src, const string &nm)
Constructor.
Definition: inject_ghidra.cc:106
pcodeinject.hh
Classes for managing p-code injection.
InjectCallotherGhidra
A callother-fixup injection that uses a Ghidra client to generate the p-code ops.
Definition: inject_ghidra.hh:57
InjectContextGhidra::saveXml
virtual void saveXml(ostream &s) const
Save this context to an XML stream as a <context> tag.
Definition: inject_ghidra.cc:18
InjectPayloadGhidra::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_ghidra.hh:44
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
InjectContext
Context needed to emit a p-code injection as a full set of p-code operations.
Definition: pcodeinject.hh:56
InjectPayload
An active container for a set of p-code operations that can be injected into data-flow.
Definition: pcodeinject.hh:78
InjectCallfixupGhidra
A call-fixup injection that uses a Ghidra client to generate the p-code ops.
Definition: inject_ghidra.hh:50
PcodeInjectLibraryGhidra::getBehaviors
virtual const vector< OpBehavior * > & getBehaviors(void)
Get the array of op-code behaviors for initializing and emulator.
Definition: inject_ghidra.cc:202
ExecutablePcodeGhidra::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_ghidra.cc:136
ExecutablePcodeGhidra::printTemplate
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_ghidra.cc:143
InjectPayloadGhidra::getSource
virtual string getSource(void) const
Return a string describing the source of the injection (.cspec, prototype model, etc....
Definition: inject_ghidra.hh:46
InjectCallotherGhidra::InjectCallotherGhidra
InjectCallotherGhidra(const string &src, const string &nm)
Constructor.
Definition: inject_ghidra.cc:89
InjectCallotherGhidra::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_ghidra.cc:94
InjectContextGhidra
An injection context that can be serialized and sent to the Ghidra client.
Definition: inject_ghidra.hh:29
InjectPayloadGhidra::printTemplate
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_ghidra.cc:72
PcodeInjectLibraryGhidra::manualCallFixup
virtual int4 manualCallFixup(const string &name, const string &snippet)
Manually add a call-fixup payload given a compilable snippet of p-code source.
Definition: inject_ghidra.cc:210
ExecutablePcodeGhidra
A p-code script that uses a Ghidra client to generate the p-code ops.
Definition: inject_ghidra.hh:68
InjectPayloadGhidra::inject
virtual void inject(InjectContext &context, PcodeEmit &emit) const
Definition: inject_ghidra.cc:47
ExecutablePcodeGhidra::inject
virtual void inject(InjectContext &context, PcodeEmit &emit) const
Definition: inject_ghidra.cc:111
ArchitectureGhidra
An implementation of the Architecture interface and connection to a Ghidra client.
Definition: ghidra_arch.hh:60
PcodeInjectLibraryGhidra::PcodeInjectLibraryGhidra
PcodeInjectLibraryGhidra(ArchitectureGhidra *ghi)
Constructor.
Definition: inject_ghidra.cc:196
PcodeInjectLibraryGhidra::getCachedContext
virtual InjectContext & getCachedContext(void)
Retrieve a reusable context object for this library.
Definition: inject_ghidra.hh:90
PcodeInjectLibraryGhidra::manualCallOtherFixup
virtual int4 manualCallOtherFixup(const string &name, const string &outname, const vector< string > &inname, const string &snippet)
Manually add a callother-fixup payload given a compilable snippet of p-code source.
Definition: inject_ghidra.cc:216
ExecutablePcode
A snippet of p-code that can be executed outside of normal analysis.
Definition: pcodeinject.hh:134
InjectCallfixupGhidra::InjectCallfixupGhidra
InjectCallfixupGhidra(const string &src, const string &nm)
Constructor.
Definition: inject_ghidra.cc:78