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.

136 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. Notes:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. IMPLEMENT_SHIM_BEGIN(TSPerUserFiles)
  10. #include "ShimHookMacro.h"
  11. #include "TSPerUserFiles_utils.h"
  12. APIHOOK_ENUM_BEGIN
  13. APIHOOK_ENUM_ENTRY(CreateFileA)
  14. APIHOOK_ENUM_ENTRY(CreateFileW)
  15. APIHOOK_ENUM_END
  16. CPerUserPaths* g_pPerUserPaths = NULL;
  17. HANDLE
  18. APIHOOK(CreateFileA)(
  19. LPCSTR lpFileName,
  20. DWORD dwDesiredAccess,
  21. DWORD dwShareMode,
  22. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  23. DWORD dwCreationDisposition,
  24. DWORD dwFlagsAndAttributes,
  25. HANDLE hTemplateFile
  26. )
  27. {
  28. LPCSTR strCorrect = lpFileName;
  29. if (g_pPerUserPaths) {
  30. strCorrect = g_pPerUserPaths->GetPerUserPathA(lpFileName);
  31. }
  32. return ORIGINAL_API(CreateFileA)(strCorrect,
  33. dwDesiredAccess,
  34. dwShareMode,
  35. lpSecurityAttributes,
  36. dwCreationDisposition,
  37. dwFlagsAndAttributes,
  38. hTemplateFile);
  39. }
  40. HANDLE
  41. APIHOOK(CreateFileW)(
  42. LPCWSTR lpFileName,
  43. DWORD dwDesiredAccess,
  44. DWORD dwShareMode,
  45. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  46. DWORD dwCreationDisposition,
  47. DWORD dwFlagsAndAttributes,
  48. HANDLE hTemplateFile
  49. )
  50. {
  51. LPCWSTR strCorrect = lpFileName;
  52. if (g_pPerUserPaths) {
  53. strCorrect = g_pPerUserPaths->GetPerUserPathW(lpFileName);
  54. }
  55. return ORIGINAL_API(CreateFileW)(strCorrect,
  56. dwDesiredAccess,
  57. dwShareMode,
  58. lpSecurityAttributes,
  59. dwCreationDisposition,
  60. dwFlagsAndAttributes,
  61. hTemplateFile);
  62. }
  63. /*++
  64. Register hooked functions
  65. --*/
  66. BOOL
  67. NOTIFY_FUNCTION(
  68. DWORD fdwReason
  69. )
  70. {
  71. if (fdwReason == DLL_PROCESS_ATTACH) {
  72. DPF("TSPerUserFiles",
  73. eDbgLevelInfo,
  74. "[NOTIFY_FUNCTION] DLL_PROCESS_ATTACH\n");
  75. g_pPerUserPaths = new CPerUserPaths;
  76. if (g_pPerUserPaths) {
  77. if (!g_pPerUserPaths->Init()) {
  78. delete g_pPerUserPaths;
  79. g_pPerUserPaths = NULL;
  80. }
  81. }
  82. } else if (fdwReason == DLL_PROCESS_DETACH) {
  83. DPF("TSPerUserFiles",
  84. eDbgLevelInfo,
  85. "[NOTIFY_FUNCTION] DLL_PROCESS_DETACH\n");
  86. }
  87. return TRUE;
  88. }
  89. HOOK_BEGIN
  90. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  91. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileW)
  92. CALL_NOTIFY_FUNCTION
  93. HOOK_END
  94. IMPLEMENT_SHIM_END