diff --git a/src/detection/os/os_android.c b/src/detection/os/os_android.c index 17752a27b..7d39954d6 100644 --- a/src/detection/os/os_android.c +++ b/src/detection/os/os_android.c @@ -5,8 +5,6 @@ void ffDetectOSImpl(FFOSResult* os) { ffStrbufSetStatic(&os->name, "Android"); - ffStrbufSetStatic(&os->prettyName, "Android"); - ffStrbufSetStatic(&os->id, "android"); ffSettingsGetAndroidProperty("ro.build.version.release", &os->version); diff --git a/src/detection/os/os_apple.m b/src/detection/os/os_apple.m index b86202b1e..dc8e30a12 100644 --- a/src/detection/os/os_apple.m +++ b/src/detection/os/os_apple.m @@ -54,18 +54,18 @@ static bool detectOSCodeName(FFOSResult* os) case 14: ffStrbufSetStatic(&os->codename, "Mojave"); return true; case 13: ffStrbufSetStatic(&os->codename, "High Sierra"); return true; case 12: ffStrbufSetStatic(&os->codename, "Sierra"); return true; - case 11: ffStrbufSetStatic(&os->codename, "El Capitan"); ffStrbufSetStatic(&os->prettyName, "OS X"); return true; - case 10: ffStrbufSetStatic(&os->codename, "Yosemite"); ffStrbufSetStatic(&os->prettyName, "OS X"); return true; - case 9: ffStrbufSetStatic(&os->codename, "Mavericks"); ffStrbufSetStatic(&os->prettyName, "OS X"); return true; - case 8: ffStrbufSetStatic(&os->codename, "Mountain Lion"); ffStrbufSetStatic(&os->prettyName, "OS X"); return true; - case 7: ffStrbufSetStatic(&os->codename, "Lion"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 6: ffStrbufSetStatic(&os->codename, "Snow Leopard"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 5: ffStrbufSetStatic(&os->codename, "Leopard"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 4: ffStrbufSetStatic(&os->codename, "Tiger"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; + case 11: ffStrbufSetStatic(&os->codename, "El Capitan"); return true; + case 10: ffStrbufSetStatic(&os->codename, "Yosemite"); return true; + case 9: ffStrbufSetStatic(&os->codename, "Mavericks"); return true; + case 8: ffStrbufSetStatic(&os->codename, "Mountain Lion"); return true; + case 7: ffStrbufSetStatic(&os->codename, "Lion"); return true; + case 6: ffStrbufSetStatic(&os->codename, "Snow Leopard"); return true; + case 5: ffStrbufSetStatic(&os->codename, "Leopard"); return true; + case 4: ffStrbufSetStatic(&os->codename, "Tiger"); return true; case 3: ffStrbufSetStatic(&os->codename, "Panther"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 2: ffStrbufSetStatic(&os->codename, "Jaguar"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 1: ffStrbufSetStatic(&os->codename, "Puma"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; - case 0: ffStrbufSetStatic(&os->codename, "Cheetah"); ffStrbufSetStatic(&os->prettyName, "Mac OS X"); return true; + case 2: ffStrbufSetStatic(&os->codename, "Jaguar"); return true; + case 1: ffStrbufSetStatic(&os->codename, "Puma"); return true; + case 0: ffStrbufSetStatic(&os->codename, "Cheetah"); return true; } } } @@ -106,8 +106,6 @@ void ffDetectOSImpl(FFOSResult* os) if(os->buildID.length == 0) ffSysctlGetString("kern.osversion", &os->buildID); - if(os->prettyName.length == 0) - ffStrbufSetStatic(&os->prettyName, "macOS"); ffStrbufAppend(&os->versionID, &os->version); if(!detectOSCodeName(os)) diff --git a/src/detection/os/os_windows.c b/src/detection/os/os_windows.c index dda2004c5..ae3ff5083 100644 --- a/src/detection/os/os_windows.c +++ b/src/detection/os/os_windows.c @@ -13,6 +13,7 @@ void ffDetectOSImpl(FFOSResult* os) const wchar_t* rawName = BrandingFormatString(L"%WINDOWS_LONG%"); ffStrbufSetWS(&os->variant, rawName); GlobalFree((HGLOBAL)rawName); + ffStrbufSet(&os->prettyName, &os->variant); ffStrbufTrimRight(&os->variant, ' '); //WMI returns the "Microsoft" prefix while BrandingFormatString doesn't. Make them consistent. @@ -22,14 +23,12 @@ void ffDetectOSImpl(FFOSResult* os) if(ffStrbufStartsWithS(&os->variant, "Windows ")) { ffStrbufAppendS(&os->name, "Windows"); - ffStrbufAppendS(&os->prettyName, "Windows"); ffStrbufSubstrAfter(&os->variant, strlen("Windows ") - 1); if(ffStrbufStartsWithS(&os->variant, "Server ")) { ffStrbufAppendS(&os->name, " Server"); - ffStrbufAppendS(&os->prettyName, " Server"); ffStrbufSubstrAfter(&os->variant, strlen(" Server") - 1); } @@ -38,7 +37,7 @@ void ffDetectOSImpl(FFOSResult* os) ffStrbufSubstrAfter(&os->variant, index); // Windows Server 20xx Rx - if(ffStrbufEndsWithC(&os->prettyName, 'r')) + if(ffStrbufEndsWithC(&os->name, 'r')) { if(os->variant.chars[0] == 'R' && ffCharIsDigit(os->variant.chars[1]) && @@ -56,6 +55,6 @@ void ffDetectOSImpl(FFOSResult* os) ffStrbufClear(&os->variant); } - ffStrbufAppendF(&os->id, "%*s %*s", os->prettyName.length, os->prettyName.chars, os->version.length, os->version.chars); + ffStrbufAppendF(&os->id, "%s %s", os->name.chars, os->version.chars); ffStrbufSetStatic(&os->idLike, "Windows"); } diff --git a/src/modules/os/os.c b/src/modules/os/os.c index 10df93b0f..b26ef8600 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -51,38 +51,6 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result) ffStrbufAppend(result, &os->variantID); ffStrbufAppendC(result, ')'); } - - //Append architecture if it is missing - if(!ffStrbufContainIgnCase(result, &instance.state.platform.sysinfo.architecture)) - { - ffStrbufAppendC(result, ' '); - ffStrbufAppend(result, &instance.state.platform.sysinfo.architecture); - } -} - -static void buildOutputNixOS(const FFOSResult* os, FFstrbuf* result) -{ - ffStrbufAppendS(result, "NixOS"); - - if(os->buildID.length > 0) - { - ffStrbufAppendC(result, ' '); - ffStrbufAppend(result, &os->buildID); - } - - if(os->codename.length > 0) - { - ffStrbufAppendS(result, " ("); - ffStrbufAppendC(result, (char) toupper(os->codename.chars[0])); - ffStrbufAppendS(result, os->codename.chars + 1); - ffStrbufAppendC(result, ')'); - } - - if(instance.state.platform.sysinfo.architecture.length > 0) - { - ffStrbufAppendC(result, ' '); - ffStrbufAppend(result, &instance.state.platform.sysinfo.architecture); - } } void ffPrintOS(FFOSOptions* options) @@ -99,11 +67,18 @@ void ffPrintOS(FFOSOptions* options) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); - if(ffStrbufIgnCaseCompS(&os->id, "nixos") == 0) - buildOutputNixOS(os, &result); + if(os->prettyName.length > 0) + ffStrbufAppend(&result, &os->prettyName); else buildOutputDefault(os, &result); + //Append architecture if it is missing + if(!ffStrbufContainIgnCase(&result, &instance.state.platform.sysinfo.architecture)) + { + ffStrbufAppendC(&result, ' '); + ffStrbufAppend(&result, &instance.state.platform.sysinfo.architecture); + } + ffPrintLogoAndKey(FF_OS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); ffStrbufPutTo(&result, stdout); } @@ -195,7 +170,7 @@ static FFModuleBaseInfo ffModuleInfo = { .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) { {"Name of the kernel", "sysname"}, {"Name of the OS", "name"}, - {"Pretty name of the OS", "pretty-name"}, + {"Pretty name of the OS, if available", "pretty-name"}, {"ID of the OS", "id"}, {"ID like of the OS", "id-like"}, {"Variant of the OS", "variant"},