Ghidra Decompiler Analysis Engine
dynamic.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  */
19 
20 #ifndef __CPUI_DYNAMIC__
21 #define __CPUI_DYNAMIC__
22 
23 #include "varnode.hh"
24 
30 class ToOpEdge {
31  const PcodeOp *op;
32  int4 slot;
33 public:
34  ToOpEdge(const PcodeOp *o,int4 s) { op = o; slot = s; }
35  const PcodeOp *getOp(void) const { return op; }
36  int4 getSlot(void) const { return slot; }
37  bool operator<(const ToOpEdge &op2) const;
38  uint4 hash(uint4 reg) const;
39 };
40 
60 class DynamicHash {
61  uint4 vnproc;
62  uint4 opproc;
63  uint4 opedgeproc;
64 
65  vector<const PcodeOp *> markop;
66  vector<const Varnode *> markvn;
67  vector<const Varnode *> vnedge;
68  vector<ToOpEdge> opedge;
69 
70  Address addrresult;
71  uint8 hash;
72  void buildVnUp(const Varnode *vn);
73  void buildVnDown(const Varnode *vn);
74  void buildOpUp(const PcodeOp *op);
75  void buildOpDown(const PcodeOp *op);
76  void gatherUnmarkedVn(void);
77  void gatherUnmarkedOp(void);
78 public:
79  void clear(void);
80  void calcHash(const Varnode *root,uint4 method);
81  void uniqueHash(const Varnode *root,Funcdata *fd);
82  Varnode *findVarnode(const Funcdata *fd,const Address &addr,uint8 h);
83  uint8 getHash(void) const { return hash; }
84 
85  const Address &getAddress(void) const { return addrresult; }
86  static void gatherFirstLevelVars(vector<Varnode *> &varlist,const Funcdata *fd,const Address &addr,uint8 h);
87  static int4 getSlotFromHash(uint8 h);
88  static uint4 getMethodFromHash(uint8 h);
89  static OpCode getOpCodeFromHash(uint8 h);
90  static uint4 getPositionFromHash(uint8 h);
91  static uint4 getTotalFromHash(uint8 h);
92  static bool getIsNotAttached(uint8 h);
93  static void clearTotalPosition(uint8 &h);
94  static uint4 transtable[];
95 };
96 
97 #endif
DynamicHash::uniqueHash
void uniqueHash(const Varnode *root, Funcdata *fd)
Select a unique hash for the given Varnode.
Definition: dynamic.cc:330
ToOpEdge::hash
uint4 hash(uint4 reg) const
Hash this edge into an accumulator.
Definition: dynamic.cc:89
DynamicHash::getIsNotAttached
static bool getIsNotAttached(uint8 h)
Retrieve the attachment boolean from a hash.
Definition: dynamic.cc:517
DynamicHash::getSlotFromHash
static int4 getSlotFromHash(uint8 h)
Retrieve the encoded slot from a hash.
Definition: dynamic.cc:469
DynamicHash::getMethodFromHash
static uint4 getMethodFromHash(uint8 h)
Retrieve the encoded method from a hash.
Definition: dynamic.cc:481
DynamicHash::getPositionFromHash
static uint4 getPositionFromHash(uint8 h)
Retrieve the encoded position from a hash.
Definition: dynamic.cc:499
DynamicHash::findVarnode
Varnode * findVarnode(const Funcdata *fd, const Address &addr, uint8 h)
Given an address and hash, find the unique matching Varnode.
Definition: dynamic.cc:396
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
DynamicHash::getTotalFromHash
static uint4 getTotalFromHash(uint8 h)
Retrieve the encoded collision total from a hash.
Definition: dynamic.cc:508
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
ToOpEdge
An edge between a Varnode and a PcodeOp.
Definition: dynamic.hh:30
DynamicHash::gatherFirstLevelVars
static void gatherFirstLevelVars(vector< Varnode * > &varlist, const Funcdata *fd, const Address &addr, uint8 h)
Get the Varnodes immediately attached to PcodeOps at the given address.
Definition: dynamic.cc:426
DynamicHash::clear
void clear(void)
Called for each additional hash (after the first)
Definition: dynamic.cc:190
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
DynamicHash::getOpCodeFromHash
static OpCode getOpCodeFromHash(uint8 h)
Retrieve the encoded op-code from a hash.
Definition: dynamic.cc:490
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
DynamicHash::clearTotalPosition
static void clearTotalPosition(uint8 &h)
Clear the collision total and position fields within a hash.
Definition: dynamic.cc:526
DynamicHash
A hash utility to uniquely identify a temporary Varnode in data-flow.
Definition: dynamic.hh:60
DynamicHash::calcHash
void calcHash(const Varnode *root, uint4 method)
Calculate the hash for given Varnode and method.
Definition: dynamic.cc:210
DynamicHash::transtable
static uint4 transtable[]
Translation of op-codes to hash values.
Definition: dynamic.hh:94
OpCode
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
varnode.hh
The Varnode and VarnodeBank classes.
ToOpEdge::operator<
bool operator<(const ToOpEdge &op2) const
Compare two edges based on PcodeOp.
Definition: dynamic.cc:66