Forum

> > Off Topic > Pointers to physical memory in C?
Forums overviewOff Topic overviewLog in to reply

English Pointers to physical memory in C?

2 replies
To the start Previous 1 Next To the start

old Pointers to physical memory in C?

DannyDeth
User Off Offline

Quote
Hi all,

Recently I have decided enough was enough and started re learning some stuff about the C programming language, one of my biggest issues is whether it is possible to point to physical memory in an OS that gives programs virtual memory to work with ( such as Windows ).

Any answers are much appreciated,
DannyDeth.

old Re: Pointers to physical memory in C?

Flacko
User Off Offline

Quote
I'm sure the library you will have to use will be system-dependant.
I only know about accessing a program's memory using WINAPI. I hate, WINAPI, btw.

Once you get the process handle, you can access it's memory by declaring a void pointer and calling read process memory.
This is how you read CS2D's memory to get the currently connected ip:
1
2
3
4
5
6
7
8
9
10
11
12
13
HANDLE cs2d_exe=0;

//I'm assuming you have some code to get the handle to CS2D or atleast it's PID (and then convert it to handle)

unsigned char arr[4]; //Declare an array of chars

memset(arr,0,4); //Fill with 0s

void* ptr = (void*)0x0063297c;//The address we want to read

ReadProcessMemory(cs2d_exe,ptr, arr, 4, 0); //Read 4bytes from the address, store in arr

printf("Connecting to: %i.%i.%i.%i\n",arr[3],arr[2],arr[1],arr[0]); //Output
edited 2×, last 23.03.11 06:43:50 am

old Re: Pointers to physical memory in C?

DannyDeth
User Off Offline

Quote
Flacko has written
I hate, WINAPI, btw.

So do I and majority of the cross-platform style developers around the world. Infact I was hoping I wouldn't have to use an API's, but I guess I have too.
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview