Editing Binary Files - Unix

This is a discussion on Editing Binary Files - Unix ; 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 ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Editing Binary Files

  1. Editing Binary Files

    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


  2. Re: Editing Binary Files

    thanks for the quick reply Bill!! could you please tell me some place
    to get started with these things? btw I do not have root permission, so
    I do not know whether I will be able to do chroot or not. thanks once
    again.


  3. Re: Editing Binary Files

    On 2005-10-29, Tulasi 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


    No, you don't. _especially_ if you're not "just an end user".
    There's rarely a good reason to modify application binaries.

    in any case, the file has to have everything in the same place.
    which means your strings have to be the same length, so like if it
    says

    /usr/local/share/something^@
    you want to change it to
    .../share/something^@^@^@^@^@^@^@^@^@

    out of curiosity, where do you expect ".." to be? the previous
    directory from where the application binary is? from where the user
    starts the program. it's not guaranteed to be either.

  4. Re: Editing Binary Files

    Thanks for the reply Jordan. First of all It is just out of curiosity
    that I want to learn a little bit of tweaking around with binary files.
    To be exact it is some precompiled binary which is meant to be in
    /usr/local/bin with share files in /usr/local/share. As I do not have
    root permissions on the machine I work, I just wanted to play around
    with the precompiled binary instead of recompiling the source. The ".."
    refers to the previous directory where I want to keep my application
    binary so that it looks for share files in the directory
    $BINDIR/../share. I think I can fix the $BINDIR somewhere in home and
    then I could use appropriate value for ".." but in case the new string
    becomes more inlength than the original then do I delete some of the
    ^@'s before that expression? what if there are not enough ^@s just
    before that expression?

    Do you know of some other way around this problem could be handled?
    Also as I have requested Bill too, could you please tell me some place
    to get started with such stuff as assembly language and handling binary
    files?

    thanks,
    Tulasi


  5. Re: Editing Binary Files

    On 2005-10-30, Tulasi wrote:
    > Thanks for the reply Jordan. First of all It is just out of
    > curiosity that I want to learn a little bit of tweaking around
    > with binary files. To be exact it is some precompiled binary
    > which is meant to be in /usr/local/bin with share files in
    > /usr/local/share. As I do not have root permissions on the machine
    > I work, I just wanted to play around with the precompiled binary
    > instead of recompiling the source. The ".." refers to the previous
    > directory where I want to keep my application binary so that it
    > looks for share files in the directory $BINDIR/../share. I think I
    > can fix the $BINDIR somewhere in home and then I could use
    > appropriate value for ".." but in case the new string becomes more
    > inlength than the original then do I delete some of the ^@'s
    > before that expression? what if there are not enough ^@s just
    > before that expression?


    The beginning has to be in the same place. You should really
    recompile. Editing binaries is generally a bad idea for anyone

    Generally it should only be using files it only reads from from
    /usr/local/share anyway - is the program not installed or what?

    > Do you know of some other way around this problem could be handled?


    by recompiling

  6. Re: Editing Binary Files

    Tulasi wrote:
    > Thanks for the reply Jordan. First of all It is just out of curiosity
    > that I want to learn a little bit of tweaking around with binary files.
    > To be exact it is some precompiled binary which is meant to be in
    > /usr/local/bin with share files in /usr/local/share. As I do not have
    > root permissions on the machine I work, I just wanted to play around
    > with the precompiled binary instead of recompiling the source. The ".."
    > refers to the previous directory where I want to keep my application
    > binary so that it looks for share files in the directory
    > $BINDIR/../share. I think I can fix the $BINDIR somewhere in home and
    > then I could use appropriate value for ".." but in case the new string
    > becomes more inlength than the original then do I delete some of the
    > ^@'s before that expression? what if there are not enough ^@s just
    > before that expression?
    >
    > Do you know of some other way around this problem could be handled?
    > Also as I have requested Bill too, could you please tell me some place
    > to get started with such stuff as assembly language and handling binary
    > files?
    >
    > thanks,
    > Tulasi
    >

    how about the hex editors..I guess they can be of some or little help to
    you. Just check in for any hex editors for your platform and get started

    Regards.
    Nikhil

  7. Re: Editing Binary Files

    On 29 Oct 2005 13:29:35 -0700, "Tulasi" 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'

  8. Re: Editing Binary Files

    >>>>> Tulasi writes:

    > 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?


    If you *really* want to do this, and fully understand the consequences
    of doing so, then one of the easiest ways is to directly edit the file
    within emacs using hexl-mode.

    > P.S. Although there is always the option of compiling the source but I
    > just want to learn editing binary files


    It's much better to edit the source, as others have already commented.

    --
    Neil.
    Used staples are good with SOY SAUCE!

  9. Re: Editing Binary Files

    laura fairhead wrote:
    > On 29 Oct 2005 13:29:35 -0700, "Tulasi" 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 ;-)


    perl -pi -e 's/something/nothing/g' file...

    (make sure to tack a null onto "nothing" if not the
    same length as "something")

+ Reply to Thread