
-----------------------------------
andytyk
Mon Jun 21, 2004 8:07 pm

Accessing a Specific Memory Address
-----------------------------------
Given an arbitrary memory location, how do I load the value stored at that address into a variable?

Is it even possible? I've been searching online, but haven't come up with any solutions.

-----------------------------------
wtd
Mon Jun 21, 2004 9:32 pm


-----------------------------------
int main()
{
   int arbitrary_address = 0x01010101;
   char * ptr = static_cast(arbitrary_address);
}

-----------------------------------
andytyk
Mon Jun 21, 2004 9:56 pm


-----------------------------------
Copy and pasted into VC++,

Untitled.cpp(8 ) : error C2440: 'static_cast' : cannot convert from 'int' to 'char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

-----------------------------------
Catalyst
Mon Jun 21, 2004 10:13 pm


-----------------------------------
char * ptr = (char*)arbitrary_address; 
I'm not sure if thats the proper c++ way to do this, but it works with no problems for me.

-----------------------------------
wtd
Mon Jun 21, 2004 10:24 pm


-----------------------------------
char * ptr = (char*)arbitrary_address; 
I'm not sure if thats the proper c++ way to do this, but it works with no problems for me.

Yes that does work.  That's how I did it initially, then decided to be too smart and replaced it with static_cast without testing it again.  :-)

-----------------------------------
andytyk
Mon Jun 21, 2004 10:34 pm


-----------------------------------
Compiled using VC++ 6, it doesn't run into any problems during compilation, but when it is run, it generates one of those "Report to Microsoft" errors and doesn't return the desired result.

I am merely trying to devise a way to pass values between two programs running concurrently (written in different languages), I was thinking of simply using files, but then I realized memory would be faster. Oh well, I'll work on the disk file implementation then.

-----------------------------------
wtd
Tue Jun 22, 2004 1:08 am


-----------------------------------
Compiled using VC++ 6, it doesn't run into any problems during compilation, but when it is run, it generates one of those "Report to Microsoft" errors and doesn't return the desired result.

Because you accessed a memory location you're not allowed to access.

I am merely trying to devise a way to pass values between two programs running concurrently (written in different languages), I was thinking of simply using files, but then I realized memory would be faster. Oh well, I'll work on the disk file implementation then.

You could possibly also use sockets and create a simple client/server environment.

If you do try to use a file, you'll need to lock the file when you write to it.  Otherwise you'll get two files making changes to the same file at the same time.  That leads to pure insanity.

I would have a server program disconnected from any other program you're working on.  Other programs would then be able to connect to it and make requests.  Sound like a database?  That's pretty much what I'm describing.

-----------------------------------
andytyk
Tue Jun 22, 2004 12:20 pm


-----------------------------------
Because you accessed a memory location you're not allowed to access. 


Then how do programs such as memory editors (ie. game cheating programs) access and write to the memory of other programs?

I have the file based method up and working so the issue is resolved. But would still like to see an answer to the question above.  :)
