forked from easysoft/phpmicro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_micro_hooks.c
635 lines (574 loc) · 21.6 KB
/
php_micro_hooks.c
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
/*
micro SAPI for PHP - php_micro_hooks.c
micro hooks for multi kinds of hooking
Copyright 2020 Longyan
Copyright 2022 Yun Dou <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "php.h"
#include "php_micro.h"
#include "php_micro_fileinfo.h"
/* ======== things for ini set ======== */
// original zend_post_startup_cb holder
static int (*micro_zend_post_startup_cb_orig)(void) = NULL;
/*
* micro_post_mstartup - post mstartup callback called as zend_post_startup_cb
* used to add ini_entries without additional_modules
*/
int micro_post_mstartup(void) {
dbgprintf("start reg inientries\n");
const zend_ini_entry_def micro_ini_entries[] = {
ZEND_INI_ENTRY(PHP_MICRO_INIENTRY(php_binary), "", ZEND_INI_PERDIR | ZEND_INI_SYSTEM, NULL){0},
};
int ret = zend_register_ini_entries(micro_ini_entries, 0);
if (SUCCESS != ret) {
return ret;
}
if (NULL != micro_zend_post_startup_cb_orig) {
return micro_zend_post_startup_cb_orig();
}
return ret;
}
/*
* micro_register_post_startup_cb - register post mstartup callback
*/
int micro_register_post_startup_cb(void) {
if (NULL != zend_post_startup_cb) {
micro_zend_post_startup_cb_orig = (void *)zend_post_startup_cb;
}
zend_post_startup_cb = (void *)micro_post_mstartup;
return SUCCESS;
}
/* ======== things for hooking php_stream ======== */
// my own ops struct
typedef struct _micro_php_stream_ops {
php_stream_ops ops;
const php_stream_ops *ops_orig;
} micro_php_stream_ops;
// use original ops as ps->ops
#define orig_ops(myops, ps) \
const php_stream_ops *myops = ps->ops; \
ps->ops = ((const micro_php_stream_ops *)(ps->ops))->ops_orig;
// use with-offset ops as ps->ops
#define ours_ops(ps) ps->ops = myops;
#define ret_orig(rtyp, name, stream, args) \
do { \
orig_ops(myops, stream); \
rtyp ret = stream->ops->name(stream args); \
ours_ops(stream); \
return ret; \
} while (0)
#define with_args(...) , __VA_ARGS__
#define nope
/* ops proxies here
* why there're many proxies:
* php DO NOT have a explcit standard applied which
* limits one php_stream op function (like ops->stat) MUST NOT call another one,
* or limits one php_stream op function MUST NOT use its own modified php_stream_obs (like what i do).
* so we use these proxies to call original operation functions
*/
/* stdio like functions - these are mandatory! */
static ssize_t micro_plain_files_write(php_stream *stream, const char *buf, size_t count) {
ret_orig(ssize_t, write, stream, with_args(buf, count));
}
static int micro_plain_files_flush(php_stream *stream) {
ret_orig(int, flush, stream, nope);
}
/* these are optional */
static int micro_plain_files_cast(php_stream *stream, int castas, void **_ret) {
ret_orig(int, cast, stream, with_args(castas, _ret));
}
static int micro_plain_files_stat(php_stream *stream, php_stream_statbuf *ssb) {
ret_orig(int, stat, stream, with_args(ssb));
}
#undef ret_orig
#undef with_args
#undef nope
/* end of ops proxies */
/* stream ops hookers */
/*
* micro_plain_files_set_option - php_stream sef_option op with offset
* to fix mmap-like behaiver
*/
static int micro_plain_files_set_option(php_stream *stream, int option, int value, void *ptrparam) {
void *myptrparam = ptrparam;
size_t limit;
if (option == PHP_STREAM_OPTION_MMAP_API && value == PHP_STREAM_MMAP_MAP_RANGE) {
dbgprintf("trying mmap self, let us mask it!\n");
php_stream_mmap_range *range = myptrparam;
if (PHP_STREAM_MAP_MODE_READWRITE == range->mode || PHP_STREAM_MAP_MODE_SHARED_READWRITE == range->mode) {
// self should not be writeable
return PHP_STREAM_OPTION_RETURN_ERR;
}
range->offset = range->offset + micro_get_sfxsize();
/**
* linux mmap(2) manpage said:
* EOVERFLOW
* The file is a regular file and
* the value of off plus len exceeds the offset maximum established in the open file description
* associated with fildes.
*
*/
if ((limit = micro_get_sfxsize_limit()) != 0) {
if (range->offset + range->length > limit) {
#ifdef EOVERFLOW // is this necessary?
errno = EOVERFLOW;
#else
errno = EINVAL;
#endif // EOVERFLOW
return PHP_STREAM_OPTION_RETURN_ERR;
}
}
}
orig_ops(myops, stream);
int ret = stream->ops->set_option(stream, option, value, myptrparam);
ours_ops(stream);
return ret;
}
/*
* micro_plain_files_seek_with_offset - php_stream seek op with offset
* return -1 for failed or 0 for success (behaives like fseek)
*/
static int micro_plain_files_seek_with_offset(
php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) {
dbgprintf("seeking %zd with sfxsize %zd limit %zd whence %d\n",
offset,
micro_get_sfxsize(),
micro_get_sfxsize_limit(),
whence);
int ret = -1;
zend_off_t want_offset, real_offset;
zend_off_t sfxsize, limit;
sfxsize = micro_get_sfxsize();
limit = micro_get_sfxsize_limit();
orig_ops(myops, stream);
switch (whence) {
case SEEK_SET:
want_offset = offset + sfxsize;
break;
case SEEK_CUR:
ret = stream->ops->seek(stream, 0, SEEK_CUR, &want_offset);
if (-1 == ret) {
goto error;
}
want_offset += offset;
break;
case SEEK_END:
if (0 == limit) {
ret = stream->ops->seek(stream, 0, SEEK_END, &limit);
if (-1 == ret) {
goto error;
}
}
want_offset = limit + offset;
break;
}
dbgprintf("want offset: %zd\n", want_offset);
if (want_offset < sfxsize) {
// seek before start
goto error;
}
ret = stream->ops->seek(stream, want_offset, SEEK_SET, &real_offset);
if (-1 == ret) {
php_error_docref(NULL, E_WARNING, "Seek on self stream failed");
goto error;
}
ours_ops(stream);
*newoffset = real_offset - sfxsize;
dbgprintf("new offset: %zd\n", *newoffset);
return 0;
error:
ours_ops(stream);
// php_error_docref(NULL, E_WARNING, "Seek on self stream failed");
return -1;
}
/*
* micro_plain_files_stat_with_offset - php_stream stat op with offset
*/
static int micro_plain_files_stat_with_offset(php_stream *stream, php_stream_statbuf *ssb) {
int ret = -1;
size_t limit = 0;
orig_ops(myops, stream);
ret = stream->ops->stat(stream, ssb);
ours_ops(stream);
if (-1 == ret) {
return -1;
}
dbgprintf("stating real size %zd\n", ssb->sb.st_size);
if ((limit = micro_get_sfxsize_limit()) > 0) {
ssb->sb.st_size = limit - micro_get_sfxsize();
} else {
ssb->sb.st_size -= micro_get_sfxsize();
}
dbgprintf("stating with offset %zd\n", ssb->sb.st_size);
return ret;
}
/*
* micro_plain_files_read_with_offset - php_stream read op with offset
*/
static ssize_t micro_plain_files_read_with_offset(php_stream *stream, char *buf, size_t count) {
ssize_t ret = 0;
zend_off_t current;
size_t limit;
orig_ops(myops, stream);
ret = stream->ops->seek(stream, 0, SEEK_CUR, ¤t);
if (-1 == ret || current < 0) {
ret = -1;
goto error;
}
dbgprintf("limit %zd, current %zd, count %zd\n", micro_get_sfxsize_limit(), current, count);
if ((limit = micro_get_sfxsize_limit()) > 0) {
if (current >= limit) {
// already at end
goto error;
} else if (((size_t)current) + count > limit) {
count = limit - current;
}
}
ret = stream->ops->read(stream, buf, count);
error:
ours_ops(stream);
return ret;
}
/*
* micro_plain_files_close_with_offset - php_stream close destroyer
*/
static int micro_plain_files_close_with_offset(php_stream *stream, int close_handle) {
dbgprintf("closing with-offset file %p\n", stream);
orig_ops(myops, stream);
pefree((void *)myops, stream->is_persistent);
// free(myops);
int ret = stream->ops->close(stream, close_handle);
return ret;
}
#undef orig_ops
#undef ours_ops
/* end of stream ops hookers */
/*
* micro_modify_ops_with_offset - modify a with-offset ops struct, the argument ps must be created
*/
static inline int micro_modify_ops_with_offset(php_stream *ps, int mod_stat) {
dbgprintf("compare %p, %p\n", ps->ops->close, micro_plain_files_close_with_offset);
if (ps->ops->close == micro_plain_files_close_with_offset) {
dbgprintf("offset alread set, skip it\n");
return FAILURE;
}
micro_php_stream_ops *ret = pemalloc(sizeof(*ret), ps->is_persistent);
// micro_php_stream_ops *ret = malloc(sizeof(*ret));
(*ret).ops = (php_stream_ops){
// set with-offset op handlers
.close = micro_plain_files_close_with_offset,
.seek = NULL == ps->ops->seek ? NULL : micro_plain_files_seek_with_offset,
.stat = NULL == ps->ops->stat ? NULL
: (0 == mod_stat ? micro_plain_files_stat : micro_plain_files_stat_with_offset),
// set proxies
.write = micro_plain_files_write,
.read = micro_plain_files_read_with_offset,
.flush = micro_plain_files_flush,
.cast = NULL == ps->ops->cast ? NULL : micro_plain_files_cast,
.set_option = NULL == ps->ops->set_option ? NULL : micro_plain_files_set_option,
// set original label
.label = ps->ops->label,
};
ret->ops_orig = ps->ops;
dbgprintf("assigning psop %p\n", ret);
ps->ops = (const php_stream_ops *)ret;
return SUCCESS;
}
// holder for original php_plain_files_wrapper_ops
const php_stream_wrapper_ops *micro_plain_files_wops_orig = NULL;
static inline int initial_seek(php_stream *ps);
/*
* micro_plain_files_opener - stream_opener that modify ops according to filename
* replaces php_plain_files_stream_opener
* should be called after micro_fileinfo_init
*/
static php_stream *micro_plain_files_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) {
dbgprintf("opening file %s like plain file\n", filename);
if (NULL == micro_plain_files_wops_orig) {
// this should never happen
return NULL;
}
static const char *self_filename_slashed = NULL;
if (NULL == self_filename_slashed) {
self_filename_slashed = micro_slashize(micro_get_filename());
}
php_stream *ps = micro_plain_files_wops_orig->stream_opener(
wrapper, filename, mode, options, opened_path, context STREAMS_REL_CC);
if (NULL == ps) {
return ps;
}
const char *filename_slashed = micro_slashize(filename);
if (0 == strcmp(filename_slashed, self_filename_slashed)) {
dbgprintf("opening self via php_stream, hook it\n");
if (SUCCESS == micro_modify_ops_with_offset(ps, 1)) {
initial_seek(ps);
}
}
free((void *)filename_slashed);
dbgprintf("done opening plain file %p\n", ps);
return ps;
}
/*
* micro_plain_files_url_stater - url_stater that modify stat according to filename
* replaces php_plain_files_url_stater
* should be called after micro_fileinfo_init
*/
static int micro_plain_files_url_stater(
php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context) {
dbgprintf("stating file %s like plain file\n", url);
if (NULL == micro_plain_files_wops_orig) {
// this should never happen
return FAILURE;
}
static const char *self_filename_slashed = NULL;
if (NULL == self_filename_slashed) {
self_filename_slashed = micro_slashize(micro_get_filename());
}
int ret = micro_plain_files_wops_orig->url_stat(wrapper, url, flags, ssb, context);
if (SUCCESS != ret) {
return ret;
}
const char *filename_slashed = micro_slashize(url);
if (0 == strcmp(filename_slashed, self_filename_slashed)) {
dbgprintf("stating self via plain file wops, hook it\n");
ssb->sb.st_size -= micro_get_sfxsize();
}
free((void *)filename_slashed);
return ret;
}
// with-offset wrapper ops to replace php_plain_files_wrapper.wops
static php_stream_wrapper_ops micro_plain_files_wops_with_offset;
/*
* micro_hook_plain_files_wops - hook plain file wrapper php_plain_files_wrapper
*/
int micro_hook_plain_files_wops(void) {
micro_plain_files_wops_orig = php_plain_files_wrapper.wops;
memcpy(µ_plain_files_wops_with_offset, micro_plain_files_wops_orig, sizeof(*micro_plain_files_wops_orig));
micro_plain_files_wops_with_offset.stream_opener = micro_plain_files_opener;
micro_plain_files_wops_with_offset.url_stat = micro_plain_files_url_stater;
// micro_plain_files_wops_with_offset.stream_opener = micro_php_stream_closer;
php_plain_files_wrapper.wops = µ_plain_files_wops_with_offset;
return SUCCESS;
}
/* ======== things for hooking url_stream ======== */
HashTable reregistered_protos = {0};
int reregistered_protos_inited = 0;
typedef struct _micro_reregistered_proto {
php_stream_wrapper *modified_wrapper;
php_stream_wrapper_ops *modified_wops;
php_stream_wrapper *orig_wrapper;
char proto[1];
} micro_reregistered_proto;
// no wrapper ops proxies here
static inline int initial_seek(php_stream *ps);
/*
* micro_wrapper_stream_opener - modify ops according to filename
* replaces someproto_wrapper_open_url
* should be called after micro_fileinfo_init
*/
static php_stream *micro_wrapper_stream_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) {
dbgprintf("opening file %s like url\n", filename);
micro_reregistered_proto *pproto = zend_hash_str_find_ptr(&reregistered_protos, (void *)wrapper, sizeof(*wrapper));
if (NULL == pproto) {
// this should never happen
return NULL;
}
static const char *self_filename_slashed = NULL;
static size_t self_filename_slashed_len = 0;
if (NULL == self_filename_slashed) {
self_filename_slashed = micro_slashize(micro_get_filename());
self_filename_slashed_len = strlen(self_filename_slashed);
}
php_stream *ps = pproto->orig_wrapper->wops->stream_opener(
wrapper, filename, mode, options, opened_path, context STREAMS_REL_CC);
if (NULL == ps) {
return ps;
}
const char *filename_slashed = micro_slashize(filename);
if (strstr(filename, "://") &&
0 == strncmp(strstr(filename_slashed, "://") + 3, self_filename_slashed, self_filename_slashed_len)) {
dbgprintf("stream %s is in self\n", filename);
if (SUCCESS == micro_modify_ops_with_offset(ps, 0)) {
initial_seek(ps);
}
}
free((void *)filename_slashed);
dbgprintf("done opening file %p like url\n", ps);
return ps;
}
#if PHP_VERSION_ID < 80100
# define zend_string_init_existing_interned zend_string_init_interned
#endif
/*
* micro_reregister_proto - hook some:// protocol
* should be called after mstartup, before start execution
*/
int micro_reregister_proto(const char *proto) {
dbgprintf("reregister proto %s\n", proto);
php_stream_wrapper_ops *modified_wops = NULL;
php_stream_wrapper *modified_wrapper = NULL;
int ret = SUCCESS;
HashTable *ht = php_stream_get_url_stream_wrappers_hash_global();
php_stream_wrapper *orig_wrapper =
zend_hash_find_ptr(ht, zend_string_init_existing_interned(proto, strlen(proto), 1));
if (NULL == orig_wrapper) {
// no wrapper found
goto end;
}
if (SUCCESS != (ret = php_unregister_url_stream_wrapper(proto))) {
dbgprintf("failed unregister proto %s\n", proto);
goto end;
}
if (NULL == orig_wrapper->wops->stream_opener) {
// no stream_opener, just say success
dbgprintf("proto %s have no stream_opener\n", proto);
goto end;
}
if (0 == reregistered_protos_inited) {
zend_hash_init(&reregistered_protos, 0, NULL, ZVAL_PTR_DTOR, 1);
reregistered_protos_inited = 1;
}
modified_wops = malloc(sizeof(*modified_wops));
modified_wrapper = malloc(sizeof(*modified_wrapper));
modified_wrapper->wops = modified_wops;
modified_wrapper->abstract = orig_wrapper->abstract;
modified_wrapper->is_url = orig_wrapper->is_url;
// copy original to modified
memcpy(modified_wops, orig_wrapper->wops, sizeof(*modified_wops));
// modify stream opener
modified_wops->stream_opener = micro_wrapper_stream_opener;
// re-register it
if (SUCCESS != (ret = php_register_url_stream_wrapper(proto, modified_wrapper))) {
dbgprintf("failed reregister proto %s\n", proto);
goto end;
};
// save info for freeing
micro_reregistered_proto *pproto = malloc(sizeof(*pproto) + strlen(proto));
pproto->modified_wops = modified_wops;
pproto->modified_wrapper = modified_wrapper;
pproto->orig_wrapper = orig_wrapper;
memcpy(pproto->proto, proto, strlen(proto) + 1);
zend_hash_str_add_ptr(&reregistered_protos, (void *)modified_wrapper, sizeof(*modified_wrapper), pproto);
dbgprintf("reregistered proto (label %s) %s %p => %p %p\n",
orig_wrapper->wops->label,
proto,
orig_wrapper,
modified_wrapper,
modified_wops);
return ret;
end:
if (modified_wops) {
free(modified_wops);
}
if (modified_wrapper) {
free(modified_wrapper);
}
return ret;
}
#ifdef ZEND_HASH_MAP_REVERSE_FOREACH_PTR
# define HASH_REVERSE_FOREACH_PTR ZEND_HASH_MAP_REVERSE_FOREACH_PTR
#else
# define HASH_REVERSE_FOREACH_PTR ZEND_HASH_REVERSE_FOREACH_PTR
#endif
/*
* micro_free_reregistered_protos - remove hook of protocol schemes
* should be called before mshutdown, after rshutdown
*/
int micro_free_reregistered_protos(void) {
int final_ret = SUCCESS;
HASH_REVERSE_FOREACH_PTR(&reregistered_protos, micro_reregistered_proto * pproto)
int ret = SUCCESS;
const char *proto = pproto->proto;
dbgprintf("free reregistered proto %s\n", proto);
if (SUCCESS != (ret = php_unregister_url_stream_wrapper(proto))) {
dbgprintf("failed unregister reregistered proto %s\n", proto);
final_ret = ret;
continue;
}
if (SUCCESS != (ret = php_register_url_stream_wrapper(proto, pproto->orig_wrapper))) {
dbgprintf("failed restore reregistered proto %s\n", proto);
final_ret = ret;
continue;
}
free(pproto->modified_wrapper);
free(pproto->modified_wops);
free(pproto);
ZEND_HASH_FOREACH_END_DEL();
return final_ret;
}
static inline int initial_seek(php_stream *ps) {
dbgprintf("initial seeking\n");
zend_off_t dummy;
if (0 == ps->position) {
// not appending mode
ps->ops->seek(ps, 0, SEEK_SET, &dummy);
} else if (0 < ps->position) {
// appending mode
// this will only called after micro_fileinfo_init,
// so it's sure thatself size wont be smaller then sfx size.
ps->position -= micro_get_sfxsize();
ps->ops->seek(ps, ps->position, SEEK_SET, &dummy);
} else {
// self should be seekable, if not, why?
abort();
}
return SUCCESS;
}
/* ======== things for hooking zend_stream ======== */
static ssize_t micro_zend_stream_reader_with_offset(void *handle, char *buf, size_t len) {
size_t limit = 0;
FILE *fp = (FILE *)handle;
zend_off_t cur = zend_fseek(fp, 0, SEEK_CUR);
dbgprintf("reader %zd from %zd\n", len, cur);
if ((limit = micro_get_sfxsize_limit()) > 0) {
if (cur >= limit) {
return 0;
} else if (cur + len > limit) {
len = limit - cur;
}
}
dbgprintf("reader with offset len become %zd\n", len);
return fread(buf, 1, len, fp);
}
static size_t micro_zend_stream_fsizer_with_offset(void *handle) {
size_t limit = micro_get_sfxsize_limit();
if (limit > 0) {
dbgprintf("fsizer return %zd\n", limit - micro_get_sfxsize());
return limit - micro_get_sfxsize();
}
zend_stat_t buf = {0};
if (handle && zend_fstat(fileno((FILE *)handle), &buf) == 0) {
#ifdef S_ISREG
if (!S_ISREG(buf.st_mode)) {
return 0;
}
#endif
dbgprintf("fsizer return %zd\n", buf.st_size - micro_get_sfxsize());
return buf.st_size - micro_get_sfxsize();
}
return -1;
}
static void micro_zend_stream_closer(void *handle) {
fclose((FILE *)handle);
}
int micro_hook_file_handle(zend_file_handle *file_handle) {
file_handle->type = ZEND_HANDLE_STREAM;
file_handle->handle.stream.handle = file_handle->handle.fp;
file_handle->handle.stream.isatty = 0;
file_handle->handle.stream.reader = (zend_stream_reader_t)micro_zend_stream_reader_with_offset;
file_handle->handle.stream.closer = (zend_stream_closer_t)micro_zend_stream_closer;
file_handle->handle.stream.fsizer = (zend_stream_fsizer_t)micro_zend_stream_fsizer_with_offset;
zend_fseek((FILE *)file_handle->handle.fp, micro_get_sfxsize(), SEEK_SET);
return SUCCESS;
}