Skip to content

Commit 3eb5e7f

Browse files
committed
asahi_firmware.img4: Support LZFSE decompression on macOS
Signed-off-by: Hector Martin <[email protected]>
1 parent 795bacd commit 3eb5e7f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

asahi_firmware/img4.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# SPDX-License-Identifier: MIT
2+
import sys
23
from . import asn1
34
from ctypes import *
45

56
__all__ = ["img4p_extract_compressed", "img4p_extract"]
67

7-
def decode_lzfse(cdata, raw_size):
8+
def decode_lzfse_liblzfse(cdata, raw_size):
89
lzfse = CDLL("liblzfse.so")
910

1011
dest = create_string_buffer(raw_size)
@@ -13,6 +14,23 @@ def decode_lzfse(cdata, raw_size):
1314
assert decoded == raw_size
1415
return dest.raw
1516

17+
def decode_lzfse_darwin(cdata, raw_size):
18+
compression = CDLL("libcompression.dylib")
19+
20+
dest = create_string_buffer(raw_size)
21+
COMPRESSION_LZFSE = 0x801
22+
decoded = compression.compression_decode_buffer(dest, raw_size,
23+
cdata, len(cdata),
24+
None, COMPRESSION_LZFSE)
25+
26+
assert decoded == raw_size
27+
return dest.raw
28+
29+
if sys.platform == 'darwin':
30+
decode_lzfse = decode_lzfse_darwin
31+
else:
32+
decode_lzfse = decode_lzfse_liblzfse
33+
1634
def decode_header(decoder):
1735
tag = decoder.peek()
1836
assert tag.nr == asn1.Numbers.Sequence

0 commit comments

Comments
 (0)