Ghidra Decompiler Analysis Engine
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
LoadImage::filename
string filename
Name of the loadimage.
Definition: loadimage.hh:73
RawLoadImage::RawLoadImage
RawLoadImage(const string &f)
RawLoadImage constructor.
Definition: loadimage.cc:37
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
LoadImageSection::noload
@ noload
uninitialized section
Definition: loadimage.hh:48
LowlevelError
The lowest level error generated by the decompiler.
Definition: error.hh:44
LoadImage::getFileName
const string & getFileName(void) const
Get the name of the LoadImage.
Definition: loadimage.hh:125
LoadImage::getReadonly
virtual void getReadonly(RangeList &list) const
Return list of readonly address ranges.
Definition: loadimage.hh:184
LoadImage::LoadImage
LoadImage(const string &f)
LoadImage constructor.
Definition: loadimage.hh:114
LoadImage::loadFill
virtual void loadFill(uint1 *ptr, int4 size, const Address &addr)=0
Get data from the LoadImage.
RawLoadImage::adjustVma
virtual void adjustVma(long adjust)
Adjust load addresses with a global offset.
Definition: loadimage.cc:75
LoadImage::getArchType
virtual string getArchType(void) const =0
Get a string indicating the architecture type.
LoadImageFunc::name
string name
Name of function.
Definition: loadimage.hh:38
LoadImageSection::readonly
@ readonly
read only section
Definition: loadimage.hh:51
LoadImage::adjustVma
virtual void adjustVma(long adjust)=0
Adjust load addresses with a global offset.
LoadImage::load
uint1 * load(int4 size, const Address &addr)
Load a chunk of image.
Definition: loadimage.cc:27
DataUnavailError
Exception indicating data was not available.
Definition: loadimage.hh:29
LoadImage
An interface into a particular binary executable image.
Definition: loadimage.hh:71
RawLoadImage::loadFill
virtual void loadFill(uint1 *ptr, int4 size, const Address &addr)
Get data from the LoadImage.
Definition: loadimage.cc:82
LoadImageSection::flags
uint4 flags
Properties of the section.
Definition: loadimage.hh:55
RangeList
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
LoadImage::~LoadImage
virtual ~LoadImage(void)
LoadImage destructor.
Definition: loadimage.hh:119
LoadImageFunc
A record indicating a function symbol.
Definition: loadimage.hh:36
LoadImage::getNextSection
virtual bool getNextSection(LoadImageSection &sec) const
Get info on the next section.
Definition: loadimage.hh:174
LoadImage::openSectionInfo
virtual void openSectionInfo(void) const
Prepare to read section info.
Definition: loadimage.hh:159
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
RawLoadImage::getArchType
virtual string getArchType(void) const
Get a string indicating the architecture type.
Definition: loadimage.cc:69
LowlevelError::LowlevelError
LowlevelError(const string &s)
Initialize the error with an explanatory string.
Definition: error.hh:47
RawLoadImage::~RawLoadImage
virtual ~RawLoadImage(void)
RawLoadImage destructor.
Definition: loadimage.cc:46
LoadImage::closeSymbols
virtual void closeSymbols(void) const
Stop reading symbols.
Definition: loadimage.hh:140
LoadImageSection::data
@ data
data only
Definition: loadimage.hh:50
LoadImageSection
A record describing a section bytes in the executable.
Definition: loadimage.hh:44
LoadImage::openSymbols
virtual void openSymbols(void) const
Prepare to read symbols.
Definition: loadimage.hh:133
LoadImageFunc::address
Address address
Start of function.
Definition: loadimage.hh:37
LoadImage::getNextSymbol
virtual bool getNextSymbol(LoadImageFunc &record) const
Get the next symbol record.
Definition: loadimage.hh:151
address.hh
Classes for specifying addresses and other low-level constants.
LoadImageSection::size
uintb size
Number of bytes in section.
Definition: loadimage.hh:54
LoadImage::closeSectionInfo
virtual void closeSectionInfo(void) const
Stop reading section info.
Definition: loadimage.hh:165
RawLoadImage
A simple raw binary loadimage.
Definition: loadimage.hh:96
RawLoadImage::open
void open(void)
Open the raw file for reading.
Definition: loadimage.cc:56
LoadImageSection::code
@ code
code only
Definition: loadimage.hh:49
LoadImageSection::unalloc
@ unalloc
Not allocated in memory (debug info)
Definition: loadimage.hh:47
LoadImageSection::address
Address address
Starting address of section.
Definition: loadimage.hh:53