When you decompress an LZMA-compressed SWF file using the ByteArray.uncompress method, an exception is thrown.


The LZMA header format Flash authoring uses does not match the header 7z format uses. You can convert the SWF file in the LZMA format into the 7z LZMA format by updating the header.

SWF file LZMA header

bytes 0-3: ZWS+version bytes 4-7: Uncompressed length (includes ZWS+version (4 bytes) and uncompressed length (4 bytes)) bytes 8-11: Compressed length bytes 12-16: LZMAproperties bytes 17-n: Compressed data

7z LZMA header

bytes 0-4: LZMA properties bytes 5-12: Uncompressed length (take the swf lzma length - 8 (don't include ZWS+version + uncompressed length)) bytes 13-n: Compressed data


The following is an example for uncompressing a file using ActionScript.

var data:ByteArray = File.readByteArray(file) data.endian = "littleEndian" var version:uint = data.readUnsignedInt() switch (version&0xffffffff) { ... case 90|87<<8|83<<16: // SWZ = lzma compressed     if (doDecompressOnly)     System.exit(0)     udata=new ByteArray     udata.endian = "littleEndian"     var ptr;

// put lzma properties in 0-4 for (ptr=0;ptr<5;ptr++) {     udata[ptr]=data[12+ptr] } // calculate uncompressed length, subtract 8 (remove header bytes) var scriptlen:uint=data[4]+(data[5]<<8)+(data[6]<<16)+(data[7]<<24)-8; // write lzma properties bytes: 0-4 for (ptr=0;ptr<4;ptr++) {     udata[5+ptr]=data[8+ptr] }

// write the uncompressed length: 5-8  udata[5]=scriptlen&0xFF; udata[6]=(scriptlen>>8) & 0xFF; udata[7]=(scriptlen>>16) & 0xFF; udata[8]=(scriptlen>>24) & 0xFF;// add 4 extra 0 to compressed length: 9-12 for (ptr=0;ptr<4;ptr++) {     udata[9+ptr]=0 }

data.position = 17 data.readBytes(udata,13,data.length-data.position) udata.position=0 csize = udata.length udata.uncompress(CompressionAlgorithm.LZMA) infoPrint("decompressed swf "+csize+" -> "+udata.length) /*var swf:Swf =*/ new Swf(udata) break

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy