Find the answer to your Linux question:
Results 1 to 6 of 6
hi ! i need a help to change a binary file, let's say to find and replace username: find string: "/home/name/bla-bla-bla/ " new string: "/home/anewname/bla-bla-bla/ " i can do it, ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    11

    search and replace in a binary file

    hi !

    i need a help to change a binary file, let's say to find and replace username:

    find string: "/home/name/bla-bla-bla/ "
    new string: "/home/anewname/bla-bla-bla/ "

    i can do it, for example, in emacs (hexl-mode), but interesting in writing a script instead. it will be much more better for me if i could do it automatically.

    is there an analog of: sed 's/string1/string2/g' ?

    P.S. the best way is to recompile the binary files i have, but there are no sources available.

  2. #2
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    It depends greatly on whether the binary file has other properties that must not be changed when you replace the string. Such as a fixed length, or a required checksum.

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    11
    thank you for your reply. i solved the problem. the simple SED works perfectly in my case, i only need to check that the length remains fixed. that was the actual problem... my stupid

    now i can do all i want in a very simple way!

  4. #4
    Just Joined! jippie's Avatar
    Join Date
    May 2006
    Location
    Eindhoven, the Netherlands
    Posts
    76
    If you have root access, create a symlink if all you want to do is change the path to a home directory:

    ln -s /home/name /home/anewname

  5. #5
    Linux Newbie unlimitedscolobb's Avatar
    Join Date
    Jan 2008
    Posts
    120
    Quote Originally Posted by mors123456 View Post
    the simple SED works perfectly in my case, i only need to check that the length remains fixed.
    In most cases you can also substitute with shorter zero-padded strings, unless the program expects a different string terminator character.

  6. #6
    Just Joined!
    Join Date
    Dec 2008
    Posts
    11
    thank you for the answers.

    to jippie: that is clearly an option, i'll keep it mind

    to unlimitedscolobb: yes, agree. that is how i finally did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...