-
Notifications
You must be signed in to change notification settings - Fork 3
/
gui.inc
2426 lines (2110 loc) · 75 KB
/
gui.inc
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;-------------------------------------------------------------------------;
; Main GUI of the application
;-------------------------------------------------------------------------;
IDC_LIST = 200h
IDC_PATH = 201h
IDC_BROWSE = 202h
IDC_ENROLL = 203h
IDC_STATUS = 204h
WM_APP = 8000h
WM_WINBIO = WM_APP+1
WM_DPICHANGED = 2e0h
WM_NUDGE = WM_USER+100
WM_TRAY = WM_USER+101
TRAY_ID = 100
IDM_PREFERENCES = WM_USER+201
IDM_UNINSTALL = WM_USER+202
IDM_QUIT = WM_USER+203
IDM_GITHUB = WM_USER+301
IDM_ABOUT = WM_USER+302
WIN_WIDTH = 400
WIN_HEIGHT = 370
WIN_WIDTH_MIN = 320
WIN_HEIGHT_MIN = 210
SUBFACTOR_MIN = 1 ; R Thumb
SUBFACTOR_MAX = 10 ; L Little
COLUMN_FINGER = 0
COLUMN_COMMAND = 1
STATUS_DEFAULT = 1
STATUS_ENROLLED = 2
STATUS_ENROLLING = 3
STATUS_ERROR = 4
STATUS_COMMITTING = 5
STATUS_DISCARDING = 6
STATUS_COMMITTED = 7
STATUS_DISCARDED = 8
STATUS_IDENTIFYING = 9
STATUS_IDENTIFIED = 10
STATUS_DELETING = 11
STATUS_DELETED = 12
SS_ENDELLIPSIS = 4000h
EM_SETCUEBANNER = 1501h
BCM_SETSHIELD = 160ch
SHACF_FILESYSTEM = 0x00000001
SHACF_URLHISTORY = 0x00000002
SHACF_URLMRU = 0x00000004
SHACF_URLALL = 0x00000006
SHACF_USETAB = 0x00000008
SHACF_AUTOSUGGEST_FORCE_ON = 0x10000000
WINBIO_RPC_X_SS_IN_NULL_CONTEXT = 800106EFh
LVN_ITEMACTIVATE = LVN_FIRST-14
struct NMITEMACTIVATE
hds NMHDR
iItem dd ?
iSubItem dd ?
uNewState dd ?
uOldState dd ?
uChanged dd ?
ptAction dd ?
lParam dd ?
uKeyFlags dd ?
ends
struct SHFILEINFO
hIcon dd ?
iIcon dd ?
dwAttributes dd ?
szDisplayName TCHAR MAX_PATH dup (?)
szTypeName TCHAR 80 dup (?)
ends
struct POS
x dd ?
y dd ?
cx dd ?
cy dd ?
ends
struct WIN
hwnd dd ?
pos POS
ends
STATE_READY = 0x00000000
STATE_INITIALIZING = 0x00000001
STATE_ENROLLING = 0x00000002
STATE_IDENTIFYING = 0x00000004
STATE_UNENROLLING = 0x00000008
STATE_ENROLL_REQUESTED = 0x00000010
STATE_UNENROLL_REQUESTED = 0x00000020
STATE_ERROR = 0x80000000
struct CONTEXT
win WIN
pSettings dd ?
dwUnitId dd ?
dwState dd ?
dwDPI dd ?
hInst dd ?
hFont dd ?
hSession dd ?
hFramework dd ?
hwndStatus dd ?
hMenu dd ?
hOptionsMenu dd ?
hHelpMenu dd ?
hTrayMenu dd ?
winList WIN
winInfo WIN
winPath WIN
winBrowse WIN
winEnroll WIN
winStatus WIN
IdIdentity WINBIO_IDENTITY
dwIdSubFactor dd ?
bUnenrollMode db ?
pad0 db 3 dup (?)
ends
CONTEXT_FIRST_WINDOW_OFFSET = CONTEXT.winList
CONTEXT_WINDOW_COUNT = (sizeof.CONTEXT - CONTEXT_FIRST_WINDOW_OFFSET)/sizeof.WIN
; Using a pointer to the middle of the structure yields more compact instruction
; encoding because of *signed* displacement byte.
CONTEXT_POINTER_DELTA = 7ch
virtual at ebx - CONTEXT_POINTER_DELTA
ebxctx CONTEXT
end virtual
proc WndProc hwnd:DWORD, msg:DWORD, wParam:DWORD, lParam:DWORD
push ebx
mov eax, [msg]
mov ebx, .get_ebx_ctx
push .exit_retn ; return address
cmp eax, WM_CREATE
jz .WM_CREATE
cmp eax, WM_DPICHANGED
jz .WM_DPICHANGED
cmp eax, WM_GETMINMAXINFO
jz .WM_GETMINMAXINFO
cmp eax, WM_SIZE
jz .WM_SIZE
cmp eax, WM_SYSCOMMAND
jz .WM_SYSCOMMAND
cmp eax, WM_COMMAND
jz .WM_COMMAND
cmp eax, WM_NOTIFY
jz .WM_NOTIFY
cmp eax, WM_NUDGE
jz .WM_NUDGE
cmp eax, WM_TRAY
jz .WM_TRAY
cmp eax, WM_WINBIO
jz .WM_WINBIO
cmp eax, WM_CLOSE
jz .WM_CLOSE
cmp eax, WM_DESTROY
jz .WM_DESTROY
.default: pop eax
pop ebx
push [lParam]
push [wParam]
push [msg]
push [hwnd]
call [DefWindowProcA]
ret
;-------------------------------------------------------------------------;
.get_ebx_ctx: push GWL_USERDATA
push [hwnd]
call [GetWindowLongA]
test eax, eax
jz @f
mov ebx, eax
retn
push MB_ICONERROR
push gui.szError
push gui.szWindowContextMissing
push [hwnd]
call [MessageBoxA]
push [hwnd]
call [DestroyWindow]
pop eax ; old return address
jmp .exit
;-------------------------------------------------------------------------;
.WM_CREATE: push edi
push -1 ; return value
; Allocate context
xor edi, edi
push sizeof.CONTEXT
push dword [esp]
push edi
call [GetProcessHeap]
push eax
call [HeapAlloc]
test eax, eax
pop ecx
jnz .init_context
push MB_ICONERROR or MB_OK
push gui.szError
push gui.szOutOfMemoryError
push [hwnd]
call [MessageBoxA]
jmp .create_fail
.init_context: xor edi, edi
lea ebx, [eax + CONTEXT_POINTER_DELTA]
xchg eax, edi
rep stosb
; lParam from CreateWindowEx
mov eax, [lParam]
push [eax + CREATESTRUCT.lpCreateParams]
pop [ebxctx.pSettings]
; Store it in GWL_USERDATA
mov eax, [hwnd]
push ebx
push GWL_USERDATA
push eax
mov [ebxctx.win.hwnd], eax
call [SetWindowLongA]
; Get default font
push NULL
call [GetModuleHandleA]
mov [ebxctx.hInst], eax
push DEFAULT_GUI_FONT
call [GetStockObject]
mov [ebxctx.hFont], eax
; Create menu
call [CreateMenu]
mov [ebxctx.hMenu], eax
call [CreatePopupMenu]
mov [ebxctx.hOptionsMenu], eax
push gui.szPreferences
push IDM_PREFERENCES
push MF_STRING or MF_GRAYED
push [ebxctx.hOptionsMenu]
call [AppendMenuA]
push NULL
push 0
push MF_SEPARATOR
push [ebxctx.hOptionsMenu]
call [AppendMenuA]
push gui.szUninstall
push IDM_UNINSTALL
push MF_STRING
push [ebxctx.hOptionsMenu]
call [AppendMenuA]
push gui.szQuit
push IDM_QUIT
push MF_STRING
push [ebxctx.hOptionsMenu]
call [AppendMenuA]
push gui.szOptions
push [ebxctx.hOptionsMenu]
push MF_STRING or MF_POPUP
push [ebxctx.hMenu]
call [AppendMenuA]
call [CreatePopupMenu]
mov [ebxctx.hHelpMenu], eax
push gui.szGitHub
push IDM_GITHUB
push MF_STRING
push [ebxctx.hHelpMenu]
call [AppendMenuA]
push NULL
push 0
push MF_SEPARATOR
push [ebxctx.hHelpMenu]
call [AppendMenuA]
push gui.szAbout
push IDM_ABOUT
push MF_STRING
push [ebxctx.hHelpMenu]
call [AppendMenuA]
push gui.szHelp
push [ebxctx.hHelpMenu]
push MF_STRING or MF_POPUP
push [ebxctx.hMenu]
call [AppendMenuA]
push [ebxctx.hMenu]
push [ebxctx.win.hwnd]
call [SetMenu]
call [CreatePopupMenu]
mov [ebxctx.hTrayMenu], eax
push gui.szQuit
push IDM_QUIT
push MF_STRING
push [ebxctx.hTrayMenu]
call [AppendMenuA]
; Get client area of our window ...
sub esp, 4*4
push esp
push [ebxctx.win.hwnd]
call [GetClientRect]
test eax, eax
pop ecx ; left
pop edx ; top
jz .rect_bad
sub dword [esp], ecx ; right - left
sub dword [esp+4], edx ; bottom - top
jmp .rect_ok
.rect_bad: mov dword [esp], WIN_WIDTH ; includes nonclient area
mov dword [esp+4], WIN_HEIGHT
.rect_ok: pop [ebxctx.win.pos.cx] ; right
pop [ebxctx.win.pos.cy] ; bottom
; ... to calcluate child window positions
call CalculateWindowPositions
; Create statusbar
mov eax, [ebxctx.pSettings]
mov ecx, MAX_PATH
sub esp, ecx
lea esi, [eax + SETTINGS.vol.wszDeviceInstanceId]
mov edi, esp
push esp
@@: lodsw
test ax, ax
jz @f
stosb
loop @b
@@: rep stosb
pop eax
push ecx
push [ebxctx.hInst]
push ecx
push [hwnd]
push [ebxctx.winStatus.pos.cy]
push [ebxctx.winStatus.pos.cx]
push [ebxctx.winStatus.pos.y]
push [ebxctx.winStatus.pos.x]
push WS_CHILD or WS_VISIBLE
push eax
push gui.szStatusClass
push ecx
call [CreateWindowExA]
mov [ebxctx.hwndStatus], eax
add esp, MAX_PATH
; List
push NULL
push [ebxctx.hInst]
push IDC_LIST
push [hwnd]
push [ebxctx.winList.pos.cy]
push [ebxctx.winList.pos.cx]
push [ebxctx.winList.pos.y]
push [ebxctx.winList.pos.x]
push WS_CHILD or WS_VISIBLE or WS_BORDER or \
WS_GROUP or WS_TABSTOP or \
LVS_REPORT or LVS_SINGLESEL or LVS_SHOWSELALWAYS
push gui.szEmpty
push gui.szListViewClass
push 0
call [CreateWindowExA]
mov [ebxctx.winList.hwnd], eax
push 0
push [ebxctx.hFont]
push WM_SETFONT
push eax
call [SendMessageA]
push LVS_EX_FULLROWSELECT or LVS_EX_GRIDLINES
push dword [esp]
push LVM_SETEXTENDEDLISTVIEWSTYLE
push [ebxctx.winList.hwnd]
call [SendMessageA]
; Info box
push NULL
push [ebxctx.hInst]
push NULL
push [hwnd]
push [ebxctx.winInfo.pos.cy]
push [ebxctx.winInfo.pos.cx]
push [ebxctx.winInfo.pos.y]
push [ebxctx.winInfo.pos.x]
push WS_CHILD or WS_VISIBLE or BS_GROUPBOX
push gui.szEmpty
push gui.szButtonClass
push 0
call [CreateWindowExA]
mov [ebxctx.winInfo.hwnd], eax
push 0
push [ebxctx.hFont]
push WM_SETFONT
push eax
call [SendMessageA]
; File controls
push NULL
push [ebxctx.hInst]
push IDC_PATH
push [hwnd]
push [ebxctx.winPath.pos.cy]
push [ebxctx.winPath.pos.cx]
push [ebxctx.winPath.pos.y]
push [ebxctx.winPath.pos.x]
push WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_AUTOHSCROLL
push gui.szEmpty
push gui.szEditClass
push WS_EX_CLIENTEDGE
call [CreateWindowExA]
mov [ebxctx.winPath.hwnd], eax
push 0
push [ebxctx.hFont]
push WM_SETFONT
push eax
call [SendMessageA]
push gui.wszPathCue
push FALSE
push EM_SETCUEBANNER ; not supported by wine
push [ebxctx.winPath.hwnd]
call [SendMessageA]
push 0
push MAX_PATH-1
push EM_LIMITTEXT
push [ebxctx.winPath.hwnd]
call [SendMessageA]
push SHACF_AUTOSUGGEST_FORCE_ON or SHACF_FILESYSTEM \
or SHACF_USETAB
push [ebxctx.winPath.hwnd]
call [SHAutoComplete]
push NULL
push [ebxctx.hInst]
push IDC_BROWSE
push [hwnd]
push [ebxctx.winBrowse.pos.cy]
push [ebxctx.winBrowse.pos.cx]
push [ebxctx.winBrowse.pos.y]
push [ebxctx.winBrowse.pos.x]
push WS_CHILD or WS_VISIBLE or WS_TABSTOP or BS_ICON
push gui.szBrowse
push gui.szButtonClass
push 0
call [CreateWindowExA]
mov [ebxctx.winBrowse.hwnd], eax
mov ecx, sizeof.SHFILEINFO
xor eax, eax
sub esp, ecx
mov edi, esp
push 113h ; SHGFI_{ICON,SMALLICON,OPENICON,USEFILEATTRIBUTES}
push ecx
push edi
push FILE_ATTRIBUTE_DIRECTORY
push gui.szBrowse
rep stosb
call [SHGetFileInfo]
mov eax, [esp + SHFILEINFO.hIcon]
mov esp, edi
push eax
push IMAGE_ICON
push BM_SETIMAGE
push [ebxctx.winBrowse.hwnd]
call [SendMessageA]
; Enroll button
push NULL
push [ebxctx.hInst]
push IDC_ENROLL
push [hwnd]
push [ebxctx.winEnroll.pos.cy]
push [ebxctx.winEnroll.pos.cx]
push [ebxctx.winEnroll.pos.y]
push [ebxctx.winEnroll.pos.x]
push WS_CHILD or WS_VISIBLE or WS_TABSTOP; or WS_DISABLED
push gui.szEnroll
push gui.szButtonClass
push 0
call [CreateWindowExA]
mov [ebxctx.winEnroll.hwnd], eax
push 0
push [ebxctx.hFont]
push WM_SETFONT
push eax
call [SendMessageA]
; Status static text
push NULL
push [ebxctx.hInst]
push IDC_STATUS
push [hwnd]
push [ebxctx.winStatus.pos.cy]
push [ebxctx.winStatus.pos.cx]
push [ebxctx.winStatus.pos.y]
push [ebxctx.winStatus.pos.x]
push WS_CHILD or WS_VISIBLE or SS_ENDELLIPSIS
push gui.szStatusDefault
push gui.szStaticClass
push 0
call [CreateWindowExA]
mov [ebxctx.winStatus.hwnd], eax
push 0
push [ebxctx.hFont]
push WM_SETFONT
push eax
call [SendMessageA]
; Fill fingerprint/commant listview
call InitFingerList
; Make it focused
push [ebxctx.winList.hwnd]
call [SetFocus]
; And show details of the current selection
call UpdateSelection
; Get window DPI
push [hwnd]
call [GetDpiForWindow]
mov [ebxctx.dwDPI], eax
; Open async WinBio
call .winbio_open
test eax, eax
jnz .create_fail
.create_ok: inc dword [esp] ; +1
inc dword [esp] ; 0
.create_fail: pop eax ; -1
pop edi
pop ebx
pop ebx
ret
.winbio_open: mov eax, [ebxctx.dwState]
test eax, eax
jnz .winbio_fail
; Open async WinBio framework for enumerating biometric units
lea eax, [ebxctx.hFramework]
push eax
push TRUE
push ebx
push NULL
push WM_WINBIO
push [ebxctx.win.hwnd]
push WINBIO_ASYNC_NOTIFY_MESSAGE
call [WinBioAsyncOpenFramework]
test eax, eax
jnz .winbio_fail
mov [ebxctx.dwState], STATE_INITIALIZING
retn
.winbio_fail: or [ebxctx.dwState], STATE_ERROR
push eax
push MB_ICONERROR or MB_OK
push gui.szError
push gui.szFrameworkError
push [ebxctx.win.hwnd]
call [MessageBoxA]
pop eax
retn
;-------------------------------------------------------------------------;
.WM_DPICHANGED: call ebx ; .get_ebx_ctx
push [hwnd]
call [GetDpiForWindow]
mov [ebxctx.dwDPI], eax
retn
.WM_GETMINMAXINFO:
mov eax, [lParam]
test eax, eax
jz .exit
mov ebx, eax
push [hwnd]
call [GetDpiForWindow]
push 96
push eax
push 96
push eax
push WIN_WIDTH_MIN
call [MulDiv]
mov [ebx + MINMAXINFO.ptMinTrackSize.x], eax
push WIN_HEIGHT_MIN
call [MulDiv]
mov [ebx + MINMAXINFO.ptMinTrackSize.y], eax
retn
.WM_SIZE: call ebx ; .get_ebx_ctx
push edi
push esi
mov eax, [lParam]
movzx ecx, ax
shr eax, 16
mov [ebxctx.win.pos.cx], ecx
mov [ebxctx.win.pos.cy], eax
call CalculateWindowPositions
lea esi, [ebxctx + CONTEXT_FIRST_WINDOW_OFFSET]
push CONTEXT_WINDOW_COUNT
pop edi
.resize_window: cmp [esi + WIN.hwnd], 0
jz .skip_null_win
push FALSE
push 96
push [ebxctx.dwDPI]
push [esi + WIN.pos.cy]
call [MulDiv]
push eax
push 96
push [ebxctx.dwDPI]
push [esi + WIN.pos.cx]
call [MulDiv]
push eax
push 96
push [ebxctx.dwDPI]
push [esi + WIN.pos.y]
call [MulDiv]
push eax
push 96
push [ebxctx.dwDPI]
push [esi + WIN.pos.x]
call [MulDiv]
push eax
push [esi + WIN.hwnd]
call [MoveWindow]
.skip_null_win: add esi, sizeof.WIN
dec edi
jnz .resize_window
push edi
push edi
push WM_SIZE
push [ebxctx.hwndStatus]
call [SendMessageA]
call ResizeColumns
push RDW_INVALIDATE
push edi
push edi
push [ebxctx.win.hwnd]
call [RedrawWindow]
pop esi
pop edi
retn
;-------------------------------------------------------------------------;
.WM_SYSCOMMAND: mov eax, [wParam]
cmp eax, SC_MAXIMIZE
jnz @f
call ebx ; .get_ebx_ctx
call SaveSettingsGUI
push 1
mov eax, [ebxctx.pSettings]
pop [eax + SETTINGS.GUI.dwMaximized]
jmp .default
@@: cmp eax, SC_RESTORE
jnz @f
call ebx ; .get_ebx_ctx
xor eax, eax
mov ebx, [ebxctx.pSettings]
mov [ebx + SETTINGS.GUI.dwMinimized], eax
mov [ebx + SETTINGS.GUI.dwMaximized], eax
; jmp .default
@@: cmp eax, SC_MINIMIZE
jnz .default
call ebx ; .get_ebx_ctx
call SaveSettingsGUI
push [hwnd]
call ShowTrayIcon
test eax, eax
jz .default
push SW_HIDE
push [hwnd]
call [ShowWindow]
push 1
mov eax, [ebxctx.pSettings]
pop [eax + SETTINGS.GUI.dwMinimized]
retn
;-------------------------------------------------------------------------;
.WM_COMMAND: mov eax, [wParam]
cmp eax, IDC_PATH + (EN_CHANGE shl 16)
jz .IDC_PATH
cmp eax, IDC_BROWSE + (BN_CLICKED shl 16)
jz .IDC_BROWSE
cmp eax, IDC_ENROLL + (BN_CLICKED shl 16)
jz .IDC_ENROLL
cmp ax, IDM_PREFERENCES
jz .IDM_PREFERENCES
cmp ax, IDM_UNINSTALL
jz .IDM_UNINSTALL
cmp ax, IDM_QUIT
jz .IDM_QUIT
cmp ax, IDM_GITHUB
jz .IDM_GITHUB
cmp ax, IDM_ABOUT
jz .IDM_ABOUT
jmp .exit
.IDC_PATH: call ebx ; .get_ebx_ctx
push [lParam]
call [GetWindowTextLengthA]
inc eax ; +1 for NULL-terminator
push eax ; for GetWindowTextA
push eax
push 0
call [GetProcessHeap]
push eax
call [HeapAlloc]
test eax, eax
pop ecx
jz .path_oom
push eax ; for HeapFree
push ecx
push eax
push [lParam]
call [GetWindowTextA]
push LVNI_SELECTED
push -1
push LVM_GETNEXTITEM
push [ebxctx.winList.hwnd]
call [SendMessageA]
test eax, eax
js .path_fail
push dword [esp]
push eax
call SetCommand
.path_fail: push 0
call [GetProcessHeap]
push eax
call [HeapFree]
.path_oom: retn
.IDC_BROWSE: call ebx ; .get_ebx_ctx
push edi
mov eax, esp
sub esp, sizeof.OPENFILENAME + MAX_PATH+4
mov edi, esp
push eax
push edi ; for GetOpenFileNameA
xor eax, eax
lea ecx, [eax + sizeof.OPENFILENAME]
push ecx
rep stosb
mov al, '"'
stosb
mov byte [edi], cl
virtual at edi - sizeof.OPENFILENAME-1
.ofn OPENFILENAME
.path db MAX_PATH+4 dup (?)
end virtual
pop [.ofn.lStructSize]
push [hwnd]
pop [.ofn.hwndOwner]
mov [.ofn.lpstrFilter], gui.szBrowseFilter
mov byte [.ofn.nFilterIndex], 1
mov [.ofn.lpstrFile], edi
mov [.ofn.nMaxFile], MAX_PATH+1
; mov byte [.ofn.Flags], 1800h
mov byte [.ofn.Flags+1], (OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST) shr 8
call [GetOpenFileNameA]
test eax, eax
jz .browse_exit
.opened: push edi ; for SendMessageA
; strlen(edi)
xor eax, eax
or ecx, -1
repnz scasb
not ecx
sub edi, ecx
dec ecx
jz .unquoted
; Add quotes if the path contains a space
mov al, ' '
repnz scasb
jnz .unquoted
;mov byte [.path], '"' ; done already
mov byte [edi+ecx], '"'
mov byte [edi+ecx+1], 0
dec dword [esp]
.unquoted:
push 0
push WM_SETTEXT
push [ebxctx.winPath.hwnd]
call [SendMessageA]
.browse_exit: pop esp
pop edi
retn
.IDC_ENROLL: call ebx ; .get_ebx_ctx
mov eax, [ebxctx.dwState]
test al, STATE_ENROLLING or STATE_UNENROLL_REQUESTED \
or STATE_UNENROLLING or STATE_ENROLL_REQUESTED
jnz .enroll_cancel
; Unenroll mode
cmp [ebxctx.bUnenrollMode], 0
jz .enroll_mode
; Ask unenrollment confirmation from the user
push ebp
mov ebp, esp
sub esp, gui.szUnenrollFormat.size-2 + 38
mov eax, esp
push gui.szEmpty
push gui.szUnenrollFormat
push eax
call [wsprintfA]
add esp, 3*4h
add eax, esp
lea ecx, [ebxctx.IdIdentity.guidTemplate]
push eax
push ecx
call GuidToString
mov eax, esp
push MB_YESNOCANCEL or MB_ICONEXCLAMATION or MB_DEFBUTTON3
push gui.szUnenrollCaption
push eax
push [ebxctx.win.hwnd]
call [MessageBoxA]
leave
cmp eax, IDYES
mov eax, [ebxctx.dwState]
jnz .enroll_ret
test al, STATE_ENROLLING or STATE_IDENTIFYING or STATE_UNENROLLING
jz .unenroll
or [ebxctx.dwState], STATE_UNENROLL_REQUESTED
jmp .enroll_cancel
.unenroll: and byte [ebxctx.dwState], not STATE_UNENROLL_REQUESTED
lea eax, [ebxctx.IdIdentity]
push dword [eax + sizeof.WINBIO_IDENTITY] ; dwIdSubFactor
push eax
push [ebxctx.dwUnitId]
push [ebxctx.hSession]
call [WinBioDeleteTemplate]
test eax, eax
jnz .enroll_error
lea eax, [ebxctx.IdIdentity.guidTemplate]
push eax
push STATUS_DELETING
call SetStatus
or [ebxctx.dwState], STATE_UNENROLLING
call EnterEnrollmentMode
retn
; Enroll mode
.enroll_mode: test al, STATE_ENROLLING or STATE_IDENTIFYING or STATE_UNENROLLING
jz .enroll
or [ebxctx.dwState], STATE_ENROLL_REQUESTED
.enroll_cancel: push [ebxctx.hSession]
call [WinBioCancel]
.enroll_ret: retn
.enroll_error: push eax
push STATUS_ERROR
call SetStatus
retn
.enroll: push LVNI_SELECTED
push -1
push LVM_GETNEXTITEM
push [ebxctx.winList.hwnd]
call [SendMessageA]
test eax, eax
js .enroll_ret
cmp eax, 10
jae .enroll_ret
inc eax ; add eax, WINBIO_ANSI_381_POS_RH_THUMB (1)
push [ebxctx.dwUnitId]
push eax
push [ebxctx.hSession]
call [WinBioEnrollBegin]
test eax, eax
jnz .enroll_error
.enrolling: or [ebxctx.dwState], STATE_ENROLLING
call EnterEnrollmentMode
retn
.IDM_PREFERENCES:
; UNIMPLEMENTED
retn
.IDM_UNINSTALL: call ebx
test ebx, ebx
jz .uninstall_quit
test [ebxctx.dwState], STATE_INITIALIZING
jnz .uninstall_err
push [ebxctx.hSession]
call .winbio_close
push [ebxctx.win.hwnd]
push gui.wszUninstall
call RunAsAdmin
test eax, eax
pop eax ; hSession
jz .uninstalled
test eax, eax
jz .uninstall_err
call .winbio_open
.uninstall_err: push MB_ICONERROR or MB_OK
push gui.szError
push gui.szUninstallError
push [ebxctx.win.hwnd]
call [MessageBoxA]
retn
.uninstalled: mov eax, [ebxctx.pSettings]
test eax, eax
jz .uninstall_quit
mov word [eax + SETTINGS.vol.wszDeviceInstanceId], 0
.uninstall_quit:;push [hwnd]
;call [DestroyWindow]
;retn
.IDM_QUIT: push [hwnd]
call [DestroyWindow]
retn
.IDM_GITHUB: push SW_SHOWNORMAL
push NULL
push NULL
push gui.szGitHubURL
push gui.szOpen