- /*Code By Pnig0s1992*/
- #include <Windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #define MEM_BLOCK_SIZE 32
- BOOL ShowMemContent(LPVOID lpMem,SIZE_T dwSize);
- int main(void){
- HANDLE hHeap = GetProcessHeap();
- LPVOID lpSrc;
- LPVOID lpDis;
- if(hHeap == NULL){
- printf("获取当前进程中的堆错误:%d\n",GetLastError());
- return 1;
- }
- lpSrc = HeapAlloc(hHeap,0,MEM_BLOCK_SIZE);
- lpDis = HeapAlloc(hHeap,0,MEM_BLOCK_SIZE);
- printf("未清零的内存:\n");
- ShowMemContent(lpSrc,MEM_BLOCK_SIZE);
- ShowMemContent(lpDis,MEM_BLOCK_SIZE);
- ZeroMemory(lpSrc,MEM_BLOCK_SIZE);
- ZeroMemory(lpDis,MEM_BLOCK_SIZE);
- printf("清零后的内存:\n");
- ShowMemContent(lpSrc,MEM_BLOCK_SIZE);
- ShowMemContent(lpDis,MEM_BLOCK_SIZE);
- FillMemory(lpSrc,MEM_BLOCK_SIZE,0xBB);
- FillMemory(lpSrc,MEM_BLOCK_SIZE/2,0xAA);
- CopyMemory(lpDis,lpSrc,MEM_BLOCK_SIZE);
- printf("填充复制后的内存:\n");
- ShowMemContent(lpDis,MEM_BLOCK_SIZE);
- system("pause");
- return 0;
- }
- BOOL ShowMemContent(LPVOID lpMem,SIZE_T dwSize){
- BYTE lpShow[MEM_BLOCK_SIZE];
- INT i=0;
- if(dwSize>MEM_BLOCK_SIZE){
- printf("over flow.");
- return FALSE;
- }
- CopyMemory(lpShow,lpMem,MEM_BLOCK_SIZE);
- for(i=0;i<dwSize;i++){
- printf("%.2X",lpShow[i]);
- if(!((i+1)%16)){
- printf("\n");
- }
- }
- printf("\n");
- return TRUE;
- }
转载于:https://blog.51cto.com/pnig0s1992/626039