How to determine binary image architecture at runtime?

前端 未结 3 1166
北荒
北荒 2020-12-29 00:43

Crash log contains \"Binary Images\" section with information about architecture (armv6/armv7) and identifier of all loaded modules. How to determine this information at run

3条回答
  •  情书的邮戳
    2020-12-29 01:34

    We can use sysctl, sysctlbyname system call to get or set system information.

    Sample code:

    #import 
    #import 
    
    int32_t value = 0;
    size_t length = sizeof(value);
    sysctlbyname("hw.cputype", &value, &length, NULL, 0);
    
    if (value == CPU_TYPE_ARM64) {
        // arm64
    }
    else if (value == CPU_TYPE_ARM) {
        // armv7/armv7s
    }
    else if (value == CPU_TYPE_X86) {
        // simulator
    }
    

    I just list most common arch at 2016. Look for "hw.cpusubtype" to get more detial, like CPU_SUBTYPE_ARM_V6 CPU_SUBTYPE_ARM_V7 CPU_SUBTYPE_ARM_V7S

提交回复
热议问题