|
1 | 1 | #include "stdafx.h" |
2 | 2 |
|
3 | | -PRTL_RB_TREE NTAPI RtlFindLdrpModuleBaseAddressIndex() { |
4 | | - static PRTL_RB_TREE LdrpModuleBaseAddressIndex = nullptr; |
5 | | - if (LdrpModuleBaseAddressIndex)return LdrpModuleBaseAddressIndex; |
6 | | - |
7 | | - PLDR_DATA_TABLE_ENTRY_WIN10 nt10 = decltype(nt10)(RtlFindNtdllLdrEntry()); |
8 | | - PRTL_BALANCED_NODE node = nullptr; |
9 | | - if (!nt10 || !RtlIsWindowsVersionOrGreater(6, 2, 0))return nullptr; |
10 | | - node = &nt10->BaseAddressIndexNode; |
11 | | - while (node->ParentValue & (~7)) node = decltype(node)(node->ParentValue & (~7)); |
12 | | - |
13 | | - if (!node->Red) { |
14 | | - BYTE count = 0; |
15 | | - PRTL_RB_TREE tmp = nullptr; |
16 | | - SEARCH_CONTEXT SearchContext{}; |
17 | | - SearchContext.MemoryBuffer = &node; |
18 | | - SearchContext.BufferLength = sizeof(size_t); |
19 | | - while (NT_SUCCESS(RtlFindMemoryBlockFromModuleSection((HMODULE)nt10->DllBase, ".data", &SearchContext))) { |
20 | | - if (count++)return nullptr; |
21 | | - tmp = (decltype(tmp))SearchContext.MemoryBlockInSection; |
22 | | - } |
23 | | - if (count && tmp && tmp->Root && tmp->Min) { |
24 | | - LdrpModuleBaseAddressIndex = tmp; |
25 | | - } |
26 | | - } |
27 | | - |
28 | | - return LdrpModuleBaseAddressIndex; |
29 | | -} |
30 | | - |
31 | | -NTSTATUS NTAPI RtlInsertModuleBaseAddressIndexNode(IN PLDR_DATA_TABLE_ENTRY DataTableEntry, IN PVOID BaseAddress) { |
32 | | - static auto LdrpModuleBaseAddressIndex = RtlFindLdrpModuleBaseAddressIndex(); |
| 3 | +NTSTATUS NTAPI RtlInsertModuleBaseAddressIndexNode( |
| 4 | + _In_ PLDR_DATA_TABLE_ENTRY DataTableEntry, |
| 5 | + _In_ PVOID BaseAddress) { |
| 6 | + auto LdrpModuleBaseAddressIndex = MmpGlobalDataPtr->MmpBaseAddressIndex.LdrpModuleBaseAddressIndex; |
33 | 7 | if (!LdrpModuleBaseAddressIndex)return STATUS_UNSUCCESSFUL; |
34 | 8 |
|
35 | 9 | PLDR_DATA_TABLE_ENTRY_WIN8 LdrNode = decltype(LdrNode)((size_t)LdrpModuleBaseAddressIndex - offsetof(LDR_DATA_TABLE_ENTRY_WIN8, BaseAddressIndexNode)); |
@@ -60,8 +34,8 @@ NTSTATUS NTAPI RtlInsertModuleBaseAddressIndexNode(IN PLDR_DATA_TABLE_ENTRY Data |
60 | 34 | return STATUS_SUCCESS; |
61 | 35 | } |
62 | 36 |
|
63 | | -NTSTATUS NTAPI RtlRemoveModuleBaseAddressIndexNode(IN PLDR_DATA_TABLE_ENTRY DataTableEntry) { |
64 | | - static auto tree{ RtlFindLdrpModuleBaseAddressIndex() }; |
| 37 | +NTSTATUS NTAPI RtlRemoveModuleBaseAddressIndexNode(_In_ PLDR_DATA_TABLE_ENTRY DataTableEntry) { |
| 38 | + static auto tree{ MmpGlobalDataPtr->MmpBaseAddressIndex.LdrpModuleBaseAddressIndex }; |
65 | 39 | if (!tree->Root)return STATUS_UNSUCCESSFUL; |
66 | 40 | RtlRbRemoveNode(tree, &PLDR_DATA_TABLE_ENTRY_WIN8(DataTableEntry)->BaseAddressIndexNode); |
67 | 41 | return STATUS_SUCCESS; |
|
0 commit comments