-
Reading process memory
Hi, I was trying to play around with some code and to see how it work, but didnt seem to get it to work right. Any ideas on how to use "ReadProcessMemory"? Also I have a question on it, when it does read the location of the memory, does it see whats there too? Like in my other programe it has a int set 50, can it see that 50 when it reads it?
Code:
//#include things and using namespace std;
int main (){
bool pQuit = false;
DWORD process_id;
HANDLE hProcess;
HANDLE hToken;
int hp = 0xXXXXX;
int patch_int;
while( false == pQuit )
{
Sleep(6000);
hProcess=OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
bool ReadProcessMemory(hProcess, hp, &patch_int, 4, NULL);
cout<<" " <<patch_int<<endl;
}
}
-
You're opening the process each time thru the loop and loosing the previous handle. You only need to open it once before the loop and close it with CloseHandle after you've finnished.
And you're not setting process ID to anything.
-
Ok, thats a start on it, i'll change some around.
-
Ok I did something differnt but I get his error at the end of me code, not sure how to fixs it
Code:
#include "tt.h"
using namespace std;
int main (void){
HANDLE hProcess = GetCurrentProcess ();
bool pQuit = false;
while( false == pQuit )
{
Sleep(6000);
bool ReadProcessMemory (hProcess,
0x3CE418,
512,
10,
NULL);
cout<<" " <<ReadProcessMemory<<endl;
}
}
error is : initializer expression list treated as compound expression
-
Code:
cout<<" " <<ReadProcessMemory<<endl;
Perhaps what you wanted to do was
Code:
cout<<"ReadProcessMemory" <<endl;
-
Will, they work either or, nothing wrong with that. Its that error I get whats wrong, lol, I dont get what it means mostly.
Thanks for trying to help Quantum1024, still looking on how to use this code more, its always fun to try out new things:)
-
And remove the bool before ReadProcessMemory, that is what's causing the error.
-
LOL, just got a few more eerors with that. invalid conversion from `int' to `const void*' and initializing argument 2 of `BOOL ReadProcessMemory(void*, const void*, void*, DWORD, DWORD*)' and initializing argument 3 of `BOOL ReadProcessMemory(void*, const void*, void*, DWORD, DWORD*)'
I think I got what thes error mean, I got school now, i'll tell if the work when I get back.
-
oK, hmm, didnt seem to work. I get theses errors, not sure what they fully mean:
*invalid conversion from `int' to `const void*'
*initializing argument 2 of `BOOL ReadProcessMemory(void*, const void*, void*, DWORD, DWORD*)'
*initializing argument 3 of `BOOL ReadProcessMemory(void*, const void*, void*, DWORD, DWORD*)'
Any ideas?
-
you need to look at each argument of ReadProcessMemory and make sure you are pasing the correct type
Code:
BOOL ReadProcessMemory(
HANDLE hProcess,
LPCVOID lpBaseAddress,
LPVOID lpBuffer,
SIZE_T nSize,
SIZE_T* lpNumberOfBytesRead
);
The second argument is the addres so if you are using a number like 0x... then that must be cast to a pointer type (void *)0x.....
The third argument is a pointer to a buffer that recieves the data, you've set it to 512 which is an int type not a pointer.
The forth argument is the size, if you want to read 10 bytes then that's correct
The fifth and final argument is a pointer to a SIZE_T type but this is ok to be NULL.
So for example
Code:
unsigned char Buffer[10];
ReadProcessMemory(hProcess, (void *)0x40100, Buffer, 10, NULL);
-
I'm a bit confused why you would need ReadProcessMemory if you can't even solve these relatively easy syntax errors.
-
1st off, I never seen theses errors, kinda hard to say what they are telling me, and thats a kinda a good things, I can learn off new code and be a better programer. I got most of the code right at less, but not some, so I have to be getting it for the most part no? Sorry tho>< I do kinds suck at c++ lol /sigh forgive.
Thanks Quantum1024, that help alot, I see what it means now. Sorrry for asking so much>< I just never seen the code befor, so I couldnt really go on much from my past work.
And may I say somethingO.o; theres a error on this website I think, I not seening any new msg. after a few of them.