I am attempting to hook into the functions within the PDO class.
I declared the zend_execute_internal function and hooked it by setting the address of my custom function, but in the code of New Relic or Datadog, it seems they use zend_hash_str_find_ptr to perform the operation within the PHP_MINIT_FUNCTION.
However, I couldn’t figure out exactly how they are hooking the functions. I’ve spent a month searching through a vast amount of materials, but none of the explanations worked as described.
How can I make my function execute first and then execute the original function?
Or is there a way to use symbols like in C..?
tried many approaches, but the most promising code was the one below. However, the result of zend_hash_str_find_ptr always returned NULL no matter where it was executed.
I want to create a feature that collects transactions performed by the user through PDO and displays them as statistics, unlike a custom class.
zend_class_entry *ce = zend_hash_str_find_ptr(CG(class_table), "PDO", sizeof("PDO")-1);
if (ce != NULL) {
original = zend_hash_str_find_ptr(&ce->function_table, "exec", sizeof("exec")-1);
if (original != NULL) {
original_handler_pdo_exec = original->internal_function.handler;
original->internal_function.handler = my_overwrite_pdo_exec;
}
}