Re: Editing Binary Files
From: laura fairhead (run_signature_script_for_my_email_at_INVALID.com)
Date: 11/01/05
- Previous message: Chet Ramey: "[gnu.bash.bug] BASH Frequently-Asked Questions (FAQ version 3.30)"
- Next in thread: Neil Woods: "Re: Editing Binary Files"
- Maybe reply: Neil Woods: "Re: Editing Binary Files"
- Reply: Chris Cox: "Re: Editing Binary Files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 1 Nov 2005 00:39:21 +0000 (UTC)
On 29 Oct 2005 13:29:35 -0700, "Tulasi" <tulasinandan@gmail.com> wrote:
>Hi!
> I am just an end user for linux/unix. I want to edit a precompiled
>binary to change the locations /usr/local etc. to some other location.
>e.g. In the code, they might have specified /usr/local/share for share
>files but I want to change it to ../share I tried to open and edit the
>file in some editors (vi, bvi). First of all I do not understand all
>the crazy stuff there. I just tried to look for /usr/local and replace
>it by ../ but it did not work. Could anyone please tell me how to do it
>and some place with a good tutorial on understanding and editing binary
>files?
>
>Thanks,
>Tulasi
>
>P.S. Although there is always the option of compiling the source but I
>just want to learn editing binary files :)
Hi,
The usual shell tools aren't really designed for working
with binary data, the only thing you can possibly get away
with is using a combination of awk/od/uuencode as follows;
(1) dump file with od, -v -An -txC for hex-byte output
pipe that into
(2) 'awk' script which searches for the pattern you are
trying to match (here '/usr/local/share\0' ).
It will have to convert all the ascii characters to
binary hexadecimal to do this. You can keep a buffer
(size specified in the script itself) which is a window
on the incoming hex-text-data and run a "match()" to look
for your search expression. When found the output can
be replaced with whatever (pressumably '../share\0\0\0\0\0\0\...')
pipe that into
(3) a shell script that make's a uuencoded output stream
from incoming hex-text-data
pipe that into
(4) uudecode
So, essentially 'od' is used to get the binary data into text form
it is then processed and 'uudecode' is used to get the text back
into binary.
Of course this is all _totally nuts_; I used this method and posted
a full solution to do binary search/replace on USENET ages ago
if you really have to do it that way google for the source....
BUT it's much better to use a tool that can handle the job: _perl_
Just open the file in binmode (for reading), read the whole
thing into a variable, do the s/// substituion, output the
result and dump it out :-) Probably an 8 line program
although maybe some of the folks on comp.lang.perl.* can
do it in a lot less ;-)
byefornow
laura
-- echo alru_aafriehdab@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'
- Previous message: Chet Ramey: "[gnu.bash.bug] BASH Frequently-Asked Questions (FAQ version 3.30)"
- Next in thread: Neil Woods: "Re: Editing Binary Files"
- Maybe reply: Neil Woods: "Re: Editing Binary Files"
- Reply: Chris Cox: "Re: Editing Binary Files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|