-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.inc
1326 lines (1169 loc) · 40.2 KB
/
database.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
;-------------------------------------------------------------------------;
; WinBio database management functions
;-------------------------------------------------------------------------;
KEY_WOW64_64KEY = 0100h
KEY_WOW64_32KEY = 0200h
RRF_RT_REG_SZ = 02h
RRF_RT_REG_DWORD = 10h
ERROR_PATH_NOT_FOUND = 3
ERROR_ACCESS_DENIED = 5
RPC_S_SERVER_TOO_BUSY = 000006BBh
RPC_X_SS_IN_NULL_CONTEXT = 000006EFh
struct WBIOSVC_SENSOR
guidDatabaseId db 16 dup (?)
dwSensorMode dd ?
dwSystemSensor dd ?
szEngineAdapterBinary db MAX_PATH dup (?)
szSensorAdapterBinary db MAX_PATH dup (?)
szStorageAdapterBinary db MAX_PATH dup (?)
ends
struct WBIOSVC_DATABASE
dwAttributes dd ?
dwAutoCreate dd ?
dwAutoName dd ?
dwBiometricType dd ?
szConnectionString db WINBIO_MAX_STRING_LEN dup (?)
szFilePath db MAX_PATH dup (?)
guidFormat db 16 dup (?)
dwInitialSize dd ?
ends
; Common prologue/epilogue for the 4 functions below:
;proc ReadWbiosvcSensorKey hKey:DWORD, pSensor:DWORD
;proc ReadWbiosvcDatabaseKey hKey:DWORD, pDatabase:DWORD
;proc SaveWbiosvcSensorKey hKey:DWORD, pSensor:DWORD
;proc SaveWbiosvcDatabaseKey hKey:DWORD, pDatabase:DWORD
ReadSaveWrapper:
.prologue: pop eax
push ebx
mov ebx, [esp+4h+4h+0] ; [arg0]
push ebp
mov ebp, Regaux.getDword
push esi
mov esi, database.szDatabaseId
push edi
mov edi, [esp+10h+4h+4h] ; [arg1]
call eax
.epilogue: sbb eax, eax
inc eax
pop edi
pop esi
pop ebp
pop ebx
retn 8h
; pSensor:WBIOSVC_SENSOR
;proc ReadWbiosvcSensorKey hKey:DWORD, pSensor:DWORD
ReadWbiosvcSensorKey:
call ReadSaveWrapper
;mov ebx, [hKey]
;mov ebp, Regaux.getDword
;mov esi, database.szDatabaseId
;mov edi, [pSensor]
;add edi, WBIOSVC_SENSOR.guidDatabaseId ; offset 0
call Regaux.getGuid
;mov esi, database.szSensorMode
call ebp
;mov esi, database.szSystemSensor
call ebp
add ebp, Regaux.getSz - Regaux.getDword
;mov esi, database.szEngineAdapterBinary
mov ecx, MAX_PATH
call ebp
;mov esi, database.szSensorAdapterBinary
call ebp
;mov esi, database.szStorageAdapterBinary
call ebp
retn
; pDatabase:WBIOSVC_DATABASE
;proc ReadWbiosvcDatabaseKey hKey:DWORD, pDatabase:DWORD
ReadWbiosvcDatabaseKey:
call ReadSaveWrapper
;mov ebx, [hKey]
;mov ebp, Regaux.getDword
;mov esi, database.szAttributes
add esi, database.szAttributes - database.szDatabaseId
;mov edi, [pDatabase]
;add edi, WBIOSVC_DATABASE.dwAttributes ; offset 0
call ebp
;mov esi, database.szAutoCreate
call ebp
;mov esi, database.szAutoName
call ebp
;mov esi, database.szBiometricType
call ebp
;mov esi, database.szConnectionString
mov ecx, WINBIO_MAX_STRING_LEN
add ebp, Regaux.getSz - Regaux.getDword
call ebp
;mov esi, database.szFilePath
;mov ecx, WINBIO_MAX_STRING_LEN
call ebp
;mov esi, database.szFormat
call Regaux.getGuid
;mov esi, database.szInitialSize
call Regaux.getDword
retn
; pSensor:WBIOSVC_SENSOR
;proc SaveWbiosvcSensorKey hKey:DWORD, pSensor:DWORD
SaveWbiosvcSensorKey:
call ReadSaveWrapper
;mov ebx, [hKey]
;mov ebp, Regaux.setDword
add ebp, Regaux.setDword - Regaux.getDword
;mov esi, database.szDatabaseId
;mov edi, [pSensor]
call Regaux.setGuid
;mov esi, database.szSensorMode
call ebp
;mov esi, database.szSystemSensor
call ebp
add ebp, Regaux.setSz - Regaux.setDword
;mov esi, database.szEngineAdapterBinary
mov ecx, MAX_PATH
call ebp
;mov esi, database.szSensorAdapterBinary
call ebp
;mov esi, database.szStorageAdapterBinary
call ebp
retn
; pDatabase:WBIOSVC_DATABASE
;proc SaveWbiosvcDatabaseKey hKey:DWORD, pDatabase:DWORD
SaveWbiosvcDatabaseKey:
call ReadSaveWrapper
;mov ebx, [hKey]
;mov ebp, Regaux.setDword
add ebp, Regaux.setDword - Regaux.getDword
;mov esi, database.szAttributes
add esi, database.szAttributes - database.szDatabaseId
;mov edi, [pDatabase]
;add edi, WBIOSVC_DATABASE.dwAttributes ; offset 0
call ebp
;mov esi, database.szAutoCreate
call ebp
;mov esi, database.szAutoName
call ebp
;mov esi, database.szBiometricType
call ebp
;mov esi, database.szConnectionString
mov ecx, WINBIO_MAX_STRING_LEN
call Regaux.setSz
;mov esi, database.szFilePath
mov ecx, MAX_PATH
call Regaux.setSz
;mov esi, database.szFormat
call Regaux.setGuid
;mov esi, database.szInitialSize
call ebp
retn
;-------------------------------------------------------------------------;
; Iterate WinBio sensor configuration keys for (all) device instances.
;
; HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\<DeviceInstanceId>
; \Device Parameters\WinBio\Configurations\<Id>
;
; wszDeviceInstanceId[WINBIO_MAX_STRING_LEN]:WORD (iter all if NULL)
; fnFilter = proc hKey:DWORD, wszDeviceInstanceId:DWORD, dwConfigId:DWORD, pUser:DWORD
;
; If fnFilter returns ...
; * eax = -2, then delete hKey and stop iteration and return NÚLL.
; * eax = -1, then delete hKey and iterate to the next key.
; * eax = 0, then close hKey and iterate to the next key.
; * eax = 1, then stop iteration and return hKey.
;-------------------------------------------------------------------------;
proc IterSensorConfigurations pwszDeviceInstanceId:DWORD, fnFilter:DWORD, pUser:DWORD
local szKey[65+WINBIO_MAX_STRING_LEN+1+255+1 + 2]:BYTE
local szConfigId[32]:BYTE
local wszDeviceInstanceId[WINBIO_MAX_STRING_LEN+2]:WORD
local dwConfigId:DWORD
local hConfigurationsKey:DWORD
local dwConfigurationsKeyWritable:DWORD
local dwConfigurationIdx:DWORD
local hConfigurationKey:DWORD
local dwInstanceLen:DWORD
local dwInstanceIdx:DWORD
local hInstanceKey:DWORD
local hDeviceKey:DWORD
local dwDeviceLen:DWORD
local dwDeviceIdx:DWORD
local hDevicesKey:DWORD
local dwEnumLen:DWORD
local dwEnumIdx:DWORD
local hEnumKey:DWORD
xor eax, eax
push esi
push edi
push eax ; return value
cmp [pwszDeviceInstanceId], eax
jz .iter_all
mov esi, [pwszDeviceInstanceId]
push esi
call [lstrlenW]
test eax, eax
lea ecx, [eax+1]
jz .exit
cmp eax, WINBIO_MAX_STRING_LEN
ja .exit
lea edi, [wszDeviceInstanceId]
lea eax, [szKey]
push edi
push database.szSensorKeyFmt
push eax
rep movsw
call [wsprintfA]
add esp, 0ch
lea eax, [hConfigurationsKey]
push eax
push KEY_READ + KEY_SET_VALUE
push 0
lea eax, [szKey]
push eax
push HKEY_LOCAL_MACHINE
call [RegOpenKeyExA]
test eax, eax
jnz .exit
jmp .configs_loop
.iter_all: lea eax, [hEnumKey]
push eax
push KEY_READ + KEY_WOW64_32KEY
push 0
push database.szEnumKey
push HKEY_LOCAL_MACHINE
call [RegOpenKeyExA]
test eax, eax
jnz .enum_end
mov [dwEnumIdx], 0
.enum_iter: xor eax, eax
push eax
push eax
push eax
push eax
lea eax, [dwEnumLen]
mov dword [eax], WINBIO_MAX_STRING_LEN
push eax
lea eax, [wszDeviceInstanceId]
push eax
push [dwEnumIdx]
inc [dwEnumIdx]
push [hEnumKey]
call [RegEnumKeyExW]
test eax, eax
jnz .enum_end
lea eax, [hDevicesKey]
push eax
push KEY_READ
push 0
lea eax, [wszDeviceInstanceId]
push eax
push [hEnumKey]
call [RegOpenKeyExW]
test eax, eax
jnz .enum_iter
mov [dwDeviceIdx], 0
.devices_iter: xor eax, eax
push eax
push eax
push eax
push eax
lea eax, [dwDeviceLen]
mov ecx, [dwEnumLen]
mov dword [eax], WINBIO_MAX_STRING_LEN
sub dword [eax], ecx
push eax
mov ax, '\'
lea edi, [wszDeviceInstanceId + ecx*2]
stosw
push edi
push [dwDeviceIdx]
inc [dwDeviceIdx]
push [hDevicesKey]
call [RegEnumKeyExW]
test eax, eax
jnz .devices_end
lea eax, [hDeviceKey]
push eax
push KEY_READ
push 0
push edi
push [hDevicesKey]
call [RegOpenKeyExW]
test eax, eax
jnz .devices_iter
mov [dwInstanceIdx], eax
.insts_iter: xor eax, eax
push eax
push eax
push eax
push eax
lea eax, [dwInstanceLen]
mov ecx, [dwEnumLen]
add ecx, [dwDeviceLen]
inc ecx
mov dword [eax], WINBIO_MAX_STRING_LEN
sub dword [eax], ecx
push eax
mov ax, '\'
lea edi, [wszDeviceInstanceId + ecx*2]
stosw
push edi
push [dwInstanceIdx]
inc [dwInstanceIdx]
push [hDeviceKey]
call [RegEnumKeyExW]
test eax, eax
jnz .insts_end
lea eax, [hInstanceKey]
push eax
push KEY_READ
push 0
push edi
push [hDeviceKey]
call [RegOpenKeyExW]
test eax, eax
jnz .devices_next
lea eax, [hConfigurationsKey]
push eax
push KEY_READ
push 0
push database.szConfigsKey
push [hInstanceKey]
call [RegOpenKeyExA]
test eax, eax
jnz .insts_next
; Check configurations of device instance
.configs_loop: mov [dwConfigurationsKeyWritable], eax
mov [dwConfigurationIdx], eax
.configs_iter: xor eax, eax
push 32
mov ecx, esp
push eax
push eax
push eax
push eax
push ecx
lea esi, [szConfigId]
push esi
push [dwConfigurationIdx]
inc [dwConfigurationIdx]
push [hConfigurationsKey]
call [RegEnumKeyExA]
test eax, eax
pop ecx
jnz .configs_end
mov byte [esi+ecx], 0
; Is numeric?
xor edx, edx
@@: cmp byte [esi+edx], '0'
jb .configs_iter
cmp byte [esi+edx], '9'
ja .configs_iter
inc edx
loop @b
call atoi
mov [dwConfigId], eax
lea eax, [hConfigurationKey]
push eax
push KEY_READ
push 0
push esi
push [hConfigurationsKey]
call [RegOpenKeyExA]
test eax, eax
jnz .configs_iter
; Finally, call the callback
push [pUser]
push [dwConfigId]
lea eax, [wszDeviceInstanceId]
push eax
push [hConfigurationKey]
call [fnFilter]
test eax, eax
jns .no_delete
.delete: pushf
push [hConfigurationKey]
call [RegCloseKey]
call .delete_hkey
popf
jnp .cleanup
test eax, eax
jnz .configs_iter
jmp .cleanup
.no_delete: jz .configs_next
mov eax, [hConfigurationKey]
mov dword [esp], eax
jmp .cleanup
.configs_next: push [hConfigurationKey]
call [RegCloseKey]
jmp .configs_iter
.configs_end: push [hConfigurationsKey]
call [RegCloseKey]
cmp [pwszDeviceInstanceId], 0
jnz .exit
.insts_next: push [hInstanceKey]
call [RegCloseKey]
jmp .insts_iter
.insts_end:
.devices_next: push [hDeviceKey]
call [RegCloseKey]
jmp .devices_iter
.devices_end: push [hDevicesKey]
call [RegCloseKey]
jmp .enum_iter
.cleanup: push [hConfigurationsKey]
call [RegCloseKey]
cmp [pwszDeviceInstanceId], 0
jnz .exit
push [hInstanceKey]
call [RegCloseKey]
push [hDeviceKey]
call [RegCloseKey]
push [hDevicesKey]
call [RegCloseKey]
.enum_end: push [hEnumKey]
call [RegCloseKey]
.exit: pop eax
pop edi
pop esi
ret
.delete_hkey: cmp [dwConfigurationsKeyWritable], 0
jnz .writable_hkey
lea eax, [wszDeviceInstanceId]
push eax
push database.szSensorKeyFmt
lea eax, [szKey]
push eax
call [wsprintfA]
add esp, 0ch
lea eax, [hConfigurationsKey]
push eax
push dword [eax]
call [RegCloseKey]
push KEY_READ + KEY_SET_VALUE
push 0
lea eax, [szKey]
push eax
push HKEY_LOCAL_MACHINE
call [RegOpenKeyExA]
test eax, eax
jz .writable_hkey
xor eax, eax
retn
.writable_hkey: lea eax, [szConfigId]
push eax
push [hConfigurationsKey]
call [RegDeleteKeyA]
xor eax, eax
inc eax
mov [dwConfigurationsKeyWritable], eax
retn
endp
proc InstallDatabaseForSensor guid:DWORD, wszDeviceInstanceId:DWORD
local dwConfigId:DWORD
local dwFound:DWORD
local hSensorKey:DWORD
local hDatabaseKey:DWORD
local sensor:WBIOSVC_SENSOR
local database:WBIOSVC_DATABASE
local szSensorKey[65+WINBIO_MAX_STRING_LEN+1+255+1 + 2]:BYTE
local szDatabaseKey[91 + 1 + 2]:BYTE
push [guid]
call IsDatabaseInstalled
test eax, eax
jz @f
mov eax, WINBIO_E_DATABASE_ALREADY_EXISTS
ret
@@: mov [dwConfigId], eax
mov [dwFound], eax
; Closures in x86 assembly, deal with it 8)
push ebp ; pUser
call .filter_end
;-------------------------------------------------------------------------;
virtual at esp
.hDbKey dd ?
.szDbKey db 91 + 1 + 2 dup (?)
.allocaSize = $ - $$
.edi dd ?
.ebp dd ?
.retAddr dd ?
.hKey dd ?
.device dd ?
.config dd ?
.user dd ?
end virtual
push ebp
push edi
sub esp, .allocaSize
mov ebp, [.user]
; Detemine configuration key (max + 1)
mov eax, [.config]
cmp eax, [dwConfigId]
jb @f
inc eax
mov [dwConfigId], eax
@@:
; Skip if suitable system sensor has been already found
cmp [dwFound], 0
jnz .exit
; We are interested only in system sensors ...
mov ecx, [.hKey]
push NULL
mov eax, esp
push 4
push esp
push eax
push 0
push RRF_RT_REG_DWORD
push database.szSystemSensor
push NULL
push ecx
call [RegGetValueA]
test eax, eax
pop ecx
pop eax
jnz .exit
cmp ecx, 4
jnz .exit
test eax, eax
jz .exit
; ... that have fingerprint database
mov ecx, database.szDatabasesKey.strlen
mov esi, database.szDatabasesKey
lea edi, [.szDbKey]
rep movsb
mov ax, '\{'
stosw
lea eax, [edi-1]
mov ecx, [.hKey]
push 36+1
push esp
push edi
push 0
push RRF_RT_REG_SZ
push database.szDatabaseId
push NULL
push ecx
call [RegGetValueA]
test eax, eax
pop ecx
jnz .exit
cmp ecx, 36+1
jnz .exit
lea edi, [edi+ecx-1]
mov al, '}'
stosw
lea eax, [.hDbKey]
lea edi, [.szDbKey]
push eax
push KEY_READ
push 0
push edi
push HKEY_LOCAL_MACHINE
call [RegOpenKeyExA]
test eax, eax
jnz .exit
mov ecx, [.hDbKey]
push 0
mov eax, esp
push 4
push esp
push eax
push 0
push RRF_RT_REG_DWORD
push database.szBiometricType
push NULL
push ecx
call [RegGetValueA]
test eax, eax
pop ecx
pop eax
jnz .exit_cleanly
cmp ecx, 4
jnz .exit_cleanly
test eax, WINBIO_TYPE_FINGERPRINT
jz .exit_cleanly
; System fingerprint sensor found.
; Read sensor & database configuration keys.
lea eax, [sensor]
push eax
push [.hKey + 4]
call ReadWbiosvcSensorKey
test eax, eax
jz .exit_cleanly
lea eax, [database]
push eax
push [.hDbKey + 4]
call ReadWbiosvcDatabaseKey
test eax, eax
jz .exit_cleanly
; Done
mov [dwFound], 1
.exit_cleanly: push [.hDbKey]
call [RegCloseKey]
.exit: xor eax, eax
add esp, .allocaSize
pop edi
pop ebp
retn 10h
;-------------------------------------------------------------------------;
.filter_end: push [wszDeviceInstanceId]
call IterSensorConfigurations
cmp [dwFound], 0
jnz .system_sensor_found
mov eax, WINBIO_E_INVALID_DEVICE_STATE
ret
.system_sensor_found:
; Adjust database & sensor configs for our private datbaase
xor eax, eax
push ebx
push esi
push edi
lea ebx, [database]
lea edi, [sensor]
mov [ebx + WBIOSVC_DATABASE.szConnectionString], al
mov [ebx + WBIOSVC_DATABASE.szFilePath], al
mov [edi + WBIOSVC_SENSOR.dwSystemSensor], eax
inc eax
mov [ebx + WBIOSVC_DATABASE.dwAutoCreate], eax
mov [ebx + WBIOSVC_DATABASE.dwAutoName], eax
mov al, 32
mov [ebx + WBIOSVC_DATABASE.dwInitialSize], eax
push 16/4
pop ecx
mov esi, [guid]
lea edi, [edi + WBIOSVC_SENSOR.guidDatabaseId]
rep movsd
.adjusted: ; Write adjusted configs to the registry
mov ecx, database.szDatabasesKey.strlen
mov esi, database.szDatabasesKey
lea edi, [szDatabaseKey]
rep movsb
mov al, '\'
stosb
push edi
push [guid]
call GuidToString
lea edi, [szSensorKey]
push [wszDeviceInstanceId]
push database.szSensorKeyFmt
push edi
call [wsprintfA]
add edi, eax
mov al, '\'
stosb
push [dwConfigId]
push database.szFormatD
push edi
call [wsprintfA]
add esp, 0ch + 0ch
push NULL
lea eax, [hDatabaseKey]
push eax
push NULL
push KEY_WRITE
push 0
push NULL
push 0
lea eax, [szDatabaseKey]
push eax
push HKEY_LOCAL_MACHINE
call [RegCreateKeyExA]
test eax, eax
jnz .finish
push NULL
lea eax, [hSensorKey]
push eax
push NULL
push KEY_WRITE
push 0
push NULL
push 0
lea eax, [szSensorKey]
push eax
push HKEY_LOCAL_MACHINE
call [RegCreateKeyExA]
test eax, eax
jz @f
push eax
push [hDatabaseKey]
call [RegCloseKey]
lea eax, [szDatabaseKey]
push eax
push HKEY_LOCAL_MACHINE
call [RegDeleteKeyA]
pop eax
jmp .finish
@@:
lea eax, [database]
push eax
push [hDatabaseKey]
call SaveWbiosvcDatabaseKey
lea eax, [sensor]
push eax
push [hSensorKey]
call SaveWbiosvcSensorKey
push [hDatabaseKey]
push [hSensorKey]
call [RegCloseKey]
call [RegCloseKey]
; WinBio service restart required to use the registered database
call WbioSrvcRestart
xor eax, eax
.finish: pop edi
pop esi
pop ebx
ret
endp
proc GetDatabaseSensorDeviceInstanceId guid:DWORD, wszDeviceInstanceId:DWORD
mov eax, [wszDeviceInstanceId]
mov word [eax], 0
push ebp ; pUser
call .filter_end
;-------------------------------------------------------------------------;
virtual at esp
.guid db 16 dup (?)
.szGuid db 36+1 + 3 dup (?)
.allocaSize = $ - $$
.edi dd ?
.esi dd ?
.ebp dd ?
.retAddr dd ?
.hKey dd ?
.device dd ?
.config dd ?
.user dd ?
end virtual
push ebp
push esi
push edi
sub esp, .allocaSize
mov ebp, [.user]
lea eax, [.szGuid]
mov ecx, [.hKey]
push 36+1
push esp
push eax
push 0
push RRF_RT_REG_SZ
push database.szDatabaseId
push NULL
push ecx
call [RegGetValueA]
test eax, eax
pop ecx
jnz .mismatch
cmp ecx, 36+1
jnz .mismatch
lea ecx, [.szGuid]
push esp ;.guid
push ecx
call StringToGuid
test eax, eax
jz .mismatch
mov ecx, 16
mov esi, esp ;lea esi, [.guid]
mov edi, [guid]
repz cmpsb
jnz .mismatch
mov esi, [.device]
mov edi, [wszDeviceInstanceId]
@@: lodsw
stosw
test ax, ax
jnz @b
.match: xor eax, eax
inc eax
jmp @f
.mismatch: xor eax, eax
@@: add esp, .allocaSize
pop edi
pop esi
pop ebp
retn 10h
;-------------------------------------------------------------------------;
.filter_end: push NULL
call IterSensorConfigurations
test eax, eax
jz .exit
push eax
call [RegCloseKey]
push 1
pop eax
.exit: ret
endp
proc IsDatabaseInstalled guid:DWORD
local wszDeviceInstanceId[WINBIO_MAX_STRING_LEN]:WORD
lea eax, [wszDeviceInstanceId]
push eax
push [guid]
call GetDatabaseSensorDeviceInstanceId
ret
endp
proc InstallDatabase guid:DWORD
local pUnits:DWORD
local dwCount:DWORD
push ebx
push esi
push edi
push [guid]
call IsDatabaseInstalled
test eax, eax
mov eax, WINBIO_E_DATABASE_ALREADY_EXISTS
jnz .fail
.retry: lea eax, [dwCount]
push eax
lea eax, [pUnits]
push eax
push WINBIO_TYPE_FINGERPRINT
call [WinBioEnumBiometricUnits]
cmp eax, RPC_S_SERVER_TOO_BUSY
jz .retry
test eax, eax
jnz .fail
push [dwCount]
push [pUnits]
call SensorSelectDialog
test eax, eax
jnz .got_sensor
mov eax, WINBIO_E_CANCELED
jmp .fail_and_free
.got_sensor: push [eax + WINBIO_UNIT_SCHEMA.wszDeviceInstanceId]
push [guid]
call InstallDatabaseForSensor
test eax, eax
jnz .fail_and_free
.success: xor eax, eax
.fail_and_free: push eax
push [pUnits]
call [WinBioFree]
pop eax
.fail: pop edi
pop esi
pop ebx
ret
endp
proc UninstallDatabase guid:DWORD
local szFilePath[MAX_PATH+4]:BYTE
local szSubKey[40]:BYTE
local szGUID[39+1]:BYTE
local hKey:DWORD
local hDatabasesKey:DWORD
push esi
push edi
.purge_sensor: push [guid] ; user data
call .filter_end
;-------------------------------------------------------------------------;
virtual at esp
.guid db 16 dup (?)
.szGuid db 39+1 dup(?)
.allocaSize = $ - $$
.edi dd ?
.esi dd ?
.rc dd ?
.retAddr dd ?
.hKey dd ?
.device dd ?
.config dd ?
.user dd ?
end virtual
xor eax, eax
push eax
push esi
push edi
sub esp, .allocaSize
mov ecx, [.hKey]
lea esi, [.szGuid]
mov edi, [.user]
push 40
push esp
push esi
push eax
push RRF_RT_REG_SZ
push database.szDatabaseId
push eax
push ecx
call [RegGetValueA]