summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sp_execute.c39
-rw-r--r--src/sp_sloppy.c41
-rw-r--r--src/sp_sloppy.h1
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) {
286 286
287#endif 287#endif
288 288
289ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle,
290 int type) = NULL;
291#if PHP_VERSION_ID >= 80000
292ZEND_API zend_op_array* (*orig_zend_compile_string)(
293 zend_string* source_string, const char* filename) = NULL;
294#else
295ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string,
296 char* filename) = NULL;
297#endif
298
299#if PHP_VERSION_ID >= 80000
300ZEND_API zend_op_array* sp_compile_string(zend_string* source_string,
301 const char* filename) {
302#else
303ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) {
304#endif
305 zend_op_array* opline = orig_zend_compile_string(source_string, filename);
306 sp_sloppy_modify_opcode(opline);
307 return opline;
308}
309
310ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle,
311 int type) {
312 zend_op_array* opline = orig_zend_compile_file(file_handle, type);
313 sp_sloppy_modify_opcode(opline);
314 return opline;
315}
316
289int hook_execute(void) { 317int hook_execute(void) {
290 TSRMLS_FETCH(); 318 TSRMLS_FETCH();
291 319
@@ -309,5 +337,16 @@ int hook_execute(void) {
309 } 337 }
310 } 338 }
311 339
340 if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) {
341 orig_zend_compile_file = zend_compile_file;
342 zend_compile_file = sp_compile_file;
343 }
344
345 if (NULL == orig_zend_compile_string &&
346 zend_compile_string != sp_compile_string) {
347 orig_zend_compile_string = zend_compile_string;
348 zend_compile_string = sp_compile_string;
349 }
350
312 return SUCCESS; 351 return SUCCESS;
313} 352}
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 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3ZEND_API zend_op_array* (*orig_zend_compile_file)(zend_file_handle* file_handle, 3void sp_sloppy_modify_opcode(zend_op_array* opline) {
4 int type) = NULL;
5#if PHP_VERSION_ID >= 80000
6ZEND_API zend_op_array* (*orig_zend_compile_string)(
7 zend_string* source_string, const char* filename) = NULL;
8#else
9ZEND_API zend_op_array* (*orig_zend_compile_string)(zval* source_string,
10 char* filename) = NULL;
11#endif
12
13static void modify_opcode(zend_op_array* opline) {
14 if (NULL != opline) { 4 if (NULL != opline) {
15 for (size_t i = 0; i < opline->last; i++) { 5 for (size_t i = 0; i < opline->last; i++) {
16 zend_op* orig_opline = &(opline->opcodes[i]); 6 zend_op* orig_opline = &(opline->opcodes[i]);
@@ -25,24 +15,6 @@ static void modify_opcode(zend_op_array* opline) {
25 } 15 }
26} 16}
27 17
28#if PHP_VERSION_ID >= 80000
29ZEND_API zend_op_array* sp_compile_string(zend_string* source_string,
30 const char* filename) {
31#else
32ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) {
33#endif
34 zend_op_array* opline = orig_zend_compile_string(source_string, filename);
35 modify_opcode(opline);
36 return opline;
37}
38
39ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle,
40 int type) {
41 zend_op_array* opline = orig_zend_compile_file(file_handle, type);
42 modify_opcode(opline);
43 return opline;
44}
45
46static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, 18static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name,
47 size_t size, zif_handler orig_handler, 19 size_t size, zif_handler orig_handler,
48 const char* spec) { 20 const char* spec) {
@@ -99,17 +71,6 @@ PHP_FUNCTION(sp_array_keys) {
99void hook_sloppy() { 71void hook_sloppy() {
100 TSRMLS_FETCH(); 72 TSRMLS_FETCH();
101 73
102 if (NULL == orig_zend_compile_file && zend_compile_file != sp_compile_file) {
103 orig_zend_compile_file = zend_compile_file;
104 zend_compile_file = sp_compile_file;
105 }
106
107 if (NULL == orig_zend_compile_string &&
108 zend_compile_string != sp_compile_string) {
109 orig_zend_compile_string = zend_compile_string;
110 zend_compile_string = sp_compile_string;
111 }
112
113 HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array)); 74 HOOK_FUNCTION("in_array", sp_internal_functions_hook, PHP_FN(sp_in_array));
114 HOOK_FUNCTION("array_search", sp_internal_functions_hook, 75 HOOK_FUNCTION("array_search", sp_internal_functions_hook,
115 PHP_FN(sp_array_search)); 76 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 @@
4#include "zend_vm.h" 4#include "zend_vm.h"
5 5
6void hook_sloppy(void); 6void hook_sloppy(void);
7void sp_sloppy_modify_opcode(zend_op_array* opline);
7 8
8#endif 9#endif