mirror of
https://github.com/dgelessus/python-rsrcfork.git
synced 2024-11-29 17:49:49 +00:00
Pass complete header info to individual decompressors
This commit is contained in:
parent
9dbdf5b827
commit
53e73be980
@ -18,7 +18,7 @@ def _decompress_application(data: bytes, header_info: CompressedApplicationHeade
|
||||
else:
|
||||
raise DecompressError(f"Unsupported 'dcmp' ID: {header_info.dcmp_id}, expected 0 or 1")
|
||||
|
||||
return decompress_func(data, header_info.decompressed_length, debug=debug)
|
||||
return decompress_func(header_info, data, debug=debug)
|
||||
|
||||
|
||||
def _decompress_system(data: bytes, header_info: CompressedSystemHeaderInfo, *, debug: bool=False) -> bytes:
|
||||
@ -27,7 +27,7 @@ def _decompress_system(data: bytes, header_info: CompressedSystemHeaderInfo, *,
|
||||
else:
|
||||
raise DecompressError(f"Unsupported 'dcmp' ID: {header_info.dcmp_id}, expected 2")
|
||||
|
||||
return decompress_func(data, header_info.decompressed_length, header_info.parameters, debug=debug)
|
||||
return decompress_func(header_info, data, debug=debug)
|
||||
|
||||
|
||||
def decompress(data: bytes, *, debug: bool=False) -> bytes:
|
||||
|
@ -36,7 +36,7 @@ TABLE = [TABLE_DATA[i:i + 2] for i in range(0, len(TABLE_DATA), 2)]
|
||||
assert len(TABLE) == len(range(0x4b, 0xfe))
|
||||
|
||||
|
||||
def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> bytes:
|
||||
def decompress(header_info: common.CompressedApplicationHeaderInfo, data: bytes, *, debug: bool=False) -> bytes:
|
||||
"""Decompress compressed data in the format used by 'dcmp' (0)."""
|
||||
|
||||
prev_literals = []
|
||||
@ -287,7 +287,7 @@ def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> b
|
||||
else:
|
||||
raise common.DecompressError(f"Unknown tag byte: 0x{data[i]:>02x}")
|
||||
|
||||
if decompressed_length % 2 != 0 and len(decompressed) == decompressed_length + 1:
|
||||
if header_info.decompressed_length % 2 != 0 and len(decompressed) == header_info.decompressed_length + 1:
|
||||
# Special case: if the decompressed data length stored in the header is odd and one less than the length of the actual decompressed data, drop the last byte.
|
||||
# This is necessary because nearly all codes generate data in groups of 2 or 4 bytes, so it is basically impossible to represent data with an odd length using this compression format.
|
||||
decompressed = decompressed[:-1]
|
||||
|
@ -19,7 +19,7 @@ TABLE = [TABLE_DATA[i:i + 2] for i in range(0, len(TABLE_DATA), 2)]
|
||||
assert len(TABLE) == len(range(0xd5, 0xfe))
|
||||
|
||||
|
||||
def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> bytes:
|
||||
def decompress(header_info: common.CompressedApplicationHeaderInfo, data: bytes, *, debug: bool=False) -> bytes:
|
||||
"""Decompress compressed data in the format used by 'dcmp' (1)."""
|
||||
|
||||
prev_literals = []
|
||||
|
@ -131,10 +131,10 @@ def _decompress_system_tagged(data: bytes, decompressed_length: int, table: typi
|
||||
return b"".join(parts)
|
||||
|
||||
|
||||
def decompress(data: bytes, decompressed_length: int, parameters: bytes, *, debug: bool=False) -> bytes:
|
||||
def decompress(header_info: common.CompressedSystemHeaderInfo, data: bytes, *, debug: bool=False) -> bytes:
|
||||
"""Decompress compressed data in the format used by 'dcmp' (2)."""
|
||||
|
||||
unknown, table_count_m1, flags_raw = STRUCT_PARAMETERS.unpack(parameters)
|
||||
unknown, table_count_m1, flags_raw = STRUCT_PARAMETERS.unpack(header_info.parameters)
|
||||
|
||||
if debug:
|
||||
print(f"Value of unknown parameter field: 0x{unknown:>04x}")
|
||||
@ -172,4 +172,4 @@ def decompress(data: bytes, decompressed_length: int, parameters: bytes, *, debu
|
||||
else:
|
||||
decompress_func = _decompress_system_untagged
|
||||
|
||||
return decompress_func(data[data_start:], decompressed_length, table, debug=debug)
|
||||
return decompress_func(data[data_start:], header_info.decompressed_length, table, debug=debug)
|
||||
|
Loading…
Reference in New Issue
Block a user