diff options
| author | jvoisin | 2018-07-09 07:37:58 +0000 |
|---|---|---|
| committer | xXx-caillou-xXx | 2018-07-09 09:37:58 +0200 |
| commit | 5da3a92492bf169e62367d954cfa7432bee51fed (patch) | |
| tree | 2e094ed1a5a8400269c48c520539b7dac28ced27 /src/sp_sloppy.c | |
| parent | ca3be84076521c4bb053511775c94c0b195aeac8 (diff) | |
Trying to fix sloppy comparison (#186)
* Trying to fix sloppy comparison https://github.com/nbs-system/snuffleupagus/issues/10 by
modifying php's opcode
Diffstat (limited to 'src/sp_sloppy.c')
| -rw-r--r-- | src/sp_sloppy.c | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ | |||
| 1 | #include "sp_sloppy.h" | ||
| 2 | |||
| 3 | ZEND_API zend_op_array* (*zend_compile_file_default)(zend_file_handle* file_handle, int type) = NULL; | ||
| 4 | ZEND_API zend_op_array* (*zend_compile_string_default)(zval* source_string, char* filename) = NULL; | ||
| 5 | |||
| 6 | static void modify_opcode(zend_op_array* opline) { | ||
| 7 | if (NULL != opline) { | ||
| 8 | zend_op* orig_opline = opline->opcodes; | ||
| 9 | for (; NULL != orig_opline->handler; orig_opline++) { | ||
| 10 | if (orig_opline->opcode == ZEND_IS_EQUAL) { | ||
| 11 | orig_opline->opcode = ZEND_IS_IDENTICAL; | ||
| 12 | zend_vm_set_opcode_handler(orig_opline); | ||
| 13 | } else if (orig_opline->opcode == ZEND_IS_NOT_EQUAL) { | ||
| 14 | orig_opline->opcode = ZEND_IS_NOT_IDENTICAL; | ||
| 15 | zend_vm_set_opcode_handler(orig_opline); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { | ||
| 22 | zend_op_array* opline = zend_compile_string_default(source_string, filename); | ||
| 23 | modify_opcode(opline); | ||
| 24 | return opline; | ||
| 25 | } | ||
| 26 | |||
| 27 | ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, int type) { | ||
| 28 | zend_op_array* opline = zend_compile_file_default(file_handle, type); | ||
| 29 | modify_opcode(opline); | ||
| 30 | return opline; | ||
| 31 | } | ||
| 32 | |||
| 33 | void hook_sloppy() { | ||
| 34 | zend_compile_file_default = zend_compile_file; | ||
| 35 | zend_compile_file = sp_compile_file; | ||
| 36 | |||
| 37 | zend_compile_string_default = zend_compile_string; | ||
| 38 | zend_compile_string = sp_compile_string; | ||
| 39 | } | ||
