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.

152 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceAnsiGetDisplayNameOf.cpp
  5. Abstract:
  6. This shim force the routine IShellFolder::GetDisplayNameOf to return
  7. an Ascii string whenever it detects that GetDisplayNameOf returned
  8. a unicode string.
  9. Notes:
  10. This is an app is generic.
  11. History:
  12. 07/26/2000 mnikkel Created
  13. 02/15/2002 mnikkel Modified to use strsafe.h
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(ForceAnsiGetDisplayNameOf)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(SHGetDesktopFolder)
  20. APIHOOK_ENUM_ENTRY_COMSERVER(SHELL32)
  21. APIHOOK_ENUM_END
  22. IMPLEMENT_COMSERVER_HOOK(SHELL32)
  23. /*++
  24. Hook SHGetDesktopFolder to get the IShellFolder Interface Pointer.
  25. --*/
  26. HRESULT
  27. APIHOOK(SHGetDesktopFolder)(
  28. IShellFolder **ppshf
  29. )
  30. {
  31. HRESULT hReturn;
  32. hReturn = ORIGINAL_API(SHGetDesktopFolder)(ppshf);
  33. if (SUCCEEDED(hReturn))
  34. {
  35. HookObject(
  36. NULL,
  37. IID_IShellFolder,
  38. (PVOID*)ppshf,
  39. NULL,
  40. FALSE);
  41. }
  42. return hReturn;
  43. }
  44. /*++
  45. Hook GetDisplayName of and when it returns a unicode string convert it over to
  46. an ANSI string.
  47. --*/
  48. HRESULT
  49. COMHOOK(IShellFolder, GetDisplayNameOf)(
  50. PVOID pThis,
  51. LPCITEMIDLIST pidl,
  52. DWORD uFlags,
  53. LPSTRRET lpName
  54. )
  55. {
  56. HRESULT hrReturn = E_FAIL;
  57. BOOL bNotConverted = TRUE;
  58. _pfn_IShellFolder_GetDisplayNameOf pfnOld =
  59. ORIGINAL_COM(IShellFolder, GetDisplayNameOf, pThis);
  60. if (pfnOld)
  61. {
  62. hrReturn = (*pfnOld)(pThis, pidl, uFlags, lpName);
  63. // Check for unicode string and validity
  64. if ((S_OK == hrReturn) && lpName &&
  65. (lpName->uType == STRRET_WSTR) && lpName->pOleStr)
  66. {
  67. LPMALLOC pMalloc;
  68. LPWSTR pTemp = lpName->pOleStr;
  69. // Get a pointer to the Shell's IMalloc interface.
  70. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  71. {
  72. CSTRING_TRY
  73. {
  74. // Copy the OleStr to Cstr
  75. CString csOleStr(lpName->pOleStr);
  76. if (StringCchCopyA(lpName->cStr, ARRAYSIZE(lpName->cStr), csOleStr.GetAnsi()) == S_OK)
  77. {
  78. // set the uType to CSTR and free the old unicode string.
  79. lpName->uType = STRRET_CSTR;
  80. pMalloc->Free(pTemp);
  81. LOGN(
  82. eDbgLevelError,
  83. "[IShellFolder_GetDisplayNameOf] Converted string from Unicode to ANSI: %s",
  84. lpName->cStr);
  85. bNotConverted = FALSE;
  86. }
  87. }
  88. CSTRING_CATCH
  89. {
  90. // do nothing
  91. }
  92. }
  93. }
  94. }
  95. if (bNotConverted)
  96. {
  97. LOGN(
  98. eDbgLevelError,
  99. "[IShellFolder_GetDisplayNameOf] Unable to convert string from Unicode to ANSI");
  100. }
  101. return hrReturn;
  102. }
  103. /*++
  104. Register hooked functions
  105. --*/
  106. HOOK_BEGIN
  107. APIHOOK_ENTRY_COMSERVER(SHELL32)
  108. APIHOOK_ENTRY(SHELL32.DLL, SHGetDesktopFolder)
  109. COMHOOK_ENTRY(ShellDesktop, IShellFolder, GetDisplayNameOf, 11)
  110. HOOK_END
  111. IMPLEMENT_SHIM_END