This commit is contained in:
parent
d0b8d25070
commit
27a5cfbb5e
|
|
@ -2,6 +2,7 @@
|
||||||
#include "php_ini.h"
|
#include "php_ini.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
#include "php_dec_interceptor.h"
|
#include "php_dec_interceptor.h"
|
||||||
|
#include "main/php_streams.h" // ✅ 必须包含,用于 php_stream 结构
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -15,7 +16,7 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
// ✅ 情况1:标准文件句柄(明文 PHP 文件)
|
// ✅ 情况1:标准文件句柄
|
||||||
if (file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
|
if (file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
|
||||||
FILE *fp = file_handle->handle.fp;
|
FILE *fp = file_handle->handle.fp;
|
||||||
fseek(fp, 0, SEEK_END);
|
fseek(fp, 0, SEEK_END);
|
||||||
|
|
@ -28,19 +29,23 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
|
||||||
buffer[size] = '\0';
|
buffer[size] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 情况2:stream(Swoole 加密文件,通过 swoole_loader 解密)
|
// ✅ 情况2:stream 句柄(swoole_loader 加密文件解密后走这个分支)
|
||||||
} else if (file_handle->type == ZEND_HANDLE_STREAM && file_handle->handle.stream.reader) {
|
} else if (file_handle->type == ZEND_HANDLE_STREAM && file_handle->handle.stream.handle) {
|
||||||
zend_stream_handle *stream = &file_handle->handle.stream;
|
php_stream *stream = (php_stream *)file_handle->handle.stream.handle;
|
||||||
size = stream->handle.len;
|
|
||||||
|
php_stream_seek(stream, 0, SEEK_END);
|
||||||
|
size = php_stream_tell(stream);
|
||||||
|
php_stream_seek(stream, 0, SEEK_SET);
|
||||||
|
|
||||||
if (size > 0 && size < 100 * 1024 * 1024) {
|
if (size > 0 && size < 100 * 1024 * 1024) {
|
||||||
buffer = emalloc(size + 1);
|
buffer = emalloc(size + 1);
|
||||||
size_t read_bytes = stream->reader(stream, buffer, size);
|
size_t read_bytes = php_stream_read(stream, buffer, size);
|
||||||
buffer[read_bytes] = '\0';
|
buffer[read_bytes] = '\0';
|
||||||
size = read_bytes;
|
size = read_bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 如果成功读取内容,保存为 .dec.php 文件
|
// ✅ 保存为 .dec.php
|
||||||
if (buffer && size > 0) {
|
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);
|
||||||
|
|
@ -58,7 +63,6 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用原始 Zend 编译器
|
|
||||||
return original_compile_file(file_handle, type);
|
return original_compile_file(file_handle, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue