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.

233 lines
5.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. DXFileVersionInfo.cpp
  5. Abstract:
  6. This AppVerifier shim hooks GetFileVersionInfo and
  7. checks to see if the application is checking version
  8. information for any known DirectX files.
  9. See the FileVersionInfoLie shim for details on the problem.
  10. Notes:
  11. This is a general purpose shim.
  12. History:
  13. 06/26/2001 rparsons Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(DXFileVersionInfo)
  17. #include "ShimHookMacro.h"
  18. //
  19. // verifier log entries
  20. //
  21. BEGIN_DEFINE_VERIFIER_LOG(DXFileVersionInfo)
  22. VERIFIER_LOG_ENTRY(VLOG_DXFILEVERSIONINFO_DXFILE)
  23. END_DEFINE_VERIFIER_LOG(DXFileVersionInfo)
  24. INIT_VERIFIER_LOG(DXFileVersionInfo);
  25. APIHOOK_ENUM_BEGIN
  26. APIHOOK_ENUM_ENTRY(GetFileVersionInfoA)
  27. APIHOOK_ENUM_ENTRY(GetFileVersionInfoW)
  28. APIHOOK_ENUM_END
  29. // Keep a list of files to track.
  30. typedef struct FILELIST {
  31. struct FILELIST* pNext;
  32. CString csFileName;
  33. } FILELIST, *PFILELIST;
  34. PFILELIST g_pFileListHead = NULL;
  35. const int g_nNumDirectX7a = 68;
  36. WCHAR *g_szDirectX7aFiles[g_nNumDirectX7a] =
  37. { L"dplay.dll", L"d3dim.dll", L"d3dim700.dll",
  38. L"d3dpmesh.dll", L"d3dramp.dll", L"d3drampf.dll",
  39. L"d3dref.dll", L"d3drg16f.dll", L"d3drg24f.dll",
  40. L"d3drg24x.dll", L"d3dhalf.dll", L"d3drg32f.dll",
  41. L"d3drg32x.dll", L"d3drg55x.dll", L"d3drg56x.dll",
  42. L"d3drg8f.dll", L"d3drg8x.dll", L"d3drgbf.dll",
  43. L"d3drgbxf.dll", L"d3drm.dll", L"d3drm16f.dll",
  44. L"d3drm24f.dll", L"d3drm32f.dll", L"d3drm8f.dll",
  45. L"d3dxof.dll", L"ddhelp.exe", L"ddraw.dll",
  46. L"ddraw16.dll", L"ddrawex.dll", L"devnode1.dll",
  47. L"devnode2.dll", L"dinput.dll", L"dmband.dll",
  48. L"dmcompos.dll", L"dmime.dll", L"dmloader.dll",
  49. L"dmstyle.dll", L"dmsynth.dll", L"dmusic.dll",
  50. L"dmusic16.dll", L"dmusic32.dll", L"dplayx.dll",
  51. L"dpmodemx.dll", L"dpserial.dll", L"dpwsock.dll",
  52. L"dpwsockx.dll", L"dsetup.dll", L"dsetup16.dll",
  53. L"dsetup32.dll", L"dsetup6e.dll", L"dsetup6j.dll",
  54. L"dsetupe.dll", L"dsetupj.dll", L"dsound.dll",
  55. L"dsound3d.dll", L"dx7vb.dll", L"dxmigr.dll",
  56. L"gcdef.dll", L"gchand.dll", L"msvcrt.dll",
  57. L"pid.dll", L"vjoyd.vxd", L"dinput.vxd",
  58. L"dsound.vxd", L"joyhid.vxd", L"mtrr.vxd",
  59. L"ddraw.vxd", L"d3d8.dll"
  60. };
  61. void
  62. CheckDirectXFile(
  63. IN CString& csFileName
  64. )
  65. {
  66. CSTRING_TRY {
  67. PFILELIST pFileList = g_pFileListHead;
  68. CString csFilePart;
  69. csFileName.GetLastPathComponent(csFilePart);
  70. //
  71. // Walk the list and perform a comparison. Report wrong-doers.
  72. //
  73. while (pFileList) {
  74. if (csFilePart.CompareNoCase(pFileList->csFileName) == 0) {
  75. VLOG(VLOG_LEVEL_ERROR, VLOG_DXFILEVERSIONINFO_DXFILE, "GetFileVersionInfo called for %ls", csFileName.Get());
  76. break;
  77. }
  78. pFileList = pFileList->pNext;
  79. }
  80. }
  81. CSTRING_CATCH {
  82. // Do nothing
  83. }
  84. }
  85. BOOL
  86. APIHOOK(GetFileVersionInfoA)(
  87. LPSTR lpstrFilename,
  88. DWORD dwHandle,
  89. DWORD dwLen,
  90. LPVOID lpData
  91. )
  92. {
  93. CString csFileName(lpstrFilename);
  94. //
  95. // See if they're requesting information on a known DX file.
  96. //
  97. CheckDirectXFile(csFileName);
  98. return ORIGINAL_API(GetFileVersionInfoA)(
  99. lpstrFilename,
  100. dwHandle,
  101. dwLen,
  102. lpData);
  103. }
  104. BOOL
  105. APIHOOK(GetFileVersionInfoW)(
  106. LPWSTR lpstrFilename,
  107. DWORD dwHandle,
  108. DWORD dwLen,
  109. LPVOID lpData
  110. )
  111. {
  112. CString csFileName(lpstrFilename);
  113. //
  114. // See if they're requesting information on a known DX file.
  115. //
  116. CheckDirectXFile(csFileName);
  117. return ORIGINAL_API(GetFileVersionInfoW)(
  118. lpstrFilename,
  119. dwHandle,
  120. dwLen,
  121. lpData);
  122. }
  123. /*++
  124. Build the linked list of files to look for.
  125. --*/
  126. BOOL
  127. BuildFileList(
  128. void
  129. )
  130. {
  131. int nCount;
  132. FILELIST* pFileList = NULL;
  133. for (nCount = 0; nCount < g_nNumDirectX7a; nCount++) {
  134. //
  135. // Allocate a new node, then assign the file name
  136. // from our global array.
  137. //
  138. pFileList = new FILELIST;
  139. if (!pFileList) {
  140. LOGN(eDbgLevelError, "[BuildFileList] Failed to allocate memory");
  141. return FALSE;
  142. }
  143. pFileList->csFileName = g_szDirectX7aFiles[nCount];
  144. pFileList->pNext = g_pFileListHead;
  145. g_pFileListHead = pFileList;
  146. }
  147. return TRUE;
  148. }
  149. SHIM_INFO_BEGIN()
  150. SHIM_INFO_DESCRIPTION(AVS_DXFILEVERINFO_DESC)
  151. SHIM_INFO_FRIENDLY_NAME(AVS_DXFILEVERINFO_FRIENDLY)
  152. SHIM_INFO_VERSION(1, 2)
  153. SHIM_INFO_FLAGS(AVRF_FLAG_EXTERNAL_ONLY)
  154. SHIM_INFO_END()
  155. /*++
  156. Register hooked functions
  157. --*/
  158. BOOL
  159. NOTIFY_FUNCTION(
  160. DWORD fdwReason
  161. )
  162. {
  163. if (fdwReason == DLL_PROCESS_ATTACH) {
  164. return BuildFileList();
  165. }
  166. return TRUE;
  167. }
  168. HOOK_BEGIN
  169. CALL_NOTIFY_FUNCTION
  170. DUMP_VERIFIER_LOG_ENTRY(VLOG_DXFILEVERSIONINFO_DXFILE,
  171. AVS_DXFILEVERINFO_DXFILE,
  172. AVS_DXFILEVERINFO_DXFILE_R,
  173. AVS_DXFILEVERINFO_DXFILE_URL)
  174. APIHOOK_ENTRY(VERSION.DLL, GetFileVersionInfoA)
  175. APIHOOK_ENTRY(VERSION.DLL, GetFileVersionInfoW)
  176. HOOK_END
  177. IMPLEMENT_SHIM_END