user-0 提问: 请教如何安全的写入内存特定地址

回复:
user: user-1
content: 写入某地址，是基于逻辑关系。  所以，根本不存在任意地址的安全写入。

user: user-2
content: IsBadWritePtr IsBadReadPtr

user: user-3
content: 引用 3 楼 bios8086 的回复:楼上的好像是windows 的函数 要是我的不是windows 那？ 提醒：Linux是开源的。

user: user-4
content: 你意思想修改可执行文件？

user: user-5
content: 啥叫特定地址，内核没有提供给你的地址？ 在high level os中，直接访问地址是很危险的，你想读写特定地址就要很小心

user: user-3
content: 啥叫安全？

user: user-6
content: 引用 楼主 bios8086 的回复:	int* pMemory =(int *) 0x00400000; 	*pMemory = 2345;  这种不行。因为这个地址可能不能用。  假设我知道那段地址可用，比如0xffffffff-0x00401000 我知道这段可以 。 怎么写比较好 如果我不知道 那怎么用比较好呢？ 调用操作系统 先知道那段能读写？  我觉得是个原则问题吧，你自己申请的地址才能够写入，不说你自己申请的地址就不要写。虽然可以通过某些手段修改别的进程申请的地址

user: user-0
content: 楼上的好像是windows 的函数 要是我的不是windows 那？

user: user-3
content: WriteProcessMemory The WriteProcessMemory 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,  // handle to process whose memory is written to   LPVOID lpBaseAddress,                     // address to start writing to   LPVOID lpBuffer,  // pointer to buffer to write data to   DWORD nSize,      // number of bytes to write   LPDWORD lpNumberOfBytesWritten                      // actual number of bytes written );   Parameters hProcess  Handle to the process whose memory is to be modified. The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process.  lpBaseAddress  Pointer to the base address in the specified process to be written to. Before any 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 this is the case, the function proceeds; otherwise, the function fails.  lpBuffer  Pointer to the buffer that supplies data to be written into the address space of the specified process.  nSize  Specifies the requested number of bytes to write into the specified process.  lpNumberOfBytesWritten  Pointer to the actual number of bytes transferred into the specified process. This parameter is optional. If lpNumberOfBytesWritten is NULL, the parameter is ignored.  Return Values If the function succeeds, the return value is nonzero.  If the function fails, the return value is zero. To get extended error information, call GetLastError. The function will fail if the requested write operation crosses into an area of the process that is inaccessible.   Remarks WriteProcessMemory copies the data from the specified buffer in the current process to the address range of the specified process. Any process that has a handle with PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process to be written to can call the function. 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 as noted previously.   Windows CE: The hProcess parameter is the handle returned from the OpenProcess function that provided full access to the process.  QuickInfo   Windows NT: Requires version 3.1 or later.   Windows: Requires Windows 95 or later.   Windows CE: Unsupported.   Header: Declared in winbase.h.   Import Library: Use kernel32.lib.  See Also Debugging Overview, Debugging Functions, ReadProcessMemory, WriteProcessMemoryVlm

user: user-3
content: 其实电脑开机后物理内存的每个字节都是可读写的，从来不会因为所谓的new、delete或malloc、free而被创建、销毁。区别仅在于操作系统内存管理模块在你读写时是否能发现并是否采取相应动作而已。操作系统管理内存的粒度不是字节而是页，一页通常为4KB。  VMMap 是进程虚拟和物理内存分析实用工具。http://technet.microsoft.com/zh-cn/sysinternals/dd535533  推荐使用WinHex软件查看或者改写（后果自负）硬盘或文件或内存中的原始字节内容。