[ale] Binary Grep

Fletch fletch at phydeaux.org
Tue Nov 16 21:33:23 EST 2004


>>>>> "Geoffrey" == Geoffrey  <esoteric at 3times25.net> writes:

    Geoffrey> Greg Freemyer wrote:
    >> Does anyone know of a grep like tool that works for binary
    >> files?  In particular, I have a binary file I want to find all
    >> occurrances of 16 hex FF chars in a row.  ie.  0xFF, 0xFF,
    >> 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    >> 0xFF, 0xFF, 0xFF, 0xFF It would be great if it also provided
    >> some surrounding detail, but at a minimum I need the offset in
    >> the file.  Thanks Greg

    Geoffrey> Man I keep getting great ideas. :) use perl?

But of course!

$ perl -le 'print "a" x 2048, "b" x 512, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024} print "hit byte ", ($.-1) * 1024 + $-[0] if /\xff{16}/' foo
hit byte 2560
$ perl -le 'print "a" x 2048, "b" x 1512, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024} print "hit byte ", ($.-1) * 1024 + $-[0] if /\xff{16}/' foo
hit byte 3560


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list