I am trying to read the value of memory address using c++.
For example, how can I read the value contained in "00B12318"?
I have tried:
Help with Code Tags
int value;
00B12318 = &value;
cout << value;
But sadly it doesnt work.
Please help! THank you
That doesn't make sense. You
declare an int but don't assign it a value.
You have this undermined type variable named 00B12318 which isn't a legal C++ variable name, then you assign it the address of your previously defined int.
Then you output the int that you never initialized.
What are you trying to do?
If you want to read the value of a memory address
Code:
int value = 23;
int* pValue = &value;
cout << *pValue;
int value = 23;
int* pValue = &value;
cout << *pValue;
I am a beginner at C++. The "&" operator means "address of" and so hence my pathetic attempt.
I am still not understanding the code. Please explain further with the memory address: 00B12318
Thank you
Last edited by Poopynoob; October 27th, 2009 at 08:05 AM.
I am a beginner at C++. The "&" operator means "address of" and so hence my pathetic attempt.
I am still not understanding the code. Please explain further with the memory address: 00B12318
Thank you
You'd have to know what pointed to do know how to interpret it. If you know it's an int
Code:
int* pInt = "0x00B12318";
int nInt = *pInt;
I don't know why you'd ever want to dereference a hardwired address though. Again, what are you trying to do?
I am a beginner at C++. The "&" operator means "address of" and so hence my pathetic attempt.
I am still not understanding the code.
Code:
#include <iostream>
using namespace std;
int main()
{
int value = 23;
int* pValue = &value;
cout << *pValue;
}
Which line of the code above do you not understand?
Please explain further with the memory address: 00B12318
What is special to you about memory address 00B12318? The only time you want to manipulate an exact memory address is either you're developing for some hardware device (a driver), or you're trying to hack something at that address.
@hoxsiew: As the title says, I am trying to READ the value contained in a memory address, in this case it would be "00B12318". I would rather not reveal what I am trying to accomplish.
@GCDEF: int* pInt = "0x00B12318";
int nInt = *pInt; is not working for me either. (error C2440: 'initializing' : cannot convert from 'const char [11]' to 'int *), of course if I remove the quotes around 0x00B12318 then there would be another error. (cannot convert from 'int' to 'int *')
@Paul: I do not get what the 23 is.
NOTE: 00B12318 is a String (series of letters)
Thanks for all the help guys but it does not solve my problem.
Last edited by Poopynoob; October 27th, 2009 at 02:54 PM.
Alright, I am doing this for a school project. Trying to get a good mark. :P (Although it is not nessesary, nevertheless I might need it later in programming)
@Paul: It gives this error: error C2440: '=' : cannot convert from 'int' to 'int *' when I use the code : int *value;
value = 0x00B12318;
cout << *value; // *value is the data at that address
You cannot access memory directly. You can do that only using a pointer variable.
Some explanations...
A line like:
v = e;
is an assignment. The '=' sign is the assignment operator. The 'v' must be an l-value and the 'e' must be an r-value.
You can find more about l-values and r-values at http://msdn.microsoft.com/en-us/library/bkbs2cds.aspx
Simply, in your line:
00B12318 = &value;
the 00B12318 is not an l-value, so your line will cause a syntax error.
To do it properly you should use the way suggested by jnmacd (I will use more suggestive variable names):
int* PointerToInt; // declare a pointer to a memory area used to store an integer
PointerToInt = 0x00B12318; // assign the address 0x00B12318 to that pointer
cout << *PointerToInt; // Show the content of the memory address pointed by PointerToInt
Important to know:
If you access memory addresses allocated to your application, that code will work. If you attempt to access memory addresses from the memory space allocated to other applications, the code will fail.
Normally, an application is denied access to the memory used by other applications. There are three reasons for that. The first is to protect the memory of an application from being spoiled by other applications. The second is the security, to prevent one application to spy on another. The third is easy memory management.
There are some special techniques to access the memory allocated to another application, (like dll injection) but frankly, at the level of your knowledge, at this time , you should focus your attention on understanding more basic tasks.
My guess is that you attempt to hack something, that's why you don't want to talk about your intentions. To me it sounds ok, trying that is an excellent way to learn programming. But be aware that the ideas you're trying to use are far from being new. Usually serious programmers will use sophisticated techniques to protect their software, so you will encounter many nasty suprises. Don't expect that you'll find what you're looking for just from readind the memory.
Alright, I am doing this for a school project. Trying to get a good mark. :P
I would be very surprised to find out that a technique commonly used for cheating at games would be assigned as a school project. Would you care to name the school and the instructor? I would be happy to write to him/her and explain why this is not a proper assignment for someone just learning to program.
Bookmarks