1#!/usr/bin/perl -w 2# ==================================================================== 3# Copyright (c) 2003 by Peter Liscovius. All rights reserved. 4# This program is free software; you can redistribute it and/or modify 5# it under the same terms as Perl itself. 6# ==================================================================== 7 8use strict; 9use Compress::Zlib; 10 11if (!$ARGV[1]) {die("Flash decompression tool\nConverts compressed flashfiles to uncompressed flashfiles.\nusage: cws2fws infile.swf outfile.swf\n\n");} 12 13my $filein = $ARGV[0]; 14my $fileout = $ARGV[1]; 15 16open(CWS,"<$filein") or die("Couldn't open $filein .\n"); 17 18#Turn off lineseparator character. We read binary data. 19$/=undef; 20my $header; 21read(CWS,$header,8); 22my $cwsfile=<CWS>; 23my $unzip = uncompress($cwsfile) or die("Uncompression failed. Maybe not a compressed SWF or corrupt data?\n"); 24close CWS; 25 26open (FWS,">$fileout") or die("Couldn't open $fileout .\n"); 27$header =~ s/^C/F/; 28print FWS $header.$unzip; 29close FWS; 30 31my @header=unpack("C*",$header); 32my $filesize=$header[4]+$header[5]*256+$header[6]*65536+$header[7]*16777216; 33if ($filesize == -s $fileout){ 34 print "Decompression of compressed SWF-file seems to be successful.\n"; 35} 36else { 37 print "\nreal filesize: ".(-s $fileout); 38 print "\nsize in swfheader: ".$filesize; 39 print "\n\nFilesize of decompressed file is not equal with size number in the header the SWF!\nMaybe it wasn't a compressed SWF or the file is corrupt or modified.\n"; 40} 41