LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
LdrDataTableEntry.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_RUNTIME_WINDOWS_LDR_DATA_TABLE_ENTRY_H
16#define LIEF_RUNTIME_WINDOWS_LDR_DATA_TABLE_ENTRY_H
17#include <cstdint>
18#include <memory>
19#include <ostream>
20#include <string>
21
23#include "LIEF/iterators.hpp"
24#include "LIEF/visibility.h"
25#include <optional>
26
27
28namespace LIEF::runtime::windows {
29
30namespace details {
31class ldr_entry;
32class ldr_entry_it;
33}
34
39 public:
42 class Iterator final
43 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
44 LdrDataTableEntry, std::ptrdiff_t,
45 const LdrDataTableEntry*,
46 const LdrDataTableEntry&> {
47 public:
48 using implementation = details::ldr_entry_it;
49 using iterator_facade_base::operator++;
50 using iterator_facade_base::operator--;
51
53
54 LIEF_API Iterator(std::unique_ptr<details::ldr_entry_it> impl);
55
58
60 LIEF_API Iterator& operator=(Iterator&&) noexcept;
61
63
64 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
65 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
66 return !(LHS == RHS);
67 }
68
69 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
71
72 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74
76
77 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
79
82 LIEF_API std::unique_ptr<LdrDataTableEntry> yield();
83
84 private:
85 void load() const;
86
87 std::unique_ptr<details::ldr_entry_it> impl_;
88 mutable std::unique_ptr<LdrDataTableEntry> cached_;
89 };
90
92 LdrDataTableEntry(std::unique_ptr<details::ldr_entry> impl);
93
95 LdrDataTableEntry& operator=(const LdrDataTableEntry&) = delete;
96
98 LdrDataTableEntry& operator=(LdrDataTableEntry&&) noexcept;
99
101 uintptr_t dll_base() const;
102
104 uintptr_t entry_point() const;
105
107 uint32_t size_of_image() const;
108
111 std::string full_dll_name() const;
112
114 std::string base_dll_name() const;
115
117 uint32_t flags() const;
118
121 uint16_t obsolete_load_count() const;
122
125 uint16_t tls_index() const;
126
128 uint32_t time_date_stamp() const;
129
133
135 uintptr_t lock() const;
136
140 std::optional<uintptr_t> ddag_node() const;
141
145 std::optional<uintptr_t> load_context() const;
146
150 std::optional<uintptr_t> parent_dll_base() const;
151
155 std::optional<uintptr_t> switch_back_context() const;
156
160 std::optional<uintptr_t> original_base() const;
161
165 std::optional<int64_t> load_time() const;
166
170 std::optional<uint32_t> base_name_hash_value() const;
171
175 std::optional<int32_t> load_reason() const;
176
180 std::optional<uint32_t> implicit_path_options() const;
181
185 std::optional<uint32_t> reference_count() const;
186
191 std::optional<uint32_t> dependent_load_flags() const;
192
196 std::optional<uint8_t> signing_level() const;
197
201 std::optional<uint32_t> check_sum() const;
202
206 std::optional<uintptr_t> active_patch_image_base() const;
207
212 std::optional<uint32_t> hot_patch_state() const;
213
215 std::string to_string() const;
216
217 LIEF_API friend std::ostream& operator<<(std::ostream& os,
218 const LdrDataTableEntry& entry) {
219 os << entry.to_string();
220 return os;
221 }
222
224
225 private:
226 std::unique_ptr<details::ldr_entry> impl_;
227};
228
229}
230
231
232#endif
Iterator(std::unique_ptr< details::ldr_entry_it > impl)
details::ldr_entry_it implementation
Definition LdrDataTableEntry.hpp:48
std::unique_ptr< LdrDataTableEntry > yield()
Transfer ownership of the entry at the current position to the caller. Returns nullptr if the iterato...
std::optional< uint32_t > reference_count() const
Number of references currently held on the module.
uintptr_t dll_base() const
Base address at which the module is mapped in memory (DllBase).
std::optional< int64_t > load_time() const
Time at which the module was loaded.
std::optional< uint32_t > base_name_hash_value() const
Hash of the module's base name used to index the loader tables.
std::optional< int32_t > load_reason() const
Reason why the module was loaded, as a LDR_DLL_LOAD_REASON value.
std::string to_string() const
Pretty-printed representation of this entry.
std::optional< uint8_t > signing_level() const
Signing level of the module's image, as a SE_SIGNING_LEVEL value.
uint32_t flags() const
Loader flags describing the state of the module (Flags).
std::optional< uint32_t > check_sum() const
Image checksum cached by the loader.
std::optional< uintptr_t > parent_dll_base() const
Base address of the module that triggered the load of this one.
std::optional< uint32_t > implicit_path_options() const
Path-search options implied when the module was resolved.
std::optional< uintptr_t > active_patch_image_base() const
Base address of the active hot-patch image, if any.
uint32_t size_of_image() const
Size (in bytes) of the module's image in memory (SizeOfImage).
uint16_t tls_index() const
TLS slot index assigned to the module, or 0 when it has no TLS (TlsIndex).
uintptr_t entry_point() const
Address of the entry point of the module (EntryPoint).
std::optional< uintptr_t > load_context() const
Address of the loader context used while the module is being snapped.
std::optional< uintptr_t > ddag_node() const
Address of the dependency-graph node of the module (DdagNode).
uint16_t obsolete_load_count() const
Legacy load count of the module (ObsoleteLoadCount). Superseded by reference_count() on Windows 8 and...
uintptr_t lock() const
Address of the per-entry loader lock.
std::string base_dll_name() const
Base name of the module (BaseDllName), e.g. ntdll.dll.
std::optional< uintptr_t > switch_back_context() const
Address of the CHPE switch-back context.
std::optional< uintptr_t > original_base() const
Preferred base address recorded in the PE headers.
std::optional< uint32_t > dependent_load_flags() const
Flags controlling how the statically-linked dependencies of the module are loaded.
uintptr_t entry_point_activation_context() const
Address of the activation context associated with the module's entry point.
std::string full_dll_name() const
Full path of the module (FullDllName), e.g. C:\Windows\System32\ntdll.dll.
uint32_t time_date_stamp() const
TimeDateStamp of the module as cached by the loader.
std::optional< uint32_t > hot_patch_state() const
State of the hot-patch engine for this module, as a LDR_HOT_PATCH_STATE value.
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition LdrDataTableEntry.hpp:30
Definition windows/Host.hpp:23
#define LIEF_API
Definition visibility.h:44