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
Printable View
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
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:
int value;
00B12318 = &value;
cout << value;
But sadly it doesnt work.
Please help! THank you
Sorry I dont know how to edit my thread. :(
Is that what you are trying to do? I don't see why you would want to print out the value of a static memory address.Code:int *value;
value = 0x00B12318;
cout << *value;
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;
Attempt at what? You haven't been very clear on what it is you are trying to accomplish.
Which line of the code above do you not understand?Code:#include <iostream>
using namespace std;
int main()
{
int value = 23;
int* pValue = &value;
cout << *pValue;
}
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.Quote:
Please explain further with the memory address: 00B12318
Regards,
Paul McKenzie
@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.
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
Thanks for all the help! Appreciate it :)
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.
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.
It still does not work. http://img515.imageshack.us/img515/2585/32810391.jpg
I have literally copied the code but same error. :(
Thanks for the replys.
I have no idea what you have said. Sorry for all the trouble but please elaborate.
Thanks alot!
Do you have a C++ book? If so, what does it say about "casting" and "casts"? When you google "C++ casting" , what do you see?
There is even a FAQ:
http://www.codeguru.com/forum/showthread.php?t=312456
Regards,
Paul McKenzie