Hello,

I am playing around with my NAS and have this qpkg package that I want to split on my Windows machine. The qpkg package is just too much to post here but roughly it consists of:

...sh script... something.tar.gzNULNULNUL...bunch tarball here....7z¼¯' ...bunch of +7z compressed material here...NULNULBS=MIME-Version: 1.0 ... base64 e +ncoded material here...

The sh script has lines:

script_len=3265 /bin/dd if="${0}" bs=$script_len skip=1 | /bin/tar -xO | /bin/tar -xzv + -C $_EXTRACT_DIR || exit 1 offset=$(/usr/bin/expr $script_len + 20480) /bin/dd if="${0}" bs=$offset skip=1 | /bin/cat | /bin/dd bs=1024 count +=26 of=$_EXTRACT_DIR/data.tar.7z || exit 1 [ -f /usr/local/bin/python ] && /usr/local/bin/python -c "with open('$ +_EXTRACT_DIR/data.tar.7z', 'rw+') as f: f.seek(26585); f.truncate()" offset=$(/usr/bin/expr $offset + 26585)

From that I calculated the following start positions:

0, 3265, 3265+20480, 3265+20480+26585

So I wrote a quick script to extract this stuff, but now I notice substr giving me trouble, most of the time it seems to output too many characters. But the start positions seems to be ok. I don't understand why. Any ideas?

#!/usr/bin/perl use strict ; use warnings ; use File::Basename ; # binmode(STDOUT, ":utf8"); my $fn = $ARGV[0] ; ( my $fns, my $fp, my $fs ) = fileparse( $fn, qr/\.[^.]*/ ) ; # print "fns = $fns, fp = $fp, fs = $fs\n" ; my $fc ; { local $/ ; # slurp # ? '<:encoding(utf8)' # open (my $fh, '<:encoding(utf8)', $fn ) or die "Failed to open f +ile $fn with error: $!\n" ; open (my $fh, '<', $fn ) or die "Failed to open file $fn with erro +r: $!\n" ; binmode $fh ; # Edit suggestion Anonymous Monk on Feb 14, 2021 at +21:31 UTC $fc = <$fh> ; close $fh ; } my $number = 'x' ; my @numbers ; while ( $number ne '' ) { print "Type number where to split: " ; $number = <STDIN> ; chomp $number ; push( @numbers, $number ) unless $number eq '' ; } my $start = 0 ; for my $i (0 .. $#numbers) { print "$i: $numbers[$i]\n" ; my $fn2 = $fp . $fns . "." . ($i+1) ; open (my $fh, ">", $fn2 ) or die "Failed to open file $fn2\n" ; binmode $fh ; # Edit suggestion Anonymous Monk on Feb 14, 2021 at +21:31 UTC print $fh substr($fc, $start, $numbers[$i]) ; $start = $numbers[$i] ; close $fh ; }

I have tried to set file input and stdout to utf8 (commented lines) but that makes things worse


In reply to Mixed script and binary problems to extract with susbstr by Veltro

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.