This commit is contained in:
hailin 2025-07-31 10:06:08 +08:00
parent 6230214f8b
commit db32006e60
2 changed files with 18 additions and 22 deletions

View File

@ -6,7 +6,7 @@
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;
zend_internal_function_handler_t prev_execute_internal = NULL;
void (*prev_execute_ex)(zend_execute_data *execute_data) = NULL;
zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type)
{
@ -28,21 +28,21 @@ zend_op_array *hook_compile_string(zval *source_string, const char *filename)
return prev_compile_string ? prev_compile_string(source_string, filename) : NULL;
}
void hook_execute_internal(zend_execute_data *execute_data, zval *return_value)
void hook_execute_ex(zend_execute_data *execute_data)
{
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
if (f) {
const zend_function *func = execute_data->func;
if (func && func->common.function_name) {
fprintf(f, "[%ld] hook_execute_internal: %s\n", (long)time(NULL), ZSTR_VAL(func->common.function_name));
fprintf(f, "[%ld] hook_execute_ex: %s\n", (long)time(NULL), ZSTR_VAL(func->common.function_name));
} else {
fprintf(f, "[%ld] hook_execute_internal: (anonymous internal)\n", (long)time(NULL));
fprintf(f, "[%ld] hook_execute_ex: (no name)\n", (long)time(NULL));
}
fclose(f);
}
if (prev_execute_internal) {
prev_execute_internal(execute_data, return_value);
if (prev_execute_ex) {
prev_execute_ex(execute_data);
}
}
@ -58,24 +58,20 @@ PHP_RINIT_FUNCTION(dec_interceptor)
PHP_MINIT_FUNCTION(dec_interceptor)
{
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
if (f) {
fprintf(f, "[%ld] MINIT: dec_interceptor initialized\n", (long)time(NULL));
fprintf(f, " zend_compile_file addr: %p\n", zend_compile_file);
fprintf(f, " hook_compile_file addr: %p\n", hook_compile_file);
fprintf(f, " zend_compile_string addr: %p\n", zend_compile_string);
fprintf(f, " hook_compile_string addr: %p\n", hook_compile_string);
fclose(f);
}
prev_compile_file = zend_compile_file;
zend_compile_file = hook_compile_file;
prev_compile_string = zend_compile_string;
zend_compile_string = hook_compile_string;
prev_execute_internal = zend_execute_internal;
zend_execute_internal = hook_execute_internal;
prev_execute_ex = zend_execute_ex;
zend_execute_ex = hook_execute_ex;
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
if (f) {
fprintf(f, "[%ld] MINIT done\n", (long)time(NULL));
fclose(f);
}
return SUCCESS;
}
@ -84,11 +80,11 @@ PHP_MSHUTDOWN_FUNCTION(dec_interceptor)
{
zend_compile_file = prev_compile_file;
zend_compile_string = prev_compile_string;
zend_execute_internal = prev_execute_internal;
zend_execute_ex = prev_execute_ex;
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
if (f) {
fprintf(f, "[%ld] MSHUTDOWN: dec_interceptor shutdown\n", (long)time(NULL));
fprintf(f, "[%ld] MSHUTDOWN done\n", (long)time(NULL));
fclose(f);
}

View File

@ -12,11 +12,11 @@ extern zend_module_entry 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);
extern zend_internal_function_handler_t prev_execute_internal;
extern void (*prev_execute_ex)(zend_execute_data *execute_data);
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);
void hook_execute_internal(zend_execute_data *execute_data, zval *return_value);
void hook_execute_ex(zend_execute_data *execute_data);
PHP_RINIT_FUNCTION(dec_interceptor);
PHP_MINIT_FUNCTION(dec_interceptor);