From 657367c040d6e719de8a55384781c8f98fd3c8ce Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 16 Mar 2019 12:17:16 -0400 Subject: [PATCH] platform/pcbid.c: Add ALLS hostname hook --- platform/meson.build | 2 ++ platform/pcbid.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ platform/pcbid.h | 3 +++ 3 files changed, 67 insertions(+) create mode 100644 platform/pcbid.c create mode 100644 platform/pcbid.h diff --git a/platform/meson.build b/platform/meson.build index bdaef9d..560c3b3 100644 --- a/platform/meson.build +++ b/platform/meson.build @@ -12,6 +12,8 @@ platform_lib = static_library( sources : [ 'hwmon.c', 'hwmon.h', + 'pcbid.c', + 'pcbid.h', 'nusec.c', 'nusec.h', ], diff --git a/platform/pcbid.c b/platform/pcbid.c new file mode 100644 index 0000000..80cc284 --- /dev/null +++ b/platform/pcbid.c @@ -0,0 +1,62 @@ +#include + +#include +#include +#include +#include + +#include "hook/table.h" + +#include "util/dprintf.h" + +static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len); + +static const char pcbid_file[] = "DEVICE/pcbid.txt"; +static char pcbid_str[16]; + +static const struct hook_symbol pcbid_syms[] = { + { + .name = "GetComputerNameA", + .patch = pcbid_GetComputerNameA, + } +}; + +void pcbid_hook_init(void) +{ + FILE *f; + + f = fopen(pcbid_file, "r"); + + if (f != NULL) { + /* De-hyphenate the serial number. Game code will re-insert it. */ + fscanf(f, "%4s-", &pcbid_str[0]); + fscanf(f, "%11s", &pcbid_str[4]); + fclose(f); + } else { + dprintf("Failed to open %s\n", pcbid_file); + } + + hook_table_apply(NULL, "kernel32.dll", pcbid_syms, _countof(pcbid_syms)); +} + +static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len) +{ + if (dest == NULL || len == NULL) { + SetLastError(ERROR_INVALID_PARAMETER); + + return FALSE; + } + + if (*len < sizeof(pcbid_str)) { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + + return FALSE; + } + + dprintf("Pcbid: Get PCB serial\n"); + + memcpy(dest, pcbid_str, sizeof(pcbid_str)); + *len = sizeof(pcbid_str) - 1; + + return TRUE; +} diff --git a/platform/pcbid.h b/platform/pcbid.h new file mode 100644 index 0000000..eea24c7 --- /dev/null +++ b/platform/pcbid.h @@ -0,0 +1,3 @@ +#pragma once + +void pcbid_hook_init(void);