Ghidra Decompiler Analysis Engine
cover.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 #ifndef __CPUI_COVER__
19 #define __CPUI_COVER__
20 
21 #include "type.hh"
22 
23 class PcodeOp;
24 class FlowBlock;
25 class Varnode;
26 
35 class CoverBlock {
36  const PcodeOp *start;
37  const PcodeOp *stop;
38 public:
39  CoverBlock(void) { start = (const PcodeOp *)0; stop = (const PcodeOp *)0; }
40  static uintm getUIndex(const PcodeOp *op);
41  const PcodeOp *getStart(void) const { return start; }
42  const PcodeOp *getStop(void) const { return stop; }
43  void clear(void) { start = (const PcodeOp *)0; stop = (const PcodeOp *)0; }
44  void setAll(void) {
45  start = (const PcodeOp *)0; stop = (const PcodeOp *)1; }
46  void setBegin(const PcodeOp *begin) {
47  start = begin; if (stop==(const PcodeOp *)0) stop = (const PcodeOp *)1; }
48  void setEnd(const PcodeOp *end) { stop = end; }
49  int4 intersect(const CoverBlock &op2) const;
50  bool empty(void) const {
51  return ((start==(const PcodeOp *)0)&&(stop==(const PcodeOp *)0)); }
52  bool contain(const PcodeOp *point) const;
53  int4 boundary(const PcodeOp *point) const;
54  void merge(const CoverBlock &op2);
55  void print(ostream &s) const;
56 };
57 
68 class Cover {
69  map<int4,CoverBlock> cover;
70  static const CoverBlock emptyBlock;
71  void addRefRecurse(const FlowBlock *bl);
72 public:
73  void clear(void) { cover.clear(); }
74  int4 compareTo(const Cover &op2) const;
75  const CoverBlock &getCoverBlock(int4 i) const;
76  int4 intersect(const Cover &op2) const;
77  int4 intersectByBlock(int4 blk,const Cover &op2) const;
78  void intersectList(vector<int4> &listout,const Cover &op2,int4 level) const;
79  bool contain(const PcodeOp *op,int4 max) const;
80  int4 containVarnodeDef(const Varnode *vn) const;
81  void merge(const Cover &op2);
82  void rebuild(const Varnode *vn);
83  void addDefPoint(const Varnode *vn);
84  void addRefPoint(const PcodeOp *ref,const Varnode *vn);
85  // void remove_refpoint(const PcodeOp *ref,const Varnode *vn) {
86  // rebuild(vn); } // Cheap but inefficient
87  void print(ostream &s) const;
88  map<int4,CoverBlock>::const_iterator begin(void) const { return cover.begin(); }
89  map<int4,CoverBlock>::const_iterator end(void) const { return cover.end(); }
90 };
91 
92 #endif
Cover::getCoverBlock
const CoverBlock & getCoverBlock(int4 i) const
Get the CoverBlock corresponding to the i-th block.
Definition: cover.cc:251
CoverBlock::intersect
int4 intersect(const CoverBlock &op2) const
Compute intersection with another CoverBlock.
Definition: cover.cc:57
FlowBlock
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
Cover::intersect
int4 intersect(const Cover &op2) const
Characterize the intersection between this and another Cover.
Definition: cover.cc:267
CoverBlock::getUIndex
static uintm getUIndex(const PcodeOp *op)
Get the comparison index for a PcodeOp.
Definition: cover.cc:27
CoverBlock::contain
bool contain(const PcodeOp *point) const
Check containment of given point.
Definition: cover.cc:105
Cover::addRefPoint
void addRefPoint(const PcodeOp *ref, const Varnode *vn)
Add a variable read to this Cover.
Definition: cover.cc:504
Cover::intersectList
void intersectList(vector< int4 > &listout, const Cover &op2, int4 level) const
Generate a list of blocks that intersect.
Definition: cover.cc:305
Cover::intersectByBlock
int4 intersectByBlock(int4 blk, const Cover &op2) const
Characterize the intersection on a specific block.
Definition: cover.cc:342
CoverBlock::boundary
int4 boundary(const PcodeOp *point) const
Characterize given point as boundary.
Definition: cover.cc:127
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
Cover::print
void print(ostream &s) const
Dump a description of this cover to stream.
Definition: cover.cc:554
Cover::containVarnodeDef
int4 containVarnodeDef(const Varnode *vn) const
Check the definition of a Varnode for containment.
Definition: cover.cc:391
CoverBlock
The topological scope of a variable within a basic block.
Definition: cover.hh:35
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
Cover::compareTo
int4 compareTo(const Cover &op2) const
Give ordering of this and another Cover.
Definition: cover.cc:221
Cover
A description of the topological scope of a single variable object.
Definition: cover.hh:68
Cover::merge
void merge(const Cover &op2)
Merge this with another Cover block by block.
Definition: cover.cc:415
Cover::addDefPoint
void addDefPoint(const Varnode *vn)
Reset to the single point where the given Varnode is defined.
Definition: cover.cc:440
Cover::contain
bool contain(const PcodeOp *op, int4 max) const
Does this contain the given PcodeOp.
Definition: cover.cc:363
type.hh
Classes for describing and printing data-types.
CoverBlock::merge
void merge(const CoverBlock &op2)
Merge another CoverBlock into this.
Definition: cover.cc:145
Cover::rebuild
void rebuild(const Varnode *vn)
Reset this based on def-use of a single Varnode.
Definition: cover.cc:427
CoverBlock::print
void print(ostream &s) const
Dump a description to stream.
Definition: cover.cc:186