This commit is contained in:
parent
ecbfced114
commit
210d32db06
|
|
@ -1,4 +1,3 @@
|
||||||
/* config.m4 */
|
|
||||||
dnl Enable or disable dec_interceptor as a PHP extension
|
dnl Enable or disable dec_interceptor as a PHP extension
|
||||||
PHP_ARG_ENABLE(dec_interceptor, whether to enable dec_interceptor support,
|
PHP_ARG_ENABLE(dec_interceptor, whether to enable dec_interceptor support,
|
||||||
[ --enable-dec_interceptor Enable dec_interceptor support])
|
[ --enable-dec_interceptor Enable dec_interceptor support])
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
/* dec_interceptor.c */
|
|
||||||
#include "php.h"
|
#include "php.h"
|
||||||
#include "php_ini.h"
|
#include "php_ini.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
|
|
@ -6,7 +5,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
/* chain-hook originals */
|
/* 链式保存原始指针 */
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -17,7 +16,7 @@ zend_op_array *hook_compile_file(zend_file_handle *file_handle, int type)
|
||||||
if (f) {
|
if (f) {
|
||||||
fprintf(f, "[%ld] compile_file: %s\n",
|
fprintf(f, "[%ld] compile_file: %s\n",
|
||||||
(long)time(NULL),
|
(long)time(NULL),
|
||||||
file_handle->filename ?: "(null)");
|
file_handle->filename ? file_handle->filename : "(null)");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
return prev_compile_file(file_handle, type);
|
return prev_compile_file(file_handle, type);
|
||||||
|
|
@ -30,7 +29,7 @@ zend_op_array *hook_compile_string(zval *source_string, const char *filename)
|
||||||
if (f) {
|
if (f) {
|
||||||
fprintf(f, "[%ld] compile_string: %s\n",
|
fprintf(f, "[%ld] compile_string: %s\n",
|
||||||
(long)time(NULL),
|
(long)time(NULL),
|
||||||
filename ?: "(null)");
|
filename ? filename : "(null)");
|
||||||
if (Z_TYPE_P(source_string) == IS_STRING) {
|
if (Z_TYPE_P(source_string) == IS_STRING) {
|
||||||
fwrite(Z_STRVAL_P(source_string), 1, Z_STRLEN_P(source_string), f);
|
fwrite(Z_STRVAL_P(source_string), 1, Z_STRLEN_P(source_string), f);
|
||||||
fprintf(f, "\n----\n");
|
fprintf(f, "\n----\n");
|
||||||
|
|
@ -42,13 +41,13 @@ zend_op_array *hook_compile_string(zval *source_string, const char *filename)
|
||||||
|
|
||||||
PHP_MINIT_FUNCTION(dec_interceptor)
|
PHP_MINIT_FUNCTION(dec_interceptor)
|
||||||
{
|
{
|
||||||
/* chain hook setup */
|
/* 注册链式钩子 */
|
||||||
prev_compile_file = zend_compile_file;
|
prev_compile_file = zend_compile_file;
|
||||||
zend_compile_file = hook_compile_file;
|
zend_compile_file = hook_compile_file;
|
||||||
prev_compile_string = zend_compile_string;
|
prev_compile_string = zend_compile_string;
|
||||||
zend_compile_string = hook_compile_string;
|
zend_compile_string = hook_compile_string;
|
||||||
|
|
||||||
/* log init */
|
/* 初始化日志 */
|
||||||
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
FILE *f = fopen("/tmp/dec_interceptor.log", "a");
|
||||||
if (f) {
|
if (f) {
|
||||||
fprintf(f, "[%ld] MINIT: chain hooks registered\n", (long)time(NULL));
|
fprintf(f, "[%ld] MINIT: chain hooks registered\n", (long)time(NULL));
|
||||||
|
|
@ -59,6 +58,7 @@ PHP_MINIT_FUNCTION(dec_interceptor)
|
||||||
|
|
||||||
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;
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
/* php_dec_interceptor.h */
|
|
||||||
#ifndef PHP_DEC_INTERCEPTOR_H
|
#ifndef PHP_DEC_INTERCEPTOR_H
|
||||||
#define PHP_DEC_INTERCEPTOR_H
|
#define PHP_DEC_INTERCEPTOR_H
|
||||||
|
|
||||||
|
|
@ -10,11 +9,11 @@
|
||||||
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
|
||||||
|
|
||||||
/* chain-hook originals */
|
/* 链式保存原始指针 */
|
||||||
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);
|
||||||
|
|
||||||
/* hooks */
|
/* 钩子函数声明 */
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue