/** * Win32 poll using stats functions including Tooltip32 */ void Win32_EntropySource::poll(Entropy_Accumulator& accum) { /* First query a bunch of basic statistical stuff, though don't count it for much in terms of contributed entropy. */ accum.add(GetTickCount(), 0); accum.add(GetMessagePos(), 0); accum.add(GetMessageTime(), 0); accum.add(GetInputState(), 0); accum.add(GetCurrentProcessId(), 0); accum.add(GetCurrentThreadId(), 0); SYSTEM_INFO sys_info; GetSystemInfo(&sys_info); accum.add(sys_info, 1); MEMORYSTATUS mem_info; GlobalMemoryStatus(&mem_info); accum.add(mem_info, 1); POINT point; GetCursorPos(&point); accum.add(point, 1); GetCaretPos(&point); accum.add(point, 1); LARGE_INTEGER perf_counter; QueryPerformanceCounter(&perf_counter); accum.add(perf_counter, 0); /* Now use the Tooltip library to iterate throug various objects on the system, including processes, threads, and heap objects. */ HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \ if(!accum.polling_finished()) \ { \ DATA_TYPE info; \ info.dwSize = sizeof(DATA_TYPE); \ if(FUNC_FIRST(snapshot, &info)) \ { \ do \ { \ accum.add(info, 1); \ } while(FUNC_NEXT(snapshot, &info)); \ } \ } TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next); TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next); TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next); #undef TOOLHELP32_ITER if(!accum.polling_finished()) { size_t heap_lists_found = 0; HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); const size_t HEAP_LISTS_MAX = 32; const size_t HEAP_OBJS_PER_LIST = 128; if(Heap32ListFirst(snapshot, &heap_list)) { do { accum.add(heap_list, 1); if(++heap_lists_found > HEAP_LISTS_MAX) break; size_t heap_objs_found = 0; HEAPENTRY32 heap_entry; heap_entry.dwSize = sizeof(HEAPENTRY32); if(Heap32First(&heap_entry, heap_list.th32ProcessID, heap_list.th32HeapID)) { do { if(heap_objs_found++ > HEAP_OBJS_PER_LIST) break; accum.add(heap_entry, 1); } while(Heap32Next(&heap_entry)); } if(accum.polling_finished()) break; } while(Heap32ListNext(snapshot, &heap_list)); } } CloseHandle(snapshot); }
void qtDLGHeapView::DisplayHeap() { tblHeapView->setRowCount(0); tblHeapBlocks->setRowCount(0); for(size_t i = m_processCountEntry; i < m_processCountEnd;i++) { HEAPLIST32 heapList; heapList.dwSize = sizeof(HEAPLIST32); HANDLE hHeapSnap = CreateToolhelp32Snapshot(TH32CS_SNAPHEAPLIST,m_pMainWindow->coreDebugger->PIDs[i].dwPID); if(hHeapSnap != INVALID_HANDLE_VALUE) { if(Heap32ListFirst(hHeapSnap,&heapList)) { do { quint64 commitedSize = NULL, usedSize = NULL, BlockCount = NULL; HEAPENTRY32 he; ZeroMemory(&he, sizeof(HEAPENTRY32)); he.dwSize = sizeof(HEAPENTRY32); if(Heap32First(&he,m_pMainWindow->coreDebugger->PIDs[i].dwPID,heapList.th32HeapID)) { do { commitedSize += he.dwBlockSize; BlockCount++; he.dwSize = sizeof(HEAPENTRY32); }while(Heap32Next(&he)); } tblHeapView->insertRow(tblHeapView->rowCount()); // PID tblHeapView->setItem(tblHeapView->rowCount() - 1,0, new QTableWidgetItem(QString("%1").arg(heapList.th32ProcessID,8,16,QChar('0')))); // Base Offset tblHeapView->setItem(tblHeapView->rowCount() - 1,1, new QTableWidgetItem(QString("%1").arg(heapList.th32HeapID,8,16,QChar('0')))); // Used Size tblHeapView->setItem(tblHeapView->rowCount() - 1,2, new QTableWidgetItem(QString("%1").arg(usedSize,16,10,QChar('0')))); // Commited Size tblHeapView->setItem(tblHeapView->rowCount() - 1,3, new QTableWidgetItem(QString("%1").arg(commitedSize,16,10,QChar('0')))); // Block Count tblHeapView->setItem(tblHeapView->rowCount() - 1,4, new QTableWidgetItem(QString("%1").arg(BlockCount,16,10,QChar('0')))); // Flags tblHeapView->setItem(tblHeapView->rowCount() - 1,5, new QTableWidgetItem(QString("%1").arg(heapList.dwFlags,8,16,QChar('0')))); heapList.dwSize = sizeof(HEAPLIST32); }while(Heap32ListNext(hHeapSnap,&heapList)); } CloseHandle(hHeapSnap); } } }