This commit is contained in:
parent
03ffa3f8a2
commit
6230214f8b
|
|
@ -4,12 +4,10 @@
|
||||||
#include "php_dec_interceptor.h"
|
#include "php_dec_interceptor.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/* 保存原始指针 */
|
|
||||||
zend_op_array *(*prev_compile_file)(zend_file_handle *file_handle, int type) = NULL;
|
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_op_array *(*prev_compile_string)(zval *source_string, const char *filename) = NULL;
|
||||||
void (*prev_execute_ex)(zend_execute_data *execute_data) = NULL;
|
zend_internal_function_handler_t prev_execute_internal = NULL;
|
||||||
|
|
||||||
/* hook zend_compile_file */
|
|
||||||
zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type)
|
zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type)
|
||||||
{
|
{
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
|
|
@ -20,7 +18,6 @@ zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type)
|
||||||
return prev_compile_file ? prev_compile_file(file_handle, type) : NULL;
|
return prev_compile_file ? prev_compile_file(file_handle, type) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hook zend_compile_string */
|
|
||||||
zend_op_array *hook_compile_string(zval *source_string, const char *filename)
|
zend_op_array *hook_compile_string(zval *source_string, const char *filename)
|
||||||
{
|
{
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
|
|
@ -31,53 +28,24 @@ zend_op_array *hook_compile_string(zval *source_string, const char *filename)
|
||||||
return prev_compile_string ? prev_compile_string(source_string, filename) : NULL;
|
return prev_compile_string ? prev_compile_string(source_string, filename) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hook zend_execute_ex */
|
void hook_execute_internal(zend_execute_data *execute_data, zval *return_value)
|
||||||
void hook_execute_ex(zend_execute_data *execute_data)
|
|
||||||
{
|
{
|
||||||
const zend_function *func = execute_data->func;
|
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
const zend_function *func = execute_data->func;
|
||||||
if (func && func->common.function_name) {
|
if (func && func->common.function_name) {
|
||||||
fprintf(f, "[%ld] hook_execute_ex: %s\n", (long)time(NULL), ZSTR_VAL(func->common.function_name));
|
fprintf(f, "[%ld] hook_execute_internal: %s\n", (long)time(NULL), ZSTR_VAL(func->common.function_name));
|
||||||
} else {
|
} else {
|
||||||
fprintf(f, "[%ld] hook_execute_ex: (anonymous or internal)\n", (long)time(NULL));
|
fprintf(f, "[%ld] hook_execute_internal: (anonymous internal)\n", (long)time(NULL));
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_execute_ex) {
|
if (prev_execute_internal) {
|
||||||
prev_execute_ex(execute_data);
|
prev_execute_internal(execute_data, return_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MINIT */
|
|
||||||
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);
|
|
||||||
fprintf(f, " zend_execute_ex addr: %p\n", zend_execute_ex);
|
|
||||||
fprintf(f, " hook_execute_ex addr: %p\n", hook_execute_ex);
|
|
||||||
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_ex = zend_execute_ex;
|
|
||||||
zend_execute_ex = hook_execute_ex;
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* RINIT */
|
|
||||||
PHP_RINIT_FUNCTION(dec_interceptor)
|
PHP_RINIT_FUNCTION(dec_interceptor)
|
||||||
{
|
{
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
|
|
@ -88,12 +56,35 @@ PHP_RINIT_FUNCTION(dec_interceptor)
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MSHUTDOWN */
|
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;
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
PHP_MSHUTDOWN_FUNCTION(dec_interceptor)
|
PHP_MSHUTDOWN_FUNCTION(dec_interceptor)
|
||||||
{
|
{
|
||||||
zend_compile_file = prev_compile_file;
|
zend_compile_file = prev_compile_file;
|
||||||
zend_compile_string = prev_compile_string;
|
zend_compile_string = prev_compile_string;
|
||||||
zend_execute_ex = prev_execute_ex;
|
zend_execute_internal = prev_execute_internal;
|
||||||
|
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
|
@ -104,7 +95,6 @@ PHP_MSHUTDOWN_FUNCTION(dec_interceptor)
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MINFO */
|
|
||||||
PHP_MINFO_FUNCTION(dec_interceptor)
|
PHP_MINFO_FUNCTION(dec_interceptor)
|
||||||
{
|
{
|
||||||
php_info_print_table_start();
|
php_info_print_table_start();
|
||||||
|
|
@ -112,7 +102,6 @@ PHP_MINFO_FUNCTION(dec_interceptor)
|
||||||
php_info_print_table_end();
|
php_info_print_table_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MODULE ENTRY */
|
|
||||||
zend_module_entry dec_interceptor_module_entry = {
|
zend_module_entry dec_interceptor_module_entry = {
|
||||||
STANDARD_MODULE_HEADER,
|
STANDARD_MODULE_HEADER,
|
||||||
"dec_interceptor",
|
"dec_interceptor",
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,17 @@
|
||||||
extern zend_module_entry dec_interceptor_module_entry;
|
extern zend_module_entry dec_interceptor_module_entry;
|
||||||
#define phpext_dec_interceptor_ptr &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_file)(zend_file_handle *file_handle, int type);
|
||||||
extern zend_op_array *(*prev_compile_string)(zval *source_string, const char *filename);
|
extern zend_op_array *(*prev_compile_string)(zval *source_string, const char *filename);
|
||||||
extern void (*prev_execute_ex)(zend_execute_data *execute_data);
|
extern zend_internal_function_handler_t prev_execute_internal;
|
||||||
|
|
||||||
/* 拦截函数 */
|
|
||||||
zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type);
|
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);
|
zend_op_array *hook_compile_string(zval *source_string, const char *filename);
|
||||||
void hook_execute_ex(zend_execute_data *execute_data);
|
void hook_execute_internal(zend_execute_data *execute_data, zval *return_value);
|
||||||
|
|
||||||
|
PHP_RINIT_FUNCTION(dec_interceptor);
|
||||||
PHP_MINIT_FUNCTION(dec_interceptor);
|
PHP_MINIT_FUNCTION(dec_interceptor);
|
||||||
PHP_MSHUTDOWN_FUNCTION(dec_interceptor);
|
PHP_MSHUTDOWN_FUNCTION(dec_interceptor);
|
||||||
PHP_RINIT_FUNCTION(dec_interceptor);
|
|
||||||
PHP_RSHUTDOWN_FUNCTION(dec_interceptor);
|
|
||||||
PHP_MINFO_FUNCTION(dec_interceptor);
|
PHP_MINFO_FUNCTION(dec_interceptor);
|
||||||
|
|
||||||
#endif /* PHP_DEC_INTERCEPTOR_H */
|
#endif /* PHP_DEC_INTERCEPTOR_H */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue