View Single Post
  #1   (View Single Post)  
Old 22nd October 2016
jb_daefo jb_daefo is offline
Spam Deminer
 
Join Date: May 2008
Posts: 303
Default new perl code from web

Found on perlmonks.org today...

One can check ascii from binaries, for example manpages
embedded and/or .so. files found as dependencies

Might be a duplicate of a tool in base.

Usage:
perl [ program below.pl] [binary ]

Code:
#!perl

use 5.010_000;
use warnings;
use strict;

if ((@ARGV < 1))
{
	$0 =~ m#([^\\/]+$)#;
	my $name = $1 // $0;
	print STDERR "$name file ...\n" . <<'_DESCRIPTION_';
	Extract ASCII strings from files listed. Multiple files allowed.
_DESCRIPTION_
	exit 1;
}

for my $file (@ARGV)
{
	open my $fh, '<:bytes', $file or die "Error: Can't open '$file': $!\n";
	my $buf;
	while (read $fh, $buf, 1024)
	{
		my @strings = split /\P{PosixGraph}/, $buf;
		for (@strings)
		{
			next if /^\s*$/;
			print "$_\n";
		}
	}
}
__________________
FreeBSD 13-STABLE
Reply With Quote