89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
#include "php.h"
|
|
#include "php_ini.h"
|
|
#include "ext/standard/info.h"
|
|
#include "php_dec_interceptor.h"
|
|
#include <time.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
|
|
/* 保存原始函数指针 */
|
|
zend_op_array *(*original_compile_file)(zend_file_handle *file_handle, int type) = NULL;
|
|
zend_op_array *(*original_compile_string)(zval *source_string, const char *filename) = NULL;
|
|
|
|
/* hook zend_compile_file */
|
|
zend_op_array *custom_compile_file(zend_file_handle *file_handle, int type)
|
|
{
|
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
|
if (f) {
|
|
time_t t = time(NULL);
|
|
fprintf(f, "[%ld] compile_file: %s\n", t,
|
|
file_handle->filename ? file_handle->filename : "(null)");
|
|
fclose(f);
|
|
}
|
|
return original_compile_file(file_handle, type);
|
|
}
|
|
|
|
/* hook zend_compile_string */
|
|
zend_op_array *custom_compile_string(zval *source_string, const char *filename)
|
|
{
|
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
|
if (f) {
|
|
time_t t = time(NULL);
|
|
fprintf(f, "[%ld] compile_string: %s\n", t, 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");
|
|
}
|
|
fclose(f);
|
|
}
|
|
|
|
return original_compile_string(source_string, filename);
|
|
}
|
|
|
|
PHP_MINIT_FUNCTION(dec_interceptor)
|
|
{
|
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
|
if (f) {
|
|
time_t t = time(NULL);
|
|
fprintf(f, "[%ld] MINIT: hook setup\n", t);
|
|
fclose(f);
|
|
}
|
|
|
|
original_compile_file = zend_compile_file;
|
|
zend_compile_file = custom_compile_file;
|
|
|
|
original_compile_string = zend_compile_string;
|
|
zend_compile_string = custom_compile_string;
|
|
|
|
return SUCCESS;
|
|
}
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(dec_interceptor)
|
|
{
|
|
zend_compile_file = original_compile_file;
|
|
zend_compile_string = original_compile_string;
|
|
return SUCCESS;
|
|
}
|
|
|
|
PHP_MINFO_FUNCTION(dec_interceptor)
|
|
{
|
|
php_info_print_table_start();
|
|
php_info_print_table_row(2, "dec_interceptor support", "enabled");
|
|
php_info_print_table_end();
|
|
}
|
|
|
|
zend_module_entry dec_interceptor_module_entry = {
|
|
STANDARD_MODULE_HEADER,
|
|
"dec_interceptor",
|
|
NULL,
|
|
PHP_MINIT(dec_interceptor),
|
|
PHP_MSHUTDOWN_FUNCTION(dec_interceptor),
|
|
NULL,
|
|
NULL,
|
|
PHP_MINFO_FUNCTION(dec_interceptor),
|
|
PHP_DEC_INTERCEPTOR_VERSION,
|
|
STANDARD_MODULE_PROPERTIES
|
|
};
|
|
|
|
ZEND_GET_MODULE(dec_interceptor)
|