Skip to content

Instantly share code, notes, and snippets.

@rmi1974
Last active February 2, 2025 02:12
Show Gist options
  • Save rmi1974/51244c06dbe1a84e052c09c5e142358a to your computer and use it in GitHub Desktop.
Save rmi1974/51244c06dbe1a84e052c09c5e142358a to your computer and use it in GitHub Desktop.
Using libfaketime to manipulate the system time for applications #faketime #wine #debug #commandlinefu

Using libfaketime to manipulate the system time for applications

See libfaketime on github for upstream project site general overview.

Build in multilib environment

#!/usr/bin/env bash

set -Eeuo pipefail

LIBFAKETIME_SOURCE_PATH=$PWD/libfaketime
LIBFAKETIME_INSTALL32_PREFIX=$PWD/install-x86
LIBFAKETIME_INSTALL64_PREFIX=$PWD/install-x86_64

[[ -d $LIBFAKETIME_SOURCE_PATH ]] || git clone https://github.com/wolfcw/libfaketime.git
make -C $LIBFAKETIME_SOURCE_PATH PREFIX=$LIBFAKETIME_INSTALL64_PREFIX distclean install | tee build64.log
CFLAGS="-m32" LDFLAGS="-m32" make -C $LIBFAKETIME_SOURCE_PATH PREFIX=$LIBFAKETIME_INSTALL32_PREFIX distclean install | tee build32.log

# generate scripts for shell environment
echo "export LD_PRELOAD=$LIBFAKETIME_INSTALL32_PREFIX/lib/faketime/libfaketime.so.1" > libfaketime32.env
echo "export LD_PRELOAD=$LIBFAKETIME_INSTALL64_PREFIX/lib/faketime/libfaketime.so.1" > libfaketime64.env

Usage in Wine to fake system time for Windows applications

64-bit application in 64-bit WINEPREFIX:

$ date
Sat Oct 19 19:11:58 CEST 2019

$ (source libfaketime64.env ; FAKETIME="-1y" wine64 "c:/windows/system32/cmd.exe" /c date /t)
Current Date is 10/19/2018

32-bit application in 64-bit WINEPREFIX:

$ date
Sat Oct 19 19:11:58 CEST 2019

$ (source libfaketime32.env ; FAKETIME="-1y" wine "c:/windows/syswow64/cmd.exe" /c date /t)
Current Date is 10/19/2018

NOTE: Since Wine 7.2, libfaketime doesn't work anymore for 32-bit processes due to missing 64-bit time_t support. See my comment


Links

@rmi1974
Copy link
Author

rmi1974 commented Jan 24, 2025

Hi,

just to clear things up. You are referring to the new experimental WoW64 mode.
Wine has Wow64 implemented since like 15 years which required a multilib host with 32-bit and 64-bit dependencies.
With the new experimental WoW64 mode, the 32-bit native host (and build) dependencies are no longer needed.
The 32-bit executables run in a 64-bit process.

Since I always build Wine on my own (I can still build all Wine versions down to Wine 1.3.x on the same Fedora 41 machine), I have those experimental wow64 builds as well, along with the traditional Wow64 32/64-bit multilib.

The new WoW64 is the way and follows what Windows natively does.
Output from my "new" wow64 mode build, showing it works:

$ source libfaketime64.env

$ wine --version
wine-10.0-127-g1f23d893483

$ FAKETIME="-1y" wine "c:/windows/syswow64/cmd.exe" /c date /t
0174:err:environ:init_peb starting L"C:\\windows\\syswow64\\cmd.exe" in experimental wow64 mode
Current Date is 1/25/2024

Not sure when they are provided as alternative/default to distros as well from WineHQ (https://gitlab.winehq.org/wine/wine/-/wikis/Download).
There are several third-party projects which provide own "custom" builds of various Wine flavours, including experimental WoW64 mode enabled ones. Example:

https://github.com/Kron4ek/Wine-Builds

Note, I don't use it/nor can comment on it, just listed as example.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment