LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-07-2009, 02:01 PM   #1
precision
LQ Newbie
 
Registered: Mar 2004
Location: Toronto, ON
Distribution: Debian
Posts: 18

Rep: Reputation: 0
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?
 
Old 04-07-2009, 02:06 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Just found a binary grep C code at http://debugmo.de/?p=100. You can give it a try.
 
Old 04-07-2009, 02:21 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
cat <filename> | hexdump -C | grep <pattern>
 
Old 04-07-2009, 02:26 PM   #4
precision
LQ Newbie
 
Registered: Mar 2004
Location: Toronto, ON
Distribution: Debian
Posts: 18

Original Poster
Rep: Reputation: 0
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?
 
Old 04-07-2009, 03:00 PM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Quote:
Originally Posted by precision View Post
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.

Last edited by H_TeXMeX_H; 04-07-2009 at 03:01 PM.
 
Old 04-07-2009, 03:27 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
Also see manpages for strings(1).

Example: $ strings /bin/ls
 
  


Reply

Tags
binary, grep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grepping a log file graziano1968 Linux - General 11 12-08-2011 02:52 AM
BASH: Grepping/sedding/etc out part of a file... (from one word to 'blank' line) elinenbe Programming 2 12-11-2008 01:17 PM
grepping from a particular key positions of a file. visitnag Linux - Newbie 5 08-30-2008 07:00 PM
Grepping a file for Text going down. keysorsoze Linux - Newbie 3 01-17-2007 09:06 AM
How to add some bytes to a binary file? kornerr Linux - General 6 02-28-2006 11:23 AM


All times are GMT -5. The time now is 04:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration