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.

171 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Win95VersionLie.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(Win95VersionLie)
  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. // Used for layer to turn on SafeDisc checking
  25. BOOL g_bCheckSafeDisc = FALSE;
  26. /*++
  27. This stub function fixes up the OSVERSIONINFO structure that is
  28. returned to the caller with Windows 95 credentials.
  29. --*/
  30. BOOL
  31. APIHOOK(GetVersionExA)(
  32. OUT LPOSVERSIONINFOA lpVersionInformation
  33. )
  34. {
  35. if (g_bCheckSafeDisc && bIsSafeDisc2()) {
  36. return ORIGINAL_API(GetVersionExA)(lpVersionInformation);
  37. } else {
  38. BOOL bReturn = FALSE;
  39. if (ORIGINAL_API(GetVersionExA)(lpVersionInformation)) {
  40. LOGN(eDbgLevelInfo, "[GetVersionExA] Return Win95");
  41. //
  42. // Fixup the structure with the Win95 data.
  43. //
  44. lpVersionInformation->dwMajorVersion = 4;
  45. lpVersionInformation->dwMinorVersion = 0;
  46. lpVersionInformation->dwBuildNumber = 950;
  47. lpVersionInformation->dwPlatformId = 1;
  48. *lpVersionInformation->szCSDVersion = '\0';
  49. bReturn = TRUE;
  50. }
  51. return bReturn;
  52. }
  53. }
  54. /*++
  55. This stub function fixes up the OSVERSIONINFO structure that is
  56. returned to the caller with Windows 95 credentials.
  57. --*/
  58. BOOL
  59. APIHOOK(GetVersionExW)(
  60. OUT LPOSVERSIONINFOW lpVersionInformation
  61. )
  62. {
  63. if (g_bCheckSafeDisc && bIsSafeDisc2()) {
  64. return ORIGINAL_API(GetVersionExW)(lpVersionInformation);
  65. } else {
  66. BOOL bReturn = FALSE;
  67. if (ORIGINAL_API(GetVersionExW)(lpVersionInformation)) {
  68. LOGN(eDbgLevelInfo, "[GetVersionExW] Return Win95");
  69. //
  70. // Fixup the structure with the Win95 data.
  71. //
  72. lpVersionInformation->dwMajorVersion = 4;
  73. lpVersionInformation->dwMinorVersion = 0;
  74. lpVersionInformation->dwBuildNumber = 950;
  75. lpVersionInformation->dwPlatformId = 1;
  76. *lpVersionInformation->szCSDVersion = L'\0';
  77. bReturn = TRUE;
  78. }
  79. return bReturn;
  80. }
  81. }
  82. /*++
  83. This stub function returns Windows 95 credentials.
  84. --*/
  85. DWORD
  86. APIHOOK(GetVersion)(
  87. void
  88. )
  89. {
  90. if (g_bCheckSafeDisc && bIsSafeDisc2()) {
  91. return ORIGINAL_API(GetVersion)();
  92. } else {
  93. LOGN(eDbgLevelInfo, "[GetVersion] Return Win95");
  94. return (DWORD)0xC3B60004;
  95. }
  96. }
  97. /*++
  98. Register hooked functions
  99. --*/
  100. BOOL
  101. NOTIFY_FUNCTION(
  102. DWORD fdwReason
  103. )
  104. {
  105. if (fdwReason == DLL_PROCESS_ATTACH)
  106. {
  107. g_bCheckSafeDisc = COMMAND_LINE && (_stricmp(COMMAND_LINE, "Detect_SafeDisc") == 0);
  108. if (g_bCheckSafeDisc && bIsSafeDisc1())
  109. {
  110. LOGN(eDbgLevelWarning, "SafeDisc 1.x detected: ignoring shim");
  111. return FALSE;
  112. }
  113. }
  114. return TRUE;
  115. }
  116. HOOK_BEGIN
  117. CALL_NOTIFY_FUNCTION
  118. APIHOOK_ENTRY(KERNEL32.DLL, GetVersion)
  119. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExA)
  120. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExW)
  121. HOOK_END
  122. IMPLEMENT_SHIM_END