zoukankan      html  css  js  c++  java
  • ring0 DOS路径转NT路径

    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;
    }
  • 相关阅读:
    学习进度笔记
    博雅数据机器学习07
    学习进度笔记
    博雅数据机器学习06
    《一级架构师》阅读笔记
    学习进度笔记
    博雅数据机器学习05
    递归的概念
    CSS学习笔记3:选择器及优先级
    CSS学习笔记2:伪类
  • 原文地址:https://www.cnblogs.com/Lthis/p/4693118.html
Copyright © 2011-2022 走看看