How to get opcodes of PHP?

前端 未结 2 1138
执念已碎
执念已碎 2020-12-02 06:36
  

Its opcode is:

相关标签:
2条回答
  • 2020-12-02 06:49

    Parsekit has parsekit_compile_string().

    sudo pecl install parsekit
    
    var_dump(parsekit_compile_string(<<<PHP
     \$show_value   = 123;
     echo 'sing_quote'.\$show_value;
     echo "double_quote{\$show_value}";
    PHP
    ));
    

    The output is quite verbose, so you'd need to process it to get assembler-like format.

      ["opcodes"]=>
      array(10) {
        [0]=>
        array(9) {
          ["address"]=>
          int(44682716)
          ["opcode"]=>
          int(101)
          ["opcode_name"]=>
          string(13) "ZEND_EXT_STMT"
          ["flags"]=>
          int(4294967295)
          ["result"]=>
          array(8) {
            ["type"]=>
            int(8)
            ["type_name"]=>
            string(9) "IS_UNUSED"
            ["var"]=>
            int(0)
            ["opline_num"]=>
            string(1) "0"
            ["op_array"]=>
            string(1) "0"
            ["jmp_addr"]=>
            string(1) "0"
            ["jmp_offset"]=>
            string(8) "35419039"
            ["EA.type"]=>
            int(0)
          }
          ["op1"]=>
          array(8) {
            ["type"]=>
            int(8)
            ["type_name"]=>
            string(9) "IS_UNUSED"
            ["var"]=>
            int(0)
            ["opline_num"]=>
            string(1) "0"
            ["op_array"]=>
            string(1) "0"
            ["jmp_addr"]=>
            string(1) "0"
            ["jmp_offset"]=>
            string(8) "35419039"
            ["EA.type"]=>
            int(0)
          }
    
    0 讨论(0)
  • Check out the Vulcan Logic Disassembler PECL extension - see author's home page for more info.

    The Vulcan Logic Disassembler hooks into the Zend Engine and dumps all the opcodes (execution units) of a script. It was written as as a beginning of an encoder, but I never got the time for that. It can be used to see what is going on in the Zend Engine.

    Once installed, you can use it like this:

    php -d vld.active=1 -d vld.execute=0 -f yourscript.php
    

    See also this interesting blog post on opcode extraction, and the PHP manual page listing the available opcodes.

    0 讨论(0)
提交回复
热议问题