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
|
#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* png16Name =
#ifdef ANDROID
"libpng16.so"
#else
"libpng16.so.16"
#endif
;
#define LIBNAME png16
#include "generated/wrappedpng16types.h"
#include "wrappercallback.h"
#define SUPER() \
GO(0) \
GO(1) \
GO(2) \
GO(3)
// user_write
#define GO(A) \
static uintptr_t my_user_write_fct_##A = 0; \
static void my_user_write_##A(void* png_ptr, void* data, size_t length) \
{ \
RunFunctionFmt(my_user_write_fct_##A, "ppL", png_ptr, data, length);\
}
SUPER()
#undef GO
static void* finduser_writeFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_user_write_fct_##A == (uintptr_t)fct) return my_user_write_##A;
SUPER()
#undef GO
#define GO(A) if(my_user_write_fct_##A == 0) {my_user_write_fct_##A = (uintptr_t)fct; return my_user_write_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 user_write callback\n");
return NULL;
}
// user_flush
#define GO(A) \
static uintptr_t my_user_flush_fct_##A = 0; \
static void my_user_flush_##A(void* png_ptr) \
{ \
RunFunctionFmt(my_user_flush_fct_##A, "p", png_ptr);\
}
SUPER()
#undef GO
static void* finduser_flushFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_user_flush_fct_##A == (uintptr_t)fct) return my_user_flush_##A;
SUPER()
#undef GO
#define GO(A) if(my_user_flush_fct_##A == 0) {my_user_flush_fct_##A = (uintptr_t)fct; return my_user_flush_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 user_flush callback\n");
return NULL;
}
// user_read
#define GO(A) \
static uintptr_t my_user_read_fct_##A = 0; \
static void my_user_read_##A(void* png_ptr, void* data, size_t length) \
{ \
RunFunctionFmt(my_user_read_fct_##A, "ppL", png_ptr, data, length);\
}
SUPER()
#undef GO
static void* finduser_readFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_user_read_fct_##A == (uintptr_t)fct) return my_user_read_##A;
SUPER()
#undef GO
#define GO(A) if(my_user_read_fct_##A == 0) {my_user_read_fct_##A = (uintptr_t)fct; return my_user_read_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 user_read callback\n");
return NULL;
}
// error
#define GO(A) \
static uintptr_t my_error_fct_##A = 0; \
static void my_error_##A(void* a, void* b) \
{ \
RunFunctionFmt(my_error_fct_##A, "pp", a, b);\
}
SUPER()
#undef GO
static void* finderrorFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_error_fct_##A == (uintptr_t)fct) return my_error_##A;
SUPER()
#undef GO
#define GO(A) if(my_error_fct_##A == 0) {my_error_fct_##A = (uintptr_t)fct; return my_error_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 error callback\n");
return NULL;
}
// warning
#define GO(A) \
static uintptr_t my_warning_fct_##A = 0; \
static void my_warning_##A(void* a, void* b) \
{ \
RunFunctionFmt(my_warning_fct_##A, "pp", a, b);\
}
SUPER()
#undef GO
static void* findwarningFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_warning_fct_##A == (uintptr_t)fct) return my_warning_##A;
SUPER()
#undef GO
#define GO(A) if(my_warning_fct_##A == 0) {my_warning_fct_##A = (uintptr_t)fct; return my_warning_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 warning callback\n");
return NULL;
}
// malloc
#define GO(A) \
static uintptr_t my_malloc_fct_##A = 0; \
static void my_malloc_##A(void* a, unsigned long b) \
{ \
RunFunctionFmt(my_malloc_fct_##A, "pL", a, b);\
}
SUPER()
#undef GO
static void* findmallocFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_malloc_fct_##A == (uintptr_t)fct) return my_malloc_##A;
SUPER()
#undef GO
#define GO(A) if(my_malloc_fct_##A == 0) {my_malloc_fct_##A = (uintptr_t)fct; return my_malloc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 malloc callback\n");
return NULL;
}
// free
#define GO(A) \
static uintptr_t my_free_fct_##A = 0; \
static void my_free_##A(void* a, void* b) \
{ \
RunFunctionFmt(my_free_fct_##A, "pp", a, b);\
}
SUPER()
#undef GO
static void* findfreeFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_free_fct_##A == (uintptr_t)fct) return my_free_##A;
SUPER()
#undef GO
#define GO(A) if(my_free_fct_##A == 0) {my_free_fct_##A = (uintptr_t)fct; return my_free_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 free callback\n");
return NULL;
}
// progressive_info
#define GO(A) \
static uintptr_t my_progressive_info_fct_##A = 0; \
static void my_progressive_info_##A(void* a, void* b) \
{ \
RunFunctionFmt(my_progressive_info_fct_##A, "pp", a, b);\
}
SUPER()
#undef GO
static void* findprogressive_infoFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_progressive_info_fct_##A == (uintptr_t)fct) return my_progressive_info_##A;
SUPER()
#undef GO
#define GO(A) if(my_progressive_info_fct_##A == 0) {my_progressive_info_fct_##A = (uintptr_t)fct; return my_progressive_info_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 progressive_info callback\n");
return NULL;
}
// progressive_end
#define GO(A) \
static uintptr_t my_progressive_end_fct_##A = 0; \
static void my_progressive_end_##A(void* a, void* b) \
{ \
RunFunctionFmt(my_progressive_end_fct_##A, "pp", a, b);\
}
SUPER()
#undef GO
static void* findprogressive_endFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_progressive_end_fct_##A == (uintptr_t)fct) return my_progressive_end_##A;
SUPER()
#undef GO
#define GO(A) if(my_progressive_end_fct_##A == 0) {my_progressive_end_fct_##A = (uintptr_t)fct; return my_progressive_end_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 progressive_end callback\n");
return NULL;
}
// progressive_row
#define GO(A) \
static uintptr_t my_progressive_row_fct_##A = 0; \
static void my_progressive_row_##A(void* a, void* b, uint32_t c, int d) \
{ \
RunFunctionFmt(my_progressive_row_fct_##A, "ppui", a, b, c, d);\
}
SUPER()
#undef GO
static void* findprogressive_rowFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_progressive_row_fct_##A == (uintptr_t)fct) return my_progressive_row_##A;
SUPER()
#undef GO
#define GO(A) if(my_progressive_row_fct_##A == 0) {my_progressive_row_fct_##A = (uintptr_t)fct; return my_progressive_row_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 progressive_row callback\n");
return NULL;
}
// user_transform
#define GO(A) \
static uintptr_t my_user_transform_fct_##A = 0; \
static void my_user_transform_##A(void* ptr, void* row, void* data) \
{ \
RunFunctionFmt(my_user_transform_fct_##A, "ppp", ptr, row, data);\
}
SUPER()
#undef GO
static void* finduser_transformFct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_user_transform_fct_##A == (uintptr_t)fct) return my_user_transform_##A;
SUPER()
#undef GO
#define GO(A) if(my_user_transform_fct_##A == 0) {my_user_transform_fct_##A = (uintptr_t)fct; return my_user_transform_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libpng16 user_transform callback\n");
return NULL;
}
#undef SUPER
EXPORT void my16_png_set_read_fn(x64emu_t *emu, void* png_ptr, void* io_ptr, void* read_data_fn)
{
my->png_set_read_fn(png_ptr, io_ptr, finduser_readFct(read_data_fn));
}
EXPORT void my16_png_set_read_user_transform_fn(x64emu_t *emu, void* png_ptr, void* read_transform_fn)
{
my->png_set_read_user_transform_fn(png_ptr, finduser_transformFct(read_transform_fn));
}
EXPORT void my16_png_set_error_fn(x64emu_t* emu, void* pngptr, void* errorptr, void* error_fn, void* warning_fn)
{
my->png_set_error_fn(pngptr, errorptr, finderrorFct(error_fn), findwarningFct(warning_fn));
}
EXPORT void my16_png_set_write_fn(x64emu_t* emu, void* png_ptr, void* io_ptr, void* write_fn, void* flush_fn)
{
my->png_set_write_fn(png_ptr, io_ptr, finduser_writeFct(write_fn), finduser_flushFct(flush_fn));
}
EXPORT void* my16_png_create_read_struct_2(x64emu_t* emu, void* user_png_ver, void* error_ptr, void* error_fn, void* warn_fn, void* mem_ptr, void* malloc_fn, void* free_fn)
{
return my->png_create_read_struct_2(user_png_ver, error_ptr, finderrorFct(error_fn), findwarningFct(warn_fn), mem_ptr, findmallocFct(malloc_fn), findfreeFct(free_fn));
}
EXPORT void* my16_png_create_write_struct_2(x64emu_t* emu, void* user_png_ver, void* error_ptr, void* error_fn, void* warn_fn, void* mem_ptr, void* malloc_fn, void* free_fn)
{
return my->png_create_write_struct_2(user_png_ver, error_ptr, finderrorFct(error_fn), findwarningFct(warn_fn), mem_ptr, findmallocFct(malloc_fn), findfreeFct(free_fn));
}
EXPORT void my16_png_set_progressive_read_fn(x64emu_t* emu, void* png_ptr, void* user_ptr, void* info, void* row, void* end)
{
my->png_set_progressive_read_fn(png_ptr, user_ptr, findprogressive_infoFct(info), findprogressive_rowFct(row), findprogressive_endFct(end));
}
EXPORT void* my16_png_create_read_struct(x64emu_t* emu, void* png_ptr, void* user_ptr, void* errorfn, void* warnfn)
{
return my->png_create_read_struct(png_ptr, user_ptr, finderrorFct(errorfn), findwarningFct(warnfn));
}
#define ALTMY my16_
#define CUSTOM_INIT \
SETALTPREFIX("yes");
#include "wrappedlib_init.h"
|