Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[c++] Hex editing through c++...

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Franc[e]sco
Expert Cheater
Reputation: 0

Joined: 22 Mar 2008
Posts: 190

PostPosted: Wed Jun 25, 2008 5:04 pm    Post subject: [c++] Hex editing through c++... Reply with quote

Heya guys... i wanna make a program that hex edits a file replacing 2 bytes at certain offsets obtained from a txt file. Can anyone explain me how i make my c++ program hex edit a file?
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Wed Jun 25, 2008 5:19 pm    Post subject: Reply with quote

http://www.cplusplus.com/doc/tutorial/files.html
file a
open as in
strtoint the offset

file b
open as binary
seeekg(offset)
write(block, size)

_________________
Back to top
View user's profile Send private message
Franc[e]sco
Expert Cheater
Reputation: 0

Joined: 22 Mar 2008
Posts: 190

PostPosted: Wed Jun 25, 2008 5:23 pm    Post subject: Reply with quote

Is this ok to replace the 2 bytes at the various offsets with 03 00?

Code:
/*
        Automatic Mob.wz hexer v0.1a
        coded by Franc[e]sco for CEF
*/
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
    ifstream mob("Mob.wz", ios::in|ios::binary|ios::ate);
    ifstream offsets("offsets.txt");
   
    string line;
    int fOffset;
    char block[2] = {03, 00};
   
    cout << "Mob.wz automatic hexer v0.1a\n";
    cout << "Coded by Franc[e]sco for CEF\n\n";
    cout << "Press enter to begin hexing your mob.wz.\n\n";
   
    system("PAUSE");
   
    cout << "\n\n";
   
    if(mob.is_open())
    {
                     if(offsets.is_open())
                     {
                                          while(!offsets.eof())
                                          {
                                                               getline(offsets,line);
                                                               fOffset = strtoint(line);
                                                               mob.seekg(fOffset);
                                                               mob.write(block, 2);
                                                               cout << "Hexing at offset: ", fOffset, ".\n";
                                          }
                                          offsets.close();
                     }
                     else
                     {
                         cout << "\n\nError opening file: offsets.txt\n\n";                           
                     }
    }
    else
    {
        cout << "\n\nError opening file: Mob.wz\n\n";
    }
   
    cout << "\nHexing done! Enjoy your hacks ^^. Press any key to exit.";
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Jun 25, 2008 7:01 pm    Post subject: Reply with quote

Franc[e]sco wrote:
Is this ok to replace the 2 bytes at the various offsets with 03 00?

Code:
/*
        Automatic Mob.wz hexer v0.1a
        coded by Franc[e]sco for CEF
*/
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
    ifstream mob("Mob.wz", ios::in|ios::binary|ios::ate);
    ifstream offsets("offsets.txt");
   
    string line;
    int fOffset;
    char block[2] = {03, 00};
   
    cout << "Mob.wz automatic hexer v0.1a\n";
    cout << "Coded by Franc[e]sco for CEF\n\n";
    cout << "Press enter to begin hexing your mob.wz.\n\n";
   
    system("PAUSE");
   
    cout << "\n\n";
   
    if(mob.is_open())
    {
                     if(offsets.is_open())
                     {
                                          while(!offsets.eof())
                                          {
                                                               getline(offsets,line);
                                                               fOffset = strtoint(line);
                                                               mob.seekg(fOffset);
                                                               mob.write(block, 2);
                                                               cout << "Hexing at offset: ", fOffset, ".\n";
                                          }
                                          offsets.close();
                     }
                     else
                     {
                         cout << "\n\nError opening file: offsets.txt\n\n";                           
                     }
    }
    else
    {
        cout << "\n\nError opening file: Mob.wz\n\n";
    }
   
    cout << "\nHexing done! Enjoy your hacks ^^. Press any key to exit.";
   
    system("PAUSE");
    return EXIT_SUCCESS;
}


lol, not that i know what a lot of this code is. I suggest not using System("PAUSE");

Various system commands aren't too good. It is usually a better idea to try and do those methods differently, as System methods must open a program to do the pausing...
Back to top
View user's profile Send private message MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Jun 25, 2008 7:15 pm    Post subject: Reply with quote

I think it'd probably be best to just read in the file all at once, then parse through that yourself. Just my opinion though.
_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Wed Jun 25, 2008 8:59 pm    Post subject: Reply with quote

ifstream makes an input file. Use ofstream for the .wz.
I haven't tried your code, but everything looks like it should work.

_________________
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Jun 25, 2008 9:45 pm    Post subject: Reply with quote

HalfPrime wrote:
ifstream makes an input file. Use ofstream for the .wz.
I haven't tried your code, but everything looks like it should work.


correct me if i'm wrong, but doesn't ifstream just make an input stream? So he opens the mob.wz file in an input stream. Because he wants to write offsets to it?
Back to top
View user's profile Send private message MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Wed Jun 25, 2008 11:18 pm    Post subject: Reply with quote

input stream is input to the process, not to the file...I think.
Seems to work for me that way, anyways.

_________________
Back to top
View user's profile Send private message
Franc[e]sco
Expert Cheater
Reputation: 0

Joined: 22 Mar 2008
Posts: 190

PostPosted: Thu Jun 26, 2008 2:08 am    Post subject: Reply with quote

Ewww. Compiling errors.

Code:
main.cpp: In function `int main(int, char**)':

main.cpp:36: error: `strToInt' undeclared (first use this function)
main.cpp:36: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:38: error: 'struct std::ifstream' has no member named 'write'

make.exe: *** [main.o] Error 1


code of the program:
Code:
/*
        Automatic Mob.wz hexer v0.1a
        coded by Franc[e]sco for CEF
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    ifstream mob("Mob.wz", ios::in|ios::binary|ios::ate);
    ifstream offsets("offsets.txt");
   
    string line;
    int fOffset;
    char block[2] = {03, 00};
   
    cout << "Mob.wz automatic hexer v0.1a\n";
    cout << "Coded by Franc[e]sco for CEF\n\n";
    cout << "Press enter to begin hexing your mob.wz.\n\n";
   
    system("PAUSE");
   
    cout << "\n\n";
   
    if(mob.is_open())
    {
                     if(offsets.is_open())
                     {
                                          while(!offsets.eof())
                                          {
                                                               getline(offsets,line);
                                                               fOffset = strToInt(line);
                                                               mob.seekg(fOffset);
                                                               mob.write(block, 2);
                                                               cout << "Hexing at offset: ", fOffset, ".\n";
                                          }
                                          offsets.close();
                     }
                     else
                     {
                         cout << "\n\nError opening file: offsets.txt\n\n";                           
                     }
    }
    else
    {
        cout << "\n\nError opening file: Mob.wz\n\n";
    }
   
    cout << "\nHexing done! Enjoy your hacks ^^. Press any key to exit.";
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Jun 26, 2008 9:59 am    Post subject: Reply with quote

c++ is case sensitive. Both of those errors deal with the casing on 1 of the letters.
_________________
Back to top
View user's profile Send private message
Franc[e]sco
Expert Cheater
Reputation: 0

Joined: 22 Mar 2008
Posts: 190

PostPosted: Thu Jun 26, 2008 10:00 am    Post subject: Reply with quote

NVM, i solved using fstream instead of ifstream and atoi instead of StrToInt
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Thu Jun 26, 2008 7:07 pm    Post subject: Reply with quote

Look at TinyXML's source for some decent functions to read and write to and from files. They use the 'f' functions (fopen, fclose, fseek, etc.). There are plenty of other methods to use as well.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites