能力值:
( LV2,RANK:10 )
2 楼
ZwOpenSymbolicLinkObject
ZwQuerySymbolicLinkObject
用这两个
能力值:
( LV2,RANK:10 )
3 楼
NTSTATUS SfNtNameToDosName(PUNICODE_STRING NtName,PUNICODE_STRING DosName)
{
OBJECT_ATTRIBUTES attributes;
UNICODE_STRING driveLetterName, linkTarget;
HANDLE linkHandle=INVALID_HANDLE_VALUE;
WCHAR c;
linkTarget.Length = 0;
linkTarget.MaximumLength = 256;
linkTarget.Buffer = (USHORT*)malloc(linkTarget.MaximumLength);
RtlInitUnicodeString(&driveLetterName, L"\\??\\C:");
for (c = L'A'; c <= L'Z'; c++)
{
driveLetterName.Buffer[4] = c; ///在这一句报异常,错误号0xc0000005
InitializeObjectAttributes(&attributes, &driveLetterName, OBJ_CASE_INSENSITIVE, 0, NULL);
if (!NT_SUCCESS(ZwOpenSymbolicLinkObject(&linkHandle, GENERIC_READ, &attributes))) continue;
if (!NT_SUCCESS(ZwQuerySymbolicLinkObject(linkHandle, &linkTarget, NULL))) continue;
//KdPrint(("%wZ->%wZ\n", &driveLetterName, &linkTarget));
if (_wcsnicmp(NtName->Buffer, linkTarget.Buffer, linkTarget.Length>>1) == 0)
{
DosName->Length = 4 + NtName->Length - linkTarget.Length;
DosName->MaximumLength = DosName->Length + 2;
DosName->Buffer =(USHORT*)malloc(DosName->MaximumLength);
if (!DosName->Buffer) return STATUS_INSUFFICIENT_RESOURCES;
memcpy((PBYTE)DosName->Buffer + 4, (PBYTE)NtName->Buffer + linkTarget.Length, NtName->Length - linkTarget.Length);
DosName->Buffer[0] = c;
DosName->Buffer[1] = L':';
DosName->Buffer[DosName->Length>>1] = 0;
RtlFreeUnicodeString(&linkTarget);
return STATUS_SUCCESS;
}
}
RtlFreeUnicodeString(&linkTarget);
return STATUS_NOT_FOUND;
}
能力值:
( LV2,RANK:10 )
4 楼
本来已经能够显示设备符号路径了,我就是想转换到DOS路径名。是不是这个字符串初始化有问题 driveLetterName.Buffer[4] = c; ///在这一句报异常,错误号0xc0000005
能力值:
( LV2,RANK:10 )
5 楼
0xc0000005 拒绝访问。
你是否有管理员权限
能力值:
( LV2,RANK:10 )
6 楼
现在我也采取了一个折中的方案调整了代码
for (c = L'A'; c <= L'Z'; c++)
{
drivername[4] =c; ///本来在在这一句报异常,错误号0xc0000005,现在改为一般的宽字符,而在下句初始化,就没报错了,但在另外地方报错了,见下面;
RtlInitUnicodeString(&driveLetterName, drivername);
InitializeObjectAttributes(&attributes, &driveLetterName, OBJ_CASE_INSENSITIVE, 0, 0);
status=ZwOpenSymbolicLinkObject(&linkHandle, GENERIC_READ, &attributes);//报错,0xc0000005
// if (!NT_SUCCESS(ZwOpenSymbolicLinkObject(&linkHandle, FILE_ALL_ACCESS/*GENERIC_READ*/, &attributes)))
// continue;
if (!NT_SUCCESS(status))
{
return status ;
}
if (!NT_SUCCESS(ZwQuerySymbolicLinkObject(linkHandle, &linkTarget, NULL)))
continue;
能力值:
( LV2,RANK:10 )
7 楼
注意这个 RtlFreeUnicodeString 用于释放 RtlAnsiStringToUnicodeString。