diff options
Diffstat (limited to '')
-rw-r--r-- | CPP/Windows/ProcessUtils.h | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/CPP/Windows/ProcessUtils.h b/CPP/Windows/ProcessUtils.h index e46f9ab..b1fce3a 100644 --- a/CPP/Windows/ProcessUtils.h +++ b/CPP/Windows/ProcessUtils.h | |||
@@ -1,9 +1,41 @@ | |||
1 | // Windows/ProcessUtils.h | 1 | // Windows/ProcessUtils.h |
2 | 2 | ||
3 | #ifndef __WINDOWS_PROCESS_UTILS_H | 3 | #ifndef ZIP7_INC_WINDOWS_PROCESS_UTILS_H |
4 | #define __WINDOWS_PROCESS_UTILS_H | 4 | #define ZIP7_INC_WINDOWS_PROCESS_UTILS_H |
5 | 5 | ||
6 | #include "../Common/MyWindows.h" | ||
7 | |||
8 | #ifndef Z7_OLD_WIN_SDK | ||
9 | |||
10 | #if defined(__MINGW32__) || defined(__MINGW64__) | ||
11 | #include <psapi.h> | ||
12 | #else | ||
6 | #include <Psapi.h> | 13 | #include <Psapi.h> |
14 | #endif | ||
15 | |||
16 | #else // Z7_OLD_WIN_SDK | ||
17 | |||
18 | typedef struct _MODULEINFO { | ||
19 | LPVOID lpBaseOfDll; | ||
20 | DWORD SizeOfImage; | ||
21 | LPVOID EntryPoint; | ||
22 | } MODULEINFO, *LPMODULEINFO; | ||
23 | |||
24 | typedef struct _PROCESS_MEMORY_COUNTERS { | ||
25 | DWORD cb; | ||
26 | DWORD PageFaultCount; | ||
27 | SIZE_T PeakWorkingSetSize; | ||
28 | SIZE_T WorkingSetSize; | ||
29 | SIZE_T QuotaPeakPagedPoolUsage; | ||
30 | SIZE_T QuotaPagedPoolUsage; | ||
31 | SIZE_T QuotaPeakNonPagedPoolUsage; | ||
32 | SIZE_T QuotaNonPagedPoolUsage; | ||
33 | SIZE_T PagefileUsage; | ||
34 | SIZE_T PeakPagefileUsage; | ||
35 | } PROCESS_MEMORY_COUNTERS; | ||
36 | typedef PROCESS_MEMORY_COUNTERS *PPROCESS_MEMORY_COUNTERS; | ||
37 | |||
38 | #endif // Z7_OLD_WIN_SDK | ||
7 | 39 | ||
8 | #include "../Common/MyString.h" | 40 | #include "../Common/MyString.h" |
9 | 41 | ||
@@ -18,7 +50,7 @@ public: | |||
18 | bool Open(DWORD desiredAccess, bool inheritHandle, DWORD processId) | 50 | bool Open(DWORD desiredAccess, bool inheritHandle, DWORD processId) |
19 | { | 51 | { |
20 | _handle = ::OpenProcess(desiredAccess, inheritHandle, processId); | 52 | _handle = ::OpenProcess(desiredAccess, inheritHandle, processId); |
21 | return (_handle != 0); | 53 | return (_handle != NULL); |
22 | } | 54 | } |
23 | 55 | ||
24 | #ifndef UNDER_CE | 56 | #ifndef UNDER_CE |
@@ -43,9 +75,14 @@ public: | |||
43 | { return BOOLToBool(::ReadProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesRead)); } | 75 | { return BOOLToBool(::ReadProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesRead)); } |
44 | 76 | ||
45 | bool WriteMemory(LPVOID baseAddress, LPCVOID buffer, SIZE_T size, SIZE_T* numberOfBytesWritten) | 77 | bool WriteMemory(LPVOID baseAddress, LPCVOID buffer, SIZE_T size, SIZE_T* numberOfBytesWritten) |
46 | { return BOOLToBool(::WriteProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesWritten)); } | 78 | { return BOOLToBool(::WriteProcessMemory(_handle, baseAddress, |
47 | 79 | #ifdef Z7_OLD_WIN_SDK | |
48 | bool FlushInstructionCache(LPCVOID baseAddress = 0, SIZE_T size = 0) | 80 | (LPVOID) |
81 | #endif | ||
82 | buffer, | ||
83 | size, numberOfBytesWritten)); } | ||
84 | |||
85 | bool FlushInstructionCache(LPCVOID baseAddress = NULL, SIZE_T size = 0) | ||
49 | { return BOOLToBool(::FlushInstructionCache(_handle, baseAddress, size)); } | 86 | { return BOOLToBool(::FlushInstructionCache(_handle, baseAddress, size)); } |
50 | 87 | ||
51 | LPVOID VirtualAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect) | 88 | LPVOID VirtualAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect) |
@@ -56,17 +93,17 @@ public: | |||
56 | 93 | ||
57 | // Process Status API (PSAPI) | 94 | // Process Status API (PSAPI) |
58 | 95 | ||
96 | /* | ||
59 | bool EmptyWorkingSet() | 97 | bool EmptyWorkingSet() |
60 | { return BOOLToBool(::EmptyWorkingSet(_handle)); } | 98 | { return BOOLToBool(::EmptyWorkingSet(_handle)); } |
61 | bool EnumModules(HMODULE *hModules, DWORD arraySizeInBytes, LPDWORD receivedBytes) | 99 | bool EnumModules(HMODULE *hModules, DWORD arraySizeInBytes, LPDWORD receivedBytes) |
62 | { return BOOLToBool(::EnumProcessModules(_handle, hModules, arraySizeInBytes, receivedBytes)); } | 100 | { return BOOLToBool(::EnumProcessModules(_handle, hModules, arraySizeInBytes, receivedBytes)); } |
63 | |||
64 | DWORD MyGetModuleBaseName(HMODULE hModule, LPTSTR baseName, DWORD size) | 101 | DWORD MyGetModuleBaseName(HMODULE hModule, LPTSTR baseName, DWORD size) |
65 | { return ::GetModuleBaseName(_handle, hModule, baseName, size); } | 102 | { return ::GetModuleBaseName(_handle, hModule, baseName, size); } |
66 | bool MyGetModuleBaseName(HMODULE hModule, CSysString &name) | 103 | bool MyGetModuleBaseName(HMODULE hModule, CSysString &name) |
67 | { | 104 | { |
68 | const unsigned len = MAX_PATH + 100; | 105 | const unsigned len = MAX_PATH + 100; |
69 | DWORD resultLen = MyGetModuleBaseName(hModule, name.GetBuf(len), len); | 106 | const DWORD resultLen = MyGetModuleBaseName(hModule, name.GetBuf(len), len); |
70 | name.ReleaseBuf_CalcLen(len); | 107 | name.ReleaseBuf_CalcLen(len); |
71 | return (resultLen != 0); | 108 | return (resultLen != 0); |
72 | } | 109 | } |
@@ -76,7 +113,7 @@ public: | |||
76 | bool MyGetModuleFileNameEx(HMODULE hModule, CSysString &name) | 113 | bool MyGetModuleFileNameEx(HMODULE hModule, CSysString &name) |
77 | { | 114 | { |
78 | const unsigned len = MAX_PATH + 100; | 115 | const unsigned len = MAX_PATH + 100; |
79 | DWORD resultLen = MyGetModuleFileNameEx(hModule, name.GetBuf(len), len); | 116 | const DWORD resultLen = MyGetModuleFileNameEx(hModule, name.GetBuf(len), len); |
80 | name.ReleaseBuf_CalcLen(len); | 117 | name.ReleaseBuf_CalcLen(len); |
81 | return (resultLen != 0); | 118 | return (resultLen != 0); |
82 | } | 119 | } |
@@ -85,6 +122,7 @@ public: | |||
85 | { return BOOLToBool(::GetModuleInformation(_handle, hModule, moduleInfo, sizeof(MODULEINFO))); } | 122 | { return BOOLToBool(::GetModuleInformation(_handle, hModule, moduleInfo, sizeof(MODULEINFO))); } |
86 | bool GetMemoryInfo(PPROCESS_MEMORY_COUNTERS memCounters) | 123 | bool GetMemoryInfo(PPROCESS_MEMORY_COUNTERS memCounters) |
87 | { return BOOLToBool(::GetProcessMemoryInfo(_handle, memCounters, sizeof(PROCESS_MEMORY_COUNTERS))); } | 124 | { return BOOLToBool(::GetProcessMemoryInfo(_handle, memCounters, sizeof(PROCESS_MEMORY_COUNTERS))); } |
125 | */ | ||
88 | 126 | ||
89 | #endif | 127 | #endif |
90 | 128 | ||