2

我想开发一个基于FileDisk-17开源项目的加密虚拟磁盘。

这是我的解决方案:

IPR_MJ_READ,当ZwReadFile返回时,我使用函数' DecryptData'来解密读取的数据ZwReadFile

IPR_MJ_WRITE调用之前ZwWriteFile,我使用函数' EncryptData'加密将写入磁盘的数据。

我将EncryptData&DecryptData函数放在一个 C 源文件中。

问题是; 当我加载我的驱动程序时,我每次都得到错误代码,即使or函数ERROR_PROC_NOT_FOUND(127)中只有一行。EncryptDataDecryptData

谁能告诉我是什么原因造成的以及如何解决?

文件磁盘.c

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(bEncrypt)
            {
                cipher = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, irp->IoStatus.Information, 'TAG');
                if(cipher)
                {   
                    **DecryptData**(buffer, cipher, irp->IoStatus.Information);
                    RtlCopyMemory(system_buffer, cipher, irp->IoStatus.Information);
                    ExFreePool(cipher);
                }
                else
                {
                    irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
                    irp->IoStatus.Information = 0;
                    break;
                }
            }*
            else
            {
                RtlCopyMemory(system_buffer, buffer, io_stack->Parameters.Read.Length);
                ExFreePool(buffer);
            }

加密.c

    VOID EncryptData(PUCHAR src, PUCHAR dst, ULONG length)
{
    BF_LONG data[2];
    BF_KEY  key;

    BF_set_key(&key, pCryptoInformation->CryptoKey, sizeof(pCryptoInformation->CryptoKey));
}

VOID DecryptData(PUCHAR src, PUCHAR dst, ULONG length)
{
    BF_LONG data[2];
    BF_KEY  key;

    BF_set_key(&key, pCryptoInformation->CryptoKey, sizeof(pCryptoInformation->CryptoKey));
}
4

0 回答 0