1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-12-21 07:35:52 +01:00
segatools-dniel97/platform/pcbid.c

71 lines
1.4 KiB
C
Raw Normal View History

#include <windows.h>
2019-08-21 00:44:57 +02:00
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "hook/table.h"
2019-08-21 00:44:57 +02:00
#include "platform/pcbid.h"
#include "util/dprintf.h"
static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len);
2019-08-21 00:44:57 +02:00
static struct pcbid_config pcbid_cfg;
static const struct hook_symbol pcbid_syms[] = {
{
.name = "GetComputerNameA",
.patch = pcbid_GetComputerNameA,
}
};
HRESULT pcbid_hook_init(const struct pcbid_config *cfg)
{
2019-08-21 00:44:57 +02:00
assert(cfg != NULL);
2019-08-21 00:44:57 +02:00
if (!cfg->enable) {
return S_FALSE;
}
2019-08-31 00:45:24 +02:00
if (wcslen(cfg->serial_no) != 15) {
dprintf("Pcbid: ERROR: Must be 15 chars! ex: ACAE01A99999999\n");
return E_INVALIDARG;
2019-08-31 00:45:24 +02:00
}
2019-08-21 00:44:57 +02:00
memcpy(&pcbid_cfg, cfg, sizeof(*cfg));
hook_table_apply(NULL, "kernel32.dll", pcbid_syms, _countof(pcbid_syms));
return S_OK;
}
static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len)
{
2019-08-21 00:44:57 +02:00
size_t required;
if (dest == NULL || len == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
2019-08-21 00:44:57 +02:00
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");
2019-08-31 00:45:24 +02:00
2019-08-21 00:44:57 +02:00
wcstombs_s(NULL, dest, *len, pcbid_cfg.serial_no, *len - 1);
2019-08-31 00:45:24 +02:00
SetLastError(ERROR_SUCCESS);
*len = required - 1;
return TRUE;
}