@@ -17,21 +17,21 @@ extern "C" PMMP_GLOBAL_DATA NTAPI GetMmpGlobalDataPtr()
1717
1818PRTL_RB_TREE FindLdrpModuleBaseAddressIndex () {
1919 PRTL_RB_TREE LdrpModuleBaseAddressIndex = nullptr ;
20- PLDR_DATA_TABLE_ENTRY_WIN10 nt10 = decltype (nt10)(MmpGlobalDataPtr->MmpBaseAddressIndex ->NtdllLdrEntry );
20+ PLDR_DATA_TABLE_ENTRY_WIN10 nt10 = reinterpret_cast < decltype (nt10)> (MmpGlobalDataPtr->MmpBaseAddressIndex ->NtdllLdrEntry );
2121 PRTL_BALANCED_NODE node = nullptr ;
2222 if (!nt10 || !RtlIsWindowsVersionOrGreater (6 , 2 , 0 ))return nullptr ;
2323 node = &nt10->BaseAddressIndexNode ;
24- while (node->ParentValue & (~7 )) node = decltype (node)(node->ParentValue & (~7 ));
24+ while (node->ParentValue & (~7 )) node = reinterpret_cast < decltype (node)> (node->ParentValue & (~7 ));
2525
2626 if (!node->Red ) {
2727 BYTE count = 0 ;
2828 PRTL_RB_TREE tmp = nullptr ;
2929 SEARCH_CONTEXT SearchContext{};
30- SearchContext.SearchPattern = ( LPBYTE) &node;
30+ SearchContext.SearchPattern = reinterpret_cast < LPBYTE>( &node) ;
3131 SearchContext.PatternSize = sizeof (size_t );
32- while (NT_SUCCESS (RtlFindMemoryBlockFromModuleSection (( HMODULE) nt10->DllBase , " .data" , &SearchContext))) {
32+ while (NT_SUCCESS (RtlFindMemoryBlockFromModuleSection (static_cast < HMODULE>( nt10->DllBase ) , " .data" , &SearchContext))) {
3333 if (count++)return nullptr ;
34- tmp = ( decltype (tmp)) SearchContext.Result ;
34+ tmp = reinterpret_cast < decltype (tmp)>( SearchContext.Result ) ;
3535 }
3636 if (count && tmp && tmp->Root && tmp->Min ) {
3737 LdrpModuleBaseAddressIndex = tmp;
@@ -68,7 +68,7 @@ PVOID FindLdrpInvertedFunctionTable32() {
6868 PIMAGE_NT_HEADERS NtdllHeaders = RtlImageNtHeader (hNtdll), ModuleHeaders = nullptr ;
6969 _RTL_INVERTED_FUNCTION_TABLE_ENTRY_WIN7_32 entry{};
7070 LPCSTR lpSectionName = " .data" ;
71- SEARCH_CONTEXT SearchContext{ SearchContext.SearchPattern = ( LPBYTE) &entry,SearchContext.PatternSize = sizeof (entry) };
71+ SEARCH_CONTEXT SearchContext{ SearchContext.SearchPattern = reinterpret_cast < LPBYTE>( &entry) ,SearchContext.PatternSize = sizeof (entry) };
7272 PLIST_ENTRY ListHead = &NtCurrentPeb ()->Ldr ->InMemoryOrderModuleList ,
7373 ListEntry = ListHead->Flink ;
7474 PLDR_DATA_TABLE_ENTRY CurEntry = nullptr ;
@@ -82,18 +82,18 @@ PVOID FindLdrpInvertedFunctionTable32() {
8282 CurEntry = CONTAINING_RECORD (ListEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
8383 ListEntry = ListEntry->Flink ;
8484 if (IsModuleUnloaded (CurEntry))continue ; // skip unloaded module
85- if (IsValidMemoryModuleHandle (( HMEMORYMODULE) CurEntry->DllBase ))continue ; // skip our memory module.
85+ if (IsValidMemoryModuleHandle (static_cast < HMEMORYMODULE>( CurEntry->DllBase ) ))continue ; // skip our memory module.
8686 if (CurEntry->DllBase == hNtdll && Offset == 0x20 )continue ; // Win10 skip first entry, if the base of ntdll is smallest.
87- hModule = ( HMODULE) (hModule ? min (hModule, CurEntry->DllBase ) : CurEntry->DllBase );
87+ hModule = static_cast < HMODULE> (hModule ? min (hModule, CurEntry->DllBase ) : CurEntry->DllBase );
8888 }
8989 ModuleHeaders = RtlImageNtHeader (hModule);
9090 if (!hModule || !ModuleHeaders || !hNtdll || !NtdllHeaders)return nullptr ;
9191
9292 RtlCaptureImageExceptionValues (hModule, &SEHTable, &SEHCount);
93- entry = { RtlEncodeSystemPointer (( PVOID) SEHTable),( DWORD) hModule,ModuleHeaders->OptionalHeader .SizeOfImage ,( PVOID) SEHCount };
93+ entry = { RtlEncodeSystemPointer (reinterpret_cast < PVOID>( SEHTable)), reinterpret_cast < DWORD>( hModule) ,ModuleHeaders->OptionalHeader .SizeOfImage ,reinterpret_cast < PVOID>( SEHCount) };
9494
9595 while (NT_SUCCESS (RtlFindMemoryBlockFromModuleSection (hNtdll, lpSectionName, &SearchContext))) {
96- PRTL_INVERTED_FUNCTION_TABLE_WIN7_32 tab = decltype (tab)(SearchContext.Result - Offset);
96+ PRTL_INVERTED_FUNCTION_TABLE_WIN7_32 tab = reinterpret_cast < decltype (tab)> (SearchContext.Result - Offset);
9797
9898 // Note: Same memory layout for RTL_INVERTED_FUNCTION_TABLE_ENTRY in Windows 10 x86 and x64.
9999 if (RtlIsWindowsVersionOrGreater (6 , 2 , 0 ) && tab->MaxCount == 0x200 && !tab->NextEntrySEHandlerTableEncoded ) return tab;
@@ -123,7 +123,7 @@ PVOID FindLdrpInvertedFunctionTable64() {
123123 _RTL_INVERTED_FUNCTION_TABLE_ENTRY_64 entry{};
124124 LPCSTR lpSectionName = " .data" ;
125125 PIMAGE_DATA_DIRECTORY dir = nullptr ;
126- SEARCH_CONTEXT SearchContext{ SearchContext.SearchPattern = ( LPBYTE) &entry,SearchContext.PatternSize = sizeof (entry) };
126+ SEARCH_CONTEXT SearchContext{ SearchContext.SearchPattern = reinterpret_cast < LPBYTE>( &entry) ,SearchContext.PatternSize = sizeof (entry) };
127127
128128 // Windows 8
129129 if (RtlVerifyVersion (6 , 2 , 0 , RTL_VERIFY_FLAGS_MAJOR_VERSION | RTL_VERIFY_FLAGS_MINOR_VERSION)) {
@@ -145,21 +145,21 @@ PVOID FindLdrpInvertedFunctionTable64() {
145145 CurEntry = CONTAINING_RECORD (ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
146146 ListEntry = ListEntry->Flink ;
147147 // Make sure the smallest base address is not our memory module
148- if (IsValidMemoryModuleHandle (( HMEMORYMODULE) CurEntry->DllBase ))continue ;
149- hModule = ( HMODULE) (hModule ? min (hModule, CurEntry->DllBase ) : CurEntry->DllBase );
148+ if (IsValidMemoryModuleHandle (static_cast < HMEMORYMODULE>( CurEntry->DllBase ) ))continue ;
149+ hModule = static_cast < HMODULE> (hModule ? min (hModule, CurEntry->DllBase ) : CurEntry->DllBase );
150150 }
151151 ModuleHeaders = RtlImageNtHeader (hModule);
152152 }
153153
154154 if (!hModule || !ModuleHeaders || !hNtdll || !NtdllHeaders)return nullptr ;
155155 dir = &ModuleHeaders->OptionalHeader .DataDirectory [IMAGE_DIRECTORY_ENTRY_EXCEPTION];
156156 entry = {
157- dir->Size ? decltype (entry.ExceptionDirectory )(( size_t ) hModule + dir->VirtualAddress ) : nullptr ,
158- ( PVOID) hModule, ModuleHeaders->OptionalHeader .SizeOfImage ,dir->Size
157+ dir->Size ? reinterpret_cast < decltype (entry.ExceptionDirectory )>( reinterpret_cast < size_t >( hModule) + dir->VirtualAddress ) : nullptr ,
158+ static_cast < PVOID>( hModule) , ModuleHeaders->OptionalHeader .SizeOfImage ,dir->Size
159159 };
160160
161161 while (NT_SUCCESS (RtlFindMemoryBlockFromModuleSection (hNtdll, lpSectionName, &SearchContext))) {
162- PRTL_INVERTED_FUNCTION_TABLE_64 tab = decltype (tab)(SearchContext.Result - 0x10 );
162+ PRTL_INVERTED_FUNCTION_TABLE_64 tab = reinterpret_cast < decltype (tab)> (SearchContext.Result - 0x10 );
163163 if (RtlIsWindowsVersionOrGreater (6 , 2 , 0 ) && tab->MaxCount == 0x200 && !tab->Overflow ) return tab;
164164 else if (tab->MaxCount == 0x200 && !tab->Epoch ) return tab;
165165 }
@@ -208,7 +208,7 @@ PLIST_ENTRY FindLdrpHashTable() {
208208 PLIST_ENTRY hashEntry = ¤t->HashLinks ;
209209
210210 if (hashEntry->Flink != hashEntry && hashEntry->Flink ->Flink == hashEntry) {
211- PLIST_ENTRY table = &hashEntry->Flink [-( LONG) LdrHashEntry (current->BaseDllName )];
211+ PLIST_ENTRY table = &hashEntry->Flink [-static_cast < LONG>( LdrHashEntry (current->BaseDllName ) )];
212212
213213 return IsValidLdrpHashTable (table) ? table : nullptr ;
214214 }
@@ -327,7 +327,7 @@ VOID InitializeWindowsVersion() {
327327 MmpGlobalDataPtr->NtVersions .MajorVersion = MajorVersion;
328328 MmpGlobalDataPtr->NtVersions .MinorVersion = MinorVersion;
329329 MmpGlobalDataPtr->NtVersions .BuildNumber = BuildNumber;
330- MmpGlobalDataPtr->LdrDataTableEntrySize = ( WORD) LdrDataTableEntrySize;
330+ MmpGlobalDataPtr->LdrDataTableEntrySize = static_cast < WORD>( LdrDataTableEntrySize) ;
331331 }
332332
333333}
@@ -347,15 +347,15 @@ NTSTATUS MmpAllocateGlobalData() {
347347 swprintf_s (
348348 buffer,
349349 L" \\ BaseNamedObjects\\ MMPP*%p" ,
350- ( PVOID)(~( ULONG_PTR) teb->ClientId .UniqueProcess ^ ( ULONG_PTR) teb->ProcessEnvironmentBlock ->ProcessHeap )
350+ reinterpret_cast < PVOID>(~ reinterpret_cast < ULONG_PTR>( teb->ClientId .UniqueProcess ) ^ reinterpret_cast < ULONG_PTR>( teb->ProcessEnvironmentBlock ->ProcessHeap ) )
351351 );
352352 }
353353 else {
354354 swprintf_s (
355355 buffer,
356356 L" \\ Sessions\\ %d\\ BaseNamedObjects\\ MMPP*%p" ,
357357 NtCurrentPeb ()->SessionId ,
358- ( PVOID)(~( ULONG_PTR) teb->ClientId .UniqueProcess ^ ( ULONG_PTR) teb->ProcessEnvironmentBlock ->ProcessHeap )
358+ reinterpret_cast < PVOID>(~ reinterpret_cast < ULONG_PTR>( teb->ClientId .UniqueProcess ) ^ reinterpret_cast < ULONG_PTR>( teb->ProcessEnvironmentBlock ->ProcessHeap ) )
359359 );
360360 }
361361
@@ -377,7 +377,7 @@ NTSTATUS MmpAllocateGlobalData() {
377377 status = NtMapViewOfSection (
378378 hSection,
379379 NtCurrentProcess (),
380- ( PVOID*) &MmpGlobalDataPtr,
380+ reinterpret_cast < PVOID*>( &MmpGlobalDataPtr) ,
381381 0 ,
382382 0 ,
383383 nullptr ,
@@ -416,7 +416,7 @@ NTSTATUS MmpAllocateGlobalData() {
416416 NtClose (hSection);
417417
418418 if (NT_SUCCESS (status)) {
419- MmpGlobalDataPtr = ( PMMP_GLOBAL_DATA)(( PMMP_GLOBAL_DATA) BaseAddress)->BaseAddress ;
419+ MmpGlobalDataPtr = reinterpret_cast < PMMP_GLOBAL_DATA>( static_cast < PMMP_GLOBAL_DATA>( BaseAddress)->BaseAddress ) ;
420420 NtUnmapViewOfSection (NtCurrentProcess (), BaseAddress);
421421
422422 status = STATUS_ALREADY_INITIALIZED;
@@ -466,19 +466,19 @@ NTSTATUS InitializeLockHeld() {
466466 break ;
467467 }
468468
469- MmpGlobalDataPtr->MmpBaseAddressIndex = ( PMMP_BASE_ADDRESS_INDEX_DATA)(( LPBYTE) MmpGlobalDataPtr + sizeof (MMP_GLOBAL_DATA));
470- MmpGlobalDataPtr->MmpInvertedFunctionTable = ( PMMP_INVERTED_FUNCTION_TABLE_DATA)(( LPBYTE) MmpGlobalDataPtr->MmpBaseAddressIndex + sizeof (MMP_BASE_ADDRESS_INDEX_DATA));
471- MmpGlobalDataPtr->MmpLdrEntry = ( PMMP_LDR_ENTRY_DATA)(( LPBYTE) MmpGlobalDataPtr->MmpInvertedFunctionTable + sizeof (MMP_INVERTED_FUNCTION_TABLE_DATA));
472- MmpGlobalDataPtr->MmpTls = ( PMMP_TLS_DATA)((LPBYTE) MmpGlobalDataPtr->MmpLdrEntry + sizeof (MMP_LDR_ENTRY_DATA));
473- MmpGlobalDataPtr->MmpDotNet = ( PMMP_DOT_NET_DATA)(( LPBYTE) MmpGlobalDataPtr->MmpTls + sizeof (MMP_TLS_DATA));
474- MmpGlobalDataPtr->MmpFunctions = ( PMMP_FUNCTIONS)(( LPBYTE) MmpGlobalDataPtr->MmpDotNet + sizeof (MMP_DOT_NET_DATA));
475- MmpGlobalDataPtr->MmpIat = ( PMMP_IAT_DATA)(( LPBYTE) MmpGlobalDataPtr->MmpFunctions + sizeof (MMP_FUNCTIONS));
469+ MmpGlobalDataPtr->MmpBaseAddressIndex = reinterpret_cast < PMMP_BASE_ADDRESS_INDEX_DATA>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr) + sizeof (MMP_GLOBAL_DATA));
470+ MmpGlobalDataPtr->MmpInvertedFunctionTable = reinterpret_cast < PMMP_INVERTED_FUNCTION_TABLE_DATA>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr->MmpBaseAddressIndex ) + sizeof (MMP_BASE_ADDRESS_INDEX_DATA));
471+ MmpGlobalDataPtr->MmpLdrEntry = reinterpret_cast < PMMP_LDR_ENTRY_DATA>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr->MmpInvertedFunctionTable ) + sizeof (MMP_INVERTED_FUNCTION_TABLE_DATA));
472+ MmpGlobalDataPtr->MmpTls = reinterpret_cast < PMMP_TLS_DATA>( reinterpret_cast <PBYTE>( MmpGlobalDataPtr->MmpLdrEntry ) + sizeof (MMP_LDR_ENTRY_DATA));
473+ MmpGlobalDataPtr->MmpDotNet = reinterpret_cast < PMMP_DOT_NET_DATA>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr->MmpTls ) + sizeof (MMP_TLS_DATA));
474+ MmpGlobalDataPtr->MmpFunctions = reinterpret_cast < PMMP_FUNCTIONS>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr->MmpDotNet ) + sizeof (MMP_DOT_NET_DATA));
475+ MmpGlobalDataPtr->MmpIat = reinterpret_cast < PMMP_IAT_DATA>( reinterpret_cast < LPBYTE>( MmpGlobalDataPtr->MmpFunctions ) + sizeof (MMP_FUNCTIONS));
476476
477477 PLDR_DATA_TABLE_ENTRY pNtdllEntry = RtlFindLdrTableEntryByBaseName (L" ntdll.dll" );
478478 MmpGlobalDataPtr->MmpBaseAddressIndex ->NtdllLdrEntry = pNtdllEntry;
479479 MmpGlobalDataPtr->MmpBaseAddressIndex ->LdrpModuleBaseAddressIndex = FindLdrpModuleBaseAddressIndex ();
480- MmpGlobalDataPtr->MmpBaseAddressIndex ->_RtlRbInsertNodeEx = GetProcAddress (( HMODULE) pNtdllEntry->DllBase , " RtlRbInsertNodeEx" );
481- MmpGlobalDataPtr->MmpBaseAddressIndex ->_RtlRbRemoveNode = GetProcAddress (( HMODULE) pNtdllEntry->DllBase , " RtlRbRemoveNode" );
480+ MmpGlobalDataPtr->MmpBaseAddressIndex ->_RtlRbInsertNodeEx = GetProcAddress (static_cast < HMODULE>( pNtdllEntry->DllBase ) , " RtlRbInsertNodeEx" );
481+ MmpGlobalDataPtr->MmpBaseAddressIndex ->_RtlRbRemoveNode = GetProcAddress (static_cast < HMODULE>( pNtdllEntry->DllBase ) , " RtlRbRemoveNode" );
482482
483483 MmpGlobalDataPtr->MmpLdrEntry ->LdrpHashTable = FindLdrpHashTable ();
484484
0 commit comments