My Project
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 
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
Definition: inject_sleigh.hh:58
Classes for managing p-code injection.
Context needed to emit a p-code injection as a full set of p-code operations.
Definition: pcodeinject.hh:56
Definition: inject_sleigh.hh:31
A collection of p-code injection payloads.
Definition: pcodeinject.hh:162
Abstract class for emitting pcode to an application.
Definition: translate.hh:76
A snippet of p-code that can be executed outside of normal analysis.
Definition: pcodeinject.hh:134
virtual string getSource(void) const
Return a string describing the source of the injection (.cspec, prototype model, etc.)
Definition: inject_sleigh.hh:42
virtual string getSource(void) const
Return a string describing the source of the injection (.cspec, prototype model, etc.)
Definition: inject_sleigh.hh:86
virtual void printTemplate(ostream &s) const
Print the p-code ops of the injection to a stream (for debugging)
Definition: inject_sleigh.hh:85
Common core of classes that read or write SLEIGH specification files natively.
Definition: sleighbase.hh:29
Definition: sleigh.hh:35
Definition: context.hh:68
vector< VarnodeData > inputlist
Storage location for input parameters.
Definition: pcodeinject.hh:62
Definition: inject_sleigh.hh:51
An active container for a set of p-code operations that can be injected into data-flow.
Definition: pcodeinject.hh:78
Definition: inject_sleigh.hh:22
Definition: context.hh:163
Manager for all the major decompiler subsystems.
Definition: architecture.hh:117
virtual InjectContext & getCachedContext(void)
Retrieve a reusable context object for this library.
Definition: inject_sleigh.hh:104
Definition: semantics.hh:161
An XML element. A node in the DOM tree.
Definition: xml.hh:150
virtual void saveXml(ostream &s) const
Save this context to an XML stream as a <context> tag.
Definition: inject_sleigh.hh:28
Architecture * glb
Architecture associated with the injection.
Definition: pcodeinject.hh:58
Definition: inject_sleigh.hh:77
vector< VarnodeData > output
Storage location for output.
Definition: pcodeinject.hh:63
Definition: inject_sleigh.hh:89
Definition: inject_sleigh.hh:64