in reply to Re: dynamic extractor based off static references in file (perl)
in thread dynamic extractor based off static references in file (perl)

I have this code so far:
open(my $infile, '<', "./file") or die "Cannot open file: $!"; binmode($infile); open(my $outfile, '>', "./reference1") or die "Cannot create file: $!" +; binmode($outfile); my $file = $infile; my $buffer = ''; sysseek $file, 0x15, 0; sysread $file, $buffer, 0x03; syswrite $outfile, $buffer; close $outfile; system ( 'pause' );
I can get the first reference and I should be able to get the second reference without trouble. I am having problems figuring out how to put the $buffer into $reference.
i tried this but it didnt work to well ofcourse:
my $reference = $buffer; print $reference;
it prints the data from $infile, but not in binary form. i guess my question really is, how can i put $buffer (binary data) into $location? any clarifications on what to do would be very much appreciated.

Replies are listed 'Best First'.
Re^3: dynamic extractor based off static references in file (perl)
by Anonymous Monk on Dec 06, 2013 at 08:19 UTC

    it prints the data from $infile, but not in binary form

    Sure it does, you used binmode on both filehandles, you read the data, its binary form, there is no doubt; if you need a different format you'll need to do something about it

      Yes sir, and that happens to be where im stuck at. when i try to put the $buffer (location) into the variable $reference, it works. but when i try to use $location in sysseek i gives me the error:
      Argument "\0^D&" isn't numeric in sysseek

        Argument "\0^D&" isn't numeric in sysseek

        Based on those bytes/octets, to turn them a "number", it all depends on what kind ... see pack, unpack, perlpacktut

        Just guessing at the right one (guessing is bad, knowing is better)

        use Data::Dump qw/ dd pp /; dd( unpack q{c*}, "\0^D&" );# (0, 94, 68, 38) dd( unpack q{C*}, "\0^D&" );# (0, 94, 68, 38) dd( unpack q{W*}, "\0^D&" );# (0, 94, 68, 38) dd( unpack q{s*}, "\0^D&" );# (24064, 9796) dd( unpack q{S*}, "\0^D&" );# (24064, 9796) dd( unpack q{l*}, "\0^D&" );# 642014720 dd( unpack q{L*}, "\0^D&" );# 642014720 dd( unpack q{i*}, "\0^D&" );# 642014720 dd( unpack q{I*}, "\0^D&" );# 642014720 dd( unpack q{n*}, "\0^D&" );# (94, 17446) dd( unpack q{N*}, "\0^D&" );# 6177830 dd( unpack q{v*}, "\0^D&" );# (24064, 9796) dd( unpack q{V*}, "\0^D&" );# 642014720 dd( unpack q{q*}, "\0^D&" );# () dd( unpack q{Q*}, "\0^D&" );# ()