Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTFSD

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

Redirect File - IO_REPARSE and On the fly decription

i014ni014n Member Posts: 1

Hello guys!
I want to develop a driver in order to decrypt a specific file on the fly. I looked at Microsoft examples SwapBuffers /, but I dind't understand too much for creating a simple example.
So, I am now trying to "simulate" that features, more exactly I thought that I can redirect on i access the encrypted file to a temporary file which contains plaintext data. I know this is not the best method, but I hope it works. I am new to windows driver and I am intending to use this driver to build an application for my bachelor degree.
I tried to implement this "redirect driver". This is a code of PreRead operation of IRP_MJ_READ:

FLT_PREOP_CALLBACK_STATUS RedirectPreOperation(
Inout PFLT_CALLBACK_DATA Data,
In PCFLT_RELATED_OBJECTS FltObjects,
Flt_CompletionContext_Outptr PVOID* CompletionContext)
{
NTSTATUS status;

UNREFERENCED_PARAMETER(FltObjects);
UNREFERENCED_PARAMETER(CompletionContext);
WCHAR oldFile[1024] = { 0 };


PFLT_FILE_NAME_INFORMATION FileInfo;
UNICODE_STRING redirectTarget;
status = FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT | FLT_FILE_NAME_DO_NOT_CACHE, &FileInfo);

if (NT_SUCCESS(status)) {
    status = FltParseFileNameInformation(FileInfo);
    if (NT_SUCCESS(status)) {

        RtlCopyMemory(oldFile, FileInfo->Name.Buffer, FileInfo->Name.MaximumLength);

        if (wcsstr(oldFile, L"write.txt") != NULL) {
            RtlInitUnicodeString(&redirectTarget, L"\\DosDevices\\C:\\Users\\ionut\\OneDrive\\Desktop\\2.txt");

            status = IoReplaceFileObjectName(Data->Iopb->TargetFileObject, redirectTarget.Buffer, redirectTarget.Length);

            if (NT_SUCCESS(status)) {
                Data->IoStatus.Information = IO_REPARSE;
                Data->IoStatus.Status = STATUS_REPARSE;
                Data->Iopb->TargetFileObject->RelatedFileObject = NULL;


                FltSetCallbackDataDirty(Data);

                DbgPrintEx(0, 0, "Rediect now \n");
            }



            return FLT_PREOP_COMPLETE;
        }
    }
    FltReleaseFileNameInformation(FileInfo);
}
return FLT_PREOP_SUCCESS_NO_CALLBACK;

}
I don't know why this is happening.
The problem is after the i open the file "write.text" it redirects me to the "redirectTarget", but its content was deleted and filled up with some garbage informations:
https://ibb.co/Fnf14gD
I look up at https://docs.microsoft.com/en-us/samples/microsoft/windows-driver-samples/simrep-file-system-minifilter-driver/, but i couldn't build this sample.
My main goal is to develop a decryption/encryption driver on the fly, so if anyone can help me understanding developing such a driver, i will be very grateful.
Thank you all!

Comments

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 434

    Redirect file name during a read won't work.
    Only in pre-create. It would work in post-create as well, but that opens a lot of cases that cannot be rolled back.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Developing Minifilters 24 May 2021 Live, Online
Writing WDF Drivers 14 June 2021 Live, Online
Internals & Software Drivers 27 September 2021 Live, Online
Kernel Debugging TBD 2021 Live, Online