1

我们做了一个 Zend 扩展,我们想写 zval 的 echo 应该写出的地址,但是我们不知道如何接收它们,因为我们注意到 echo "test" 之间存在差异;和 $a = "测试"; 回声$a;

.... Some stuff that overrides the echo opcode ....

FILE *tmpfile;
int echo_handler(ZEND_OPCODE_HANDLER_ARGS)
{
    zend_op *opline = execute_data->opline;
    tmpfile = fopen("/tmp/echo.test","a+");
    fprintf(tmpfile,"Echo was called\n");
    fclose(tmpfile);

    return ZEND_USER_OPCODE_DISPATCH;
}

无论它是否是变量,我们如何获得参数?

4

1 回答 1

0

The handler for echo is

static int ZEND_FASTCALL  ZEND_ECHO_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
    zend_op *opline = EX(opline);

    zval z_copy;
    zval *z = &opline->op1.u.constant;

    if (IS_CONST != IS_CONST &&
        Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get_method != NULL &&
        zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
        zend_print_variable(&z_copy);
        zval_dtor(&z_copy);
    } else {
        zend_print_variable(z);
    }

    ZEND_VM_NEXT_OPCODE();
}

from Zend/zend_vm_execute.h, and as you can see all it basically does is to call zend_print_variable().

Hook that function and you should be on the right track.

Bonus: it works for print statements too.

于 2011-10-04T16:38:47.763 回答