forked from acidprime/platformExpert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
45 lines (38 loc) · 1.22 KB
/
main.c
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
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
int main (int argc, const char * argv[]) {
CFDataRef data;
char * arg;
if (argc == 1)
{
char *c_msg = "Called without arguments, looking up serial-number";
CFStringRef cf_msg = CFStringCreateWithCString(0, c_msg, kCFStringEncodingUTF8);
CFShow(cf_msg);
arg = "serial-number";
}
else
{
arg = (char *) argv[1];
}
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert)
{
data = IORegistryEntryCreateCFProperty(platformExpert,
CFStringCreateWithCString(
NULL,
arg,
kCFStringEncodingUTF8),
kCFAllocatorDefault, 0);
}
IOObjectRelease(platformExpert);
CFIndex bufferLength = CFDataGetLength(data);
UInt8 *buffer = malloc(bufferLength);
CFDataGetBytes(data, CFRangeMake(0,bufferLength), (UInt8*) buffer);
CFStringRef string = CFStringCreateWithBytes(kCFAllocatorDefault,
buffer,
bufferLength,
kCFStringEncodingUTF8,
TRUE);
CFShow(string);
return 0;
}