meilimeimei
驱动牛犊
驱动牛犊
  • 注册日期2006-05-16
  • 最后登录2013-02-25
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望72点
  • 贡献值0点
  • 好评度50点
  • 原创分0分
  • 专家分0分
阅读:2108回复:4

DDK文档中的一个错误

楼主#
更多 发布于:2007-05-29 18:57
今天我用到一个函数 ZwFreeVirtualMemory 我看了一下DDK3790中的帮助文档
Installable File System Kit
ZwFreeVirtualMemory
ZwFreeVirtualMemory releases, decommits, or both, a region of pages within the virtual address space of a specified process.

NTSTATUS
  ZwFreeVirtualMemory(
    IN PHANDLE  ProcessHandle,
    IN OUT PVOID  *BaseAddress,
    IN OUT PULONG  RegionSize,
    IN ULONG  FreeType
    );
请注意第一个参数类型 是 PHANDLE  而不是HANDLE ,当时我就觉得有点怪,但是还是按文档的说法用,弄了一个小时都失败了 后来跟到此函数代码里面一看才发现居然微软的文档写错了 函数原形应该是
NTSTATUS ZwFreeVirtualMemory(HANDLE ProcessHandle,PVOID *BaseAddress,PULONG FreeSize,ULONG FreeType);

下面是IDA的结果

; NTSTATUS __stdcall ZwFreeVirtualMemory(HANDLE ProcessHandle,PVOID *BaseAddress,PULONG FreeSize,ULONG FreeType)
.text:00405D38                 public _ZwFreeVirtualMemory@16
.text:00405D38 _ZwFreeVirtualMemory@16 proc near       ; CODE XREF: NtTerminateThread(x,x)+141p
.text:00405D38                                         ; LsaFreeReturnBuffer(x)+19p ...
.text:00405D38
.text:00405D38 ProcessHandle   = dword ptr  4
.text:00405D38 BaseAddress     = dword ptr  8
.text:00405D38 FreeSize        = dword ptr  0Ch
.text:00405D38 FreeType        = dword ptr  10h
.text:00405D38
.text:00405D38                 mov     eax, 53h
.text:00405D3D                 lea     edx, [esp+ProcessHandle]
.text:00405D41                 pushf
.text:00405D42                 push    8
.text:00405D44                 call    _KiSystemService
.text:00405D49                 retn    10h
.text:00405D49 _ZwFreeVirtualMemory@16 endp ; sp = -8

/*************************************************/
PAGE:004918C7 ; NTSTATUS __stdcall NtFreeVirtualMemory(HANDLE ProcessHandle,PVOID *BaseAddress,PULONG FreeSize,ULONG FreeType)
PAGE:004918C7                 public _NtFreeVirtualMemory@16
PAGE:004918C7 _NtFreeVirtualMemory@16 proc near       ; DATA XREF: .text:0040B7F4o
………………………………
//比较进程句柄是不是当前进程句柄
PAGE:00491AF0 loc_491AF0:                             ; CODE XREF: NtFreeVirtualMemory(x,x,x,x)+88FCEj
PAGE:00491AF0                 cmp     [ebp+Handle], 0FFFFFFFFh
PAGE:00491AF4                 jnz     loc_51A89A

看样子文档也不一定正确啊
xaxiao
驱动小牛
驱动小牛
  • 注册日期2007-09-11
  • 最后登录2010-02-10
  • 粉丝1
  • 关注0
  • 积分1分
  • 威望199点
  • 贡献值0点
  • 好评度197点
  • 原创分2分
  • 专家分0分
沙发#
发布于:2008-04-04 13:46
^_^
WQXNETQIQI
驱动大牛
驱动大牛
  • 注册日期2006-06-12
  • 最后登录2010-10-26
  • 粉丝0
  • 关注0
  • 积分13分
  • 威望1076点
  • 贡献值0点
  • 好评度895点
  • 原创分1分
  • 专家分0分
板凳#
发布于:2007-05-30 16:18
ZwFreeVirtualMemory
ZwFreeVirtualMemory frees virtual memory in the user mode address range.
NTSYSAPI
NTSTATUS
NTAPI
ZwFreeVirtualMemory(
IN HANDLE ProcessHandle,
IN OUT PVOID *BaseAddress,
IN OUT PULONG FreeSize,
IN ULONG FreeType
);
Parameters
ProcessHandle
A handle of a process object, representing the process from which the virtual memory
should be freed.The handle must grant PROCESS_VM_OPERATION access.
BaseAddress
Points to a variable that specifies the base address of the virtual memory to be freed.
FreeSize
Points to a variable that specifies the size, in bytes, of the virtual memory to free and
receives the size of virtual memory actually freed. If FreeType is MEM_RELEASE, this
value must be zero.
FreeType
A set of flags that describes the type of de-allocation to be performed for the specified
region of pages.The permitted values are:
MEM_DECOMMIT Decommit but maintain reservation
MEM_RELEASE Decommit and free reservation
Return Value
Returns STATUS_SUCCESS or an error status, such as STATUS_UNABLE_TO_FREE_VM,
STATUS_UNABLE_TO_DELETE_SECTION, STATUS_FREE_VM_NOT_AT_BASE,
STATUS_MEMORY_NOT_ALLOCATED, or STATUS_PROCESS_IS_TERMINATING.
Related Win32 Functions
VirtualFree, VirtualFreeEx.
Remarks
VirtualFreeEx exposes almost all of the functionality of ZwFreeVirtualMemory.


看Native api Reference吧 :)
驱动开发者 呵呵
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
地板#
发布于:2007-05-30 13:17
帖出来:)
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
carwin
驱动牛犊
驱动牛犊
  • 注册日期2007-05-27
  • 最后登录2010-03-15
  • 粉丝0
  • 关注0
  • 积分304分
  • 威望71点
  • 贡献值0点
  • 好评度30点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2007-05-30 10:25
恩,还有几个地方也是HANDLE写成了PHANDLE,弄得我蓝屏好多次。
大家要注意啊!!!
游客

返回顶部