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.

106 lines
2.4 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. BOOL bRet = ORIGINAL_API(VerQueryValueA)(
  30. pBlock,
  31. lpSubBlock,
  32. lplpBuffer,
  33. puLen);
  34. if (bRet)
  35. {
  36. CSTRING_TRY
  37. {
  38. CString csSubBlock(lpSubBlock);
  39. if (csSubBlock.Find(L"ProductVersion") != -1 ||
  40. csSubBlock.Find(L"FileVersion") != -1)
  41. {
  42. int nLoc = 0;
  43. DPFN(eDbgLevelError, "[VerQueryValueA] Asking for Product or File Version, trimming blanks");
  44. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info is <%s>", *lplpBuffer);
  45. CString csBuffer((char *)*lplpBuffer);
  46. //
  47. // Search for first blank
  48. //
  49. nLoc = csBuffer.Find(L" ");
  50. if (nLoc != -1)
  51. {
  52. // if a blank is found then truncate string to that point
  53. csBuffer.Truncate(nLoc);
  54. StringCchCopyA((char *)*lplpBuffer, *puLen, csBuffer.GetAnsi());
  55. if (puLen)
  56. {
  57. *puLen = nLoc;
  58. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info Length = %d.", *puLen);
  59. }
  60. }
  61. DPFN(eDbgLevelSpew, "[VerQueryValueA] Version info after trim is <%s>.", *lplpBuffer);
  62. }
  63. }
  64. CSTRING_CATCH
  65. {
  66. /* do nothing */
  67. }
  68. }
  69. return bRet;
  70. }
  71. /*++
  72. Register hooked functions
  73. --*/
  74. HOOK_BEGIN
  75. APIHOOK_ENTRY(VERSION.DLL, VerQueryValueA)
  76. HOOK_END
  77. IMPLEMENT_SHIM_END