in reply to Portable way to extract string from a binary

C:\>perl -ne "print $1,$/ while m/([\w ]{2,})/gc" myscript.exe MZ This program cannot be run in DOS mode efx Rich PE RES text rdata data C:\>

Add whatever you want to the character class according to your definition of a string :-)

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Portable way to extract string from a binary (strings.pl)
by tye (Sage) on Jul 14, 2004 at 16:44 UTC

    To match strings(1) as I'm used to, you'd want something like:

    my( $min, $max ) = ( 4, 32*1024 ); local( $/ ) = \(32*1024); my $prev = ''; while( <> ) { $prev .= $_; while( $prev =~ /([\n\t -~]{$min,$max})\0/g ) { print "$1\n"; } $prev =~ s/.*\0//s; }

    Though I notice that strings(1) on FreeBSD replaces the "followed by '\0'" with "followed by an unprintable character", which my testing finds to be a disadvantage (at least it should be made optional).

    - tye        

      Hmm, while I take your point about looking for null termination the code you present does not work for me. The first issue is this:

      C:\>strings.pl myscript.exe Quantifier in {,} bigger than 32766 before HERE mark in regex m/([\n\t + -~]{ << HERE 4,32768})\0/