Leaked source code of windows server 2003
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.

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