33#include "common/sysctl.h"
44
55#include <stdlib.h>
6+ #include <string.h>
67
78typedef enum PListKey
89{
@@ -12,7 +13,7 @@ typedef enum PListKey
1213 PLIST_KEY_OTHER
1314} PListKey ;
1415
15- static void parseFile (FFOSResult * os )
16+ static void parseSystemVersion (FFOSResult * os )
1617{
1718 FILE * plist = fopen ("/System/Library/CoreServices/SystemVersion.plist" , "r" );
1819 if (plist == NULL )
@@ -58,6 +59,33 @@ static void parseFile(FFOSResult* os)
5859 fclose (plist );
5960}
6061
62+ void parseOSXSoftwareLicense (FFOSResult * os )
63+ {
64+ FILE * rtf = fopen ("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf" , "r" );
65+ if (rtf == NULL )
66+ return ;
67+
68+ char * line = NULL ;
69+ size_t len = 0 ;
70+ const char * searchStr = "\\f0\\b SOFTWARE LICENSE AGREEMENT FOR macOS " ;
71+ const size_t searchLen = strlen (searchStr );
72+ while (getline (& line , & len , rtf ) != EOF )
73+ {
74+ if (strncmp (line , searchStr , searchLen ) == 0 )
75+ {
76+ ffStrbufAppendS (& os -> codename , line + searchLen );
77+ ffStrbufTrimRight (& os -> codename , '\n' );
78+ ffStrbufTrimRight (& os -> codename , '\\' );
79+ break ;
80+ }
81+ }
82+
83+ if (line != NULL )
84+ free (line );
85+
86+ fclose (rtf );
87+ }
88+
6189void ffDetectOSImpl (FFOSResult * os , const FFinstance * instance )
6290{
6391 FF_UNUSED (instance );
@@ -76,17 +104,21 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
76104 ffStrbufInitA (& os -> variant , 0 );
77105 ffStrbufInitA (& os -> variantID , 0 );
78106
79- parseFile (os );
107+ parseSystemVersion (os );
80108
81109 if (ffStrbufStartsWithIgnCaseS (& os -> name , "MacOS" ))
82110 ffStrbufAppendS (& os -> id , "macos" );
83111
84112 if (os -> version .length == 0 )
85113 ffSysctlGetString ("kern.osproductversion" , & os -> version );
86114
87- //TODO map version to pretty name
115+ if (os -> buildID .length == 0 )
116+ ffSysctlGetString ("kern.osversion" , & os -> buildID );
117+
88118 ffStrbufAppend (& os -> prettyName , & os -> name );
89119 ffStrbufAppend (& os -> versionID , & os -> version );
90120 ffSysctlGetString ("kern.ostype" , & os -> systemName );
91121 ffSysctlGetString ("hw.machine" , & os -> architecture );
122+
123+ parseOSXSoftwareLicense (os );
92124}
0 commit comments