1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-24 05:20:10 +01:00
segatools-dniel97/platform/pcbid.c
2019-08-30 18:45:24 -04:00

69 lines
1.4 KiB
C

#include <windows.h>
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "hook/table.h"
#include "platform/pcbid.h"
#include "util/dprintf.h"
static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len);
static struct pcbid_config pcbid_cfg;
static const struct hook_symbol pcbid_syms[] = {
{
.name = "GetComputerNameA",
.patch = pcbid_GetComputerNameA,
}
};
void pcbid_hook_init(const struct pcbid_config *cfg)
{
assert(cfg != NULL);
if (!cfg->enable) {
return;
}
if (wcslen(cfg->serial_no) != 15) {
dprintf("Pcbid: ERROR: Must be 15 chars! ex: ACAE01A99999999\n");
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;
}
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");
wcstombs_s(NULL, dest, *len, pcbid_cfg.serial_no, *len - 1);
SetLastError(ERROR_SUCCESS);
*len = required - 1;
return TRUE;
}