View previous topic :: View next topic |
Author |
Message |
Franc[e]sco Expert Cheater Reputation: 0
Joined: 22 Mar 2008 Posts: 190
|
Posted: Wed Jun 25, 2008 5:04 pm Post subject: [c++] Hex editing through c++... |
|
|
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 |
|
|
HalfPrime Grandmaster Cheater Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
|
Back to top |
|
|
Franc[e]sco Expert Cheater Reputation: 0
Joined: 22 Mar 2008 Posts: 190
|
Posted: Wed Jun 25, 2008 5:23 pm Post subject: |
|
|
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 |
|
|
Overload Master Cheater Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Wed Jun 25, 2008 7:01 pm Post subject: |
|
|
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 |
|
|
samuri25404 Grandmaster Cheater Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Wed Jun 25, 2008 7:15 pm Post subject: |
|
|
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.
_________________
|
|
Back to top |
|
|
HalfPrime Grandmaster Cheater Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Wed Jun 25, 2008 8:59 pm Post subject: |
|
|
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 |
|
|
Overload Master Cheater Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Wed Jun 25, 2008 9:45 pm Post subject: |
|
|
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 |
|
|
HalfPrime Grandmaster Cheater Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Wed Jun 25, 2008 11:18 pm Post subject: |
|
|
input stream is input to the process, not to the file...I think.
Seems to work for me that way, anyways.
_________________
|
|
Back to top |
|
|
Franc[e]sco Expert Cheater Reputation: 0
Joined: 22 Mar 2008 Posts: 190
|
Posted: Thu Jun 26, 2008 2:08 am Post subject: |
|
|
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 |
|
|
HomerSexual Grandmaster Cheater Supreme Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Jun 26, 2008 9:59 am Post subject: |
|
|
c++ is case sensitive. Both of those errors deal with the casing on 1 of the letters.
_________________
|
|
Back to top |
|
|
Franc[e]sco Expert Cheater Reputation: 0
Joined: 22 Mar 2008 Posts: 190
|
Posted: Thu Jun 26, 2008 10:00 am Post subject: |
|
|
NVM, i solved using fstream instead of ifstream and atoi instead of StrToInt
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Thu Jun 26, 2008 7:07 pm Post subject: |
|
|
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 |
|
|
|