diff --git a/platform/pcbid.c b/platform/pcbid.c index 80cc284..7c66c24 100644 --- a/platform/pcbid.c +++ b/platform/pcbid.c @@ -1,18 +1,19 @@ #include +#include #include -#include #include #include #include "hook/table.h" +#include "platform/pcbid.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 struct pcbid_config pcbid_cfg; static const struct hook_symbol pcbid_syms[] = { { @@ -21,42 +22,38 @@ static const struct hook_symbol pcbid_syms[] = { } }; -void pcbid_hook_init(void) +void pcbid_hook_init(const struct pcbid_config *cfg) { - FILE *f; + assert(cfg != NULL); - 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); + if (!cfg->enable) { + return; } + memcpy(&pcbid_cfg, cfg, sizeof(*cfg)); hook_table_apply(NULL, "kernel32.dll", pcbid_syms, _countof(pcbid_syms)); } static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len) { + size_t required; + if (dest == NULL || len == NULL) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - if (*len < sizeof(pcbid_str)) { + wcstombs_s(&required, NULL, 0, pcbid_cfg.serial_no, 0); + + if (required > *len) { SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } dprintf("Pcbid: Get PCB serial\n"); - - memcpy(dest, pcbid_str, sizeof(pcbid_str)); - *len = sizeof(pcbid_str) - 1; + wcstombs_s(NULL, dest, *len, pcbid_cfg.serial_no, *len - 1); return TRUE; } diff --git a/platform/pcbid.h b/platform/pcbid.h index eea24c7..1346af1 100644 --- a/platform/pcbid.h +++ b/platform/pcbid.h @@ -1,3 +1,5 @@ #pragma once -void pcbid_hook_init(void); +#include "platform/config.h" + +void pcbid_hook_init(const struct pcbid_config *cfg);