From 2509cc5e0bf4d9c4bbd6798f71886e34cc8476b2 Mon Sep 17 00:00:00 2001 From: mac builder Date: Tue, 13 Aug 2019 20:01:42 +0200 Subject: [PATCH] get mac serial for hdid --- src/hardware_functions.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/hardware_functions.cpp b/src/hardware_functions.cpp index 5d6b6ff..bd6a6c3 100644 --- a/src/hardware_functions.cpp +++ b/src/hardware_functions.cpp @@ -50,10 +50,31 @@ QString get_hdid() } #elif defined __APPLE__ +#include +#include + QString get_hdid() { - //hdids are broken at this point anyways - return "just a mac passing by"; + CFStringRef serial; + char buffer[64] = {0}; + QString hdid; + io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, + IOServiceMatching("IOPlatformExpertDevice")); + if (platformExpert) + { + CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, + CFSTR(kIOPlatformSerialNumberKey), + kCFAllocatorDefault, 0); + if (serialNumberAsCFString) { + serial = (CFStringRef)serialNumberAsCFString; + } + if (CFStringGetCString(serial, buffer, 64, kCFStringEncodingUTF8)) { + hdid = buffer; + } + + IOObjectRelease(platformExpert); + } + return hdid; } #else