WriteProcessMemory

王朝百科·作者佚名  2010-03-31  
宽屏版  字体:   |    |    |  超大  

EN:

This function writes memory in a specified process. The entire area to be written to must be accessible, or the operation fails.

BOOL WriteProcessMemory(

HANDLE hProcess,

LPVOID lpBaseAddress,

LPVOID lpBuffer,

DWORD nSize,

LPDWORD lpNumberOfBytesWritten

);

Parameters

hProcess

[in] Handle returned from the OpenProcess function that provided full access to the process.

lpBaseAddress

[in] Pointer to the base address in the specified process.

Before data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for write access. If so, the function proceeds; otherwise, the function fails.

lpBuffer

[in] Pointer to the buffer that supplies data to be written into the address space of the specified process.

nSize

[in] Specifies the requested number of bytes to write into the specified process.

lpNumberOfBytesWritten

[out] Pointer to the number of bytes transferred into the specified process.

This parameter is optional.

If lpNumberOfBytesWritten is NULL, the parameter is ignored.

Return Values

Nonzero indicates success.

Zero indicates failure.

To get extended error information, call GetLastError.

The function fails if the requested write operation crosses into an area of the process that is inaccessible.

Remarks

WriteProcessMemory copies data from the specified buffer in the current process to the address range of the specified process. The process whose address space is being written to is typically, but not necessarily, being debugged.

The entire area to be written to must be accessible. If it is not, the function fails.

Requirements

OS Versions: Windows CE 2.0 and later.

Header: Winbase.h.

Link Library: Nk.lib.

See Also

OpenProcess | ReadProcessMemory

---------------------------------------------------------------------------------------------

ch:

WriteProcessMemory

VB函数原型:

Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long

作用:写内存

说明:

hProcess , 进程的句柄

lpBaseAddress, 写入进程的位置(地址)

lpBuffer, 数据当前存放地址

nSize, 数据的长度

lpNumberOfBytesWritten,实际数据的长度

nSize以字节为单位,一个字节Byte等于8位

基本数据类型的长度

ShortInt 8位 = 1Byte

SmallInt 16位 = 2Byte

Integer 16位 = 2Byte

LongInt 32位 = 4Byte

Word 16位 = 2Byte

LongWord 32位 = 4Byte

Boolean 8位 = 1Byte

WordBool 16位 = 2Byte

LongBool 32位 = 4Byte

比如要写入Integer类型的数据,那么Integer长度2Byte

所以nSize = 2

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有