Minifilter在特定情况下会丢失已删除的文件Windows 10 1903 +

问题描述 投票:0回答:1

我有一个微型过滤器驱动程序,该驱动程序缺少某些文件删除功能,问题在于不知道如何删除它们。 Windows 10 1903及更高版本就是这种情况。经过测试的1809年之前的版本,工作正常。

例如,MS C ++ 2008 x86可再发行的https://www.microsoft.com/en-gb/download/details.aspx?id=29,在安装时将setup.exe提取文件提取到C:{random GUID}(可以在日志中看到),然后进行安装。文件/目录随后被删除,在其中我错过了带有以下代码的IRP。

我目前正在使用FileDispositionInformation监视IRP_MJ_SET_INFORMATION的文件删除,您可以通过浏览器并按Shift + Delete进行测试。

添加了IRP_MJ_CREATE,用于关闭时以及根据RbMm注释删除。

我还监视FileRenameInformation来移动文件或重命名,如果您在资源管理器中移动/重命名文件,这同样有效。

我理想的解决方案是在创建文件时将其复制并复制到另一个位置,但是我不确定从哪里开始。我查看了一些微型过滤器示例,但找不到示例中的PreOperationCallback复制新创建的文件的位置。

我的另一种选择是尝试并理解上面的示例如何获取这些已删除的文件。还有其他可能要检查的FileInformationClass案例,以识别这种删除。

我的代码在下面的PreOperationCallback:

FLT_PREOP_CALLBACK_STATUS PreOperationCallback(_Inout_ 
PFLT_CALLBACK_DATA Data,
_In_ PCFLT_RELATED_OBJECTS FltObjects, 
_Flt_CompletionContext_Outptr_ PVOID* CompletionContext)
{

  /* IRP-based I/O operation? */
  if (FLT_IS_IRP_OPERATION(Data)) {

   if (Data->Iopb->MajorFunction == IRP_MJ_CREATE) {

    if (Data->Iopb->Parameters.Create.Options & (FILE_DELETE_ON_CLOSE)) {
        DbgPrint("FILE_DELETE_ON_CLOSE");
        return process_irp(Data, FltObjects, CompletionContext, FALSE, FALSE);

   }else if (Data->Iopb->MajorFunction == IRP_MJ_SET_INFORMATION) {

   switch (Data->Iopb->Parameters.SetFileInformation.FileInformationClass) {

     case FileDispositionInformation:
        // deleting a file we need to action
        if (((FILE_DISPOSITION_INFORMATION*) Data->Iopb->Parameters.SetFileInformation.InfoBuffer)->DeleteFile) {
          return process_irp(Data, FltObjects, CompletionContext, FALSE, FALSE);
        }
        break;

     case FileRenameInformation:

       // Process the request according to our needs e.g copy the file
       return process_irp(Data, FltObjects, CompletionContext, FALSE, TRUE);
     }
   }
 }

  return FLT_PREOP_SUCCESS_NO_CALLBACK;
}

更新-我刚刚创建了一个非常简单的C#应用​​程序来创建文件,并使用File.Delete(“ C:\ test.txt”)删除它;驱动程序不会在1903或更高版本的当前代码库中进行提取。

任何帮助将不胜感激。

c windows driver minifilter
1个回答
0
投票

您必须像下面那样为FileRenameInformationEx和FileDispositionInformationEx设置'process_irp'。

switch (Data->Iopb->Parameters.SetFileInformation.FileInformationClass) {

 case FileDispositionInformation:
 case 64/*FileDispositionInformationEx*/:
    // deleting a file we need to action
    if (((FILE_DISPOSITION_INFORMATION*) Data->Iopb->Parameters.SetFileInformation.InfoBuffer)->DeleteFile) {
      return process_irp(Data, FltObjects, CompletionContext, FALSE, FALSE);
    }
    break;

 case FileRenameInformation:
 case 65/*FileRenameInformationEx*/:
   // Process the request according to our needs e.g copy the file
   return process_irp(Data, FltObjects, CompletionContext, FALSE, TRUE);
 }

}

© www.soinside.com 2019 - 2024. All rights reserved.