Memory Address

This is a discussion on Memory Address within the C++ Programming forums, part of the General Programming Boards category; What if i got this: Code: ofstream file("file.txt"); int Address; int TheAddress; file << &Address; Okay now, let's say, in ...

  1. #1
    kevinawad
    Guest

    Memory Address

    What if i got this:

    Code:
    ofstream file("file.txt");
    
    int Address;
    int TheAddress;
    
    file << &Address;
    Okay now, let's say, in the file file.txt, it's written : 0029F93C

    How could i make that TheAddress is Equal to 0029F93C?

    I'm trying to retreive it from the file, but it retreives an integer.

    Can anyone give me a hand? Thank you .

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    And 0029F93C is also an integer, so that's handy. If you mean "how do I read an integer that's written in hex", then you need to set the ios::hex flag.

  3. #3
    kevinawad
    Guest
    Is it possible to set the flag directly while getting the string from the file?

  4. #4
    kevinawad
    Guest
    Here's the deal...

    001FF92C = 66952.

    001FF92C >> Wads;

    Now Wads = 66952.

    ReadProcessMemory(client, (int*)Wads, &WadsBuffer, sizeof(int), 0);

    It won't read the Wads address...because of it's value.

    How could it be possible to make it work?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    0x001FF92C equals 2095404, not 66952.

  6. #6
    kevinawad
    Guest
    Hmmm, when i read it from the file...it gives me this value...

    Hmmm...

    That's a big problem im having...

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    Reading in hex is not that hard.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    
    int main() {
        std::ifstream hexin("hex.txt");
        int wads;
        hexin.flags(std::ios::hex);  //or hexin << std::hex
        hexin >> wads;
        std::cout << wads << std::endl;
        return 0;
    }
    Remember iomanip for all the flags. (Okay, I lied: flags is in iostream, not iomanip.)
    Last edited by tabstop; 10-18-2008 at 08:46 PM. Reason: Lie

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    6,826
    Why do you have a file of memory addresses?
    Quote Originally Posted by phantomotap
    Can you write code while blindfolded only with the blind covering your brain? Can you code while brainfolded?

  9. #9
    kevinawad
    Guest
    Code:
    file.open(filename.c_str());
    
    file.flags(ios::hex);
    
    file >> Wads;
    
    cout <<Wads;
    Value in the text file = : 001FF92C



    When printing wads. Im getting 66952

    Still having some problems. Hmm...


    I'm working on a localhost - kind of server. It will be a debug console. it will access the memory location for the variables in the client.

    I'm actually working on a Text Role playing Game.
    Last edited by kevinawad; 10-18-2008 at 08:53 PM.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    Check that you're reading the right file, I guess. 66952 is 0x10588, so maybe look for that pattern.

  11. #11
    kevinawad
    Guest
    I am reading the right one :P...Hmmm...Did you try it? does it work for you?

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    13,007
    Quote Originally Posted by kevinawad View Post
    I am reading the right one :P...Hmmm...Did you try it? does it work for you?
    Code:
    $ ./temp
    2095404
    And of course my hex.txt has 001FF92C in it.

  13. #13
    kevinawad
    Guest
    Your right, i just remade a new program. And it worked...I think im reading the wrong file.

  14. #14
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    6,826
    I'm working on a localhost - kind of server. It will be a debug console. it will access the memory location for the variables in the client.
    Are you aware that you cannot just access a hard coded address? Further aware that even if you can access a hard coded address that there is no guarantee it has the data you want to inspect?
    Quote Originally Posted by phantomotap
    Can you write code while blindfolded only with the blind covering your brain? Can you code while brainfolded?

  15. #15
    kevinawad
    Guest
    Wow...I just found out about the problem...But im not sure what causes it?

    Code:
    	file.open(filename.c_str());
    	file >> processid;
    	file.flags(ios::hex);
    	file >> Attack;
    	file >> MagicAttack;
    	file >> Defense;
    	file >> Speed;
    	file >> Health;
    	file >> MaxHealth;
    	file >> Mana;
    	file >> MaxMana;
    	file >> AbilityPoint;
    	file >> Strength;
    	file >> Intelligence;
    	file >> Dexterity;
    	file >> Ritual;
    	file >> SkillPoint;
    	file >> MasterSkillPoint;
    	file >> UniqueSkillPoint;
    	file >> Name;
    	file >> Wads;
    Alright so, when i want to get the value from the file...it only works if i put one value in the txt file.

    My text file:

    Code:
    41612
    0019F9B8
    0019F9BC
    0019F9C0
    0019F9C4
    0019F9C8
    0019F9CC
    0019F9D0
    0019F9D4
    0019F9D8
    0019F9DC
    0019F9E0
    0019F9E4
    0019F9E8
    0019F9EC
    0019F9F0
    0019F9F4
    0019F9F8
    0019FA14
    I don't understand really about the problem.

    Doing this works:
    Code:
    #include <iostream>
    #include <fstream>
    
    
    using namespace std;
    
    
    int main()
    {
    
    	int Address;
    
    	ifstream file("file.add");
    
    	file.flags(ios::hex);
    
    	file >> Address;
    
    	cout <<Address;
    
    	return 0;
    }
    But doing this doesn't?

    Code:
    	file.open(filename.c_str());
    	file >> processid;
    	file.flags(ios::hex);
    	file >> Attack;
    	file >> MagicAttack;
    	file >> Defense;
    	file >> Speed;
    	file >> Health;
    	file >> MaxHealth;
    	file >> Mana;
    	file >> MaxMana;
    	file >> AbilityPoint;
    	file >> Strength;
    	file >> Intelligence;
    	file >> Dexterity;
    	file >> Ritual;
    	file >> SkillPoint;
    	file >> MasterSkillPoint;
    	file >> UniqueSkillPoint;
    	file >> Name;
    	file >> Wads;
    Hmmm?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Pointer to specific memory address
    By elnerdo in forum C++ Programming
    Replies: 10
    Last Post: 05-19-2006, 07:35 AM
  3. Memory Address
    By Stack Overflow in forum C Programming
    Replies: 5
    Last Post: 05-25-2004, 11:43 AM
  4. Memory address?
    By Munkey01 in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 08:04 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21