monotone

monotone Mtn Source Tree

Root/botan/es_win32.cpp

1/*************************************************
2* Win32 EntropySource Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/es_win32.h>
7#include <windows.h>
8#include <tlhelp32.h>
9
10namespace Botan {
11
12/*************************************************
13* Win32 Slow Poll *
14*************************************************/
15void Win32_EntropySource::do_slow_poll()
16 {
17 const u32bit MAX_ITEMS = 256;
18
19 do_fast_poll();
20
21 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
22
23#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
24 { \
25 u32bit items = 0; \
26 DATA_TYPE info; \
27 info.dwSize = sizeof(DATA_TYPE); \
28 if(FUNC_FIRST(snapshot, &info)) \
29 { \
30 do \
31 { \
32 if(items++ > MAX_ITEMS) break; \
33 add_bytes(&info, sizeof(info)); \
34 } while(FUNC_NEXT(snapshot, &info)); \
35 } \
36 }
37
38 TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next);
39 TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next);
40 TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next);
41
42#undef TOOLHELP32_ITER
43
44 u32bit heap_lists_found = 0;
45 HEAPLIST32 heap_list;
46 heap_list.dwSize = sizeof(HEAPLIST32);
47
48 const u32bit HEAP_LISTS_MAX = 32;
49 const u32bit HEAP_OBJS_PER_LIST = 128;
50 if(Heap32ListFirst(snapshot, &heap_list))
51 {
52 do
53 {
54 add_bytes(&heap_list, sizeof(HEAPLIST32));
55
56 if(heap_lists_found++ > HEAP_LISTS_MAX)
57 break;
58
59 u32bit heap_objs_found = 0;
60 HEAPENTRY32 heap_entry;
61 heap_entry.dwSize = sizeof(HEAPENTRY32);
62 if(Heap32First(&heap_entry, heap_list.th32ProcessID,
63 heap_list.th32HeapID))
64 {
65 do
66 {
67 if(heap_objs_found++ > HEAP_OBJS_PER_LIST)
68 break;
69 add_bytes(&heap_entry, sizeof(HEAPENTRY32));
70 } while(Heap32Next(&heap_entry));
71 }
72 } while(Heap32ListNext(snapshot, &heap_list));
73 }
74
75 CloseHandle(snapshot);
76 }
77
78/*************************************************
79* Win32 Fast Poll *
80*************************************************/
81void Win32_EntropySource::do_fast_poll()
82 {
83 add_bytes(GetTickCount());
84 add_bytes(GetMessagePos());
85 add_bytes(GetMessageTime());
86 add_bytes(GetInputState());
87 add_bytes(GetCurrentProcessId());
88 add_bytes(GetCurrentThreadId());
89
90 SYSTEM_INFO sys_info;
91 GetSystemInfo(&sys_info);
92 add_bytes(&sys_info, sizeof(sys_info));
93
94 MEMORYSTATUS mem_info;
95 GlobalMemoryStatus(&mem_info);
96 add_bytes(&mem_info, sizeof(mem_info));
97
98 POINT point;
99 GetCursorPos(&point);
100 add_bytes(&point, sizeof(point));
101 GetCaretPos(&point);
102 add_bytes(&point, sizeof(point));
103
104 LARGE_INTEGER perf_counter;
105 QueryPerformanceCounter(&perf_counter);
106 add_bytes(&perf_counter, sizeof(perf_counter));
107 }
108
109}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status