Jump to content
  • Advertisement
Sign in to follow this  

C++: Pointers to other programs.

This topic is 4759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm building a clan management program for a particular game. This means I'll need to be able to read certain values from the game's memory during runtime. I'll worry about finding the values myself. However, how would I be able to find the range of memory addresses that the program currently has taken up in memory? Also, would I be able to simply make an int pointer point at any part of memory without getting some kind of access exception? I am somewhat of a newb with C++, so if your going to give me code snippets, please comment it thoroughly. Thanks for your time and understanding, FenixRoA

Share this post


Link to post
Share on other sites
Advertisement
You mean you need to read this in-game memory at runtime, but you have to read it from what. From another program? Why exactly? I don't know of any use, but maybe you have a valid one. If you try to use a pointer, you get GPF errors cuz windows won't let you access memory from another program. If it isn't every frame, the only solution I can think of is if you write a file, but if you try to do this each frame or very often, your programs will slow to a crawl.

Share this post


Link to post
Share on other sites
Quote:
Original post by kburkhart84
You mean you need to read this in-game memory at runtime, but you have to read it from what. From another program? Why exactly? I don't know of any use, but maybe you have a valid one. If you try to use a pointer, you get GPF errors cuz windows won't let you access memory from another program. If it isn't every frame, the only solution I can think of is if you write a file, but if you try to do this each frame or very often, your programs will slow to a crawl.



If you want an example: Ultima Online Auto-Map. The makers of Ultima Online gave it their blessing, and no UO player I know can do without it. How they manage to read Ultima Online's memory, I don't know. But apparently, they can, and to great effect.

Share this post


Link to post
Share on other sites
On Windows you can use functions like OpenProcess, ReadProcessMemory etc. to hack into the address space of another application, but where the targeted data is is totaly up to you to figure out. In general these things aren't easy.

Edit: here's a little app I wrote a while ago which reads the currently playing song from WinAmp:

#include <windows.h>
#include <iostream>
#include <string>

// WinAmp messages
#define IPC_GETLISTPOS 125
#define IPC_GETPLAYLISTFILE 212

struct s_winampinfo {
unsigned int index;
std::string filename;
};


s_winampinfo GetWinAmpInfo()
{
// Get info from winamp
HWND _hwnd = FindWindow("Winamp v1.x", NULL);
if(_hwnd==NULL) _hwnd=FindWindow("Winamp 3.x",NULL);
int _index = SendMessage(_hwnd, WM_USER, 0, IPC_GETLISTPOS);
char* _base = (char*)SendMessage(_hwnd, WM_USER, _index, IPC_GETPLAYLISTFILE);

// Get filename from winamp memory space
unsigned long _hwnd_tmp;
char* _buffer = new char[1024];
unsigned long _numread;
GetWindowThreadProcessId(_hwnd, &_hwnd_tmp);
HANDLE _hwnd2 = OpenProcess(PROCESS_ALL_ACCESS, false, _hwnd_tmp);
ReadProcessMemory(_hwnd2, _base, &_buffer[0], 1024, &_numread);

// Fill result struct
s_winampinfo _result;
_result.index = _index + 1;
_result.filename = _buffer;

// Cleanup
CloseHandle(_hwnd2);
delete[] _buffer;
return _result;
}

int main()
{
std::string _urlstr;
s_winampinfo& _info = GetWinAmpInfo();
std::cout << "Currently playing: (" << _info.index << ") " << _info.filename << std::endl;
return 0;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!