My Project
loadimage.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 __CPUI_LOADIMAGE__
20 #define __CPUI_LOADIMAGE__
21 
22 #include "address.hh"
23 
30  DataUnavailError(const string &s) : LowlevelError(s) {}
31 };
32 
36 struct LoadImageFunc {
38  string name;
39 };
40 
46  enum {
47  unalloc = 1,
48  noload = 2,
49  code = 4,
50  data = 8,
51  readonly = 16
52  };
54  uintb size;
55  uint4 flags;
56 };
57 
71 class LoadImage {
72 protected:
73  string filename;
74 public:
75  LoadImage(const string &f);
76  virtual ~LoadImage(void);
77  const string &getFileName(void) const;
78  virtual void loadFill(uint1 *ptr,int4 size,const Address &addr)=0;
79  virtual void openSymbols(void) const;
80  virtual void closeSymbols(void) const;
81  virtual bool getNextSymbol(LoadImageFunc &record) const;
82  virtual void openSectionInfo(void) const;
83  virtual void closeSectionInfo(void) const;
84  virtual bool getNextSection(LoadImageSection &sec) const;
85  virtual void getReadonly(RangeList &list) const;
86  virtual string getArchType(void) const=0;
87  virtual void adjustVma(long adjust)=0;
88  uint1 *load(int4 size,const Address &addr);
89 };
90 
96 class RawLoadImage : public LoadImage {
97  uintb vma;
98  ifstream *thefile;
99  uintb filesize;
100  AddrSpace *spaceid;
101 public:
102  RawLoadImage(const string &f);
103  void attachToSpace(AddrSpace *id) { spaceid = id; }
104  void open(void);
105  virtual ~RawLoadImage(void);
106  virtual void loadFill(uint1 *ptr,int4 size,const Address &addr);
107  virtual string getArchType(void) const;
108  virtual void adjustVma(long adjust);
109 };
110 
114 inline LoadImage::LoadImage(const string &f) {
115  filename = f;
116 }
117 
119 inline LoadImage::~LoadImage(void) {
120 }
121 
125 inline const string &LoadImage::getFileName(void) const {
126  return filename;
127 }
128 
133 inline void LoadImage::openSymbols(void) const {
134 }
135 
140 inline void LoadImage::closeSymbols(void) const {
141 }
142 
151 inline bool LoadImage::getNextSymbol(LoadImageFunc &record) const {
152  return false;
153 }
154 
159 inline void LoadImage::openSectionInfo(void) const {
160 }
161 
165 inline void LoadImage::closeSectionInfo(void) const {
166 }
167 
174 inline bool LoadImage::getNextSection(LoadImageSection &record) const {
175  return false;
176 }
177 
184 inline void LoadImage::getReadonly(RangeList &list) const {
185 }
186 
202 
213 
226 
227 #endif
Address address
Starting address of section.
Definition: loadimage.hh:53
virtual void openSymbols(void) const
Prepare to read symbols.
Definition: loadimage.hh:133
A region where processor data is stored.
Definition: space.hh:73
A record indicating a function symbol.
Definition: loadimage.hh:36
DataUnavailError(const string &s)
Instantiate with an explanatory string.
Definition: loadimage.hh:30
An interface into a particular binary executable image.
Definition: loadimage.hh:71
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
virtual void closeSectionInfo(void) const
Stop reading section info.
Definition: loadimage.hh:165
string filename
Name of the loadimage.
Definition: loadimage.hh:73
const string & getFileName(void) const
Get the name of the LoadImage.
Definition: loadimage.hh:125
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Exception indicating data was not available.
Definition: loadimage.hh:29
Classes for specifying addresses and other low-level constants.
uint4 flags
Properties of the section.
Definition: loadimage.hh:55
The lowest level error generated by the decompiler.
Definition: error.hh:44
void attachToSpace(AddrSpace *id)
Attach the raw image to a particular space.
Definition: loadimage.hh:103
virtual void getReadonly(RangeList &list) const
Return list of readonly address ranges.
Definition: loadimage.hh:184
virtual void openSectionInfo(void) const
Prepare to read section info.
Definition: loadimage.hh:159
virtual bool getNextSymbol(LoadImageFunc &record) const
Get the next symbol record.
Definition: loadimage.hh:151
Address address
Start of function.
Definition: loadimage.hh:37
virtual ~LoadImage(void)
LoadImage destructor.
Definition: loadimage.hh:119
A record describing a section bytes in the executable.
Definition: loadimage.hh:44
string name
Name of function.
Definition: loadimage.hh:38
uintb size
Number of bytes in section.
Definition: loadimage.hh:54
LoadImage(const string &f)
LoadImage constructor.
Definition: loadimage.hh:114
virtual void closeSymbols(void) const
Stop reading symbols.
Definition: loadimage.hh:140
virtual bool getNextSection(LoadImageSection &sec) const
Get info on the next section.
Definition: loadimage.hh:174
A simple raw binary loadimage.
Definition: loadimage.hh:96