How to log value changes and store them to txt file?

Discussions Related to Game Hacking and Memory Hacking Software

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

How to log value changes and store them to txt file?

Postby bogdan » Sat Jan 08, 2011 1:07 am

I have found the memory addresses that store the values for X,Y,Z coordinates in Quake2. I tested them with /viewpos and MHS displays them correctly. The values type is Float.

I need to save these X,Y,Z values every second (or less) in a txt file, so i can trace my movement inside the game (using some CAD software to visualize the points).

Is there any way to do this using MHS ?
Is there any other software that can record in a file the changing value at a specific memory address?

Thank you!
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Sat Jan 08, 2011 1:27 am

Write a script that does it.
FOpen()
FPrintF()
FClose()
EvalExp()
Sleep()


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby Dimple » Sat Jan 08, 2011 4:39 am

Using a script is probably the easiest way to go (I still haven't had time to learn it), but I would like to add that writing such a program would be very easy in C/C++, too. (I don't know about other languages because I haven't used them for this kind of stuff.)

In C it's easy to do with ReadProcessMemory() and using a timer to set the intervals when to read the memory. Then just save the data into a file.
Dimple
Hackleberry Fin
 
Posts: 21
Joined: Tue Dec 14, 2010 8:25 pm
Location: Finland

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Sat Jan 08, 2011 5:51 am

However with C/C++ you would also have to create a gateway to your data.
That is, a mechanism to find and lock onto the target process and get the data from it, potentially through lots of dereferences (a Complex Address).
L. Spiro Scripts and MHS provide you with easy access to any process.
In fact L. Spiro Scripts are always easier to write than C code, since you don’t have to start a new Microsoft® Visual Studio® project and clutter your hard drive with lots of files just for a simple 1-day task.

L. Spiro Scripts should be preferred over C in many cases, not just in hacking. I use L. Spiro Scripts daily for the work I do, and my coworkers do as well.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby Dimple » Sat Jan 08, 2011 6:27 am

You're right, I overlooked the complications in finding the process and the data inside the process since I have already solved these problems and written functions for them. And actually I use a template when I start a new project so I only have to change the name of the process and the module and write the complex address using your DeRef function (makes it real easy, thanks for the tip).

It's true that it's a real hassle to create a new project for every small thing. I've been working on the Unreal Tournament for a couple of weeks now and I have created 11 new projects for it. All I have actually done is a fly hack and aimbot (which I'm still working on) and a couple of tools that have hard coded values in them. I would have to change a lot of things to make them useful for other projects. I guess I have to take a really good look at that L. Spiro script. ;)
Dimple
Hackleberry Fin
 
Posts: 21
Joined: Tue Dec 14, 2010 8:25 pm
Location: Finland

Re: How to log value changes and store them to txt file?

Postby bogdan » Sat Jan 08, 2011 8:28 am

I don't understand EvalExp(). Is it the one that reads the value from the address and returns it to lpertRet?

I can write to a file with the code below....

void writevalue ()
{
FILE * pFile;
pFile = FOpen ("logfile.txt","w");
if (pFile!=NULL)
{
FPrintF(pFile, /* float type variable that holds the value */);
FClose (pFile);
Sleep(1000);
}
}

I am not a programmer so please explain further.
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Sat Jan 08, 2011 4:49 pm

Code: Select all
EVAL_RET_TYPE ertRet;
if ( EvalExp( "[[MyComplexAddressHere.exe+0x4524]+84h]+3C", &ertRet, false ) ) {
    // Address is stored in ertRet.u.ui64Int64.
}



L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby bogdan » Mon Jan 10, 2011 5:55 am

Thanks for the help so far!
I am still having trouble with it...

void On_HK_2 ()
{
FILE * pFile;
EVAL_RET_TYPE ertRet;

EvalExp( "f[quake2.exe+c2d70]", &ertRet, false );
pFile = FOpen ("logfile.txt","a");
FPrintF(pFile, " %f",&ertRet);
FClose (pFile);
}

writes 0.000 in the file even though Expression Evaluator shows : f[quake2.exe+c2d70] = 239.937500
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Mon Jan 10, 2011 6:54 am

Code: Select all
FPrintF(pFile, " %f", ertRet.u.dDouble);



L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby bogdan » Mon Jan 10, 2011 11:38 pm

Works great! but still i have one more question.

I've made a do .. while loop that writes at 1 second interval but i don't know how to stop it.
I tried using another Hotkey that changes a variable value from true to false but is not working.
(loop goes on and MHS.exe crushes when i click on one of his windows)

or maybe just inserting an
Code: Select all
if (/*key 3 is pressed*/) {break;}
in the loop will do it. but i don't know how to write it.

Code: Select all
bool myVal=true;
void On_HK_3 () {myVal=false;}

void On_HK_2 ()
{
FILE * pFile;
EVAL_RET_TYPE ertRet;

do
{
EvalExp( "f[quake2.exe+c2d70]", &ertRet, false );
pFile = FOpen ("logfile.txt","a");
FPrintF(pFile, "  %f",ertRet.u.dDouble);
FClose (pFile);
Sleep(1000);
}
while (myVal = true);

}


Thanks again for the support!
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Tue Jan 11, 2011 9:23 am

If you lock up MHS you can’t hit keys to stop the loop.

Start a second thread so that you are not locking up MHS.

CreateThread() should be called from On_HK_2().


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby bogdan » Tue Jan 11, 2011 10:24 pm

I inserted CreateThread in both functions... still MHS is locked. What's wrong?

Code: Select all
bool myVal=true;

void On_HK_2 ()
{
HANDLE hThread = CreateThread("On_HK_2()",0);

FILE * pFile;
EVAL_RET_TYPE ertRet;

do
{
EvalExp( "f[quake2.exe+c2d70]", &ertRet, false );
pFile = FOpen ("logfile.txt","a");
FPrintF(pFile, "  %f",ertRet.u.dDouble);
FClose (pFile);
Sleep(1000);
}
while (myVal = true);

CloseHandle( hThread );
}

void On_HK_3 () {
HANDLE hThread1 = CreateThread("On_HK_3()",0);
myVal=false;
CloseHandle( hThread1 );
}
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Tue Jan 11, 2011 11:16 pm

Code: Select all
bool myVal=true;

void On_HK_2() {
    // Run SaveValues() on a second thread.
    CloseHandle( CreateThread("SaveValues",0) );
    // Main MHS thread continues, giving MHS control.  SaveValues() runs on another thread.
}
void SaveValues() {
    FILE * pFile;
    EVAL_RET_TYPE ertRet;

    do {
        EvalExp( "f[quake2.exe+c2d70]", &ertRet, false );
        pFile = FOpen ("logfile.txt","a");
        FPrintF(pFile, "  %f",ertRet.u.dDouble);
        FClose (pFile);
        Sleep(1000);
    }
    while (myVal = true);

}

void On_HK_3() {
    myVal=false;
}



L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: How to log value changes and store them to txt file?

Postby bogdan » Thu Jan 13, 2011 1:30 am

The script still has a problem, Hotkey 3 does not change myVal from true to false, but with CreateThread i can simply close MHS and logging will end.

I've attached a jpg with some results from the first unit of quake 2.

Code: Select all
bool myVal=true;

void On_HK_2() {
    // Run SaveValues() on a second thread.
    CloseHandle( CreateThread("SaveValues",0) );
    // Main MHS thread continues, giving MHS control.  SaveValues() runs on another thread.
}
    void SaveValues() {
    FILE * pFile;
    EVAL_RET_TYPE ertRetX;
    EVAL_RET_TYPE ertRetY;
    EVAL_RET_TYPE ertRetZ;

    do {
        EvalExp( "f[quake2.exe+c2d70]", &ertRetX, false );
        EvalExp( "f[quake2.exe+c2d74]", &ertRetY, false );
        EvalExp( "f[quake2.exe+c2d78]", &ertRetZ, false );
        pFile = FOpen ("logfile.txt","a");
        FPrintF(pFile, "x= %f\n",ertRetX.u.dDouble);
        FPrintF(pFile, "y= %f\n",ertRetY.u.dDouble);
        FPrintF(pFile, "z= %f\n",ertRetZ.u.dDouble);
        FClose (pFile);
        Sleep(1000);
    }
    while (myVal = true);

}

void On_HK_3() {
    myVal=false;
}


Attachments
logfiles.jpg
logfiles.jpg (211.89 KiB) Viewed 30875 times
bogdan
I Have A Few Questions
 
Posts: 7
Joined: Sat Jan 08, 2011 1:04 am

Re: How to log value changes and store them to txt file?

Postby L. Spiro » Thu Jan 13, 2011 2:02 am

Code: Select all
while (myVal == true);


You have no code to set myVal back to true, so once you log once you have to recompile scripts to log again.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Next

Return to General Related Discussions

Who is online

Users browsing this forum: No registered users and 0 guests

cron