Skip to content

Commit d1787b1

Browse files
authored
Merge pull request #15 from bb107/initialize
Initialize
2 parents 3b2f04e + 609d7e7 commit d1787b1

30 files changed

Lines changed: 1454 additions & 981 deletions

MemoryModule/BaseAddressIndex.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
#include "stdafx.h"
22

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;
337
if (!LdrpModuleBaseAddressIndex)return STATUS_UNSUCCESSFUL;
348

359
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
6034
return STATUS_SUCCESS;
6135
}
6236

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 };
6539
if (!tree->Root)return STATUS_UNSUCCESSFUL;
6640
RtlRbRemoveNode(tree, &PLDR_DATA_TABLE_ENTRY_WIN8(DataTableEntry)->BaseAddressIndexNode);
6741
return STATUS_SUCCESS;

MemoryModule/BaseAddressIndex.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3-
PRTL_RB_TREE NTAPI RtlFindLdrpModuleBaseAddressIndex();
3+
NTSTATUS NTAPI RtlInsertModuleBaseAddressIndexNode(
4+
_In_ PLDR_DATA_TABLE_ENTRY DataTableEntry,
5+
_In_ PVOID BaseAddress
6+
);
47

5-
NTSTATUS NTAPI RtlInsertModuleBaseAddressIndexNode(IN PLDR_DATA_TABLE_ENTRY DataTableEntry, IN PVOID BaseAddress);
6-
7-
NTSTATUS NTAPI RtlRemoveModuleBaseAddressIndexNode(IN PLDR_DATA_TABLE_ENTRY DataTableEntry);
8+
NTSTATUS NTAPI RtlRemoveModuleBaseAddressIndexNode(_In_ PLDR_DATA_TABLE_ENTRY DataTableEntry);

0 commit comments

Comments
 (0)