| View previous topic :: View next topic |
| Author |
Message |
0_00_0 Cheater
Reputation: 0
Joined: 17 Feb 2007 Posts: 30
|
Posted: Sat Dec 20, 2008 5:02 am Post subject: C++ ReadProcessMemory problem |
|
|
So I tried to read the static memory address for player X address in C++ and it didnt work. I have cheat engine open with the same memory address being viewed with the correct X location.
The current output is just 2. always 2. Im running vista and there is always problems with my permissions. I thought OpenProcess as ACCESS_ALL and running as administrator would do the trick but I guess not.
heres my code
| Code: | #include <cstdlib>
#include <iostream>
#include <Windows.h>
//memory addresses
DWORD PLAYER_X = 0x012E1B7C;
int main(int argc, char *argv[])
{
long x;
unsigned long pID;
HWND hWnd = FindWindow(NULL, "World of Warcraft");
GetWindowThreadProcessId(hWnd, &pID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
ReadProcessMemory(hProcess, (LPVOID) PLAYER_X, &x, sizeof(x), NULL);
std::cout<< x << "\n";
system("PAUSE");
return EXIT_SUCCESS;
} |
_________________
C++
autoIT
Java PrOgRaMmEr |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Dec 20, 2008 5:15 am Post subject: |
|
|
Is it 0 now?
Also make sure your functions success and if they fail, do ::GetLastError();
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sat Dec 20, 2008 5:49 am Post subject: |
|
|
| Code: | #include <cstdlib>
#include <iostream>
#include <Windows.h>
//memory addresses
DWORD PLAYER_X = 0x012E1B7C;
int main(int argc, char *argv[])
{
int x = 0;
unsigned long pID;
HWND hWnd = FindWindow(NULL, "World of Warcraft");
// Better use ClassName
GetWindowThreadProcessId(hWnd, &pID);
HANDLE hProcess = OpenProcess(PROCESS_VM_READ, FALSE, pID);
// I think PROCESS_VM_READ is enough
ReadProcessMemory(hProcess, (LPVOID)PLAYER_X, &x, 4, NULL);
// I don't know why you took sizeof(x), the 4th parameter is the NumberOfBytesTORead, for example: 4.
std::cout<< x << "\n";
system("PAUSE");
return EXIT_SUCCESS;
} |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Sat Dec 20, 2008 8:53 am Post subject: |
|
|
| system("PAUSE")?, delete this crap.
|
|
| Back to top |
|
 |
0_00_0 Cheater
Reputation: 0
Joined: 17 Feb 2007 Posts: 30
|
Posted: Sat Dec 20, 2008 11:41 am Post subject: |
|
|
| Jani wrote: | Is it 0 now?
Also make sure your functions success and if they fail, do ::GetLastError(); |
Ah yes very smart. It does remain at zero when I initialize it to zero.
| noz3001 wrote: | | http://msdn.microsoft.com/en-us/library/aa446619(VS.85).aspx |
I am 99.9% sure this is my problem. I have to give myself privileges before I can read the memory. Im just really foggy how to use the privilege tokens.
_________________
C++
autoIT
Java PrOgRaMmEr |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Dec 20, 2008 12:14 pm Post subject: |
|
|
Quick snippet I wrote for my Engine a couple days ago, if you want to use PROCESS_ALL_ACCESS.
| Code: | BOOL SetDebugPrivileges()
{
BOOL bRET = FALSE;
TOKEN_PRIVILEGES tp;
HANDLE hToken;
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid))
{
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
if (hToken != INVALID_HANDLE_VALUE)
{
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
tp.PrivilegeCount = 1;
if (AdjustTokenPrivileges(hToken, FALSE, &tp, 0, 0, 0))
bRET = TRUE;
CloseHandle(hToken);
}
}
}
return bRET;
} |
_________________
|
|
| Back to top |
|
 |
0_00_0 Cheater
Reputation: 0
Joined: 17 Feb 2007 Posts: 30
|
Posted: Sat Dec 20, 2008 12:37 pm Post subject: |
|
|
| lurc wrote: | Quick snippet I wrote for my Engine a couple days ago, if you want to use PROCESS_ALL_ACCESS.
|
this worked perfectly. your the best. I was having a little difficulty with the MSDN one. I always hate their examples.
edit:+rep:P
_________________
C++
autoIT
Java PrOgRaMmEr |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Dec 22, 2008 5:51 am Post subject: |
|
|
| ::GetLastError(); would have returned 5, in other words ERROR_ACCESS_DENIED (probably, I'm not 100% sure does it return this when you don't have the proper access rights). -> Problem solved :)
|
|
| Back to top |
|
 |
|