From 78791de7e983b72bca4bc99a52985c77577f8737 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 30 Jul 2025 23:00:18 +0800 Subject: [PATCH] . --- dec_interceptor/dec_interceptor_string.c | 43 +++++++++++------------- dec_interceptor/php_dec_interceptor.h | 2 -- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/dec_interceptor/dec_interceptor_string.c b/dec_interceptor/dec_interceptor_string.c index f7b643a7..33d32857 100644 --- a/dec_interceptor/dec_interceptor_string.c +++ b/dec_interceptor/dec_interceptor_string.c @@ -3,9 +3,8 @@ #include "ext/standard/info.h" #include "php_dec_interceptor.h" #include -#include -/* 链式保存原始指针 */ +/* 保存原始编译函数指针 */ zend_op_array *(*prev_compile_file)(zend_file_handle *file_handle, int type) = NULL; zend_op_array *(*prev_compile_string)(zval *source_string, const char *filename) = NULL; @@ -14,12 +13,10 @@ zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type) { FILE *f = fopen("/tmp/dec_interceptor.log", "a"); if (f) { - fprintf(f, "[%ld] compile_file: %s\n", - (long)time(NULL), - file_handle->filename ? file_handle->filename : "(null)"); + fprintf(f, "[%ld] hook_compile_file called\n", (long)time(NULL)); fclose(f); } - return prev_compile_file(file_handle, type); + return prev_compile_file ? prev_compile_file(file_handle, type) : NULL; } /* hook zend_compile_string */ @@ -27,40 +24,40 @@ zend_op_array *hook_compile_string(zval *source_string, const char *filename) { FILE *f = fopen("/tmp/dec_interceptor.log", "a"); if (f) { - fprintf(f, "[%ld] compile_string: %s\n", - (long)time(NULL), - filename ? filename : "(null)"); - if (Z_TYPE_P(source_string) == IS_STRING) { - fwrite(Z_STRVAL_P(source_string), 1, Z_STRLEN_P(source_string), f); - fprintf(f, "\n----\n"); - } + fprintf(f, "[%ld] hook_compile_string called\n", (long)time(NULL)); fclose(f); } - return prev_compile_string(source_string, filename); + return prev_compile_string ? prev_compile_string(source_string, filename) : NULL; } PHP_MINIT_FUNCTION(dec_interceptor) { - /* 注册链式钩子 */ - prev_compile_file = zend_compile_file; - zend_compile_file = hook_compile_file; + prev_compile_file = zend_compile_file; + zend_compile_file = hook_compile_file; + prev_compile_string = zend_compile_string; zend_compile_string = hook_compile_string; - /* 初始化日志 */ FILE *f = fopen("/tmp/dec_interceptor.log", "a"); if (f) { - fprintf(f, "[%ld] MINIT: chain hooks registered\n", (long)time(NULL)); + fprintf(f, "[%ld] MINIT: dec_interceptor initialized\n", (long)time(NULL)); fclose(f); } + return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(dec_interceptor) { - /* 恢复原始指针 */ - zend_compile_file = prev_compile_file; + zend_compile_file = prev_compile_file; zend_compile_string = prev_compile_string; + + FILE *f = fopen("/tmp/dec_interceptor.log", "a"); + if (f) { + fprintf(f, "[%ld] MSHUTDOWN: dec_interceptor shutdown\n", (long)time(NULL)); + fclose(f); + } + return SUCCESS; } @@ -71,14 +68,14 @@ PHP_MINFO_FUNCTION(dec_interceptor) php_info_print_table_end(); } +/* 模块定义 */ zend_module_entry dec_interceptor_module_entry = { STANDARD_MODULE_HEADER, "dec_interceptor", NULL, PHP_MINIT(dec_interceptor), PHP_MSHUTDOWN(dec_interceptor), - NULL, - NULL, + NULL, NULL, PHP_MINFO(dec_interceptor), PHP_DEC_INTERCEPTOR_VERSION, STANDARD_MODULE_PROPERTIES diff --git a/dec_interceptor/php_dec_interceptor.h b/dec_interceptor/php_dec_interceptor.h index 4a61b276..848aa0dd 100644 --- a/dec_interceptor/php_dec_interceptor.h +++ b/dec_interceptor/php_dec_interceptor.h @@ -9,11 +9,9 @@ extern zend_module_entry dec_interceptor_module_entry; #define phpext_dec_interceptor_ptr &dec_interceptor_module_entry -/* 链式保存原始指针 */ extern zend_op_array *(*prev_compile_file)(zend_file_handle *file_handle, int type); extern zend_op_array *(*prev_compile_string)(zval *source_string, const char *filename); -/* 钩子函数声明 */ zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type); zend_op_array *hook_compile_string(zval *source_string, const char *filename);