码迷,mamicode.com
首页 > 其他好文 > 详细

ring0 DOS路径转NT路径

时间:2015-07-31 21:39:38      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

xxx

NTSTATUS NTAPI RtlpWin32NTNameToNtPathName_U    (    IN PUNICODE_STRING     DosPath,
                                                    OUT PUNICODE_STRING     NtPath,
                                                    OUT PCWSTR *     PartName,
                                                    OUT PRTL_RELATIVE_NAME_U     RelativeName )    
{
    ULONG DosLength;
    PWSTR NewBuffer, p;

    /* Validate the input */
    if (!DosPath) return STATUS_OBJECT_NAME_INVALID;

    /* Validate the DOS length */
    DosLength = DosPath->Length;
    if (DosLength >= UNICODE_STRING_MAX_BYTES) return STATUS_NAME_TOO_LONG;

    /* Make space for the new path */
    NewBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
                                0,
                                DosLength + sizeof(UNICODE_NULL));
    if (!NewBuffer) return STATUS_NO_MEMORY;

    /* Copy the prefix, and then the rest of the DOS path, and NULL-terminate */
    RtlCopyMemory(NewBuffer, RtlpDosDevicesPrefix.Buffer, RtlpDosDevicesPrefix.Length);
    RtlCopyMemory((PCHAR)NewBuffer + RtlpDosDevicesPrefix.Length,
                  DosPath->Buffer + RtlpDosDevicesPrefix.Length / sizeof(WCHAR),
                  DosPath->Length - RtlpDosDevicesPrefix.Length);
    NewBuffer[DosLength / sizeof(WCHAR)] = UNICODE_NULL;

    /* Did the caller send a relative name? */
    if (RelativeName)
    {
        /* Zero initialize it */
        RtlInitEmptyUnicodeString(&RelativeName->RelativeName, NULL, 0);
        RelativeName->ContainingDirectory = NULL;
        RelativeName->CurDirRef = 0;
    }

    /* Did the caller request a partial name? */
    if (PartName)
    {
        /* Loop from the back until we find a path separator */
        p = &NewBuffer[(DosLength - 1) / sizeof (WCHAR)];
        while (p > NewBuffer) if (*p-- == \\) break;

        /* Was one found? */
        if (p > NewBuffer)
        {
            /* Move past it -- anything left? */
            p++;
            if (!*p)
            {
                /* The path ends with a path separator, no part name */
                *PartName = NULL;
            }
            else
            {
                /* What follows the path separator is the part name */
                *PartName = p;
            }
        }
    }

    /* Build the final NT path string */
    NtPath->Length = (USHORT)DosLength;
    NtPath->Buffer = NewBuffer;
    NtPath->MaximumLength = (USHORT)DosLength + sizeof(UNICODE_NULL);
    return STATUS_SUCCESS;
}

 

ring0 DOS路径转NT路径

标签:

原文地址:http://www.cnblogs.com/Lthis/p/4693118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!