Decompressing A SWF With Java

This example reads a swf file into a byte array and decompresses / inflates all of the bytes of the swf except for the the first 8 bytes which are always uncompressed. As most swf files have zlib compression applied, file decompression is necessary if you wish to fully parse the swf. As with the previous post on swf compression, this is a very raw example–no file signature or compression checking is performed before attempting to inflate the file.

SWFDecompressor.java



8 Responses to “ “Decompressing A SWF With Java”

  1. sherm says:

    look dude, this makes no sense at all.

  2. Brooks says:

    Heh, heh–you should read the file format specification….you know you’re in trouble when it starts to make sense to you.

  3. Mark says:

    What type of compression is used for an SWF file? Gzip? zip? bzip? tar?

  4. Brooks says:

    Hey Mark,

    The swf file format uses zlib compression.

  5. Daniel says:

    Yep…

    Yes, I’ve heard of “decaf.” What’s your point?

  6. cotta says:

    hey there, first comment after 2 year!!!

    thank you for the code
    I’m using it in my own project and I’ve found a bug related to inflater: sometimes finished() is read as false when in fact should be true… workaround is use also count!=0 in while loop.

    cheers

  7. cotta says:

    hi, it’s me again ;) , the project I was talking about in the last post had become a quite structured one… it is called JavaSWF9 , if you or someone in the audience interested in contributing drop a message at http://www.stefanocottafavi.com

    cheers

  8. This can be done with a Perl one-liner instead of 115 lines of Java ;-),

    perl -MCompress::Zlib -0777 -e \
    ‘print uncompress substr , 8;’ flash.swf > flash

Leave a Reply