检查读取操作是否针对过滤器驱动程序中的特定文件
check if read operation is for spesific file in filter driver
你好,我是过滤器驱动程序编程的新手,我以 windows swapBuffer 示例为例,我尝试修改它以打印每个 read/write 操作的文件名
并打印尝试读取/写入的数据。
我试过这样做:
FLT_PREOP_CALLBACK_STATUS SwapPreWriteBuffers(
_Inout_ PFLT_CALLBACK_DATA Data,
_In_ PCFLT_RELATED_OBJECTS FltObjects,
_Flt_CompletionContext_Outptr_ PVOID *CompletionContext)
{
/* here we do some logic that check that we want to write more the
0 bytes and get volume context and allocate aligned nonPaged memory
for the "swapping memory" , build a MDL and then if all succeed i try this:
*/
WCHAR filename[300] = {0};
wfprintf(filename, "%wZ[=10=]", Data->Iopb->TargetFileObject->FileName);
if (NULL != wcstr(filename, L"try_me.txt"))
{
DbgPrint("Fname %S try to write %S\n", filename, Data->Iopb->Parameters.Write.WriteBuffe);
}
}
我的主要问题(我认为)Data->Iopb->TargetFileObject->FileName 是 unicode,我不知道如何在这个和文件名字符串之间进行比较
我的另一个问题是如何在不冒蓝屏风险的情况下将缓冲区当前打印到 dbg 字符串? (我从他们那里得到了很多......)有时我不用写字符串就可以使用这个函数,我如何识别不同并安全地打印它?
最后一个问题,有没有办法nake try除了驱动还是所有的故障都直接蓝屏?
谢谢
p.s。
这是整个代码的 link(没有我写的附加内容(我在上面的 post 中列出))
https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/miniFilter/swapBuffers/swapBuffers.c
文件名是IRP_MJ_CREATE处的概念。您不能依赖 irp_mj_write 上的名称或阅读。所以最好在创造中做到这一点。还尝试从 FltObject->FileObject->FileName 获取名称,它可能会为您提供所需的文件名称以及其他名称。
为了打印写入的数据,您需要检查 minifilter 中的 Irp 标志,它来自 Data->Iopb->IrpFlags,IRP_PAGING_IO 如果它是 true,则使用打印缓冲区
KdPrint(("..."));
是的,你可以使用 try,除了在驱动程序中。
希望这可能有所帮助。
:)
你好,我是过滤器驱动程序编程的新手,我以 windows swapBuffer 示例为例,我尝试修改它以打印每个 read/write 操作的文件名 并打印尝试读取/写入的数据。
我试过这样做:
FLT_PREOP_CALLBACK_STATUS SwapPreWriteBuffers(
_Inout_ PFLT_CALLBACK_DATA Data,
_In_ PCFLT_RELATED_OBJECTS FltObjects,
_Flt_CompletionContext_Outptr_ PVOID *CompletionContext)
{
/* here we do some logic that check that we want to write more the
0 bytes and get volume context and allocate aligned nonPaged memory
for the "swapping memory" , build a MDL and then if all succeed i try this:
*/
WCHAR filename[300] = {0};
wfprintf(filename, "%wZ[=10=]", Data->Iopb->TargetFileObject->FileName);
if (NULL != wcstr(filename, L"try_me.txt"))
{
DbgPrint("Fname %S try to write %S\n", filename, Data->Iopb->Parameters.Write.WriteBuffe);
}
}
我的主要问题(我认为)Data->Iopb->TargetFileObject->FileName 是 unicode,我不知道如何在这个和文件名字符串之间进行比较
我的另一个问题是如何在不冒蓝屏风险的情况下将缓冲区当前打印到 dbg 字符串? (我从他们那里得到了很多......)有时我不用写字符串就可以使用这个函数,我如何识别不同并安全地打印它?
最后一个问题,有没有办法nake try除了驱动还是所有的故障都直接蓝屏?
谢谢
p.s。 这是整个代码的 link(没有我写的附加内容(我在上面的 post 中列出)) https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/miniFilter/swapBuffers/swapBuffers.c
文件名是IRP_MJ_CREATE处的概念。您不能依赖 irp_mj_write 上的名称或阅读。所以最好在创造中做到这一点。还尝试从 FltObject->FileObject->FileName 获取名称,它可能会为您提供所需的文件名称以及其他名称。
为了打印写入的数据,您需要检查 minifilter 中的 Irp 标志,它来自 Data->Iopb->IrpFlags,IRP_PAGING_IO 如果它是 true,则使用打印缓冲区 KdPrint(("..."));
是的,你可以使用 try,除了在驱动程序中。
希望这可能有所帮助。
:)