Skip to content

Commit df73acb

Browse files
authored
Fix LZMA Compression (unity specific) (K0lb3#246)
1 parent 1a6d5dc commit df73acb

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

‎UnityPy/helpers/CompressionHelper.py‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,29 @@ def compress_lzma(data: bytes) -> bytes:
4949
:return: compressed data
5050
:rtype: bytes
5151
"""
52-
ec = lzma.LZMACompressor(
53-
format=lzma.FORMAT_RAW,
54-
filters=[
55-
{"id": lzma.FILTER_LZMA1, "dict_size": 524288, "lc": 3, "lp": 0, "pb": 2, }
56-
],
57-
)
58-
ec.compress(data)
59-
return b"]\x00\x00\x08\x00" + ec.flush()
52+
compressor = lzma.LZMACompressor(format=lzma.FORMAT_ALONE, filters=[{
53+
"id": lzma.FILTER_LZMA1,
54+
"dict_size": 524288,
55+
"lc": 3,
56+
"lp": 0,
57+
"pb": 2,
58+
}])
59+
compressed_data = compressor.compress(data) + compressor.flush()
60+
61+
# Extract the header
62+
header = bytearray(compressed_data[:13])
63+
compressed_body = compressed_data[13:]
64+
65+
# Decompressed size (adjust this value according to your data)
66+
decompressed_size = len(data)
67+
68+
# Manually set the decompressed size in the header
69+
header[5:13] = decompressed_size.to_bytes(8, 'little')
70+
71+
# Combine the header and the compressed body
72+
final_compressed_data = header + compressed_body
73+
74+
return final_compressed_data
6075

6176

6277
# LZ4

0 commit comments

Comments
 (0)