LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
ImportEntry.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_ENTRY_H
17#define LIEF_PE_IMPORT_ENTRY_H
18#include <string>
19#include <ostream>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/visibility.h"
23#include "LIEF/Abstract/Symbol.hpp"
24
25#include "LIEF/PE/enums.hpp"
26
27namespace LIEF {
28namespace PE {
29class Parser;
30class Builder;
31
36class LIEF_API ImportEntry : public LIEF::Symbol {
37 friend class Parser;
38 friend class Builder;
39
40 public:
42 ImportEntry(uint64_t data, const std::string& name = "");
43 ImportEntry(uint64_t data, PE_TYPE type, const std::string& name);
44 ImportEntry(const std::string& name);
45 ImportEntry(const std::string& name, PE_TYPE type);
47 ImportEntry& operator=(const ImportEntry&);
48 ~ImportEntry() override;
49
51 bool is_ordinal() const;
52
54 uint16_t ordinal() const {
55 static constexpr auto MASK = 0xFFFF;
56 return is_ordinal() ? (data_ & MASK) : 0;
57 }
58
60 uint64_t hint_name_rva() const {
61 return data();
62 }
63
66 uint16_t hint() const {
67 return hint_;
68 }
69
72 uint64_t iat_value() const {
73 return iat_value_;
74 }
75
77 uint64_t data() const {
78 return data_;
79 }
80
82 uint64_t iat_address() const {
83 return rva_;
84 }
85
86 void data(uint64_t data) {
87 data_ = data;
88 }
89
90 void accept(Visitor& visitor) const override;
91
92
93 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ImportEntry& entry);
94
95 private:
96 uint64_t data_ = 0;
97 uint16_t hint_ = 0;
98 uint64_t iat_value_ = 0;
99 uint64_t rva_ = 0;
100 PE_TYPE type_ = PE_TYPE::PE32_PLUS;
101};
102
103}
104}
105
106#endif /* IMPORTENTRY_H */
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Class that represents an entry (i.e. an import) in the import table (Import).
Definition ImportEntry.hpp:36
uint16_t ordinal() const
The ordinal value.
Definition ImportEntry.hpp:54
uint64_t iat_value() const
Value of the current entry in the Import Address Table. It should match the lookup table value.
Definition ImportEntry.hpp:72
uint16_t hint() const
Index into the Export::entries that is used to speed-up the symbol resolution.
Definition ImportEntry.hpp:66
uint64_t hint_name_rva() const
Definition ImportEntry.hpp:60
uint64_t data() const
Raw value.
Definition ImportEntry.hpp:77
bool is_ordinal() const
True if it is an import by ordinal
uint64_t iat_address() const
Original address of the entry in the Import Address Table
Definition ImportEntry.hpp:82
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:28
Definition Visitor.hpp:219
PE_TYPE
Definition PE/enums.hpp:680
LIEF namespace.
Definition Abstract/Binary.hpp:32