Botan  1.11.10
Public Member Functions | List of all members
Botan::Win32_EntropySource Class Reference

#include <es_win32.h>

Inheritance diagram for Botan::Win32_EntropySource:
Botan::EntropySource

Public Member Functions

std::string name () const
 
void poll (Entropy_Accumulator &accum)
 

Detailed Description

Win32 Entropy Source

Definition at line 18 of file es_win32.h.

Member Function Documentation

std::string Botan::Win32_EntropySource::name ( ) const
inlinevirtual
Returns
name identifying this entropy source

Implements Botan::EntropySource.

Definition at line 21 of file es_win32.h.

21 { return "Win32 Statistics"; }
void Botan::Win32_EntropySource::poll ( Entropy_Accumulator accum)
virtual

Win32 poll using stats functions including Tooltip32

Implements Botan::EntropySource.

Definition at line 17 of file es_win32.cpp.

References Botan::Entropy_Accumulator::add(), Botan::Entropy_Accumulator::polling_goal_achieved(), and TOOLHELP32_ITER.

18  {
19  /*
20  First query a bunch of basic statistical stuff, though
21  don't count it for much in terms of contributed entropy.
22  */
23  accum.add(GetTickCount(), 0);
24  accum.add(GetMessagePos(), 0);
25  accum.add(GetMessageTime(), 0);
26  accum.add(GetInputState(), 0);
27  accum.add(GetCurrentProcessId(), 0);
28  accum.add(GetCurrentThreadId(), 0);
29 
30  SYSTEM_INFO sys_info;
31  GetSystemInfo(&sys_info);
32  accum.add(sys_info, 1);
33 
34  MEMORYSTATUS mem_info;
35  GlobalMemoryStatus(&mem_info);
36  accum.add(mem_info, 1);
37 
38  POINT point;
39  GetCursorPos(&point);
40  accum.add(point, 1);
41 
42  GetCaretPos(&point);
43  accum.add(point, 1);
44 
45  LARGE_INTEGER perf_counter;
46  QueryPerformanceCounter(&perf_counter);
47  accum.add(perf_counter, 0);
48 
49  /*
50  Now use the Tooltip library to iterate throug various objects on
51  the system, including processes, threads, and heap objects.
52  */
53 
54  HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
55 
56 #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
57  if(!accum.polling_goal_achieved()) \
58  { \
59  DATA_TYPE info; \
60  info.dwSize = sizeof(DATA_TYPE); \
61  if(FUNC_FIRST(snapshot, &info)) \
62  { \
63  do \
64  { \
65  accum.add(info, 1); \
66  } while(FUNC_NEXT(snapshot, &info)); \
67  } \
68  }
69 
70  TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next);
71  TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next);
72  TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next);
73 
74 #undef TOOLHELP32_ITER
75 
76  if(!accum.polling_goal_achieved())
77  {
78  size_t heap_lists_found = 0;
79  HEAPLIST32 heap_list;
80  heap_list.dwSize = sizeof(HEAPLIST32);
81 
82  const size_t HEAP_LISTS_MAX = 32;
83  const size_t HEAP_OBJS_PER_LIST = 128;
84 
85  if(Heap32ListFirst(snapshot, &heap_list))
86  {
87  do
88  {
89  accum.add(heap_list, 1);
90 
91  if(++heap_lists_found > HEAP_LISTS_MAX)
92  break;
93 
94  size_t heap_objs_found = 0;
95  HEAPENTRY32 heap_entry;
96  heap_entry.dwSize = sizeof(HEAPENTRY32);
97  if(Heap32First(&heap_entry, heap_list.th32ProcessID,
98  heap_list.th32HeapID))
99  {
100  do
101  {
102  if(heap_objs_found++ > HEAP_OBJS_PER_LIST)
103  break;
104  accum.add(heap_entry, 1);
105  } while(Heap32Next(&heap_entry));
106  }
107 
108  if(accum.polling_goal_achieved())
109  break;
110 
111  } while(Heap32ListNext(snapshot, &heap_list));
112  }
113  }
114 
115  CloseHandle(snapshot);
116  }
#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT)

The documentation for this class was generated from the following files: