class DyldInfoCommand(LoadCommandHeader): ENDIAN = None FIELDS = (MagicField( 'cmd', 'I', { LoadCommandCommand.COMMANDS['LC_DYLD_INFO']: 'LC_DYLD_INFO', LoadCommandCommand.COMMANDS['LC_DYLD_INFO_ONLY']: 'LC_DYLD_INFO_ONLY' }), Field('cmdsize', 'I'), Field('rebase_off', 'I'), Field('rebase_size', 'I'), Field('bind_off', 'I'), Field('bind_size', 'I'), Field('weak_bind_off', 'I'), Field('weak_bind_size', 'I'), Field('lazy_bind_off', 'I'), Field('lazy_bind_size', 'I'), Field('export_off', 'I'), Field('export_size', 'I')) def __init__(self, bytes_=None, **kwargs): self.rebase_off = None self.rebase_size = None self.bind_off = None self.bind_size = None self.weak_bind_off = None self.weak_bind_size = None self.lazy_bind_off = None self.lazy_bind_size = None self.export_off = None self.export_size = None super(DyldInfoCommand, self).__init__('dyld_info_command', bytes_, **kwargs)
class EncryptionInfoCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', { LoadCommandCommand.COMMANDS['LC_ENCRYPTION_INFO']: 'LC_ENCRYPTION_INFO' }), Field('cmdsize', 'I'), Field('cryptoff', 'I'), Field('cryptsize', 'I'), Field('cryptid', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.cryptoff = None self.cryptsize = None self.cryptid = None super(EncryptionInfoCommand, self).__init__('encryption_info_command', bytes_, **kwargs) def is_encrypted(self): return self.cryptid != 0 def covers(self, section): assert isinstance(section, Section) return (Range(section.offset, section.offset + section.size) in Range(self.cryptoff, self.cryptoff + self.cryptsize))
class LinkeditDataCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', { LoadCommandCommand.COMMANDS['LC_CODE_SIGNATURE']: 'LC_CODE_SIGNATURE', LoadCommandCommand.COMMANDS['LC_SEGMENT_SPLIT_INFO']: 'LC_SEGMENT_SPLIT_INFO', LoadCommandCommand.COMMANDS['LC_FUNCTION_STARTS']: 'LC_FUNCTION_STARTS', LoadCommandCommand.COMMANDS['LC_DATA_IN_CODE']: 'LC_DATA_IN_CODE', LoadCommandCommand.COMMANDS['LC_DYLIB_CODE_SIGN_DRS']: 'LC_DYLIB_CODE_SIGN_DRS', LoadCommandCommand.COMMANDS['LC_LINKER_OPTIMIZATION_HINT']: 'LC_LINKER_OPTIMIZATION_HINT' }), Field('cmdsize', 'I'), Field('dataoff', 'I'), Field('datasize', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.dataoff = None self.datasize = None super(LinkeditDataCommand, self).__init__('linkedit_data_command', bytes_, **kwargs)
class SegmentCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SEGMENT']: 'LC_SEGMENT'}), Field('cmdsize', 'I'), NullTerminatedStringField('segname', '16s'), HexField('vmaddr', 'I'), Field('vmsize', 'I'), Field('fileoff', 'I'), Field('filesize', 'I'), Field('maxprot', 'I'), Field('initprot', 'I'), Field('nsects', 'I'), HexField('flags', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.segname = None self.vmaddr = None self.vmsize = None self.fileoff = None self.filesize = None self.maxprot = None self.initprot = None self.nsects = None self.flags = None super(SegmentCommand, self).__init__('segment_command', bytes_, **kwargs)
class SubUmbrellaCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SUB_UMBRELLA']: 'LC_SUB_UMBRELLA'}), Field('cmdsize', 'I'), Field('sub_umbrella_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.sub_umbrella_offset = None super(SubUmbrellaCommand, self).__init__(bytes_, **kwargs)
class SourceVersionCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SOURCE_VERSION']: 'LC_SOURCE_VERSION'}), Field('cmdsize', 'I'), SourceVersionField('version', 'Q'), ) def __init__(self, bytes_=None, **kwargs): self.version = None super(SourceVersionCommand, self).__init__('source_version_command', bytes_, **kwargs)
class RpathCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_RPATH']: 'LC_RPATH'}), Field('cmdsize', 'I'), Field('path_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.path_offset = None super(RpathCommand, self).__init__('rpath_command', bytes_, **kwargs)
class PrebindCksumCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', {LoadCommandCommand.COMMANDS['LC_DYSYMTAB']: 'LC_DYSYMTAB'}), Field('cmdsize', 'I'), Field('cksum', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.cksum = None super(PrebindCksumCommand, self).__init__(bytes_, **kwargs)
class SubClientCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SUB_CLIENT']: 'LC_SUB_CLIENT'}), Field('cmdsize', 'I'), Field('client_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.client_offset = None super(SubClientCommand, self).__init__(bytes_, **kwargs)
class DylinkerCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_ID_DYLINKER']: 'LC_ID_DYLINKER', LoadCommandCommand.COMMANDS['LC_LOAD_DYLINKER']: 'LC_LOAD_DYLINKER', LoadCommandCommand.COMMANDS['LC_DYLD_ENVIRONMENT']: 'LC_DYLD_ENVIRONMENT'}), Field('cmdsize', 'I'), Field('name_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.name_offset = None super(DylinkerCommand, self).__init__('dylinker_command', bytes_, **kwargs)
class SubLibraryCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SUB_LIBRARY']: 'LC_SUB_LIBRARY'}), Field('cmdsize', 'I'), Field('library_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.library_offset = None super(SubLibraryCommand, self).__init__(bytes_, **kwargs)
class EntryPointCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_MAIN']: 'LC_MAIN'}), Field('cmdsize', 'I'), Field('entryoff', 'I'), Field('stacksize', 'Q'), ) def __init__(self, bytes_=None, **kwargs): self.entryoff = None self.stacksize = None super(EntryPointCommand, self).__init__('entry_point_command', bytes_, **kwargs)
class LinkerOptionCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', { LoadCommandCommand.COMMANDS['LC_LINKER_OPTION']: 'LC_LINKER_OPTION' }), Field('cmdsize', 'I'), Field('count', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.count = None super(LinkerOptionCommand, self).__init__('linker_option_command', bytes_, **kwargs)
class VersionMinCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_VERSION_MIN_MACOSX']: 'LC_VERSION_MIN_MACOSX', LoadCommandCommand.COMMANDS['LC_VERSION_MIN_IPHONEOS']: 'LC_VERSION_MIN_IPHONEOS'}), Field('cmdsize', 'I'), VersionField('version', 'I'), VersionField('sdk', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.version = None self.sdk = None super(VersionMinCommand, self).__init__('version_min_command', bytes_, **kwargs)
class SubFrameworkCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', { LoadCommandCommand.COMMANDS['LC_SUB_FRAMEWORK']: 'LC_SUB_FRAMEWORK' }), Field('cmdsize', 'I'), Field('umbrella_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.umbrella_offset = None super(SubFrameworkCommand, self).__init__('sub_framework_command', bytes_, **kwargs)
class TwolevelHintsCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', { LoadCommandCommand.COMMANDS['LC_TWOLEVEL_HINTS']: 'LC_TWOLEVEL_HINTS' }), Field('cmdsize', 'I'), Field('offset', 'I'), Field('nhints', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.offset = None self.nhints = None super(TwolevelHintsCommand, self).__init__('twolevel_hints_command', bytes_, **kwargs)
class FatHeader(Header): MAGIC = 0xcafebabe CIGAM = 0xbebafecab ENDIAN = True # big endian FIELDS = ( MagicField('magic', 'I', { MAGIC: 'MAGIC', CIGAM: 'CIGAM' }), Field('nfat_arch', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.magic = None self.nfat_arch = None super(FatHeader, self).__init__('fat_header', bytes_, **kwargs)
class DysymtabCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_DYSYMTAB']: 'LC_DYSYMTAB'}), Field('cmdsize', 'I'), Field('ilocalsym', 'I'), Field('nlocalsym', 'I'), Field('iextdefsym', 'I'), Field('nextdefsym', 'I'), Field('iundefsym', 'I'), Field('nundefsym', 'I'), Field('tocoff', 'I'), Field('ntoc', 'I'), Field('modtaboff', 'I'), Field('nmodtab', 'I'), Field('extrefsymoff', 'I'), Field('nextrefsyms', 'I'), Field('indirectsymoff', 'I'), Field('nindirectsyms', 'I'), Field('extreloff', 'I'), Field('nextrel', 'I'), Field('locreloff', 'I'), Field('nlocrel', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.ilocalsym = None self.nlocalsym = None self.iextdefsym = None self.nextdefsym = None self.iundefsym = None self.nundefsym = None self.tocoff = None self.ntoc = None self.modtaboff = None self.nmodtab = None self.extrefsymoff = None self.nextrefsyms = None self.indirectsymoff = None self.nindirectsyms = None self.extreloff = None self.nextrel = None self.locreloff = None self.nlocrel = None super(DysymtabCommand, self).__init__('dysymtab_command', bytes_, **kwargs)
class SymtabCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', {LoadCommandCommand.COMMANDS['LC_SYMTAB']: 'LC_SYMTAB'}), Field('cmdsize', 'I'), Field('symoff', 'I'), Field('nsyms', 'I'), Field('stroff', 'I'), Field('strsize', 'I'), ) def __init__(self, bytes_, **kwargs): self.symoff = None self.nsyms = None self.stroff = None self.strsize = None super(SymtabCommand, self).__init__('symtab_command', bytes_, **kwargs)
class PreboundDylibCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField('cmd', 'I', { LoadCommandCommand.COMMANDS['LC_PREBOUND_DYLIB']: 'LC_PREBOUND_DYLIB' }), Field('cmdsize', 'I'), Field('name_offset', 'I'), Field('nmodules', 'I'), Field('linked_modules_offset', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.name_offset = None self.nmodules = None self.linked_modules_offset = None super(PreboundDylibCommand, self).__init__(bytes_, **kwargs)
class MachHeader64(Header): MH_MAGIC64 = 0xfeedfacf ENDIAN = None FIELDS = (MagicField('magic', 'I', {MH_MAGIC64: 'MH_MAGIC64'}), CpuType('cputype', 'I'), CpuSubType('cpusubtype', 'cputype', 'I'), FileType('filetype', 'I'), Field('ncmds', 'I'), Field('sizeofcmds', 'I'), MachHeaderFlags('flags', 'I'), Field('reserved', 'I')) def __init__(self, bytes_=None, **kwargs): self.magic = None self.cputype = None self.cpusubtype = None self.filetype = None self.ncmds = None self.sizeofcmds = None self.flags = None self.reserved = None super(MachHeader64, self).__init__('mach_header_64', bytes_, **kwargs)
class DylibCommand(LoadCommandHeader): ENDIAN = None FIELDS = ( MagicField( 'cmd', 'I', { LoadCommandCommand.COMMANDS['LC_LOAD_DYLIB']: 'LC_LOAD_DYLIB', LoadCommandCommand.COMMANDS['LC_LOAD_WEAK_DYLIB']: 'LC_LOAD_WEAK_DYLIB', LoadCommandCommand.COMMANDS['LC_ID_DYLIB']: 'LC_ID_DYLIB' }), Field('cmdsize', 'I'), Field('dylib_name_offset', 'I'), UnixTimeField('dylib_timestamp', 'I'), VersionField('dylib_current_version', 'I'), VersionField('dylib_compatiblity_version', 'I'), ) def __init__(self, bytes_=None, **kwargs): self.dylib_name_offset = None self.dylib_timestamp = None self.dylib_current_version = None self.dylib_compatibility_version = None super(DylibCommand, self).__init__('dylib_command', bytes_, **kwargs)