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.

200 lines
4.8 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. 02/13/2002 astritz Security Review
  15. --*/
  16. #include "precomp.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. long g_Count = 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. DWORD dwCount = InterlockedIncrement(&g_Count);
  39. if (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. if( lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) )
  54. {
  55. // We are here as we are passed a OSVERSIONINFOEX structure.
  56. // Set the major and minor service pack numbers.
  57. ((LPOSVERSIONINFOEXA)lpVersionInformation)->wServicePackMajor = 0;
  58. ((LPOSVERSIONINFOEXA)lpVersionInformation)->wServicePackMinor = 0;
  59. }
  60. bReturn = TRUE;
  61. }
  62. return bReturn;
  63. }
  64. }
  65. /*++
  66. This stub function fixes up the OSVERSIONINFO structure that is
  67. returned to the caller with Windows 95 credentials.
  68. --*/
  69. BOOL
  70. APIHOOK(GetVersionExW)(
  71. OUT LPOSVERSIONINFOW lpVersionInformation
  72. )
  73. {
  74. DWORD dwCount = InterlockedIncrement(&g_Count);
  75. if (dwCount < g_dwDelay) {
  76. return ORIGINAL_API(GetVersionExW)(lpVersionInformation);
  77. } else {
  78. BOOL bReturn = FALSE;
  79. if (ORIGINAL_API(GetVersionExW)(lpVersionInformation)) {
  80. LOGN(eDbgLevelInfo, "[GetVersionExW] Return Win95");
  81. //
  82. // Fixup the structure with the Win95 data.
  83. //
  84. lpVersionInformation->dwMajorVersion = 4;
  85. lpVersionInformation->dwMinorVersion = 0;
  86. lpVersionInformation->dwBuildNumber = 950;
  87. lpVersionInformation->dwPlatformId = 1;
  88. *lpVersionInformation->szCSDVersion = L'\0';
  89. if( lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) )
  90. {
  91. // We are here as we are passed a OSVERSIONINFOEX structure.
  92. // Set the major and minor service pack numbers.
  93. ((LPOSVERSIONINFOEXW)lpVersionInformation)->wServicePackMajor = 0;
  94. ((LPOSVERSIONINFOEXW)lpVersionInformation)->wServicePackMinor = 0;
  95. }
  96. bReturn = TRUE;
  97. }
  98. return bReturn;
  99. }
  100. }
  101. /*++
  102. This stub function returns Windows 95 credentials.
  103. --*/
  104. DWORD
  105. APIHOOK(GetVersion)()
  106. {
  107. DWORD dwCount = InterlockedIncrement(&g_Count);
  108. if (dwCount < g_dwDelay) {
  109. return ORIGINAL_API(GetVersion)();
  110. } else {
  111. LOGN(eDbgLevelInfo, "[GetVersion] Return Win95");
  112. return (DWORD)0xC3B60004;
  113. }
  114. }
  115. /*++
  116. Register hooked functions
  117. --*/
  118. BOOL
  119. NOTIFY_FUNCTION(
  120. DWORD fdwReason
  121. )
  122. {
  123. if (fdwReason == DLL_PROCESS_ATTACH)
  124. {
  125. CSTRING_TRY
  126. {
  127. CString csCl(COMMAND_LINE);
  128. if (!csCl.IsEmpty())
  129. {
  130. WCHAR * unused;
  131. g_dwDelay = wcstol(csCl, &unused, 10);
  132. }
  133. DPFN(eDbgLevelInfo, "Delaying version lie by %d", g_dwDelay);
  134. }
  135. CSTRING_CATCH
  136. {
  137. return FALSE;
  138. }
  139. }
  140. return TRUE;
  141. }
  142. HOOK_BEGIN
  143. CALL_NOTIFY_FUNCTION
  144. APIHOOK_ENTRY(KERNEL32.DLL, GetVersion)
  145. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExA)
  146. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExW)
  147. HOOK_END
  148. IMPLEMENT_SHIM_END