Hello, is there a function that will allow me to pass through the process name and variable address, and return the value of the address?
Here is my current code:
Code:
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
|
int ReadVariable(LPCSTR pName, LPVOID address){
int point1;
char value[255];
SIZE_T stBytes = 0;
HWND hwnd;
HANDLE phandle;
DWORD pid;
hwnd = FindWindow(NULL, pName);
if (hwnd != 0) {
GetWindowThreadProcessId(hwnd, &pid);
phandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, pid);
} else {
cout << pName << " is not open.";
cout << "Press ENTER to exit." << endl;
cin.get();
CloseHandle(phandle);
return 0;
}
if (phandle != 0) {
cout << "The pointer is " << address << endl; //Print the pointer
ReadProcessMemory(phandle, address, &point1, 4, &stBytes); //Get the address that the pointer is pointing at
cout << "The pointer is pointing at " << point1 << " (DEC)" << endl; //Print the address that the pointer is pointing at
ReadProcessMemory(phandle, (LPVOID)point1, &value, 6, &stBytes); //Get the value that is in the address pointed by the pointer
cout << "The value in the non-static address is " << (char*)value << endl << endl; //Print the value
cout << "Press ENTER to exit." << endl;
cin.get();
} else {
cout << "Couldn't get a handle";
cin.get();
}
CloseHandle(phandle);
}
|
The current code outputs random characters when I pass through an address.
Here's the output of some variables when I use breakpoints.
&point1: 0x0026f730 {-253001723} int *
&stBytes: 0x0026f728 {6} unsigned long *
&value: 0x0026f734 {0 '\0', 0 '\0', 0 '\0', 1 '\x1', 0 '\0', 0 '\0', 38 '&', 0 '\0', 80 'P', 78 'N', 17 '\x11', ...} char[255] *
address: 0x0026f88c void *
phandle: 0x000014c0 void *
point1: -253001723 int
value: 0x0026f734 "" char[255]
Thanks.
|