Post: [C++] Read memory
03-12-2011, 10:22 PM #1
kiwimoosical
Bounty hunter
(adsbygoogle = window.adsbygoogle || []).push({}); To read memory from a particular memory address IF allocated:

    char* readMem(DWORD address, unsigned int count)
{
char* addr = (char*)address; //convert the address to a char*
char* newAddr = new char[count]; //instansiate a new char* to hold the data from that address
for(unsigned int x = 0;x<count;++x)
newAddr[x] = addr[x]; //fill the array
return newAddr;
}

The following 2 users say thank you to kiwimoosical for this useful post:

Ritztro, TheUberFail
03-13-2011, 05:42 PM #2
kiwimoosical
Bounty hunter
Does anyone know what this is or does?...
03-13-2011, 06:30 PM #3
Originally posted by kiwimoosical View Post
Does anyone know what this is or does?...


Looks at the memory address given and adds from that memory address onwards the memory to the char array. Upside Down Happy
03-13-2011, 06:31 PM #4
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
Does anyone know what this is or does?...


Let me take a shot, you point to the memory location given, then you take the data that is pointed to and assign it to a char. Then you fill an array with the amount of data the user wants by going up in memory adresses. Then you return the actual data that is there in the form of an array?

Note:
I thought you could only access memory that your application owned.. Or does that only apply for the app's stack? Can you access the heap or "Free Store" at any location?
Last edited by Ritztro ; 03-13-2011 at 06:34 PM.
03-13-2011, 06:33 PM #5
Originally posted by kiwimoosical View Post
To read memory from a particular memory address IF allocated:

    char* readMem(DWORD address, unsigned int count)
{
char* addr = (char*)address; //convert the address to a char*
char* newAddr = new char[count]; //instansiate a new char* to hold the data from that address
for(unsigned int x = 0;x<count;++x)
newAddr[x] = addr[x]; //fill the array
return newAddr;
}


dont you have to delete the char array since you initialized it with the keyword new?
03-13-2011, 07:06 PM #6
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Let me take a shot, you point to the memory location given, then you take the data that is pointed to and assign it to a char. Then you fill an array with the amount of data the user wants by going up in memory adresses. Then you return the actual data that is there in the form of an array?

Note:
I thought you could only access memory that your application owned.. Or does that only apply for the app's stack? Can you access the heap or "Free Store" at any location?


You can access any memory as long as it has been allocated/malloc'd.

---------- Post added at 03:06 PM ---------- Previous post was at 03:01 PM ----------

Originally posted by TheUberFail View Post
dont you have to delete the char array since you initialized it with the keyword new?


A little bit of excess memory doesn't hurt. But in your code, you would do:
    typedef unsigned long long DWORD;
//-------------------------------------------------
DWORD address = 0x1A;
char* dataAtMem = readMem(address, 2);
free(&(dataAtMem*)); //That might be wrong, but you just call the free method.
//free(*(dataAtMem*)); Might be the right way, don't have compiler open to test atm.


So yeah. This code is just for reading, the memory management is your task Smile
03-13-2011, 07:41 PM #7
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
You can access any memory as long as it has been allocated/malloc'd.

---------- Post added at 03:06 PM ---------- Previous post was at 03:01 PM ----------



A little bit of excess memory doesn't hurt. But in your code, you would do:
    typedef unsigned long long DWORD;
//-------------------------------------------------
DWORD address = 0x1A;
char* dataAtMem = readMem(address, 2);
free(&(dataAtMem*)); //That might be wrong, but you just call the free method.
//free(*(dataAtMem*)); Might be the right way, don't have compiler open to test atm.


So yeah. This code is just for reading, the memory management is your task Smile


Can you write it though?
03-13-2011, 10:07 PM #8
Girby2K11
☮ ☯ ☢ ✔ ➝
how many years have you been programming
03-14-2011, 12:21 AM #9
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Can you write it though?


yes.

&address = (char*)0xEE; //your data here.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo