aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/MemoryLock.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/MemoryLock.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/CPP/Windows/MemoryLock.cpp b/CPP/Windows/MemoryLock.cpp
index 24866b1..0bd7504 100644
--- a/CPP/Windows/MemoryLock.cpp
+++ b/CPP/Windows/MemoryLock.cpp
@@ -21,7 +21,10 @@ typedef BOOL (WINAPI * Func_LookupPrivilegeValue)(LPCTSTR lpSystemName, LPCTSTR
21typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges, 21typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges,
22 PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength); 22 PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength);
23} 23}
24#define GET_PROC_ADDR(fff, name) Func_ ## fff my_ ## fff = (Func_ ## fff) (void(*)()) GetProcAddress(hModule, name) 24
25#define GET_PROC_ADDR(fff, name) \
26 const Func_ ## fff my_ ## fff = Z7_GET_PROC_ADDRESS( \
27 Func_ ## fff, hModule, name);
25#endif 28#endif
26 29
27bool EnablePrivilege(LPCTSTR privilegeName, bool enable) 30bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
@@ -30,13 +33,19 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
30 33
31 #ifndef _UNICODE 34 #ifndef _UNICODE
32 35
33 HMODULE hModule = ::LoadLibrary(TEXT("Advapi32.dll")); 36 const HMODULE hModule = ::LoadLibrary(TEXT("advapi32.dll"));
34 if (hModule == NULL) 37 if (!hModule)
35 return false; 38 return false;
36 39
37 GET_PROC_ADDR(OpenProcessToken, "OpenProcessToken"); 40 GET_PROC_ADDR(
38 GET_PROC_ADDR(LookupPrivilegeValue, "LookupPrivilegeValueA"); 41 OpenProcessToken,
39 GET_PROC_ADDR(AdjustTokenPrivileges, "AdjustTokenPrivileges"); 42 "OpenProcessToken")
43 GET_PROC_ADDR(
44 LookupPrivilegeValue,
45 "LookupPrivilegeValueA")
46 GET_PROC_ADDR(
47 AdjustTokenPrivileges,
48 "AdjustTokenPrivileges")
40 49
41 if (my_OpenProcessToken && 50 if (my_OpenProcessToken &&
42 my_AdjustTokenPrivileges && 51 my_AdjustTokenPrivileges &&
@@ -85,10 +94,13 @@ typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
85unsigned Get_LargePages_RiskLevel() 94unsigned Get_LargePages_RiskLevel()
86{ 95{
87 OSVERSIONINFOEXW vi; 96 OSVERSIONINFOEXW vi;
88 HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); 97 const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
89 if (!ntdll) 98 if (!ntdll)
90 return 0; 99 return 0;
91 Func_RtlGetVersion func = (Func_RtlGetVersion)(void *)GetProcAddress(ntdll, "RtlGetVersion"); 100 const
101 Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
102 Func_RtlGetVersion, ntdll,
103 "RtlGetVersion");
92 if (!func) 104 if (!func)
93 return 0; 105 return 0;
94 func(&vi); 106 func(&vi);