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.

131 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. LogFileChanges.h
  5. Abstract:
  6. This AppVerifier shim hooks all the native file I/O APIs
  7. that change the state of the system and logs their
  8. associated data to a text file.
  9. Notes:
  10. This is a general purpose shim.
  11. History:
  12. 08/17/2001 rparsons Created
  13. --*/
  14. #ifndef __APPVERIFIER_LOGFILECHANGES_H_
  15. #define __APPVERIFIER_LOGFILECHANGES_H_
  16. #include "precomp.h"
  17. //
  18. // Length (in characters) of the largest element.
  19. //
  20. #define MAX_ELEMENT_SIZE 1024 * 10
  21. //
  22. // Length (in characters) of the longest operation type.
  23. //
  24. #define MAX_OPERATION_LENGTH 32
  25. //
  26. // Flags that indicate what state the file is in.
  27. //
  28. #define LFC_EXISTING 0x00000001
  29. #define LFC_DELETED 0x00000002
  30. #define LFC_MODIFIED 0x00000004
  31. #define LFC_UNAPPRVFW 0x00000008
  32. //
  33. // Maximum number of handles we can track for a single file.
  34. //
  35. #define MAX_NUM_HANDLES 64
  36. //
  37. // We maintain a doubly linked list of file handles so we know what file is being modified
  38. // during a file operation.
  39. //
  40. typedef struct _LOG_HANDLE {
  41. LIST_ENTRY Entry;
  42. HANDLE hFile[MAX_NUM_HANDLES]; // array of file handles
  43. DWORD dwFlags; // flags that relate to the state of the file
  44. LPWSTR pwszFilePath; // full path to the file
  45. UINT cHandles; // number of handles open for this file
  46. } LOG_HANDLE, *PLOG_HANDLE;
  47. //
  48. // Flags that define different settings in effect.
  49. //
  50. #define LFC_OPTION_ATTRIBUTES 0x00000001
  51. #define LFC_OPTION_UFW_WINDOWS 0x00000002
  52. #define LFC_OPTION_UFW_PROGFILES 0x00000004
  53. //
  54. // Enumeration for different operations.
  55. //
  56. typedef enum {
  57. eCreatedFile = 0,
  58. eOpenedFile,
  59. eDeletedFile,
  60. eModifiedFile,
  61. eRenamedFile
  62. } OperationType;
  63. #ifdef ARRAYSIZE
  64. #undef ARRAYSIZE
  65. #endif
  66. #define ARRAYSIZE(a) (sizeof(a)/sizeof(*a))
  67. //
  68. // Macros for memory allocation/deallocation.
  69. //
  70. #define MemAlloc(s) RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, (s))
  71. #define MemFree(b) RtlFreeHeap(RtlProcessHeap(), 0, (b))
  72. //
  73. // Keep us safe while we're playing with linked lists and shared resources.
  74. //
  75. static BOOL g_bInitialized = FALSE;
  76. CRITICAL_SECTION g_csLogging;
  77. class CLock
  78. {
  79. public:
  80. CLock()
  81. {
  82. if (!g_bInitialized)
  83. {
  84. InitializeCriticalSection(&g_csLogging);
  85. g_bInitialized = TRUE;
  86. }
  87. EnterCriticalSection(&g_csLogging);
  88. }
  89. ~CLock()
  90. {
  91. LeaveCriticalSection(&g_csLogging);
  92. }
  93. };
  94. APIHOOK_ENUM_BEGIN
  95. APIHOOK_ENUM_ENTRY(NtDeleteFile)
  96. APIHOOK_ENUM_ENTRY(NtClose)
  97. APIHOOK_ENUM_ENTRY(NtCreateFile)
  98. APIHOOK_ENUM_ENTRY(NtOpenFile)
  99. APIHOOK_ENUM_ENTRY(NtWriteFile)
  100. APIHOOK_ENUM_ENTRY(NtWriteFileGather)
  101. APIHOOK_ENUM_ENTRY(NtSetInformationFile)
  102. APIHOOK_ENUM_END
  103. #endif // __APPVERIFIER_LOGFILECHANGES_H_