platform/pcbid.c: Add ALLS hostname hook

This commit is contained in:
Tau 2019-03-16 12:17:16 -04:00
parent 24b82b64e6
commit 657367c040
3 changed files with 67 additions and 0 deletions

View File

@ -12,6 +12,8 @@ platform_lib = static_library(
sources : [
'hwmon.c',
'hwmon.h',
'pcbid.c',
'pcbid.h',
'nusec.c',
'nusec.h',
],

62
platform/pcbid.c Normal file
View File

@ -0,0 +1,62 @@
#include <windows.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}

3
platform/pcbid.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void pcbid_hook_init(void);