Binary file pattern search - Unix

This is a discussion on Binary file pattern search - Unix ; Not sure I post this in the right group. Is there a Unix/Linux application that searches a binary file for a pattern and report the byte offset where this pattern is found and where it ends. The pattern may exist ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Binary file pattern search

  1. Binary file pattern search

    Not sure I post this in the right group.

    Is there a Unix/Linux application that searches a binary file for a
    pattern and report the byte offset where this pattern is found and
    where it ends. The pattern may exist multiple times and I need all
    offsets.

    Any ideas or do I need to write my own program?

    /P

  2. Re: Binary file pattern search

    Pal Hulden wrote:
    > Is there a Unix/Linux application that searches a binary file for a
    > pattern and report the byte offset where this pattern is found and
    > where it ends. The pattern may exist multiple times and I need all
    > offsets.
    >
    > Any ideas or do I need to write my own program?


    I wrote a similar program years ago (in C).
    My program has no "pattern matching" and just looks for the text
    you give it to search for in the binary (or not) file, and gives
    back the offset where it finds the string.

    There *is* a bug with it, if you look for "aab" and the file
    has "aaab" it does not find it. Oh well. I know about this, and
    if I ever what to look for such patterns I'll remember.

    Feel free to take my code, change it, whatever. If it breaks
    anything of yours, too bad. It's there to help you out, or to
    just give a hint on how you can write something better:
    http://www.dongrays.com/tools/
    It's called "pos", from all the other code I have out there.

    I think perhaps "strings" might help you out. Read the man page.


  3. Thumbs up Re: Binary file pattern search

    In linux try:
    grep -Ubo --binary-files=text 'pattern' filename

    Here is a sample output

    $ grep -Ubo --binary-files=text 'Configuration' myfile.odt
    107:Configuration
    163:Configuration
    234:Configuration
    288:Configuration
    344:Configuration

+ Reply to Thread