[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Wed Nov 17 13:35:28 2004 -->
- <!--x-from-r13: syrgpu ng culqrnhk.bet (Tyrgpu) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Binary Grep -->
- <li><em>date</em>: Wed Nov 17 13:35:28 2004</li>
- <li><em>from</em>: fletch at phydeaux.org (Fletch)</li>
- <li><em>in-reply-to</em>: <<a href="msg00756.html">[email protected]</a>> (Greg Freemyer's message of "Wed, 17 Nov 2004 12:31:35 -0500")</li>
- <li><em>references</em>: <[email protected]> <<a href="msg00756.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Binary Grep</li>
[...]
Greg> I was so impressed with Perl and Fletch that it could do
Greg> this in a single line.
Greg> I don't speak Perl at all, so I did not realize he was only
Greg> scanning 1K blocks and any patterns that crossed the
Greg> boundary were ignored. (I assume that is the issue you
Greg> found.)
Hey, pay no attention to that match split across buffer boundaries. :)
That of course was the quick and dirty one-liner that catches most
cases. (Yeah, that's the ticket . . .) To really do it right you
want to append into a buffer and search that buffer each time, then
clear all but the last (patternlength-1) characters from your buffer
before the next iteration.
That'd look something akin to:
$ perl -le 'print "a" x 2047, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 2047
$ perl -le 'print "a" x 2040, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 2040
Of course genericising this (and dealing with figuring out the longest
possible length string that an arbitrary regex could match) is left as
an exercise for the reader . . . :)
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00765" href="msg00765.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> jkinney at localnetsolutions.com (James P. Kinney III)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00753" href="msg00753.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> joe at madewell.com (Joe Steele)</li></ul></li>
<li><strong><a name="00756" href="msg00756.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> greg.freemyer at gmail.com (Greg Freemyer)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00756.html">[ale] Binary Grep</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00758.html">[ale] problems with Cendyne 32x10x40 USB CD-RW with SUSE 9.2 and FC3</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00756.html">[ale] Binary Grep</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00765.html">[ale] Binary Grep</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00757"><strong>Date</strong></a></li>
<li><a href="threads.html#00757"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>