Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ ReadProcessMemory with pointers?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Tue Nov 30, 2010 11:59 am    Post subject: C++ ReadProcessMemory with pointers? Reply with quote

Hi!

I'm a beginner with C++ language. Now I'm trying to code a program that checks 6 characters that are at a non-static adress which has pointer.

Here is the info that is known:
The address of the pointer: 0x005F2D24
Window: xXx

I want to get 6 characters from the non-static address. Example: A string of numbers that is "567834" (DEC).

I have tried this:

Code:
#include <windows.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    LONG pointer1 = 0x005F2D24;
    string pointer1_p = "0x005F2D24";
    HWND hwnd;
    HANDLE phandle;
    DWORD pid;
    string point1;
    SIZE_T stBytes = 0;

    hwnd = FindWindow(NULL, "xXx");
    if (hwnd != 0) {
        GetWindowThreadProcessId(hwnd, &pid);
        phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
    } else {
        cout << "xXx is not opened.";
        cin.get();
        return 0;
    }

    if (phandle != 0) {
        ReadProcessMemory(phandle, (LPVOID)pointer1, &point1, 4, &stBytes);
        cout << "Pointer 1: " + pointer1_p << endl;
        cout << "Pointer 1 points to " + point1;
        cin.get();
    } else {
        cout << "Couldn't get a handle";
        cin.get();
    }
}


The program crashes as it tries to cout point1. Why is this? I'm using DEV-C++.

Could someone please finish my code so it gives me 6 characters that are at the pointed, non-static address?

Thanks in advance!
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Nov 30, 2010 2:14 pm    Post subject: Reply with quote

Don't use dev c++, it's hideously outdated. Just get visual studio. it has a free version and is pretty much the best you can get.



Actually, I'm surprised you crash

Code:
cout << "Pointer 1: " + pointer1_p << endl;
cout << "Pointer 1 points to " + point1;


because this probably shouldn't compile in the first place
Back to top
View user's profile Send private message
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Tue Nov 30, 2010 2:39 pm    Post subject: Reply with quote

Here is my new code but it still gives me the wrong address that the pointer should be pointing at (and of course a wrong value):
Code:
#include <windows.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    char* pointer1_p = "0x005F2D24";
    HWND hwnd;
    HANDLE phandle;
    DWORD pid;
    char* point1[4];
    char* value[6];
    SIZE_T stBytes = 0;
    /* Get window */
    hwnd = FindWindow(NULL, "xXx");
    if (hwnd != 0) {
        GetWindowThreadProcessId(hwnd, &pid);
        phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
    } else {
        cout << "xXx is not opened.";
        cin.get();
        return 0;
    }
   
    if (phandle != 0) {
        cout << pointer1_p << endl; //Print the pointer
        ReadProcessMemory(phandle, (LPCVOID)pointer1_p, &point1, 4, &stBytes); //Get the address that the pointer is pointing at
        cout << point1 << 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 << value << endl; //Print the value
        cin.get();
    } else {
        cout << "Couldn't get a handle";
        cin.get();
    }
}
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Nov 30, 2010 2:50 pm    Post subject: Reply with quote

the second argument you are trying to pass for the first ReadProcessMemory is not what you think it is.

Code:
char* pointer1_p = "0x005F2D24";


can you figure out what is wrong with this?
Back to top
View user's profile Send private message
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Tue Nov 30, 2010 2:54 pm    Post subject: Reply with quote

slovach wrote:
the second argument you are trying to pass for the first ReadProcessMemory is not what you think it is.

Code:
char* pointer1_p = "0x005F2D24";


can you figure out what is wrong with this?


Should it be
Code:
int pointer1_p = 0x005F2D24;

?

EDIT: Got it working! Now it prints the correct number (DEC):

Code:
#include <windows.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int point1;
    char* value[4];
    SIZE_T stBytes = 0;
   
    HWND hwnd;
    HANDLE phandle;
    DWORD pid;
   
    hwnd = FindWindow(NULL, "xXx");
    if (hwnd != 0) {
        GetWindowThreadProcessId(hwnd, &pid);
        phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
    } else {
        cout << "xXx is not opened.";
        cin.get();
        return 0;
    }
   
    if (phandle != 0) {
        cout << "The pointer is 0x005F2D24" << endl; //Print the pointer
        ReadProcessMemory(phandle, (LPVOID)0x005F2D24, &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();
    }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites