forked from mfmans/php-eval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_eval.c
103 lines (79 loc) · 2.11 KB
/
php_eval.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
/* $Id$ */
#include "php.h"
#include "ext/standard/info.h"
#define EVAL_CALLBACK_FUNCTION "__eval"
static zend_op_array* (*old_compile_string)(zval *source_string, char *filename TSRMLS_DC);
static zend_op_array* eval_compile_string(zval *source_string, char *filename TSRMLS_DC)
{
zend_op_array *op_array = NULL;
int op_compiled = 0;
if(strstr(filename, "eval()'d code")) {
if(zend_hash_str_exists(CG(function_table), EVAL_CALLBACK_FUNCTION, strlen(EVAL_CALLBACK_FUNCTION) TSRMLS_CC)) {
zval function;
zval retval;
zval parameter[2];
parameter[0] = *source_string;
ZVAL_STRING(&function, EVAL_CALLBACK_FUNCTION);
ZVAL_STRING(¶meter[1], filename);
if(call_user_function(CG(function_table), NULL, &function, &retval, 2, parameter TSRMLS_CC) == SUCCESS) {
switch(Z_TYPE(retval)) {
case IS_STRING:
op_array = old_compile_string(&retval, filename TSRMLS_CC);
case IS_FALSE:
op_compiled = 1;
break;
}
}
zval_dtor(&function);
zval_dtor(&retval);
zval_dtor(¶meter[1]);
}
}
if(op_compiled) {
return op_array;
} else {
return old_compile_string(source_string, filename TSRMLS_CC);
}
}
PHP_MINIT_FUNCTION(eval)
{
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(eval)
{
return SUCCESS;
}
PHP_RINIT_FUNCTION(eval)
{
old_compile_string = zend_compile_string;
zend_compile_string = eval_compile_string;
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(eval)
{
zend_compile_string = old_compile_string;
return SUCCESS;
}
PHP_MINFO_FUNCTION(eval)
{
php_info_print_table_start();
php_info_print_table_row(2, "eval() hooking", "enabled");
php_info_print_table_row(2, "callback function", EVAL_CALLBACK_FUNCTION);
php_info_print_table_end();
}
zend_function_entry eval_functions[] = {
ZEND_FE_END
};
zend_module_entry eval_module_entry = {
STANDARD_MODULE_HEADER,
"eval",
eval_functions,
PHP_MINIT(eval),
PHP_MSHUTDOWN(eval),
PHP_RINIT(eval),
PHP_RSHUTDOWN(eval),
PHP_MINFO(eval),
"0.0.1-dev",
STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(eval)