LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   grepping through a binary file for a sequence of bytes (http://www.linuxquestions.org/questions/linux-software-2/grepping-through-a-binary-file-for-a-sequence-of-bytes-717503/)

precision 04-07-2009 03:01 PM

grepping through a binary file for a sequence of bytes
 
Is it possible to use grep to search for a sequence of bytes? For instance say I was looking for the following byte sequence in a file:

64 03 40 30 ; add eax, fs:[eax+30h]

Is this possible to do using grep?

colucix 04-07-2009 03:06 PM

Just found a binary grep C code at http://debugmo.de/?p=100. You can give it a try.

pixellany 04-07-2009 03:21 PM

cat <filename> | hexdump -C | grep <pattern>

precision 04-07-2009 03:26 PM

bgrep works very well for what I am trying to do.

Question about the second response - will this work if the bytes span a line in hexdump ie they are in position ?F then ?0 on the next line?

H_TeXMeX_H 04-07-2009 04:00 PM

Quote:

Originally Posted by precision (Post 3501575)
bgrep works very well for what I am trying to do.

Question about the second response - will this work if the bytes span a line in hexdump ie they are in position ?F then ?0 on the next line?

nope

As for bgrep, it's interesting, I kinda made my own for a specific purpose. Now if only it supported regular expressions. Probably using perl is better idea.

anomie 04-07-2009 04:27 PM

Also see manpages for strings(1).

Example: $ strings /bin/ls


All times are GMT -5. The time now is 10:17 PM.