I’ve been working with the Microsoft provided file system filter drivers from the IFS for quite some time now (a few weeks), but I’m still very new to driver development.
Like many others on this forum, I need to encrypt and decrypt file data. I’ve succeeded in encrypting file data for txt files. I’m just encrypting the Irp->UserBuffer in a IRP_MJ_WRITE operation by first making sure the file I’m writing to is a .TXT file and that it’s a UserMode operation.
Question on this: I noticed in-situ encryption is listed as a big “no no” here. I need to allocate my own buffer and use that. Heh? Actually, I originally did allocate my own buffer, but I don’t really know how to “use” it per se.
Create my own Irp? Can someone give me exact details on this process in a DispatchWrite() routine? Sure, I can make an Irp and fill it in with goodness and lovingkindness, but what *exactly* do I do with it then? Using my new Irp, do I?
IoCopyCurrentIrpStackLocationToNext( Irp );
IoSetCompletionRoutine( Irp,
DispatchReadCompletion,
NULL,
TRUE,
TRUE,
TRUE);
status = IoCallDriver( nextDrvThingy, Irp );
What do I do with the old Irp?
Okay. Enough of that.
How do I get the read buffer? My DispatchRead() routine will, of course, NOT have the read buffer. It might have information barely useful to what I need, but it doesn’t. I’ve created the DispatchReadCompletion() and successfully looked at ALL of the Irp->UserBuffer values returning, and they’re worthless.
Now, I’ve actually looked at this forum for this answer, and I’m all the more confused. People say to do the following:
IoAllocateMdl()
MmProbeAndLockPages()
And that’s about it. Wait, I also read I need to make the Irp pending for some reason.
As a big-time n00b, this stuff has confused me. Do I do this in my read dispatch routine?
Irp->MdlAddress = IoAllocateMdl()?
For all I’ve used Google until my eyes are bleeding, I can’t figure out what the heck I need to do to succesfully allocate an Mdl. Right now, I’m creating a buffer using ExAllocatePoolWithTag() and sending that buffer into the IoAllocateMdl() function
Wait, I found it, I also need to MmGetSystemAddressForMdlSafe() in my DispatchReadCompletion(), right?
None of this makes any sense to me.
First off, if I try to do this, it bombs most of the time:
Irp->MdlAddress = IoAllocateMdl(Irp->UserBuffer, strlen(Irp->UserBuffer), TRUE, FALSE, Irp);
if (Irp->MdlAddress != NULL)
{
try
{
MmProbeAndLockPages(Irp->MdlAddress, KernelMode, IoModifyAccess);
}
except (EXCEPTION_EXECUTE_HANDLER)
{
status = STATUS_ACCESS_VIOLATION;
}
}
…which is… I think… the gist of what I’ve read so far.
I would appreciate any help.