38 #define SWF_ZLIB_MIN_VERSION 0x06
39 #define SWF_LZMA_MIN_VERSION 0x0D
43 if (buffer_len >= 3 && buffer[1] ==
'W' && buffer[2] ==
'S') {
46 else if (buffer[0] ==
'C')
48 else if (buffer[0] ==
'Z')
75 uint32_t decompress_depth,
76 uint32_t compress_depth)
94 if (buffer_len <=
offset) {
99 uint32_t compressed_data_len = 0;
100 if (compress_depth > 0 && compress_depth <= buffer_len -
offset) {
101 compressed_data_len = compress_depth;
103 compressed_data_len = buffer_len -
offset;
123 if (decompressed_swf_len == 0) {
128 uint32_t decompressed_data_len = (decompress_depth == 0) ? decompressed_swf_len : decompress_depth;
129 decompressed_data_len += 8;
133 if (out_buffer->
size < decompressed_data_len) {
137 out_buffer->
len = decompressed_data_len;
144 out_buffer->
buf[0] =
'F';
145 out_buffer->
buf[1] =
'W';
146 out_buffer->
buf[2] =
'S';
147 out_buffer->
buf[3] = swf_version;
148 memcpy(out_buffer->
buf + 4, &decompressed_swf_len, 4);
149 memset(out_buffer->
buf + 8, 0, decompressed_data_len - 8);
158 (uint8_t *)buffer +
offset, compressed_data_len,
159 out_buffer->
buf + 8, out_buffer->
len - 8);
171 compressed_data_len += 13;
172 uint8_t compressed_data[compressed_data_len];
174 memcpy(compressed_data, buffer + 12, 5);
176 memset(compressed_data + 5, 0xFF, 8);
178 memcpy(compressed_data + 13, buffer +
offset, compressed_data_len - 13);
184 compressed_data, compressed_data_len,
185 out_buffer->
buf + 8, out_buffer->
len - 8);