Ghidra Decompiler Analysis Engine
inject_sleigh.hh
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  */
16 #ifndef __INJECT_SLEIGH__
17 #define __INJECT_SLEIGH__
18 
19 #include "pcodeinject.hh"
20 #include "sleigh.hh"
21 
23 public:
24  PcodeCacher cacher;
25  ParserContext *pos;
26  InjectContextSleigh(void) { pos = (ParserContext *)0; }
27  virtual ~InjectContextSleigh(void);
28  virtual void saveXml(ostream &s) const {} // We don't need this functionality for sleigh
29 };
30 
32  friend class PcodeInjectLibrarySleigh;
33  ConstructTpl *tpl;
34  string parsestring;
35  string source;
36 public:
37  InjectPayloadSleigh(const string &src,const string &nm,int4 tp);
38  virtual ~InjectPayloadSleigh(void);
39  virtual void inject(InjectContext &context,PcodeEmit &emit) const;
40  virtual void restoreXml(const Element *el);
41  virtual void printTemplate(ostream &s) const;
42  virtual string getSource(void) const { return source; }
43 
44  static void checkParameterRestrictions(InjectContextSleigh &con,const vector<InjectParameter> &inputlist,
45  const vector<InjectParameter> &output,const string &source);
46  static void setupParameters(InjectContextSleigh &con,ParserWalkerChange &walker,
47  const vector<InjectParameter> &inputlist,const vector<InjectParameter> &output,
48  const string &source);
49 };
50 
52  vector<string> targetSymbolNames;
53 public:
54  InjectPayloadCallfixup(const string &sourceName);
55  virtual void restoreXml(const Element *el);
56 };
57 
59 public:
60  InjectPayloadCallother(const string &sourceName);
61  virtual void restoreXml(const Element *el);
62 };
63 
65  friend class PcodeInjectLibrarySleigh;
66 protected:
67  string parsestring;
68  ConstructTpl *tpl;
69  public:
70  ExecutablePcodeSleigh(Architecture *g,const string &src,const string &nm);
71  virtual ~ExecutablePcodeSleigh(void);
72  virtual void inject(InjectContext &context,PcodeEmit &emit) const;
73  virtual void restoreXml(const Element *el);
74  virtual void printTemplate(ostream &s) const;
75 };
76 
78  Architecture *glb;
79  map<Address,Document *> addrMap; // Map from address to specific inject
80 public:
81  InjectPayloadDynamic(Architecture *g,const string &nm,int4 tp) : InjectPayload(nm,tp) { glb = g; dynamic = true; }
82  virtual ~InjectPayloadDynamic(void);
83  void restoreEntry(const Element *el);
84  virtual void inject(InjectContext &context,PcodeEmit &emit) const;
85  virtual void printTemplate(ostream &s) const { s << "dynamic"; }
86  virtual string getSource(void) const { return "dynamic"; }
87 };
88 
90  const SleighBase *slgh;
91  vector<OpBehavior *> inst;
92  InjectContextSleigh contextCache;
93  int4 registerDynamicInject(InjectPayload *payload);
94  void parseInject(InjectPayload *payload);
95 protected:
96  virtual int4 allocateInject(const string &sourceName,const string &name,int4 type);
97  virtual void registerInject(int4 injectid);
98 public:
99  PcodeInjectLibrarySleigh(Architecture *g,uintb tmpbase);
100  virtual void restoreDebug(const Element *el);
101  virtual int4 manualCallFixup(const string &name,const string &snippetstring);
102  virtual int4 manualCallOtherFixup(const string &name,const string &outname,const vector<string> &inname,
103  const string &snippet);
104  virtual InjectContext &getCachedContext(void) { return contextCache; }
105  virtual const vector<OpBehavior *> &getBehaviors(void);
106 };
107 
108 #endif
InjectPayload::output
vector< InjectParameter > output
List of output parameters.
Definition: pcodeinject.hh:93
PcodeInjectLibrarySleigh::registerInject
virtual void registerInject(int4 injectid)
Finalize a payload within the library, once the payload is initialized.
Definition: inject_sleigh.cc:356
PcodeEmit
Abstract class for emitting pcode to an application.
Definition: translate.hh:76
InjectPayloadDynamic
Definition: inject_sleigh.hh:77
InjectPayloadCallfixup
Definition: inject_sleigh.hh:51
PcodeInjectLibrarySleigh::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_sleigh.cc:428
InjectPayloadCallfixup::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_sleigh.cc:141
pcodeinject.hh
Classes for managing p-code injection.
ParserContext
Definition: context.hh:68
InjectPayloadDynamic::printTemplate
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_sleigh.hh:85
InjectPayloadSleigh::getSource
virtual string getSource(void) const
Return a string describing the source of the injection (.cspec, prototype model, etc....
Definition: inject_sleigh.hh:42
InjectPayloadDynamic::inject
virtual void inject(InjectContext &context, PcodeEmit &emit) const
Definition: inject_sleigh.cc:268
PcodeInjectLibrary
A collection of p-code injection payloads.
Definition: pcodeinject.hh:162
InjectPayloadSleigh::printTemplate
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_sleigh.cc:80
InjectPayloadSleigh
Definition: inject_sleigh.hh:31
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
InjectContextSleigh
Definition: inject_sleigh.hh:22
ExecutablePcodeSleigh::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_sleigh.cc:214
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
PcodeInjectLibrarySleigh::allocateInject
virtual int4 allocateInject(const string &sourceName, const string &name, int4 type)
Allocate a new InjectPayload object.
Definition: inject_sleigh.cc:341
PcodeInjectLibrarySleigh::getCachedContext
virtual InjectContext & getCachedContext(void)
Retrieve a reusable context object for this library.
Definition: inject_sleigh.hh:104
ExecutablePcodeSleigh::inject
virtual void inject(InjectContext &context, PcodeEmit &emit) const
Definition: inject_sleigh.cc:192
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
InjectPayloadSleigh::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_sleigh.cc:64
InjectContextSleigh::saveXml
virtual void saveXml(ostream &s) const
Save this context to an XML stream as a <context> tag.
Definition: inject_sleigh.hh:28
ParserWalkerChange
Definition: context.hh:163
sleigh.hh
Classes and utilities for the main SLEIGH engine.
InjectPayloadCallother
Definition: inject_sleigh.hh:58
PcodeInjectLibrarySleigh::restoreDebug
virtual void restoreDebug(const Element *el)
A method for reading in p-code generated externally for use in debugging.
Definition: inject_sleigh.cc:388
PcodeCacher
Class for caching a chunk of p-code, prior to emitting.
Definition: sleigh.hh:56
InjectPayloadCallother::restoreXml
virtual void restoreXml(const Element *el)
Restore this payload from an XML stream.
Definition: inject_sleigh.cc:167
InjectPayload::dynamic
bool dynamic
True if the injection is generated dynamically.
Definition: pcodeinject.hh:89
PcodeInjectLibrarySleigh::getBehaviors
virtual const vector< OpBehavior * > & getBehaviors(void)
Get the array of op-code behaviors for initializing and emulator.
Definition: inject_sleigh.cc:409
InjectPayload::inputlist
vector< InjectParameter > inputlist
List of input parameters to this payload.
Definition: pcodeinject.hh:92
InjectPayloadSleigh::inject
virtual void inject(InjectContext &context, PcodeEmit &emit) const
Definition: inject_sleigh.cc:42
SleighBase
Common core of classes that read or write SLEIGH specification files natively.
Definition: sleighbase.hh:57
InjectPayloadDynamic::getSource
virtual string getSource(void) const
Return a string describing the source of the injection (.cspec, prototype model, etc....
Definition: inject_sleigh.hh:86
ConstructTpl
Definition: semantics.hh:161
PcodeInjectLibrarySleigh
Definition: inject_sleigh.hh:89
ExecutablePcodeSleigh
Definition: inject_sleigh.hh:64
ExecutablePcode
A snippet of p-code that can be executed outside of normal analysis.
Definition: pcodeinject.hh:134
PcodeInjectLibrarySleigh::manualCallFixup
virtual int4 manualCallFixup(const string &name, const string &snippetstring)
Manually add a call-fixup payload given a compilable snippet of p-code source.
Definition: inject_sleigh.cc:417
ExecutablePcodeSleigh::printTemplate
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_sleigh.cc:232