forked from brunexgeek/smbios-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_macos_hardware_debug.c
More file actions
84 lines (70 loc) · 2.45 KB
/
Copy pathtest_macos_hardware_debug.c
File metadata and controls
84 lines (70 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Debug test - check what properties are available
*/
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
static void print_property(io_service_t service, const char *key_name) {
const CFStringRef key = CFStringCreateWithCString(NULL, key_name, kCFStringEncodingUTF8);
if (!key) return;
const CFTypeRef prop = IORegistryEntryCreateCFProperty(service, key, kCFAllocatorDefault, 0);
CFRelease(key);
if (!prop) {
printf(" %-20s: <not found>\n", key_name);
return;
}
printf(" %-20s: ", key_name);
if (CFGetTypeID(prop) == CFStringGetTypeID()) {
char buf[256];
if (CFStringGetCString((CFStringRef) prop, buf, sizeof(buf), kCFStringEncodingUTF8)) {
printf("%s\n", buf);
} else {
printf("<cfstring conversion error>\n");
}
} else if (CFGetTypeID(prop) == CFDataGetTypeID()) {
const CFDataRef data = (CFDataRef) prop;
const CFIndex len = CFDataGetLength(data);
const UInt8 *bytes = CFDataGetBytePtr(data);
printf("[CFData len=%ld] ", len);
for (CFIndex i = 0; i < len && i < 64; i++) {
if (bytes[i] >= 32 && bytes[i] < 127) {
putchar(bytes[i]);
} else {
printf("\\x%02X", bytes[i]);
}
}
if (len >= 64) printf("...");
putchar('\n');
} else {
printf("<unknown type>\n");
}
CFRelease(prop);
}
int main(void) {
CFMutableDictionaryRef matching;
io_service_t service;
printf("=== IOKit Property Discovery ===\n\n");
matching = IOServiceMatching("IOPlatformExpertDevice");
if (!matching) {
fprintf(stderr, "ERROR: IOServiceMatching failed\n");
return 1;
}
service = IOServiceGetMatchingService(kIOMainPortDefault, matching);
if (service == 0) {
fprintf(stderr, "ERROR: IOServiceGetMatchingService failed\n");
return 1;
}
printf("Found IOPlatformExpertDevice\n");
/* Try common properties */
print_property(service, kIOPlatformUUIDKey);
print_property(service, "serial-number");
print_property(service, "model");
print_property(service, "board-id");
print_property(service, "platform-name");
print_property(service, "product-name");
print_property(service, "compatible");
print_property(service, "manufacturer");
print_property(service, "location");
IOObjectRelease(service);
return 0;
}