Dear NTFSD members,
my encryption filter encrypts/decrypts files and filenames on removable drives.
No filesize changes.
Everything work fine on FAT (or at least I can’t find any bugs) but not on NTFS. The following bug I can always see on NTFS volume with compression:
I’m trying to copy 1000 files to removable drive. 1-3 of this files becomes bad after this operation (not the whole file, but a small part of it, with 32768 size).
With debug output I can see, that the content of this broken files was correctly encrypted.
Please take a look on this part of code, I did try a lot of ways, read this forum but…
You are the latest hope-)
case IRP_MJ_WRITE:
{
CMyCryptorFolder* pFolder;
PVOID pvBuffer;
ULONG dwLength;
pFolder = GetFolderFromFileObject(pFileObject);
if (pFolder == NULL)
break;
if (IsFolderFileObject(pFileObject))
break;
if (!(Irp->Flags & IRP_NOCACHE) && !(Irp->Flags & (IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO)))
break;
if (Irp->MdlAddress)
{
PMDL MdlNext;
ULONG cbMdl;
__try
{
dwLength = 0;
MdlNext = Irp->MdlAddress;
while (MdlNext != NULL)
{
pvBuffer = MmGetSystemAddressForMdlSafe(MdlNext, NormalPagePriority);
cbMdl = MmGetMdlByteCount(MdlNext);
pFolder->CryptData(pvBuffer, cbMdl);
MdlNext = MdlNext->Next;
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
break;
}
}
else
{
dwLength = pIoStackLocation->Parameters.Write.Length;
if (Irp->AssociatedIrp.SystemBuffer != NULL)
pFolder->CryptData(Irp->AssociatedIrp.SystemBuffer, dwLength);
else if (Irp->UserBuffer != NULL)
pFolder->CryptData(Irp->UserBuffer, dwLength);
}
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp, WriteFileComplete, pFolder, TRUE, TRUE, TRUE);
return IoCallDriver(deviceExt->FileSystem, Irp);
}
NTSTATUS WriteFileComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
{
PIO_STACK_LOCATION pIoStackLocation = IoGetCurrentIrpStackLocation(Irp);
PMDL MdlPrev, MdlNext;
CMyCryptorFolder* pFolder = (CMyCryptorFolder*) Context;
PVOID pvBuffer;
ULONG cbMdl;
if (Irp->MdlAddress == NULL)
{
ULONG dwLength = pIoStackLocation->Parameters.Write.Length;
if (Irp->AssociatedIrp.SystemBuffer != NULL)
pFolder->CryptData(Irp->AssociatedIrp.SystemBuffer, dwLength);
}
MdlNext = Irp->MdlAddress;
while (MdlNext != NULL)
{
pvBuffer = MmGetSystemAddressForMdlSafe(MdlNext, NormalPagePriority);
cbMdl = MmGetMdlByteCount(MdlNext);
pFolder->CryptData(pvBuffer, cbMdl);
MdlNext = MdlNext->Next;
}
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);
return Irp->IoStatus.Status;
}