LinuxQuestions.org
Visit Jeremy's Blog.
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, 03: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, 03:06 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
cat <filename> | hexdump -C | grep <pattern>
 
Old 04-07-2009, 03: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, 04:00 PM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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 04:01 PM.
 
Old 04-07-2009, 04:27 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
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 03:52 AM
BASH: Grepping/sedding/etc out part of a file... (from one word to 'blank' line) elinenbe Programming 2 12-11-2008 02:17 PM
grepping from a particular key positions of a file. visitnag Linux - Newbie 5 08-30-2008 08:00 PM
Grepping a file for Text going down. keysorsoze Linux - Newbie 3 01-17-2007 10:06 AM
How to add some bytes to a binary file? kornerr Linux - General 6 02-28-2006 12:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration