Ghidra Decompiler Analysis Engine
override.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 __OVERRIDE__
20 #define __OVERRIDE__
21 
22 #include "database.hh"
23 
24 class FuncCallSpecs; // Forward declaration
25 
40 class Override {
41 public:
43  enum {
44  NONE = 0,
45  BRANCH = 1,
46  CALL = 2,
48  RETURN = 4
49  };
50 private:
51  map<Address,Address> forcegoto;
52  vector<int4> deadcodedelay;
53  map<Address,Address> indirectover;
54  map<Address,FuncProto *> protoover;
55  vector<Address> multistagejump;
56  map<Address,uint4> flowoverride;
57  void clear(void);
58  static string generateDeadcodeDelayMessage(int4 index,Architecture *glb);
59 public:
60  ~Override(void) { clear(); }
61  void insertForceGoto(const Address &targetpc,const Address &destpc);
62  void insertDeadcodeDelay(AddrSpace *spc,int4 delay);
63  bool hasDeadcodeDelay(AddrSpace *spc) const;
64  void insertIndirectOverride(const Address &callpoint,const Address &directcall);
65  void insertProtoOverride(const Address &callpoint,FuncProto *p);
66  void insertMultistageJump(const Address &addr);
67  void insertFlowOverride(const Address &addr,uint4 type);
68 
69  void applyPrototype(Funcdata &data,FuncCallSpecs &fspecs) const;
70  void applyIndirect(Funcdata &data,FuncCallSpecs &fspecs) const;
71  bool queryMultistageJumptable(const Address &addr) const;
72  void applyDeadCodeDelay(Funcdata &data) const;
73  void applyForceGoto(Funcdata &data) const;
74  bool hasFlowOverride(void) const { return (!flowoverride.empty()); }
75  uint4 getFlowOverride(const Address &addr) const;
76  void printRaw(ostream &s,Architecture *glb) const;
77  void generateOverrideMessages(vector<string> &messagelist,Architecture *glb) const;
78  void saveXml(ostream &s,Architecture *glb) const;
79  void restoreXml(const Element *el,Architecture *glb);
80  static string typeToString(uint4 tp);
81  static uint4 stringToType(const string &nm);
82 };
83 
84 #endif
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
Override::restoreXml
void restoreXml(const Element *el, Architecture *glb)
Read in override commands from XML.
Definition: override.cc:349
Override::applyIndirect
void applyIndirect(Funcdata &data, FuncCallSpecs &fspecs) const
Look for and apply destination overrides of indirect calls.
Definition: override.cc:167
Override::BRANCH
@ BRANCH
Replace primary CALL or RETURN with suitable BRANCH operation.
Definition: override.hh:45
Override::insertMultistageJump
void insertMultistageJump(const Address &addr)
Flag an indirect jump for multistage analysis.
Definition: override.cc:127
Override
A container of commands that override the decompiler's default behavior for a single function.
Definition: override.hh:40
Override::getFlowOverride
uint4 getFlowOverride(const Address &addr) const
Return the particular flow override at a given address.
Definition: override.cc:223
Override::printRaw
void printRaw(ostream &s, Architecture *glb) const
Dump a description of the overrides to stream.
Definition: override.cc:238
Override::applyForceGoto
void applyForceGoto(Funcdata &data) const
Push all the force-goto overrides into the function.
Definition: override.cc:194
FuncCallSpecs
A class for analyzing parameters to a sub-function call.
Definition: fspec.hh:1449
Override::applyDeadCodeDelay
void applyDeadCodeDelay(Funcdata &data) const
Apply any dead-code delay overrides.
Definition: override.cc:207
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
Override::insertFlowOverride
void insertFlowOverride(const Address &addr, uint4 type)
Mark a branch instruction with a different flow type.
Definition: override.cc:138
Override::stringToType
static uint4 stringToType(const string &nm)
Convert a string to a flow override type.
Definition: override.cc:434
Override::applyPrototype
void applyPrototype(Funcdata &data, FuncCallSpecs &fspecs) const
Look for and apply a function prototype override.
Definition: override.cc:150
Override::CALL_RETURN
@ CALL_RETURN
Replace primary BRANCH or RETURN with suitable CALL/RETURN operation.
Definition: override.hh:47
Override::hasDeadcodeDelay
bool hasDeadcodeDelay(AddrSpace *spc) const
Check if a delay override is already installed for an address space.
Definition: override.cc:82
Override::typeToString
static string typeToString(uint4 tp)
Convert a flow override type to a string.
Definition: override.cc:418
Override::queryMultistageJumptable
bool queryMultistageJumptable(const Address &addr) const
Check for a multistage marker for a specific indirect jump.
Definition: override.cc:181
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Override::generateOverrideMessages
void generateOverrideMessages(vector< string > &messagelist, Architecture *glb) const
Create warning messages that describe current overrides.
Definition: override.cc:269
Override::insertIndirectOverride
void insertIndirectOverride(const Address &callpoint, const Address &directcall)
Override an indirect call turning it into a direct call.
Definition: override.cc:99
Override::NONE
@ NONE
No override.
Definition: override.hh:44
database.hh
Symbol and Scope objects for the decompiler.
Override::insertForceGoto
void insertForceGoto(const Address &targetpc, const Address &destpc)
Force a specific branch instruction to be an unstructured goto.
Definition: override.cc:56
Override::insertProtoOverride
void insertProtoOverride(const Address &callpoint, FuncProto *p)
Override the assumed function prototype at a specific call site.
Definition: override.cc:111
Override::CALL
@ CALL
Replace primary BRANCH or RETURN with suitable CALL operation.
Definition: override.hh:46
Override::saveXml
void saveXml(ostream &s, Architecture *glb) const
Write the override commands to an XML stream.
Definition: override.cc:284
FuncProto
A function prototype.
Definition: fspec.hh:1164
Override::RETURN
@ RETURN
Replace primary BRANCH or CALL with a suitable RETURN operation.
Definition: override.hh:48
Override::insertDeadcodeDelay
void insertDeadcodeDelay(AddrSpace *spc, int4 delay)
Override the number of passes that are executed before dead-code elimination starts.
Definition: override.cc:69