This commit is contained in:
parent
69b1ab3c3c
commit
22ad8735e1
|
|
@ -0,0 +1,6 @@
|
||||||
|
PHP_ARG_ENABLE(dec_interceptor, whether to enable dec_interceptor support,
|
||||||
|
[ --enable-dec_interceptor Enable dec_interceptor support])
|
||||||
|
|
||||||
|
if test "$PHP_DEC_INTERCEPTOR" = "yes"; then
|
||||||
|
PHP_NEW_EXTENSION(dec_interceptor, dec_interceptor.c, $ext_shared)
|
||||||
|
fi
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
#include "php.h"
|
||||||
|
#include "php_ini.h"
|
||||||
|
#include "ext/standard/info.h"
|
||||||
|
#include "php_dec_interceptor.h"
|
||||||
|
|
||||||
|
static zend_op_array* (*original_compile_file)(zend_file_handle *file_handle, int type);
|
||||||
|
|
||||||
|
static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int type) {
|
||||||
|
// 尝试拷贝解密后的 PHP 文件
|
||||||
|
if (file_handle && file_handle->filename && file_handle->handle.fp) {
|
||||||
|
const char *source_path = file_handle->filename;
|
||||||
|
|
||||||
|
FILE *fp = fopen(source_path, "rb");
|
||||||
|
if (fp) {
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
long size = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
if (size > 0 && size < 100 * 1024 * 1024) { // 限制大小避免错误
|
||||||
|
char *buffer = emalloc(size + 1);
|
||||||
|
fread(buffer, 1, size, fp);
|
||||||
|
buffer[size] = '\0';
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
// 保存到同目录 .dec.php 文件
|
||||||
|
char output_path[PATH_MAX];
|
||||||
|
snprintf(output_path, sizeof(output_path), "%s.dec.php", source_path);
|
||||||
|
|
||||||
|
FILE *out = fopen(output_path, "wb");
|
||||||
|
if (out) {
|
||||||
|
fwrite(buffer, 1, size, out);
|
||||||
|
fclose(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
efree(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用原始编译器
|
||||||
|
return original_compile_file(file_handle, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_MINIT_FUNCTION(dec_interceptor) {
|
||||||
|
original_compile_file = zend_compile_file;
|
||||||
|
zend_compile_file = custom_compile_file;
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_MSHUTDOWN_FUNCTION(dec_interceptor) {
|
||||||
|
zend_compile_file = original_compile_file;
|
||||||
|
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(dec_interceptor),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
PHP_MINFO(dec_interceptor),
|
||||||
|
"0.1",
|
||||||
|
STANDARD_MODULE_PROPERTIES
|
||||||
|
};
|
||||||
|
|
||||||
|
ZEND_GET_MODULE(dec_interceptor)
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef PHP_DEC_INTERCEPTOR_H
|
||||||
|
#define PHP_DEC_INTERCEPTOR_H
|
||||||
|
|
||||||
|
#define PHP_DEC_INTERCEPTOR_VERSION "0.1"
|
||||||
|
|
||||||
|
extern zend_module_entry dec_interceptor_module_entry;
|
||||||
|
#define phpext_dec_interceptor_ptr &dec_interceptor_module_entry
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue