Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. DelayWin95VersionLie.cpp
  5. Abstract:
  6. This DLL hooks GetVersion and GetVersionEx so that they return Windows 95
  7. version credentials. Applications often check to ensure that they are
  8. running on a Win9x system, even though they will run OK on an NT based
  9. system.
  10. Notes:
  11. This is a general purpose shim.
  12. History:
  13. 11/10/1999 v-johnwh Created
  14. --*/
  15. #include "precomp.h"
  16. #include "LegalStr.h"
  17. IMPLEMENT_SHIM_BEGIN(DelayWin95VersionLie)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(GetVersion)
  21. APIHOOK_ENUM_ENTRY(GetVersionExA)
  22. APIHOOK_ENUM_ENTRY(GetVersionExW)
  23. APIHOOK_ENUM_END
  24. //
  25. // Used to delay version lying
  26. //
  27. DWORD g_dwCount = 0;
  28. DWORD g_dwDelay = 0;
  29. /*++
  30. This stub function fixes up the OSVERSIONINFO structure that is
  31. returned to the caller with Windows 95 credentials.
  32. --*/
  33. BOOL
  34. APIHOOK(GetVersionExA)(
  35. OUT LPOSVERSIONINFOA lpVersionInformation
  36. )
  37. {
  38. g_dwCount++;
  39. if (g_dwCount < g_dwDelay) {
  40. return ORIGINAL_API(GetVersionExA)(lpVersionInformation);
  41. } else {
  42. BOOL bReturn = FALSE;
  43. if (ORIGINAL_API(GetVersionExA)(lpVersionInformation)) {
  44. LOGN(eDbgLevelInfo, "[GetVersionExA] Return Win95");
  45. //
  46. // Fixup the structure with the Win95 data.
  47. //
  48. lpVersionInformation->dwMajorVersion = 4;
  49. lpVersionInformation->dwMinorVersion = 0;
  50. lpVersionInformation->dwBuildNumber = 950;
  51. lpVersionInformation->dwPlatformId = 1;
  52. *lpVersionInformation->szCSDVersion = '\0';
  53. bReturn = TRUE;
  54. }
  55. return bReturn;
  56. }
  57. }
  58. /*++
  59. This stub function fixes up the OSVERSIONINFO structure that is
  60. returned to the caller with Windows 95 credentials.
  61. --*/
  62. BOOL
  63. APIHOOK(GetVersionExW)(
  64. OUT LPOSVERSIONINFOW lpVersionInformation
  65. )
  66. {
  67. g_dwCount++;
  68. if (g_dwCount < g_dwDelay) {
  69. return ORIGINAL_API(GetVersionExW)(lpVersionInformation);
  70. } else {
  71. BOOL bReturn = FALSE;
  72. if (ORIGINAL_API(GetVersionExW)(lpVersionInformation)) {
  73. LOGN(eDbgLevelInfo, "[GetVersionExW] Return Win95");
  74. //
  75. // Fixup the structure with the Win95 data.
  76. //
  77. lpVersionInformation->dwMajorVersion = 4;
  78. lpVersionInformation->dwMinorVersion = 0;
  79. lpVersionInformation->dwBuildNumber = 950;
  80. lpVersionInformation->dwPlatformId = 1;
  81. *lpVersionInformation->szCSDVersion = L'\0';
  82. bReturn = TRUE;
  83. }
  84. return bReturn;
  85. }
  86. }
  87. /*++
  88. This stub function returns Windows 95 credentials.
  89. --*/
  90. DWORD
  91. APIHOOK(GetVersion)()
  92. {
  93. g_dwCount++;
  94. if (g_dwCount < g_dwDelay) {
  95. return ORIGINAL_API(GetVersion)();
  96. } else {
  97. LOGN(eDbgLevelInfo, "[GetVersion] Return Win95");
  98. return (DWORD)0xC3B60004;
  99. }
  100. }
  101. /*++
  102. Register hooked functions
  103. --*/
  104. BOOL
  105. NOTIFY_FUNCTION(
  106. DWORD fdwReason
  107. )
  108. {
  109. if (fdwReason == DLL_PROCESS_ATTACH)
  110. {
  111. CSTRING_TRY
  112. {
  113. CString csCl(COMMAND_LINE);
  114. if (!csCl.IsEmpty())
  115. {
  116. WCHAR * unused;
  117. g_dwDelay = wcstol(csCl, &unused, 10);
  118. }
  119. DPFN(eDbgLevelInfo, "Delaying version lie by %d", g_dwDelay);
  120. }
  121. CSTRING_CATCH
  122. {
  123. return FALSE;
  124. }
  125. }
  126. return TRUE;
  127. }
  128. HOOK_BEGIN
  129. CALL_NOTIFY_FUNCTION
  130. APIHOOK_ENTRY(KERNEL32.DLL, GetVersion)
  131. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExA)
  132. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExW)
  133. HOOK_END
  134. IMPLEMENT_SHIM_END