This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobserver.c
More file actions
86 lines (72 loc) · 2.24 KB
/
Copy pathobserver.c
File metadata and controls
86 lines (72 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "Zend/zend_observer.h"
#include "php_observer.h"
ZEND_DECLARE_MODULE_GLOBALS(observer)
static void observer_begin(zend_execute_data *execute_data) {
php_printf("[BEGIN %s()]\n", ZSTR_VAL(execute_data->func->common.function_name));
}
static void observer_end(zend_execute_data *execute_data, zval *return_value) {
php_printf("[END %s(): %s]\n", ZSTR_VAL(execute_data->func->common.function_name), return_value ? zend_zval_type_name(return_value) : "null");
}
// Runs once per zend_function on its first call
static zend_observer_fcall_handlers observer_instrument(zend_execute_data *execute_data) {
zend_observer_fcall_handlers handlers = {NULL, NULL};
if (OBSERVER_G(instrument) == 0 ||
!execute_data->func ||
!execute_data->func->common.function_name) {
return handlers; // I have no handlers for this function
}
handlers.begin = observer_begin;
handlers.end = observer_end;
return handlers; // I have handlers for this function
}
static void php_observer_init_globals(zend_observer_globals *observer_globals)
{
observer_globals->instrument = 0;
}
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("observer.instrument", "0", PHP_INI_SYSTEM, OnUpdateBool, instrument, zend_observer_globals, observer_globals)
PHP_INI_END()
static PHP_MINIT_FUNCTION(observer)
{
ZEND_INIT_MODULE_GLOBALS(observer, php_observer_init_globals, NULL);
REGISTER_INI_ENTRIES();
zend_observer_fcall_register(observer_instrument);
return SUCCESS;
}
static PHP_RINIT_FUNCTION(observer)
{
#if defined(ZTS) && defined(COMPILE_DL_OBSERVER)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
static PHP_MINFO_FUNCTION(observer)
{
php_info_print_table_start();
php_info_print_table_header(2, "Observer PoC extension", "enabled");
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
zend_module_entry observer_module_entry = {
STANDARD_MODULE_HEADER,
"observer",
NULL, /* zend_function_entry */
PHP_MINIT(observer),
NULL, /* PHP_MSHUTDOWN */
PHP_RINIT(observer),
NULL, /* PHP_RSHUTDOWN */
PHP_MINFO(observer),
PHP_OBSERVER_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_OBSERVER
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(observer)
#endif