about summary refs log tree commit diff stats
path: root/src/wrapped/wrappedlibssl3.c
blob: 658fd2fdd2751df8285da0f13c72ec30c060788c (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <dlfcn.h>

#include "wrappedlibs.h"

#include "debug.h"
#include "wrapper.h"
#include "bridge.h"
#include "librarian/library_private.h"
#include "x64emu.h"
#include "emu/x64emu_private.h"
#include "callback.h"
#include "librarian.h"
#include "box64context.h"
#include "emu/x64emu_private.h"

const char* libssl3Name = "libssl.so.3";
#define LIBNAME libssl3

#include "generated/wrappedlibssl3types.h"

#include "wrappercallback.h"

// utility functions
#define SUPER() \
GO(0)   \
GO(1)   \
GO(2)   \
GO(3)   \
GO(4)

// pem_passwd_cb
#define GO(A)   \
static uintptr_t my3_pem_passwd_cb_fct_##A = 0;                                                     \
static int my3_pem_passwd_cb_##A(void* buf, int size, int rwflag, void* password)                   \
{                                                                                                   \
    return (int)RunFunctionFmt(my3_pem_passwd_cb_fct_##A, "piip", buf, size, rwflag, password);     \
}
SUPER()
#undef GO
static void* find_pem_passwd_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_pem_passwd_cb_fct_##A == (uintptr_t)fct) return my3_pem_passwd_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_pem_passwd_cb_fct_##A == 0) {my3_pem_passwd_cb_fct_##A = (uintptr_t)fct; return my3_pem_passwd_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL pem_passwd_cb callback\n");
    return NULL;
}
static void* reverse_pem_passwd_cb_Fct(void* fct)
{
    if(!fct) return fct;
    if(CheckBridged(my_lib->w.bridge, fct))
        return (void*)CheckBridged(my_lib->w.bridge, fct);
    #define GO(A) if(my3_pem_passwd_cb_##A == fct) return (void*)my3_pem_passwd_cb_fct_##A;
    SUPER()
    #undef GO
    return (void*)AddBridge(my_lib->w.bridge, pFp, fct, 0, NULL);
}

// anonymous
#define GO(A)   \
static uintptr_t my3_anonymous_fct_##A = 0;                                     \
static void* my3_anonymous_##A(void* a, void* b, void* c, void *d)              \
{                                                                               \
    return (void*)RunFunctionFmt(my3_anonymous_fct_##A, "pppp", a, b, c, d);    \
}
SUPER()
#undef GO
static void* find_anonymous_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_anonymous_fct_##A == (uintptr_t)fct) return my3_anonymous_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_anonymous_fct_##A == 0) {my3_anonymous_fct_##A = (uintptr_t)fct; return my3_anonymous_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL anonymous callback\n");
    return NULL;
}


// verify
#define GO(A)   \
static uintptr_t my3_verify_fct_##A = 0;                            \
static int my3_verify_##A(int a, void* b)                           \
{                                                                   \
    return (int)RunFunctionFmt(my3_verify_fct_##A, "ip", a, b);     \
}
SUPER()
#undef GO
static void* find_verify_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_verify_fct_##A == (uintptr_t)fct) return my3_verify_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_verify_fct_##A == 0) {my3_verify_fct_##A = (uintptr_t)fct; return my3_verify_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL verify callback\n");
    return NULL;
}
static void* reverse_verify_Fct(void* fct)
{
    if(!fct) return fct;
    if(CheckBridged(my_lib->w.bridge, fct))
        return (void*)CheckBridged(my_lib->w.bridge, fct);
    #define GO(A) if(my3_verify_##A == fct) return (void*)my3_verify_fct_##A;
    SUPER()
    #undef GO
    return (void*)AddBridge(my_lib->w.bridge, iFip, fct, 0, NULL);
}

// ex_new
#define GO(A)   \
static uintptr_t my3_ex_new_fct_##A = 0;                                                        \
static void my3_ex_new_##A(void* parent, void* ptr, void* ad, int idx, long argl, void* argp)   \
{                                                                                               \
    RunFunctionFmt(my3_ex_new_fct_##A, "pppilp", parent, ptr, ad, idx, argl, argp);             \
}
SUPER()
#undef GO
static void* find_ex_new_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_ex_new_fct_##A == (uintptr_t)fct) return my3_ex_new_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_ex_new_fct_##A == 0) {my3_ex_new_fct_##A = (uintptr_t)fct; return my3_ex_new_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL ex_new callback\n");
    return NULL;
}

// ex_free
#define GO(A)   \
static uintptr_t my3_ex_free_fct_##A = 0;                                                       \
static void my3_ex_free_##A(void* parent, void* ptr, void* ad, int idx, long argl, void* argp)  \
{                                                                                               \
    RunFunctionFmt(my3_ex_free_fct_##A, "pppilp", parent, ptr, ad, idx, argl, argp);            \
}
SUPER()
#undef GO
static void* find_ex_free_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_ex_free_fct_##A == (uintptr_t)fct) return my3_ex_free_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_ex_free_fct_##A == 0) {my3_ex_free_fct_##A = (uintptr_t)fct; return my3_ex_free_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL ex_free callback\n");
    return NULL;
}

// ex_dup
#define GO(A)   \
static uintptr_t my3_ex_dup_fct_##A = 0;                                                            \
static int my3_ex_dup_##A(void* to, void* from, void* from_d, int idx, long argl, void* argp)       \
{                                                                                                   \
    return (int) RunFunctionFmt(my3_ex_dup_fct_##A, "pppilp", to, from, from_d, idx, argl, argp);   \
}
SUPER()
#undef GO
static void* find_ex_dup_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_ex_dup_fct_##A == (uintptr_t)fct) return my3_ex_dup_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_ex_dup_fct_##A == 0) {my3_ex_dup_fct_##A = (uintptr_t)fct; return my3_ex_dup_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL ex_dup callback\n");
    return NULL;
}

// client_cb
#define GO(A)   \
static uintptr_t my3_client_cb_fct_##A = 0;                                                                             \
static uint32_t my3_client_cb_##A(void* ssl, void* hint, void* identity, uint32_t id_len, void* psk, uint32_t psk_len)  \
{                                                                                                                       \
    return RunFunctionFmt(my3_client_cb_fct_##A, "pppupu", ssl, hint, identity, id_len, psk, psk_len);                  \
}
SUPER()
#undef GO
static void* find_client_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_client_cb_fct_##A == (uintptr_t)fct) return my3_client_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_client_cb_fct_##A == 0) {my3_client_cb_fct_##A = (uintptr_t)fct; return my3_client_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL client_cb callback\n");
    return NULL;
}

// proto_select
#define GO(A)   \
static uintptr_t my3_proto_select_fct_##A = 0;                                                          \
static int my3_proto_select_##A(void* s, void* out, void* outlen, void* in, uint32_t inlen, void* arg)  \
{                                                                                                       \
    return (int)RunFunctionFmt(my3_proto_select_fct_##A, "ppppup", s, out, outlen, in, inlen, arg);     \
}
SUPER()
#undef GO
static void* find_proto_select_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_proto_select_fct_##A == (uintptr_t)fct) return my3_proto_select_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_proto_select_fct_##A == 0) {my3_proto_select_fct_##A = (uintptr_t)fct; return my3_proto_select_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL proto_select callback\n");
    return NULL;
}

// client_cert
#define GO(A)   \
static uintptr_t my3_client_cert_fct_##A = 0;                               \
static int my3_client_cert_##A(void* a, void* b, void* c)                   \
{                                                                           \
    return (int)RunFunctionFmt(my3_client_cert_fct_##A, "ppp", a, b, c);    \
}
SUPER()
#undef GO
static void* find_client_cert_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_client_cert_fct_##A == (uintptr_t)fct) return my3_client_cert_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_client_cert_fct_##A == 0) {my3_client_cert_fct_##A = (uintptr_t)fct; return my3_client_cert_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL client_cert callback\n");
    return NULL;
}

// alpn_select_cb
#define GO(A)   \
static uintptr_t my3_alpn_select_cb_fct_##A = 0;                                                    \
static int my3_alpn_select_cb_##A(void* a, void* b, void* c, void* d, uint32_t e, void* f)          \
{                                                                                                   \
    return (int)RunFunctionFmt(my3_alpn_select_cb_fct_##A, "ppppup", a, b, c, d, e, f);             \
}
SUPER()
#undef GO
static void* find_alpn_select_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_alpn_select_cb_fct_##A == (uintptr_t)fct) return my3_alpn_select_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_alpn_select_cb_fct_##A == 0) {my3_alpn_select_cb_fct_##A = (uintptr_t)fct; return my3_alpn_select_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL alpn_select_cb callback\n");
    return NULL;
}
// keylog_cb
#define GO(A)   \
static uintptr_t my3_keylog_cb_fct_##A = 0;                 \
static void my3_keylog_cb_##A(void* ssl, void* line)        \
{                                                           \
    RunFunctionFmt(my3_keylog_cb_fct_##A, "pp", ssl, line); \
}
SUPER()
#undef GO
static void* find_keylog_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_keylog_cb_fct_##A == (uintptr_t)fct) return my3_keylog_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_keylog_cb_fct_##A == 0) {my3_keylog_cb_fct_##A = (uintptr_t)fct; return my3_keylog_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL keylog_cb callback\n");
    return NULL;
}
// msg_cb
#define GO(A)   \
static uintptr_t my3_msg_cb_fct_##A = 0;                                                \
static void my3_msg_cb_##A(int a, int b, int c, void* d, size_t e, void* f, void* g)    \
{                                                                                       \
    RunFunctionFmt(my3_msg_cb_fct_##A, "iiipLpp", a, b, c, d, e, f, g);                 \
}
SUPER()
#undef GO
static void* find_msg_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_msg_cb_fct_##A == (uintptr_t)fct) return my3_msg_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_msg_cb_fct_##A == 0) {my3_msg_cb_fct_##A = (uintptr_t)fct; return my3_msg_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL msg_cb callback\n");
    return NULL;
}
// info_cb
#define GO(A)   \
static uintptr_t my3_info_cb_fct_##A = 0;                   \
static void my3_info_cb_##A(void* a, int b, int c)          \
{                                                           \
    RunFunctionFmt(my3_info_cb_fct_##A, "pii", a, b, c);    \
}
SUPER()
#undef GO
static void* find_info_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my3_info_cb_fct_##A == (uintptr_t)fct) return my3_info_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my3_info_cb_fct_##A == 0) {my3_info_cb_fct_##A = (uintptr_t)fct; return my3_info_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for libSSL info_cb callback\n");
    return NULL;
}
// new_seesion_cb
#define GO(A)   \
static uintptr_t my_new_seesion_cb_fct_##A = 0;                         \
static int my_new_seesion_cb_##A(void* a, void* b)                      \
{                                                                       \
    return (int)RunFunctionFmt(my_new_seesion_cb_fct_##A, "pp", a, b);  \
}
SUPER()
#undef GO
static void* find_new_seesion_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_new_seesion_cb_fct_##A == (uintptr_t)fct) return my_new_seesion_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_new_seesion_cb_fct_##A == 0) {my_new_seesion_cb_fct_##A = (uintptr_t)fct; return my_new_seesion_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 new_seesion_cb callback\n");
    return NULL;
}
// psk_use_session_cb
#define GO(A)   \
static uintptr_t my_psk_use_session_cb_fct_##A = 0;                                     \
static int my_psk_use_session_cb_##A(void* a, void* b, void* c, void* d, void* e)       \
{                                                                                       \
    return (int)RunFunctionFmt(my_psk_use_session_cb_fct_##A, "ppppp", a, b, c, d, e);  \
}
SUPER()
#undef GO
static void* find_psk_use_session_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_psk_use_session_cb_fct_##A == (uintptr_t)fct) return my_psk_use_session_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_psk_use_session_cb_fct_##A == 0) {my_psk_use_session_cb_fct_##A = (uintptr_t)fct; return my_psk_use_session_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 psk_use_session_cb callback\n");
    return NULL;
}
// app_verify_cookie_cb
#define GO(A)   \
static uintptr_t my_app_verify_cookie_cb_fct_##A = 0;                               \
static int my_app_verify_cookie_cb_##A(void* a, void* b, uint32_t c)                \
{                                                                                   \
    return (int)RunFunctionFmt(my_app_verify_cookie_cb_fct_##A, "ppu", a, b, c);    \
}
SUPER()
#undef GO
static void* find_app_verify_cookie_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_app_verify_cookie_cb_fct_##A == (uintptr_t)fct) return my_app_verify_cookie_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_app_verify_cookie_cb_fct_##A == 0) {my_app_verify_cookie_cb_fct_##A = (uintptr_t)fct; return my_app_verify_cookie_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 app_verify_cookie_cb callback\n");
    return NULL;
}
// set_cookie_generate_cb
#define GO(A)   \
static uintptr_t my_set_cookie_generate_cb_fct_##A = 0;                             \
static int my_set_cookie_generate_cb_##A(void* a, void* b, void* c)                 \
{                                                                                   \
    return (int)RunFunctionFmt(my_set_cookie_generate_cb_fct_##A, "ppp", a, b, c);  \
}
SUPER()
#undef GO
static void* find_set_cookie_generate_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_set_cookie_generate_cb_fct_##A == (uintptr_t)fct) return my_set_cookie_generate_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_set_cookie_generate_cb_fct_##A == 0) {my_set_cookie_generate_cb_fct_##A = (uintptr_t)fct; return my_set_cookie_generate_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 set_cookie_generate_cb callback\n");
    return NULL;
}
// psk_server_cb
#define GO(A)   \
static uintptr_t my_psk_server_cb_fct_##A = 0;                                      \
static uint32_t my_psk_server_cb_##A(void* a, void* b, void* c, uint32_t d)         \
{                                                                                   \
    return (uint32_t)RunFunctionFmt(my_psk_server_cb_fct_##A, "pppu", a, b, c, d);  \
}
SUPER()
#undef GO
static void* find_psk_server_cb_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_psk_server_cb_fct_##A == (uintptr_t)fct) return my_psk_server_cb_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_psk_server_cb_fct_##A == 0) {my_psk_server_cb_fct_##A = (uintptr_t)fct; return my_psk_server_cb_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 psk_server_cb callback\n");
    return NULL;
}
// read_write
#define GO(A)   \
static uintptr_t my_read_write_fct_##A = 0;                             \
static int my_read_write_##A(void* a, void* b, int c)                   \
{                                                                       \
    return (int)RunFunctionFmt(my_read_write_fct_##A, "ppi", a, b, c);  \
}
SUPER()
#undef GO
static void* find_read_write_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_read_write_fct_##A == (uintptr_t)fct) return my_read_write_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_read_write_fct_##A == 0) {my_read_write_fct_##A = (uintptr_t)fct; return my_read_write_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 read_write callback\n");
    return NULL;
}
// puts
#define GO(A)   \
static uintptr_t my_puts_fct_##A = 0;                           \
static int my_puts_##A(void* a, void* b)                        \
{                                                               \
    return (int)RunFunctionFmt(my_puts_fct_##A, "pp", a, b);    \
}
SUPER()
#undef GO
static void* find_puts_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_puts_fct_##A == (uintptr_t)fct) return my_puts_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_puts_fct_##A == 0) {my_puts_fct_##A = (uintptr_t)fct; return my_puts_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 puts callback\n");
    return NULL;
}
// ctrl
#define GO(A)   \
static uintptr_t my_ctrl_fct_##A = 0;                                   \
static long my_ctrl_##A(void* a, int b, long c, void* d)                \
{                                                                       \
    return (long)RunFunctionFmt(my_ctrl_fct_##A, "pilp", a, b, c, d);   \
}
SUPER()
#undef GO
static void* find_ctrl_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_ctrl_fct_##A == (uintptr_t)fct) return my_ctrl_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_ctrl_fct_##A == 0) {my_ctrl_fct_##A = (uintptr_t)fct; return my_ctrl_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 ctrl callback\n");
    return NULL;
}
// create_destroy
#define GO(A)   \
static uintptr_t my_create_destroy_fct_##A = 0;                     \
static int my_create_destroy_##A(void* a)                           \
{                                                                   \
    return (int)RunFunctionFmt(my_create_destroy_fct_##A, "p", a);  \
}
SUPER()
#undef GO
static void* find_create_destroy_Fct(void* fct)
{
    if(!fct) return NULL;
    void* p;
    if((p = GetNativeFnc((uintptr_t)fct))) return p;
    #define GO(A) if(my_create_destroy_fct_##A == (uintptr_t)fct) return my_create_destroy_##A;
    SUPER()
    #undef GO
    #define GO(A) if(my_create_destroy_fct_##A == 0) {my_create_destroy_fct_##A = (uintptr_t)fct; return my_create_destroy_##A; }
    SUPER()
    #undef GO
    printf_log(LOG_NONE, "Warning, no more slot for ssl3 create_destroy callback\n");
    return NULL;
}

#undef SUPER

EXPORT void my3_SSL_CTX_set_default_passwd_cb(x64emu_t* emu, void* ctx, void* cb)
{
    (void)emu;
    my->SSL_CTX_set_default_passwd_cb(ctx, find_pem_passwd_cb_Fct(cb));
}

EXPORT long my3_SSL_CTX_callback_ctrl(x64emu_t* emu, void* ctx, int cmd, void* f)
{
    (void)emu;
    return my->SSL_CTX_callback_ctrl(ctx, cmd, find_anonymous_Fct(f));
}

EXPORT long my3_SSL_callback_ctrl(x64emu_t* emu, void* ctx, int cmd, void* f)
{
    (void)emu;
    return my->SSL_callback_ctrl(ctx, cmd, find_anonymous_Fct(f));
}

EXPORT void my3_SSL_CTX_set_verify(x64emu_t* emu, void* ctx, int mode, void* f)
{
    (void)emu;
    my->SSL_CTX_set_verify(ctx, mode, find_verify_Fct(f));
}

EXPORT void my3_SSL_set_verify(x64emu_t* emu, void* ctx, int mode, void* f)
{
    (void)emu;
    my->SSL_set_verify(ctx, mode, find_verify_Fct(f));
}

EXPORT void my3_SSL_get_ex_new_index(x64emu_t* emu, long argl, void* argp, void* new_func, void* dup_func, void* free_func)
{
    (void)emu;
    my->SSL_get_ex_new_index(argl, argp, find_ex_new_Fct(new_func), find_ex_dup_Fct(dup_func), find_ex_free_Fct(free_func));
}

EXPORT void my3_SSL_set_psk_client_callback(x64emu_t* emu, void* ctx, void* cb)
{
    (void)emu;
    my->SSL_set_psk_client_callback(ctx, find_client_cb_Fct(cb));
}

EXPORT void my3_SSL_CTX_set_next_proto_select_cb(x64emu_t* emu, void* ctx, void* cb, void* arg)
{
    (void)emu;
    my->SSL_CTX_set_next_proto_select_cb(ctx, find_proto_select_Fct(cb), arg);
}

EXPORT void* my3_SSL_get_verify_callback(x64emu_t* emu, void* ctx)
{
    (void)emu;
    return reverse_verify_Fct(my->SSL_get_verify_callback(ctx));
}

EXPORT void my3_SSL_CTX_set_cert_verify_callback(x64emu_t* emu, void* ctx, void* cb, void* arg)
{
    (void)emu;
    my->SSL_CTX_set_cert_verify_callback(ctx, find_verify_Fct(cb), arg);
}

EXPORT void my3_SSL_CTX_set_client_cert_cb(x64emu_t* emu, void* ctx, void* cb)
{
    (void)emu;
    my->SSL_CTX_set_client_cert_cb(ctx, find_client_cert_Fct(cb));
}

EXPORT void my3_SSL_CTX_set_alpn_select_cb(x64emu_t* emu, void* ctx, void* f, void* arg)
{
    my->SSL_CTX_set_alpn_select_cb(ctx, find_alpn_select_cb_Fct(f), arg);
}

EXPORT void* my3_SSL_CTX_get_default_passwd_cb(x64emu_t* emu, void* ctx)
{
    return reverse_pem_passwd_cb_Fct(my->SSL_CTX_get_default_passwd_cb(ctx));
}

EXPORT void* my3_SSL_CTX_get_verify_callback(x64emu_t* emu, void* ctx)
{
    return reverse_verify_Fct(my->SSL_CTX_get_verify_callback(ctx));
}

EXPORT void my3_SSL_CTX_set_keylog_callback(x64emu_t* emu, void* ctx, void* cb)
{
    my->SSL_CTX_set_keylog_callback(ctx, find_keylog_cb_Fct(cb));
}

EXPORT void my3_SSL_CTX_set_msg_callback(x64emu_t* emu, void* ctx, void* cb)
{
    my->SSL_CTX_set_msg_callback(ctx, find_msg_cb_Fct(cb));
}

EXPORT void my3_SSL_set_msg_callback(x64emu_t* emu, void* ctx, void* cb)
{
    my->SSL_set_msg_callback(ctx, find_msg_cb_Fct(cb));
}

EXPORT void my3_SSL_CTX_sess_set_new_cb(x64emu_t* emu, void *ctx, void* f)
{
    my->SSL_CTX_sess_set_new_cb(ctx, find_new_seesion_cb_Fct(f));
}

EXPORT void my3_SSL_set_info_callback(x64emu_t* emmu, void* ctx, void* f)
{
    my->SSL_set_info_callback(ctx, find_info_cb_Fct(f));
}

EXPORT void my3_SSL_set_psk_use_session_callback(x64emu_t* emu, void* ctx, void* f)
{
    my->SSL_set_psk_use_session_callback(ctx, find_psk_use_session_cb_Fct(f));
}

EXPORT void my3_SSL_CTX_set_cookie_verify_cb(x64emu_t* emu, void* ctx, void* f)
{
    my->SSL_CTX_set_cookie_verify_cb(ctx, find_app_verify_cookie_cb_Fct(f));
}

EXPORT void my3_SSL_CTX_set_cookie_generate_cb(x64emu_t* emu, void* ctx, void* f)
{
    my->SSL_CTX_set_cookie_generate_cb(ctx, find_set_cookie_generate_cb_Fct(f));
}

EXPORT void my3_SSL_set_psk_server_callback(x64emu_t* emu, void* ctx, void* f)
{
    my->SSL_set_psk_server_callback(ctx, find_psk_server_cb_Fct(f));
}

EXPORT int my3_BIO_meth_set_write(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_write(biom, find_read_write_Fct(f));
}

EXPORT int my3_BIO_meth_set_read(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_read(biom, find_read_write_Fct(f));
}

EXPORT int my3_BIO_meth_set_puts(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_puts(biom, find_puts_Fct(f));
}

EXPORT int my3_BIO_meth_set_ctrl(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_ctrl(biom, find_ctrl_Fct(f));
}

EXPORT int my3_BIO_meth_set_create(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_create(biom, find_create_destroy_Fct(f));
}

EXPORT int my3_BIO_meth_set_destroy(x64emu_t* emu, void* biom, void* f)
{
    return my->BIO_meth_set_destroy(biom, find_create_destroy_Fct(f));
}

#define ALTMY my3_

#define NEEDED_LIBS "libcrypto.so.3", "libpthread.so.0"

#include "wrappedlib_init.h"