#include #include "hook/table.h" #include "hooklib/reg.h" #include "hook/procaddr.h" #include "util/dprintf.h" #include "saohook/systype.h" #include "platform/es3sec.h" const wchar_t *cpu_name_client = L"Intel(R) Genuine Snake Oil"; const wchar_t *cpu_name_terminal = L"AMD(R) Certified Abacus"; static bool is_terminal = false; static struct es3sec_config dong_config; static HRESULT systype_read_cpu_name(void *bytes, uint32_t *nbytes); static BOOL my_GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer); static BOOL (*next_GlobalMemoryStatusEx)(LPMEMORYSTATUSEX lpBuffer); static int my_GetSerialNumber(ULONG usercode, intptr_t serialnumber); static int (*next_GetSerialNumber)(ULONG usercode, intptr_t serialnumber); const struct reg_hook_val sys_info_reg[] = { { .name = L"ProcessorNameString", .type = REG_SZ, .read = systype_read_cpu_name } }; static const struct hook_symbol systype_kernel32_syms[] = { { .name = "GlobalMemoryStatusEx", .patch = my_GlobalMemoryStatusEx, .link = (void **) &next_GlobalMemoryStatusEx, }, }; static struct hook_symbol procaddr_dong_syms[] = { { .name = "GetSerialNumber", .patch = my_GetSerialNumber, .link = (void **) &next_GetSerialNumber, }, }; HRESULT systype_hook_init(const struct systype_config *sys_cfg, const struct es3sec_config *dong_cfg) { HRESULT hr = S_OK; if (!sys_cfg->enable) { return hr; } is_terminal = sys_cfg->type; memcpy(&dong_config, dong_cfg, sizeof(*dong_cfg)); hr = reg_hook_push_key( HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", sys_info_reg, _countof(sys_info_reg)); hook_table_apply( NULL, "kernel32.dll", systype_kernel32_syms, _countof(systype_kernel32_syms)); proc_addr_table_push( NULL, "nbamUsbFinder_sup.dll", procaddr_dong_syms, _countof(procaddr_dong_syms) ); dprintf("Systype: Init\n"); return hr; } static HRESULT systype_read_cpu_name(void *bytes, uint32_t *nbytes) { dprintf("Systype: Read CPU Name\n"); if (!is_terminal) { return reg_hook_read_wstr(bytes, nbytes, cpu_name_client); } return reg_hook_read_wstr(bytes, nbytes, cpu_name_terminal); } static BOOL my_GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer) { dprintf("Systype: Get RAM Size\n"); BOOL ret = next_GlobalMemoryStatusEx(lpBuffer); if (!ret) { dprintf("Systype: next_GlobalMemoryStatusEx failed!\n"); return ret; } if (!is_terminal) { lpBuffer->ullTotalPhys = (DWORDLONG) 8000 << 20; } else { lpBuffer->ullTotalPhys = (DWORDLONG) 4000 << 20; } return true; } static int my_GetSerialNumber(ULONG usercode, intptr_t serialnumber) { wcstombs((char *)serialnumber, dong_config.serial, 32); dprintf("Systype: my_GetSerialNumber %ls\n", dong_config.serial); return 0; }