VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume/Pkcs5Kdf.h
blob: 76cc56a0ea14d1b41ecdedffe88d5f94272c219f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 Derived from source code of TrueCrypt 7.1a, which is
 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
 by the TrueCrypt License 3.0.

 Modifications and additions to the original source code (contained in this file)
 and all other portions of this file are Copyright (c) 2013-2017 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages.
*/

#ifndef TC_HEADER_Encryption_Pkcs5
#define TC_HEADER_Encryption_Pkcs5

#include "Platform/Platform.h"
#include "Hash.h"
#include "VolumePassword.h"

namespace VeraCrypt
{
	class Pkcs5Kdf;
	typedef list < shared_ptr <Pkcs5Kdf> > Pkcs5KdfList;

	class Pkcs5Kdf
	{
	public:
		virtual ~Pkcs5Kdf ();

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, int pim, const ConstBufferPtr &salt) const;
		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const = 0;
		static shared_ptr <Pkcs5Kdf> GetAlgorithm (const wstring &name, bool truecryptMode);
		static shared_ptr <Pkcs5Kdf> GetAlgorithm (const Hash &hash, bool truecryptMode);
		static Pkcs5KdfList GetAvailableAlgorithms (bool truecryptMode);
		virtual shared_ptr <Hash> GetHash () const = 0;
		virtual int GetIterationCount (int pim) const = 0;
		virtual wstring GetName () const = 0;
		virtual Pkcs5Kdf* Clone () const = 0;
		virtual bool IsDeprecated () const { return GetHash()->IsDeprecated(); }
		bool GetTrueCryptMode () const { return m_truecryptMode;}
		void SetTrueCryptMode (bool truecryptMode) { m_truecryptMode = truecryptMode;}

	protected:
		bool m_truecryptMode;
		Pkcs5Kdf (bool truecryptMode);

		void ValidateParameters (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;

	private:
		Pkcs5Kdf (const Pkcs5Kdf &);
		Pkcs5Kdf &operator= (const Pkcs5Kdf &);
	};

	class Pkcs5HmacRipemd160 : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacRipemd160 (bool truecryptMode) : Pkcs5Kdf (truecryptMode) { }
		virtual ~Pkcs5HmacRipemd160 () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); }
		virtual int GetIterationCount (int pim) const { return m_truecryptMode? 2000 : (pim <= 0 ? 655331 : (15000 + (pim * 1000))) ; }
		virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacRipemd160(m_truecryptMode); }

	private:
		Pkcs5HmacRipemd160 (const Pkcs5HmacRipemd160 &);
		Pkcs5HmacRipemd160 &operator= (const Pkcs5HmacRipemd160 &);
	};

	class Pkcs5HmacRipemd160_1000 : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacRipemd160_1000 (bool truecryptMode) : Pkcs5Kdf(truecryptMode) { }
		virtual ~Pkcs5HmacRipemd160_1000 () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); }
		virtual int GetIterationCount (int pim) const { return m_truecryptMode? 1000 : (pim <= 0 ? 327661 : (pim * 2048)); }
		virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacRipemd160_1000(m_truecryptMode); }

	private:
		Pkcs5HmacRipemd160_1000 (const Pkcs5HmacRipemd160_1000 &);
		Pkcs5HmacRipemd160_1000 &operator= (const Pkcs5HmacRipemd160_1000 &);
	};

	class Pkcs5HmacSha256_Boot : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacSha256_Boot () : Pkcs5Kdf(false) { }
		virtual ~Pkcs5HmacSha256_Boot () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); }
		virtual int GetIterationCount (int pim) const { return pim <= 0 ? 200000 : (pim * 2048); }
		virtual wstring GetName () const { return L"HMAC-SHA-256"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha256_Boot(); }

	private:
		Pkcs5HmacSha256_Boot (const Pkcs5HmacSha256_Boot &);
		Pkcs5HmacSha256_Boot &operator= (const Pkcs5HmacSha256_Boot &);
	};

	class Pkcs5HmacSha256 : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacSha256 () : Pkcs5Kdf(false) { }
		virtual ~Pkcs5HmacSha256 () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); }
		virtual int GetIterationCount (int pim) const { return pim <= 0 ? 500000 : (15000 + (pim * 1000)); }
		virtual wstring GetName () const { return L"HMAC-SHA-256"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha256(); }

	private:
		Pkcs5HmacSha256 (const Pkcs5HmacSha256 &);
		Pkcs5HmacSha256 &operator= (const Pkcs5HmacSha256 &);
	};

	class Pkcs5HmacSha512 : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacSha512 (bool truecryptMode) : Pkcs5Kdf(truecryptMode) { }
		virtual ~Pkcs5HmacSha512 () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha512); }
		virtual int GetIterationCount (int pim) const { return m_truecryptMode? 1000 : (pim <= 0 ? 500000 : (15000 + (pim * 1000))); }
		virtual wstring GetName () const { return L"HMAC-SHA-512"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha512(m_truecryptMode); }

	private:
		Pkcs5HmacSha512 (const Pkcs5HmacSha512 &);
		Pkcs5HmacSha512 &operator= (const Pkcs5HmacSha512 &);
	};

	class Pkcs5HmacWhirlpool : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacWhirlpool (bool truecryptMode) : Pkcs5Kdf(truecryptMode) { }
		virtual ~Pkcs5HmacWhirlpool () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Whirlpool); }
		virtual int GetIterationCount (int pim) const { return m_truecryptMode? 1000 : (pim <= 0 ? 500000 : (15000 + (pim * 1000))); }
		virtual wstring GetName () const { return L"HMAC-Whirlpool"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacWhirlpool(m_truecryptMode); }

	private:
		Pkcs5HmacWhirlpool (const Pkcs5HmacWhirlpool &);
		Pkcs5HmacWhirlpool &operator= (const Pkcs5HmacWhirlpool &);
	};
	
	class Pkcs5HmacStreebog : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacStreebog () : Pkcs5Kdf(false) { }
		virtual ~Pkcs5HmacStreebog () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Streebog); }
		virtual int GetIterationCount (int pim) const { return pim <= 0 ? 500000 : (15000 + (pim * 1000)); }
		virtual wstring GetName () const { return L"HMAC-Streebog"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacStreebog(); }

	private:
		Pkcs5HmacStreebog (const Pkcs5HmacStreebog &);
		Pkcs5HmacStreebog &operator= (const Pkcs5HmacStreebog &);
	};
	
	class Pkcs5HmacStreebog_Boot : public Pkcs5Kdf
	{
	public:
		Pkcs5HmacStreebog_Boot () : Pkcs5Kdf(false) { }
		virtual ~Pkcs5HmacStreebog_Boot () { }

		virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const;
		virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Streebog); }
		virtual int GetIterationCount (int pim) const { return pim <= 0 ? 200000 : pim * 2048; }
		virtual wstring GetName () const { return L"HMAC-Streebog"; }
		virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacStreebog_Boot(); }

	private:
		Pkcs5HmacStreebog_Boot (const Pkcs5HmacStreebog_Boot &);
		Pkcs5HmacStreebog_Boot &operator= (const Pkcs5HmacStreebog_Boot &);
	};
}

#endif // TC_HEADER_Encryption_Pkcs5
>VK_ICO_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_CLEAR"); break; case VK_ATTN: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Attn"); break; case VK_CRSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"CrSel"); break; case VK_EXSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ExSel"); break; case VK_EREOF: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Erase EOF"); break; case VK_PA1: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"PA1"); break; case VK_OEM_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM Clear"); break; case 0: case 1: case 0xFF: result = FALSE; break; default: { char key[16]; wchar_t *desc; StringCbPrintfA (key, sizeof(key),"VKEY_%02X", vKey); desc = GetString (key); if (desc == UnknownString) result = FALSE; else StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, desc); } } } return result; } static BOOL ShortcutInUse (UINT vKeyCode, UINT modifiers, TCHOTKEY hotkeys[]) { int i; for (i = 0; i < NBR_HOTKEYS; i++) { if (hotkeys[i].vKeyCode == vKeyCode && hotkeys[i].vKeyModifiers == modifiers) return TRUE; } return FALSE; } void UnregisterAllHotkeys (HWND hwndDlg, TCHOTKEY hotkeys[]) { int i; for (i = 0; i < NBR_HOTKEYS; i++) { if (hotkeys[i].vKeyCode != 0) UnregisterHotKey (hwndDlg, i); } } BOOL RegisterAllHotkeys (HWND hwndDlg, TCHOTKEY hotkeys[]) { BOOL result = TRUE; int i; for (i = 0; i < NBR_HOTKEYS; i++) { if (hotkeys[i].vKeyCode != 0 && !RegisterHotKey (hwndDlg, i, hotkeys[i].vKeyModifiers, hotkeys[i].vKeyCode)) result = FALSE; } return result; } static void DisplayHotkeyList (HWND hwndDlg) { LVITEMW item; HWND hList = GetDlgItem (hwndDlg, IDC_HOTKEY_LIST); int i; wchar_t ShortcutMod [MAX_KEY_COMB_NAME_LEN]; wchar_t ShortcutFinal [MAX_KEY_COMB_NAME_LEN*2]; wchar_t Shortcut [MAX_KEY_COMB_NAME_LEN]; SendMessage (hList, LVM_DELETEALLITEMS,0, (LPARAM)&item); for (i = 0; i < NBR_HOTKEYS; i++) { memset (&item,0,sizeof(item)); item.mask = LVIF_TEXT; item.iItem = i; item.iSubItem = 0; switch (i) { case HK_AUTOMOUNT_DEVICES: item.pszText = GetString ("HK_AUTOMOUNT_DEVICES"); break; case HK_DISMOUNT_ALL: item.pszText = GetString ("HK_DISMOUNT_ALL"); break; case HK_WIPE_CACHE: item.pszText = GetString ("HK_WIPE_CACHE"); break; case HK_DISMOUNT_ALL_AND_WIPE: item.pszText = GetString ("HK_DISMOUNT_ALL_AND_WIPE"); break; case HK_FORCE_DISMOUNT_ALL_AND_WIPE: item.pszText = GetString ("HK_FORCE_DISMOUNT_ALL_AND_WIPE"); break; case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT: item.pszText = GetString ("HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT"); break; case HK_MOUNT_FAVORITE_VOLUMES: item.pszText = GetString ("HK_MOUNT_FAVORITE_VOLUMES"); break; case HK_SHOW_HIDE_MAIN_WINDOW: item.pszText = GetString ("HK_SHOW_HIDE_MAIN_WINDOW"); break; case HK_CLOSE_SECURITY_TOKEN_SESSIONS: item.pszText = GetString ("IDM_CLOSE_ALL_TOKEN_SESSIONS"); break; default: item.pszText = L"[?]"; } SendMessageW (hList,LVM_INSERTITEMW,0,(LPARAM)&item); item.iSubItem = 1; Shortcut[0] = 0; ShortcutMod[0] = 0; if (GetKeyName (tmpHotkeys[i].vKeyCode, Shortcut)) { if (tmpHotkeys[i].vKeyModifiers & MOD_CONTROL) { StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_CONTROL")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+"); } if (tmpHotkeys[i].vKeyModifiers & MOD_SHIFT) { StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_SHIFT")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+"); } if (tmpHotkeys[i].vKeyModifiers & MOD_ALT) { StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_ALT")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+"); } if (tmpHotkeys[i].vKeyModifiers & MOD_WIN) { StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_WIN")); StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+"); } StringCbPrintfW (ShortcutFinal, sizeof(ShortcutFinal), L"%s%s", ShortcutMod, Shortcut); item.pszText = ShortcutFinal; } else item.pszText = L""; SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&item); } } BOOL CALLBACK HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { WORD lw = LOWORD (wParam); WORD hw = HIWORD (wParam); static BOOL bKeyScanOn; static BOOL bTPlaySoundOnSuccessfulHkDismount; static BOOL bTDisplayBalloonOnSuccessfulHkDismount; switch (msg) { case WM_INITDIALOG: { LVCOLUMNW col; HWND hList = GetDlgItem (hwndDlg, IDC_HOTKEY_LIST); bKeyScanOn = FALSE; nSelectedHotkeyId = -1; currentVKeyCode = 0; memcpy (tmpHotkeys, Hotkeys, sizeof(tmpHotkeys)); memset (vkeysDown, 0, sizeof(vkeysDown)); SendMessageW (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP ); memset (&col,0,sizeof(col)); col.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT; col.pszText = GetString ("ACTION"); col.cx = CompensateXDPI (341); col.fmt = LVCFMT_LEFT; SendMessageW (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&col); col.pszText = GetString ("SHORTCUT"); col.cx = CompensateXDPI (190); col.fmt = LVCFMT_LEFT; SendMessageW (hList,LVM_INSERTCOLUMNW,1,(LPARAM)&col); LocalizeDialog (hwndDlg, "IDD_HOTKEYS_DLG"); SetCheckBox (hwndDlg, IDC_HK_MOD_CTRL, TRUE); SetCheckBox (hwndDlg, IDC_HK_MOD_SHIFT, FALSE); SetCheckBox (hwndDlg, IDC_HK_MOD_ALT, TRUE); SetCheckBox (hwndDlg, IDC_HK_MOD_WIN, FALSE); SetCheckBox (hwndDlg, IDC_HK_DISMOUNT_PLAY_SOUND, bPlaySoundOnSuccessfulHkDismount); SetCheckBox (hwndDlg, IDC_HK_DISMOUNT_BALLOON_TOOLTIP, bDisplayBalloonOnSuccessfulHkDismount); bTPlaySoundOnSuccessfulHkDismount = bPlaySoundOnSuccessfulHkDismount; bTDisplayBalloonOnSuccessfulHkDismount = bDisplayBalloonOnSuccessfulHkDismount; EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), FALSE); DisplayHotkeyList(hwndDlg); if (SetTimer (hwndDlg, 0xfe, 10, NULL) == 0) { Error ("CANNOT_SET_TIMER", MainDlg); EndDialog (hwndDlg, IDCANCEL); return 1; } return 1; } case WM_TIMER: { if ((nSelectedHotkeyId > -1) && (GetFocus () == GetDlgItem (hwndDlg, IDC_HOTKEY_KEY))) { wchar_t keyName [MAX_KEY_COMB_NAME_LEN]; UINT tmpVKeyCode; keyName[0] = 0; ScanAndProcessKey (&tmpVKeyCode, &keyName[0]); if (keyName[0] != 0) { currentVKeyCode = tmpVKeyCode; SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), keyName); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), TRUE); } else if ((currentVKeyCode != 0) && GetKeyName (currentVKeyCode, keyName)) { SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), keyName); } } return 1; } case WM_NOTIFY: if (wParam == IDC_HOTKEY_LIST) { if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE || ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED)) { LVITEM item; memset(&item,0,sizeof(item)); nSelectedHotkeyId = ((LPNMLISTVIEW) lParam)->iItem; currentVKeyCode = 0; memset (vkeysDown, 0, sizeof(vkeysDown)); SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), GetString ("PRESS_A_KEY_TO_ASSIGN")); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), (tmpHotkeys[nSelectedHotkeyId].vKeyCode > 0)); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), FALSE); bKeyScanOn = TRUE; return 1; } } return 0; case WM_COMMAND: if (lw == IDC_HOTKEY_KEY && hw == EN_CHANGE) { if (!bKeyScanOn && nSelectedHotkeyId < 0 && GetWindowTextLengthW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY))) SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), L""); } if (lw == IDC_HOTKEY_ASSIGN) { BOOL bOwnActiveShortcut = FALSE; if (nSelectedHotkeyId >= 0 && currentVKeyCode != 0) { UINT modifiers = 0; if (GetCheckBox (hwndDlg, IDC_HK_MOD_CTRL)) modifiers = MOD_CONTROL; if (GetCheckBox (hwndDlg, IDC_HK_MOD_ALT)) modifiers |= MOD_ALT; if (GetCheckBox (hwndDlg, IDC_HK_MOD_SHIFT)) modifiers |= MOD_SHIFT; if (GetCheckBox (hwndDlg, IDC_HK_MOD_WIN)) modifiers |= MOD_WIN; // Check if it's not already assigned if (ShortcutInUse (currentVKeyCode, modifiers, tmpHotkeys)) { Error ("SHORTCUT_ALREADY_IN_USE", hwndDlg); return 1; } // Check for reserved system keys switch (currentVKeyCode) { case VK_F1: case VK_F12: /* F1 is help and F12 is reserved for use by the debugger at all times */ if (modifiers == 0) { Error ("CANNOT_USE_RESERVED_KEY", hwndDlg); return 1; } break; } bOwnActiveShortcut = ShortcutInUse (currentVKeyCode, modifiers, Hotkeys); // Test if the shortcut can be assigned without errors if (!bOwnActiveShortcut && !RegisterHotKey (hwndDlg, nSelectedHotkeyId, modifiers, currentVKeyCode)) { handleWin32Error(hwndDlg, SRC_POS); return 1; } else { if (!bOwnActiveShortcut && !UnregisterHotKey (hwndDlg, nSelectedHotkeyId)) handleWin32Error(hwndDlg, SRC_POS); tmpHotkeys[nSelectedHotkeyId].vKeyCode = currentVKeyCode; tmpHotkeys[nSelectedHotkeyId].vKeyModifiers = modifiers; SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), L""); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), FALSE); nSelectedHotkeyId = -1; bKeyScanOn = FALSE; currentVKeyCode = 0; memset (vkeysDown, 0, sizeof(vkeysDown)); } } DisplayHotkeyList(hwndDlg); return 1; } if (lw == IDC_HOTKEY_REMOVE) { if (nSelectedHotkeyId >= 0) { tmpHotkeys[nSelectedHotkeyId].vKeyCode = 0; tmpHotkeys[nSelectedHotkeyId].vKeyModifiers = 0; SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), L""); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), FALSE); nSelectedHotkeyId = -1; bKeyScanOn = FALSE; currentVKeyCode = 0; memset (vkeysDown, 0, sizeof(vkeysDown)); DisplayHotkeyList(hwndDlg); } return 1; } if (lw == IDC_RESET_HOTKEYS) { int i; for (i = 0; i < NBR_HOTKEYS; i++) { tmpHotkeys[i].vKeyCode = 0; tmpHotkeys[i].vKeyModifiers = 0; } SetWindowTextW (GetDlgItem (hwndDlg, IDC_HOTKEY_KEY), L""); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_ASSIGN), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), FALSE); nSelectedHotkeyId = -1; bKeyScanOn = FALSE; currentVKeyCode = 0; memset (vkeysDown, 0, sizeof(vkeysDown)); DisplayHotkeyList(hwndDlg); return 1; } if (lw == IDC_HK_DISMOUNT_PLAY_SOUND) { bTPlaySoundOnSuccessfulHkDismount = GetCheckBox (hwndDlg, IDC_HK_DISMOUNT_PLAY_SOUND); } if (lw == IDC_HK_DISMOUNT_BALLOON_TOOLTIP) { bTDisplayBalloonOnSuccessfulHkDismount = GetCheckBox (hwndDlg, IDC_HK_DISMOUNT_BALLOON_TOOLTIP); } if (lw == IDCANCEL || lw == IDCLOSE) { KillTimer (hwndDlg, 0xfe); EndDialog (hwndDlg, IDCANCEL); return 1; } if (lw == IDOK) { HWND hwndMainDlg = hwndDlg; while (GetParent (hwndMainDlg) != NULL) { hwndMainDlg = GetParent (hwndMainDlg); } UnregisterAllHotkeys (hwndMainDlg, Hotkeys); memcpy (Hotkeys, tmpHotkeys, sizeof(Hotkeys)); RegisterAllHotkeys (hwndMainDlg, Hotkeys); KillTimer (hwndDlg, 0xfe); bPlaySoundOnSuccessfulHkDismount = bTPlaySoundOnSuccessfulHkDismount; bDisplayBalloonOnSuccessfulHkDismount = bTDisplayBalloonOnSuccessfulHkDismount; SaveSettings (hwndDlg); EndDialog (hwndDlg, IDCANCEL); return 1; } return 0; case WM_CLOSE: KillTimer (hwndDlg, 0xfe); EndDialog (hwndDlg, IDCANCEL); return 1; } return 0; }