-
-
[求助]关于内核层与用户层的共享内存问题
-
发表于: 2023-6-11 16:48 5374
-
我在用户层创建一个文件映像,名为DataMap,在内核中我需要填什么名字,才能使ZwOpenSection成功?
下面是尝试更改驱动中的usMappingName(都未成功):
1、L"DataMap"
2、L"\\BaseNamedObjects\\DataMap"
下面是发生错误的代码:
用户层
1 2 3 4 5 6 7 8 9 10 11 | HANDLE hRecvMap = NULL; LPVOID lpData = NULL; hRecvMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0 , 1000 , L "DataMap" ); printf( "%p\n" , hRecvMap); / / 打印模块地址的内容 lpData = (LPVOID)MapViewOfFile(hRecvMap, FILE_MAP_READ, 0 , 0 , 0 ); printf( "%p\n" , lpData); / / 打印模块地址的内容 |
内核层
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | UNICODE_STRING usMappingName; RtlInitUnicodeString(&usMappingName, L "DataMap" ); / / 打开命名内存对象 OBJECT_ATTRIBUTES objectAttributes = { 0 }; InitializeObjectAttributes(&objectAttributes, &usMappingName, OBJ_CASE_INSENSITIVE, NULL, NULL); HANDLE hMapping; NTSTATUS status = ZwOpenSection(&hMapping, SECTION_MAP_READ | SECTION_MAP_WRITE, &objectAttributes); if (!NT_SUCCESS(status)) { KdPrint(( "Failed to open section. Status: 0x%X\n" , status)); return status; } / / 映射内存对象 PVOID pMappedMemory; SIZE_T viewSize = 0 ; LARGE_INTEGER offset = { 0 }; status = ZwMapViewOfSection(hMapping, ZwCurrentProcess(), &pMappedMemory, 0 , 0 , &offset, &viewSize, ViewUnmap, 0 , PAGE_READWRITE); if (!NT_SUCCESS(status)) { KdPrint(( "Failed to map view of section. Status: 0x%X\n" , status)); ZwClose(hMapping); return status; } / / 在这里可以通过 pMappedMemory 操作内存对象 / / 解除映射和关闭内存对象句柄 ZwUnmapViewOfSection(ZwCurrentProcess(), pMappedMemory); ZwClose(hMapping); |
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
最后于 2023-6-11 16:50
被黑嘿黑编辑
,原因: 又有点小错误
赞赏
看原图
赞赏
雪币:
留言: