vxiiduu / VxKex

Windows 7 API Extensions
855 stars 47 forks source link

RRF_RT_REG_EXPAND_SZ bug in Windows 7 #243

Open NulAsh opened 1 month ago

NulAsh commented 1 month ago

When we are calling RegGetValue and flags have RRF_RT_REG_EXPAND_SZ bit set, and RRF_NOEXPAND bit not set, function returns ERROR_INVALID_PARAMETER. This is a bug in Windows 7, not described in documentation, and was fixed in Windows 8.1. Here's the result of decompilation of buggy function in C:\Windows\syswow64\kernel32.dll:

int __stdcall RestrictArguments(int a1, int a2, int a3, int a4)
{
  if ( a1 && (_WORD)a2 && ((unsigned __int16)a2 == 0xFFFF || (a2 & 4) == 0 || (a2 & 0x10000000) != 0) && (!a3 || a4) )
    return 0;
  else
    return 87;
}

Due to this bug, py.exe from Python 3.12 does not work in Windows 7. Because _registryReadString from PC/launcher2.c have this code:

    DWORD flags = RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ;

    if (ERROR_SUCCESS != RegGetValueW(root, subkey, value, flags, NULL, NULL, &cbData)) {
        return 0;
    }
vxiiduu commented 1 month ago

Is this what causes the "unicode codec" bug? Thanks for the investigation. I will keep it in mind.

NulAsh commented 1 month ago

It may be the reason why Python 3.12 can't find it's own directory without explicitly specifying it in environment variables. Also this may be the reason why pip is not installed.