-
Notifications
You must be signed in to change notification settings - Fork 3
/
hotfinger.asm
497 lines (436 loc) · 17.5 KB
/
hotfinger.asm
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
format PE GUI 4.0
include 'win32a.inc'
include 'winbio.inc'
;-------------------------------------------------------------------------
; Program settings
;-------------------------------------------------------------------------
struct GUI_SETTINGS
x dd ?
y dd ?
cx dd ?
cy dd ?
dwMinimized dd ?
dwMaximized dd ?
ends
struct COMMAND_SETTINGS
RThumb db MAX_PATH dup (?)
RIndex db MAX_PATH dup (?)
RMiddle db MAX_PATH dup (?)
RRing db MAX_PATH dup (?)
RLittle db MAX_PATH dup (?)
LThumb db MAX_PATH dup (?)
LIndex db MAX_PATH dup (?)
LMiddle db MAX_PATH dup (?)
LRing db MAX_PATH dup (?)
LLittle db MAX_PATH dup (?)
ends
struct VOLATILE_SETTINGS
wszDeviceInstanceId du WINBIO_MAX_STRING_LEN dup (?)
ends
struct SETTINGS
GUI GUI_SETTINGS
cmd COMMAND_SETTINGS
vol VOLATILE_SETTINGS
ends
section '.text' code readable executable
entry $
push SW_SHOWDEFAULT
call [GetCommandLineA]
push eax
push NULL
push NULL
call [GetModuleHandleA]
push eax
call WinMain
push eax
call [ExitProcess]
;-------------------------------------------------------------------------;
; WinMain
;-------------------------------------------------------------------------;
proc WinMain hInst:DWORD, hPrevInst:DWORD, szCmdLine:DWORD, nCmdShow:DWORD
local ini:SETTINGS
local wc:WNDCLASSEX
local msg:MSG
local icl:INITCOMMONCONTROLSEX
local rc:DWORD
push ebx
push esi
push edi
push 1
pop [rc]
; Initialize common controls & OLE
push sizeof.INITCOMMONCONTROLSEX
push ICC_LISTVIEW_CLASSES or ICC_BAR_CLASSES
lea eax, [icl]
pop [icl.dwICC]
pop [icl.dwSize]
push eax
call [InitCommonControlsEx]
push NULL
call [CoInitialize]
; Parse command-line arguments
call CommandLineInterface
; Focus existing window
push NULL
push hotfinger.szClassName
call [FindWindowA]
test eax, eax
jz .not_found
push NULL
push NULL
push WM_NUDGE
push eax
call [SendMessageA]
push 2
pop eax
ret
.not_found:
; Read settings
lea ebx, [ini]
push ebx
call ReadAppDataSettings
lea eax, [ebx + SETTINGS.vol.wszDeviceInstanceId]
push eax
push guidDatabase
call GetSensorDeviceInstanceIdForDatabase
test eax, eax
jz .die
;--------------------------------------------------------------------------;
; Register window class
;--------------------------------------------------------------------------;
xor eax, eax
lea ecx, [eax + sizeof.WNDCLASSEX]
push ecx
lea edi, [wc]
rep stosb
pop [wc.cbSize]
mov [wc.style], CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov [wc.lpfnWndProc], WndProc
push [hInst]
pop [wc.hInstance]
push IDI_MAIN
push [hInst]
call [LoadIconA]
mov [wc.hIcon], eax
mov [wc.hIconSm], eax
push IDC_ARROW
push NULL
call [LoadCursorA]
mov [wc.hCursor], eax
mov [wc.hbrBackground], COLOR_BTNFACE+1
mov [wc.lpszClassName], hotfinger.szClassName
lea eax, [wc]
push eax
call [RegisterClassExA]
test eax, eax
jnz .create_window
push MB_ICONERROR
push hotfinger.szError
push hotfinger.szWindowRegistrationFailed
push NULL
call [MessageBoxA]
jmp .die
;--------------------------------------------------------------------------;
; Create the window
;--------------------------------------------------------------------------;
.create_window: push ebx
push [hInst]
push NULL
push NULL
push [ini + SETTINGS.GUI.cy] ; height
mov ecx, [ini + SETTINGS.GUI.y]
sub [esp], ecx
push [ini + SETTINGS.GUI.cx] ; width
mov eax, [ini + SETTINGS.GUI.x]
sub [esp], eax
push ecx ; y
push eax ; x
push WS_OVERLAPPEDWINDOW
push hotfinger.szCaption
push hotfinger.szClassName
push 0
call [CreateWindowExA]
test eax, eax
jnz .show_window
push MB_ICONERROR
push hotfinger.szError
push hotfinger.szWindowCreationFailed
push eax ; NULL
call [MessageBoxA]
jmp .die
.show_window: xor esi, esi
xchg eax, esi
lea edi, [msg]
cmp [ini + SETTINGS.GUI.dwMinimized], eax
jnz .show_in_tray
push SW_SHOWMAXIMIZED
cmp [ini + SETTINGS.GUI.dwMaximized], eax
pop eax
cmovz eax, [nCmdShow]
push esi
push eax
push esi
call [ShowWindow]
call [UpdateWindow]
jmp .msg_loop
.show_in_tray: push SW_HIDE
push esi
call [ShowWindow]
push esi
call ShowTrayIcon
;--------------------------------------------------------------------------;
; Message loop
;--------------------------------------------------------------------------;
.msg_loop: push 0
push 0
push NULL
push edi
call [GetMessageA]
test eax, eax
jz .finish
push edi
push esi
call [IsDialogMessage]
test eax, eax
jnz .msg_loop
push edi
push edi
call [TranslateMessage]
call [DispatchMessageA]
jmp .msg_loop
.finish: push [msg.wParam]
pop [rc]
;--------------------------------------------------------------------------;
; Finish
;--------------------------------------------------------------------------;
cmp word [ini.vol.wszDeviceInstanceId], 0
jz .die ; uninstalled or something, do not save settings
push ebx
call WriteAppDataSettings
.die: call [CoUninitialize]
pop edi
pop esi
pop ebx
mov eax, [rc]
ret
endp
include 'cli.inc'
include 'database.inc'
include 'gui.inc'
include 'sensor.inc'
include 'settings.inc'
include 'utils.inc'
section '.data' data readable writeable
include 'data.inc'
section '.idata' import readable
library advapi32, 'advapi32.dll', \
comctl32, 'comctl32.dll', \
comdlg32, 'comdlg32.dll', \
gdi32, 'gdi32.dll', \
kernel32, 'kernel32.dll', \
ole32, 'ole32.dll', \
shell32, 'shell32.dll', \
shlwapi, 'shlwapi.dll', \
user32, 'user32.dll', \
winbio, 'winbio.dll'
import advapi32, \
CloseServiceHandle, 'CloseServiceHandle', \
ControlService, 'ControlService', \
OpenSCManagerA, 'OpenSCManagerA', \
OpenServiceA, 'OpenServiceA', \
QueryServiceStatus, 'QueryServiceStatus', \
RegCloseKey, 'RegCloseKey', \
RegCreateKeyExA, 'RegCreateKeyExA', \
RegDeleteKeyA, 'RegDeleteKeyA', \
RegEnumKeyExA, 'RegEnumKeyExA', \
RegEnumKeyExW, 'RegEnumKeyExW', \
RegGetValueA, 'RegGetValueA', \
RegOpenKeyExA, 'RegOpenKeyExA', \
RegOpenKeyExW, 'RegOpenKeyExW', \
RegSetValueExA, 'RegSetValueExA', \
StartServiceA, 'StartServiceA'
import comctl32, \
InitCommonControlsEx, 'InitCommonControlsEx'
import comdlg32, \
GetOpenFileNameA, 'GetOpenFileNameA'
import gdi32, \
GetStockObject, 'GetStockObject'
import kernel32, \
CloseHandle, 'CloseHandle', \
CreateDirectoryA, 'CreateDirectoryA', \
DeleteFileA, 'DeleteFileA', \
ExitProcess, 'ExitProcess', \
GetCommandLineA, 'GetCommandLineA', \
GetCommandLineW, 'GetCommandLineW', \
GetExitCodeProcess, 'GetExitCodeProcess', \
GetFileAttributesA, 'GetFileAttributesA', \
GetLastError, 'GetLastError', \
GetModuleFileNameW, 'GetModuleFileNameW', \
GetModuleHandleA, 'GetModuleHandleA', \
GetPrivateProfileIntA, 'GetPrivateProfileIntA', \
GetPrivateProfileStringA, 'GetPrivateProfileStringA', \
GetProcessHeap, 'GetProcessHeap', \
HeapAlloc, 'HeapAlloc', \
HeapFree, 'HeapFree', \
HeapReAlloc, 'HeapReAlloc', \
LocalFree, 'LocalFree', \
MulDiv, 'MulDiv', \
RemoveDirectoryA, 'RemoveDirectoryA', \
Sleep, 'Sleep', \
WaitForSingleObject, 'WaitForSingleObject', \
Wow64DisableWow64FsRedirection, 'Wow64DisableWow64FsRedirection', \
Wow64RevertWow64FsRedirection, 'Wow64RevertWow64FsRedirection', \
WritePrivateProfileStringA, 'WritePrivateProfileStringA', \
lstrcmpW, 'lstrcmpW', \
lstrcmpiW, 'lstrcmpiW', \
lstrlenA, 'lstrlenA', \
lstrlenW, 'lstrlenW'
import ole32, \
CoInitialize, 'CoInitialize', \
CoUninitialize, 'CoUninitialize'
import shell32, \
CommandLineToArgvW, 'CommandLineToArgvW', \
SHGetFileInfo, 'SHGetFileInfo', \
SHGetFolderPathA, 'SHGetFolderPathA', \
Shell_NotifyIconA, 'Shell_NotifyIconA', \
ShellExecuteA, 'ShellExecuteA', \
ShellExecuteExW, 'ShellExecuteExW'
import shlwapi, \
SHAutoComplete, 'SHAutoComplete'
import user32, \
AdjustWindowRectExForDpi, 'AdjustWindowRectExForDpi', \
AppendMenuA, 'AppendMenuA', \
CreateMenu, 'CreateMenu', \
CreatePopupMenu, 'CreatePopupMenu', \
CreateWindowExA, 'CreateWindowExA', \
DefWindowProcA, 'DefWindowProcA', \
DestroyMenu, 'DestroyMenu', \
DestroyWindow, 'DestroyWindow', \
DialogBoxParamA, 'DialogBoxParamA', \
DispatchMessageA, 'DispatchMessageA', \
DrawMenuBar, 'DrawMenuBar', \
EnableMenuItem, 'EnableMenuItem', \
EnableWindow, 'EnableWindow', \
EndDialog, 'EndDialog', \
FindWindowA, 'FindWindowA', \
GetClientRect, 'GetClientRect', \
GetCursorPos, 'GetCursorPos', \
GetDlgItem, 'GetDlgItem', \
GetDpiForSystem, 'GetDpiForSystem', \
GetDpiForWindow, 'GetDpiForWindow', \
GetMenuItemCount, 'GetMenuItemCount', \
GetMessageA, 'GetMessageA', \
GetSystemMetricsForDpi, 'GetSystemMetricsForDpi', \
GetWindowLongA, 'GetWindowLongA', \
GetWindowRect, 'GetWindowRect', \
GetWindowTextA, 'GetWindowTextA', \
GetWindowTextLengthA, 'GetWindowTextLengthA', \
IsDialogMessage, 'IsDialogMessage', \
LoadCursorA, 'LoadCursorA', \
LoadIconA, 'LoadIconA', \
MapDialogRect, 'MapDialogRect', \
MessageBoxA, 'MessageBoxA', \
MoveWindow, 'MoveWindow', \
PostQuitMessage, 'PostQuitMessage', \
RedrawWindow, 'RedrawWindow', \
RegisterClassExA, 'RegisterClassExA', \
SendDlgItemMessageA, 'SendDlgItemMessageA', \
SendMessageA, 'SendMessageA', \
SetFocus, 'SetFocus', \
SetForegroundWindow, 'SetForegroundWindow', \
SetMenu, 'SetMenu', \
SetWindowLongA, 'SetWindowLongA', \
SetWindowPos, 'SetWindowPos', \
SetWindowTextA, 'SetWindowTextA', \
ShowWindow, 'ShowWindow', \
TrackPopupMenu, 'TrackPopupMenu', \
TranslateMessage, 'TranslateMessage', \
UpdateWindow, 'UpdateWindow', \
wsprintfA, 'wsprintfA'
import winbio, \
WinBioAsyncEnumBiometricUnits, 'WinBioAsyncEnumBiometricUnits', \
WinBioAsyncOpenFramework, 'WinBioAsyncOpenFramework', \
WinBioAsyncOpenSession, 'WinBioAsyncOpenSession', \
WinBioCancel,'WinBioCancel', \
WinBioCloseFramework, 'WinBioCloseFramework', \
WinBioCloseSession, 'WinBioCloseSession', \
WinBioDeleteTemplate, 'WinBioDeleteTemplate', \
WinBioEnrollBegin, 'WinBioEnrollBegin', \
WinBioEnrollCapture, 'WinBioEnrollCapture', \
WinBioEnrollCommit, 'WinBioEnrollCommit', \
WinBioEnrollDiscard, 'WinBioEnrollDiscard', \
WinBioEnumBiometricUnits, 'WinBioEnumBiometricUnits', \
WinBioFree, 'WinBioFree', \
WinBioIdentify, 'WinBioIdentify', \
WinBioLocateSensor, 'WinBioLocateSensor', \
WinBioWait, 'WinBioWait'
section '.rsrc' resource data readable
; Dialogs
IDD_SENSOR = 100
IDD_ABOUT = 101
; Sensor dialog
IDD_SENSOR_WIDTH = 350
IDD_SENSOR_HEIGHT = 120
IDD_SENSOR_WIDTH_MIN = 250
IDD_SENSOR_HEIGHT_MIN = 80
IDC_BTN_SELECT = 2000
IDC_BTN_CANCEL = 2001
IDC_STATIC_MESSAGE = 2002
IDC_LIST_SENSORS = 2003
; About dialog
IDC_SYSLINK = 3000
; Icons
IDI_MAIN = 401
directory RT_DIALOG, dialogs, \
RT_ICON, icons, \
RT_GROUP_ICON, group_icons, \
RT_MANIFEST, manifests, \
RT_VERSION, versions
resource dialogs, \
IDD_SENSOR, LANG_ENGLISH+SUBLANG_DEFAULT, sensor_dialog, \
IDD_ABOUT, LANG_ENGLISH+SUBLANG_DEFAULT, about_dialog
resource icons, 1, LANG_NEUTRAL, icon_data
resource group_icons, IDI_MAIN, LANG_NEUTRAL, main_icon
resource manifests, 1, LANG_NEUTRAL, manifest
resource versions, 1, LANG_NEUTRAL, version
dialog sensor_dialog, 'Sensor dialog', 0,0,IDD_SENSOR_WIDTH,IDD_SENSOR_HEIGHT, WS_POPUP+WS_OVERLAPPEDWINDOW+DS_MODALFRAME+DS_CENTER
dialogitem 'BUTTON','&Select', IDC_BTN_SELECT, IDD_SENSOR_WIDTH-108,IDD_SENSOR_HEIGHT-18,50,14, BS_DEFPUSHBUTTON+WS_VISIBLE+WS_TABSTOP+WS_DISABLED
dialogitem 'BUTTON','&Cancel', IDC_BTN_CANCEL, IDD_SENSOR_WIDTH-54,IDD_SENSOR_HEIGHT-18,50,14, BS_PUSHBUTTON+WS_VISIBLE+WS_TABSTOP
dialogitem 'STATIC','Select sensor from the list', IDC_STATIC_MESSAGE, 4,IDD_SENSOR_HEIGHT-14,IDD_SENSOR_WIDTH-112,8, WS_VISIBLE
dialogitem 'SysListView32','', IDC_LIST_SENSORS, 4,4,IDD_SENSOR_WIDTH-8,IDD_SENSOR_HEIGHT-24, WS_VISIBLE+WS_BORDER+WS_TABSTOP+LVS_REPORT+LVS_SINGLESEL+LVS_SHOWSELALWAYS
enddialog
dialog about_dialog, 'About', 40,40,160,55, WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
dialogitem 'STATIC', <'HotFinger application launcher'>, -1, 36,10,120,10, WS_VISIBLE
dialogitem 'SysLink', <'<a>https://github.com/resilar/HotFinger</a>'>, IDC_SYSLINK, 36,20,120,10, WS_VISIBLE
dialogitem 'STATIC', IDI_MAIN, -1, 8,8,32,32, WS_VISIBLE+SS_ICON
dialogitem 'STATIC', '', -1, 4,35,152,11, WS_VISIBLE+SS_ETCHEDHORZ
dialogitem 'STATIC', <'HotFinger v0.1.0'>, -1, 4,42,100,10, WS_VISIBLE+SS_LEFT
dialogitem 'BUTTON', 'OK', IDOK, 114,38,42,14, WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
enddialog
icon main_icon, icon_data, 'sysclass.ico'
resdata manifest
db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',0dh,0ah
db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">',0dh,0ah
db ' <assemblyIdentity version="1.0.0.0" processorArchitecture="x86" type="win32" name="hotfinger.exe"/>',0dh,0ah
db ' <description>HotFinger</description>',0dh,0ah
db ' <dependency>',0dh,0ah
db ' <dependentAssembly>',0dh,0ah
db ' <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"/> ',0dh,0ah
db ' </dependentAssembly>',0dh,0ah
db ' </dependency>',0dh,0ah
db ' <asmv3:application>',0dh,0ah
db ' <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">',0dh,0ah
; db ' <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>',0dh,0ah
db ' <dpiAware>true</dpiAware>',0dh,0ah
db ' </asmv3:windowsSettings>',0dh,0ah
db ' </asmv3:application>',0dh,0ah
db '</assembly>',0dh,0ah
endres
versioninfo version, \
VOS__WINDOWS32, VFT_APP,VFT2_UNKNOWN, LANG_ENGLISH+SUBLANG_DEFAULT, 0, \
'FileDescription', 'Biometric hotkeys', \
'FileVersion', '0.1.0.0', \
'ProductName', 'HotFinger', \
'ProductVersion', '0.1.0', \
'LegalCopyright', 'UNLICENSE', \
'OriginalFilename', 'hotfinger.exe'