r/Windhawk • • 1d ago

Environment Variable Spoofer 1.0

Environment Variable Spoofer 1.0

Environment Variable Spoofer

Makes selected processes see fake values for environment variables such as TEMP and TMP. The system and other processes are not affected.

By default, the mod only intercepts the Win32 APIs that read environment variables, and the real environment block of the process is left untouched.

Choosing the target program

The mod targets nothing by default, so it does nothing until you tell it which process to apply to. Open the mod in Windhawk, go to the Advanced tab, and put the executable name of your target in the Custom process inclusion list. The mod takes effect as soon as you save.

Settings

SettingDefaultDescription
Spoofed variablesTEMP=C:FakeTemp, TMP=C:FakeTempThe environment variables to spoof, one NAME=VALUE entry per item. Names are case-insensitive.
Also write into the process environment blockoffAlso write the values into the process environment block, so that CRT getenv, GetEnvironmentStrings and child processes see them too. The original values are restored when the mod is unloaded.

Intercepted APIs

  • GetEnvironmentVariableW/A
  • ExpandEnvironmentStringsW/A, i.e. the expansion of %TEMP% and similar
  • GetTempPathW/A and GetTempPath2W/A, which look at TMP, TEMP and USERPROFILE in that order

GetTempPath keeps the lookup order of the system: if the process has a real TMP and only TEMP is spoofed, the real TMP still wins. Spoof both.

Notes

Changing the settings reloads the mod automatically.

With the environment block option turned off, programs that cache a copy of the environment at startup (CRT getenv / _wgetenv, Python os.environ) and child processes created by the target process still see the real values. Turn the option on to cover these cases.

With the option turned on, the mod must be injected before the target program caches its environment. A cache made earlier cannot be changed.

Programs that parse the environment block in the PEB directly, or call ntdll!RtlQueryEnvironmentVariable* themselves, are not affected by the API hooks. The environment block option covers them.

Implementation notes

The mod hooks the exports in kernelbase.dll, falling back to kernel32.dll. GetTempPath2W/A do not exist on older systems and are skipped there.

ExpandEnvironmentStrings is only taken over when the source string contains at least one spoofed variable. Everything else goes to the original function, so without a spoofed variable in the string the behavior is unchanged.

The environment block option writes the values with SetEnvironmentVariableW before the hooks are installed, so the original values can be read back and restored when the mod is unloaded.

1 Upvotes

0 comments sorted by