diff --git a/Sandboxie/core/dll/kernel.c b/Sandboxie/core/dll/kernel.c index 3305ba5fb7..b9d2590332 100644 --- a/Sandboxie/core/dll/kernel.c +++ b/Sandboxie/core/dll/kernel.c @@ -74,6 +74,13 @@ typedef LANGID (*P_GetSystemDefaultLangID)(); typedef BOOL (*P_GetVolumeInformationByHandleW)(HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber,LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize); +typedef void (*P_GetLocalTime)(LPSYSTEMTIME lpSystemTime); + +typedef void (*P_GetSystemTime)(LPSYSTEMTIME lpSystemTime); + +typedef void (*P_GetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime); + +typedef void (*P_GetSystemTimePreciseAsFileTime)(LPFILETIME lpSystemTimeAsFileTime); //typedef int (*P_GetLocaleInfoEx)(LPCWSTR lpLocaleName, LCTYPE LCType, LPWSTR lpLCData, int cchData); //typedef int (*P_GetLocaleInfoA)(LCID Locale, LCTYPE LCType, LPSTR lpLCData, int cchData); @@ -110,6 +117,11 @@ P_GetSystemDefaultLocaleName __sys_GetSystemDefaultLocaleName = NULL; P_GetSystemDefaultLCID __sys_GetSystemDefaultLCID = NULL; P_GetSystemDefaultLangID __sys_GetSystemDefaultLangID = NULL; P_GetVolumeInformationByHandleW __sys_GetVolumeInformationByHandleW = NULL; +P_GetSystemTime __sys_GetSystemTime = NULL; +P_GetSystemTimeAsFileTime __sys_GetSystemTimeAsFileTime = NULL; +P_GetLocalTime __sys_GetLocalTime = NULL; + +P_GetSystemTimePreciseAsFileTime __sys_GetSystemTimePreciseAsFileTime = NULL; LCID Kernel_CustomLCID = 0; @@ -161,7 +173,14 @@ static LCID Kernel_GetSystemDefaultLCID(); static LANGID Kernel_GetSystemDefaultLangID(); static BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber, LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags, LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize); - + +static void Kernel_GetLocalTime(LPSYSTEMTIME lpSystemTime); + +static void Kernel_GetSystemTime(LPSYSTEMTIME lpSystemTime); + +static void Kernel_GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime); + +static void Kernel_GetSystemTimePreciseAsFileTime(LPFILETIME lpSystemTimeAsFileTime); //--------------------------------------------------------------------------- // Kernel_Init //--------------------------------------------------------------------------- @@ -270,6 +289,15 @@ _FX BOOLEAN Kernel_Init() SBIEDLL_HOOK(Kernel_, GetVolumeInformationByHandleW); } } + if (SbieApi_QueryConfBool(NULL, L"TimeOffset", FALSE)) { + SBIEDLL_HOOK(Kernel_, GetSystemTime); + SBIEDLL_HOOK(Kernel_, GetSystemTimeAsFileTime); + void* GetSystemTimePreciseAsFileTime = GetProcAddress(Dll_KernelBase ? Dll_KernelBase : Dll_Kernel32, "GetSystemTimePreciseAsFileTime"); + if (GetSystemTimePreciseAsFileTime) { + SBIEDLL_HOOK(Kernel_, GetSystemTimePreciseAsFileTime); + } + SBIEDLL_HOOK(Kernel_, GetLocalTime); + } return TRUE; } @@ -542,3 +570,97 @@ _FX BOOL Kernel_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameB } return rtn; } +_FX void Kernel_GetLocalTime(LPSYSTEMTIME lpSystemTime) { + __sys_GetLocalTime(lpSystemTime); + if (SbieApi_QueryConfBool(NULL, L"TimeOffsetPlus", TRUE)) { + lpSystemTime->wYear += (WORD)SbieApi_QueryConfNumber(NULL,"TimeOffsetYear",0); + lpSystemTime->wDay += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + + } + else { + lpSystemTime->wYear -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + } +} + +_FX void Kernel_GetSystemTime(LPSYSTEMTIME lpSystemTime) { + __sys_GetSystemTime(lpSystemTime); + if (SbieApi_QueryConfBool(NULL, L"TimeOffsetPlus", TRUE)) { + lpSystemTime->wYear += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + + } + else { + lpSystemTime->wYear -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + } +} + +_FX void Kernel_GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime) { + LPSYSTEMTIME lpSystemTime=(LPSYSTEMTIME)Dll_Alloc(sizeof(LPSYSTEMTIME)); + memset(lpSystemTimeAsFileTime, 0, sizeof(lpSystemTimeAsFileTime)); + __sys_GetSystemTimeAsFileTime(lpSystemTimeAsFileTime); + if (FileTimeToSystemTime(lpSystemTimeAsFileTime, lpSystemTime)) { + if (SbieApi_QueryConfBool(NULL, L"TimeOffsetPlus", TRUE)) { + lpSystemTime->wYear += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + + } + else { + lpSystemTime->wYear -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + } + SystemTimeToFileTime(lpSystemTime, lpSystemTimeAsFileTime); + Dll_Free(lpSystemTime); + } +} +_FX void Kernel_GetSystemTimePreciseAsFileTime(LPFILETIME lpSystemTimeAsFileTime) { + LPSYSTEMTIME lpSystemTime = (LPSYSTEMTIME)Dll_Alloc(sizeof(LPSYSTEMTIME)); + memset(lpSystemTimeAsFileTime, 0, sizeof(lpSystemTimeAsFileTime)); + __sys_GetSystemTimePreciseAsFileTime(lpSystemTimeAsFileTime); + if (FileTimeToSystemTime(lpSystemTimeAsFileTime, lpSystemTime)) { + if (SbieApi_QueryConfBool(NULL, L"TimeOffsetPlus", TRUE)) { + lpSystemTime->wYear += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond += (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + + } + else { + lpSystemTime->wYear -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetYear", 0); + lpSystemTime->wDay -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetDay", 0); + lpSystemTime->wHour -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetHour", 0); + lpSystemTime->wMonth -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMonth", 0); + lpSystemTime->wMinute -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetMinute", 0); + lpSystemTime->wSecond -= (WORD)SbieApi_QueryConfNumber(NULL, "TimeOffsetSecond", 0); + } + SystemTimeToFileTime(lpSystemTime, lpSystemTimeAsFileTime); + Dll_Free(lpSystemTime); + } +}