Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: dynamic extractor based off static references in file (perl)

by james289o9 (Acolyte)
on Dec 06, 2013 at 08:38 UTC ( [id://1065926]=note: print w/replies, xml ) Need Help??


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

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
  • Comment on Re^4: dynamic extractor based off static references in file (perl)
  • Download Code

Replies are listed 'Best First'.
Re^5: dynamic extractor based off static references in file (perl)
by Anonymous Monk on Dec 06, 2013 at 09:03 UTC
      $buffer stores the reference to where the actual data is in the file.
      so it will look like this:
      my $buffer = ''; sysseek $file, 0x15, 0; sysread $file, $buffer, 0x03; syswrite $outfile, $buffer;
      And 0x15 is the reference to the actual data in this file. this code will get that reference and store it in $buffer.
      What I want to be able to do is use $buffer in sysseek like this:
      sysseek $file, $buffer, 0;
      as opposed to:
      sysseek $file, 0x400, 0;
        This is what i got from data::dumper
        $VAR1 = ' ♦└';

        So I guess it is not a numerical value. I need to get "' ♦└'" into its binary form
        This is what i got from data::dumper
        $VAR1 = ' ♦└';

        So I guess it is not a numerical value. I need to get "' ♦└'" into its binary form. I already have the endianess worked out.
Re^5: dynamic extractor based off static references in file (perl)
by Anonymous Monk on Dec 06, 2013 at 11:29 UTC

    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&" );# ()
      Here is my 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 $buffer = ''; sysseek $infile, 0x15, 0; sysread $infile, $buffer, 0x03; syswrite $outfile, $buffer; $buffer =~ s/(.)/sprintf("%x",ord($1))/eg; #this converts it into hex. print $buffer, "\n"; #this prints the converted $buffer (04C0)
      Maybe I am trying to go about this the wrong way.
      $buffer = (04C0)
      It would be really nice to be able to use $buffer like this but I dont think its possible that way:
      sysseek $infile, $buffer, 1; sysread $infile, $new, 0x40000; syswrite $newfile, $new;
      Remember that $buffer contains the 04C0, which is a reference to the actual data further into the file. so I get the reference values with this:
      my $buffer = ''; sysseek $infile, 0x15, 0; sysread $infile, $buffer, 0x03; syswrite $outfile, $buffer;
      Then I try to sysseek to that position in the file like this, using the reference i obtained with the code above:
      sysseek $infile, $buffer, 1; sysread $infile, $new, 0x40000; syswrite $newfile, $new;
      Also Anonomous Monk, please let me thank you for the help so far. Im not exactly pro at programming, but I know how i want it to work, I am just having a hard time setting this up to work. I feel like i am going in circles now.
        Thank you all for helping. i finally got it to work like this:
        # this gets the reference to the actual data in the file my $buffer = ''; sysseek $infile, 0x15, 0; sysread $infile, $buffer, 0x03; $buffer =~ s/(.)/sprintf("%x",ord($1))/eg; # this will move the CUR to the actual data as specified from the refe +rence and will extract it to file. open(my $newfile, '>', "./file"); my $new; sysseek $infile,hex($buffer), 0; sysread $infile, $new, 0x40000; syswrite $newfile, $new;

        If you notice in the second set of sysseek, i had to hex($buffer). That solved the problem and allowed me to input "04C0" i am now extracting the data successfully.
        Thanks to everyone who took their time to help me :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1065926]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found