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.

99 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Attune.cpp
  5. Abstract:
  6. App uses counters that are obsolete since Win2k.
  7. App uses \System\% Total Processor Time counter instead of
  8. \Processor(_Total)\% Processor Time counter.
  9. This shim corrects the counter name before making a
  10. call to PdhAddCounterA.
  11. Notes:
  12. This is an app specific shim.
  13. History:
  14. 03/16/2001 a-leelat Created
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(Attune)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(PdhAddCounterA)
  21. APIHOOK_ENUM_END
  22. /*++
  23. Hook PdhAddCounterA
  24. --*/
  25. PDH_FUNCTION
  26. APIHOOK(PdhAddCounterA)(
  27. IN HQUERY hQuery,
  28. IN LPCSTR szFullCounterPath,
  29. IN DWORD_PTR dwUserData,
  30. IN HCOUNTER *phCounter
  31. )
  32. {
  33. PDH_STATUS ReturnStatus = ERROR_SUCCESS;
  34. BOOL bCorrectedPath = false;
  35. CHAR szCorrectCounterPath[] = "\\Processor(_Total)\\% Processor Time";
  36. CSTRING_TRY
  37. {
  38. //Obsolete counter Path to check for
  39. CString szObsoleteCounterPath = "\\System\\% Total Processor Time";
  40. //Passed in counter Path
  41. CString szCounterPath(szFullCounterPath);
  42. //Check to see if we have the obolsete counter passed in
  43. if (szObsoleteCounterPath.CompareNoCase(szCounterPath.Get()) == 0)
  44. bCorrectedPath = true;
  45. }
  46. CSTRING_CATCH
  47. {
  48. }
  49. //Call the original API
  50. ReturnStatus = ORIGINAL_API(PdhAddCounterA)(
  51. hQuery,
  52. bCorrectedPath ? szCorrectCounterPath : szFullCounterPath,
  53. dwUserData,
  54. phCounter);
  55. return ReturnStatus;
  56. }
  57. /*++
  58. Register hooked functions
  59. --*/
  60. HOOK_BEGIN
  61. APIHOOK_ENTRY(PDH.DLL, PdhAddCounterA)
  62. HOOK_END
  63. IMPLEMENT_SHIM_END