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.

84 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CorrectFilePathInSetDlgItemText.cpp
  5. Abstract:
  6. This is an general purpose shim that watches the calls to SetDlgItemText
  7. and looks for paths. If found it corrects the path.
  8. History:
  9. 12/21/2000 a-brienw Created
  10. --*/
  11. #include "precomp.h"
  12. #include "ShimHook.h"
  13. IMPLEMENT_SHIM_BEGIN(CorrectFilePathInSetDlgItemText)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(SetDlgItemTextA)
  17. APIHOOK_ENUM_END
  18. /*
  19. Look for incorrect system directory path being put into a dialog box
  20. item and replace it with the correct system directory path.
  21. */
  22. BOOL
  23. APIHOOK(SetDlgItemTextA)(
  24. HWND hWnd, // handle to window
  25. int nIDDlgItem, // control identifier
  26. LPCSTR lpString // text to set
  27. )
  28. {
  29. if( lpString != NULL)
  30. {
  31. CSTRING_TRY
  32. {
  33. CString csText(lpString);
  34. if (csText.CompareNoCase(L"c:\\windows\\system\\") == 0 )
  35. {
  36. CString csWinDir;
  37. csWinDir.GetSystemDirectory();
  38. csText.Replace(L"c:\\windows\\system\\", csWinDir);
  39. LOGN( eDbgLevelWarning,
  40. "SetDlgItemTextA converted lpString from \"%s\" to \"%S\".",
  41. lpString, csText.Get());
  42. return SetDlgItemTextA(hWnd, nIDDlgItem, csText.GetAnsi());
  43. }
  44. }
  45. CSTRING_CATCH
  46. {
  47. // Do nothing
  48. }
  49. }
  50. return ORIGINAL_API(SetDlgItemTextA)(hWnd, nIDDlgItem, lpString);
  51. }
  52. /*++
  53. Register hooked functions
  54. --*/
  55. HOOK_BEGIN
  56. APIHOOK_ENTRY(USER32.DLL, SetDlgItemTextA)
  57. HOOK_END
  58. IMPLEMENT_SHIM_END