MCPcopy Create free account
hub / github.com/D4stiny/PeaceMaker / HandlePreWriteOperation

Method HandlePreWriteOperation

PeaceMaker Kernel/FSFilter.cpp:235–318  ·  view source on GitHub ↗

This function is called prior to a write operation. Data - The data associated with the current operation. FltObjects - Objects related to the filter, instance, and its associated volume. CompletionContext - Optional context to be passed to post operation callbacks. */

Source from the content-addressed store, hash-verified

233 CompletionContext - Optional context to be passed to post operation callbacks.
234*/
235FLT_PREOP_CALLBACK_STATUS
236FSBlockingFilter::HandlePreWriteOperation(
237 _Inout_ PFLT_CALLBACK_DATA Data,
238 _In_ PCFLT_RELATED_OBJECTS FltObjects,
239 _Flt_CompletionContext_Outptr_ PVOID* CompletionContext
240 )
241{
242 FLT_PREOP_CALLBACK_STATUS callbackStatus;
243 PFLT_FILE_NAME_INFORMATION fileNameInfo;
244
245 PUNICODE_STRING callerProcessPath;
246 PSTACK_RETURN_INFO fileOperationStack;
247 ULONG fileOperationStackSize;
248 BOOLEAN reportOperation;
249
250 UNREFERENCED_PARAMETER(FltObjects);
251 UNREFERENCED_PARAMETER(CompletionContext);
252
253 reportOperation = FALSE;
254 fileOperationStackSize = MAX_STACK_RETURN_HISTORY;
255 fileNameInfo = NULL;
256 callbackStatus = FLT_PREOP_SUCCESS_NO_CALLBACK;
257
258 //
259 // PeaceMaker is not designed to block kernel operations.
260 //
261 if (ExGetPreviousMode() == KernelMode)
262 {
263 return callbackStatus;
264 }
265
266 if (NT_SUCCESS(FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &fileNameInfo)))
267 {
268 if (FSBlockingFilter::FileStringFilters->MatchesFilter(fileNameInfo->Name.Buffer, FILTER_FLAG_WRITE) != FALSE)
269 {
270 DBGPRINT("FSBlockingFilter!HandlePreWriteOperation: Detected write on %wZ. Prevented write!", fileNameInfo->Name);
271 Data->Iopb->TargetFileObject->DeletePending = FALSE;
272 Data->IoStatus.Information = 0;
273 Data->IoStatus.Status = STATUS_ACCESS_DENIED;
274 callbackStatus = FLT_PREOP_COMPLETE;
275 reportOperation = TRUE;
276 }
277 }
278
279 if (reportOperation)
280 {
281 //
282 // Grab the caller's path.
283 //
284 ImageHistoryFilter::GetProcessImageFileName(PsGetCurrentProcessId(), &callerProcessPath);
285
286 //
287 // Walk the stack.
288 //
289 FSBlockingFilter::walker.WalkAndResolveStack(&fileOperationStack, &fileOperationStackSize, STACK_HISTORY_TAG);
290
291 NT_ASSERT(fileOperationStack);
292

Callers

nothing calls this directly

Calls 3

MatchesFilterMethod · 0.80
WalkAndResolveStackMethod · 0.80
ReportFilterViolationMethod · 0.80

Tested by

no test coverage detected