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