This commit is contained in:
parent
9bba235035
commit
d0b8d25070
|
|
@ -6,25 +6,42 @@
|
||||||
static zend_op_array* (*original_compile_file)(zend_file_handle *file_handle, int type);
|
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) {
|
static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int type) {
|
||||||
// 尝试拷贝解密后的 PHP 文件
|
fprintf(stderr, "[hook] file_handle->type = %d\n", file_handle->type);
|
||||||
if (file_handle && file_handle->filename && file_handle->handle.fp) {
|
|
||||||
|
if (file_handle && file_handle->filename) {
|
||||||
const char *source_path = file_handle->filename;
|
const char *source_path = file_handle->filename;
|
||||||
|
php_printf("[dec_interceptor] compiling: %s\n", source_path);
|
||||||
|
|
||||||
php_printf("[dec_interceptor] compiling: %s\n", source_path); // ✅ 输出调试信息
|
char *buffer = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
FILE *fp = fopen(source_path, "rb");
|
// ✅ 情况1:标准文件句柄(明文 PHP 文件)
|
||||||
if (fp) {
|
if (file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
|
||||||
|
FILE *fp = file_handle->handle.fp;
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
long size = ftell(fp);
|
size = ftell(fp);
|
||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
if (size > 0 && size < 100 * 1024 * 1024) { // 限制大小避免错误
|
if (size > 0 && size < 100 * 1024 * 1024) {
|
||||||
char *buffer = emalloc(size + 1);
|
buffer = emalloc(size + 1);
|
||||||
fread(buffer, 1, size, fp);
|
fread(buffer, 1, size, fp);
|
||||||
buffer[size] = '\0';
|
buffer[size] = '\0';
|
||||||
fclose(fp);
|
}
|
||||||
|
|
||||||
// 保存到同目录 .dec.php 文件
|
// ✅ 情况2:stream(Swoole 加密文件,通过 swoole_loader 解密)
|
||||||
|
} else if (file_handle->type == ZEND_HANDLE_STREAM && file_handle->handle.stream.reader) {
|
||||||
|
zend_stream_handle *stream = &file_handle->handle.stream;
|
||||||
|
size = stream->handle.len;
|
||||||
|
if (size > 0 && size < 100 * 1024 * 1024) {
|
||||||
|
buffer = emalloc(size + 1);
|
||||||
|
size_t read_bytes = stream->reader(stream, buffer, size);
|
||||||
|
buffer[read_bytes] = '\0';
|
||||||
|
size = read_bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 如果成功读取内容,保存为 .dec.php 文件
|
||||||
|
if (buffer && size > 0) {
|
||||||
char output_path[PATH_MAX];
|
char output_path[PATH_MAX];
|
||||||
snprintf(output_path, sizeof(output_path), "%s.dec.php", source_path);
|
snprintf(output_path, sizeof(output_path), "%s.dec.php", source_path);
|
||||||
|
|
||||||
|
|
@ -32,17 +49,20 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
|
||||||
if (out) {
|
if (out) {
|
||||||
fwrite(buffer, 1, size, out);
|
fwrite(buffer, 1, size, out);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
fprintf(stderr, "[dump] saved to: %s\n", output_path);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "[dump] failed to save: %s\n", output_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
efree(buffer);
|
efree(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 调用原始编译器
|
// 调用原始 Zend 编译器
|
||||||
return original_compile_file(file_handle, type);
|
return original_compile_file(file_handle, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PHP_MINIT_FUNCTION(dec_interceptor) {
|
PHP_MINIT_FUNCTION(dec_interceptor) {
|
||||||
original_compile_file = zend_compile_file;
|
original_compile_file = zend_compile_file;
|
||||||
zend_compile_file = custom_compile_file;
|
zend_compile_file = custom_compile_file;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue