C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-18-2008, 08:16 PM   #1
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
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 .
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:19 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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.
tabstop is offline   Reply With Quote
Old 10-18-2008, 08:29 PM   #3
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
Is it possible to set the flag directly while getting the string from the file?
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:31 PM   #4
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
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?
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:33 PM   #5
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
0x001FF92C equals 2095404, not 66952.
tabstop is offline   Reply With Quote
Old 10-18-2008, 08:34 PM   #6
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
Hmmm, when i read it from the file...it gives me this value...

Hmmm...

That's a big problem im having...
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:40 PM   #7
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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
tabstop is offline   Reply With Quote
Old 10-18-2008, 08:48 PM   #8
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,202
Why do you have a file of memory addresses?
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 10-18-2008, 08:50 PM   #9
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
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.
__________________
~kevinawad~

Last edited by kevinawad; 10-18-2008 at 08:53 PM.
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:55 PM   #10
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Check that you're reading the right file, I guess. 66952 is 0x10588, so maybe look for that pattern.
tabstop is offline   Reply With Quote
Old 10-18-2008, 08:56 PM   #11
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
I am reading the right one :P...Hmmm...Did you try it? does it work for you?
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 08:58 PM   #12
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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.
tabstop is offline   Reply With Quote
Old 10-18-2008, 09:00 PM   #13
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
Your right, i just remade a new program. And it worked...I think im reading the wrong file.
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Old 10-18-2008, 09:04 PM   #14
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,202
Quote:
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?
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 10-18-2008, 09:09 PM   #15
Kevin
 
kevinawad's Avatar
 
Join Date: Nov 2006
Posts: 192
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?
__________________
~kevinawad~
kevinawad is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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