Ejemplo n.º 1
0
 def __init__(self, reader: MemoryViewReader):
     self.minor_version = reader.read_u16()
     self.major_version = reader.read_u16()
     self.constant_pool = ASConstantPool(reader)
     self.methods = read_array(reader, ASMethod)
     self.metadata = read_array(reader, ASMetadata)
     class_count = reader.read_int()
     self.instances = read_array(reader, ASInstance, class_count)
     self.classes = read_array(reader, ASClass, class_count)
     self.scripts = read_array(reader, ASScript)
     self.method_bodies = read_array(reader, ASMethodBody)
Ejemplo n.º 2
0
def parse_swf(input_: Union[memoryview, bytes]) -> Iterable[Tag]:
    """
    Parse SWF file and get an iterable of its tags.
    """
    reader = MemoryViewReader(input_)
    signature = Signature(reader.read_u8())
    assert reader.read_u16() == 0x5357
    reader.skip(1)  # version
    reader.skip(4)  # file length
    reader = decompress(reader, signature)
    reader.skip_rect()
    reader.skip(4)  # frame rate and frame count
    return read_tags(reader)
Ejemplo n.º 3
0
def read_tags(reader: MemoryViewReader) -> Iterable[Tag]:
    """
    Read tags from the stream and get an iterable of tags.
    """
    while not reader.is_eof():
        code_length = reader.read_u16()
        length = code_length & 0b111111
        if length == 0x3F:
            # Long tag header.
            length = reader.read_u32()
        try:
            type_ = TagType(code_length >> 6)
        except ValueError:
            # Unknown tag type. Skip the tag.
            reader.skip(length)
        else:
            yield Tag(type_=type_, raw=reader.read(length))