This commit is contained in:
hailin 2025-07-30 19:25:44 +08:00
parent fe288136f8
commit b884b966ca
1 changed files with 69 additions and 56 deletions

View File

@ -9,17 +9,23 @@ static zend_op_array* (*original_compile_file)(zend_file_handle *file_handle, in
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) {
fprintf(stderr, "[hook] zend_compile_file called\n"); fprintf(stderr, "[hook] zend_compile_file called\n");
if (file_handle && file_handle->filename) { if (file_handle) {
if (file_handle->filename) {
const char *source_path = file_handle->filename; const char *source_path = file_handle->filename;
fprintf(stderr, "[hook] filename = %s\n", source_path); fprintf(stderr, "[hook] filename = %s\n", source_path);
fprintf(stderr, "[hook] file_handle->type = %d\n", file_handle->type); fprintf(stderr, "[hook] file_handle->type = %d\n", file_handle->type);
// ✅ 只处理 install.php // ✅ 强化路径判断:只要末尾是 install.php 就处理
if (!strstr(source_path, "install.php")) { const char *p = strrchr(source_path, '/');
const char *basename = p ? (p + 1) : source_path;
if (strcmp(basename, "install.php") != 0) {
fprintf(stderr, "[skip] not install.php, skip dump: %s\n", source_path); fprintf(stderr, "[skip] not install.php, skip dump: %s\n", source_path);
return original_compile_file(file_handle, type); return original_compile_file(file_handle, type);
} }
fprintf(stderr, "[match] matched install.php, start dumping...\n");
char *buffer = NULL; char *buffer = NULL;
size_t size = 0; size_t size = 0;
@ -65,13 +71,16 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
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), "/tmp/dump_install_%ld.dec.php", time(NULL));
FILE *out = fopen(output_path, "wb"); FILE *out = fopen(output_path, "wb");
if (out) { if (out) {
fwrite(buffer, 1, size, out); fwrite(buffer, 1, size, out);
fclose(out); fclose(out);
fprintf(stderr, "[dump] saved to: %s (%zu bytes)\n", output_path, size); fprintf(stderr, "[dump] saved to: %s (%zu bytes)\n", output_path, size);
// ✅ 打印内容预览前200字节
fprintf(stderr, "[preview] %.200s\n", buffer);
} else { } else {
fprintf(stderr, "[error] failed to open output file: %s\n", output_path); fprintf(stderr, "[error] failed to open output file: %s\n", output_path);
} }
@ -81,12 +90,16 @@ static zend_op_array* custom_compile_file(zend_file_handle *file_handle, int typ
fprintf(stderr, "[skip] buffer is NULL or size = 0\n"); fprintf(stderr, "[skip] buffer is NULL or size = 0\n");
} }
} else { } else {
fprintf(stderr, "[warn] file_handle or filename is NULL\n"); fprintf(stderr, "[warn] file_handle->filename is NULL\n");
}
} else {
fprintf(stderr, "[warn] file_handle is NULL\n");
} }
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;