阅读:1589回复:12
内核读文件的问题?
在内核中是否可以通过依次调用以下函数将一个文件读到内存中呢?
ZwCreateFile,ZwCreateSection,ZwMapViewOfSection。有做过的人给个答复啊! |
|
沙发#
发布于:2005-02-25 08:18
用 ZwCreateFile,ZwReadFile就可以了。缓冲区可以用非分页内存。 肯定可以的,都用过的,也可以用 ZwWriteFile 进行内核态写文件。
|
|
|
板凳#
发布于:2005-02-25 09:04
应该可以的....
|
|
|
地板#
发布于:2005-02-25 09:10
ZwMapViewOfSection类似应用程序中的内存映射文件,但是ZwMapViewOfSection可不能用于将文件映射到用户空间去!!
|
|
|
地下室#
发布于:2005-02-25 09:13
我不是要映射到用户空间中,我就是要在内核中将文件映射到内存中,然后在内核中处理。这样用可以么?
[编辑 - 2/25/05 by cicada] |
|
5楼#
发布于:2005-02-25 09:34
我不是要映射到用户空间中,我就是要在内核中将文件映射到内存中,然后在内核中处理。这样用可以么? 正好就是ZwMapViewOfSection这个东东 |
|
|
6楼#
发布于:2005-02-25 21:11
我用以下的代码想把读G盘的根目录下的ship.exe这个文件读到内核空间,可是为何ZwMapViewOfSection就失败啊?该如何写呢?
NewCreateFile() { IO_STATUS_BLOCK ioStatus; NTSTATUS ntStatus; HANDLE hFileHandle, hSectionHandle; OBJECT_ATTRIBUTES objectAttributes; UNICODE_STRING fileNameUnicodeString; WCHAR cFilename[] = L\"\\\\DosDevices\\\\G:\\\\ship.exe\"; PVOID pBaseAddress; SIZE_T ViewSize; RtlInitUnicodeString( &fileNameUnicodeString, cFilename ); InitializeObjectAttributes( &objectAttributes, &fileNameUnicodeString, OBJ_CASE_INSENSITIVE, NULL, NULL ); ntStatus = ZwCreateFile( &hFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS, &objectAttributes, &ioStatus, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT|FILE_NOT_DIRECTORY_FILE, NULL, 0 ); if( !NT_SUCCESS( ntStatus ) ) { DbgPrint((\"ZwCreateFile failed and status is 0X%x, %S.\\n\", ntStatus , fileNameUnicodeString.Buffer) ); return; } ntStatus = ZwCreateSection(&hSectionHandle, SECTION_ALL_ACCESS, NULL, NULL, PAGE_READWRITE,//PAGE_WRITECOPY, 0x8000000, //SEC_COMMIT, hFileHandle); if (!NT_SUCCESS( ntStatus )) { ZwClose(hFileHandle); DbgPrint(\"Can\'t create a section.n\"); return; } ntStatus = ZwMapViewOfSection(hSectionHandle, NtCurrentProcess(), //(HANDLE) -1, &pBaseAddress, 0, // zero bits 0, // commit size NULL, // section offset &ViewSize, 0, 0,//MEM_RESERVE,//MEM_COMMIT,//0x1000,//MEM_COMMIT, PAGE_READWRITE); if (!NT_SUCCESS( ntStatus )) { ZwClose(hFileHandle); ZwClose (hSectionHandle); DbgPrint(\"Can\'t Map a section.n\"); return; } ZwClose (hSectionHandle); ZwClose (hFileHandle); return; } [编辑 - 3/4/05 by cicada] [编辑 - 3/4/05 by cicada] |
|
7楼#
发布于:2005-03-04 08:03
我用以下的代码想把读G盘的根目录下的ship.exe这个文件读到内核空间,可是为何ZwMapViewOfSection就失败啊?该如何写呢?
NewCreateFile() { IO_STATUS_BLOCK ioStatus; NTSTATUS ntStatus; HANDLE hFileHandle, hSectionHandle; OBJECT_ATTRIBUTES objectAttributes; UNICODE_STRING fileNameUnicodeString; WCHAR cFilename[] = L\"\\\\DosDevices\\\\G:\\\\ship.exe\"; PVOID pBaseAddress; SIZE_T ViewSize; RtlInitUnicodeString( &fileNameUnicodeString, cFilename ); InitializeObjectAttributes( &objectAttributes, &fileNameUnicodeString, OBJ_CASE_INSENSITIVE, NULL, NULL ); ntStatus = ZwCreateFile( &hFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS, &objectAttributes, &ioStatus, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT|FILE_NOT_DIRECTORY_FILE, NULL, 0 ); if( !NT_SUCCESS( ntStatus ) ) { DbgPrint((\"ZwCreateFile failed and status is 0X%x, %S.\\n\", ntStatus , fileNameUnicodeString.Buffer) ); return; } ntStatus = ZwCreateSection(&hSectionHandle, SECTION_ALL_ACCESS, NULL, NULL, PAGE_READWRITE,//PAGE_WRITECOPY, 0x8000000, //SEC_COMMIT, hFileHandle); if (!NT_SUCCESS( ntStatus )) { ZwClose(hFileHandle); DbgPrint(\"Can\'t create a section.n\"); return; } ntStatus = ZwMapViewOfSection(hSectionHandle, NtCurrentProcess(), //(HANDLE) -1, &pBaseAddress, 0, // zero bits 0, // commit size NULL, // section offset &ViewSize, 0, 0,//MEM_RESERVE,//MEM_COMMIT,//0x1000,//MEM_COMMIT, PAGE_READWRITE); if (!NT_SUCCESS( ntStatus )) { ZwClose(hFileHandle); ZwClose (hSectionHandle); DbgPrint(\"Can\'t Map a section.n\"); return; } ZwClose (hSectionHandle); ZwClose (hFileHandle); return; } [编辑 - 3/4/05 by cicada] [编辑 - 3/4/05 by cicada] |
|
8楼#
发布于:2005-03-04 11:09
大侠们看看如何解决啊?
ZwMapViewOfSection返回的是0xc00000f1。 |
|
9楼#
发布于:2005-03-04 15:57
花两分钟看看啊!
|
|
10楼#
发布于:2005-03-04 16:11
为什么不用ZwOpenFile
|
|
|
11楼#
发布于:2005-03-04 16:55
WCHAR cFilename[] = L\"\\\\DosDevices\\\\G:\\\\ship.exe\";
改为 WCHAR cFilename[] = L\"\\\\??\\\\G:\\\\ship.exe\"; |
|
|
12楼#
发布于:2005-03-04 22:34
ZwCreateFile和ZwCreateSection都执行正确,ZwMapViewOfSection执行错误,返回的是0xc00000f1。为何?
|
|