-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadWrite.cpp
35 lines (26 loc) · 961 Bytes
/
readWrite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "readWrite.h"
DWORD readMem(HANDLE processHandle, LPCVOID address) {
DWORD buffer = 0;
SIZE_T numberOfBytesToRead = sizeof(buffer);
SIZE_T numberOfBytesActuallyRead;
BOOL error = ReadProcessMemory(processHandle, address, &buffer,
numberOfBytesToRead, &numberOfBytesActuallyRead);
if (!error || numberOfBytesActuallyRead != numberOfBytesToRead) {
std::cout << "readMem GetLastError: " << GetLastError() << std::endl;
std::cout << buffer << std::endl;
std::cout << "error reading memory" << std::endl;
}
#ifdef DEBUG
std::cout << "buffer: 0x" << std::hex << buffer << std::endl;
#endif
return buffer;
}
BOOL writeMem(HANDLE handle, LPVOID address, int writeData) {
BOOL error = WriteProcessMemory(handle, address, &writeData,
sizeof(writeData), 0);
if (!error) {
std::cout << "writeMem GetLastError: " << GetLastError() << std::endl;
std::cout << "address: 0x" << std::hex << address << std::endl;
}
return error;
}