diff --git a/puppy/Dockerfile b/puppy/Dockerfile index a973673..300c1d9 100644 --- a/puppy/Dockerfile +++ b/puppy/Dockerfile @@ -16,7 +16,6 @@ COPY include include COPY src src COPY CMakeLists.txt . - RUN --mount=type=cache,target=cmake-build cmake -B cmake-build \ -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ && cmake --build cmake-build -j$(nproc) && \ cp cmake-build/promt-puppy.exe .; diff --git a/puppy/app/main.cpp b/puppy/app/main.cpp index f1874a6..13a52b2 100644 --- a/puppy/app/main.cpp +++ b/puppy/app/main.cpp @@ -1,15 +1,57 @@ #include "http/httplib.h" #include +#include +#include #include #include #include #include #include +#include +#include #include "PromtCtlDocument.hpp" #include "PromtFTManager.hpp" +#define EPOCH_DIFF 116444736000000000LL +#define TICKS_PER_SEC 10000000LL + +static LARGE_INTEGER fake_time; + +static NTSTATUS WINAPI HookedNtQuerySystemTime(PLARGE_INTEGER time) +{ + if (time) + time->QuadPart = fake_time.QuadPart; + + fake_time.QuadPart += TICKS_PER_SEC; + return 0; +} + +static void InstallTimeHook() +{ + HMODULE ntdll = GetModuleHandleA("ntdll.dll"); + if (!ntdll) + return; + + auto target = (BYTE *)GetProcAddress(ntdll, "NtQuerySystemTime"); + if (!target) + return; + + DWORD old; + VirtualProtect(target, 5, PAGE_EXECUTE_READWRITE, &old); + + intptr_t rel = (BYTE *)HookedNtQuerySystemTime - target - 5; + target[0] = 0xE9; // jmp rel32 + *(int32_t *)(target + 1) = (int32_t)rel; + + VirtualProtect(target, 5, old, &old); + + const char *env = std::getenv("FAKETIME"); + long long unix_ts = env ? std::strtoll(env, nullptr, 10) : 0; + fake_time.QuadPart = unix_ts * TICKS_PER_SEC + EPOCH_DIFF; +} + static inline std::string random_filename(int len = 65) { static const char ASCII_PRINTABLE[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static std::random_device random_device; @@ -189,6 +231,8 @@ void signal_handler(int signal) { } int main() { + InstallTimeHook(); + CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeSecurity(nullptr, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, nullptr, EOAC_NONE, nullptr); diff --git a/puppy/docker-entrypoint.sh b/puppy/docker-entrypoint.sh index 5209beb..82cd9b6 100755 --- a/puppy/docker-entrypoint.sh +++ b/puppy/docker-entrypoint.sh @@ -1,8 +1,12 @@ #!/bin/bash +# shellcheck disable=SC2155 echo 'initializing wine...' wineboot -i + echo 'copying registy values...' -wine regedit $WINEPREFIX/drive_c/registry.reg -echo 'starting...' +wine regedit "$WINEPREFIX"/drive_c/registry.reg + +export FAKETIME="$(cat "$WINEPREFIX"/drive_c/build-date)" +echo "starting with date $(date -d @"$FAKETIME")..." exec wine /app/promt-puppy.exe diff --git a/puppy/scripts/prepare_envirionment.sh b/puppy/scripts/prepare_envirionment.sh index 64bc9a3..df8a9a3 100755 --- a/puppy/scripts/prepare_envirionment.sh +++ b/puppy/scripts/prepare_envirionment.sh @@ -21,3 +21,5 @@ winetricks_init winetricks_vcrun6_helper w_try_cabextract "${W_CACHE}"/vcrun6/vcredist.exe -d "$SCRIPT_DIR/build/windows/" -F "mfc42*.dll" mkdir -p "$SCRIPT_DIR/build/windows/system32" + +date +'%s' > "$SCRIPT_DIR/build/build-date"