ReactOS  0.4.14-dev-41-g31d7680
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  {
164  case DLL_PROCESS_ATTACH:
165  DisableThreadLibraryCalls(hinstDLL);
166  break;
167  }
168 
169  return TRUE;
170 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
DWORD dwReason
Definition: misc.cpp:154

◆ 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 }
#define TRUE
Definition: types.h:120
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,
100  BufferLength);
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,
115  BufferLength);
116 
117  /* Cleanup and bail*/
118  RtlFreeHeap(GetProcessHeap(), 0, FilterName);
119  CloseHandle(hFltMgr);
120 
121  return HRESULT_FROM_WIN32(dwError);
122 }
#define CloseHandle
Definition: compat.h:398
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define IOCTL_FILTER_UNLOAD
Definition: fltmgr_shared.h:4
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define GetProcessHeap()
Definition: compat.h:395
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
struct _FILTER_NAME FILTER_NAME
ULONG_PTR SIZE_T
Definition: typedefs.h:78
static DWORD SendIoctl(_In_ HANDLE Handle, _In_ ULONG IoControlCode, _In_reads_bytes_opt_(BufferSize) LPVOID lpInBuffer, _In_ DWORD BufferSize)
Definition: fltlib.c:126
#define CreateFileW
Definition: compat.h:400
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IOCTL_FILTER_LOAD
Definition: fltmgr_shared.h:3
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

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 }
static HRESULT FilterLoadUnload(_In_z_ LPCWSTR lpFilterName, _In_ BOOL Load)
Definition: fltlib.c:72

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
HRESULT hr
Definition: shlfolder.c:183
LONG HRESULT
Definition: typedefs.h:77
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
unsigned int ULONG
Definition: retypes.h:1

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,
138  &IoStatusBlock,
140  lpInBuffer,
141  BufferSize,
142  NULL,
143  0);
144  if (Status == STATUS_PENDING)
145  {
147  if (NT_SUCCESS(Status))
148  {
150  }
151  }
152 
154 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
LONG NTSTATUS
Definition: precomp.h:26
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)
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define BufferSize
Definition: classpnp.h:419
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by FilterLoadUnload().