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 don't work with method 'PREPARSE_DATA_BUFFER'

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

Hello,
Then option '_shareconfig' is equal to 0 or 1 , it work good.
Why the method redirect by PREPARSE_DATA_BUFFER don't work ???

Thank.

PREPARSE_DATA_BUFFER PrepareBufferForRedirect(WCHAR *destmount, int mode)
{
PREPARSE_DATA_BUFFER Reparse=(PREPARSE_DATA_BUFFER)ExAllocatePoolWithTag(NonPagedPool, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
if (Reparse != NULL)
{
USHORT _len = wcslen(destmount);
USHORT len = (_len+1) << 1;
RtlZeroMemory(Reparse, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
Reparse->ReparseTag = mode;
//int len = wcslen(destmount);

    if (mode == IO_REPARSE_TAG_MOUNT_POINT)
    {
        Reparse->ReparseDataLength = 8+4 + len;//sizeof(L"\\??\\C:\\Documents and Settings");
        Reparse->MountPointReparseBuffer.SubstituteNameLength = len - sizeof(UNICODE_NULL);
        Reparse->MountPointReparseBuffer.PrintNameOffset = len;
        RtlCopyMemory(Reparse->MountPointReparseBuffer.PathBuffer, destmount, len);
    }       
    else
    if (mode== IO_REPARSE_TAG_SYMLINK)
    {
        Reparse->ReparseDataLength = 12 + 4 + len;
        Reparse->SymbolicLinkReparseBuffer.SubstituteNameLength = len - sizeof(UNICODE_NULL);
        Reparse->SymbolicLinkReparseBuffer.PrintNameOffset = len;
        RtlCopyMemory(Reparse->SymbolicLinkReparseBuffer.PathBuffer, destmount, len);
    }
    else
    {
        ExFreePool(Reparse);
        Reparse = NULL;

    }


}
return Reparse;

}

..
..
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)
{
    PFILE_OBJECT fileObject;
    fileObject = irps->FileObject;
    //get destination from fileObject
    WCHAR  dest[1024] = { 0 };
    ...
    GetRedirect(fileObject,dest,1023);
    ...
    ...
    //
    #ifndef WINXP
            if (_shareconfig1 == 1) //It works only on Windows 7,8,10
            {
                IoReplaceFileObjectName(fileObject, dest, wcslen(dest)<<1);
                ret = STATUS_REPARSE;
            }
            else

else

            _shareconfig1=0;

endif

            if (_shareconfig1 == 0) //Trust, it works !
            {
                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;
                }
            }
            else

//#else
{
///It don't work !
int vi;
PREPARSE_DATA_BUFFER Reparse = PrepareBufferForRedirect(dest, vi= _shareconfig1);
if (Reparse != NULL)
{
Irp->Tail.Overlay.AuxiliaryBuffer = (PCHAR)Reparse;
Irp->IoStatus.Information = vi;
ret = STATUS_REPARSE;
}
else
{
ret = STATUS_INSUFFICIENT_RESOURCES;
KDPublic(("Status failure PrepareBufferForRedirect\n"));
}
}
}
}

Comments

  • Gova_GimerGova_Gimer Member - All Emails Posts: 43
    edited December 2019

    Excuse me , but in this forum , i can't joint properly code !
    How do i put properly the code in this forum ?
    Thank.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,356
    Please stop posting random chunks of code and asking why/if it doesn’t work.

    File systems and file system filters are difficult on Windows and no one can help you in this way. You need to step way, way, WAY back and explain what you’re trying to accomplish. It seems as if you’re just trying to copy/paste a file system into existence and I promise you it will never work, it’s all just too complicated and all you’ll end up with is a broken mess.

    -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