- 实验环境:
- 操作系统: Windows 2000 Service Pack 4
- 集成开发环境: Microsoft Visual C++ 6.0 SP6
- 实验代码如下:
-
1 #include <windows.h> 2 #include <stdio.h> 3 4 int main(int argc, char **argv) 5 { 6 HLOCAL h1, h2, h3, h4, h5, h6; 7 HANDLE hp; 8 hp = HeapCreate(0, 0x1000, 0x10000); 9 10 // 为了方便显示堆的地址,这里把它打印出来 11 printf("Heap address: %p\n", hp); 12 13 // 为了避免程序监测出调试器而是使用调试堆管理策略 14 __asm int 3 15 16 h1 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 3); 17 printf("h1: %p\n", h1); 18 h2 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 5); 19 printf("h2: %p\n", h2); 20 h3 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 6); 21 printf("h3: %p\n", h3); 22 h4 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 8); 23 printf("h4: %p\n", h4); 24 h5 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 19); 25 printf("h5: %p\n", h5); 26 h6 = HeapAlloc(hp, HEAP_ZERO_MEMORY, 24); 27 printf("h6: %p\n", h6); 28 29 HeapFree(hp,0, h1); 30 HeapFree(hp,0, h3); 31 HeapFree(hp,0, h5); 32 33 HeapFree(hp, 0, h4); 34 35 return 0; 36 }
- 根据
时间: 2024-12-14 00:24:49