Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time set #4196

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 123 additions & 1 deletion Sandboxie/core/dll/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}