Is there a command line Linux tool that will find and replace Hex representation of data in a binary file? Example Usage?

For example: 's/00FF00FFFF06500B49/11BB00BFFF06500B49/g'

  • There's a similar question here. – Paused until further notice. Apr 9 '10 at 19:18
  • @Dennis Williamson, Agreed but those answers are more programmatic then an expected answer on ServerFault (i.e. several include non-sed/awk source code). – mctylr Apr 9 '10 at 19:35

Perl Scirpt:

my $find_packed = pack "H*", '0100000000000000FF0A16731485400000000000FFA10201FF22FFFFFFFF0200';
my $repl_packed = pack "H*", '0100000000000000FF0A16731485400010FFC545FFA10201FF22FFFFFFFF0200';
my $file = do { local $/; <> };
$file =~ s/\Q$find_packed/$repl_packed/g;
print $file;


perl hexreplace.pl in_binary > out_binary

The above unpolished version seems to have worked for me, thanks to the guys in #perl on freenode :-)

| improve this answer | |
  • I'm deleting my post about sed, it's not the right tool for this, sorry. – kbyrd Apr 9 '10 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.