How do I read the value of an address?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: How do I read the value of an address?

  1. #1
    Join Date
    Oct 2009
    Posts
    8

    How do I read the value of an address?

    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

  2. #2
    Join Date
    Oct 2009
    Posts
    8

    Re: How do I read the value of an address?

    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.

  3. #3
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: How do I read the value of an address?

    Code:
    int *value;
    value = 0x00B12318;
    cout << *value;
    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.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,977

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    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;

  5. #5
    Join Date
    Oct 2009
    Posts
    8

    Re: How do I read the value of an address?

    Quote Originally Posted by GCDEF View Post
    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;
    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.

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How do I read the value of an address?

    Attempt at what? You haven't been very clear on what it is you are trying to accomplish.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,977

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    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?

  8. #8
    Join Date
    Apr 1999
    Posts
    27,418

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    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.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Oct 2009
    Posts
    8

    Re: How do I read the value of an 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.

  10. #10
    Join Date
    Apr 1999
    Posts
    27,418

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    I would rather not reveal what I am trying to accomplish.
    Why not? It sounds suspicious to me as to why you want to know what is at a hard-coded address.

    Regards,

    Paul McKenzie

  11. #11
    Join Date
    Apr 1999
    Posts
    27,418

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    @hoxsiew: As the title says, I am trying to READ the value contained in a memory address
    You were told in post #3 how to do it. Did you read it?
    Code:
    int *value;
    value = 0x00B12318;
    cout << *value; // *value is the data at that address
    Regards,

    Paul McKenzie

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,977

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    I would rather not reveal what I am trying to accomplish.

    Thanks for all the help guys but it does not solve my problem.
    Then you probably shouldn't expect any more help.

  13. #13
    Join Date
    Oct 2009
    Posts
    8

    Re: How do I read the value of an address?

    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

  14. #14
    Join Date
    Nov 2007
    Posts
    613

    Re: How do I read the value of an 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.

  15. #15
    Join Date
    May 2002
    Posts
    1,435

    Re: How do I read the value of an address?

    Quote Originally Posted by Poopynoob View Post
    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.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center