Results 1 to 4 of 4
I can use hexedit to manually edit one or two hex values in a binary file, but if I want to change many of the, this is impractical. Is there ...
- 11-11-2010 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 41
Modifying hex values from a script
I can use hexedit to manually edit one or two hex values in a binary file, but if I want to change many of the, this is impractical. Is there any tool that will take parameters like
?Code:someTool filename byteNumber replacementByte
Thanks,
David
- 11-12-2010 #2Just Joined!
- Join Date
- Sep 2006
- Location
- Norfolk Island
- Posts
- 31
You could try awk, it's bloody powerful, but I've never actually cracked it in any real sense..... Personally I would write a quick perl script.
for a quick & dirty, have it move the file to .bak (or whatever), open the file, read binary char by char, output to the original filename & replace the char you want when it gets to it.
This code has basics you need to proccess the files & deal with the hex chars. You can fill it out for full function:
cheersCode:open INFILE, "$infile"; binmode (INFILE); open OUTFILE,">$outfile"; binmode (OUTFILE); $replace=pack("H2",$hextext); while (read(INFILE, $buffer, 1)){ $data = sprintf("%02X",ord($buffer)); $charcount++; if ($charcount == $location){ print OUTFILE $replace; }else{ print OUTFILE pack("H2",$data); } } close INFILE; close OUTFILE;
- 11-12-2010 #3
Ni_boy, is the script you've given in bash, PERL or AWK?
- 11-13-2010 #4Just Joined!
- Join Date
- Sep 2006
- Location
- Norfolk Island
- Posts
- 31
perl.
obviously you'll need to do you own variable assignment, etc.
Also, that's basically pulled from something I wrote where I was scanning files. If you wanted to replace a single byte in a specific loc there's probably a function for it in perl when writing binary mode, so the script could be a lot simpler.
cheers


Reply With Quote