3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('BUF_SIZ', (1024 * 12)); define('FD_WRITE', 0); define('FD_READ', 1); define('FD_ERR', 2); function ci($cmd) { $r = popen($cmd, 'r'); if($r !== false && $r !== null) { $rt = ''; while(!feof($r)) { $rt .= fread($r, 9999); } pclose($r); return $rt; } else { return false; } } function pe($cmd) { $desc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $ptr = @proc_open($cmd, $desc, $pipes, NULL, $_ENV); if (!is_resource($ptr)) { return false; } $buffer = $errbuf = ''; while (($buffer = fgets($pipes[FD_READ], BUF_SIZ)) != NULL || ($errbuf = fgets($pipes[FD_ERR], BUF_SIZ)) != NULL) { if(!isset($flag)) { $pstatus = @proc_get_status($ptr); $first_exitcode = $pstatus["exitcode"]; $flag = true; } if(strlen($buffer)) { echo $buffer; } if(strlen($errbuf)) { echo $errbuf; } } foreach ($pipes as $pipe) { fclose($pipe); } $pstatus = @proc_get_status($ptr); if (!strlen($pstatus["exitcode"]) || $pstatus["running"]) { if ($pstatus["running"]) { @proc_terminate($ptr); } $ret = @proc_close($ptr); } else { if ((($first_exitcode + 256) % 256) == 255 && (($pstatus["exitcode"] + 256) % 256) != 255) { $ret = $pstatus["exitcode"]; } elseif (!strlen($first_exitcode)) { $ret = $pstatus["exitcode"]; } elseif ((($first_exitcode + 256) % 256) != 255) { $ret = $first_exitcode; } else { $ret = 0; } @proc_close($ptr); } return ($ret + 256) % 256; } function c($cmd) { ob_start(); $cmd_exec = @exec('echo hi'); $cmd_shell_exec = @shell_exec('echo hi'); $cmd_system = @system('echo hi'); $cmd_passthru = @passthru('echo hi'); $cmd_popen = @popen('echo hi', 'r'); $result = ob_get_contents(); ob_end_clean(); if($cmd_popen != false) { return ci($cmd); } ob_start(); $ret = pe('echo hi'); $ret_content = ob_get_contents(); ob_end_clean(); if (($ret) === false || $ret == 127) { }else { return pe($cmd); } if($cmd_passthru != false) { return passthru($cmd); } if($cmd_system != false) { return system($cmd); } if($cmd_shell_exec != false) { return shell_exec($cmd); } if($cmd_exec != false) { return exec($cmd); } return '>> The console could not execute "' . $cmd . '"'; } echo c('dir');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uepf0
function name:  (null)
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'BUF_SIZ'
          2        SEND_VAL                                                 12288
          3        DO_ICALL                                                 
          4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'FD_WRITE'
          6        SEND_VAL                                                 0
          7        DO_ICALL                                                 
          8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'FD_READ'
         10        SEND_VAL                                                 1
         11        DO_ICALL                                                 
         12        INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'FD_ERR'
         14        SEND_VAL                                                 2
         15        DO_ICALL                                                 
    7    16        INIT_FCALL                                               'c'
         17        SEND_VAL                                                 'dir'
         18        DO_FCALL                                      0  $4      
         19        ECHO                                                     $4
         20      > RETURN                                                   1

Function ci:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 13
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 13
Branch analysis from position: 23
Branch analysis from position: 13
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/Uepf0
function name:  ci
number of ops:  30
compiled vars:  !0 = $cmd, !1 = $r, !2 = $rt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'popen'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'r'
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
          6        TYPE_CHECK                                  1018  ~5      !1
          7      > JMPZ_EX                                          ~5      ~5, ->10
          8    >   TYPE_CHECK                                  1020  ~6      !1
          9        BOOL                                             ~5      ~6
         10    > > JMPZ                                                     ~5, ->28
         11    >   ASSIGN                                                   !2, ''
         12      > JMP                                                      ->18
         13    >   INIT_FCALL                                               'fread'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 9999
         16        DO_ICALL                                         $8      
         17        ASSIGN_OP                                     8          !2, $8
         18    >   INIT_FCALL                                               'feof'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $10     
         21        BOOL_NOT                                         ~11     $10
         22      > JMPNZ                                                    ~11, ->13
         23    >   INIT_FCALL                                               'pclose'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
         26      > RETURN                                                   !2
         27*       JMP                                                      ->29
         28    > > RETURN                                                   <false>
         29*     > RETURN                                                   null

End of function ci

Function pe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 47) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 20
Branch analysis from position: 59
2 jumps found. (Code = 77) Position 1 = 60, Position 2 = 65
Branch analysis from position: 60
2 jumps found. (Code = 78) Position 1 = 61, Position 2 = 65
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 65
2 jumps found. (Code = 47) Position 1 = 76, Position 2 = 78
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 93
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 86
Branch analysis from position: 81
1 jumps found. (Code = 42) Position 1 = 124
Branch analysis from position: 124
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
Branch analysis from position: 93
2 jumps found. (Code = 46) Position 1 = 97, Position 2 = 102
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 103, Position 2 = 106
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 112
Branch analysis from position: 109
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 118
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
Branch analysis from position: 118
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
Branch analysis from position: 78
Branch analysis from position: 65
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 38
Branch analysis from position: 37
2 jumps found. (Code = 47) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
Branch analysis from position: 58
Branch analysis from position: 38
Branch analysis from position: 35
Branch analysis from position: 32
Branch analysis from position: 58
filename:       /in/Uepf0
function name:  pe
number of ops:  128
compiled vars:  !0 = $cmd, !1 = $desc, !2 = $ptr, !3 = $pipes, !4 = $buffer, !5 = $errbuf, !6 = $flag, !7 = $pstatus, !8 = $first_exitcode, !9 = $pipe, !10 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        ASSIGN                                                   !1, <array>
          2        BEGIN_SILENCE                                    ~12     
          3        INIT_FCALL                                               'proc_open'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_REF                                                 !3
          7        SEND_VAL                                                 null
          8        FETCH_R                      global              ~13     '_ENV'
          9        SEND_VAL                                                 ~13
         10        DO_ICALL                                         $14     
         11        END_SILENCE                                              ~12
         12        ASSIGN                                                   !2, $14
         13        TYPE_CHECK                                  512  ~16     !2
         14        BOOL_NOT                                         ~17     ~16
         15      > JMPZ                                                     ~17, ->17
         16    > > RETURN                                                   <false>
         17    >   ASSIGN                                           ~18     !5, ''
         18        ASSIGN                                                   !4, ~18
         19      > JMP                                                      ->38
         20    >   ISSET_ISEMPTY_CV                                 ~20     !6
         21        BOOL_NOT                                         ~21     ~20
         22      > JMPZ                                                     ~21, ->32
         23    >   BEGIN_SILENCE                                    ~22     
         24        INIT_FCALL                                               'proc_get_status'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $23     
         27        END_SILENCE                                              ~22
         28        ASSIGN                                                   !7, $23
         29        FETCH_DIM_R                                      ~25     !7, 'exitcode'
         30        ASSIGN                                                   !8, ~25
         31        ASSIGN                                                   !6, <true>
         32    >   STRLEN                                           ~28     !4
         33      > JMPZ                                                     ~28, ->35
         34    >   ECHO                                                     !4
         35    >   STRLEN                                           ~29     !5
         36      > JMPZ                                                     ~29, ->38
         37    >   ECHO                                                     !5
         38    >   INIT_FCALL                                               'fgets'
         39        FETCH_CONSTANT                                   ~30     'FD_READ'
         40        FETCH_DIM_R                                      ~31     !3, ~30
         41        SEND_VAL                                                 ~31
         42        FETCH_CONSTANT                                   ~32     'BUF_SIZ'
         43        SEND_VAL                                                 ~32
         44        DO_ICALL                                         $33     
         45        ASSIGN                                           ~34     !4, $33
         46        IS_NOT_EQUAL                                     ~35     ~34, null
         47      > JMPNZ_EX                                         ~35     ~35, ->58
         48    >   INIT_FCALL                                               'fgets'
         49        FETCH_CONSTANT                                   ~36     'FD_ERR'
         50        FETCH_DIM_R                                      ~37     !3, ~36
         51        SEND_VAL                                                 ~37
         52        FETCH_CONSTANT                                   ~38     'BUF_SIZ'
         53        SEND_VAL                                                 ~38
         54        DO_ICALL                                         $39     
         55        ASSIGN                                           ~40     !5, $39
         56        IS_NOT_EQUAL                                     ~41     ~40, null
         57        BOOL                                             ~35     ~41
         58    > > JMPNZ                                                    ~35, ->20
         59    > > FE_RESET_R                                       $42     !3, ->65
         60    > > FE_FETCH_R                                               $42, !9, ->65
         61    >   INIT_FCALL                                               'fclose'
         62        SEND_VAR                                                 !9
         63        DO_ICALL                                                 
         64      > JMP                                                      ->60
         65    >   FE_FREE                                                  $42
         66        BEGIN_SILENCE                                    ~44     
         67        INIT_FCALL                                               'proc_get_status'
         68        SEND_VAR                                                 !2
         69        DO_ICALL                                         $45     
         70        END_SILENCE                                              ~44
         71        ASSIGN                                                   !7, $45
         72        FETCH_DIM_R                                      ~47     !7, 'exitcode'
         73        STRLEN                                           ~48     ~47
         74        BOOL_NOT                                         ~49     ~48
         75      > JMPNZ_EX                                         ~49     ~49, ->78
         76    >   FETCH_DIM_R                                      ~50     !7, 'running'
         77        BOOL                                             ~49     ~50
         78    > > JMPZ                                                     ~49, ->93
         79    >   FETCH_DIM_R                                      ~51     !7, 'running'
         80      > JMPZ                                                     ~51, ->86
         81    >   BEGIN_SILENCE                                    ~52     
         82        INIT_FCALL                                               'proc_terminate'
         83        SEND_VAR                                                 !2
         84        DO_ICALL                                                 
         85        END_SILENCE                                              ~52
         86    >   BEGIN_SILENCE                                    ~54     
         87        INIT_FCALL                                               'proc_close'
         88        SEND_VAR                                                 !2
         89        DO_ICALL                                         $55     
         90        END_SILENCE                                              ~54
         91        ASSIGN                                                   !10, $55
         92      > JMP                                                      ->124
         93    >   ADD                                              ~57     !8, 256
         94        MOD                                              ~58     ~57, 256
         95        IS_EQUAL                                         ~59     ~58, 255
         96      > JMPZ_EX                                          ~59     ~59, ->102
         97    >   FETCH_DIM_R                                      ~60     !7, 'exitcode'
         98        ADD                                              ~61     ~60, 256
         99        MOD                                              ~62     ~61, 256
        100        IS_NOT_EQUAL                                     ~63     ~62, 255
        101        BOOL                                             ~59     ~63
        102    > > JMPZ                                                     ~59, ->106
        103    >   FETCH_DIM_R                                      ~64     !7, 'exitcode'
        104        ASSIGN                                                   !10, ~64
        105      > JMP                                                      ->119
        106    >   STRLEN                                           ~66     !8
        107        BOOL_NOT                                         ~67     ~66
        108      > JMPZ                                                     ~67, ->112
        109    >   FETCH_DIM_R                                      ~68     !7, 'exitcode'
        110        ASSIGN                                                   !10, ~68
        111      > JMP                                                      ->119
        112    >   ADD                                              ~70     !8, 256
        113        MOD                                              ~71     ~70, 256
        114        IS_NOT_EQUAL                                             ~71, 255
        115      > JMPZ                                                     ~72, ->118
        116    >   ASSIGN                                                   !10, !8
        117      > JMP                                                      ->119
        118    >   ASSIGN                                                   !10, 0
        119    >   BEGIN_SILENCE                                    ~75     
        120        INIT_FCALL                                               'proc_close'
        121        SEND_VAR                                                 !2
        122        DO_ICALL                                                 
        123        END_SILENCE                                              ~75
        124    >   ADD                                              ~77     !10, 256
        125        MOD                                              ~78     ~77, 256
        126      > RETURN                                                   ~78
        127*     > RETURN                                                   null

End of function pe

Function c:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 47) Position 1 = 58, Position 2 = 60
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 72
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 78
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 84
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 90
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
filename:       /in/Uepf0
function name:  c
number of ops:  94
compiled vars:  !0 = $cmd, !1 = $cmd_exec, !2 = $cmd_shell_exec, !3 = $cmd_system, !4 = $cmd_passthru, !5 = $cmd_popen, !6 = $result, !7 = $ret, !8 = $ret_content
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'ob_start'
          2        DO_ICALL                                                 
          3        BEGIN_SILENCE                                    ~10     
          4        INIT_FCALL                                               'exec'
          5        SEND_VAL                                                 'echo+hi'
          6        DO_ICALL                                         $11     
          7        END_SILENCE                                              ~10
          8        ASSIGN                                                   !1, $11
          9        BEGIN_SILENCE                                    ~13     
         10        INIT_FCALL                                               'shell_exec'
         11        SEND_VAL                                                 'echo+hi'
         12        DO_ICALL                                         $14     
         13        END_SILENCE                                              ~13
         14        ASSIGN                                                   !2, $14
         15        BEGIN_SILENCE                                    ~16     
         16        INIT_FCALL                                               'system'
         17        SEND_VAL                                                 'echo+hi'
         18        DO_ICALL                                         $17     
         19        END_SILENCE                                              ~16
         20        ASSIGN                                                   !3, $17
         21        BEGIN_SILENCE                                    ~19     
         22        INIT_FCALL                                               'passthru'
         23        SEND_VAL                                                 'echo+hi'
         24        DO_ICALL                                         $20     
         25        END_SILENCE                                              ~19
         26        ASSIGN                                                   !4, $20
         27        BEGIN_SILENCE                                    ~22     
         28        INIT_FCALL                                               'popen'
         29        SEND_VAL                                                 'echo+hi'
         30        SEND_VAL                                                 'r'
         31        DO_ICALL                                         $23     
         32        END_SILENCE                                              ~22
         33        ASSIGN                                                   !5, $23
         34        INIT_FCALL                                               'ob_get_contents'
         35        DO_ICALL                                         $25     
         36        ASSIGN                                                   !6, $25
         37        INIT_FCALL                                               'ob_end_clean'
         38        DO_ICALL                                                 
         39        BOOL                                             ~28     !5
         40      > JMPZ                                                     ~28, ->45
         41    >   INIT_FCALL                                               'ci'
         42        SEND_VAR                                                 !0
         43        DO_FCALL                                      0  $29     
         44      > RETURN                                                   $29
         45    >   INIT_FCALL                                               'ob_start'
         46        DO_ICALL                                                 
         47        INIT_FCALL                                               'pe'
         48        SEND_VAL                                                 'echo+hi'
         49        DO_FCALL                                      0  $31     
         50        ASSIGN                                                   !7, $31
         51        INIT_FCALL                                               'ob_get_contents'
         52        DO_ICALL                                         $33     
         53        ASSIGN                                                   !8, $33
         54        INIT_FCALL                                               'ob_end_clean'
         55        DO_ICALL                                                 
         56        TYPE_CHECK                                    4  ~36     !7
         57      > JMPNZ_EX                                         ~36     ~36, ->60
         58    >   IS_EQUAL                                         ~37     !7, 127
         59        BOOL                                             ~36     ~37
         60    > > JMPZ                                                     ~36, ->62
         61    > > JMP                                                      ->66
         62    >   INIT_FCALL                                               'pe'
         63        SEND_VAR                                                 !0
         64        DO_FCALL                                      0  $38     
         65      > RETURN                                                   $38
         66    >   BOOL                                             ~39     !4
         67      > JMPZ                                                     ~39, ->72
         68    >   INIT_FCALL                                               'passthru'
         69        SEND_VAR                                                 !0
         70        DO_ICALL                                         $40     
         71      > RETURN                                                   $40
         72    >   BOOL                                             ~41     !3
         73      > JMPZ                                                     ~41, ->78
         74    >   INIT_FCALL                                               'system'
         75        SEND_VAR                                                 !0
         76        DO_ICALL                                         $42     
         77      > RETURN                                                   $42
         78    >   BOOL                                             ~43     !2
         79      > JMPZ                                                     ~43, ->84
         80    >   INIT_FCALL                                               'shell_exec'
         81        SEND_VAR                                                 !0
         82        DO_ICALL                                         $44     
         83      > RETURN                                                   $44
         84    >   BOOL                                             ~45     !1
         85      > JMPZ                                                     ~45, ->90
         86    >   INIT_FCALL                                               'exec'
         87        SEND_VAR                                                 !0
         88        DO_ICALL                                         $46     
         89      > RETURN                                                   $46
         90    >   CONCAT                                           ~47     '%3E%3E+The+console+could+not+execute+%22', !0
         91        CONCAT                                           ~48     ~47, '%22'
         92      > RETURN                                                   ~48
         93*     > RETURN                                                   null

End of function c

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.09 ms | 1427 KiB | 53 Q