Re: Editing Binary Files

From: laura fairhead (run_signature_script_for_my_email_at_INVALID.com)
Date: 11/01/05

  • Next message: Neil Woods: "Re: Editing Binary Files"
    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'
    

  • Next message: Neil Woods: "Re: Editing Binary Files"

    Relevant Pages

    • Re: update
      ... You did not edit the code correctly. ... David Mustard wrote: ... effectivly rather than keeping them all together as a publisher website. ... replaceinfiles script wont work for this kind of setup I dont think. ...
      (microsoft.public.publisher.webdesign)
    • Re: fileevent and vwait dilema with one tcl script calling multiple copies of another
      ... pies of each script. ... loop *IS* the event loop and the 'main program' has no loop at all. ... # Event proc: file read event. ... proc Reader {pipe} { ...
      (comp.lang.tcl)
    • accessing a pipe from TCL and C, hang in `close/exit
      ... I have a TCL shell script which opens a socket to some remote host, ... and opens a read-converter pipe. ... data arrives on the remote host. ... Now I want to close the channel from C++: ...
      (comp.lang.tcl)
    • I can process my mail!
      ... I figured out how to pipe mail to my own scripts! ... the script as an argument. ... that won't confuse boundaries for message text. ... sendmail, but I'm not that interested in sendmail in particular. ...
      (comp.unix.questions)
    • Re: IO::Pipe and loss of data
      ... May be I cut too much, but as the last run of my big script was ... > show at least how I work to send a message and use the pipe. ... There is a fixed amount of buffer (probably 4K ... for each "server". ...
      (comp.lang.perl.misc)