2019-05-18 03:14:08 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-08-12 23:13:58 +00:00
|
|
|
#include "hook/table.h"
|
|
|
|
|
2019-05-18 03:14:08 +00:00
|
|
|
#include "hooklib/reg.h"
|
|
|
|
|
|
|
|
#include "platform/misc.h"
|
|
|
|
|
2021-08-12 23:13:58 +00:00
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
|
|
|
static BOOL WINAPI misc_ExitWindowsEx(unsigned int flags, uint32_t reason);
|
2024-02-08 06:05:13 +00:00
|
|
|
static int my_vsprintf(char *const buffer, const char *const format, va_list args);
|
|
|
|
static int (*next_vsprintf)(char *const buffer, const char *const format, va_list args);
|
2021-08-12 23:13:58 +00:00
|
|
|
|
2019-05-18 03:14:08 +00:00
|
|
|
static HRESULT misc_read_os_version(void *bytes, uint32_t *nbytes);
|
|
|
|
static HRESULT misc_read_app_loader_count(void *bytes, uint32_t *nbytes);
|
|
|
|
static HRESULT misc_read_cpu_temp_error(void *bytes, uint32_t *nbytes);
|
|
|
|
static HRESULT misc_read_cpu_temp_warning(void *bytes, uint32_t *nbytes);
|
|
|
|
static HRESULT misc_read_platform_id(void *bytes, uint32_t *nbytes);
|
2022-08-12 03:58:24 +00:00
|
|
|
static HRESULT misc_read_platform_name(void *bytes, uint32_t *nbytes);
|
2019-05-18 03:14:08 +00:00
|
|
|
|
2021-08-12 23:13:58 +00:00
|
|
|
static const struct hook_symbol misc_syms[] = {
|
|
|
|
{
|
|
|
|
.name = "ExitWindowsEx",
|
|
|
|
.patch = misc_ExitWindowsEx,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-08 06:05:13 +00:00
|
|
|
static const struct hook_symbol logging_sym[] = {
|
|
|
|
{
|
|
|
|
.name = "vsprintf",
|
|
|
|
.patch = my_vsprintf,
|
|
|
|
.link = (void **) &next_vsprintf,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-18 03:14:08 +00:00
|
|
|
static const struct reg_hook_val misc_root_keys[] = {
|
|
|
|
{
|
|
|
|
.name = L"OSVersion",
|
|
|
|
.read = misc_read_os_version,
|
|
|
|
.type = REG_SZ,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct reg_hook_val misc_master_keys[] = {
|
|
|
|
{
|
|
|
|
.name = L"AppLoaderCount",
|
|
|
|
.read = misc_read_app_loader_count,
|
|
|
|
.type = REG_DWORD,
|
|
|
|
}, {
|
|
|
|
/* Black-hole val, list it here so we don't get a warning msg */
|
|
|
|
.name = L"NextProcess",
|
|
|
|
.type = REG_SZ,
|
2019-06-09 19:38:27 +00:00
|
|
|
}, {
|
|
|
|
/* ditto */
|
|
|
|
.name = L"SystemError",
|
|
|
|
.type = REG_SZ,
|
2019-05-18 03:14:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct reg_hook_val misc_static_keys[] = {
|
|
|
|
{
|
|
|
|
.name = L"CpuTempError",
|
|
|
|
.read = misc_read_cpu_temp_error,
|
|
|
|
.type = REG_DWORD,
|
|
|
|
}, {
|
|
|
|
.name = L"CpuTempWarning",
|
|
|
|
.read = misc_read_cpu_temp_warning,
|
|
|
|
.type = REG_DWORD,
|
|
|
|
}, {
|
|
|
|
.name = L"PlatformId",
|
|
|
|
.read = misc_read_platform_id,
|
|
|
|
.type = REG_SZ,
|
2022-08-12 03:58:24 +00:00
|
|
|
}, {
|
|
|
|
.name = L"PlatformName",
|
|
|
|
.read = misc_read_platform_name,
|
|
|
|
.type = REG_SZ,
|
2019-05-18 03:14:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static wchar_t misc_platform_id[5];
|
|
|
|
|
|
|
|
HRESULT misc_hook_init(const struct misc_config *cfg, const char *platform_id)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(cfg != NULL);
|
|
|
|
assert(platform_id != NULL && strlen(platform_id) == 4);
|
|
|
|
|
|
|
|
if (!cfg->enable) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set platform ID registry value */
|
|
|
|
|
|
|
|
mbstowcs_s(
|
|
|
|
NULL,
|
|
|
|
misc_platform_id,
|
|
|
|
_countof(misc_platform_id),
|
|
|
|
platform_id,
|
|
|
|
_countof(misc_platform_id) - 1);
|
|
|
|
|
|
|
|
/* Add hardcoded dummy keys */
|
|
|
|
|
|
|
|
hr = reg_hook_push_key(
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\SEGA\\SystemProperty",
|
|
|
|
misc_root_keys,
|
|
|
|
_countof(misc_root_keys));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = reg_hook_push_key(
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\SEGA\\SystemProperty\\static",
|
|
|
|
misc_static_keys,
|
|
|
|
_countof(misc_static_keys));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = reg_hook_push_key(
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\SEGA\\SystemProperty\\Master",
|
|
|
|
misc_master_keys,
|
|
|
|
_countof(misc_master_keys));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-08-12 23:13:58 +00:00
|
|
|
/* Apply function hooks */
|
|
|
|
|
|
|
|
hook_table_apply(NULL, "user32.dll", misc_syms, _countof(misc_syms));
|
2024-02-08 06:05:13 +00:00
|
|
|
hook_table_apply(NULL, "msvcr110.dll", logging_sym, _countof(logging_sym));
|
2021-08-12 23:13:58 +00:00
|
|
|
|
2019-05-18 03:14:08 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-08-12 23:13:58 +00:00
|
|
|
static BOOL WINAPI misc_ExitWindowsEx(unsigned int flags, uint32_t reason)
|
|
|
|
{
|
|
|
|
dprintf("Misc: Blocked system reboot\n");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-18 03:14:08 +00:00
|
|
|
static HRESULT misc_read_os_version(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_wstr(bytes, nbytes, L"0_0_0");
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT misc_read_app_loader_count(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_u32(bytes, nbytes, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT misc_read_cpu_temp_error(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_u32(bytes, nbytes, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT misc_read_cpu_temp_warning(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_u32(bytes, nbytes, 95);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT misc_read_platform_id(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_wstr(bytes, nbytes, misc_platform_id);
|
|
|
|
}
|
2022-08-12 03:58:24 +00:00
|
|
|
|
|
|
|
static HRESULT misc_read_platform_name(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_wstr(bytes, nbytes, L"ALLS MX2.1"); // TODO: Dynamic
|
|
|
|
}
|
2024-02-08 06:05:13 +00:00
|
|
|
|
|
|
|
static int my_vsprintf(char *const buffer, const char *const format, va_list args)
|
|
|
|
{
|
|
|
|
int ret = next_vsprintf(buffer, format, args);
|
|
|
|
dprintf("%s\n", buffer);
|
|
|
|
return ret;
|
|
|
|
}
|