gpt4 book ai didi

winapi - "\\?\C:"上的 RtlDosPathNameToNtPathName_U 返回无效路径

转载 作者:行者123 更新时间:2023-12-03 02:01:17 25 4
gpt4 key购买 nike

为什么当我在路径 \\?\C: 上调用 RtlDosPathNameToNtPathName_U 时,而不是返回

\??\C:

我回来了

\??\C:\฀\\?\C:

哪个明显不正确?

<小时/>

代码片段(D 中):

struct CurDir { UnicodeString DosPath; HANDLE Handle; }

extern (Windows) static bool RtlDosPathNameToNtPathName_U(
in const(wchar)* DosPathName, out UnicodeString NtPathName,
out const(wchar)* NtFileNamePart, out CurDir DirectoryInfo);

wchar[] toNtPath(const(wchar)[] path)
{
UnicodeString ntPath;
CurDir curDir;
const(wchar)* fileNamePart;
enforce(RtlDosPathNameToNtPathName_U(path.ptr, ntPath,
fileNamePart, curDir));
try
{ return ntPath.Buffer[0 .. ntPath.Length / ntPath.Buffer[0].sizeof].dup; }
finally { RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer); }
}

writeln(toNtPath(r"\\?\C:")); //Returns the weird string
<小时/>

更新:

我找到了问题所在——请参阅我的答案。

最佳答案

RtlDosPathNameToNtPathName_U给你正确的输出。你之所以在中间看到一个看起来很奇怪的字符,是因为 UNICODE_STRING s不需要必须以空终止(我相信您已经知道了)。文件名\??\C:\是完全有效的 native 格式文件名。我怀疑您真正想要的是在前面添加设备名称,而不是仅仅引用 GLOBAL??目录就像RtlDosPathNameToNtPathName_U已经完成了。

为此,只需调用 NtQuerySymbolicLinkObject\??\x: ,其中 x 是路径正在使用的驱动器号,并将结果添加到前面。如果是 UNC 路径,请在前面添加 \Device\Mup 。对于其他类型的路径(如果有),依此类推。

关于winapi - "\\?\C:"上的 RtlDosPathNameToNtPathName_U 返回无效路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5285585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com