Пример #1
0
def decompress(reader: MemoryViewReader,
               signature: Signature) -> MemoryViewReader:
    """
    Decompress the rest of an SWF file, depending on its signature.
    """
    if signature == Signature.UNCOMPRESSED:
        return reader
    if signature == Signature.LZMA:
        # https://stackoverflow.com/a/39777419/359730
        reader.skip(4)  # skip compressed length
        return MemoryViewReader(
            lzma.decompress(
                reader.read(5).tobytes() +
                b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF' +
                reader.read_all().tobytes()))
    if signature == Signature.ZLIB:
        return MemoryViewReader(zlib.decompress(reader.read_all()))
    assert False, 'unreachable code'
Пример #2
0
 def __init__(self, raw: memoryview):
     reader = MemoryViewReader(raw)
     self.flags = DoABCTagFlags(reader.read_u32())
     self.name = reader.read_string()
     self.abc_file = reader.read_all()