0

I need to replace a bit of text string in a hex file. I have already used a binary writer but as i add more stuff to the file, the offsets change. Therefore I have to keep fixing the offsets.

I have already tried the binary writer method.

BinaryWriter BinaryWriter1 = new BinaryWriter((Stream) File.OpenWrite("[File]"));
for (int index = [Offset]; index <= [Offset]; ++index) {
    BinaryWriter1.BaseStream.Position = (long) index;
    BinaryWriter1.Write([Name of form].Byte1);
    BinaryWriter1.Close();
}
Tenusha Guruge
  • 2,147
  • 3
  • 18
  • 38
Terry
  • 1
  • 2
  • Please explain what is a **hex file** – Sir Rufo Jun 09 '19 at 06:20
  • I mean a pak file. – Terry Jun 09 '19 at 06:27
  • 1
    You have to know the format/rules of the file structure very well to do this kind of patching. There are some known file types using the pak extension and all are different. This is impossible to answer – Sir Rufo Jun 09 '19 at 06:35
  • You could write the offset itself into the file as well, at a known position. But that's just one of the many possible answers we can come up with; all valid, possibly none which is going to help you. As Rufo says: add more information to your question. And fix the title: using binary writer or not isn't your problem here. – stijn Jun 09 '19 at 07:49
  • @stijn That's the thing though. I want a button to replace text within the file without using a binary writer. – Terry Jun 09 '19 at 09:01
  • Seek to the right spot in the file, then overwrite the original bytes making up the original text with the new bytes making up the new text. Note that this may or may not work depending on how the text is actually stored. For instance, if there is room in the file for, say, 128 bytes for the text, and you overwrite with something shorter, likely you will have to keep writing 0-bytes to fill the rest of that 128 space. However, if the string is supposed to end, and then be followed by other data, then this will only work if you overwrite with a new text with the exact same length. – Lasse V. Karlsen Jun 09 '19 at 14:09
  • Also, if the file format contains any form of checksums used to verify its integrity, you will have to patch that as well. – Lasse V. Karlsen Jun 09 '19 at 14:10

0 Answers0