Author | Message | Time |
---|---|---|
FrostWraith | I am having a strange problem. For a fun little test, I decided to see if I could get some minesweeper info out of memory. For some reason though, ReadProcessMemory() fails every time. I am not sure why because with this same code I was previously reading some memory from other processes. I have tried opening the process with PROCESS_ALL_ACCESS but to no avail. Can anyone point me in the right direction? Also, point out any bad code practices. [code]#include <stdio.h> #include <windows.h> typedef unsigned long DWORD; int main(void) { HWND hWnd = FindWindow(NULL, "Minesweeper"); HWND pHandle; DWORD PID; unsigned long lpWidth = 0x1005334; unsigned long bytesread; unsigned int width; if (hWnd == NULL) { printf("Window not found\n"); return 1; } printf("Window Handle = %x\n", hWnd); GetWindowThreadProcessId(hWnd, &PID); printf("Process ID = %x\n", PID); pHandle = OpenProcess(PROCESS_ALL_ACCESS, 1, PID); printf("Process Handle = %x\n", pHandle); if (pHandle == NULL) { printf("The Process handle could not be retrieved\n"); return 1; } if (ReadProcessMemory(pHandle, &lpWidth, &width, sizeof(width), &bytesread)) { printf("Width = %d\n", width); } else { printf("ReadProcessMemory Failed\n"); } return 0; }[/code] | April 11, 2008, 12:47 AM |
iago | What's getlasterror()? | April 11, 2008, 2:29 AM |
FrostWraith | 299 Strange thing though. I changed the parts to be read size to 0 and I got a value returned. I'm going to have to see if it is what I'm looking for. As a matter of fact, any address I read I get 0x4025CB as a result, why is this. The program that i downloaded reads from this address and gets the value of 9 (or whatever the width is). SOLVED: [code] const void *lpWidth = (void *)0x1005334; ReadProcessMemory(pHandle, lpWidth, &width, sizeof(width), &bytesread) [/code] | April 11, 2008, 3:16 AM |
TheMinistered | well i have some similar code, but i call virtualprotectex because i'm patching stuffs... but anyways you can find the code here: http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=52494&lngWId=1 note: this code only works on minesweeper 5.1 oh and sorry that its overly oop and in vb6 ;p | April 16, 2008, 9:05 PM |