From 30f1270c26edb6ced469eb302de2fa27befbdbec Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 27 Jun 2022 20:12:47 +0200 Subject: Move compile_file and compile_string to sp_execute.c --- src/sp_execute.c | 39 +++++++++++++++++++++++++++++++++++++++ src/sp_sloppy.c | 41 +---------------------------------------- src/sp_sloppy.h | 1 + 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/sp_execute.c b/src/sp_execute.c index f1ed8d0..b81f408 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c @@ -286,6 +286,34 @@ static zend_result sp_stream_open(zend_file_handle *handle) { #endif +ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, + int type) = NULL; +#if PHP_VERSION_ID >= 80000 +ZEND_API zend_op_array* (*orig_zend_compile_string)( + zend_string* source_string, const char* filename) = NULL; +#else +ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string, + char* filename) = NULL; +#endif + +#if PHP_VERSION_ID >= 80000 +ZEND_API zend_op_array* sp_compile_string(zend_string* source_string, + const char* filename) { +#else +ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { +#endif + zend_op_array* opline = orig_zend_compile_string(source_string, filename); + sp_sloppy_modify_opcode(opline); + return opline; +} + +ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, + int type) { + zend_op_array* opline = orig_zend_compile_file(file_handle, type); + sp_sloppy_modify_opcode(opline); + return opline; +} + int hook_execute(void) { TSRMLS_FETCH(); @@ -309,5 +337,16 @@ int hook_execute(void) { } } + if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) { + orig_zend_compile_file = zend_compile_file; + zend_compile_file = sp_compile_file; + } + + if (NULL == orig_zend_compile_string && + zend_compile_string != sp_compile_string) { + orig_zend_compile_string = zend_compile_string; + zend_compile_string = sp_compile_string; + } + return SUCCESS; } diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c index fca4be5..2c6ef6a 100644 --- a/src/sp_sloppy.c +++ b/src/sp_sloppy.c @@ -1,16 +1,6 @@ #include "php_snuffleupagus.h" -ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, - int type) = NULL; -#if PHP_VERSION_ID >= 80000 -ZEND_API zend_op_array* (*orig_zend_compile_string)( - zend_string* source_string, const char* filename) = NULL; -#else -ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string, - char* filename) = NULL; -#endif - -static void modify_opcode(zend_op_array* opline) { +void sp_sloppy_modify_opcode(zend_op_array* opline) { if (NULL != opline) { for (size_t i = 0; i < opline->last; i++) { zend_op* orig_opline = &(opline->opcodes[i]); @@ -25,24 +15,6 @@ static void modify_opcode(zend_op_array* opline) { } } -#if PHP_VERSION_ID >= 80000 -ZEND_API zend_op_array* sp_compile_string(zend_string* source_string, - const char* filename) { -#else -ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { -#endif - zend_op_array* opline = orig_zend_compile_string(source_string, filename); - modify_opcode(opline); - return opline; -} - -ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, - int type) { - zend_op_array* opline = orig_zend_compile_file(file_handle, type); - modify_opcode(opline); - return opline; -} - static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, size_t size, zif_handler orig_handler, const char* spec) { @@ -99,17 +71,6 @@ PHP_FUNCTION(sp_array_keys) { void hook_sloppy() { TSRMLS_FETCH(); - if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) { - orig_zend_compile_file = zend_compile_file; - zend_compile_file = sp_compile_file; - } - - if (NULL == orig_zend_compile_string && - zend_compile_string != sp_compile_string) { - orig_zend_compile_string = zend_compile_string; - zend_compile_string = sp_compile_string; - } - HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array)); HOOK_FUNCTION("array_search", sp_internal_functions_hook, PHP_FN(sp_array_search)); diff --git a/src/sp_sloppy.h b/src/sp_sloppy.h index cd9f304..4c5d121 100644 --- a/src/sp_sloppy.h +++ b/src/sp_sloppy.h @@ -4,5 +4,6 @@ #include "zend_vm.h" void hook_sloppy(void); +void sp_sloppy_modify_opcode(zend_op_array* opline); #endif -- cgit v1.3