LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
Import.hpp
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
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 */
16#ifndef LIEF_PE_IMPORT_H
17#define LIEF_PE_IMPORT_H
18
19#include <string>
20#include <ostream>
21
22#include "LIEF/errors.hpp"
23#include "LIEF/Object.hpp"
24#include "LIEF/types.hpp"
25#include "LIEF/visibility.h"
26#include "LIEF/iterators.hpp"
27#include "LIEF/PE/ImportEntry.hpp"
28
29namespace LIEF {
30namespace PE {
31class Parser;
32class Builder;
33class DataDirectory;
34
35namespace details {
36struct pe_import;
37}
38
40class LIEF_API Import : public Object {
41
42 friend class Parser;
43 friend class Builder;
44
45 public:
46 using entries_t = std::vector<ImportEntry>;
49
50 Import(const details::pe_import& import);
51 Import(std::string name);
52 Import();
53 ~Import() override;
54
55 Import(const Import& other);
56 Import(Import&& other) noexcept;
57 Import& operator=(Import&& other) noexcept;
58 Import& operator=(const Import& other);
59
61 uint32_t forwarder_chain() const;
62
65 uint32_t timedatestamp() const;
66
69 it_entries entries();
70
76 uint32_t import_address_table_rva() const;
77
82 uint32_t import_lookup_table_rva() const;
83
88 result<uint32_t> get_function_rva_from_iat(const std::string& function) const;
89
91 ImportEntry* get_entry(const std::string& name);
92 const ImportEntry* get_entry(const std::string& name) const;
93
95 const std::string& name() const;
96
98 void name(const std::string& name);
99
105 const DataDirectory* directory() const;
106
112 const DataDirectory* iat_directory() const;
113
116
118 ImportEntry& add_entry(const std::string& name);
119
120 void import_lookup_table_rva(uint32_t rva);
121 void import_address_table_rva(uint32_t rva);
122
123 void accept(Visitor& visitor) const override;
124
125
126 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Import& entry);
127
128 private:
129 entries_t entries_;
130 DataDirectory* directory_ = nullptr;
131 DataDirectory* iat_directory_ = nullptr;
132 uint32_t import_lookup_table_RVA_ = 0;
133 uint32_t timedatestamp_ = 0;
134 uint32_t forwarder_chain_ = 0;
135 uint32_t name_RVA_ = 0;
136 uint32_t import_address_table_RVA_ = 0;
137 std::string name_;
138 PE_TYPE type_ = PE_TYPE::PE32;
139};
140
141}
142}
143
144#endif
Definition Object.hpp:25
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:38
Class that represents an entry (i.e. an import) in the import table (Import).
Definition ImportEntry.hpp:36
Class that represents a PE import.
Definition Import.hpp:40
DataDirectory * directory()
Return the PE::DataDirectory associated with this import. It should be the one at index PE::DataDirec...
void name(const std::string &name)
Change the current import name.
it_const_entries entries() const
Iterator over the PE::ImportEntry.
ImportEntry & add_entry(const std::string &name)
Add a new import entry with the given name (i.e. an imported function)
uint32_t forwarder_chain() const
The index of the first forwarder reference.
ImportEntry * get_entry(const std::string &name)
Return the imported function with the given name.
uint32_t import_lookup_table_rva() const
Return the relative virtual address of the import lookup table.
uint32_t import_address_table_rva() const
The RVA of the import address table (IAT). The content of this table is identical to the content of t...
uint32_t timedatestamp() const
The stamp that is set to zero until the image is bound. After the image is bound, this field is set t...
result< uint32_t > get_function_rva_from_iat(const std::string &function) const
Return the Function's RVA from the import address table (IAT)
const std::string & name() const
Return the library's name (e.g. kernel32.dll)
DataDirectory * iat_directory()
Return the PE::DataDirectory associated associated with the IAT. It should be the one at index PE::Da...
ImportEntry & add_entry(const ImportEntry &entry)
Add a new import entry (i.e. an imported function)
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
PE_TYPE
Definition PE/enums.hpp:680
LIEF namespace.
Definition Abstract/Binary.hpp:32
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:72