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.

344 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FileVersionInfoLie.cpp
  5. Abstract:
  6. This shim replaces the info returned from calls to GetFileVersionInfoSize and
  7. GetFileVersionInfo with information stored in resource files. The default
  8. is to replace file info with stored info obtained from DirectX ver 7a.
  9. This can be overridden with command line input. For example:
  10. COMMAND_LINE("D3drgbxf.dll,IDR_D3DRGBXFINFO;dsound.vxd,IDR_DSOUNDVXDINFO")
  11. this would intercept the info calls for D3drgbxf.dll and dsounc.vxd and replace
  12. their info with the info stored in the resources named. Note: All spaces within
  13. the command line are considered part of the filename or resource name, only the
  14. commas and semicolons are delimeters.
  15. Notes:
  16. This is a general purpose shim.
  17. History:
  18. 01/03/2000 a-jamd Created
  19. 03/28/2000 a-jamd Added resource for ddraw16.dll
  20. 04/04/2000 a-michni Added resource for D3drgbxf.dll
  21. 04/07/2000 linstev Added resource for dsound.vxd
  22. 04/10/2000 markder Removed GetModuleHandle("_DDRAW6V") calls -- use g_hinstDll
  23. 04/18/2000 a-michni Modified DDraw6Versionlie to be command line input driven and
  24. renamed to FileVersionInfoLie
  25. 04/26/2000 a-batjar GetFileVersionInfo should return truncated result if passed
  26. in buffer size is smaller than infosize
  27. 07/19/2000 andyseti Added resource for shdocvw.bin
  28. 08/11/2000 a-brienw changed g_nNumDirectX6 to 7 and added entry for dsound.dll
  29. made it the same as dsound.vxd
  30. 08/15/2000 a-vales Added resource for dsound.dll
  31. 11/08/2000 a-brienw changed dsound.dll entry to return dsound.vxd version info.
  32. a-vales changed it from my previous entry which caused MAX2
  33. to no longer work. I changed it back and checked it with
  34. MAX2 and his app Golden Nugget and it is fine with both.
  35. 12/06/2000 mnikkel Added resources for all directx7a dlls and also for any
  36. dlls that existed in previous versions of directx but
  37. were deleted. NOTE: the resources for these files are
  38. in win98 format so that apps which directly read the version
  39. info will receive them in the way they are expecting.
  40. --*/
  41. #include "precomp.h"
  42. IMPLEMENT_SHIM_BEGIN(FileVersionInfoLie)
  43. #include "ShimHookMacro.h"
  44. APIHOOK_ENUM_BEGIN
  45. APIHOOK_ENUM_ENTRY(GetFileVersionInfoA)
  46. APIHOOK_ENUM_ENTRY(GetFileVersionInfoSizeA)
  47. APIHOOK_ENUM_END
  48. // Keep a list of files to version lie.
  49. struct LIELIST
  50. {
  51. struct LIELIST * next;
  52. CString szFileName;
  53. CString szResource;
  54. };
  55. LIELIST *g_pLieList = NULL;
  56. // DirectX 7a default files go here.
  57. const INT g_nNumDirectX7a = 67;
  58. WCHAR *g_szDirectX7aFiles[g_nNumDirectX7a] =
  59. { L"dplay.dll", L"d3dim.dll", L"d3dim700.dll",
  60. L"d3dpmesh.dll", L"d3dramp.dll", L"d3drampf.dll",
  61. L"d3dref.dll", L"d3drg16f.dll", L"d3drg24f.dll",
  62. L"d3drg24x.dll", L"d3dhalf.dll", L"d3drg32f.dll",
  63. L"d3drg32x.dll", L"d3drg55x.dll", L"d3drg56x.dll",
  64. L"d3drg8f.dll", L"d3drg8x.dll", L"d3drgbf.dll",
  65. L"d3drgbxf.dll", L"d3drm.dll", L"d3drm16f.dll",
  66. L"d3drm24f.dll", L"d3drm32f.dll", L"d3drm8f.dll",
  67. L"d3dxof.dll", L"ddhelp.exe", L"ddraw.dll",
  68. L"ddraw16.dll", L"ddrawex.dll", L"devnode1.dll",
  69. L"devnode2.dll", L"dinput.dll", L"dmband.dll",
  70. L"dmcompos.dll", L"dmime.dll", L"dmloader.dll",
  71. L"dmstyle.dll", L"dmsynth.dll", L"dmusic.dll",
  72. L"dmusic16.dll", L"dmusic32.dll", L"dplayx.dll",
  73. L"dpmodemx.dll", L"dpserial.dll", L"dpwsock.dll",
  74. L"dpwsockx.dll", L"dsetup.dll", L"dsetup16.dll",
  75. L"dsetup32.dll", L"dsetup6e.dll", L"dsetup6j.dll",
  76. L"dsetupe.dll", L"dsetupj.dll", L"dsound.dll",
  77. L"dsound3d.dll", L"dx7vb.dll", L"dxmigr.dll",
  78. L"gcdef.dll", L"gchand.dll", L"msvcrt.dll",
  79. L"pid.dll", L"vjoyd.vxd", L"dinput.vxd",
  80. L"dsound.vxd", L"joyhid.vxd", L"mtrr.vxd",
  81. L"ddraw.vxd"
  82. };
  83. // NOTE: These are 16 bit resources!!! This is necessary in case
  84. // they index into the data themselves. If they do a verqueryvalue
  85. // the data is converted before its returned by verqueryvalue.
  86. WCHAR * g_szDirectX7aResource[g_nNumDirectX7a] =
  87. { L"IDR_dplay", L"IDR_d3dim", L"IDR_d3dim700",
  88. L"IDR_d3dpmesh", L"IDR_d3dramp", L"IDR_d3drampf",
  89. L"IDR_d3dref", L"IDR_d3drg16f", L"IDR_d3drg24f",
  90. L"IDR_d3drg24x", L"IDR_d3dhalf", L"IDR_d3drg32f",
  91. L"IDR_d3drg32x", L"IDR_d3drg55x", L"IDR_d3drg56x",
  92. L"IDR_d3drg8f", L"IDR_d3drg8x", L"IDR_d3drgbf",
  93. L"IDR_d3drgbxf", L"IDR_d3drm", L"IDR_d3drm16f",
  94. L"IDR_d3drm24f", L"IDR_d3drm32f", L"IDR_d3drm8f",
  95. L"IDR_d3dxof", L"IDR_ddhelp", L"IDR_ddraw",
  96. L"IDR_ddraw16", L"IDR_ddrawex", L"IDR_devnode1",
  97. L"IDR_devnode2", L"IDR_dinput", L"IDR_dmband",
  98. L"IDR_dmcompos", L"IDR_dmime", L"IDR_dmloader",
  99. L"IDR_dmstyle", L"IDR_dmsynth", L"IDR_dmusic",
  100. L"IDR_dmusic16", L"IDR_dmusic32", L"IDR_dplayx",
  101. L"IDR_dpmodemx", L"IDR_dpserial", L"IDR_dpwsock",
  102. L"IDR_dpwsockx", L"IDR_dsetup", L"IDR_dsetup16",
  103. L"IDR_dsetup32", L"IDR_dsetup6e", L"IDR_dsetup6j",
  104. L"IDR_dsetupe", L"IDR_dsetupj", L"IDR_dsound",
  105. L"IDR_dsound3d", L"IDR_dx7vb", L"IDR_dxmigr",
  106. L"IDR_gcdef", L"IDR_gchand", L"IDR_msvcrt",
  107. L"IDR_pid", L"IDR_vjoydvxd", L"IDR_dinputvxd",
  108. L"IDR_dsoundvxd", L"IDR_joyhidvxd", L"IDR_mtrrvxd",
  109. L"IDR_ddrawvxd"
  110. };
  111. /*++
  112. return the size from the resource.
  113. --*/
  114. DWORD
  115. APIHOOK(GetFileVersionInfoSizeA)(
  116. LPSTR lpstrFilename,
  117. LPDWORD lpdwHandle
  118. )
  119. {
  120. DWORD dwRet = 0;
  121. CSTRING_TRY
  122. {
  123. HRSRC hrsrcManifest = NULL;
  124. LIELIST *pLiePtr = g_pLieList;
  125. DPFN( eDbgLevelSpew, "[GetFileVersionInfoSizeA] size requested for %s\n", lpstrFilename );
  126. CString csFileName(lpstrFilename);
  127. CString csFilePart;
  128. csFileName.GetLastPathComponent(csFilePart);
  129. // Search through the list of files with their matching IDR's
  130. while( pLiePtr )
  131. {
  132. if (csFilePart.CompareNoCase(pLiePtr->szFileName) == 0)
  133. {
  134. hrsrcManifest = FindResourceW( g_hinstDll, pLiePtr->szResource, L"FILES");
  135. break;
  136. }
  137. pLiePtr = pLiePtr->next;
  138. }
  139. // If a match was found, get the resource size
  140. if( hrsrcManifest )
  141. {
  142. dwRet = SizeofResource(g_hinstDll, hrsrcManifest);
  143. *lpdwHandle = NULL;
  144. }
  145. }
  146. CSTRING_CATCH
  147. {
  148. // Do nothing
  149. }
  150. if (dwRet == 0)
  151. {
  152. dwRet = ORIGINAL_API(GetFileVersionInfoSizeA)(lpstrFilename, lpdwHandle);
  153. }
  154. return dwRet;
  155. }
  156. /*++
  157. Return the version for the modules that shipped with Win98SE.
  158. --*/
  159. BOOL
  160. APIHOOK(GetFileVersionInfoA)(
  161. LPSTR lpstrFilename,
  162. DWORD dwHandle,
  163. DWORD dwLen,
  164. LPVOID lpData
  165. )
  166. {
  167. BOOL bRet = FALSE;
  168. CSTRING_TRY
  169. {
  170. HRSRC hrsrcManifest = NULL;
  171. LIELIST *pLiePtr = g_pLieList;
  172. DPFN( eDbgLevelSpew, "[GetFileVersionInfoA] info requested for %s\n", lpstrFilename );
  173. CString csFileName(lpstrFilename);
  174. CString csFilePart;
  175. csFileName.GetLastPathComponent(csFilePart);
  176. // Search through the list of files with their matching IDR's
  177. while( pLiePtr )
  178. {
  179. if (csFilePart.CompareNoCase(pLiePtr->szFileName) == 0)
  180. {
  181. hrsrcManifest = FindResourceW( g_hinstDll, pLiePtr->szResource, L"FILES");
  182. break;
  183. }
  184. pLiePtr = pLiePtr->next;
  185. }
  186. // If a match was found, get the resource size
  187. if( hrsrcManifest )
  188. {
  189. LOGN( eDbgLevelError, "[GetFileVersionInfoA] Getting legacy version for %s.", lpstrFilename);
  190. DWORD dwManifestSize = SizeofResource(g_hinstDll, hrsrcManifest);
  191. HGLOBAL hManifestMem = LoadResource (g_hinstDll, hrsrcManifest);
  192. PVOID lpManifestMem = LockResource (hManifestMem);
  193. memcpy(lpData, lpManifestMem, dwLen >= dwManifestSize ? dwManifestSize:dwLen );
  194. bRet = TRUE;
  195. }
  196. }
  197. CSTRING_CATCH
  198. {
  199. // Do nothing
  200. }
  201. if (!bRet)
  202. {
  203. bRet = ORIGINAL_API(GetFileVersionInfoA)(
  204. lpstrFilename,
  205. dwHandle,
  206. dwLen,
  207. lpData);
  208. }
  209. return bRet;
  210. }
  211. /*++
  212. Parse the command line inputs.
  213. --*/
  214. BOOL ParseCommandLine(const char * commandLine)
  215. {
  216. CSTRING_TRY
  217. {
  218. CString csCmdLine(commandLine);
  219. // if there are no command line inputs then default to
  220. // the DirectX 7a files needed.
  221. if (csCmdLine.IsEmpty())
  222. {
  223. DPFN( eDbgLevelSpew, "Defaulting to DirectX7a\n" );
  224. for(int i = 0; i < g_nNumDirectX7a; i++)
  225. {
  226. LIELIST * pLiePtr = new LIELIST;
  227. pLiePtr->szFileName = g_szDirectX7aFiles[i];
  228. pLiePtr->szResource = g_szDirectX7aResource[i];
  229. pLiePtr->next = g_pLieList;
  230. g_pLieList = pLiePtr;
  231. }
  232. }
  233. else
  234. {
  235. CStringToken csTokenList(csCmdLine, L";");
  236. CString csEntryTok;
  237. while (csTokenList.GetToken(csEntryTok))
  238. {
  239. CStringToken csEntry(csEntryTok, L",");
  240. CString csLeft;
  241. CString csRight;
  242. csEntry.GetToken(csLeft);
  243. csEntry.GetToken(csRight);
  244. if (!csLeft.IsEmpty() && !csRight.IsEmpty())
  245. {
  246. LIELIST * pLiePtr = new LIELIST;
  247. pLiePtr->szFileName = csLeft;
  248. pLiePtr->szResource = csRight;
  249. pLiePtr->next = g_pLieList;
  250. g_pLieList = pLiePtr;
  251. }
  252. }
  253. }
  254. }
  255. CSTRING_CATCH
  256. {
  257. return FALSE;
  258. }
  259. return TRUE;
  260. }
  261. /*++
  262. Register hooked functions
  263. --*/
  264. BOOL
  265. NOTIFY_FUNCTION(
  266. DWORD fdwReason
  267. )
  268. {
  269. if (fdwReason == DLL_PROCESS_ATTACH)
  270. {
  271. return ParseCommandLine(COMMAND_LINE);
  272. }
  273. return TRUE;
  274. }
  275. HOOK_BEGIN
  276. CALL_NOTIFY_FUNCTION
  277. APIHOOK_ENTRY(VERSION.DLL, GetFileVersionInfoA)
  278. APIHOOK_ENTRY(VERSION.DLL, GetFileVersionInfoSizeA)
  279. HOOK_END
  280. IMPLEMENT_SHIM_END