From 868f96c759b6650d88ff9f4fbc5c048302134248 Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Wed, 20 Sep 2017 10:11:01 +0200 Subject: Initial import --- src/sp_compile.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/sp_compile.c (limited to 'src/sp_compile.c') 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 @@ +#include "php_snuffleupagus.h" + +ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus); + +static zend_op_array *(*orig_compile_file)(zend_file_handle *, int); +static zend_op_array *(*orig_compile_string)(zval *, char *); + +zend_op_array *sp_compile_file(zend_file_handle *file_handle, int type) { + zend_op_array *ret = orig_compile_file(file_handle, type); + + const sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_functions->disabled_functions; + + while (config && config->data) { + const char* function_name = ((sp_disabled_function*)config->data)->function; + const pcre* function_name_regexp = ((sp_disabled_function*)config->data)->r_function; + + sp_log_err("checking for %s", function_name); + // EG(function_table)->arData[count - 1].val.value.func->internal_function.handler = PHP_FN(check_disabled_function); + + if (function_name) { + if (HOOK_FUNCTION(function_name, disabled_functions_hook, PHP_FN(check_disabled_function), true) == SUCCESS) { + sp_log_err("Successfully hooked %s", function_name); + } + break; + } else if (function_name_regexp) { + sp_log_err("error", "We'll hook regard later."); + } + config = config->next; + } + + return ret; +} + +zend_op_array *sp_compile_string(zval *source_string, char *filename) { + zend_op_array *ret = orig_compile_string(source_string, filename); + sp_log_err("in compile_string : filename is :%s", filename); + return ret; +} + + +int hook_compile(void) { + TSRMLS_FETCH(); + + /* zend_compile_file is used to compile php file */ + orig_compile_file = zend_compile_file; + zend_compile_file = sp_compile_file; + + /* zend_compile_string is used to compile php string */ + orig_compile_string = zend_compile_string; + zend_compile_string = sp_compile_string; + + return SUCCESS; +} \ No newline at end of file -- cgit v1.3