Search code examples
inno-setuppascalscript

How to change certain bytes in huge file in Inno Setup?


I am trying to replace a file's contents. The file is a huge binary file (500 MB).

I need to change some of bytes in it with my Inno Setup script.

How can I do it?

Here is the screenshot of my file's hex code that I want to change.

Here is the files:

enter image description here

I want to make the right side file just like the one on the left side.


Solution

  • Start here: Writing binary file in Inno Setup.

    And you need to do two changes:

    • Open an existing file for writing, instead of creating a new one:

      Stream := TFileStream.Create(FileName, fmOpenReadWrite);
      
    • Seek to the desired position before writing the data:

      Stream.Seek($217F6DF1, soFromBeginning)
      Stream.WriteBuffer(Buffer, Size);