| 192 | } |
| 193 | |
| 194 | bool ProcessAccessHelp::readMemoryFromProcess(DWORD_PTR address, SIZE_T size, LPVOID dataBuffer) |
| 195 | { |
| 196 | SIZE_T lpNumberOfBytesRead = 0; |
| 197 | DWORD dwProtect = 0; |
| 198 | bool returnValue = false; |
| 199 | |
| 200 | if (!hProcess) |
| 201 | { |
| 202 | #ifdef DEBUG_COMMENTS |
| 203 | Scylla::debugLog.log(L"readMemoryFromProcess :: hProcess == NULL"); |
| 204 | #endif |
| 205 | return returnValue; |
| 206 | } |
| 207 | |
| 208 | if (!ReadProcessMemory(hProcess, (LPVOID)address, dataBuffer, size, &lpNumberOfBytesRead)) |
| 209 | { |
| 210 | #ifdef DEBUG_COMMENTS |
| 211 | Scylla::debugLog.log(L"readMemoryFromProcess :: Error ReadProcessMemory %X %X err: %u", address, size, GetLastError()); |
| 212 | #endif |
| 213 | if (!VirtualProtectEx(hProcess, (LPVOID)address, size, PAGE_READWRITE, &dwProtect)) |
| 214 | { |
| 215 | #ifdef DEBUG_COMMENTS |
| 216 | Scylla::debugLog.log(L"readMemoryFromProcess :: Error VirtualProtectEx %X %X err: %u", address,size, GetLastError()); |
| 217 | #endif |
| 218 | returnValue = false; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | if (!ReadProcessMemory(hProcess, (LPVOID)address, dataBuffer, size, &lpNumberOfBytesRead)) |
| 223 | { |
| 224 | #ifdef DEBUG_COMMENTS |
| 225 | Scylla::debugLog.log(L"readMemoryFromProcess :: Error ReadProcessMemory %X %X err: %u", address, size, GetLastError()); |
| 226 | #endif |
| 227 | returnValue = false; |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | returnValue = true; |
| 232 | } |
| 233 | VirtualProtectEx(hProcess, (LPVOID)address, size, dwProtect, &dwProtect); |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | returnValue = true; |
| 239 | } |
| 240 | |
| 241 | if (returnValue) |
| 242 | { |
| 243 | if (size != lpNumberOfBytesRead) |
| 244 | { |
| 245 | #ifdef DEBUG_COMMENTS |
| 246 | Scylla::debugLog.log(L"readMemoryFromProcess :: Error ReadProcessMemory read %d bytes requested %d bytes", lpNumberOfBytesRead, size); |
| 247 | #endif |
| 248 | returnValue = false; |
| 249 | } |
| 250 | else |
| 251 | { |