Thursday | 21 NOV 2024
[ previous ]
[ next ]

Editing a Binary File

Title:
Date: 2023-12-17
Tags:  sysadmin, hacking

These are my notes on editing a binary file using vim. A bit cumbersome but it worked well enough to hack the R83 disks.

These are my notes on editing a binary file using vim. A bit cumbersome but it worked well enough to hack the R83 disks to skip the copyright protection.

The first step is open the binary file in vim and set the mode to binary.

:set binary

If you don't do this, vim will corrupt the file as it is treating everything as text and converting things.

Once the file is opened you can use xxd to get into a hexadecimal view of the file. This will display the raw data on the right and on the left will be a textual representation. Only the changes on the hexadecimal side, the left side, will be kept.

%!xxd

An example screen:

1 00000000: e972 0000 0000 0000 5238 3320 332e 3120  .r......R83 3.1 
2 00000010: dc65 0000 0000 0201 46bf 94d1 4c43 3309  .e......F...LC3.
3 00000020: 0009 1200 0000 0000 7800 0000 0000 0000  ........x.......

Make sure not to save in this mode as it will save the xxd data!

To exit xxd after making changes:

%!xxd -r

This will bring you back to the binary view of the file.

Now you can save the file using vim.

:w

You can also save the modified file to a new file:

%!xxd -r > patched.binary.img