Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Accessing a Specific Memory Address
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
andytyk




PostPosted: Mon Jun 21, 2004 8:07 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Mon Jun 21, 2004 9:32 pm   Post subject: (No subject)

code:
int main()
{
   int arbitrary_address = 0x01010101;
   char * ptr = static_cast<char *>(arbitrary_address);
}
andytyk




PostPosted: Mon Jun 21, 2004 9:56 pm   Post subject: (No subject)

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




PostPosted: Mon Jun 21, 2004 10:13 pm   Post subject: (No subject)

code:
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




PostPosted: Mon Jun 21, 2004 10:24 pm   Post subject: (No subject)

Catalyst wrote:
code:
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. Smile
andytyk




PostPosted: Mon Jun 21, 2004 10:34 pm   Post subject: (No subject)

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




PostPosted: Tue Jun 22, 2004 1:08 am   Post subject: (No subject)

andytyk wrote:
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.

andytyk wrote:
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




PostPosted: Tue Jun 22, 2004 12:20 pm   Post subject: (No subject)

wtd wrote:
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. Smile
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: