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/

After reducing the $max value down to 32766 to keep the RE happy it fails to find 'This program cannot be run in DOS mode' which it certainly should:

C:\>strings.pl myscript.exe RES> .text `.rdata @.data 5@e@ C:\>type strings.pl my( $min, $max ) = ( 4, 32766 ); local( $/ ) = \(32*1024); my $prev = ''; while( <> ) { $prev .= $_; while( $prev =~ /([\n\t -~]{$min,$max})\0/g ) { print "$1\n"; } $prev =~ s/.*\0//s; }

The bug (on win32 and Mac) is not allowing \r. BTW it took me about 5 minutes to realise what ' -~' was doing :-) I have written it longhand octol for slow learners like me. There is a CRLF before the terminating $ in the assembly.

C:\>strings.pl myscript.exe !This program cannot be run in DOS mode. $ RES> .text `.rdata @.data 5@e@ C:\>type strings.pl my( $min, $max ) = ( 4, 32766 ); local( $/ ) = \(32*1024); my $prev = ''; while( <> ) { $prev .= $_; while( $prev =~ /([\t\r\n\040-\176]{$min,$max})\0/g ) { print "$1\n"; } $prev =~ s/.*\0//s; } C:\>

cheers

tachyon


In reply to Re^3: Portable way to extract string from a binary (strings.pl) by tachyon
in thread Portable way to extract string from a binary by mpeppler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.