swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Swftools-common] swfextractall


From: Mathieu Boillat
Subject: [Swftools-common] swfextractall
Date: Fri, 08 Dec 2006 00:55:41 +0100
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

Hi All,

I have just released a tiny Perl script in order to extract all objects from a specified SWF file
with swfextract.

Usage: swfextractall [-v] -o output_path file.swf

Hope it can be useful for someone.

Cheers

--
Mathieu Boillat
MTProd.com
#!/usr/bin/perl


###############################################################
#       swfextractall is (C) 2006, Mathieu Boillat.
#       swfextractall is licensed to you under the GPL.
#       Usage: swfextractall [-v] -o output_path file.swf
###############################################################


&ReadArgs();

$tmp_file = "/tmp/swfextractall" . time();
$ret = system("swfextract $input_file > $tmp_file");

if ( $ret )
{
        &Fatal("swfextract returned $ret, exiting.");
}

open(SWFEXTRACT, "<$tmp_file");
while ( $output = <SWFEXTRACT> )
{
        if ( $output =~ /^(.+)ID\(s\) / )
        {
                $extract_mode = $object_type = $1;

                # Define object extraction mode (used by swfextract)
                $extract_mode =~ s/^.*?\[(.+?)\].*$/$1/;

                # Define object(s) type
                if ( $object_type =~ /shape/i )
                {
                        $object_type = "shape";
                        $file_extension = "swf";
                }
                elsif ( $object_type =~ /movieclip/i )
                {
                        $object_type = "movieclip";
                        $file_extension = "swf";
                }
                elsif ( $object_type =~ /frame/i )
                {
                        $object_type = "frame";
                        $file_extension = "swf";
                }
                elsif ( $object_type =~ /font/i )
                {
                        $object_type = "font";
                        $file_extension = "swf";
                }
                elsif ( $object_type =~ /png/i )
                {
                        $object_type = "png";
                        $file_extension = "png";
                }
                elsif ( $object_type =~ /jpeg/i )
                {
                        $object_type = "jpeg";
                        $file_extension = "jpeg";
                }
                elsif ( $object_type =~ /mp3/i )
                {
                        $object_type = "mp3";
                        $file_extension = "mp3";
                }
                elsif ( $object_type =~ /sound/i )
                {
                        $object_type = "sound";
                        $file_extension = "swf";
                }

                # Cleanup output
                $output =~ s/^.+ID\(s\) //;
                $output =~ s/\s+//g;

                # Split the IDs groups
                @id_arr = split(/,/, $output);

                # Parse the IDs groups
                for (my $i=0; $i<scalar(@id_arr); $i++)
                {
                        # This is a range of IDs
                        if ( $id_arr[$i] =~ /(\d+)\-(\d+)/ )
                        {
                                $range_from = $1;
                                $range_to = $2;
                                for (my $j=$range_from; $j<$range_to+1; $j++)
                                {
                                        &WriteObjectToFile($input_file, $j, 
$output_dir . "/" . $object_type . "_" . $j . "." . $file_extension, 
$extract_mode, $swfextract_options);
                                }
                        }
                        # This is an single ID
                        else
                        {
                                &WriteObjectToFile($input_file, $id_arr[$i], 
$output_dir . "/" . $object_type . "_" . $id_arr[$i] . "." . $file_extension, 
$extract_mode, $swfextract_options);
                        }
                }
        }
}
close(SWFEXTRACT);

exit(0);




sub WriteObjectToFile()
{
        my($input_file, $object_id, $output_file, $extract_mode, 
$swfextract_options) = @_;

        if ( $integrity && $extract_mode eq "-f" )
        {
                $swfextract_options .= " -w";
        }
        if ( $integrity && $extract_mode eq "-i" )
        {
                $swfextract_options .= " -P";
        }

        $command = "swfextract $swfextract_options $extract_mode $object_id -o 
$output_file $input_file";

        $ret = system($command);

        if ( $verbosity >= 1 )
        {
                print "[$command] returned $ret\n";
        }
}


sub ReadArgs()
{
        $argc = @ARGV;

        # Default options value
        $verbosity = 0;
        $integrity = 1;

        for (my $i=0; $i<$argc; $i++)
        {
                $arg = $ARGV[$i];

                if ( $arg =~ /^\-o$/ )
                {
                        $output_dir = $ARGV[$i+1];
                }
                elsif ( $arg =~ /^\-v/ )
                {
                        $verbosity = length($arg) - 1;
                }
        }

        $input_file = $ARGV[$argc-1];

        if ( !length($input_file) )
        {
                &Fatal("No input file specified, exiting");
        }
        if ( !length($output_dir) )
        {
                &Fatal("No output output specified, exiting");
        }
}


sub Fatal()
{
        my($msg) = @_;

        print $msg . "\n\n" . &Usage;
        exit(-1);
}


sub Usage()
{
        $usage = "Usage: swfextractall [-v] -o output_path file.swf\n";
        $usage .= "\t-o path\t\t\t\tSet output path\n";
        $usage .= "\t-v\t\t\t\tBe more verbose\n";

        return $usage;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]