retdec
ExportDirectory.h
Go to the documentation of this file.
1 /*
2 * ExportDirectory.h - Part of the PeLib library.
3 *
4 * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5 * All rights reserved.
6 *
7 * This software is licensed under the zlib/libpng License.
8 * For more details see http://www.opensource.org/licenses/zlib-license.php
9 * or the license information file (license.htm) in the root directory
10 * of PeLib.
11 */
12 
13 #ifndef RETDEC_PELIB_EXPORTDIRECTORY_H
14 #define RETDEC_PELIB_EXPORTDIRECTORY_H
15 
17 
18 namespace PeLib
19 {
21 
26  {
27  protected:
31  std::vector<std::pair<unsigned int, unsigned int>> m_occupiedAddresses;
32 
33  void addOccupiedAddress(const std::string & str, std::uint32_t rva);
34 
35  public:
36  virtual ~ExportDirectory() = default;
37 
39  int read(ImageLoader & imageLoader);
40 
42  void addFunction(const std::string& strFuncname, std::uint32_t dwFuncAddr); // EXPORT
43  unsigned int calcNumberOfFunctions() const; // EXPORT
44  void clear(); // EXPORT
46  int getFunctionIndex(const std::string& strFunctionName) const; // EXPORT
48  void rebuild(std::vector<std::uint8_t>& vBuffer, std::uint32_t dwRva) const; // EXPORT
49  void removeFunction(unsigned int index); // EXPORT
51  unsigned int size() const; // EXPORT
53  int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const; // EXPORT
54 
56  void setNameString(const std::string& strFilename); // EXPORT
57  std::string getNameString() const; // EXPORT
58 
60  std::string getFunctionName(std::size_t index) const; // EXPORT
62  std::uint16_t getFunctionOrdinal(std::size_t index) const; // EXPORT
64  std::uint32_t getAddressOfName(std::size_t index) const; // EXPORT
66  std::uint32_t getAddressOfFunction(std::size_t index) const; // EXPORT
67 
69  void setFunctionName(std::size_t index, const std::string& strName); // EXPORT
71  void setFunctionOrdinal(std::size_t index, std::uint16_t wValue); // EXPORT
73  void setAddressOfName(std::size_t index, std::uint32_t dwValue); // EXPORT
75  void setAddressOfFunction(std::size_t index, std::uint32_t dwValue); // EXPORT
76 
77  /*
78  std::uint16_t getFunctionOrdinal(std::string strFuncname) const;
79  std::uint32_t getAddressOfName(std::string strFuncname) const;
80  std::uint32_t getAddressOfFunction(std::string strFuncname) const;
81 
82  void setFunctionOrdinal(std::string strFuncname, std::uint16_t wValue);
83  void setAddressOfName(std::string strFuncname, std::uint32_t dwValue);
84  void setAddressOfFunction(std::string strFuncname, std::uint32_t dwValue);
85  */
86 
88  std::uint32_t getBase() const; // EXPORT
90  std::uint32_t getCharacteristics() const; // EXPORT
92  std::uint32_t getTimeDateStamp() const; // EXPORT
94  std::uint16_t getMajorVersion() const; // EXPORT
96  std::uint16_t getMinorVersion() const; // EXPORT
98  std::uint32_t getName() const; // EXPORT
100  std::uint32_t getNumberOfFunctions() const; // EXPORT
102  std::uint32_t getNumberOfNames() const; // EXPORT
104  std::uint32_t getAddressOfFunctions() const; // EXPORT
106  std::uint32_t getAddressOfNames() const; // EXPORT
108  std::uint32_t getAddressOfNameOrdinals() const; // EXPORT
109 
110 /* /// Returns the number of NameOrdinals.
111  std::uint32_t getNumberOfNameOrdinals() const; // EXPORT
113  std::uint32_t getNumberOfAddressOfFunctionNames() const; // EXPORT
115  std::uint32_t getNumberOfAddressOfFunctions() const; // EXPORT
116 */
118  void setBase(std::uint32_t dwValue); // EXPORT
120  void setCharacteristics(std::uint32_t dwValue); // EXPORT
122  void setTimeDateStamp(std::uint32_t dwValue); // EXPORT
124  void setMajorVersion(std::uint16_t wValue); // EXPORT
126  void setMinorVersion(std::uint16_t wValue); // EXPORT
128  void setName(std::uint32_t dwValue); // EXPORT
130  void setNumberOfFunctions(std::uint32_t dwValue); // EXPORT
132  void setNumberOfNames(std::uint32_t dwValue); // EXPORT
134  void setAddressOfFunctions(std::uint32_t dwValue); // EXPORT
136  void setAddressOfNames(std::uint32_t dwValue); // EXPORT
137  void setAddressOfNameOrdinals(std::uint32_t value); // EXPORT
138 
139  const std::vector<std::pair<unsigned int, unsigned int>>& getOccupiedAddresses() const;
140  };
141 }
142 #endif
Class that handles the export directory.
Definition: ExportDirectory.h:26
std::uint32_t getAddressOfFunction(std::size_t index) const
Get the address of an exported function.
Definition: ExportDirectory.cpp:348
std::vector< std::pair< unsigned int, unsigned int > > m_occupiedAddresses
Stores RVAs which are occupied by this export directory.
Definition: ExportDirectory.h:31
void rebuild(std::vector< std::uint8_t > &vBuffer, std::uint32_t dwRva) const
Rebuild the current export directory.
Definition: ExportDirectory.cpp:179
std::uint32_t getAddressOfFunctions() const
Return the AddressOfFunctions value of the export directory.
Definition: ExportDirectory.cpp:456
const std::vector< std::pair< unsigned int, unsigned int > > & getOccupiedAddresses() const
Definition: ExportDirectory.cpp:577
std::string getNameString() const
Definition: ExportDirectory.cpp:312
void setNameString(const std::string &strFilename)
Changes the name of the file (according to the export directory).
Definition: ExportDirectory.cpp:307
int write(const std::string &strFilename, unsigned int uiOffset, unsigned int uiRva) const
Writes the current export directory to a file.
Definition: ExportDirectory.cpp:271
void setAddressOfNames(std::uint32_t dwValue)
Set the AddressOfNames value of the export directory.
Definition: ExportDirectory.cpp:567
void setBase(std::uint32_t dwValue)
Set the Base value of the export directory.
Definition: ExportDirectory.cpp:495
void setMinorVersion(std::uint16_t wValue)
Set the MinorVersion value of the export directory.
Definition: ExportDirectory.cpp:527
void removeFunction(unsigned int index)
Definition: ExportDirectory.cpp:137
void setFunctionName(std::size_t index, const std::string &strName)
Change the name of an exported function.
Definition: ExportDirectory.cpp:357
void setCharacteristics(std::uint32_t dwValue)
Set the Characteristics value of the export directory.
Definition: ExportDirectory.cpp:503
std::uint32_t getName() const
Return the Name value of the export directory.
Definition: ExportDirectory.cpp:432
std::uint32_t getAddressOfName(std::size_t index) const
Get the address of the name of an exported function.
Definition: ExportDirectory.cpp:339
void setNumberOfFunctions(std::uint32_t dwValue)
Set the NumberOfFunctions value of the export directory.
Definition: ExportDirectory.cpp:543
std::uint32_t getAddressOfNameOrdinals() const
Returns the AddressOfNameOrdinals value.
Definition: ExportDirectory.cpp:487
std::uint16_t getMajorVersion() const
Return the MajorVersion value of the export directory.
Definition: ExportDirectory.cpp:416
void addOccupiedAddress(const std::string &str, std::uint32_t rva)
Definition: ExportDirectory.cpp:22
void setFunctionOrdinal(std::size_t index, std::uint16_t wValue)
Change the ordinal of an exported function.
Definition: ExportDirectory.cpp:366
void setMajorVersion(std::uint16_t wValue)
Set the MajorVersion value of the export directory.
Definition: ExportDirectory.cpp:519
void addFunction(const std::string &strFuncname, std::uint32_t dwFuncAddr)
Add another function to be exported.
Definition: ExportDirectory.cpp:129
std::uint32_t getAddressOfNames() const
Return the AddressOfNames value of the export directory.
Definition: ExportDirectory.cpp:464
std::uint16_t getFunctionOrdinal(std::size_t index) const
Get the ordinal of an exported function.
Definition: ExportDirectory.cpp:330
std::string getFunctionName(std::size_t index) const
Get the name of an exported function.
Definition: ExportDirectory.cpp:321
void setAddressOfFunctions(std::uint32_t dwValue)
Set the AddressOfFunctions value of the export directory.
Definition: ExportDirectory.cpp:559
void setName(std::uint32_t dwValue)
Set the Name value of the export directory.
Definition: ExportDirectory.cpp:535
std::uint32_t getBase() const
Return the Base value of the export directory.
Definition: ExportDirectory.cpp:392
void setNumberOfNames(std::uint32_t dwValue)
Set the NumberOfNames value of the export directory.
Definition: ExportDirectory.cpp:551
void setTimeDateStamp(std::uint32_t dwValue)
Set the TimeDateStamp value of the export directory.
Definition: ExportDirectory.cpp:511
unsigned int size() const
Returns the size of the current export directory.
Definition: ExportDirectory.cpp:260
virtual ~ExportDirectory()=default
int getFunctionIndex(const std::string &strFunctionName) const
Identifies a function through it's name.
Definition: ExportDirectory.cpp:157
int read(ImageLoader &imageLoader)
Load the export directory from the image loader.
Definition: ExportDirectory.cpp:33
std::uint32_t getTimeDateStamp() const
Return the TimeDateStamp value of the export directory.
Definition: ExportDirectory.cpp:408
std::uint16_t getMinorVersion() const
Return the MinorVersion value of the export directory.
Definition: ExportDirectory.cpp:424
void setAddressOfName(std::size_t index, std::uint32_t dwValue)
Change the address of the name of an exported function.
Definition: ExportDirectory.cpp:375
std::uint32_t getNumberOfNames() const
Return the NumberOfNames value of the export directory.
Definition: ExportDirectory.cpp:448
std::uint32_t getCharacteristics() const
Return the Characteristics value of the export directory.
Definition: ExportDirectory.cpp:400
void clear()
Definition: ExportDirectory.cpp:142
void setAddressOfNameOrdinals(std::uint32_t value)
Definition: ExportDirectory.cpp:572
std::uint32_t getNumberOfFunctions() const
Return the NumberOfFunctions value of the export directory.
Definition: ExportDirectory.cpp:440
void setAddressOfFunction(std::size_t index, std::uint32_t dwValue)
Change the address of an exported function.
Definition: ExportDirectory.cpp:384
unsigned int calcNumberOfFunctions() const
Definition: ExportDirectory.cpp:147
PELIB_IMAGE_EXP_DIRECTORY m_ied
Used to store all necessary information about a file's exported functions.
Definition: ExportDirectory.h:29
Definition: ImageLoader.h:138
Definition: BoundImportDirectory.h:21
Definition: PeLibAux.h:1041