How I solved the year 2038 problem on Windows with Sandboxie

Hello, gentlemen. I kindly ask you to forgive me if I allowed myself to make any shortcomings; this is my first attempt at writing.

You've probably already heard about the Year 2000 problem, also known as Y2K.

For those who are not in the know, the year used to be often displayed like this:

printf("19%02d год",year);

Which in 2000 would say “19100”. The problem in 2038 is somewhat more serious.

On January 19, 2038, time will become negative due to a 32-bit number overflow, becoming a thing of the past. Because of this, many purchased programs will lose their license.

However, I was able to get around this through the Sandboxie parameter, InjectDll. The Sandboxie injector is remarkable because it patches all browser processes, unlike similar programs, and does not require launchers.

The following code works on both x86 and x64.

#include <windows.h>
#include <stdlib.h>
#include <string.h>
/*сдвиг изначально ставится в 0, чтобы измерить размер*/
ULONGLONG shift=0;
/*эта функция используется только для замера*/
ULONGLONG ft2i(LPFILETIME d){
    ULONGLONG t=d->dwHighDateTime;
    t<<=32;
    t+=(unsigned)d->dwLowDateTime;
    return t;
}
/*Не совместимо с XP без обновлений
и более ранними
Можно убрать суффикс 64 для совместимости,
но тогда через какое-то время будет глюк*/
ULONGLONG gett(){
    ULONGLONG t=GetTickCount64();
    return t*10000+shift;
}
/*MS обещали удалить эту функцию.
Патчим, только если она есть*/
int WINAPI fake_NtQuerySystemTime(
PLARGE_INTEGER t){
    t->QuadPart=gett();
    return 0;
}
/*работает так же, как и NtQuerySystemTime
я проверил*/
void WINAPI fake_GetSystemTimeAsFileTime(
LPFILETIME d){
    ULONGLONG t=gett();
    d->dwLowDateTime=(int)t;
    d->dwHighDateTime=t>>32;
}
void WINAPI fake_GetSystemTime(
LPSYSTEMTIME t){
    FILETIME ft;
    fake_GetSystemTimeAsFileTime(&ft);
    FileTimeToSystemTime(&ft,t);
}
void*ptr_NtQuerySystemTime=fake_NtQuerySystemTime;
void*ptr_GetSystemTimeAsFileTime=fake_GetSystemTimeAsFileTime;
void*ptr_GetSystemTime=fake_GetSystemTime;
void _hook(char*d,LONGLONG*f){
    DWORD old;
    VirtualProtect(d,14,PAGE_EXECUTE_READWRITE,&old);
    /*на всякий случай сначала ставим int3*/
    d[0]=0xcc;
#ifdef _WIN64
    *(int*)(d+2)=0;
    *(LONGLONG*)(d+6)=*f;
#else
    *(int*)(d+2)=(int)f;
#endif
    d[1]=0x25;
    d[0]=0xff;
    /*MS очень не любят принимать NULL*/
    VirtualProtect(d,14,old,&old);
}
#define hook(d,f) _hook((void*)(d),(void*)(&f))
void patch(char const*s){
    void*d;
    HMODULE m=LoadLibraryA(s);
    if(!m)return;
    d=GetProcAddress(m,"NtQuerySystemTime");
    if(d)hook(d,ptr_NtQuerySystemTime);
    d=GetProcAddress(m,"GetSystemTimeAsFileTime");
    if(d)hook(d,ptr_GetSystemTimeAsFileTime);
    d=GetProcAddress(m,"GetSystemTimePreciseAsFileTime");
    if(d)hook(d,ptr_GetSystemTimeAsFileTime);
    d=GetProcAddress(m,"GetSystemTime");
    if(d)hook(d,ptr_GetSystemTime);
    d=GetProcAddress(m,"GetLocalTime");
    if(d)hook(d,ptr_GetSystemTime);
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved){
    char*a;
    FILETIME t;
    switch(fdwReason){ 
    case DLL_PROCESS_ATTACH:
        GetSystemTimeAsFileTime(&t);
        shift=ft2i(&t)-gett();
        a=getenv("Y38ADJ");/*единица - 4 года,
        таким образом, високосный год не сдвигается
        секундой в 100 лет можно пока пренебречь*/
        if(a)shift+=(atoll(a)*10000000)*126230400;
        patch("kernel32.dll");
        patch("kernelbase.dll");
        patch("ntdll.dll");
        break;
    }
    return TRUE;
}

Only the latest version of Sandboxie still works with current browsers. I'll take the Catsxp browser as an example – it still works with Windows 7. Nothing below is any good, unfortunately.

I'll skip creating the sandbox itself, installing the browser…

In new versions of Windows, it is difficult to open the taskbar. The easiest way is to press Win-R and enter sysdm.cpl.

Advanced – Environment Variables. I create a system variable Y38ADJ with a value of 2.

This will move the time in patched programs forward 8 years. Now I will set the system time back 8 years.

Now the patch itself. In Sandboxie Options-Edit Sandboxie.ini.

I find the line [GlobalSettings].

I'm adding two more lines below indicating where I put the dll files. Now it looks like this:

[GlobalSettings]
InjectDll=c:\adjtim\adjtim32.dll
InjectDll64=c:\adjtim\adjtim64.dll

And Catsxp works, although the system thinks it's 2016. This allows time to be set back every 4 years while maintaining the functionality of the SSL protocol.

True, it does not work very well with DDOS protection. Still, Windows 7, 8 and 10 may live a little longer.

So how?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *