in reply to how to search binary file
#/!usr/bin/perl use warnings; use strict; @ARGV or die "usage: $0 file\n"; my $file = shift @ARGV; open my $fh, "<", $file or die "unable to open file"; binmode $fh; # disable "\n" translation my $data; { local $/=undef; $data=<$fh>; } my $pattern=pack('CC', 0xff, 0xd9); my $at=index($data, $pattern); if ($at<0) { print "pattern not found\n" } else { print "pattern found at pos $at\n" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to search binary file
by Roy Johnson (Monsignor) on Apr 25, 2005 at 16:55 UTC | |
by ikegami (Patriarch) on Apr 25, 2005 at 17:18 UTC |