Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
class FatArch(Header):
    ENDIAN = True  # big endian
    FIELDS = (CpuType('cputype', 'I'), CpuSubType('cpusubtype', 'cputype',
                                                  'I'), Field('offset', 'I'),
              Field('size', 'I'), Field('align', 'I'))

    def __init__(self, bytes_=None, **kwargs):
        self.cputype = None
        self.cpusubtype = None
        self.offset = None
        self.size = None
        self.align = None
        super(FatArch, self).__init__('fat_arch', bytes_, **kwargs)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
class Section64(IndexedHeader):
    ENDIAN = None
    FIELDS = (
        NullTerminatedStringField('sectname', '16s'),
        NullTerminatedStringField('segname', '16s'),
        HexField('addr', 'Q'),
        Field('size', 'Q'),
        Field('offset', 'I'),
        Field('align', 'I'),
        Field('reloff', 'I'),
        Field('nreloc', 'I'),
        HexField('flags', 'I'),
        Field('reserved1', 'I'),
        Field('reserved2', 'I'),
        Field('reserved3', 'I'),
    )

    NEXT_INDEX = 1

    def __init__(self, bytes_=None, **kwargs):
        self.sectname = None
        self.segname = None
        self.addr = None
        self.size = None
        self.offset = None
        self.align = None
        self.reloff = None
        self.nreloc = None
        self.flags = None
        self.reserved1 = None
        self.reserved2 = None
        super(Section64, self).__init__('section_64', bytes_, **kwargs)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
class Nlist64(IndexedHeader):
    ENDIAN = None
    FIELDS = (
        Field('n_strx', 'I'),
        NType('n_type', 'B'),
        NSect('n_sect', 'B'),
        NDesc('n_desc', 'H'),
        HexField('n_value', 'Q'),
    )

    def __init__(self, bytes_=None, **kwargs):
        self.n_strx = None
        self.n_type = None
        self.n_sect = None
        self.n_desc = None
        self.n_value = None
        super(Nlist64, self).__init__('nlist64', bytes_, **kwargs)

    def is_global(self):
        return self.FIELDS[3].is_global(self)

    def is_defined(self):
        return self.FIELDS[3].is_defined(self)

    def is_lazy(self):
        return self.FIELDS[3].is_lazy(self)

    def type(self):
        return self.FIELDS[1].type(self)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
class LoadCommand(LoadCommandHeader):
    ENDIAN = None
    FIELDS = (
        LoadCommandCommand('cmd', 'I'),
        Field('cmdsize', 'I'),
    )

    def __init__(self, bytes_=None, **kwargs):
        super(LoadCommand, self).__init__('load_command', bytes_, **kwargs)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
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)