Is there a way to open a file for hex editing?

Aug 21, 2008 at 10:35pm
I know that you can open a file for binary editing by using something like this:

ifstream myFile ("data.bin", ios::in | ios::binary);

Here's my situation:

-I play a low-grade game called Conquer Online.
-My system can easily run 10+ clients, so I can play on many characters interchangeably.
-The .exe limits you to two clients running at a time.
-This can be changed by opening the .exe in a hex editor and changing a few bytes.
-Every time the game patches (multiple times a week) I have to make this edit and a few others again. It's getting kind of old.
-The bytes that need to be changed are always the same, so I'd like to automate this process by making a program that will change these bytes when I run it.

Is there a way to hex edit a file in this way that is simple, like standard fstream and binary fstream? I'd really appreciate it if someone could muster up a quick sample code for me if they have the time. Here's an example of a change that needs to be made:

-byte 15B3A0 needs to be changed from 'E'(45) to 'e'(65).

Thanks,
SCP
Aug 22, 2008 at 2:28am
One solution is to open the file like a normal file. Then you can use the seekp() function to go to the position you want. There you write the char you want and then the remaining of the file.

Hope this helps
Last edited on Aug 22, 2008 at 2:46am
Aug 22, 2008 at 7:36am
I could be wrong, but I don't think that approach will work. I'm pretty sure if you use seekp() and then call write() or put(), you will end up deleting everything in the file and merely putting the one character in. If it works, then great, but if it doesn't, you may have to read the entire file in, alter the byte in memory, the write the whole thing out to file again. I would be interested to know if the above method works though.
Aug 22, 2008 at 12:34pm
It works... I made once such a hexeditor myself (a long as you are using files smaller than 2GB ;))
Topic archived. No new replies allowed.