From 42276cee4b6bb2ce34f7b4396a7236b8db08089f Mon Sep 17 00:00:00 2001 From: kxtzownsu Date: Sat, 7 Dec 2024 12:06:07 -0500 Subject: [PATCH] kvs: add working AP firmware version detection --- Makefile | 2 +- include/hex_utils.h | 3 +++ include/sysinfo.h | 29 +++++++++++++++++++++++++++++ src/KVS/main.c | 9 ++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 include/sysinfo.h diff --git a/Makefile b/Makefile index 7304ccd..c80b0ed 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CC ?= gcc +CC := gcc SHELL ?= /bin/sh KVSFLIST := \ src/KVS/main.c \ diff --git a/include/hex_utils.h b/include/hex_utils.h index 4aa5592..925c851 100644 --- a/include/hex_utils.h +++ b/include/hex_utils.h @@ -1,3 +1,6 @@ +#include +#include + uint32_t convert_to_uint32(const char *str) { char *endptr; unsigned long ul_value = strtoul(str, &endptr, 0); diff --git a/include/sysinfo.h b/include/sysinfo.h new file mode 100644 index 0000000..c3c20f0 --- /dev/null +++ b/include/sysinfo.h @@ -0,0 +1,29 @@ +void trim_newline(char* str) { + size_t len = strlen(str); + if (len > 0 && str[len - 1] == '\n') { + str[len - 1] = '\0'; + } +} + + +const char* getFirmwareVersion(){ + // note, may not work on all chromebooks + FILE *fptr; + char stupidfile[] = "/sys/class/dmi/id/bios_version"; + fptr = fopen(stupidfile, "r"); + static char firmwareVersion[1024]; + + if (fptr == NULL) { + printf("Error reading Firmware Version \n"); + printf("Please report as a bug at https://github.com/kxtzownsu/KVS-private\n"); + + sleep(86400); // sleep for 1d if error + return "Error!"; + } + fgets(firmwareVersion, 100, fptr); + fclose(fptr); + + trim_newline(firmwareVersion); + + return firmwareVersion; +} \ No newline at end of file diff --git a/src/KVS/main.c b/src/KVS/main.c index 278b880..fa32ced 100644 --- a/src/KVS/main.c +++ b/src/KVS/main.c @@ -1,11 +1,18 @@ #include #include #include +#include #include "ui.h" +#include "sysinfo.h" int main(int argc, char **argv) { + if (geteuid() != 0){ + printf("Please run KVS as root!\n"); + exit(1); + } + // example values for testing - char* fwver = "Google_Grunt.11031.149.0"; + const char* fwver = getFirmwareVersion(); char* kernver = "0x00010001"; char* tpmver = "2.0"; char* fwmp = "0x1";