From 5c4bed0830c23597fe3da1281ee7ba1563ee43b4 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Tue, 20 Aug 2024 10:18:04 -0400 Subject: [PATCH] siva: port clock chenages from dniel segatools --- platform/clock.c | 27 ++++++++++++++++++--------- platform/clock.h | 1 + sivahook/unity.c | 3 +++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/platform/clock.c b/platform/clock.c index b67b111..e163961 100644 --- a/platform/clock.c +++ b/platform/clock.c @@ -4,6 +4,7 @@ #include #include "hook/table.h" +#include "hook/procaddr.h" #include "platform/clock.h" @@ -19,7 +20,9 @@ static BOOL WINAPI my_SetTimeZoneInformation(TIME_ZONE_INFORMATION *tzinfo); static BOOL (WINAPI * next_GetSystemTimeAsFileTime)(FILETIME *out); static int64_t clock_current_day; +static bool clock_timezone; static bool clock_time_warp; +static bool clock_writeable; static const struct hook_symbol clock_base_hook_syms[] = { { @@ -158,7 +161,7 @@ static BOOL WINAPI my_GetSystemTime(SYSTEMTIME *out) return ok; } -#if 0 +#if defined(LOG_CLOCK) static int last_second; if (out->wSecond != last_second) { @@ -225,35 +228,41 @@ HRESULT clock_hook_init(const struct clock_config *cfg) { assert(cfg != NULL); + clock_timezone = cfg->timezone; clock_time_warp = cfg->timewarp; + clock_writeable = cfg->writeable; - if (cfg->timezone || cfg->timewarp || !cfg->writeable) { + clock_hook_insert_hooks(NULL); + + return S_OK; +} + +void clock_hook_insert_hooks(HMODULE target) { + if (clock_timezone || clock_time_warp || !clock_writeable) { /* All the clock hooks require the core GSTAFT hook to be installed */ /* Note the ! up there btw. */ hook_table_apply( - NULL, + target, "kernel32.dll", clock_base_hook_syms, _countof(clock_base_hook_syms)); } - if (cfg->timezone) { + if (clock_timezone) { hook_table_apply( - NULL, + target, "kernel32.dll", clock_read_hook_syms, _countof(clock_read_hook_syms)); } - if (!cfg->writeable) { + if (!clock_writeable) { /* Install hook if this config parameter is FALSE! */ hook_table_apply( - NULL, + target, "kernel32.dll", clock_write_hook_syms, _countof(clock_write_hook_syms)); } - - return S_OK; } diff --git a/platform/clock.h b/platform/clock.h index 4d67754..6d8c201 100644 --- a/platform/clock.h +++ b/platform/clock.h @@ -11,3 +11,4 @@ struct clock_config { }; HRESULT clock_hook_init(const struct clock_config *cfg); +void clock_hook_insert_hooks(HMODULE target); diff --git a/sivahook/unity.c b/sivahook/unity.c index 7970133..3bb0813 100644 --- a/sivahook/unity.c +++ b/sivahook/unity.c @@ -16,6 +16,7 @@ #include "idmac/idmac.h" #include "platform/cert.h" #include "platform/netenv.h" +#include "platform/clock.h" #include "util/dprintf.h" @@ -119,6 +120,7 @@ static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name) netenv_hook_apply(result); idmac_hook_table_apply(result); serial_hook_apply_hooks(result); + clock_hook_insert_hooks(result); } for (size_t i = 0; i < dep_hooks_len; i++) { @@ -131,6 +133,7 @@ static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name) serial_hook_apply_hooks(dep_mod); reg_hook_insert_hooks(dep_mod); cert_hook_insert_hooks(dep_mod); + clock_hook_insert_hooks(dep_mod); } } }