Loading... ## 堆的管理 | API | 说明 | | - | - | | HeapCreate | 在进程中创建一个堆,返回一个堆句柄 | | GetProcessHeap | 获取进程中的一个堆,返回一个句柄 | | GetProcessHeaps | 获取进程中所有堆,包括对的数量和各个堆的句柄 | | HeapAlloc | 从指定对上分配块 | | HeapReAlloc | 重新分配内存,改变已经分配好的堆内存大小 | | GetStstemInfo | 获取系统信息 | | HeapFree | 释放HeapAlloc和HeapReAlloc申请的内存 | | HeapSize | 获取指定堆大小 | | HeapDestory | 销毁由HeapCreate创建的堆 | | CreateToolhelp32Snapshot | 可以分别创建进程,线程,进程模块,进程堆的快照 | | Heap32First | 用来首次调用,获取第一个堆对象的信息 | | Heap32Next | 以后的调用由它来完成,不断获取堆对象信息 | ## 虚拟内存 AMD Intel 支持 [微软页安全属性表] https://docs.microsoft.com/en-us/windows/win32/memory/memory-protection-constants ### 虚拟内存管理 | 作用 | 函数名 | 说明 | | - | - | - | | 分配 | VirtualAlloc | 分配或者预定一块虚拟内存 | | | VirtualAllocEx | 在其他进城费配或者预定一块虚拟内存 | | 释放 | virtualFree | 释放虚拟内存 | | | virtualFreeEx | 释放其他进程内存 | | 锁定与解锁 | VirtualLock | 锁定内存,不能交换硬盘 | | | VirtualUnlock | 内存解锁 | | 修改保护属性 | VirtualProtect | 修改一块内存的属性 | | | VirtualProtectEX | 修改其他进程属性 | | 读写其他进程内存 | ReadProcessMemory | 读取远程进程内存属性 | | | WriteProcessMemory | 将数据写入远程进程内存 | | 查询内存状态 | VirtualQuery | 查看内存状态 | | | VirtualQueryEx | 查询其他进程内存信息 | | | | | | | | | | 值 | 含义 | | - | - | | MEM_COMMIT | 直接分配内存并将数初始化为0 | | MEM_RESERVE | 保留范围 | | | | 三种状态 | 状态 | 说明 | | - | - | | 空闲的 | 进程不能访问这种页面(内存页)还没有被分配 | | 保留的 | 这个页面已经被分配了,但是还位于物理内存映射,因此不能访问 | | 提交的 | 内存已经被分配了,并且也与物理内存映射,进程已经可以访问这里 | MEM_RELEASE 释放内存 设置为空闲状态 MEM_FREE MEM_DECOMMIT 保留状态 ### 虚拟内存的安全属性> VirtualProtect修改 | 属性 | 描述 | | - | - | | PAGE_EXECUTE | 可执行 | | PAGE_EXECUTE_READ | 可读可执行 | | PAGE_EXECUTE_READWRITE | 可读可写 | | PAGE_EXECUTE_WRITECOPY | 可执行,写时复制 | | PAGE_NOACCESS | 不可访问 | | PAGE_READONLY | 只读 | | PAGE_READWRITE | 可读可写 | | PAGE_WRITECOPY | 写时复制 | | | | ## 内存映射 Mapping 文件内容映射到进程虚拟内存中 映射成功文件用视图(view)引用这段内存,然后操作 优势: * 文件操作简单(直接在内存中操作,原文件操作 是从 文件读取内存 ,保存还是要写入文件,绑定后直接修改) * 不同进程中共享数据 | API | 详细 | | - | - | | private | 进程私有内存,不被其他进程所共享,一般为堆,栈 | | mapped | 从别的进程内存映射进来 | | image | 从程序的PE映像而来,一般是映像的区段 | | API | 说明 | | - | - | | GetSystemInfo | 获取系统信息,用于确定分配粒度 | | CreateFileMapping | 创建一个mapping对象 | | OpenFIleMapping | 打开已命名的mapping对象(可跨进程) | | UnmapViewOfFile | 取消文件映射 | | MapViewOfFile | 经Mapping对象的文件映射到内存 | | FlushViewOfFile | 将映射的内存写回硬盘中 | ## 注入与HOOK | Openprocess | | | - | - | | virtualAllocEx | | | WriteProcessMemory | | | WaitforsingleObject | | | CreateThread | | | loadlibrary | | | GetModuleHandle() ;//获取句柄 | | | | | | | | ## 堆的管理 | API | 说明 | | - | - | | HeapCreate | 在进程中创建一个堆,返回一个堆句柄 | | GetProcessHeap | 获取进程中的一个堆,返回一个句柄 | | GetProcessHeaps | 获取进程中所有堆,包括对的数量和各个堆的句柄 | | HeapAlloc | 从指定对上分配块 | | HeapReAlloc | 重新分配内存,改变已经分配好的堆内存大小 | | GetStstemInfo | 获取系统信息 | | HeapFree | 释放HeapAlloc和HeapReAlloc申请的内存 | | HeapSize | 获取指定堆大小 | | HeapDestory | 销毁由HeapCreate创建的堆 | | CreateToolhelp32Snapshot | 可以分别创建进程,线程,进程模块,进程堆的快照 | | Heap32First | 用来首次调用,获取第一个堆对象的信息 | | Heap32Next | 以后的调用由它来完成,不断获取堆对象信息 | 堆实例: ``` //创建一个堆使用 HANDLE hHelap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0); //在已经存在的堆上申请空间 //HANDLE hHelap = GetProcessHeap(); SYSTEM_INFO si;//系统信息 GetSystemInfo(&si); //在堆上分配3个页大小的内存 char *lpMem = (char*)HeapAlloc(hHelap, HEAP_ZERO_MEMORY, si.dwPageSize * 3); HeapFree(hHelap, HEAP_NO_SERIALIZE, lpMem); HeapDestroy(hHelap); ``` 最后修改:2021 年 03 月 01 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏