ReactOS 0.4.15-dev-5667-ged97270
fltlib.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <ndk/iofuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/rtlfuncs.h>
#include <fltmgr_shared.h>
Include dependency graph for fltlib.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 

Functions

static HRESULT FilterLoadUnload (_In_z_ LPCWSTR lpFilterName, _In_ BOOL Load)
 
static DWORD SendIoctl (_In_ HANDLE Handle, _In_ ULONG IoControlCode, _In_reads_bytes_opt_(BufferSize) LPVOID lpInBuffer, _In_ DWORD BufferSize)
 
_Must_inspect_result_ HRESULT WINAPI FilterLoad (_In_ LPCWSTR lpFilterName)
 
_Must_inspect_result_ HRESULT WINAPI FilterUnload (_In_ LPCWSTR lpFilterName)
 
HRESULT NtStatusToHResult (_In_ NTSTATUS Status)
 
BOOL WINAPI DllMain (_In_ HINSTANCE hinstDLL, _In_ DWORD dwReason, _In_ LPVOID lpvReserved)
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 16 of file fltlib.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file fltlib.c.

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( _In_ HINSTANCE  hinstDLL,
_In_ DWORD  dwReason,
_In_ LPVOID  lpvReserved 
)

Definition at line 158 of file fltlib.c.

161{
162 switch (dwReason)
163 {
166 break;
167 }
168
169 return TRUE;
170}
DWORD dwReason
Definition: misc.cpp:154
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85

◆ FilterLoad()

_Must_inspect_result_ HRESULT WINAPI FilterLoad ( _In_ LPCWSTR  lpFilterName)

Definition at line 42 of file fltlib.c.

43{
44 return FilterLoadUnload(lpFilterName, TRUE);
45}
static HRESULT FilterLoadUnload(_In_z_ LPCWSTR lpFilterName, _In_ BOOL Load)
Definition: fltlib.c:72

Referenced by KmtFltLoad(), and LoadFilter().

◆ FilterLoadUnload()

static HRESULT FilterLoadUnload ( _In_z_ LPCWSTR  lpFilterName,
_In_ BOOL  Load 
)
static

Definition at line 72 of file fltlib.c.

74{
75 PFILTER_NAME FilterName;
76 HANDLE hFltMgr;
77 SIZE_T StringLength;
79 DWORD dwError;
80
81 /* Get a handle to the filter manager */
82 hFltMgr = CreateFileW(L"\\\\.\\fltmgr",
85 NULL,
88 &hFltMgr);
89 if (hFltMgr == INVALID_HANDLE_VALUE)
90 {
91 dwError = GetLastError();
92 return HRESULT_FROM_WIN32(dwError);
93 }
94
95 /* Calc and allocate a buffer to hold our filter name */
96 StringLength = wcslen(lpFilterName) * sizeof(WCHAR);
97 BufferLength = StringLength + sizeof(FILTER_NAME);
98 FilterName = RtlAllocateHeap(GetProcessHeap(),
99 0,
101 if (FilterName == NULL)
102 {
103 CloseHandle(hFltMgr);
105 }
106
107 /* Build up the filter name */
108 FilterName->Length = StringLength;
109 CopyMemory(FilterName->FilterName, lpFilterName, StringLength);
110
111 /* Tell the filter manager to load the filter for us */
112 dwError = SendIoctl(hFltMgr,
114 FilterName,
116
117 /* Cleanup and bail*/
118 RtlFreeHeap(GetProcessHeap(), 0, FilterName);
119 CloseHandle(hFltMgr);
120
121 return HRESULT_FROM_WIN32(dwError);
122}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD SendIoctl(_In_ HANDLE Handle, _In_ ULONG IoControlCode, _In_reads_bytes_opt_(BufferSize) LPVOID lpInBuffer, _In_ DWORD BufferSize)
Definition: fltlib.c:126
#define IOCTL_FILTER_UNLOAD
Definition: fltmgr_shared.h:4
#define IOCTL_FILTER_LOAD
Definition: fltmgr_shared.h:3
struct _FILTER_NAME FILTER_NAME
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define CopyMemory
Definition: winbase.h:1668
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by FilterLoad(), and FilterUnload().

◆ FilterUnload()

_Must_inspect_result_ HRESULT WINAPI FilterUnload ( _In_ LPCWSTR  lpFilterName)

Definition at line 50 of file fltlib.c.

51{
52 return FilterLoadUnload(lpFilterName, FALSE);
53}
#define FALSE
Definition: types.h:117

Referenced by KmtFltUnload(), and UnloadFilter().

◆ NtStatusToHResult()

HRESULT NtStatusToHResult ( _In_ NTSTATUS  Status)

Definition at line 59 of file fltlib.c.

60{
61 HRESULT hr;
63 if (hr != ERROR_SUCCESS)
64 {
65 hr = (ULONG)hr | 0x80070000;
66 }
67 return hr;
68}
#define ERROR_SUCCESS
Definition: deptool.c:10
Status
Definition: gdiplustypes.h:25
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
HRESULT hr
Definition: shlfolder.c:183
uint32_t ULONG
Definition: typedefs.h:59

Referenced by FilterConnectCommunicationPort().

◆ SendIoctl()

static DWORD SendIoctl ( _In_ HANDLE  Handle,
_In_ ULONG  IoControlCode,
_In_reads_bytes_opt_(BufferSize) LPVOID  lpInBuffer,
_In_ DWORD  BufferSize 
)
static

Definition at line 126 of file fltlib.c.

130{
133
135 NULL,
136 NULL,
137 NULL,
140 lpInBuffer,
142 NULL,
143 0);
144 if (Status == STATUS_PENDING)
145 {
147 if (NT_SUCCESS(Status))
148 {
150 }
151 }
152
154}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG Handle
Definition: gdb_input.c:15
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by FilterLoadUnload().