#----------------------------- |
$old_rs = $/; # save old $/ |
$/ = "\0" ; # NULL |
seek (FH, $addr , SEEK_SET) or die "Seek error: $!\n" ; |
$string = <FH>; # read string |
chomp $string ; # remove NULL |
$/ = $old_rs ; # restore old $/ |
#----------------------------- |
{ |
local $/ = "\0" ; |
# ... |
} # $/ is automatically restored |
#----------------------------- |
# download the following standalone program |
#!/usr/bin/perl |
# bgets - get a string from an address in a binary file |
use IO::Seekable; |
( $file , @addrs ) = @ARGV or die "usage: $0 addr ..." ; |
open (FH, $file ) or die "cannot open $file: $!" ; |
$/ = "\000" ; |
foreach $addr ( @addrs ) { |
$addr = oct $addr if $addr =~ /^0/; |
seek (FH, $addr , SEEK_SET) |
or die "can't seek to $addr in $file: $!" ; |
printf qq{% #x %#o %d "%s"\n}, $addr, $addr, $addr, scalar <>; |
} |
#----------------------------- |
# download the following standalone program |
#!/usr/bin/perl |
# strings - pull strings out of a binary file |
$/ = "\0" ; |
while (<>) { |
while (/([\040-\176\s]{4,})/g) { |
print $1 , "\n" ; |
} |
} |
#----------------------------- |