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.

285 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. HighVersionLie.cpp
  5. Abstract:
  6. This DLL hooks GetVersion and GetVersionEx so that they return a future OS
  7. version credentials.
  8. Notes:
  9. This is a general purpose shim.
  10. History:
  11. 02/08/2001 clupu Created
  12. 09/21/2001 rparsons Added VLOG on hooks per billshih.
  13. 10/17/2001 rparsons Fixed bugs in GetVersionExW and GetVersion.
  14. 11/27/2001 rparsons Modified the VLOGs so they display what we
  15. used for the API call.
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(HighVersionLie)
  19. #include "ShimHookMacro.h"
  20. BEGIN_DEFINE_VERIFIER_LOG(HighVersionLie)
  21. VERIFIER_LOG_ENTRY(VLOG_HIGHVERSION_GETVERSION)
  22. VERIFIER_LOG_ENTRY(VLOG_HIGHVERSION_GETVERSIONEX)
  23. END_DEFINE_VERIFIER_LOG(HighVersionLie)
  24. INIT_VERIFIER_LOG(HighVersionLie);
  25. APIHOOK_ENUM_BEGIN
  26. APIHOOK_ENUM_ENTRY(GetVersionExA)
  27. APIHOOK_ENUM_ENTRY(GetVersionExW)
  28. APIHOOK_ENUM_ENTRY(GetVersion)
  29. APIHOOK_ENUM_END
  30. DWORD g_dwMajorVersion;
  31. DWORD g_dwMinorVersion;
  32. DWORD g_dwBuildNumber;
  33. BOOL
  34. APIHOOK(GetVersionExA)(
  35. OUT LPOSVERSIONINFOA lpVersionInformation
  36. )
  37. {
  38. BOOL bReturn = FALSE;
  39. if (ORIGINAL_API(GetVersionExA)(lpVersionInformation)) {
  40. LOGN(eDbgLevelInfo,
  41. "[GetVersionExA] called. Returning %lu.%lu build %lu",
  42. g_dwMajorVersion,
  43. g_dwMinorVersion,
  44. g_dwBuildNumber);
  45. VLOG(VLOG_LEVEL_INFO,
  46. VLOG_HIGHVERSION_GETVERSIONEX,
  47. "Returned %lu.%lu build number %lu.",
  48. g_dwMajorVersion,
  49. g_dwMinorVersion,
  50. g_dwBuildNumber);
  51. lpVersionInformation->dwMajorVersion = g_dwMajorVersion;
  52. lpVersionInformation->dwMinorVersion = g_dwMinorVersion;
  53. lpVersionInformation->dwBuildNumber = g_dwBuildNumber;
  54. lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
  55. *lpVersionInformation->szCSDVersion = '\0';
  56. bReturn = TRUE;
  57. }
  58. return bReturn;
  59. }
  60. BOOL
  61. APIHOOK(GetVersionExW)(
  62. OUT LPOSVERSIONINFOW lpVersionInformation
  63. )
  64. {
  65. BOOL bReturn = FALSE;
  66. if (ORIGINAL_API(GetVersionExW)(lpVersionInformation)) {
  67. LOGN(eDbgLevelInfo,
  68. "[GetVersionExW] called. Returning %lu.%lu build %lu",
  69. g_dwMajorVersion,
  70. g_dwMinorVersion,
  71. g_dwBuildNumber);
  72. VLOG(VLOG_LEVEL_INFO,
  73. VLOG_HIGHVERSION_GETVERSIONEX,
  74. "Returned %lu.%lu build number %lu.",
  75. g_dwMajorVersion,
  76. g_dwMinorVersion,
  77. g_dwBuildNumber);
  78. lpVersionInformation->dwMajorVersion = g_dwMajorVersion;
  79. lpVersionInformation->dwMinorVersion = g_dwMinorVersion;
  80. lpVersionInformation->dwBuildNumber = g_dwBuildNumber;
  81. lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
  82. *lpVersionInformation->szCSDVersion = L'\0';
  83. bReturn = TRUE;
  84. }
  85. return bReturn;
  86. }
  87. DWORD
  88. APIHOOK(GetVersion)(
  89. void
  90. )
  91. {
  92. LOGN(eDbgLevelInfo,
  93. "[GetVersion] called. Returning %lu.%lu build %lu",
  94. g_dwMajorVersion,
  95. g_dwMinorVersion,
  96. g_dwBuildNumber);
  97. VLOG(VLOG_LEVEL_INFO,
  98. VLOG_HIGHVERSION_GETVERSION,
  99. "Returned %lu.%lu build number %lu.",
  100. g_dwMajorVersion,
  101. g_dwMinorVersion,
  102. g_dwBuildNumber);
  103. return (((VER_PLATFORM_WIN32_NT ^ 0x2) << 30) |
  104. (g_dwBuildNumber << 16) |
  105. (g_dwMinorVersion << 8) |
  106. g_dwMajorVersion);
  107. }
  108. LRESULT CALLBACK
  109. DlgOptions(
  110. HWND hDlg,
  111. UINT message,
  112. WPARAM wParam,
  113. LPARAM lParam
  114. )
  115. {
  116. static LPCWSTR szExeName;
  117. switch (message) {
  118. case WM_INITDIALOG:
  119. {
  120. WCHAR szTemp[20];
  121. //
  122. // Limit the number of characters for each edit control.
  123. //
  124. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_MAJOR_VERSION, EM_LIMITTEXT, (WPARAM)5, 0);
  125. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_MINOR_VERSION, EM_LIMITTEXT, (WPARAM)5, 0);
  126. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_BUILD_NUMBER, EM_LIMITTEXT, (WPARAM)5, 0);
  127. //
  128. // find out what exe we're handling settings for
  129. //
  130. szExeName = ExeNameFromLParam(lParam);
  131. g_dwMajorVersion = GetShimSettingDWORD(L"HighVersionLie", szExeName, L"MajorVersion", 7);
  132. g_dwMinorVersion = GetShimSettingDWORD(L"HighVersionLie", szExeName, L"MinorVersion", 2);
  133. g_dwBuildNumber = GetShimSettingDWORD(L"HighVersionLie", szExeName, L"BuildNumber", 3595);
  134. swprintf(szTemp, L"%d", g_dwMajorVersion);
  135. SetDlgItemText(hDlg, IDC_HVL_EDIT_MAJOR_VERSION, szTemp);
  136. swprintf(szTemp, L"%d", g_dwMinorVersion);
  137. SetDlgItemText(hDlg, IDC_HVL_EDIT_MINOR_VERSION, szTemp);
  138. swprintf(szTemp, L"%d", g_dwBuildNumber);
  139. SetDlgItemText(hDlg, IDC_HVL_EDIT_BUILD_NUMBER, szTemp);
  140. return TRUE;
  141. }
  142. break;
  143. case WM_COMMAND:
  144. switch (LOWORD(wParam)) {
  145. case IDC_HVL_BTN_DEFAULT:
  146. {
  147. WCHAR szTemp[20];
  148. g_dwMajorVersion = 7;
  149. g_dwMinorVersion = 2;
  150. g_dwBuildNumber = 3595;
  151. //
  152. // Limit the number of characters for each edit control.
  153. //
  154. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_MAJOR_VERSION, EM_LIMITTEXT, (WPARAM)5, 0);
  155. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_MINOR_VERSION, EM_LIMITTEXT, (WPARAM)5, 0);
  156. SendDlgItemMessage(hDlg, IDC_HVL_EDIT_BUILD_NUMBER, EM_LIMITTEXT, (WPARAM)5, 0);
  157. swprintf(szTemp, L"%d", g_dwMajorVersion);
  158. SetDlgItemText(hDlg, IDC_HVL_EDIT_MAJOR_VERSION, szTemp);
  159. swprintf(szTemp, L"%d", g_dwMinorVersion);
  160. SetDlgItemText(hDlg, IDC_HVL_EDIT_MINOR_VERSION, szTemp);
  161. swprintf(szTemp, L"%d", g_dwBuildNumber);
  162. SetDlgItemText(hDlg, IDC_HVL_EDIT_BUILD_NUMBER, szTemp);
  163. break;
  164. }
  165. }
  166. break;
  167. case WM_NOTIFY:
  168. switch (((NMHDR FAR *) lParam)->code) {
  169. case PSN_APPLY:
  170. g_dwMajorVersion = GetDlgItemInt(hDlg, IDC_HVL_EDIT_MAJOR_VERSION, NULL, FALSE);
  171. g_dwMinorVersion = GetDlgItemInt(hDlg, IDC_HVL_EDIT_MINOR_VERSION, NULL, FALSE);
  172. g_dwBuildNumber = GetDlgItemInt(hDlg, IDC_HVL_EDIT_BUILD_NUMBER, NULL, FALSE);
  173. SaveShimSettingDWORD(L"HighVersionLie", szExeName, L"MajorVersion", g_dwMajorVersion);
  174. SaveShimSettingDWORD(L"HighVersionLie", szExeName, L"MinorVersion", g_dwMinorVersion);
  175. SaveShimSettingDWORD(L"HighVersionLie", szExeName, L"BuildNumber", g_dwBuildNumber);
  176. break;
  177. }
  178. break;
  179. }
  180. return FALSE;
  181. }
  182. SHIM_INFO_BEGIN()
  183. SHIM_INFO_DESCRIPTION(AVS_HIGHVERSIONLIE_DESC)
  184. SHIM_INFO_FRIENDLY_NAME(AVS_HIGHVERSIONLIE_FRIENDLY)
  185. SHIM_INFO_VERSION(1, 2)
  186. SHIM_INFO_INCLUDE_EXCLUDE("E:msvcrt.dll msvcirt.dll oleaut32.dll")
  187. SHIM_INFO_OPTIONS_PAGE(IDD_HIGHVERSION_OPTIONS, DlgOptions)
  188. SHIM_INFO_END()
  189. /*++
  190. Register hooked functions
  191. --*/
  192. HOOK_BEGIN
  193. if (fdwReason == DLL_PROCESS_ATTACH) {
  194. //
  195. // get the settings
  196. //
  197. WCHAR szExe[100];
  198. GetCurrentExeName(szExe, 100);
  199. g_dwMajorVersion = GetShimSettingDWORD(L"HighVersionLie", szExe, L"MajorVersion", 7);
  200. g_dwMinorVersion = GetShimSettingDWORD(L"HighVersionLie", szExe, L"MinorVersion", 2);
  201. g_dwBuildNumber = GetShimSettingDWORD(L"HighVersionLie", szExe, L"BuildNumber", 3595);
  202. DUMP_VERIFIER_LOG_ENTRY(VLOG_HIGHVERSION_GETVERSION,
  203. AVS_HIGHVERSION_GETVERSION,
  204. AVS_HIGHVERSION_GETVERSION_R,
  205. AVS_HIGHVERSION_GETVERSION_URL)
  206. DUMP_VERIFIER_LOG_ENTRY(VLOG_HIGHVERSION_GETVERSIONEX,
  207. AVS_HIGHVERSION_GETVERSIONEX,
  208. AVS_HIGHVERSION_GETVERSIONEX_R,
  209. AVS_HIGHVERSION_GETVERSIONEX_URL)
  210. }
  211. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExA)
  212. APIHOOK_ENTRY(KERNEL32.DLL, GetVersionExW)
  213. APIHOOK_ENTRY(KERNEL32.DLL, GetVersion)
  214. HOOK_END
  215. IMPLEMENT_SHIM_END