Howdy!
I have been experimenting with my system's electronics (MacBook Pro 13-inch, M1, 2020) by using software probe written in C/C++ type program. The idea is to extract the relevant information just like it is presented in
Apple > About This Mac > System Report,
for my cross-platform Engine.
I have been tinkering with a tool dmidecode. It works just fine on Linux and Windows. For MacOS, I need to find a graceful way of obtaining the AppleSMBIOS service, in this context.
To my best of knowledge, the service is nonexistent as I have checked by C code and some application named IORegistryExplorer (courtesy Google).
Just wondering if someone has been on such endurance and how much satisfaction has been achieved upon the topic.
Thanks a lot!
WARNING The I/O Registry presents significant binary compatibility challenges. Rummaging around the registry and pulling out undocumented properties is not something that we support. It might work today on your specific Mac, but it might not work on other machines or in previous or future OS releases.
With that out of the way, let’s see what we can do to help. You wrote:
void* someValuePointer = malloc(CFNumberGetByteSize(someStuff));
if(CFNumberGetValue(someStuff, CFNumberGetType(someStuff), someValuePointer))
That code is kinda weird. A CFNumber holds an abstract numeric value. While you can look at the specific type of number it holds, in most case you don’t need to. Rather, you ask for the type you want and CFNumber does the conversion. For example:
CFNumberRef n1234 = … a CFNumber with the value 1234 …
int64_t i64 = 0;
Boolean success = CFNumberGetValue(n1234, kCFNumberSInt64Type, &i64);
if ( ! success ) {
// … handle the error …
}
printf("%lld\n", (long long) i64);
Also, when dealing with Core Foundation types the best you can do is leave ‘CF Land’ as quickly as possible and do all the heavy lifting in Objective-C. That yields a much nicer API:
CFNumberRef cf = … a CFNumber with a +0 reference count …
NSNumber * ns = (__bridge NSNumber *) cf;
NSUInteger u = ns.unsignedIntegerValue;
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"