Ghidra Decompiler Analysis Engine
loadimage_bfd.hh
1 /* ###
2  * IP: GHIDRA
3  * NOTE: Interface to GNU BFD library which is GPL 3
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 // Use the GNU bfd library to manipulate a load image
18 
19 #ifndef __LOADIMAGE_BFD__
20 #define __LOADIMAGE_BFD__
21 
22 #include "loadimage.hh"
23 #include <bfd.h>
24 
25 struct ImportRecord {
26  string dllname;
27  string funcname;
28  int ordinal;
29  Address address;
30  Address thunkaddress;
31 };
32 
33 class LoadImageBfd : public LoadImage {
34  static int4 bfdinit; // Is the library (globally) initialized
35  string target; // File format (supported by BFD)
36  bfd *thebfd;
37  AddrSpace *spaceid; // We need to map space id to segments but since
38  // we are currently ignoring segments anyway...
39  uintb bufoffset; // Starting offset of byte buffer
40  uint4 bufsize; // Number of bytes in the buffer
41  uint1 *buffer; // The actual buffer
42  mutable asymbol **symbol_table;
43  mutable long number_of_symbols;
44  mutable long cursymbol;
45  mutable asection *secinfoptr;
46  asection *findSection(uintb offset,uintb &ssize) const; // Find section containing given offset
47  void advanceToNextSymbol(void) const;
48 public:
49  LoadImageBfd(const string &f,const string &t);
50  void attachToSpace(AddrSpace *id) { spaceid = id; }
51  void open(void); // Open any descriptors
52  void close(void); // Close any descriptor
53  void getImportTable(vector<ImportRecord> &irec) { throw LowlevelError("Not implemented"); }
54  virtual ~LoadImageBfd(void);
55  virtual void loadFill(uint1 *ptr,int4 size,const Address &addr); // Load a chunk of image
56  virtual void openSymbols(void) const;
57  virtual void closeSymbols(void) const;
58  virtual bool getNextSymbol(LoadImageFunc &record) const;
59  virtual void openSectionInfo(void) const;
60  virtual void closeSectionInfo(void) const;
61  virtual bool getNextSection(LoadImageSection &sec) const;
62  virtual void getReadonly(RangeList &list) const;
63  virtual string getArchType(void) const;
64  virtual void adjustVma(long adjust);
65 };
66 
67 #endif
LoadImageBfd::loadFill
virtual void loadFill(uint1 *ptr, int4 size, const Address &addr)
Get data from the LoadImage.
Definition: loadimage_bfd.cc:122
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
ImportRecord
Definition: loadimage_bfd.hh:25
LowlevelError
The lowest level error generated by the decompiler.
Definition: error.hh:44
loadimage.hh
Classes and API for accessing a binary load image.
LoadImageBfd
Definition: loadimage_bfd.hh:33
LoadImageBfd::openSymbols
virtual void openSymbols(void) const
Prepare to read symbols.
Definition: loadimage_bfd.cc:192
LoadImage
An interface into a particular binary executable image.
Definition: loadimage.hh:71
LoadImageBfd::getArchType
virtual string getArchType(void) const
Get a string indicating the architecture type.
Definition: loadimage_bfd.cc:49
RangeList
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
LoadImageFunc
A record indicating a function symbol.
Definition: loadimage.hh:36
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
LoadImageBfd::getReadonly
virtual void getReadonly(RangeList &list) const
Return list of readonly address ranges.
Definition: loadimage_bfd.cc:284
LoadImageSection
A record describing a section bytes in the executable.
Definition: loadimage.hh:44
LoadImageBfd::openSectionInfo
virtual void openSectionInfo(void) const
Prepare to read section info.
Definition: loadimage_bfd.cc:239
LoadImageBfd::getNextSection
virtual bool getNextSection(LoadImageSection &sec) const
Get info on the next section.
Definition: loadimage_bfd.cc:251
LoadImageBfd::adjustVma
virtual void adjustVma(long adjust)
Adjust load addresses with a global offset.
Definition: loadimage_bfd.cc:61
LoadImageBfd::getNextSymbol
virtual bool getNextSymbol(LoadImageFunc &record) const
Get the next symbol record.
Definition: loadimage_bfd.cc:225
LoadImageBfd::closeSymbols
virtual void closeSymbols(void) const
Stop reading symbols.
Definition: loadimage_bfd.cc:274
LoadImageBfd::closeSectionInfo
virtual void closeSectionInfo(void) const
Stop reading section info.
Definition: loadimage_bfd.cc:245