I need to read files that are opened exclusively. For my test I’m using
\hiberfil.sys (is this the registry?).
I am trying to roll my own IRP_MJ_CREATE. I am having a big problem
creating a file object from scratch. The NTFS driver crashes with a bad
access. Is there a better way to do this?
Here is my code I’ve been trying to use. devExt is the same as defined in
FileSpy.
PIRP Irp;
PIO_STACK_LOCATION irpSp;
KEVENT event;
FILE_OBJECT fileObject;
Path = L"\hiberfil.sys";
Irp = IoAllocateIrp( MAXIMUM_IRP_STACK_LOCATIONS, FALSE );
Irp->Flags = IRP_CREATE_OPERATION | IRP_DEFER_IO_COMPLETION |
IRP_SYNCHRONOUS_API;
Irp->RequestorMode = KernelMode;
Irp->UserEvent = &event;
Irp->UserIosb = &ioStatus;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject = NULL;
irpSp = IoGetNextIrpStackLocation(Irp);
irpSp->Flags = 0;
irpSp->MajorFunction = IRP_MJ_CREATE;
irpSp->MinorFunction = 0;
irpSp->Parameters.Create.EaLength = 0;
irpSp->Parameters.Create.FileAttributes = FILE_ATTRIBUTE_NORMAL;
irpSp->Parameters.Create.Options = FILE_NON_DIRECTORY_FILE |
FILE_SEQUENTIAL_ONLY |
FILE_SYNCHRONOUS_IO_NONALERT;
irpSp->Parameters.Create.SecurityContext = NULL;
irpSp->DeviceObject = devExt->AttachedToDeviceObject;
irpSp->FileObject = NULL;
irpSp->Parameters.Create.ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE;
RtlZeroMemory( &fileObject, sizeof(fileObject));
fileObject.Type = 5;
fileObject.Size = sizeof(fileObject);
fileObject.DeviceObject = devExt->DiskDeviceObject;
fileObject.Vpb = devExt->DiskDeviceObject->Vpb;
fileObject.Flags = FO_SYNCHRONOUS_IO;
fileObject.FileName.Length = (SHORT) (wcslen(Path) * sizeof(WCHAR));
fileObject.FileName.MaximumLength = fileObject.FileName.Length;
fileObject.FileName.Buffer = Path;
irpSp->FileObject = &fileObject;
KeInitializeEvent( &event, NotificationEvent , FALSE);
IoSetCompletionRoutine( Irp, CpsSyncCreateCompletion, NULL, TRUE, TRUE,
TRUE );
status = IoCallDriver( devExt->AttachedToDeviceObject, Irp );