文件系统过滤驱动中关于IRP_MJ_CREATE文件路径的重定向问题???

liwenjing402398 2010-03-04 02:58:37
如题,我想在IRP_MJ_CREATE截获创建的文件路径,并修改重定向到U盘上创建,就是文件的转存!如有可行代码请多多提示,大牛帮帮忙啊!!!
...全文
243 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liwenjing402398 2010-03-10
  • 打赏
  • 举报
回复
用.Create.Options >> 24可以对打开和创建分开,楼上有相关连接吗???
asideu 2010-03-09
  • 打赏
  • 举报
回复
IRP_MJ_CREATE不仅仅是创建 打开也是这个,你去驱动开发网找找,我记得那里有讨论的。
kyzf 2010-03-05
  • 打赏
  • 举报
回复
不会, 帮顶下。


期待高手吧,MARK 、 、 、 、 、
liwenjing402398 2010-03-05
  • 打赏
  • 举报
回复
不种方法我也用过了,要修改很多地方,而且一开始就蓝屏了!有谁写过文件转存的吗??请指教啊!!!!
CubieZhou 2010-03-05
  • 打赏
  • 举报
回复
To redirect a file-open or file-creation operation to another file, a file system filter driver does the following:
In the handler of IRP_MJ_CREATE, obtains the file name (FileName field) from the FILE_OBJECT.
Replaces this name with the full name of the destination file.

This full name includes the name of the volume device object (for example, Device\HardDiskVolume0\Directory\MyFile.txt). You can substitute your own buffer to the existing FileName.Buffer present in the FILE_OBJECT. In this case, allocate your buffer from NonPaged pool memory, free the original FileName.Buffer by using ExFreePool, and then replace FileName.Buffer with your buffer.
Sets the status field of the IoStatus block to STATUS_REPARSE, and then sets the Information field to IO_REPARSE.
Completes the request.
Returns STATUS_REPARSE.
The IO Manager then triggers another file-open operation and sends an IRP_MJ_CREATE, taking into account the particular file name.

The destination file can be local or on a remote computer. To redirect the file-open operation to a remote file, use the following syntax for the file name:
"\??\UNC\HostName\Share\File"

-or-
"\Device\Mup\HostName\Share\File"

-or-
"\Device\LanmanagerRedirector\HostName\Share\File" (assuming you are targeting a file on CIFS/SMB/LanManager)
The fact that the first create-file operation is performed relative to another file object does not matter. Do not modify the RelatedFileObject field of the FILE_OBJECT. To perform the reparse operation, the IO Manager considers only the FileName field and not the RelatedFileObject. Additionally, the IO Manager frees the RelatedFileObject, as appropriate, when it handles the STATUS_REPARSE status returned by the filter. Therefore, it is not the responsibility of the filter to free that file object.

There is a fixed limit concerning the number of nested reparse operations that the IO Manager can perform. This limit has been introduced to avoid infinite loops. The maximum number of nested reparse operations the system can perform is 32.

This reparsing method performed by the IO Manager has to be disassociated from reparse points. Reparse points have been introduced in NTFS, starting with Microsoft Windows 2000. Reparse points permit you to store information together with a file.



NTSTATUS
SfCreate (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION IrpSp;
PUNICODE_STRING FileName;
PVOID FileNameBuffer;
UNICODE_STRING NewFileName;
BOOLEAN bRedirectFileOpen = FALSE;

//
// If the device being opened is the primary device object instead of a
// filter device object, just indicate that the operation worked.
//

if (DeviceObject == FsDeviceObject)
{
//
// Allow users to open the device that represents our driver.
//

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;

IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_SUCCESS;
}

IrpSp = IoGetCurrentIrpStackLocation(Irp);

//
// At this point, you must determine whether you want to redirect
// the file open/create for this particular file.
// Beware that the file name from the FILE_OBJECT in the current
// IRP stack location is not always the file name with the full
// path, nor the long file name or even a name. The way the file is
// opened (with full path, relatively to another file, with short
// or long file name, by ID, ...) affects this name.
//
// TODO: Put your code here to check whether you have to redirect the operation.
// If so, set bRedirectFileOpen to TRUE and initialize the NewFileName
// UNICODE_STRING to the full file name of the destination file.
//

if ( bRedirectFileOpen )
{
FileName = &(IrpSp->FileObject->FileName);

FileNameBuffer = ExAllocatePool( NonPagedPool, NewFileName.MaximumLength );
if (!FileNameBuffer)
{
//
// Not enough resources. Complete the IRP with the appropriate status.
//

Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Information = 0;

IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_INSUFFICIENT_RESOURCES;
}

ExFreePool( FileName->Buffer );
FileName->Buffer = FileNameBuffer;
FileName->MaximumLength = NewFileName.MaximumLength;

RtlCopyUnicodeString( FileName, &NewFileName );

//
// Instruct the IO Manager to reparse this file.
//

Irp->IoStatus.Status = STATUS_REPARSE;
Irp->IoStatus.Information = IO_REPARSE;

IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_REPARSE;
}
else
{
//
// Pass the request "as is" down the device stack.
//

//
// The next driver will get the IO_STACK_LOCATION
// that you received.
//

IoSkipCurrentIrpStackLocation( Irp );

//
// Call the appropriate file system driver with the request.
//
// TODO: Replace AttachedToDeviceObject by the device
// object pointer your device object is attached to (the
// lower device object in the stack).
// Typically, this device object pointer is saved by your
// filter in your device extension.
//

return IoCallDriver( AttachedToDeviceObject, Irp );
}
}
liwenjing402398 2010-03-05
  • 打赏
  • 举报
回复
高手呢,帮帮忙啊!!!!!!!

21,600

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧