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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |