我试着写一个php扩展来获取函数args。
<?php system('ls');?>
在这个例子中是&#39; ls&#39;。
我用zend_set_user_opcode_handler挂钩了这个函数,函数代码是。
PHP_MINIT_FUNCTION(hello)
{
zend_set_user_opcode_handler(ZEND_DO_ICALL, do_fcall_handle);
return SUCCESS;
}
static int do_fcall_handle(ZEND_OPCODE_HANDLER_ARGS){
return ZEND_USER_OPCODE_DISPATCH;
}
PHP版本是7.2.5。
答案 0 :(得分:2)
在php7中,使用EG(current_execute_data) - &gt;调用获取arg名称和值。
static int do_fcall_handle(ZEND_OPCODE_HANDLER_ARGS){
zend_string *funcName = EG(current_execute_data)->call->func->common.function_name;
php_printf("[!] Hooked `%s`, ",ZSTR_VAL(funcName));
int arg_count = EG(current_execute_data)->call->This.u2.num_args;
for(int i=0; i<arg_count; i++){
php_printf("arg%d is `%s`, ", i+1, ZSTR_VAL((EG(vm_stack_top)-(i+1))->value.str) );
}
php_printf("HOOK end;\n");
return ZEND_USER_OPCODE_DISPATCH;
}