-
Notifications
You must be signed in to change notification settings - Fork 127
Conversation
Cheers, mate! |
Glad to help! Hope it will work, haha) |
OK this works: public function swfUncompress(compressionMethod:String, uncompressedLength:uint = 0):void {
var pos:uint = position;
var ba:ByteArray = new ByteArray();
if(compressionMethod == SWF.COMPRESSION_METHOD_ZLIB) {
readBytes(ba);
ba.position = 0;
ba.uncompress();
} else if(compressionMethod == SWF.COMPRESSION_METHOD_LZMA) {
// Write LZMA properties
for(var i:uint = 0; i < 5; i++) {
ba.writeByte(this[i + 12]);
}
// Write uncompressed length (64 bit)
ba.endian = Endian.LITTLE_ENDIAN;
ba.writeUnsignedInt(uncompressedLength - 8);
ba.writeUnsignedInt(0);
// Write compressed data
position = 17;
readBytes(ba, 13);
// Uncompress
ba.position = 0;
ba.uncompress(compressionMethod);
} else {
throw(new Error("Unknown compression method: " + compressionMethod));
}
length = position = pos;
writeBytes(ba);
position = pos;
} |
Hey, that's great! We need a renewed SWF spec to make working code from the start... |
Yeah i've been nagging Thibault for an updated SWF spec like forever now ;) We're at 17, the spec is at 10. I guess not that much changed, but anyways. I'll commit once i feel confident that this actually works correctly, and once swfCompress is working too. |
For the record: The uncompressed part of a compressed SWF is always (first 8 bytes): What follows is compressed data until end of file. A LZMA compressed SWF looks like this (example):
To convert the compressed data into something that can be uncompressed by ByteArray.uncompress (7z), the compressed size has to be thrown away, and the uncompressed size (padded to 64 bits) has to be injected As the uncompressed size in SWF refers to the size of the entire SWF (including the uncompressed header of 8
|
Thanks, good to know! |
Let's make an another try!)