Пример #1
0
class Thread(Struct, partials={'S'}):
    flavor: Enum(ThreadFlavor, UInt(32))
    size: Processed(UInt(32), lambda x: x * 4, lambda x: x // 4) @ S.limit
    state: Sized(Switch(fallback=Data(), options=THREAD_TYPES), exact=True) @ S

    def on_parse_flavor(self, spec, context):
        spec.state.type.selector = (context.user.cpu_type, self.flavor)
Пример #2
0
class Section(Struct, generics={'AddrSize'}):
    name: Str(length=16, exact=True)
    segment_name: Str(length=16, exact=True)
    vm_offset: UInt(AddrSize)
    vm_size: UInt(AddrSize)
    file_offset: UInt(32)
    alignment: UInt(32)
    reloc_offset: UInt(32)
    reloc_count: UInt(32)
    flags: UInt(32)
    _reserved: Data(12)
Пример #3
0
class LoadCommand(Struct, partials={'T', 'S'}):
    type: Enum(LoadCommandType, Bits(31)) @ T.selector
    vital: Bool(Bits(1))
    size: Processed(UInt(32), lambda x: x - 8, lambda x: x + 8) @ S.limit
    data: Sized(Switch(fallback=Data(), options=LOAD_COMMANDS) @ T,
                exact=True) @ S
Пример #4
0
    ChainedFixups = 52
    FileSetEntry = 53


LOAD_COMMANDS = {}


def lc(i):
    def inner(v):
        LOAD_COMMANDS[i] = v
        return v

    return inner


lc(LoadCommandType.UUID)(Processed(Data(16), lambda x: uuid.UUID(bytes=x),
                                   lambda x: x.bytes))


class Version(Struct):
    patch: UInt(8)
    minor: UInt(8)
    major: UInt(16)


class BuildTool(enum.Enum):
    Clang = 1
    Swift = 2
    LD = 3