summaryrefslogtreecommitdiffstats
path: root/src/detection/tpm/tpm_windows.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/tpm/tpm_windows.c
Add the files
Diffstat (limited to 'src/detection/tpm/tpm_windows.c')
-rw-r--r--src/detection/tpm/tpm_windows.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/detection/tpm/tpm_windows.c b/src/detection/tpm/tpm_windows.c
new file mode 100644
index 0000000..14f6e8a
--- /dev/null
+++ b/src/detection/tpm/tpm_windows.c
@@ -0,0 +1,51 @@
+#include "tpm.h"
+#include "common/library.h"
+
+#include <windef.h>
+#include <tbs.h>
+#include <winerror.h>
+
+const char* ffDetectTPM(FFTPMResult* result) {
+ FF_LIBRARY_LOAD_MESSAGE(tbs, "TBS" FF_LIBRARY_EXTENSION, -1)
+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE(tbs, Tbsi_GetDeviceInfo)
+
+ TPM_DEVICE_INFO deviceInfo = {};
+ TBS_RESULT code = ffTbsi_GetDeviceInfo(sizeof(deviceInfo), &deviceInfo);
+ if (code != TBS_SUCCESS) {
+ return code == (TBS_RESULT) TBS_E_TPM_NOT_FOUND ? "TPM device is not found" : "Tbsi_GetDeviceInfo() failed";
+ }
+
+ switch (deviceInfo.tpmVersion) {
+ case TPM_VERSION_12:
+ ffStrbufSetStatic(&result->version, "1.2");
+ break;
+ case TPM_VERSION_20:
+ ffStrbufSetStatic(&result->version, "2.0");
+ break;
+ default:
+ ffStrbufSetStatic(&result->version, "unknown");
+ break;
+ }
+
+ switch (deviceInfo.tpmInterfaceType) {
+ case TPM_IFTYPE_1:
+ ffStrbufSetF(&result->description, "I/O-port or MMIO TPM %s", result->version.chars);
+ break;
+ case TPM_IFTYPE_TRUSTZONE:
+ ffStrbufSetF(&result->description, "Trustzone TPM %s", result->version.chars);
+ break;
+ case TPM_IFTYPE_HW:
+ ffStrbufSetF(&result->description, "HW TPM %s", result->version.chars);
+ break;
+ case TPM_IFTYPE_EMULATOR:
+ ffStrbufSetF(&result->description, "SW-emulator TPM %s", result->version.chars);
+ break;
+ case TPM_IFTYPE_SPB:
+ ffStrbufSetF(&result->description, "SPB attached TPM %s", result->version.chars);
+ break;
+ default:
+ break;
+ }
+
+ return NULL;
+}