diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2c2277d..c4abf4671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,10 @@ Changes: * `--percent-type` now defaults to 9 (colored percentage numbers) * `fastfetch` now prints LocalIp module by default -* LocalIp module now prints netmask in CIDR format + +Features: +* LocalIP module now prints netmask in CIDR format for IPv4 (LocalIP) +* Bios module now detects system firmware type (Bios) Bugfixes: * Fix unitialized variables (#609) diff --git a/src/detection/bios/bios.h b/src/detection/bios/bios.h index 84046ad40..04d55811c 100644 --- a/src/detection/bios/bios.h +++ b/src/detection/bios/bios.h @@ -11,6 +11,7 @@ typedef struct FFBiosResult FFstrbuf release; FFstrbuf vendor; FFstrbuf version; + FFstrbuf type; } FFBiosResult; const char* ffDetectBios(FFBiosResult* bios); diff --git a/src/detection/bios/bios_android.c b/src/detection/bios/bios_android.c index 737df08de..b2b20aaf9 100644 --- a/src/detection/bios/bios_android.c +++ b/src/detection/bios/bios_android.c @@ -9,5 +9,7 @@ const char* ffDetectBios(FFBiosResult* bios) if (ffStrbufIgnCaseEqualS(&bios->version, "unknown")) ffStrbufClear(&bios->version); + ffStrbufSetStatic(&bios->type, "Bootloader"); + return NULL; } diff --git a/src/detection/bios/bios_apple.c b/src/detection/bios/bios_apple.c index 3ebc1f468..34b7da1d4 100644 --- a/src/detection/bios/bios_apple.c +++ b/src/detection/bios/bios_apple.c @@ -23,7 +23,7 @@ const char* ffDetectBios(FFBiosResult* bios) ffCfDictGetString(properties, CFSTR("vendor"), &bios->vendor); ffCfDictGetString(properties, CFSTR("version"), &bios->version); ffCfDictGetString(properties, CFSTR("release-date"), &bios->date); - ffStrbufAppendS(&bios->release, "Efi"); + ffStrbufSetStatic(&bios->type, "UEFI"); CFRelease(properties); IOObjectRelease(registryEntry); @@ -54,12 +54,12 @@ const char* ffDetectBios(FFBiosResult* bios) uint32_t index = ffStrbufFirstIndexC(&bios->version, '-'); if (index != bios->version.length) { - ffStrbufAppendNS(&bios->release, index, bios->version.chars); + ffStrbufAppendNS(&bios->type, index, bios->version.chars); ffStrbufRemoveSubstr(&bios->version, 0, index + 1); } else { - ffStrbufAppendS(&bios->release, "iBoot"); + ffStrbufSetStatic(&bios->type, "iBoot"); } CFRelease(properties); } diff --git a/src/detection/bios/bios_bsd.c b/src/detection/bios/bios_bsd.c index 26c0dd1b5..6111b4315 100644 --- a/src/detection/bios/bios_bsd.c +++ b/src/detection/bios/bios_bsd.c @@ -1,6 +1,7 @@ #include "bios.h" #include "common/settings.h" +#include "common/sysctl.h" #include "util/smbiosHelper.h" const char* ffDetectBios(FFBiosResult* result) @@ -13,5 +14,6 @@ const char* ffDetectBios(FFBiosResult* result) ffCleanUpSmbiosValue(&result->vendor); ffSettingsGetFreeBSDKenv("smbios.bios.version", &result->version); ffCleanUpSmbiosValue(&result->version); + ffSysctlGetString("machdep.bootmethod", &result->type); return NULL; } diff --git a/src/detection/bios/bios_linux.c b/src/detection/bios/bios_linux.c index fc8cba62b..2c7402c90 100644 --- a/src/detection/bios/bios_linux.c +++ b/src/detection/bios/bios_linux.c @@ -23,5 +23,9 @@ const char* ffDetectBios(FFBiosResult* bios) getSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->release); getSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->vendor); getSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->version); + if (ffPathExists("/sys/firmware/efi", FF_PATHTYPE_DIRECTORY) || ffPathExists("/sys/firmware/acpi/tables/UEFI", FF_PATHTYPE_FILE)) + ffStrbufSetStatic(&bios->type, "UEFI"); + else + ffStrbufSetStatic(&bios->type, "BIOS"); return NULL; } diff --git a/src/detection/bios/bios_windows.c b/src/detection/bios/bios_windows.c index 69930a178..5adfbdd0d 100644 --- a/src/detection/bios/bios_windows.c +++ b/src/detection/bios/bios_windows.c @@ -2,6 +2,30 @@ #include "util/windows/registry.h" #include "util/smbiosHelper.h" +#include +#include + +typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION +{ + GUID BootIdentifier; + FIRMWARE_TYPE FirmwareType; + union + { + ULONGLONG BootFlags; + struct + { + ULONGLONG DbgMenuOsSelection : 1; // REDSTONE4 + ULONGLONG DbgHiberBoot : 1; + ULONGLONG DbgSoftBoot : 1; + ULONGLONG DbgMeasuredLaunch : 1; + ULONGLONG DbgMeasuredLaunchCapable : 1; // 19H1 + ULONGLONG DbgSystemHiveReplace : 1; + ULONGLONG DbgMeasuredLaunchSmmProtections : 1; + ULONGLONG DbgMeasuredLaunchSmmLevel : 7; // 20H1 + }; + }; +} SYSTEM_BOOT_ENVIRONMENT_INFORMATION; + const char* ffDetectBios(FFBiosResult* bios) { FF_HKEY_AUTO_DESTROY hKey = NULL; @@ -24,5 +48,18 @@ const char* ffDetectBios(FFBiosResult* bios) ) ffStrbufAppendF(&bios->release, "%u.%u", (unsigned)major, (unsigned)minor); + // Same as GetFirmwareType, but support (?) Windows 7 + // https://ntdoc.m417z.com/system_information_class + SYSTEM_BOOT_ENVIRONMENT_INFORMATION sbei; + if (NT_SUCCESS(NtQuerySystemInformation(90 /*SystemBootEnvironmentInformation*/, &sbei, sizeof(sbei), NULL))) + { + switch (sbei.FirmwareType) + { + case FirmwareTypeBios: ffStrbufSetStatic(&bios->type, "BIOS"); break; + case FirmwareTypeUefi: ffStrbufSetStatic(&bios->type, "UEFI"); break; + default: break; + } + } + return NULL; } diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index e9b7e3a2b..bc7d9bec1 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -4,7 +4,7 @@ #include "modules/bios/bios.h" #include "util/stringUtils.h" -#define FF_BIOS_NUM_FORMAT_ARGS 4 +#define FF_BIOS_NUM_FORMAT_ARGS 5 void ffPrintBios(FFBiosOptions* options) { @@ -13,9 +13,12 @@ void ffPrintBios(FFBiosOptions* options) ffStrbufInit(&bios.release); ffStrbufInit(&bios.vendor); ffStrbufInit(&bios.version); + ffStrbufInit(&bios.type); const char* error = ffDetectBios(&bios); + FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); + if(error) { ffPrintError(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, "%s", error); @@ -28,21 +31,40 @@ void ffPrintBios(FFBiosOptions* options) goto exit; } - if(options->moduleArgs.outputFormat.length == 0) + if(options->moduleArgs.key.length == 0) { - ffPrintLogoAndKey(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - ffStrbufWriteTo(&bios.version, stdout); - if (bios.release.length) - printf(" (%s)", bios.release.chars); - putchar('\n'); + if(bios.type.length == 0) + ffStrbufSetStatic(&bios.type, "Unknown"); + else if (ffStrbufIgnCaseEqualS(&bios.type, "BIOS")) + ffStrbufSetStatic(&bios.type, "Legacy"); + + ffStrbufSetF(&key, FF_BIOS_MODULE_NAME " (%s)", bios.type.chars); } else { - ffPrintFormat(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, FF_BIOS_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffStrbufClear(&key); + ffParseFormatString(&key, &options->moduleArgs.key, 3, (FFformatarg[]){ + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type}, + }); + } + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufWriteTo(&bios.version, stdout); + if (bios.release.length) + printf(" (%s)\n", bios.release.chars); + else + putchar('\n'); + } + else + { + ffPrintFormat(key.chars, 0, &options->moduleArgs, FF_BIOS_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &bios.date}, {FF_FORMAT_ARG_TYPE_STRBUF, &bios.release}, {FF_FORMAT_ARG_TYPE_STRBUF, &bios.vendor}, {FF_FORMAT_ARG_TYPE_STRBUF, &bios.version}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type}, }); } @@ -51,6 +73,7 @@ exit: ffStrbufDestroy(&bios.release); ffStrbufDestroy(&bios.vendor); ffStrbufDestroy(&bios.version); + ffStrbufDestroy(&bios.type); } bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value) @@ -95,6 +118,7 @@ void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut ffStrbufInit(&bios.release); ffStrbufInit(&bios.vendor); ffStrbufInit(&bios.version); + ffStrbufInit(&bios.type); const char* error = ffDetectBios(&bios); @@ -115,12 +139,14 @@ void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut yyjson_mut_obj_add_strbuf(doc, obj, "release", &bios.release); yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &bios.vendor); yyjson_mut_obj_add_strbuf(doc, obj, "version", &bios.version); + yyjson_mut_obj_add_strbuf(doc, obj, "type", &bios.type); exit: ffStrbufDestroy(&bios.date); ffStrbufDestroy(&bios.release); ffStrbufDestroy(&bios.vendor); ffStrbufDestroy(&bios.version); + ffStrbufDestroy(&bios.type); } void ffPrintBiosHelpFormat(void) @@ -129,7 +155,8 @@ void ffPrintBiosHelpFormat(void) "bios date", "bios release", "bios vendor", - "bios version" + "bios version", + "firmware type", }); }