How to use the macholib.mach_o.CPU_TYPE_NAMES.get function in macholib

To help you get started, we’ve selected a few macholib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MobSF / Mobile-Security-Framework-MobSF / StaticAnalyzer / views / ios / binary_analysis.py View on Github external
def get_bin_info(bin_file):
    """Get Binary Information."""
    logger.info('Getting Binary Information')
    m = MachO(bin_file)
    for header in m.headers:
        if header.MH_MAGIC == MH_MAGIC_64 or header.MH_MAGIC == MH_CIGAM_64:
            sz = '64-bit'
        else:
            sz = '32-bit'
        arch = CPU_TYPE_NAMES.get(
            header.header.cputype, header.header.cputype)
        subarch = get_cpu_subtype(
            header.header.cputype, header.header.cpusubtype)
        return {'endian': header.endian,
                'bit': sz,
                'arch': arch,
                'subarch': subarch}
github lunixbochs / usercorn / usercorn.py View on Github external
self.arch = None
        self.info = None
        self.symtab = None
        self.entry = None
        if magic == '7f454c46':
            self.elf = ELFFile(self.fp)
            self.arch = self.elf.get_machine_arch()
            self.entry = self.elf['e_entry']
            self.symtab = self.elf.get_section_by_name('.symtab')
            self.info = ARCH_INFO.get(self.arch)
        elif magic in ('cafebabe', 'feedface', 'feedfacf', 'cefaedfe', 'cffaedfe'):
            macho = FileMachO(exe, self.fp)
            for header in macho.headers:
                if header.endian == '<':
                    self.macho = header
                    self.arch = mach_o.CPU_TYPE_NAMES.get(header.header.cputype)
                    self.arch = ARCH_MAP.get(self.arch, self.arch)
                    self.info = ARCH_INFO.get(self.arch)
                    for lc, cmd, data in header.commands:
                        # entry point
                        if lc.cmd == mach_o.LC_MAIN or lc.cmd == mach_o.LC_UNIXTHREAD:
                            if self.info['bits'] == 64:
                                ip = 2 * 4 + 16 * 8
                                self.entry = struct.unpack(header.endian + 'Q', data[ip:ip+8])[0]
                            else:
                                ip = 2 * 4 + 10 * 4
                                self.entry = struct.unpack(header.endian + 'L', data[ip:ip+4])[0]
                    break
            else:
                raise NotImplementedError('Could not find suitable MachO arch.')
        else:
            raise NotImplementedError('Unrecognized file magic: %s' % magic)
github lunixbochs / usercorn / py / usercorn / loader / macho.py View on Github external
def __init__(self, exe, fp):
        # NeXT?
        self.os = 'darwin'
        self.fp = fp
        self.macho = FileMachO(exe, fp)
        for header in self.macho.headers:
            if header.endian == '<':
                self.header = header
                self.arch = mach_o.CPU_TYPE_NAMES.get(header.header.cputype)
                if self.header.MH_MAGIC in (MH_MAGIC_64, MH_CIGAM_64):
                    self.bits = 64
                else:
                    self.bits = 32
                for lc, cmd, data in header.commands:
                    # entry point
                    if lc.cmd == mach_o.LC_MAIN or lc.cmd == mach_o.LC_UNIXTHREAD:
                        if self.bits == 64:
                            ip = 2 * 4 + 16 * 8
                            self.entry = struct.unpack(header.endian + 'Q', data[ip:ip+8])[0]
                        else:
                            ip = 2 * 4 + 10 * 4
                            self.entry = struct.unpack(header.endian + 'L', data[ip:ip+4])[0]
                break
        else:
            raise NotImplementedError('Could not find suitable MachO arch.')
github NetEaseGame / iOS-private-api-checker / api / app_utils.py View on Github external
def check_architectures(app):
    '''
    info检查是否支持64位
    demo:armv7, arm64, armv7s
    '''
    from macholib import MachO, mach_o

    m = MachO.MachO(app)
    arcs = []
    for header in m.headers:
        cpu_type = header.header.cputype
        cpu_subtype = header.header.cpusubtype
        arch = str(mach_o.CPU_TYPE_NAMES.get(cpu_type, cpu_type)).lower()
        if cpu_type == 12:
            if cpu_subtype == 0:
                arch = 'armall'
            elif cpu_subtype == 5:
                arch = 'armv4t'
            elif cpu_subtype == 6:
                arch = 'armv6'
            elif cpu_subtype == 7:
                arch = 'armv5tej'
            elif cpu_subtype == 8:
                arch = 'arm_xscale'
            elif cpu_subtype == 9:
                arch = 'armv7'
            elif cpu_subtype == 10:
                arch = 'armv7f'
            elif cpu_subtype == 11: