-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreversed_driver.c
More file actions
4444 lines (4292 loc) · 108 KB
/
reversed_driver.c
File metadata and controls
4444 lines (4292 loc) · 108 KB
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
/* This file has been generated by the Hex-Rays decompiler.
Copyright (c) 2007-2017 Hex-Rays <[email protected]>
Detected compiler: GNU C++
*/
#include <defs.h>
//-------------------------------------------------------------------------
// Function declarations
__int64 __fastcall ParseATR(__int64 a1, _BYTE *a2, signed int a3);
__int64 __fastcall GetCurrentMode(__int64 a1);
__int64 __fastcall GetSpecificModeProtocol(__int64 a1);
__int64 __fastcall GetfirstOfferedProtocol(__int64 a1);
signed __int64 GetT1CWI();
signed __int64 GetT1BWI();
__int64 __fastcall GetT1IFSC(__int64 a1);
__int64 __fastcall GetDi(__int64 a1);
__int64 __fastcall Getfi(__int64 a1);
__int64 __fastcall GetN(__int64 a1);
__int64 __fastcall GetT1EDC(__int64 a1);
float __fastcall GetEtu(__int64 a1);
__int64 __fastcall GetCWT(__int64 a1, __m128 a2);
__int64 __fastcall GetBWT(__int64 a1);
__int64 __fastcall GetT0CWT(unsigned __int8 *a1);
signed __int64 __fastcall csum_lrc_compute(__int64 a1, __int64 a2, _BYTE *a3);
signed __int64 __fastcall csum_crc_compute(__int64 a1, __int64 a2, _BYTE *a3);
void __fastcall ReaderInitialize(__int64 a1, int a2);
__int64 IFDHCreateChannel();
__int64 __fastcall IFDHCreateChannelByName(unsigned int a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6);
__int64 __fastcall closeDriver(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6);
__int64 __fastcall IFDHCloseChannel(unsigned int a1);
__int64 __fastcall IFDHGetCapabilities(unsigned int a1, signed int a2, _DWORD *a3, _BYTE *a4);
__int64 __fastcall IFDHSetCapabilities(unsigned int a1);
__int64 IFDHSetProtocolParameters();
__int64 __fastcall IFDHPowerICC(unsigned int Lun, int Action, __int64 Atr, _DWORD *AtrLength); // idb
signed __int64 __fastcall GetDataBlock(int a1, __int64 a2, _BYTE *a3);
signed __int64 __fastcall EvaluteStatus(unsigned int a1, char a2, _BYTE *a3, char a4);
__int64 __fastcall IFDHTransmitToICC(unsigned int a1, int a2, __int64 a3, unsigned int a4, _WORD *a5, _DWORD *a6);
__int64 __fastcall IFDHControl(unsigned int a1, _BYTE *a2, unsigned __int8 *a3, int a4, void *a5, __int64 a6, _DWORD *a7);
__int64 __fastcall IFDHICCPresence(unsigned int a1);
__int64 __fastcall t1_init(__int64 a1);
signed __int64 __fastcall t1_set_defaults(__int64 a1);
signed __int64 __fastcall t1_set_param(__int64 a1, int a2, int a3);
__int64 __fastcall t1_compute_checksum(__int64 a1, __int64 a2, __int64 a3);
void __fastcall t1_set_checksum(__int64 a1, int a2);
signed __int64 __fastcall t1_block_type(unsigned __int8 a1);
__int64 __fastcall t1_seq(unsigned int a1);
__int64 __fastcall t1_build(__int64 a1, _BYTE *a2, unsigned int a3, unsigned __int8 a4, __int64 a5, _QWORD *a6);
__int64 __fastcall cur_buf_avail(__int64 a1);
__int64 __fastcall cur_buf_head(__int64 a1);
signed __int64 __fastcall t1_rebuild(__int64 a1, _DWORD *a2);
__int64 __fastcall cur_buf_init(_QWORD *a1, __int64 a2, int a3);
void __fastcall cur_buf_set(__int64 a1, __int64 a2, int a3);
signed __int64 __fastcall cur_buf_get(__int64 a1, void *a2, size_t a3);
__int64 __fastcall cur_buf_put(__int64 a1, const void *a2, size_t a3);
__int64 __fastcall cur_buf_putc(__int64 a1, char a2);
void __fastcall tds_log_msg();
void tds_log_xxd();
void __fastcall lock_mutex(__int64 a1);
void __fastcall unlock_mutex(__int64 a1);
void __fastcall cancel_lock_mutex(__int64 a1);
void __fastcall cancel_unlock_mutex(__int64 a1);
__int64 __fastcall PCSC_GetCardStatus(__int64 device, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6); // idb
__int64 __fastcall read_response(__int64 a1, _BYTE *a2, __int64 a3, unsigned int a4, unsigned int *a5, __int64 a6);
__int64 __fastcall write_command(__int64 a1, __int64 a2, __int64 a3, int a4);
__int64 __fastcall ABNED_Vendor_Transmit_Receive(__int64 a1, __int64 a2, __int64 a3, int a4, _BYTE *a5, __int64 a6, unsigned int a7, unsigned int *a8);
__int64 __fastcall PCSC_CAP_SendAndReceive(__int64 a1, __int64 a2, unsigned int a3, _BYTE *a4, _DWORD *a5, __int64 a6);
__int64 __fastcall PCSC_ABNTransmit(__int64 a1, __int64 a2, unsigned int a3, _BYTE *a4, _DWORD *a5);
__int64 __fastcall CardPowerOn(__int64 a1);
__int64 __fastcall CardPowerOff(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6);
__int64 __fastcall PCSC_CardPower(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6);
signed __int64 __fastcall T0CmdParsing(__int64 a1, unsigned int a2, _DWORD *a3);
void *__fastcall Read_NamedPipeThreadRoutine(void *a1);
// __int64 __usercall UsbIo_Write@<rax>(__int64 a1@<rax>, __int64 a2@<rdi>, __int64 a3@<rsi>, __int64 a4@<r9>);
// __int64 __usercall UsbIo_CloseDeviceAndInterface@<rax>(__int64 a1@<rax>, __int64 a2@<rdi>);
__int64 __fastcall Notify_Close_NamedPipe(__int64 a1);
void __fastcall UsbIo_AsynReadCompletionRoutine(__int64 a1, signed int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6);
// void __usercall UsbIo_SetAsynRead(__int64 a1@<rax>, __int64 a2@<rdi>, __int64 a3@<r9>);
__int64 __fastcall UsbIo_Read(__int64 a1, _QWORD *a2);
void *__fastcall UsbIo_ThreadRoutine(void *a1);
void __fastcall MySleepCallBack(__int64 a1, __int64 a2, int a3, __int64 a4);
void *__fastcall UsbIo_DetectSleepNotification(void *a1);
// __int64 __usercall DetectSleepNotification@<rax>(void *a1@<rdi>, struct _opaque_pthread_t *a2@<rax>);
// __int64 __usercall UsbIo_CreateThread@<rax>(void *a1@<rdi>, struct _opaque_pthread_t *a2@<rax>);
// __int64 __usercall Read_Create_NamedPipeThread@<rax>(void *a1@<rdi>, struct _opaque_pthread_t *a2@<rax>);
void __fastcall UsbIo_GetPipes(unsigned int a1, __int64 a2, __int64 a3);
void __fastcall UsbIo_GetInterface(unsigned int a1, __int64 a2, __int64 a3);
__int64 __fastcall UsbIo_GetDevice(unsigned int a1, __int64 a2, __int64 a3);
__int64 __fastcall UsbIo_Open(__int64 a1, __int64 a2, const char *a3, __int64 a4, __int64 a5, __int64 a6);
__int64 __fastcall UsbIo_Close(__int64 a1);
// __int64 __fastcall CFDictionaryAddValue(_QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall CFDictionarySetValue(_QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall CFNumberCreate(_QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall CFRelease(_QWORD); weak
// __int64 __fastcall CFRetain(_QWORD, _QWORD); weak
// __int64 __fastcall CFRunLoopAddSource(_QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall CFRunLoopGetCurrent(_QWORD); weak
// __int64 __fastcall CFRunLoopRun(_QWORD, _QWORD); weak
// __int64 __fastcall CFUUIDGetConstantUUIDWithBytes(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall CFUUIDGetUUIDBytes(_QWORD); weak
// __int64 __fastcall IOAllowPowerChange(_QWORD, _QWORD); weak
// __int64 __fastcall IOCreatePlugInInterfaceForService(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall IODestroyPlugInInterface(_QWORD); weak
// __int64 __fastcall IOIteratorNext(_QWORD, _QWORD); weak
// __int64 __fastcall IOMasterPort(_QWORD, _QWORD); weak
// __int64 __fastcall IONotificationPortCreate(_QWORD); weak
// __int64 __fastcall IONotificationPortGetRunLoopSource(_QWORD); weak
// __int64 __fastcall IOObjectRelease(_QWORD); weak
// __int64 __fastcall IORegisterForSystemPower(_QWORD, _QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall IOServiceAddMatchingNotification(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall IOServiceGetMatchingServices(_QWORD, _QWORD, _QWORD); weak
// __int64 __fastcall IOServiceMatching(_QWORD); weak
// __int64 __fastcall __bzero(_QWORD, _QWORD); weak
// int *__error(void);
// __int64 __fastcall __memcpy_chk(_QWORD, _QWORD, _QWORD, _QWORD); weak
// int __cdecl close(int);
// void __cdecl free(void *);
// kern_return_t __cdecl mach_port_deallocate(ipc_space_t task, mach_port_name_t name);
// void *__cdecl malloc(size_t);
// void *__cdecl memcpy(void *, const void *, size_t);
// int __cdecl mkfifo(const char *, mode_t);
// int open(const char *, int, ...);
// int printf(const char *, ...);
// int __cdecl pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
// int __cdecl pthread_cond_signal(pthread_cond_t *);
// int __cdecl pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
// int __cdecl pthread_create(pthread_t *, const pthread_attr_t *, void *(__cdecl *)(void *), void *);
// int __cdecl pthread_mutex_destroy(pthread_mutex_t *);
// int __cdecl pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
// int __cdecl pthread_mutex_lock(pthread_mutex_t *);
// int __cdecl pthread_mutex_unlock(pthread_mutex_t *);
// int __cdecl putchar(int);
// ssize_t __cdecl read(int, void *, size_t);
// int __cdecl strncmp(const char *, const char *, size_t);
// mode_t __cdecl umask(mode_t);
// int __cdecl usleep(useconds_t);
// ssize_t __cdecl write(int, const void *, size_t);
//-------------------------------------------------------------------------
// Data declarations
void *__ptr32 off_324C[5] =
{
(void *__ptr32 )0xFFFFFBF1LL,
(void *__ptr32 )0xFFFFFBFCLL,
(void *__ptr32 )0xFFFFFC2CLL,
(void *__ptr32 )0xFFFFFB35LL,
(void *__ptr32 )0xFFFFFB35LL
}; // weak
signed int fi[16] = { 372, 372, 558, 744, 1116, 1488, 1860, 1, 1, 512, 768, 1024, 1536, 2048, 1, 1 }; // idb
signed int di[16] = { 1, 1, 2, 4, 8, 16, 32, 1, 12, 20, 1, 1, 1, 1, 1, 1 }; // idb
_WORD crctab[294] =
{
0,
4489,
8978,
12955,
17956,
22445,
25910,
29887,
35912,
40385,
44890,
48851,
51820,
56293,
59774,
63735,
4225,
264,
13203,
8730,
22181,
18220,
30135,
25662,
40137,
36160,
49115,
44626,
56045,
52068,
63999,
59510,
8450,
12427,
528,
5017,
26406,
30383,
17460,
21949,
44362,
48323,
36440,
40913,
60270,
64231,
51324,
55797,
12675,
8202,
4753,
792,
30631,
26158,
21685,
17724,
48587,
44098,
40665,
36688,
64495,
60006,
55549,
51572,
16900,
21389,
24854,
28831,
1056,
5545,
10034,
14011,
52812,
57285,
60766,
64727,
34920,
39393,
43898,
47859,
21125,
17164,
29079,
24606,
5281,
1320,
14259,
9786,
57037,
53060,
64991,
60502,
39145,
35168,
48123,
43634,
25350,
29327,
16404,
20893,
9506,
13483,
1584,
6073,
61262,
65223,
52316,
56789,
43370,
47331,
35448,
39921,
29575,
25102,
20629,
16668,
13731,
9258,
5809,
1848,
65487,
60998,
56541,
52564,
47595,
43106,
39673,
35696,
33800,
38273,
42778,
46739,
49708,
54181,
57662,
61623,
2112,
6601,
11090,
15067,
20068,
24557,
28022,
31999,
38025,
34048,
47003,
42514,
53933,
49956,
61887,
57398,
6337,
2376,
15315,
10842,
24293,
20332,
32247,
27774,
42250,
46211,
34328,
38801,
58158,
62119,
49212,
53685,
10562,
14539,
2640,
7129,
28518,
32495,
19572,
24061,
46475,
41986,
38553,
34576,
62383,
57894,
53437,
49460,
14787,
10314,
6865,
2904,
32743,
28270,
23797,
19836,
50700,
55173,
58654,
62615,
32808,
37281,
41786,
45747,
19012,
23501,
26966,
30943,
3168,
7657,
12146,
16123,
54925,
50948,
62879,
58390,
37033,
33056,
46011,
41522,
23237,
19276,
31191,
26718,
7393,
3432,
16371,
11898,
59150,
63111,
50204,
54677,
41258,
45219,
33336,
37809,
27462,
31439,
18516,
23005,
11618,
15595,
3696,
8185,
63375,
58886,
54429,
50452,
45483,
40994,
37561,
33584,
31687,
27214,
22741,
18780,
15843,
11370,
7921,
3960,
41984,
3080,
57092,
20480,
50,
1188,
1792,
160,
0,
377,
0,
1188,
2572,
37587,
240,
294,
0,
256,
0,
0,
0,
0,
0,
0,
41984,
4,
40971,
0,
2051,
0,
16,
1,
4736,
256,
4736,
258,
4736,
259
}; // idb
_BYTE ReaderData[896]; // idb
__int64 gBuffer; // weak
__int64 gNotifyPort; // weak
_UNKNOWN gSendAsynReadIter; // weak
mach_port_name_t masterPort; // idb
char gContion; // weak
int root_port; // weak
// extern _UNKNOWN kCFAllocatorDefault; weak
// extern _UNKNOWN kCFRunLoopCommonModes; weak
// extern _UNKNOWN kCFRunLoopDefaultMode; weak
// extern _UNKNOWN __stack_chk_guard; weak
// extern mach_port_t mach_task_self_;
//----- (0000000000000AC0) ----------------------------------------------------
__int64 __fastcall ParseATR(__int64 a1, _BYTE *a2, signed int a3)
{
signed int v3; // er12
_BYTE *v4; // r15
unsigned int v5; // er14
char v7; // al
char v8; // dl
signed __int64 v9; // rax
unsigned __int64 v10; // rcx
int v11; // esi
signed int v12; // esi
char v13; // si
char v14; // si
char v15; // si
signed __int64 v16; // rdx
char v17; // cl
char v18; // cl
v3 = a3;
v4 = a2;
__bzero(a1 + 288, 160LL);
v5 = -11;
if ( v3 < 2 )
return v5;
v7 = *a2;
*(_BYTE *)(a1 + 328) = *a2;
*(_BYTE *)(a1 + 288) = v7;
if ( v7 != 63 && v7 != 59 )
{
if ( v7 != 3 )
return v5;
*(_BYTE *)(a1 + 328) = 63;
}
v8 = a2[1];
*(_BYTE *)(a1 + 329) = v8;
*(_BYTE *)(a1 + 289) = v8;
*(_DWORD *)(a1 + 444) = v8 & 0xF;
*(_BYTE *)(a1 + 421) = 0;
LODWORD(v9) = 1;
v10 = 0LL;
while ( 1 )
{
if ( v8 & 0x10 )
{
if ( (signed int)v9 >= v3 )
return v5;
v9 = (signed int)v9 + 1LL;
v13 = v4[v9];
*(_BYTE *)(a1 + 8 * v10 + 364) = v13;
*(_BYTE *)(a1 + 8 * v10 + 365) = 1;
*(_BYTE *)(a1 + v9 + 288) = v13;
}
else
{
*(_BYTE *)(a1 + 8 * v10 + 365) = 0;
}
if ( v8 & 0x20 )
{
if ( (signed int)v9 >= v3 )
return v5;
v9 = (signed int)v9 + 1LL;
v14 = v4[v9];
*(_BYTE *)(a1 + 8 * v10 + 366) = v14;
*(_BYTE *)(a1 + 8 * v10 + 367) = 1;
*(_BYTE *)(a1 + v9 + 288) = v14;
}
else
{
*(_BYTE *)(a1 + 8 * v10 + 367) = 0;
}
if ( v8 & 0x40 )
{
if ( (signed int)v9 >= v3 )
return v5;
v9 = (signed int)v9 + 1LL;
v15 = v4[v9];
*(_BYTE *)(a1 + 8 * v10 + 368) = v15;
*(_BYTE *)(a1 + 8 * v10 + 369) = 1;
*(_BYTE *)(a1 + v9 + 288) = v15;
}
else
{
*(_BYTE *)(a1 + 8 * v10 + 369) = 0;
}
if ( v8 >= 0 )
break;
if ( (signed int)v9 >= v3 )
return v5;
v9 = (signed int)v9 + 1LL;
v8 = v4[v9];
*(_BYTE *)(a1 + 8 * v10 + 370) = v8;
*(_BYTE *)(a1 + 8 * v10 + 371) = 1;
*(_BYTE *)(a1 + v9 + 288) = v8;
v11 = v8 & 0xF;
*(_DWORD *)(a1 + 4 * v10 + 336) = v11;
*(_BYTE *)(a1 + 421) = (_BYTE)v11 != 0;
if ( v10 > 6 )
return v5;
++v10;
if ( v8 & 0xF )
{
if ( v11 == 1 )
{
v12 = 2;
goto LABEL_14;
}
}
else
{
v12 = 1;
LABEL_14:
*(_DWORD *)(a1 + 332) |= v12;
}
}
if ( !(_DWORD)v10 )
*(_BYTE *)(a1 + 332) |= 1u;
*(_BYTE *)(a1 + 8 * v10 + 371) = 0;
*(_DWORD *)(a1 + 424) = v10 + 1;
if ( *(_DWORD *)(a1 + 444) < 0 )
{
LABEL_34:
if ( *(_BYTE *)(a1 + 421) )
{
if ( (signed int)v9 >= v3 )
return v5;
v9 = (signed int)v9 + 1LL;
v18 = v4[v9];
*(_BYTE *)(a1 + 420) = v18;
*(_BYTE *)(a1 + v9 + 288) = v18;
}
*(_DWORD *)(a1 + 324) = v9;
v5 = 0;
tds_log_msg();
return v5;
}
v9 = (signed int)v9;
v16 = -1LL;
while ( v9 < v3 )
{
v17 = v4[v9 + 1];
*(_BYTE *)(a1 + v16 + 429) = v17;
*(_BYTE *)(a1 + v9++ + 289) = v17;
if ( ++v16 >= *(signed int *)(a1 + 444) )
goto LABEL_34;
}
return v5;
}
// 7224: using guessed type __int64 __fastcall __bzero(_QWORD, _QWORD);
//----- (0000000000000D1B) ----------------------------------------------------
__int64 __fastcall GetCurrentMode(__int64 a1)
{
return (unsigned int)(*(_BYTE *)(a1 + 85) < 1u) + 1;
}
//----- (0000000000000D2D) ----------------------------------------------------
__int64 __fastcall GetSpecificModeProtocol(__int64 a1)
{
__int64 result; // rax
if ( *(_BYTE *)(a1 + 85) )
LOBYTE(result) = *(_BYTE *)(a1 + 84) & 0xF;
else
LOBYTE(result) = 20;
return (unsigned __int8)result;
}
//----- (0000000000000D45) ----------------------------------------------------
__int64 __fastcall GetfirstOfferedProtocol(__int64 a1)
{
__int64 result; // rax
if ( *(_BYTE *)(a1 + 83) )
LOBYTE(result) = *(_BYTE *)(a1 + 82) & 0xF;
else
LOBYTE(result) = 0;
return (unsigned __int8)result;
}
//----- (0000000000000D5D) ----------------------------------------------------
signed __int64 GetT1CWI()
{
return 5LL;
}
//----- (0000000000000D68) ----------------------------------------------------
signed __int64 GetT1BWI()
{
return 4LL;
}
//----- (0000000000000D73) ----------------------------------------------------
__int64 __fastcall GetT1IFSC(__int64 a1)
{
signed __int64 v1; // rdx
unsigned __int8 v2; // si
signed __int64 v3; // rcx
v1 = *(signed int *)(a1 + 136);
v2 = 32;
if ( v1 >= 2 )
{
v3 = 1LL;
while ( !*(_BYTE *)(a1 + 8 * v3 + 83) || (*(_BYTE *)(a1 + 8 * v3 + 82) & 0xF) != 1 )
{
if ( ++v3 >= v1 )
return v2;
}
if ( *(_BYTE *)(a1 + 8 * v3 + 85) )
v2 = *(_BYTE *)(a1 + 8 * v3 + 84);
}
return v2;
}
//----- (0000000000000DB9) ----------------------------------------------------
__int64 __fastcall GetDi(__int64 a1)
{
__int64 result; // rax
if ( *(_BYTE *)(a1 + 77) )
LOBYTE(result) = *(_BYTE *)(a1 + 76) & 0xF;
else
LOBYTE(result) = 1;
return (unsigned __int8)result;
}
//----- (0000000000000DD1) ----------------------------------------------------
__int64 __fastcall Getfi(__int64 a1)
{
__int64 result; // rax
if ( *(_BYTE *)(a1 + 77) )
LOBYTE(result) = *(_BYTE *)(a1 + 76) >> 4;
else
LOBYTE(result) = 1;
return (unsigned __int8)result;
}
//----- (0000000000000DEA) ----------------------------------------------------
__int64 __fastcall GetN(__int64 a1)
{
__int64 result; // rax
if ( *(_BYTE *)(a1 + 81) )
LOBYTE(result) = *(_BYTE *)(a1 + 80);
else
LOBYTE(result) = 0;
return (unsigned __int8)result;
}
//----- (0000000000000E00) ----------------------------------------------------
__int64 __fastcall GetT1EDC(__int64 a1)
{
signed __int64 v1; // rcx
__int64 result; // rax
signed __int64 v3; // rbx
__int64 v4; // r9
v1 = *(signed int *)(a1 + 136);
LOBYTE(result) = 1;
if ( v1 >= 2 )
{
v3 = 1LL;
while ( !*(_BYTE *)(a1 + 8 * v3 + 83) || (*(_BYTE *)(a1 + 8 * v3 + 82) & 0xF) != 1 )
{
if ( ++v3 >= v1 )
return (unsigned __int8)result;
}
if ( *(_BYTE *)(a1 + 8 * v3 + 89) )
{
v4 = *(unsigned __int8 *)(a1 + 8 * v3 + 88);
tds_log_msg();
LOBYTE(result) = (*(_BYTE *)(a1 + 8 * v3 + 88) & 1) + 1;
}
}
return (unsigned __int8)result;
}
//----- (0000000000000E82) ----------------------------------------------------
float __fastcall GetEtu(__int64 a1)
{
unsigned __int8 v1; // bl
__int64 v2; // rax
unsigned __int8 v3; // bl
signed int v4; // ecx
float result; // xmm0_4
if ( *(_BYTE *)(a1 + 77) )
{
v1 = *(_BYTE *)(a1 + 76);
LOBYTE(v2) = v1 >> 4;
v3 = v1 & 0xF;
if ( !(v3 | (unsigned __int8)v2) )
{
v3 = 0;
tds_log_msg();
LOBYTE(v2) = 0;
}
}
else
{
v3 = 1;
LOBYTE(v2) = 1;
}
v2 = (unsigned __int8)v2;
v4 = 15999;
if ( _bittest(&v4, (unsigned __int8)v2) )
result = (float)((float)fi[v2] / (float)di[v3]) / 3000000.0;
else
result = 0.000124;
return result;
}
//----- (0000000000000F14) ----------------------------------------------------
__int64 __fastcall GetCWT(__int64 a1, __m128 a2)
{
__m128 v2; // xmm2
__m128 v3; // xmm3
__m128 v4; // xmm3
*(double *)a2.m128_u64 = GetEtu(a1) * 43.0 * 1000.0 + 0.5;
a2.m128_f32[0] = *(double *)a2.m128_u64;
v2.m128_f32[0] = 1.0 - a2.m128_f32[0];
v3.m128_i32[0] = 0;
v4 = _mm_cmplt_ss(v3, v2);
return (unsigned int)(signed int)COERCE_FLOAT(*(unsigned __int128 *)&_mm_andnot_ps(v4, a2) | v4.m128_i32[0] & 0x3F800000);
}
//----- (0000000000000F63) ----------------------------------------------------
__int64 __fastcall GetBWT(__int64 a1)
{
float v1; // xmm0_4
v1 = ((float)(GetEtu(a1) * 11.0) + 1.90464) * 1000.0;
return (unsigned int)(signed int)v1;
}
//----- (0000000000000F92) ----------------------------------------------------
__int64 __fastcall GetT0CWT(unsigned __int8 *a1)
{
unsigned __int64 v1; // rax
float v2; // xmm0_4
if ( a1[77] )
v1 = (unsigned __int64)a1[76] >> 4;
else
v1 = 1LL;
if ( a1[89] )
v2 = (float)(960 * a1[88]);
else
v2 = 9600.0;
return (unsigned int)(signed int)(float)((float)((float)((float)fi[v1] * v2) / 3000000.0) * 1000.0);
}
//----- (0000000000000FEF) ----------------------------------------------------
signed __int64 __fastcall csum_lrc_compute(__int64 a1, __int64 a2, _BYTE *a3)
{
__int64 v3; // rcx
char v4; // al
if ( a2 )
{
v3 = 0LL;
v4 = 0;
do
v4 ^= *(_BYTE *)(a1 + v3++);
while ( a2 != v3 );
}
else
{
v4 = 0;
}
if ( a3 )
*a3 = v4;
return 1LL;
}
//----- (0000000000001019) ----------------------------------------------------
signed __int64 __fastcall csum_crc_compute(__int64 a1, __int64 a2, _BYTE *a3)
{
signed __int16 v3; // ax
__int64 v4; // rcx
v3 = -1;
if ( a2 )
{
v4 = 0LL;
do
v3 = HIBYTE(v3) ^ crctab[*(unsigned __int8 *)(a1 + v4++) ^ (unsigned __int8)v3];
while ( a2 != v4 );
}
if ( a3 )
{
*a3 = HIBYTE(v3);
a3[1] = v3;
}
return 2LL;
}
//----- (0000000000001060) ----------------------------------------------------
void __fastcall ReaderInitialize(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rax
*(_QWORD *)(a1 + 160) = 34359738376LL;
*(_BYTE *)(a1 + 22) = 0;
*(_WORD *)(a1 + 24) = 1;
*(_DWORD *)(a1 + 4) = a2;
*(_DWORD *)a1 = 1;
*(_BYTE *)(a1 + 26) = 0;
tds_log_msg();
tds_log_msg();
tds_log_msg();
v2 = (pthread_mutex_t *)malloc(0x78uLL);
*(_QWORD *)(a1 + 176) = v2;
if ( pthread_mutex_init(v2, 0LL) )
{
tds_log_msg();
free(*(void **)(a1 + 176));
}
if ( pthread_cond_init((pthread_cond_t *)(*(_QWORD *)(a1 + 176) + 64LL), 0LL) )
{
tds_log_msg();
pthread_mutex_destroy(*(pthread_mutex_t **)(a1 + 176));
free(*(void **)(a1 + 176));
}
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 32), 0LL) )
tds_log_msg();
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 96), 0LL) )
tds_log_msg();
}
//----- (0000000000001224) ----------------------------------------------------
__int64 IFDHCreateChannel()
{
return 0LL;
}
//----- (000000000000122C) ----------------------------------------------------
__int64 __fastcall IFDHCreateChannelByName(unsigned int a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rbx
_BYTE *device; // r13
struct _opaque_pthread_t *v8; // rax
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
unsigned int v12; // er15
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // r9
struct _opaque_pthread_t *v17; // rax
struct _opaque_pthread_t *v18; // rax
__int64 v19; // rdx
__int64 v20; // rcx
__int64 v21; // r8
__int64 v22; // r9
v6 = a1 >> 16;
tds_log_msg();
tds_log_msg();
tds_log_msg();
device = &ReaderData[448 * v6];
ReaderInitialize((__int64)device, v6);
v12 = 612;
if ( (unsigned __int8)DetectSleepNotification(device, v8) )
{
if ( (unsigned __int8)UsbIo_Open((__int64)ReaderData, (__int64)device, a2, v9, v10, v11) )
{
ReaderData[448 * v6 + 21] = 1;
v17 = (struct _opaque_pthread_t *)PCSC_GetCardStatus((__int64)device, (__int64)device, v13, v14, v15, v16);
if ( !(_BYTE)v17 )
{
UsbIo_Close((__int64)device);
return v12;
}
v18 = (struct _opaque_pthread_t *)UsbIo_CreateThread(device, v17);
if ( !(_BYTE)v18 || !(unsigned __int8)Read_Create_NamedPipeThread(device, v18) )
{
closeDriver(a1, (__int64)device, v19, v20, v21, v22);
return v12;
}
v12 = 0;
}
tds_log_msg();
}
return v12;
}
//----- (000000000000139C) ----------------------------------------------------
__int64 __fastcall closeDriver(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
signed __int64 v6; // rbx
char v7; // al
v6 = 448LL * (a1 >> 16);
if ( *(_DWORD *)&ReaderData[v6 + 228] == 2 )
{
if ( (unsigned int)PCSC_CardPower((__int64)&ReaderData[v6], 1LL, a3, a4, a5, a6) )
tds_log_msg();
*(_DWORD *)&ReaderData[v6 + 324] = 0;
}
v7 = UsbIo_Close((__int64)&ReaderData[v6]);
LOBYTE(v6) = 1;
if ( !v7 )
{
LODWORD(v6) = 0;
tds_log_msg();
}
return (unsigned int)v6;
}
//----- (000000000000144C) ----------------------------------------------------
__int64 __fastcall IFDHCloseChannel(unsigned int a1)
{
unsigned int v1; // er14
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
v1 = 0;
tds_log_msg();
if ( (unsigned __int8)closeDriver(a1, (__int64)"%s:%d:%s() IFDHCloseChannel Lun = 0x%04x%04x IN", v2, v3, v4, v5) )
{
tds_log_msg();
}
else
{
tds_log_msg();
v1 = 612;
}
return v1;