From e6e78a7aae6638c7f1234dd6b5efbf9d38370538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Sep 2025 13:35:48 +0800 Subject: [PATCH] OS (macOS): improves OS detection accuracy and sets pretty name --- src/detection/os/os_apple.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/detection/os/os_apple.m b/src/detection/os/os_apple.m index 8aabfabd4..82732ac79 100644 --- a/src/detection/os/os_apple.m +++ b/src/detection/os/os_apple.m @@ -8,14 +8,14 @@ #include #import -static void parseSystemVersion(FFOSResult* os) +static bool parseSystemVersion(FFOSResult* os) { NSError* error; NSString* fileName = @"file:///System/Library/CoreServices/SystemVersion.plist"; NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName] error:&error]; if(error) - return; + return false; NSString* value; @@ -30,6 +30,8 @@ static void parseSystemVersion(FFOSResult* os) // macOS 26 Tahoe. #1809 os->version.chars[0] = '2'; } + + return true; } static bool detectOSCodeName(FFOSResult* os) @@ -86,13 +88,18 @@ void ffDetectOSImpl(FFOSResult* os) ffStrbufSetStatic(&os->id, "macos"); - if(os->version.length == 0) + if(__builtin_expect(os->name.length == 0, 0)) + ffStrbufSetStatic(&os->name, "macOS"); + + if(__builtin_expect(os->version.length == 0, 0)) ffSysctlGetString("kern.osproductversion", &os->version); - if(os->buildID.length == 0) + if(__builtin_expect(os->buildID.length == 0, 0)) ffSysctlGetString("kern.osversion", &os->buildID); ffStrbufAppend(&os->versionID, &os->version); detectOSCodeName(os); + + ffStrbufSetF(&os->prettyName, "%s %s %s (%s)", os->name.chars, os->codename.chars, os->version.chars, os->buildID.chars); }