Search/replacing data in a binary file?

Just starting out? Need help? Post your questions and find answers here.
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: Search/replacing data in a binary file?

Post by cas »

wallgod wrote:So for example, if I wanted to replace "Span" with "Spain", the result would be "Spai". :P
Unfortunately, it is not possible to replace 4 bytes with 5 bytes in same file without overwriting other bytes (except if writing to end of file). And, it is not possible to replace 5 bytes with 4 bytes. For that situations you need to 1)rename original file to some different name, 2) create new file with same name as original file and 3)stream data to new file from from original renamed file.
With this function, if you replace 5 bytes with 4 bytes then it appends additional (5th) empty byte to that 4 bytes so they are equal.
Post Reply