From 5da3a92492bf169e62367d954cfa7432bee51fed Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 9 Jul 2018 07:37:58 +0000 Subject: Trying to fix sloppy comparison (#186) * Trying to fix sloppy comparison https://github.com/nbs-system/snuffleupagus/issues/10 by modifying php's opcode --- src/sp_sloppy.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/sp_sloppy.c (limited to 'src/sp_sloppy.c') diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c new file mode 100644 index 0000000..05d2505 --- /dev/null +++ b/src/sp_sloppy.c @@ -0,0 +1,39 @@ +#include "sp_sloppy.h" + +ZEND_API zend_op_array* (*zend_compile_file_default)(zend_file_handle* file_handle, int type) = NULL; +ZEND_API zend_op_array* (*zend_compile_string_default)(zval* source_string, char* filename) = NULL; + +static void modify_opcode(zend_op_array* opline) { + if (NULL != opline) { + zend_op* orig_opline = opline->opcodes; + for (; NULL != orig_opline->handler; orig_opline++) { + if (orig_opline->opcode == ZEND_IS_EQUAL) { + orig_opline->opcode = ZEND_IS_IDENTICAL; + zend_vm_set_opcode_handler(orig_opline); + } else if (orig_opline->opcode == ZEND_IS_NOT_EQUAL) { + orig_opline->opcode = ZEND_IS_NOT_IDENTICAL; + zend_vm_set_opcode_handler(orig_opline); + } + } + } +} + +ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { + zend_op_array* opline = zend_compile_string_default(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 = zend_compile_file_default(file_handle, type); + modify_opcode(opline); + return opline; +} + +void hook_sloppy() { + zend_compile_file_default = zend_compile_file; + zend_compile_file = sp_compile_file; + + zend_compile_string_default = zend_compile_string; + zend_compile_string = sp_compile_string; +} -- cgit v1.3