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.

74 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. LoadLibraryCWD.cpp
  5. Abstract:
  6. Some applications rely on the fact that LoadLibrary will search the current
  7. working directory (CWD) in-order to find dlls that are there. This is a
  8. security hole, so we apply shims to only the apps that really need it.
  9. Notes:
  10. This is a general purpose shim.
  11. History:
  12. 05/01/2002 linstev Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(LoadLibraryCWD)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_END
  19. typedef BOOL (WINAPI *_pfn_SetDllDirectoryW)(LPCWSTR lpPathName);
  20. BOOL
  21. NOTIFY_FUNCTION(
  22. DWORD fdwReason
  23. )
  24. {
  25. if (fdwReason == DLL_PROCESS_ATTACH) {
  26. HMODULE hMod = GetModuleHandleW(L"KERNEL32.DLL");
  27. if (hMod) {
  28. // Get the API
  29. _pfn_SetDllDirectoryW pfn = (_pfn_SetDllDirectoryW)
  30. GetProcAddress(hMod, "SetDllDirectoryW");
  31. if (pfn) {
  32. // Success, the API exists
  33. LOGN(eDbgLevelError, "DLL search order now starts with current directory");
  34. pfn(L".");
  35. return TRUE;
  36. }
  37. }
  38. LOGN(eDbgLevelError, "ERROR: DLL search order API does not exist");
  39. }
  40. return TRUE;
  41. }
  42. /*++
  43. Register hooked functions
  44. --*/
  45. HOOK_BEGIN
  46. CALL_NOTIFY_FUNCTION
  47. HOOK_END
  48. IMPLEMENT_SHIM_END