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;
    }
  • 相关阅读:
    教准备租房的同学如何避开坑!
    mvc3中controler和view之间的数据传递
    WebMail发送邮件
    mvc Razor视图语法与Aspx视图语法对比
    SQL Server sql分页查询
    WCF之一
    C++总结笔记(一)抽象、多态、继承
    Perl脚本学习经验(二)常用命令举例
    makefile学习经验(四)编译生成动态库文件(方式二)
    makefile学习经验(三)编译生成动态库文件(方式一)
  • 原文地址:https://www.cnblogs.com/Lthis/p/4693118.html
Copyright © 2011-2022 走看看