<code id="m8pbv"><strong id="m8pbv"></strong></code>
    <meter id="m8pbv"><strong id="m8pbv"></strong></meter>
  1. <code id="m8pbv"></code>
    <big id="m8pbv"></big>

  2. <output id="m8pbv"><sup id="m8pbv"></sup></output>

    <output id="m8pbv"></output>
        <big id="m8pbv"></big>
      1. <acronym id="m8pbv"></acronym>
        <var id="m8pbv"><strong id="m8pbv"><dl id="m8pbv"></dl></strong></var>

        <blockquote id="m8pbv"></blockquote>

        <blockquote id="m8pbv"><ruby id="m8pbv"></ruby></blockquote>
      2. <output id="m8pbv"><ruby id="m8pbv"><div id="m8pbv"></div></ruby></output>

      3. <blockquote id="m8pbv"><ruby id="m8pbv"><rp id="m8pbv"></rp></ruby></blockquote>

      4. <var id="m8pbv"></var>

      5. <td id="m8pbv"></td>

        <big id="m8pbv"><strong id="m8pbv"></strong></big>
        <meter id="m8pbv"></meter>

      6. <dfn id="m8pbv"></dfn>

      7. <thead id="m8pbv"><sup id="m8pbv"><rp id="m8pbv"></rp></sup></thead>
        International       English      China       
        加密軟件網DRM Plus視頻加密方案
        首頁 SmartPhone DRM加密方案列表 DRM演示中心 軟件定制服務 加密狗 國際軟件 聯系我們
         
        文件過濾加密的源代碼   返回

        //過濾讀

        NTSTATUS SfRead(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)

        {

        PIO_STACK_LOCATION irp_stack;

        BOOLEAN is_crypt;

        NTSTATUS status;

        PSFILTER_DEVICE_EXTENSION devExt;

        PAGED_CODE();

        ASSERT(!IS_MY_CONTROL_DEVICE_OBJECT( DeviceObject ));

        ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

        devExt = (PSFILTER_DEVICE_EXTENSION)(DeviceObject->DeviceExtension);

        if(Irp->Flags & (IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO))

        {

        irp_stack = IoGetCurrentIrpStackLocation( Irp );

        is_crypt = IsMyCryptFile(irp_stack->FileObject);

        if(is_crypt) //是我的加密文件

        {

        //設置完成例程

        IoCopyCurrentIrpStackLocationToNext( Irp );

        IoSetCompletionRoutine(Irp, SfReadCompletion, 0, TRUE, FALSE, FALSE);

        //調用原來的驅動

        return IoCallDriver(devExt->AttachedToDeviceObject, Irp);

        }

        }

        //非加密文件

        IoSkipCurrentIrpStackLocation(Irp);

        return IoCallDriver(devExt->AttachedToDeviceObject, Irp);

        }

        //讀操作的完成例程

        NTSTATUS SfReadCompletion(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp, __in PVOID Context)

        {

        ULONG length; //長度

        PUCHAR buffer; //緩沖區

        ULONG i;

        PIO_STACK_LOCATION irp_stack;

        irp_stack = IoGetCurrentIrpStackLocation( Irp );

        ShowUnicodeString(&(irp_stack->FileObject->FileName));

        DbgPrint("SfReadCompletion 讀文件解密");

        length = Irp->IoStatus.Information;

        buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);

        for(i = 0; i < length; i++)

        {

        buffer[i] = buffer[i] - 17; //解密

        }

        return STATUS_SUCCESS;

        }

        //過濾寫

        NTSTATUS SfWrite(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)

        {

        PIO_STACK_LOCATION irp_stack;

        BOOLEAN is_crypt;

        NTSTATUS status;

        PSFILTER_DEVICE_EXTENSION devExt;

        PAGED_CODE();

        ASSERT(!IS_MY_CONTROL_DEVICE_OBJECT( DeviceObject ));

        ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

        devExt = (PSFILTER_DEVICE_EXTENSION)(DeviceObject->DeviceExtension);

        if(Irp->Flags & (IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO))

        {

        irp_stack = IoGetCurrentIrpStackLocation( Irp );

        is_crypt = IsMyCryptFile(irp_stack->FileObject);

        if(is_crypt)

        {

        ULONG length; //長度

        PUCHAR buffer, buffer2; //原來緩沖區和加密后緩沖區

        ULONG i;

        PMDL new_mdl;

        length = irp_stack->Parameters.Write.Length;

        buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);

        //分配同樣大小的空間

        buffer2 = (PUCHAR)ExAllocatePool(NonPagedPool, length);

        if(buffer2 != 0)

        {

        ShowUnicodeString(&(irp_stack->FileObject->FileName));

        DbgPrint("SfWrite 寫文件加密");

        for(i = 0; i < length; i++)

        {

        buffer2[i] = buffer[i] + 17; //加密

        }

        //設置完成例程

        IoCopyCurrentIrpStackLocationToNext( Irp );

        IoSetCompletionRoutine(Irp, SfWriteCompletion, Irp->MdlAddress, TRUE, TRUE, TRUE);

        //替換成新的緩沖區

        new_mdl = IoAllocateMdl(buffer2, length, FALSE, TRUE, NULL);

        MmBuildMdlForNonPagedPool(new_mdl);

        Irp->MdlAddress = new_mdl;

        //調用原來的驅動

        return IoCallDriver(devExt->AttachedToDeviceObject, Irp);

        }

        else

        {

        ShowUnicodeString(&(irp_stack->FileObject->FileName));

        DbgPrint("SfWrite 寫不能分配內存");

        Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;

        Irp->IoStatus.Information = 0;

        IoCompleteRequest( Irp, IO_NO_INCREMENT );

        return Irp->IoStatus.Status;

        }

        }

        }

        //非加密文件

        IoSkipCurrentIrpStackLocation(Irp);

        return IoCallDriver(devExt->AttachedToDeviceObject, Irp);

        }

        //寫完成后就把分配的空間給刪除掉

        NTSTATUS SfWriteCompletion(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp, __in PVOID Context)

        {

        PMDL old_mdl, new_mdl;

        PUCHAR buffer2; //我分配的緩沖區

        PIO_STACK_LOCATION irp_stack;

        irp_stack = IoGetCurrentIrpStackLocation( Irp );

        ShowUnicodeString(&(irp_stack->FileObject->FileName));

        DbgPrint("完成: SfWriteCompletion");

        new_mdl = Irp->MdlAddress;

        old_mdl = (PMDL)Context;

        //還是指向原來的緩沖區

        Irp->MdlAddress = old_mdl;

        //刪除掉我分配的緩沖區

        buffer2 = MmGetSystemAddressForMdlSafe(new_mdl, NormalPagePriority);

        IoFreeMdl(new_mdl);

        ExFreePool(buffer2);

        return STATUS_SUCCESS;

        }

        //文件打開的時候調用

        NTSTATUS SfCreate(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)

        {

        NTSTATUS status;

        PSFILTER_DEVICE_EXTENSION devExt;

        PAGED_CODE();

        //如果不是過濾驅動設備就退出

        if (IS_MY_CONTROL_DEVICE_OBJECT(DeviceObject))

        {

        Irp->IoStatus.Status = STATUS_SUCCESS;

        Irp->IoStatus.Information = 0;

        IoCompleteRequest( Irp, IO_NO_INCREMENT );

        return STATUS_SUCCESS;

        }

        ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

        devExt = (PSFILTER_DEVICE_EXTENSION)(DeviceObject->DeviceExtension);

        //設置完成例程

        IoCopyCurrentIrpStackLocationToNext( Irp );

        IoSetCompletionRoutine(Irp, SfCreateCompletion, 0, TRUE, FALSE, FALSE);

        //調用原來的驅動

        return IoCallDriver( devExt->AttachedToDeviceObject, Irp );

        }

        //在打開文件的完成例程中記錄文件對象

        NTSTATUS SfCreateCompletion(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp, __in PVOID Context)

        {

        PIO_STACK_LOCATION irp_stack;

        PFILE_OBJECT file_obj;

        BOOLEAN is_crypt;

        irp_stack = IoGetCurrentIrpStackLocation(Irp);

        file_obj = irp_stack->FileObject;

        is_crypt = IsMyCryptFile(file_obj);

        if(is_crypt)

        {

        if(CcIsFileCached(file_obj))

        {

        ShowUnicodeString(&(file_obj->FileName));

        DbgPrint("打開時清除緩存 \n");

        CcPurgeCacheSection(file_obj->SectionObjectPointer, 0, 0, FALSE);

        }

        }

        return STATUS_SUCCESS;

        }

        //關閉文件后的清理工作

        NTSTATUS SfCleanupClose(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)

        {

        NTSTATUS status;

        PSFILTER_DEVICE_EXTENSION devExt;

        PIO_STACK_LOCATION irp_stack;

        PFILE_OBJECT file_obj;

        BOOLEAN is_crypt;

        PAGED_CODE();

        if (IS_MY_CONTROL_DEVICE_OBJECT(DeviceObject))

        {

        Irp->IoStatus.Status = STATUS_SUCCESS;

        Irp->IoStatus.Information = 0;

        IoCompleteRequest( Irp, IO_NO_INCREMENT );

        return STATUS_SUCCESS;

        }

        ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

        irp_stack = IoGetCurrentIrpStackLocation(Irp);

        file_obj = irp_stack->FileObject;

        is_crypt = IsMyCryptFile(file_obj);

        if(is_crypt)

        {

        if(CcIsFileCached(file_obj))

        {

        ShowUnicodeString(&(file_obj->FileName));

        DbgPrint("關閉時清除緩存 \n");

        CcPurgeCacheSection(file_obj->SectionObjectPointer, 0, 0, FALSE);

        }

        }

        IoSkipCurrentIrpStackLocation( Irp );

        devExt = (PSFILTER_DEVICE_EXTENSION)(DeviceObject->DeviceExtension);

        return IoCallDriver(devExt->AttachedToDeviceObject, Irp);

        }





        China-DRM.com All Rights Reserved.
        十一选五最简单技巧