- #include <Tlhelp32.h>
- int GetVoidPointerSize(void *nPoint)
- {
- int pid = (int)GetCurrentProcessId();
- HANDLE hSnap;
- HEAPLIST32 hl;
- HEAPENTRY32 he;
- hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPHEAPLIST, pid );
- if( hSnap == (HANDLE)-1 ){ return 0; }
- hl.dwSize=sizeof(HEAPLIST32);
- if (Heap32ListFirst(hSnap,&hl))
- {
- do
- {
- he.dwSize=sizeof(HEAPENTRY32);
- if (Heap32First(&he,pid,hl.th32HeapID))
- {
- do
- {
- if( he.dwAddress == (DWORD)nPoint )
- {
- // get kernel heap allocation chunk size
- char *t = (char*)(((unsigned char*)he.dwAddress) - 2);
- return he.dwBlockSize - *(t);
- }
- } while (Heap32Next(&he));
- }
- } while (Heap32ListNext(hSnap,&hl));
- }
- CloseHandle(hSnap);
- return 0;
- }
메모리 주소만으로 Heap에서 해당 타입의 크기와 배열 인자의 개수를 알아내는 방법
이 글에는 트랙백을 보낼 수 없습니다