Skip to content

Commit ebdfa8e

Browse files
author
Dan Dees
committed
Support DLL build by exporting GetMmpGlobalDataPtr()
- problems with exported global at runtime - wrapping data access in a function allows additional controls
1 parent cea37e0 commit ebdfa8e

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

MemoryModule/Initialize.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
PMMP_GLOBAL_DATA MmpGlobalDataPtr;
77

8+
// DLL compliant access
9+
PMMP_GLOBAL_DATA NTAPI GetMmpGlobalDataPtr()
10+
{
11+
return MmpGlobalDataPtr;
12+
}
13+
814
#if MEMORY_MODULE_IS_PREVIEW(MEMORY_MODULE_MINOR_VERSION)
915
#pragma message("WARNING: You are using a preview version of MemoryModulePP.")
1016
#endif
@@ -621,6 +627,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
621627
}
622628
#else
623629
#ifdef _HAS_AUTO_INITIALIZE
624-
const NTSTATUS Initializer = MmInitialize();
630+
static const NTSTATUS Initializer = MmInitialize();
625631
#endif
626632
#endif

MemoryModule/MemoryModulePP.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ LdrUnloadDllMemoryAndExitThread
1515
LdrQuerySystemMemoryModuleFeatures
1616

1717
MmpGlobalDataPtr
18+
GetMmpGlobalDataPtr

MemoryModule/MmpGlobalData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@ typedef struct _MMP_GLOBAL_DATA {
153153
)
154154

155155
extern PMMP_GLOBAL_DATA MmpGlobalDataPtr;
156+
PMMP_GLOBAL_DATA NTAPI GetMmpGlobalDataPtr() ;

test/test.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#include <string>
55
#pragma comment(lib,"ntdll.lib")
66

7-
static void DisplayStatus() {
7+
static int DisplayStatus() {
8+
const auto gdp = GetMmpGlobalDataPtr();
9+
if ( !gdp ) {
10+
printf("failed GetMmpGlobalDataPtr().\n");
11+
return -1 ;
12+
}
813
printf(
914
"\
1015
MemoryModulePP [Version %d.%d%s]\n\n\t\
@@ -16,17 +21,18 @@ RtlRbRemoveNode = %p\n\n\t\
1621
LdrpInvertedFunctionTable = %p\n\n\t\
1722
LdrpHashTable = %p\n\n\
1823
",
19-
MmpGlobalDataPtr->MajorVersion,
20-
MEMORY_MODULE_GET_MINOR_VERSION(MmpGlobalDataPtr->MinorVersion),
21-
MEMORY_MODULE_IS_PREVIEW(MmpGlobalDataPtr->MinorVersion) ? " Preview" : "",
22-
MmpGlobalDataPtr->MmpFeatures,
23-
MmpGlobalDataPtr->MmpBaseAddressIndex->LdrpModuleBaseAddressIndex,
24-
MmpGlobalDataPtr->MmpBaseAddressIndex->NtdllLdrEntry,
25-
MmpGlobalDataPtr->MmpBaseAddressIndex->_RtlRbInsertNodeEx,
26-
MmpGlobalDataPtr->MmpBaseAddressIndex->_RtlRbRemoveNode,
27-
MmpGlobalDataPtr->MmpInvertedFunctionTable->LdrpInvertedFunctionTable,
28-
MmpGlobalDataPtr->MmpLdrEntry->LdrpHashTable
24+
gdp->MajorVersion,
25+
MEMORY_MODULE_GET_MINOR_VERSION(gdp->MinorVersion),
26+
MEMORY_MODULE_IS_PREVIEW(gdp->MinorVersion) ? " Preview" : "",
27+
gdp->MmpFeatures,
28+
(PVOID)gdp->MmpBaseAddressIndex->LdrpModuleBaseAddressIndex,
29+
(PVOID)gdp->MmpBaseAddressIndex->NtdllLdrEntry,
30+
gdp->MmpBaseAddressIndex->_RtlRbInsertNodeEx,
31+
gdp->MmpBaseAddressIndex->_RtlRbRemoveNode,
32+
gdp->MmpInvertedFunctionTable->LdrpInvertedFunctionTable,
33+
(PVOID)gdp->MmpLdrEntry->LdrpHashTable
2934
);
35+
return 0 ;
3036
}
3137

3238
static PVOID ReadDllFile(const std::string& FilePath) {
@@ -141,7 +147,10 @@ int test(const std::string& dll_path) {
141147

142148
int main(int argc, char* argv[]) {
143149

144-
DisplayStatus();
150+
// check MemoryModulePP initialization
151+
if ( DisplayStatus() ) {
152+
return -1 ;
153+
}
145154

146155
std::string dll_path("a.dll"); // default
147156
dll_path = argc > 1 ? argv[1] : ResolveWithModulePath(dll_path);

0 commit comments

Comments
 (0)