C++: Pointers to other programs.

Started by
4 comments, last by Prototype 18 years, 11 months ago
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
Advertisement
Windows uses virtual memory pointers that are not valid across programs.

Though, this might help.
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.


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.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
I'd like to know how it is done. I DO accept that even windows (HAHAHA) can be outdone in it's own territory, but I still want to see how.


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 212struct 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;}

This topic is closed to new replies.

Advertisement