阅读:1463回复:5
自己发IRP包更名文件出错,帮我看看代码
根据网上的代码改变的,但是总是返回0xc000000d,无效参数错误,请高手指点一下吧
KeRenameFile( PDEVICE_OBJECT DeviceObject, PFILE_OBJECT FileObject, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID FileInformation, IN ULONG Length ) { PIRP Irp; PIO_STACK_LOCATION IrpSp; KEVENT Event; NTSTATUS Status; Irp = IoAllocateIrp( DeviceObject->StackSize, FALSE ); if ( ! Irp ) return STATUS_INSUFFICIENT_RESOURCES; KeInitializeEvent( &Event, SynchronizationEvent, FALSE ); IoStatusBlock->Status = STATUS_SUCCESS; IoStatusBlock->Information = 0; Irp->Flags |= IRP_BUFFERED_IO; Irp->RequestorMode = KernelMode; Irp->UserIosb = &IoStatusBlock; Irp->UserEvent = NULL; Irp->Tail.Overlay.OriginalFileObject = FileObject; Irp->Tail.Overlay.Thread = PsGetCurrentThread(); Irp->AssociatedIrp.SystemBuffer = (PVOID)FileInformation; IrpSp = IoGetNextIrpStackLocation( Irp ); IrpSp->MajorFunction = IRP_MJ_SET_INFORMATION; IrpSp->FileObject = FileObject; IrpSp->DeviceObject = DeviceObject; IrpSp->Parameters.SetFile.Length = Length; // length of Rename IrpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation; IrpSp->Parameters.SetFile.FileObject = FileObject; IrpSp->Parameters.SetFile.ReplaceIfExists = ((PFILE_RENAME_INFORMATION)FileInformation)->ReplaceIfExists; IoSetCompletionRoutine( Irp, KeFileCompletion, &Event, TRUE, TRUE, TRUE ); Status = IoCallDriver( DeviceObject, Irp ); if (STATUS_PENDING == Status) { (VOID) KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL ); } if(Irp) { IoFreeIrp(Irp); Irp = NULL; } KeClearEvent(&Event); if (!NT_SUCCESS(Status)) IoStatusBlock->Status = Status; return IoStatusBlock->Status; } len = sizeof(FILE_RENAME_INFORMATION)+wcslen(fullUniName.Buffer)*2+1; ReFileInfo = ExAllocatePool(NonPagedPool,len); if(ReFileInfo) { RtlZeroMemory(ReFileInfo,len); } ReFileInfo->ReplaceIfExists = FALSE; ReFileInfo->RootDirectory = 0; ReFileInfo->FileNameLength = wcslen(fullUniName.Buffer)*2 ; RtlCopyMemory(ReFileInfo->FileName,fullUniName.Buffer,wcslen(fullUniName.Buffer)*2); KdPrint(("\nrename file:%ws\n",ReFileInfo->FileName)); Status = KeRenameFile(device_extension->NLExtHeader.AttachedToDeviceObject,IrpStack->FileObject, &MyIoStatusBlock,ReFileInfo,sizeof(FILE_RENAME_INFORMATION)); |
|
沙发#
发布于:2008-04-10 15:01
大家都不用这种方式吗
|
|
板凳#
发布于:2008-04-16 22:00
这个错误码我也遇到过,帮你顶~
|
|
地板#
发布于:2008-04-17 09:47
发个可以编译的code
|
|
地下室#
发布于:2008-04-17 16:35
KeRenameFile(device_extension->NLExtHeader.AttachedToDeviceObject,IrpStack->FileObject,
&MyIoStatusBlock,ReFileInfo,sizeof(FILE_RENAME_INFORMATION)); 这里的sizeof(FILE_RENAME_INFORMATION)应该改为len (-1?, -3?) |
|
5楼#
发布于:2008-04-22 15:40
看了一下。
IrpSp->Parameters.SetFile.FileObject = FileObject; 画蛇添足,应删掉。 ReFileInfo->ReplaceIfExists = FALSE;与 IrpSp->Parameters.SetFile.ReplaceIfExists = ((PFILE_RENAME_INFORMATION)FileInformation)->ReplaceIfExists; 自相矛盾,改为 ReFileInfo->ReplaceIfExists = TRUE;吧。 |
|