Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7 KiB

  1. #include<windows.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<malloc.h>
  5. DWORD NumberOfHeaps;
  6. HANDLE ProcessHeaps[ 64 ];
  7. char MyBuffer[ 256 ];
  8. int
  9. _cdecl
  10. main()
  11. {
  12. struct _heapinfo info;
  13. PROCESS_HEAP_ENTRY Entry;
  14. size_t i;
  15. LPBYTE s;
  16. info._pentry = NULL;
  17. setvbuf( stdout, MyBuffer, _IOFBF, sizeof( MyBuffer ) );
  18. _heapset( 0xAE );
  19. while (_heapwalk( &info ) == _HEAPOK) {
  20. printf( "%08x: %05x - %s", info._pentry, info._size, info._useflag ? "busy" : "free" );
  21. if (info._useflag == _FREEENTRY) {
  22. s = (LPBYTE)info._pentry;
  23. for (i=0; i<info._size; i++) {
  24. if (s[i] != 0xAE) {
  25. printf( " *** free block invalid at offset %x [%x]", i, s[i] );
  26. break;
  27. }
  28. }
  29. }
  30. printf( "\n" );
  31. fflush( stdout );
  32. }
  33. printf( "*** end of heap ***\n\n" );
  34. fflush( stdout );
  35. NumberOfHeaps = GetProcessHeaps( 64, ProcessHeaps );
  36. Entry.lpData = NULL;
  37. for (i=0; i<NumberOfHeaps; i++) {
  38. printf( "Heap[ %u ]: %x HeapCompact result: %lx\n",
  39. i,
  40. ProcessHeaps[ i ],
  41. HeapCompact( ProcessHeaps[ i ], 0 )
  42. );
  43. while (HeapWalk( ProcessHeaps[ i ], &Entry )) {
  44. if (Entry.wFlags & PROCESS_HEAP_REGION) {
  45. printf( " %08x: %08x - Region(First: %08x Last: %08x Committed: %x Uncommitted: %08x)\n",
  46. Entry.lpData, Entry.cbData,
  47. Entry.Region.lpFirstBlock,
  48. Entry.Region.lpLastBlock,
  49. Entry.Region.dwCommittedSize,
  50. Entry.Region.dwUnCommittedSize
  51. );
  52. }
  53. else
  54. if (Entry.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE) {
  55. printf( " %08x: %08x - Uncommitted\n",
  56. Entry.lpData, Entry.cbData
  57. );
  58. }
  59. else
  60. if (Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) {
  61. printf( " %08x: %08x - Busy", Entry.lpData, Entry.cbData );
  62. if (Entry.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) {
  63. printf( " hMem: %08x", Entry.Block.hMem );
  64. }
  65. if (Entry.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) {
  66. printf( " DDE" );
  67. }
  68. printf( "\n" );
  69. }
  70. else {
  71. printf( " %08x: %08x - Free\n", Entry.lpData, Entry.cbData );
  72. }
  73. fflush( stdout );
  74. }
  75. printf( "*** end of heap ***\n\n" );
  76. fflush( stdout );
  77. }
  78. return 0;
  79. }