阅读:2179回复:2
求助 FileDisk 文件加密问题。
我的目的是实现虚拟磁盘上文件的透明加解密。
刚开始做,想先作个实验,修改了 FileDiskThread 函数中文件读写的内容, 读的时候数据-1, 写的时候数据+1,但是发现根本不行,格式化就通不过。请问问题出在什么地方? 大家能否给我一个实现FileDisk加密问题的思路!万分感谢。 VOID FileDiskThread ( IN PVOID Context ) { PDEVICE_OBJECT device_object; PDEVICE_EXTENSION device_extension; PLIST_ENTRY request; PIRP irp; PIO_STACK_LOCATION io_stack; PUCHAR system_buffer; PUCHAR buffer; PUCHAR wBuf; int i = 0; ASSERT(Context != NULL); device_object = (PDEVICE_OBJECT) Context; device_extension = (PDEVICE_EXTENSION) device_object->DeviceExtension; KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY); for (;;) { KeWaitForSingleObject( &device_extension->request_event, Executive, KernelMode, FALSE, NULL ); if (device_extension->terminate_thread) { PsTerminateSystemThread(STATUS_SUCCESS); } while (request = ExInterlockedRemoveHeadList( &device_extension->list_head, &device_extension->list_lock )) { irp = CONTAINING_RECORD(request, IRP, Tail.Overlay.ListEntry); io_stack = IoGetCurrentIrpStackLocation(irp); switch (io_stack->MajorFunction) { case IRP_MJ_READ: system_buffer = (PUCHAR) MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority); if (system_buffer == NULL) { irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; irp->IoStatus.Information = 0; break; } buffer = (PUCHAR) ExAllocatePool(PagedPool, io_stack->Parameters.Read.Length); if (buffer == NULL) { irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; irp->IoStatus.Information = 0; break; } ZwReadFile( device_extension->file_handle, NULL, NULL, NULL, &irp->IoStatus, buffer, io_stack->Parameters.Read.Length, &io_stack->Parameters.Read.ByteOffset, NULL ); if ( (irp->Flags & IRP_PAGING_IO) || (irp->Flags & IRP_SYNCHRONOUS_PAGING_IO) ) { for(i = 0; i < io_stack->Parameters.Read.Length; i ++) { buffer -= 1; } } RtlCopyMemory(system_buffer, buffer, io_stack->Parameters.Read.Length); ExFreePool(buffer); break; case IRP_MJ_WRITE: if ((io_stack->Parameters.Write.ByteOffset.QuadPart + io_stack->Parameters.Write.Length) > device_extension->file_size.QuadPart) { irp->IoStatus.Status = STATUS_INVALID_PARAMETER; irp->IoStatus.Information = 0; } wBuf = (PUCHAR)MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority); if ( (irp->Flags & IRP_PAGING_IO) || (irp->Flags & IRP_SYNCHRONOUS_PAGING_IO) ) { for(i = 0; i < io_stack->Parameters.Write.Length; i ++) { wBuf += 1; } } ZwWriteFile( device_extension->file_handle, NULL, NULL, NULL, &irp->IoStatus, wBuf, io_stack->Parameters.Write.Length, &io_stack->Parameters.Write.ByteOffset, NULL ); break; case IRP_MJ_DEVICE_CONTROL: switch (io_stack->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_FILE_DISK_OPEN_FILE: SeImpersonateClient(device_extension->security_client_context, NULL); irp->IoStatus.Status = FileDiskOpenFile(device_object, irp); PsRevertToSelf(); break; case IOCTL_FILE_DISK_CLOSE_FILE: irp->IoStatus.Status = FileDiskCloseFile(device_object, irp); break; default: irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR; } break; default: irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR; } IoCompleteRequest( irp, (CCHAR) (NT_SUCCESS(irp->IoStatus.Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT) ); } } } |
|
沙发#
发布于:2007-07-12 17:12
没细看代码,不过要注意写的时候保证不改变原来缓存里的内容,就是说应该自己分配一段新内存来存放要写的数据,在这段内存上进行加密操作,然后写到磁盘,最后释放这段内存。
|
|
板凳#
发布于:2011-04-22 21:23
支持,这样可以实现!!
|
|