php内存映射,如何用ZwMapViewOfSection将Driver分配的内存映射到App空间?

保存

在DDK的例子Mapmem中,用ZwMapViewOfSection将物理地址映射到App空间,该函数能否将系统地址映射到App空间?

我尝试着做了一下,但返回invalid_view_size,好像length给的不对。各位大侠帮忙看看啊。

PVOID

GetUserAddressFromSystemAddress(IN PVOID iSystemAddress,///系统地址

IN ULONG iBufferLength  ///地址空间长度

)

{

UNICODE_STRING     systemMemoryUnicodeString;

OBJECT_ATTRIBUTES  objectAttributes;

HANDLE             systemMemoryHandle  = NULL;

PVOID              systemMemorySection = NULL;

NTSTATUS           ntStatus;

PVOID              virtualAddress;

ULONG length=iBufferLength;

LARGE_INTEGER lSystemAddress;

KIRQL irql=KeGetCurrentIrql();

RtlInitUnicodeString (&systemMemoryUnicodeString,

L\"\\\\Device\\\\SystemMemory\");

InitializeObjectAttributes(&objectAttributes,///OUT

&systemMemoryUnicodeString,  ///the ObjectName

OBJ_CASE_INSENSITIVE,  the Attributes

(HANDLE) NULL,

(PSECURITY_DESCRIPTOR) NULL);

ntStatus = ZwOpenSection(&systemMemoryHandle, //SectionHandle OUT

SECTION_ALL_ACCESS,///DesireAccess

&objectAttributes);///ObjectAttributes

if (!NT_SUCCESS(ntStatus))

{

return NULL;

}

ntStatus = ObReferenceObjectByHandle (systemMemoryHandle,//got by ZwOpenSection

SECTION_ALL_ACCESS,

(POBJECT_TYPE) NULL,

KernelMode,

&systemMemorySection,//OUT Pointer to the object bocy

(POBJECT_HANDLE_INFORMATION) NULL);

///OUT points to the struture receives the handle attributes

///and the granted access rights for the object

if (!NT_SUCCESS(ntStatus))

{

goto close_handle;

}

virtualAddress = NULL;

///存放Driver分配的系统地址

lSystemAddress.QuadPart=(LONGLONG)iSystemAddress;

// Map the section

ntStatus = ZwMapViewOfSection(systemMemoryHandle,

(HANDLE) -1,

&virtualAddress,

0L,///IN ZeroBits

length,

&lSystemAddress,

&length,

ViewShare,

0,

PAGE_READWRITE | PAGE_NOCACHE);

if (!NT_SUCCESS(ntStatus))

{

goto close_handle;

}

//

return virtualAddress;

close_handle:

ZwClose (systemMemoryHandle);

return NULL;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值