forked from eaccelerator/eaccelerator
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathea_dasm.c
More file actions
707 lines (667 loc) · 28.5 KB
/
ea_dasm.c
File metadata and controls
707 lines (667 loc) · 28.5 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
/*
+----------------------------------------------------------------------+
| eAccelerator project |
+----------------------------------------------------------------------+
| Copyright (c) 2004 - 2012 eAccelerator |
| http://eaccelerator.net |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| MA 02111-1307, USA. |
| |
| A copy is availble at http://www.gnu.org/copyleft/gpl.txt |
+----------------------------------------------------------------------+
$Id: ea_dasm.c 377 2010-01-20 14:58:03Z hans $
*/
#include "ea_dasm.h"
#include "eaccelerator.h"
#include "opcodes.h"
#include "zend.h"
#ifdef WITH_EACCELERATOR_DISASSEMBLER
extern eaccelerator_mm *ea_mm_instance;
#define LOOKUP(arr, index, max, ptr) if (index < max) { ptr = arr[index]; } else { ptr = "UNDEFINED (TODO)"; };
/* {{{ static const char *extopnames_declare[] */
static const char *extopnames_declare[] = {
"", /* 0 */
"DECLARE_CLASS", /* 1 */
"DECLARE_FUNCTION", /* 2 */
"DECLARE_INHERITED_CLASS" /* 3 */
};
#define EXTOPNAMES_DECLARE_NUM 4
#define GET_EXTOPNAMES_DECLARE(index, ptr) LOOKUP(extopnames_declare, index, EXTOPNAMES_DECLARE_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_cast[] */
static const char *extopnames_cast[] = {
"IS_NULL", /* 0 */
"IS_LONG", /* 1 */
"IS_DOUBLE", /* 2 */
"IS_BOOL", /* 3 */
"IS_ARRAY", /* 4 */
"IS_OBJECT", /* 5 */
"IS_STRING", /* 6 */
"IS_RESOURCE", /* 7 */
"IS_CONSTANT", /* 8 */
"IS_CONSTANT_ARRAY" /* 9 */
};
#define EXTOPNAMES_CAST_NUM 10
#define GET_EXTOPNAMES_CAST(index, ptr) LOOKUP(extopnames_cast, index, EXTOPNAMES_CAST_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_fetch[] */
static const char *extopnames_fetch[] = {
"FETCH_STANDARD", /* 0 */
"FETCH_ADD_LOCK", /* 1 */
"FETCH_MAKE_REF" /* 2 */
};
#define EXTOPNAMES_FETCH_NUM 3
#define GET_EXTOPNAMES_FETCH(index, ptr) LOOKUP(extopnames_fetch, index, EXTOPNAMES_FETCH_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_fetch_class[] */
static const char *extopnames_fetch_class[] = {
"FETCH_CLASS_DEFAULT", /* 0 */
"FETCH_CLASS_SELF", /* 1 */
"FETCH_CLASS_PARENT", /* 2 */
"FETCH_CLASS_MAIN", /* 3 */
"FETCH_CLASS_GLOBAL", /* 4 */
"FETCH_CLASS_AUTO", /* 5 */
"FETCH_CLASS_INTERFACE", /* 6 */
"FETCH_CLASS_STATIC", /* 7 */
};
#define EXTOPNAMES_FETCH_CLASS_NUM 8
#define GET_EXTOPNAMES_FETCH_CLASS(index, ptr) LOOKUP(extopnames_fetch_class, index, EXTOPNAMES_FETCH_CLASS_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_init_fcall[] */
static const char *extopnames_init_fcall[] = {
"", /* 0 */
"MEMBER_FUNC_CALL", /* 1 */
"CTOR_CALL", /* 2 */
"CTOR_CALL" /* 3 */
};
#define EXTOPNAMES_INIT_FCALL_NUM 4
#define GET_EXTOPNAMES_INIT_FCALL(index, ptr) LOOKUP(extopnames_init_fcall, index, EXTOPNAMES_INIT_FCALL_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_sendnoref[] */
static const char *extopnames_sendnoref[] = {
" ", /* 0 */
"ARG_SEND_BY_REF", /* 1 */
"ARG_COMPILE_TIME_BOUND", /* 2 */
"ARG_SEND_BY_REF | ZEND_ARG_COMPILE_TIME_BOUND", /* 3 */
"ZEND_ARG_SEND_FUNCTION" /* 4 */
/* bleh, this sucks for bitmasks */
};
#define EXTOPNAMES_SENDNOREF_NUM 5
#define GET_EXTOPNAMES_SENDNOREF(index, ptr) LOOKUP(extopnames_sendnoref, index, EXTOPNAMES_SENDNOREF_NUM, ptr)
/* }}} */
/* {{{ static const char *fetchtypename[] */
static const char *fetchtypename[] = {
"FETCH_GLOBAL", /* 0 */
"FETCH_LOCAL", /* 1 */
"FETCH_STATIC", /* 2 */
"FETCH_STATIC_MEMBER", /* 3 */
"FETCH_GLOBAL_LOCK", /* 4 */
"FETCH_LEXICAL" /* 5 */
};
#define FETCHTYPENAME_NUM 5
#define GET_FETCHTYPENAME(index, ptr) LOOKUP(fetchtypename, index, FETCHTYPENAME_NUM, ptr)
/* }}} */
/* {{{ static const char *extopnames_fe[] */
static const char *extopnames_fe[] = {
"", /* 0 */
"FE_FETCH_BYREF", /* 1 */
"FE_FETCH_WITH_KEY" /* 2 */
};
#define EXTOPNAMES_FE_NUM 3
#define GET_EXTOPNAMES_FE(index, ptr) LOOKUP(extopnames_fe, index, EXTOPNAMES_FE_NUM, ptr)
/* }}} */
/* {{{ get_zval: create a string from the given zval */
static char *get_zval(zval *v)
{
char *str = NULL;
char buf[512];
size_t size;
#ifndef ZEND_ENGINE_2_3
switch (Z_TYPE_P(v) & ~IS_CONSTANT_INDEX) {
#else
switch (Z_TYPE_P(v) & IS_CONSTANT_TYPE_MASK) {
#endif
case IS_NULL:
str = emalloc(sizeof("null"));
strncpy(str, "null", sizeof("null"));
break;
case IS_LONG:
snprintf(buf, sizeof(buf), "long(%ld)", Z_LVAL_P(v));
str = emalloc(strlen(buf) + 1);
strcpy(str, buf);
break;
case IS_DOUBLE:
snprintf(buf, sizeof(buf), "double(%e)", Z_DVAL_P(v));
str = emalloc(strlen(buf) + 1);
strcpy(str, buf);
break;
case IS_STRING:
size = Z_STRLEN_P(v) + 1 + sizeof("string('')");
str = emalloc(size);
snprintf(str, size, "string('%s')", Z_STRVAL_P(v));
break;
case IS_BOOL:
if (Z_LVAL_P(v)) {
str = emalloc(sizeof("bool(true)"));
strcpy(str, "bool(true)");
} else {
str = emalloc(sizeof("bool(false)"));
strcpy(str, "bool(false)");
}
break;
case IS_ARRAY:
str = emalloc(sizeof("array(?)"));
strcpy(str, "array(?)");
break;
case IS_OBJECT:
str = emalloc(sizeof("object(?)"));
strcpy(str, "object(?)");
break;
case IS_RESOURCE:
str = emalloc(sizeof("resource(?)"));
strcpy(str, "resource(?)");
break;
case IS_CONSTANT:
size = Z_STRLEN_P(v) + 1 + sizeof("constant('')");
str = emalloc(size);
snprintf(str, size, "constant('%s')", Z_STRVAL_P(v));
break;
case IS_CONSTANT_ARRAY:
str = emalloc(sizeof("constant_array(?)"));
strcpy(str, "constant_array(?)");
break;
default:
snprintf(buf, sizeof(buf), "unknown(type=%d)", Z_TYPE_P(v));
str = emalloc(strlen(buf) + 1);
strcpy(str, buf);
}
return str;
}
/* }}} */
/* {{{ get_op_array: return a php array with the given op_array structure
* array() { [0] .. [n] =>
* array () {
* [lineno] => // the line number in the source code
* [opcode] => // the opcode
* [extended_value]=> // the extended value field
* [op1] => // the first opcode
* [op2] => // the second opcode
* [result] => // the result
* }
* }
*/
static zval *get_op_array(ea_op_array *op_array TSRMLS_DC)
{
zval *return_value;
MAKE_STD_ZVAL(return_value);
array_init(return_value);
if (op_array->opcodes) {
zend_op *opline;
zend_op *end;
opline = op_array->opcodes;
end = opline + op_array->last;
for (; opline < end; ++opline) {
zval *el;
char buf[512];
const opcode_dsc *op = get_opcode_dsc(opline->opcode);
int zval_used = 0;
MAKE_STD_ZVAL(el);
array_init(el);
/* lineno */
add_assoc_long(el, "lineno", opline->lineno);
/* opname */
if (op != NULL) {
add_assoc_string(el, "opcode", (char *)op->opname, 1);
} else {
snprintf(buf, sizeof(buf), "UNKNOWN OPCODE %d", opline->opcode);
add_assoc_string(el, "opcode", buf, 1);
}
/* extended value */
if ((op->ops & EXT_MASK) == EXT_OPLINE) {
snprintf(buf, sizeof(buf), "opline(%lu)", opline->extended_value);
} else if ((op->ops & EXT_MASK) == EXT_FCALL) {
snprintf(buf, sizeof(buf), "args(%lu)", opline->extended_value);
} else if ((op->ops & EXT_MASK) == EXT_ARG) {
snprintf(buf, sizeof(buf), "arg(%lu)", opline->extended_value);
} else if ((op->ops & EXT_MASK) == EXT_SEND) {
strncpy(buf, get_opcode_dsc(opline->extended_value)->opname, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_CAST) {
const char *ptr = NULL;
GET_EXTOPNAMES_CAST(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_INIT_FCALL) {
const char *ptr = NULL;
GET_EXTOPNAMES_INIT_FCALL(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
//snprintf(buf, sizeof(buf), "%d", opline->extended_value);
} else if ((op->ops & EXT_MASK) == EXT_FETCH) {
const char *ptr = NULL;
GET_EXTOPNAMES_FETCH(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_FE) {
const char *ptr = NULL;
GET_EXTOPNAMES_FE(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_DECLARE) {
const char *ptr = NULL;
GET_EXTOPNAMES_DECLARE(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_SEND_NOREF) {
const char *ptr = NULL;
GET_EXTOPNAMES_SENDNOREF(opline->extended_value, ptr);
strncpy(buf, ptr, sizeof(buf));
} else if ((op->ops & EXT_MASK) == EXT_FCLASS) {
const char *ptr = NULL;
GET_EXTOPNAMES_FETCH_CLASS(opline->extended_value, ptr);
snprintf(buf, sizeof(buf), "%s", ptr);
} else if ((op->ops & EXT_MASK) == EXT_IFACE) {
snprintf(buf, sizeof(buf), "interface(%lu)", opline->extended_value);
} else if ((op->ops & EXT_MASK) == EXT_CLASS) {
snprintf(buf, sizeof(buf), "$class%u", VAR_NUM(opline->extended_value));
} else if ((op->ops & EXT_MASK) == EXT_BIT) {
if (opline->extended_value) {
snprintf(buf, sizeof(buf), "true");
} else {
snprintf(buf, sizeof(buf), "false");
}
} else if ((op->ops & EXT_MASK) == EXT_ISSET) {
if (opline->extended_value == ZEND_ISSET) {
snprintf(buf, sizeof(buf), "ZEND_ISSET");
} else if (opline->extended_value == ZEND_ISEMPTY) {
snprintf(buf, sizeof(buf), "ZEND_ISEMPTY");
} else {
buf[0] = '\0';
}
} else if ((op->ops & EXT_MASK) == EXT_ASSIGN) {
if (opline->extended_value == ZEND_ASSIGN_OBJ) {
snprintf(buf, sizeof(buf), "ZEND_ASSIGN_OBJ");
} else if (opline->extended_value == ZEND_ASSIGN_DIM) {
snprintf(buf, sizeof(buf), "ZEND_ASSIGN_DIM");
} else {
buf[0] = '\0';
}
} else if (opline->extended_value != 0) {
snprintf(buf, sizeof(buf), "%ld", opline->extended_value);
} else {
buf[0] = '\0';
}
add_assoc_string(el, "extended_value", buf, 1);
/* op1 */
zval_used = 0;
if (OP1_TYPE(opline) == IS_CV) {
snprintf(buf, sizeof(buf), "$cv%u(%s)", OP1_VARR(opline),
op_array->vars[OP1_VARR(opline)].name);
} else if ((op->ops & OP1_MASK) == OP1_OPLINE) {
snprintf(buf, sizeof(buf), "opline(%d)", OP1_OPLINE_NUM(opline));
} else if ((op->ops & OP1_MASK) == OP1_JMPADDR) {
snprintf(buf, sizeof(buf), "opline(%u)", (unsigned int)(OP1_JMP_ADDR(opline) - op_array->opcodes));
} else if ((op->ops & OP1_MASK) == OP1_CLASS) {
snprintf(buf, sizeof(buf), "$class%u", VAR_NUM(OP1_VARR(opline)));
#ifdef ZEND_ENGINE_2_3
} else if ((op->ops & OP1_MASK) == OP1_UCLASS) {
if (OP1_TYPE(opline) == IS_UNUSED) {
buf[0] = '\0';
} else {
snprintf(buf, sizeof(buf), "$class%u", VAR_NUM(OP1_VARR(opline)));
}
#endif
} else if ((op->ops & OP1_MASK) == OP1_BRK) {
#ifdef ZEND_ENGINE_2_4
if (OP1_OPLINE_NUM(opline) != -1 && OP2_TYPE(opline) == IS_CONST && Z_TYPE_P(opline->op2.zv) == IS_LONG) {
int level = Z_LVAL_P(opline->op2.zv);
#else
if (OP1_OPLINE_NUM(opline) != -1 && OP2_TYPE(opline) == IS_CONST && opline->op2.u.constant.type == IS_LONG) {
int level = Z_LVAL(OP2_CONST(opline));
#endif
zend_uint offset = OP1_OPLINE_NUM(opline);
zend_brk_cont_element *jmp_to;
do {
if (offset >= op_array->last_brk_cont) {
goto brk_failed;
}
jmp_to = &op_array->brk_cont_array[offset];
offset = jmp_to->parent;
} while (--level > 0);
snprintf(buf, sizeof(buf), "opline(%d)", jmp_to->brk);
} else {
brk_failed:
snprintf(buf, sizeof(buf), "brk_cont(%u)", OP1_OPLINE_NUM(opline));
}
} else if ((op->ops & OP1_MASK) == OP1_CONT) {
#ifdef ZEND_ENGINE_2_4
if (OP1_OPLINE_NUM(opline) != -1 && OP2_TYPE(opline) == IS_CONST && Z_TYPE_P(opline->op2.zv) == IS_LONG) {
int level = Z_LVAL_P(opline->op2.zv);
#else
if (OP1_OPLINE_NUM(opline) != -1 && OP2_TYPE(opline) == IS_CONST && opline->op2.u.constant.type == IS_LONG) {
int level = Z_LVAL(OP2_CONST(opline));
#endif
zend_uint offset = OP1_OPLINE_NUM(opline);
zend_brk_cont_element *jmp_to;
do {
if (offset >= op_array->last_brk_cont) {
goto cont_failed;
}
jmp_to = &op_array->brk_cont_array[offset];
offset = jmp_to->parent;
} while (--level > 0);
snprintf(buf, sizeof(buf), "opline(%d)", jmp_to->cont);
} else {
cont_failed:
snprintf(buf, sizeof(buf), "brk_cont(%u)", OP1_OPLINE_NUM(opline));
}
} else if ((op->ops & OP1_MASK) == OP1_ARG) {
#ifdef ZEND_ENGINE_2_4
snprintf(buf, sizeof(buf), "arg(%ld)", opline->op1.num);
#else
snprintf(buf, sizeof(buf), "arg(%ld)", Z_LVAL(OP1_CONST(opline)));
#endif
} else if ((op->ops & OP1_MASK) == OP1_VAR) {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(OP1_VARR(opline)));
} else if ((op->ops & OP1_MASK) == OP1_TMP) {
snprintf(buf, sizeof(buf), "$tmp%u", VAR_NUM(OP1_VARR(opline)));
} else {
if (OP1_TYPE(opline) == IS_CONST) {
zval_used = 1;
#ifdef ZEND_ENGINE_2_4
add_assoc_string(el, "op1", get_zval((zval*)opline->op1.literal), 0);
#else
add_assoc_string(el, "op1", get_zval(&opline->op1.u.constant), 0);
#endif
} else if (OP1_TYPE(opline) == IS_TMP_VAR) {
snprintf(buf, sizeof(buf), "$tmp%u", VAR_NUM(OP1_VARR(opline)));
} else if (OP1_TYPE(opline) == IS_VAR) {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(OP1_VARR(opline)));
} else if (OP1_TYPE(opline) == IS_UNUSED) {
buf[0] = '\0';
} else {
snprintf(buf, sizeof(buf), "UNKNOWN NODE %d", OP1_TYPE(opline));
}
}
if (zval_used == 0) {
add_assoc_string(el, "op1", buf, 1);
}
/* op2 */
zval_used = 0;
if (OP2_TYPE(opline) == IS_CV) {
snprintf(buf, sizeof(buf), "$cv%u(%s)", OP2_VARR(opline), op_array->vars[OP2_VARR(opline)].name);
} else if ((op->ops & OP2_MASK) == OP2_OPLINE) {
snprintf(buf, sizeof(buf), "opline(%d)", OP2_OPLINE_NUM(opline));
} else if ((op->ops & OP2_MASK) == OP2_JMPADDR) {
snprintf(buf, sizeof(buf), "opline(%u)", (unsigned int) (OP2_JMP_ADDR(opline) - op_array->opcodes));
} else if ((op->ops & OP2_MASK) == OP2_CLASS) {
snprintf(buf, sizeof(buf), "$class%u", VAR_NUM(OP2_VARR(opline)));
} else if ((op->ops & OP2_MASK) == OP2_VAR) {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(OP2_VARR(opline)));
} else if ((op->ops & OP2_MASK) == OP2_FETCH) {
const char *typename = NULL;
#ifdef ZEND_ENGINE_2_4
GET_FETCHTYPENAME((opline->extended_value & ~ZEND_FETCH_TYPE_MASK), typename);
// if (opline->extended_value == ZEND_FETCH_STATIC_MEMBER) {
if (opline->op2_type == IS_CONST) {
snprintf(buf, sizeof(buf), "%s %s", typename, Z_STRVAL_P(opline->op2.zv));
} else {
snprintf(buf, sizeof(buf), "%s", typename);
}
#else
GET_FETCHTYPENAME(opline->op2.u.EA.type, typename);
if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
snprintf(buf, sizeof(buf), "%s $class%u", typename, VAR_NUM(OP2_VARR(opline)));
} else {
snprintf(buf, sizeof(buf), "%s", typename);
}
#endif
} else if ((op->ops & OP2_MASK) == OP2_INCLUDE) {
#ifdef ZEND_ENGINE_2_4
if (opline->extended_value == ZEND_EVAL) {
snprintf(buf, sizeof(buf), "ZEND_EVAL");
} else if (opline->extended_value == ZEND_INCLUDE) {
snprintf(buf, sizeof(buf), "ZEND_INCLUDE");
} else if (opline->extended_value == ZEND_INCLUDE_ONCE) {
snprintf(buf, sizeof(buf), "ZEND_INCLUDE_ONCE");
} else if (opline->extended_value == ZEND_REQUIRE) {
snprintf(buf, sizeof(buf), "ZEND_REQUIRE");
} else if (opline->extended_value == ZEND_REQUIRE_ONCE) {
snprintf(buf, sizeof(buf), "ZEND_REQUIRE_ONCE");
} else {
buf[0] = '\0';
}
#else
if (opline->op2.u.constant.value.lval == ZEND_EVAL) {
snprintf(buf, sizeof(buf), "ZEND_EVAL");
} else if (opline->op2.u.constant.value.lval == ZEND_INCLUDE) {
snprintf(buf, sizeof(buf), "ZEND_INCLUDE");
} else if (opline->op2.u.constant.value.lval == ZEND_INCLUDE_ONCE) {
snprintf(buf, sizeof(buf), "ZEND_INCLUDE_ONCE");
} else if (opline->op2.u.constant.value.lval == ZEND_REQUIRE) {
snprintf(buf, sizeof(buf), "ZEND_REQUIRE");
} else if (opline->op2.u.constant.value.lval == ZEND_REQUIRE_ONCE) {
snprintf(buf, sizeof(buf), "ZEND_REQUIRE_ONCE");
} else {
buf[0] = '\0';
}
#endif
} else if ((op->ops & OP2_MASK) == OP2_ARG) {
snprintf(buf, sizeof(buf), "arg(%u)", OP2_OPLINE_NUM(opline));
} else if ((op->ops & OP2_MASK) == OP2_ISSET) {
#ifdef ZEND_ENGINE_2_4
if (opline->extended_value == ZEND_ISSET) {
snprintf(buf, sizeof(buf), "ZEND_ISSET");
} else if (opline->extended_value == ZEND_ISEMPTY) {
snprintf(buf, sizeof(buf), "ZEND_ISEMPTY");
} else {
buf[0] = '\0';
}
#else
if (opline->op2.u.constant.value.lval == ZEND_ISSET) {
snprintf(buf, sizeof(buf), "ZEND_ISSET");
} else if (opline->op2.u.constant.value.lval == ZEND_ISEMPTY) {
snprintf(buf, sizeof(buf), "ZEND_ISEMPTY");
} else {
buf[0] = '\0';
}
#endif
} else {
if (OP2_TYPE(opline) == IS_CONST) {
zval_used = 1;
#ifdef ZEND_ENGINE_2_4
add_assoc_string(el, "op2", get_zval((zval*)opline->op2.literal), 0);
#else
add_assoc_string(el, "op2", get_zval(&opline->op2.u.constant), 0);
#endif
} else if (OP2_TYPE(opline) == IS_TMP_VAR) {
snprintf(buf, sizeof(buf), "$tmp%u", VAR_NUM(OP2_VARR(opline)));
} else if (OP2_TYPE(opline) == IS_VAR) {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(OP2_VARR(opline)));
} else if (OP2_TYPE(opline) == IS_UNUSED) {
buf[0] = '\0';
} else {
snprintf(buf, sizeof(buf), "UNKNOWN NODE %d", OP2_TYPE(opline));
}
}
if (zval_used == 0) {
add_assoc_string(el, "op2", buf, 1);
}
/* result */
zval_used = 0;
if (RES_TYPE(opline) & IS_CV) {
snprintf(buf, sizeof(buf), "$cv%u(%s)", RES_VARR(opline), op_array->vars[RES_VARR(opline)].name);
} else
switch (op->ops & RES_MASK) {
case RES_STD:
if (RES_TYPE(opline) & IS_CONST) {
zval_used = 1;
#ifdef ZEND_ENGINE_2_4
add_assoc_string(el, "result", get_zval((zval*)opline->result.literal), 0);
#else
add_assoc_string(el, "result", get_zval(&opline->result.u.constant), 0);
#endif
} else if (RES_TYPE(opline) & IS_TMP_VAR) {
snprintf(buf, sizeof(buf), "$tmp%u", VAR_NUM(RES_VARR(opline)));
} else if (RES_TYPE(opline) & IS_VAR) {
#ifdef ZEND_ENGINE_2_4
if ((RES_TYPE(opline) & EXT_TYPE_UNUSED) != 0) {
#else
if ((opline->result.u.EA.type & EXT_TYPE_UNUSED) != 0) {
#endif
snprintf(buf, sizeof(buf), "$var%u (unused)", VAR_NUM(RES_VARR(opline)));
} else {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(RES_VARR(opline)));
}
} else if (RES_TYPE(opline) & IS_UNUSED) {
buf[0] = '\0';
} else {
snprintf(buf, sizeof(buf), "UNKNOWN NODE %d", RES_TYPE(opline));
}
break;
case RES_CLASS:
snprintf(buf, sizeof(buf), "$class%u", VAR_NUM(RES_VARR(opline)));
break;
case RES_TMP:
snprintf(buf, sizeof(buf), "$tmp%u", VAR_NUM(RES_VARR(opline)));
break;
case RES_VAR:
#ifdef ZEND_ENGINE_2_4
if ((RES_TYPE(opline) & EXT_TYPE_UNUSED) != 0) {
#else
if ((opline->result.u.EA.type & EXT_TYPE_UNUSED) != 0) {
#endif
snprintf(buf, sizeof(buf), "$var%u (unused)", VAR_NUM(RES_VARR(opline)));
} else {
snprintf(buf, sizeof(buf), "$var%u", VAR_NUM(RES_VARR(opline)));
}
break;
case RES_UNUSED:
buf[0] = '\0';
break;
case RES_OPLINE:
snprintf(buf, sizeof(buf), "opline(%d)", RES_OPLINE_NUM(opline));
break;
default:
snprintf(buf, sizeof(buf), "UNKNOWN NODE %d", RES_TYPE(opline));
break;
}
if (zval_used == 0) {
add_assoc_string(el, "result", buf, 1);
}
add_next_index_zval(return_value, el);
}
}
return return_value;
}
/* }}} */
/* {{{ get_cache_entry: get the cache_entry for the given file */
static ea_cache_entry *get_cache_entry(const char *file)
{
unsigned int slot;
ea_cache_entry *p;
ea_cache_entry *result = NULL;
if (file != NULL) {
EACCELERATOR_LOCK_RD();
for (slot = 0; slot < EA_HASH_SIZE; slot++) {
p = ea_mm_instance->hash[slot];
while (p != NULL) {
if (strcmp(p->realfilename, file) == 0) {
result = p;
}
p = p->next;
}
}
EACCELERATOR_UNLOCK_RD();
}
return result;
}
/* }}} */
/* {{{ PHP_FUNCTION(eaccelerator_dasm_file): get the op_arrays from a file that's cached
* This function will return an array with this elements:
* array() {
* [op_array] => array() // the op_array
* [classes] => array() { // an array with classes
* [class1] => array() { // an array with class methods
* [method1] => array() // the op_array of that method
* }
* }
* [functions]=> array() {
* [function1] => array() // the op_array of that function
* }
*/
PHP_FUNCTION(eaccelerator_dasm_file)
{
const char *file;
int file_len;
ea_cache_entry *p;
ea_fc_entry *fc;
zval *functions;
zval *classes;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
return;
}
if (ea_mm_instance == NULL || php_check_open_basedir(file TSRMLS_CC)) {
RETURN_NULL();
}
p = get_cache_entry(file);
if (p == NULL) {
RETURN_NULL();
}
array_init(return_value);
/* file op_array */
add_assoc_zval(return_value, "op_array", get_op_array(p->op_array TSRMLS_CC));
/* file functions */
fc = p->f_head;
MAKE_STD_ZVAL(functions);
array_init(functions);
while (fc != NULL) {
ea_op_array *func = (ea_op_array *) fc->fc;
add_assoc_zval(functions, func->function_name, get_op_array(func TSRMLS_CC));
fc = fc->next;
}
add_assoc_zval(return_value, "functions", functions);
/* file classes */
fc = p->c_head;
MAKE_STD_ZVAL(classes);
array_init(classes);
if (fc != NULL) {
while (fc != NULL) {
ea_class_entry *c = (ea_class_entry *) fc->fc;
if (c->type == ZEND_USER_CLASS) { /* get methods */
zval *methods;
Bucket *q;
MAKE_STD_ZVAL(methods);
array_init(methods);
q = c->function_table.pListHead;
while (q) {
ea_op_array *func = (ea_op_array *) q->pData;
if (func->type == ZEND_USER_FUNCTION) {
add_assoc_zval(methods, func->function_name, get_op_array(func TSRMLS_CC));
}
q = q->pListNext;
}
add_assoc_zval(classes, c->name, methods);
}
fc = fc->next;
}
}
add_assoc_zval(return_value, "classes", classes);
}
/* }}} */
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: et sw=4 ts=4 fdm=marker
* vim<600: et sw=4 ts=4
*/