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

    ReactOS里面给的源码

    真是碉堡了

     1 NTSTATUS NTAPI RtlpWin32NTNameToNtPathName_U    (    IN PUNICODE_STRING     DosPath,
     2                                                     OUT PUNICODE_STRING     NtPath,
     3                                                     OUT PCWSTR *     PartName,
     4                                                     OUT PRTL_RELATIVE_NAME_U     RelativeName )    
     5 {
     6     ULONG DosLength;
     7     PWSTR NewBuffer, p;
     8 
     9     /* Validate the input */
    10     if (!DosPath) return STATUS_OBJECT_NAME_INVALID;
    11 
    12     /* Validate the DOS length */
    13     DosLength = DosPath->Length;
    14     if (DosLength >= UNICODE_STRING_MAX_BYTES) return STATUS_NAME_TOO_LONG;
    15 
    16     /* Make space for the new path */
    17     NewBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
    18                                 0,
    19                                 DosLength + sizeof(UNICODE_NULL));
    20     if (!NewBuffer) return STATUS_NO_MEMORY;
    21 
    22     /* Copy the prefix, and then the rest of the DOS path, and NULL-terminate */
    23     RtlCopyMemory(NewBuffer, RtlpDosDevicesPrefix.Buffer, RtlpDosDevicesPrefix.Length);
    24     RtlCopyMemory((PCHAR)NewBuffer + RtlpDosDevicesPrefix.Length,
    25                   DosPath->Buffer + RtlpDosDevicesPrefix.Length / sizeof(WCHAR),
    26                   DosPath->Length - RtlpDosDevicesPrefix.Length);
    27     NewBuffer[DosLength / sizeof(WCHAR)] = UNICODE_NULL;
    28 
    29     /* Did the caller send a relative name? */
    30     if (RelativeName)
    31     {
    32         /* Zero initialize it */
    33         RtlInitEmptyUnicodeString(&RelativeName->RelativeName, NULL, 0);
    34         RelativeName->ContainingDirectory = NULL;
    35         RelativeName->CurDirRef = 0;
    36     }
    37 
    38     /* Did the caller request a partial name? */
    39     if (PartName)
    40     {
    41         /* Loop from the back until we find a path separator */
    42         p = &NewBuffer[(DosLength - 1) / sizeof (WCHAR)];
    43         while (p > NewBuffer) if (*p-- == '\\') break;
    44 
    45         /* Was one found? */
    46         if (p > NewBuffer)
    47         {
    48             /* Move past it -- anything left? */
    49             p++;
    50             if (!*p)
    51             {
    52                 /* The path ends with a path separator, no part name */
    53                 *PartName = NULL;
    54             }
    55             else
    56             {
    57                 /* What follows the path separator is the part name */
    58                 *PartName = p;
    59             }
    60         }
    61     }
    62 
    63     /* Build the final NT path string */
    64     NtPath->Length = (USHORT)DosLength;
    65     NtPath->Buffer = NewBuffer;
    66     NtPath->MaximumLength = (USHORT)DosLength + sizeof(UNICODE_NULL);
    67     return STATUS_SUCCESS;
    68 }
  • 相关阅读:
    B.Icebound and Sequence
    Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS
    Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
    Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers
    Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number
    Codeforces Round #561 (Div. 2) C. A Tale of Two Lands
    Codeforces Round #561 (Div. 2) B. All the Vowels Please
    Codeforces Round #561 (Div. 2) A. Silent Classroom
    HDU-2119-Matrix(最大匹配)
    读书的感想!
  • 原文地址:https://www.cnblogs.com/02xiaoma/p/2764909.html
Copyright © 2011-2022 走看看