Calling "sysctlbyname(...)" with "hw.machine" flag in iOS9
Asked Answered
W

1

6

Following WWDC 2015 session "703 Privacy and Your App", there is changes using sysctl. And now there we will no longer be able to call kern.proc, kern.procargs, kern.procargs2 and see data from any other processes then one's self. It's a quite legit privacy hardening by Apple.

Can anyone confirm that calling sysctlbyname(...) with hw.machine to fetch exact device name is allowed in iOS9 and not affected by restriction mentioned above?

Williamson answered 24/8, 2015 at 13:24 Comment(1)
If you need the string like "iPhone1,1", then also see How to get device make and model on iOS?. It looks easier to use for the model string than sysctlbyname.Anarch
S
3

Yes,I have tested it Using Xcode7 beta5 in iPhone5(iOS9 beta5 installed,not simulator).

+(NSString *) getDeviceModel {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *model = malloc(size);
    sysctlbyname("hw.machine", model, &size, NULL, 0);
    NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
    free(model);
    return deviceModel;
}

And the returning value is "iPhone5,2".So I thought the device name is not affected by restriction on the "sysctl" function.

Schuman answered 1/9, 2015 at 14:42 Comment(3)
Hi, thank you for the answer. But my question was actually is if Apple can reject application that uses "sysctlbyname" with "hw.machine" flag or they just reject only those, who use "kern.proc" flags?Williamson
By the way, fot the same reason we cannot get the list of running apps now (((Spalding
I believe that this is used in CDVDevice.m of Cordova. So if it wasn't allowed then Cordova wouldn't be using it. The real question I have is ... how can we verify this string came from a real device? I need it to prevent people from creating unlimited accounts on my social network.Empery

© 2022 - 2024 — McMap. All rights reserved.