能力值:
( LV2,RANK:10 )
|
-
-
2 楼
是不是放错板块呢?还是都休息去了?
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
附上自己写的代码
首先是普通文件的dos转nt
HANDLE keyhandle
=CreateFile(L"C:\\MyServiceLog.txt",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL,NULL);
NTSTATUS Status = NtQueryObject((HANDLE)keyhandle,ObjectNameInformation,cInfoBuffer,0,&Size);
if(Size > 0)
{
Status = NtQueryObject((HANDLE)keyhandle,ObjectNameInformation,cInfoBuffer,Size,&Size);
if(NT_SUCCESS(Status))
{
pNameInfo = (POBJECT_NAME_INFORMATION)cInfoBuffer;
wprintf(L"%s\r\n",pNameInfo->Name.Buffer);
}
}
然后就是想打开打开各分区根目录,用上面的方法获取NT路径
OBJECT_ATTRIBUTES obj;
UNICODE_STRING string;
IO_STATUS_BLOCK IoStatusBlock;
RtlInitUnicodeString(&string, L"\\\\.\\C\\MyService");
//string.Length = wcslen(L"\\\\.\\C:");
//string.MaximumLength = wcslen(L"\\\\.\\C:") + 1;
//string.Buffer = (PWCH)malloc(sizeof(WCHAR)*string.Length);
InitializeObjectAttributes(&obj,&string, OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL);
//NtOpenFile(&keyhandle,DIRECTORY_ALL_ACCESS,&obj,&IoStatusBlock,NULL,NULL);
//NtCreateFile(&keyhandle,FILE_TRAVERSE |FILE_LIST_DIRECTORY, &obj, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0,FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT,NULL, 0);
(以上两函数句柄返回都是0)
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
再给一段RtlNtPathNameToDosPathName的代码
HMODULE hNTDLL = LoadLibrary(L"ntdll.dll");
if(hNTDLL == NULL) return ;
RtlNtPathNameToDosPathName = (_RtlNtPathNameToDosPathName)GetProcAddress(hNTDLL, "RtlNtPathNameToDosPathName");
if(RtlNtPathNameToDosPathName == NULL) return ;
//RtlGetProcessHeap = (_RtlGetProcessHeap)GetProcAddress(hNTDLL,"RtlGetProcessHeap");
//if(RtlGetProcessHeap == NULL) return ;
PWCHAR puBuffer = (PWCHAR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, pNameInfo->Name.Length * sizeof(PWCHAR));
PWCHAR _puBuffer = (PWCHAR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, pNameInfo->Name.Length * sizeof(PWCHAR));
if(puBuffer == NULL || _puBuffer == NULL) return ;
//RtlCopyMemory(puBuffer, pNameInfo->Name.Buffer, pNameInfo->Name.Length);
//RtlCopyMemory(_puBuffer, pNameInfo->Name.Buffer, pNameInfo->Name.Length);
RTL_UNICODE_STRING_BUFFER DosPath;
DosPath.String.Buffer = pNameInfo->Name.Buffer;
DosPath.String.Length = pNameInfo->Name.Length;
DosPath.String.MaximumLength = pNameInfo->Name.MaximumLength;
DosPath.ByteBuffer.Buffer = puBuffer;
DosPath.ByteBuffer.StaticBuffer = _puBuffer;
DosPath.ByteBuffer.Size = MAX_PATH;
DosPath.ByteBuffer.StaticSize = MAX_PATH;
DosPath.ByteBuffer.ReservedForAllocatedSize = 0;
DosPath.ByteBuffer.ReservedForIMalloc = NULL;
ULONG Disposition = 0; //(Disposition返回1)
Status = RtlNtPathNameToDosPathName(0, &DosPath, &Disposition, NULL);
if(NT_SUCCESS(Status))
{
wprintf(L"DosPath.String.Buffer = %s\n",DosPath.String.Buffer);
wprintf(L"DosPath.ByteBuffer.Buffer = %s\n",DosPath.ByteBuffer.Buffer);
wprintf(L"DosPath.ByteBuffer.StaticBuffer = %s\n", DosPath.ByteBuffer.StaticBuffer);
}
}
真心求各位大神指导。
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
上面RtlNtPathNameToDosPathName用到的结构体定义
typedef struct _RTL_BUFFER {
PWCHAR Buffer;
PWCHAR StaticBuffer;
SIZE_T Size;
SIZE_T StaticSize;
SIZE_T ReservedForAllocatedSize;
PVOID ReservedForIMalloc;
} RTL_BUFFER, *PRTL_BUFFER;
typedef struct _RTL_UNICODE_STRING_BUFFER {
UNICODE_STRING String;
RTL_BUFFER ByteBuffer;
WCHAR MinimumStaticBufferForTerminalNul[sizeof(WCHAR)];
} RTL_UNICODE_STRING_BUFFER, *PRTL_UNICODE_STRING_BUFFER;
typedef NTSTATUS
(NTAPI* _RtlNtPathNameToDosPathName)(
__in ULONG Flags,
__inout PRTL_UNICODE_STRING_BUFFER Path,
__out_opt PULONG Disposition,
__inout_opt PWSTR* FilePart
);
_RtlNtPathNameToDosPathName RtlNtPathNameToDosPathName;
|
能力值:
(RANK:10 )
|
-
-
6 楼
....
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
今天早上逆向了WDK里面的FilterGetDosName,发现
GetVolumeNameForVolumeMountPoint 和 GetVolumePathNamesForVolumeName
发现FilterGetDosName通过把NT路径拼接成 \\\\?\\Gobal\\Device\\HarddiskVolume3\\, 传入GetVolumeNameForVolumeMountPoint 获得Guid,得到的Guid再传入GetVolumePathNamesForVolumeName就获得对应的Dos路径。
问题虽然可以这样解决,但是NtCreateFile和NtOpenFile还是打不开分区目录,获取不了句柄!
最后windbg逆向知道NtOpenFile的第二个参数是0x00100080对应FILE_SEQUENTIAL_WRITE_ONCE|FILE_SUPPORTS_REPARSE_POINTS
目录句柄返回成功!
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
楼主研究精神值得赞
|
能力值:
( LV8,RANK:130 )
|
-
-
9 楼
楼主到底是在驱动里转换还是在应用层转换?
之前写的一段,供参考.
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
[QUOTE=xSpy;1302099]楼主到底是在驱动里转换还是在应用层转换?
之前写的一段,供参考.
[/QUOTE]
其实我也不知道我自己写的算是r3 or r0 纯粹是不懂研究研究,多谢知识分享
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
MARK,学习了。也学习楼主的钻研精神。
|