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

Home NTFSD
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

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/


My Driver . UNC function work ! Question about STATUS_REPARSE ??

Gova_GimerGova_Gimer Member - All Emails Posts: 43
edited December 2019 in NTFSD

Hello ,
i developped a driver filesystem with mup function which work good ! BUT
it is correct code on SECTION STATUS_REPARSE ?
If no correct , then How do i work for good correct ?

Thank.

`

NTSTATUS drvdispatchmupdisk(PDEVICE_EXTENSION_MOTHER mu, PIRP Irp, PIO_STACK_LOCATION irps)
{
//PDEVICE_EXTENSION_MOTHER mu = (PDEVICE_EXTENSION_MOTHER)DeviceObject->DeviceExtension;
NTSTATUS ret = STATUS_INVALID_DEVICE_REQUEST;
if (irps->MajorFunction == IRP_MJ_CREATE)
{
fileObject = irps->FileObject;

    if (fileObject == NULL) {
        KdPrintfSure2(("[MUP]  fileObject == NULL\n"));
        ret = STATUS_INVALID_PARAMETER;
        goto GGGH;
    }
    pSIn = &(fileObject->FileName);

...
...
if (ISUNCREGISTERED(mu, source, &LEN, wchemin, &flagunc) == TRUE)
{
...
...
dest[0] = 0;

            {
                wcscat(dest, wchemin);
            }
            wcscat(dest, L"\\");
            if ((flagunc&FL_UNC_ADDPATHUNC) != FL_UNC_ADDPATHUNC)
                wcscat(dest, source + LEN);
            else
                wcscat(dest, source);
            KdPrintfSure2(("IRP_MJ_CREATE %ws devient %ws\n", source, dest));
            UNICODE_STRING SOut;
            SOut.MaximumLength = 4096;
            ret = SimRepAllocateUnicodeString(&SOut);
            if (ret == STATUS_SUCCESS)
            {
                SOut.Length = wcslen(dest) << 1;
                RtlCopyMemory(SOut.Buffer, dest, SOut.Length);
                NRedSwapUnicodeString(pSIn, &SOut);
                SimRepFreeUnicodeString(&SOut);
                KDPublic(("File %ws matched\n", source));
                ret = STATUS_REPARSE;
            }

...
...
}

VOID
NRedSwapUnicodeString(
__in __out PUNICODE_STRING p1,
__in __out PUNICODE_STRING p2
)
{
UNICODE_STRING tmp;

//PAGED_CODE();

tmp.Length = p1->Length;
tmp.MaximumLength = p1->MaximumLength;
tmp.Buffer = p1->Buffer;

p1->Length = p2->Length;
p1->MaximumLength = p2->MaximumLength;
p1->Buffer = p2->Buffer;

p2->Length = tmp.Length;
p2->MaximumLength = tmp.MaximumLength;
p2->Buffer = tmp.Buffer;

}

NTSTATUS
SimRepAllocateUnicodeString(
PUNICODE_STRING String
)
{

PAGED_CODE();

String->Buffer = (PWCH)
    ExAllocatePool(
        PagedPool,
        String->MaximumLength

    );

if (String->Buffer == NULL) {

    /*DDbgPrint("[SimRep]: Failed to allocate unicode string of size 0x%x\n",
    String->MaximumLength);
    */
    return STATUS_INSUFFICIENT_RESOURCES;
}

String->Length = 0;

return STATUS_SUCCESS;

}

VOID
SimRepFreeUnicodeString(
PUNICODE_STRING String
)
{
PAGED_CODE();

if (String->Buffer) {
    ExFreePool(String->Buffer);
    String->Buffer = NULL;
}

String->Length = String->MaximumLength = 0;
String->Buffer = NULL;

}

`

Comments

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,356

    You've provided a snippet of some random driver (that is actually a copy/paste of a sample driver) and asked if it works. Who knows? Have you tried it?

    I'm sorry, there is no way anyone can help you with whatever you're asking based on what you've provided. Also, please take the effort to fix the formatting.

    -scott
    OSR

  • Gova_GimerGova_Gimer Member - All Emails Posts: 43

    I copied some function since source code:
    https://github.com/kenjiuno/NRedir4Dokan/blob/master/sys/NRedir4Dokan.cpp

    It is code conforme about STATUS_REPARSE ??
    Else the source code that I modified work good.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,356

    If you're just asking about the mechanics of STATUS_REPARSE, sure, yes, you replace the name and then complete the IRP with STATUS_REPARSE. Note that you should use IoReplaceFileObjectName instead of touching the fields of the FILE_OBJECT directly.

    Now, whether or not your usage of STATUS_REPARSE is correct I have no idea. You need to test your code.

    -scott
    OSR

  • Gova_GimerGova_Gimer Member - All Emails Posts: 43

    IoReplaceFileObjectName is not implemented for Windows XP.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,356
    Right. Which is why the sample you used only uses the API on Windows 7 and later.

    We’ve previously discussed in the forum why this API exists. Search the archives.

    -scott
    OSR

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!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE