Script to patch binary file

Hi,
I’ll need a script that:

  • launches a software (the epson scan software)
  • patches the resulting “scan.bmp” file overwriting the 3 bytes at 0x22, 0x23, 0x24 with values 0x20 0x56 0x15

Is it possible? Thank you.

Hi echeclus, welome to the forums :wave:

Yes, this is possible.
Launching the software is straightforward and there are several ways of doing it. Pick your favourite.
To modify the file: read the file, access the offset, change the value, write the file.

Example:

$bytes = [System.IO.File]::ReadAllBytes("E:\Temp\Files\scan.bmp")
$bytes[0x22] = 0x20
$bytes[0x23] = 0x56
$bytes[0x24] = 0x15
$bytes = [System.IO.File]::WriteAllBytes("E:\Temp\Files\scan.bmp",$bytes)
1 Like

Thank you very very much.
My problem is solved!