#!/usr/bin/perl -w # splitgzip.pl # # written by Michael Holzt, , 5/2003 # slightly modified by an unknown contributor # # this code is declared public domain by the author use strict; my ($fn, $imglen, $image, $offset, $x, $output); ($fn) = @ARGV; die "Usage: splitgzip.pl \n" if ( $fn eq '' ); print "Reading $fn...\n"; open(IN,"<$fn") or die "Can't open: $fn\n"; $imglen = read(IN,$image,2000000); close(IN); print "FIXME: \$imglen = $imglen\n"; print "Analysing $fn...\n"; $offset = 0; $output = 0; for ( $offset=0; $offset<$imglen; $offset++ ) { if ( ord(substr($image,$offset,1)) == 0x1F && ord(substr($image,$offset+1,1)) == 0x8B && ord(substr($image,$offset+2,1)) == 0x08 ) { print "Found GZIP-Header... "; print "FIXME: found at offset $offset"; close(OUT) if ( $output ); $fn = ''; $x = 10; while ( ord(substr($image,$offset+$x,1)) != 0 ) { $fn .= substr($image,$offset+$x,1); $x++; } print "Filename $fn.gz... writing...\n"; open(OUT,">$fn.gz") or die "Can't open: $fn\n"; $output = 1; } print OUT substr($image,$offset,1) if ( $output ); } close(OUT) if ( $output );