summaryrefslogtreecommitdiff
path: root/src/sp_compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_compile.c')
-rw-r--r--src/sp_compile.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/sp_compile.c b/src/sp_compile.c
new file mode 100644
index 0000000..2902377
--- /dev/null
+++ b/src/sp_compile.c
@@ -0,0 +1,53 @@
1#include "php_snuffleupagus.h"
2
3ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus);
4
5static zend_op_array *(*orig_compile_file)(zend_file_handle *, int);
6static zend_op_array *(*orig_compile_string)(zval *, char *);
7
8zend_op_array *sp_compile_file(zend_file_handle *file_handle, int type) {
9 zend_op_array *ret = orig_compile_file(file_handle, type);
10
11 const sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions;
12
13 while (config && config->data) {
14 const char* function_name = ((sp_disabled_function*)config->data)->function;
15 const pcre* function_name_regexp = ((sp_disabled_function*)config->data)->r_function;
16
17 sp_log_err("checking for %s", function_name);
18 // EG(function_table)->arData[count - 1].val.value.func->internal_function.handler = PHP_FN(check_disabled_function);
19
20 if (function_name) {
21 if (HOOK_FUNCTION(function_name, disabled_functions_hook, PHP_FN(check_disabled_function), true) == SUCCESS) {
22 sp_log_err("Successfully hooked %s", function_name);
23 }
24 break;
25 } else if (function_name_regexp) {
26 sp_log_err("error", "We'll hook regard later.");
27 }
28 config = config->next;
29 }
30
31 return ret;
32}
33
34zend_op_array *sp_compile_string(zval *source_string, char *filename) {
35 zend_op_array *ret = orig_compile_string(source_string, filename);
36 sp_log_err("in compile_string : filename is :%s", filename);
37 return ret;
38}
39
40
41int hook_compile(void) {
42 TSRMLS_FETCH();
43
44 /* zend_compile_file is used to compile php file */
45 orig_compile_file = zend_compile_file;
46 zend_compile_file = sp_compile_file;
47
48 /* zend_compile_string is used to compile php string */
49 orig_compile_string = zend_compile_string;
50 zend_compile_string = sp_compile_string;
51
52 return SUCCESS;
53} \ No newline at end of file