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.

108 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. TrimVersionInfo.cpp
  5. Abstract:
  6. This shim trims the blanks off of the end the version info string.
  7. Notes:
  8. This is a general shim.
  9. History:
  10. 08/01/2001 mnikkel, astritz Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(TrimVersionInfo)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(VerQueryValueA)
  17. APIHOOK_ENUM_END
  18. /*++
  19. Return the product version with blanks trimmed from end.
  20. --*/
  21. BOOL
  22. APIHOOK(VerQueryValueA)(
  23. const LPVOID pBlock,
  24. LPSTR lpSubBlock,
  25. LPVOID *lplpBuffer,
  26. PUINT puLen
  27. )
  28. {
  29. UINT nLen;
  30. BOOL bRet = ORIGINAL_API(VerQueryValueA)(
  31. pBlock,
  32. lpSubBlock,
  33. lplpBuffer,
  34. puLen);
  35. if (bRet)
  36. {
  37. CSTRING_TRY
  38. {
  39. CString csSubBlock(lpSubBlock);
  40. if (csSubBlock.Find(L"ProductVersion") != -1 ||
  41. csSubBlock.Find(L"FileVersion") != -1)
  42. {
  43. int nLoc = 0;
  44. DPFN(eDbgLevelError, "[VerQueryValueA] Asking for Product or File Version, trimming blanks");
  45. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info is <%s>", *lplpBuffer);
  46. CString csBuffer((char *)*lplpBuffer);
  47. //
  48. // Search for first blank
  49. //
  50. nLoc = csBuffer.Find(L" ");
  51. if (nLoc != -1)
  52. {
  53. // if a blank is found then truncate string to that point
  54. csBuffer.Truncate(nLoc);
  55. csBuffer.CopyAnsiChars((char *)*lplpBuffer, nLoc+1);
  56. if (puLen)
  57. {
  58. *puLen = nLoc;
  59. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info Length = %d.", *puLen);
  60. }
  61. }
  62. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info after trim is <%s>.", *lplpBuffer);
  63. }
  64. }
  65. CSTRING_CATCH
  66. {
  67. /* do nothing */
  68. }
  69. }
  70. return bRet;
  71. }
  72. /*++
  73. Register hooked functions
  74. --*/
  75. HOOK_BEGIN
  76. APIHOOK_ENTRY(VERSION.DLL, VerQueryValueA)
  77. HOOK_END
  78. IMPLEMENT_SHIM_END