Hi, I'm looking for a way to replace a few bytes in a binary file from a script. Something similar to MS debug's e command through an input file.
The binary file is a boot sector but the values need to be changed for different disk types. I could write a small C program to do this easily but I'm wondering if it's possible to do from a script/makefile command line under linux.
This is only a temp solution until the full mkfs code is written to use the boot sector.
Thanks for any help.
Replacing values in a binary file
Replacing values in a binary file
"God! Not Unix" - Richard Stallman
Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Re: Replacing values in a binary file
Have a look at xxd command.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Replacing values in a binary file
Hex editor.
Re: Replacing values in a binary file
Depending on what exactly you're planning to do, you could plant "marker" values in the binary, i.e. character sequences you know for sure won't appear in the file legally, and search & replace them using sed.
At least, that's what I would do.
At least, that's what I would do.
Every good solution is obvious once you've found it.
Re: Replacing values in a binary file
Code: Select all
hexdump -Cv < myfile.bin > myfile.dump # makes a hex dump of the file
Then :
Code: Select all
hexdump -R < myfile.dump > myfile.bin.modified # makes a file out of the hex dump
Code: Select all
dd if=patch.bin bs=1 seek=<offset in myfile.bin> of=myfile.bin conv=notrunc # optionnaly add : count=<length of patch>
IIRC, you can get the position in the file of a specific function or whatever by using objdump and grepping through it. That might be usefull for method 1 (hexdump).
Re: Replacing values in a binary file
I've started a project called hexed for a solution to this.
Info will be updated here http://forum.osdev.org/viewtopic.php?f= ... 42&start=0
Info will be updated here http://forum.osdev.org/viewtopic.php?f= ... 42&start=0
"God! Not Unix" - Richard Stallman
Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed