3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); $fh = fopen(__FILE__, 'r'); fseek($fh, __COMPILER_HALT_OFFSET__, SEEK_SET); $mh = new MimeHalt($fh); #var_dump($mh); eval('?>' . $mh->getFile('/test.php')); exit; class MimeHalt { public $config; protected $fh; protected $offset_diff = 0; protected $offset_after_main_header = 0; protected $offset_after_first_file_header = 0; protected $mime_boundary; public static $max_read_length = 1048577; public function __construct($fh) { $this->fh = $fh; $this->offset_diff = ftell($this->fh); $this->init(); } public function init() { $this->offset_after_first_file_header = 0; $this->resetOffset(); $first_line = stream_get_line($this->fh, MimeHalt::$max_read_length, "\n"); $matches = array(); if(!preg_match('/^content\-type: multipart\/related; boundary=(.+)(?:;\s+.+)?$/i', $first_line, $matches)) { throw new RuntimeException('Invalid or corrupt file'); } $this->mime_boundary = '--' . $matches[1]; $this->resetOffset(); $header = MimeHalt::readNextHeaderChunk($this->fh); fseek($this->fh, strlen($this->mime_boundary) + 1, SEEK_CUR); $this->offset_after_main_header = ftell($this->fh) - $this->offset_diff; $json_header = MimeHalt::readNextHeaderChunk($this->fh); $json_body = MimeHalt::readNextBodyChunk($this->fh, $this->mime_boundary); $this->config = json_decode($json_body, true); $this->offset_after_first_file_header = ftell($this->fh) - $this->offset_diff; $this->resetOffset(); if(!is_array($this->config['offset_map']) || !count($this->config['offset_map'])) $this->buildOffsetMap(); } public function resetOffset() { fseek($this->fh, $this->offset_diff + $this->offset_after_first_file_header, SEEK_SET); } public function buildOffsetMap() { fseek($this->fh, $this->offset_diff + $this->offset_after_main_header, SEEK_SET); $header_text = ''; while($header_text = MimeHalt::readNextHeaderChunk($this->fh)) { $headers = MimeHalt::processHeader($header_text); $this->config['offset_map'][$headers['Content-ID']] = ftell($this->fh); MimeHalt::readNextBodyChunk($this->fh, $this->mime_boundary); } } public function getFile($filename) { $content_id = $this->config['files'][$filename]; $offset = $this->config['offset_map'][$content_id]; fseek($this->fh, $offset, SEEK_SET); return MimeHalt::readNextBodyChunk($this->fh, $this->mime_boundary); } protected static function readNextHeaderChunk($fh) { $line = stream_get_line($fh, MimeHalt::$max_read_length, "\n\n"); if($line === false) return false; return $line . "\n"; } protected static function readNextBodyChunk($fh, $boundary) { $line = rtrim(stream_get_line($fh, MimeHalt::$max_read_length, "\n" . $boundary . "\n")); $end_of_body_string = "\n" . $boundary . "--"; $eobs_length = strlen($end_of_body_string); if(substr($line, $eobs_length * -1) == $end_of_body_string) $line = substr($line, 0, $eobs_length * -1); return $line; } protected static function processHeader($header_text) { $headers = array(); $matches = array(); $found = preg_match_all('/^(.+): ((.|\r\n\s)+)\r?\n/m', $header_text, $matches, PREG_SET_ORDER); if($found) { foreach($matches as $set) $headers[ $set[1] ] = $set[2]; } return $headers; } } __halt_compiler();Content-type: multipart/related; boundary=mimehalt_outer X-MimeHalt-Version: 1.0.0 --mimehalt_outer Content-Type: application/json Content-ID: 100000001 { "files": { "/mimehalt.json": "100000001", "/test.php": "100000002" }, "dirs": [ "/" ], "offset_map": null } --mimehalt_outer Content-Type: application/x-php Content-ID: 100000002 <?php echo "Hello, world!"; var_dump(debug_backtrace()); --mimehalt_outer--
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/cuNo4
function name:  (null)
number of ops:  24
compiled vars:  !0 = $fh, !1 = $mh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    5     3        INIT_FCALL                                               'fopen'
          4        SEND_VAL                                                 '%2Fin%2FcuNo4'
          5        SEND_VAL                                                 'r'
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !0, $3
    6     8        INIT_FCALL                                               'fseek'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 4030
         11        SEND_VAL                                                 0
         12        DO_ICALL                                                 
    8    13        NEW                                              $6      'MimeHalt'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !1, $6
   10    17        INIT_METHOD_CALL                                         !1, 'getFile'
         18        SEND_VAL_EX                                              '%2Ftest.php'
         19        DO_FCALL                                      0  $9      
         20        CONCAT                                           ~10     '%3F%3E', $9
         21        INCLUDE_OR_EVAL                                          ~10, EVAL
   11    22      > EXIT                                                     
  108    23*     > RETURN                                                   1

Class MimeHalt:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cuNo4
function name:  __construct
number of ops:  12
compiled vars:  !0 = $fh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        ASSIGN_OBJ                                               'fh'
          2        OP_DATA                                                  !0
   28     3        INIT_FCALL                                               'ftell'
          4        FETCH_OBJ_R                                      ~3      'fh'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN_OBJ                                               'offset_diff'
          8        OP_DATA                                                  $4
   29     9        INIT_METHOD_CALL                                         'init'
         10        DO_FCALL                                      0          
   30    11      > RETURN                                                   null

End of function __construct

Function init:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 89, Position 2 = 94
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 97
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
Branch analysis from position: 94
filename:       /in/cuNo4
function name:  init
number of ops:  98
compiled vars:  !0 = $first_line, !1 = $matches, !2 = $header, !3 = $json_header, !4 = $json_body
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN_OBJ                                               'offset_after_first_file_header'
          1        OP_DATA                                                  0
   34     2        INIT_METHOD_CALL                                         'resetOffset'
          3        DO_FCALL                                      0          
   36     4        INIT_FCALL                                               'stream_get_line'
          5        FETCH_OBJ_R                                      ~7      'fh'
          6        SEND_VAL                                                 ~7
          7        FETCH_STATIC_PROP_R          unknown             ~8      'max_read_length'
          8        SEND_VAL                                                 ~8
          9        SEND_VAL                                                 '%0A'
         10        DO_ICALL                                         $9      
         11        ASSIGN                                                   !0, $9
   37    12        ASSIGN                                                   !1, <array>
   38    13        INIT_FCALL                                               'preg_match'
         14        SEND_VAL                                                 '%2F%5Econtent%5C-type%3A+multipart%5C%2Frelated%3B+boundary%3D%28.%2B%29%28%3F%3A%3B%5Cs%2B.%2B%29%3F%24%2Fi'
         15        SEND_VAR                                                 !0
         16        SEND_REF                                                 !1
         17        DO_ICALL                                         $12     
         18        BOOL_NOT                                         ~13     $12
         19      > JMPZ                                                     ~13, ->24
   39    20    >   NEW                                              $14     'RuntimeException'
         21        SEND_VAL_EX                                              'Invalid+or+corrupt+file'
         22        DO_FCALL                                      0          
         23      > THROW                                         0          $14
   41    24    >   FETCH_DIM_R                                      ~17     !1, 1
         25        CONCAT                                           ~18     '--', ~17
         26        ASSIGN_OBJ                                               'mime_boundary'
         27        OP_DATA                                                  ~18
   42    28        INIT_METHOD_CALL                                         'resetOffset'
         29        DO_FCALL                                      0          
   43    30        INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextHeaderChunk'
         31        CHECK_FUNC_ARG                                           
         32        FETCH_OBJ_FUNC_ARG                               $20     'fh'
         33        SEND_FUNC_ARG                                            $20
         34        DO_FCALL                                      0  $21     
         35        ASSIGN                                                   !2, $21
   44    36        INIT_FCALL                                               'fseek'
         37        FETCH_OBJ_R                                      ~23     'fh'
         38        SEND_VAL                                                 ~23
         39        FETCH_OBJ_R                                      ~24     'mime_boundary'
         40        STRLEN                                           ~25     ~24
         41        ADD                                              ~26     ~25, 1
         42        SEND_VAL                                                 ~26
         43        SEND_VAL                                                 1
         44        DO_ICALL                                                 
   45    45        INIT_FCALL                                               'ftell'
         46        FETCH_OBJ_R                                      ~29     'fh'
         47        SEND_VAL                                                 ~29
         48        DO_ICALL                                         $30     
         49        FETCH_OBJ_R                                      ~31     'offset_diff'
         50        SUB                                              ~32     $30, ~31
         51        ASSIGN_OBJ                                               'offset_after_main_header'
         52        OP_DATA                                                  ~32
   47    53        INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextHeaderChunk'
         54        CHECK_FUNC_ARG                                           
         55        FETCH_OBJ_FUNC_ARG                               $33     'fh'
         56        SEND_FUNC_ARG                                            $33
         57        DO_FCALL                                      0  $34     
         58        ASSIGN                                                   !3, $34
   48    59        INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextBodyChunk'
         60        CHECK_FUNC_ARG                                           
         61        FETCH_OBJ_FUNC_ARG                               $36     'fh'
         62        SEND_FUNC_ARG                                            $36
         63        CHECK_FUNC_ARG                                           
         64        FETCH_OBJ_FUNC_ARG                               $37     'mime_boundary'
         65        SEND_FUNC_ARG                                            $37
         66        DO_FCALL                                      0  $38     
         67        ASSIGN                                                   !4, $38
   49    68        INIT_FCALL                                               'json_decode'
         69        SEND_VAR                                                 !4
         70        SEND_VAL                                                 <true>
         71        DO_ICALL                                         $41     
         72        ASSIGN_OBJ                                               'config'
         73        OP_DATA                                                  $41
   51    74        INIT_FCALL                                               'ftell'
         75        FETCH_OBJ_R                                      ~43     'fh'
         76        SEND_VAL                                                 ~43
         77        DO_ICALL                                         $44     
         78        FETCH_OBJ_R                                      ~45     'offset_diff'
         79        SUB                                              ~46     $44, ~45
         80        ASSIGN_OBJ                                               'offset_after_first_file_header'
         81        OP_DATA                                                  ~46
   52    82        INIT_METHOD_CALL                                         'resetOffset'
         83        DO_FCALL                                      0          
   54    84        FETCH_OBJ_R                                      ~48     'config'
         85        FETCH_DIM_R                                      ~49     ~48, 'offset_map'
         86        TYPE_CHECK                                  128  ~50     ~49
         87        BOOL_NOT                                         ~51     ~50
         88      > JMPNZ_EX                                         ~51     ~51, ->94
         89    >   FETCH_OBJ_R                                      ~52     'config'
         90        FETCH_DIM_R                                      ~53     ~52, 'offset_map'
         91        COUNT                                            ~54     ~53
         92        BOOL_NOT                                         ~55     ~54
         93        BOOL                                             ~51     ~55
         94    > > JMPZ                                                     ~51, ->97
   55    95    >   INIT_METHOD_CALL                                         'buildOffsetMap'
         96        DO_FCALL                                      0          
   56    97    > > RETURN                                                   null

End of function init

Function resetoffset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cuNo4
function name:  resetOffset
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   INIT_FCALL                                               'fseek'
          1        FETCH_OBJ_R                                      ~0      'fh'
          2        SEND_VAL                                                 ~0
          3        FETCH_OBJ_R                                      ~1      'offset_diff'
          4        FETCH_OBJ_R                                      ~2      'offset_after_first_file_header'
          5        ADD                                              ~3      ~1, ~2
          6        SEND_VAL                                                 ~3
          7        SEND_VAL                                                 0
          8        DO_ICALL                                                 
   60     9      > RETURN                                                   null

End of function resetoffset

Function buildoffsetmap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 11
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 11
Branch analysis from position: 39
Branch analysis from position: 11
filename:       /in/cuNo4
function name:  buildOffsetMap
number of ops:  40
compiled vars:  !0 = $header_text, !1 = $headers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_FCALL                                               'fseek'
          1        FETCH_OBJ_R                                      ~2      'fh'
          2        SEND_VAL                                                 ~2
          3        FETCH_OBJ_R                                      ~3      'offset_diff'
          4        FETCH_OBJ_R                                      ~4      'offset_after_main_header'
          5        ADD                                              ~5      ~3, ~4
          6        SEND_VAL                                                 ~5
          7        SEND_VAL                                                 0
          8        DO_ICALL                                                 
   64     9        ASSIGN                                                   !0, ''
   65    10      > JMP                                                      ->32
   66    11    >   INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'processHeader'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !1, $8
   67    15        FETCH_DIM_R                                      ~12     !1, 'Content-ID'
         16        INIT_FCALL                                               'ftell'
         17        FETCH_OBJ_R                                      ~14     'fh'
         18        SEND_VAL                                                 ~14
         19        DO_ICALL                                         $15     
         20        FETCH_OBJ_W                                      $10     'config'
         21        FETCH_DIM_W                                      $11     $10, 'offset_map'
         22        ASSIGN_DIM                                               $11, ~12
         23        OP_DATA                                                  $15
   68    24        INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextBodyChunk'
         25        CHECK_FUNC_ARG                                           
         26        FETCH_OBJ_FUNC_ARG                               $16     'fh'
         27        SEND_FUNC_ARG                                            $16
         28        CHECK_FUNC_ARG                                           
         29        FETCH_OBJ_FUNC_ARG                               $17     'mime_boundary'
         30        SEND_FUNC_ARG                                            $17
         31        DO_FCALL                                      0          
   65    32    >   INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextHeaderChunk'
         33        CHECK_FUNC_ARG                                           
         34        FETCH_OBJ_FUNC_ARG                               $19     'fh'
         35        SEND_FUNC_ARG                                            $19
         36        DO_FCALL                                      0  $20     
         37        ASSIGN                                           ~21     !0, $20
         38      > JMPNZ                                                    ~21, ->11
   70    39    > > RETURN                                                   null

End of function buildoffsetmap

Function getfile:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cuNo4
function name:  getFile
number of ops:  25
compiled vars:  !0 = $filename, !1 = $content_id, !2 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
   73     1        FETCH_OBJ_R                                      ~3      'config'
          2        FETCH_DIM_R                                      ~4      ~3, 'files'
          3        FETCH_DIM_R                                      ~5      ~4, !0
          4        ASSIGN                                                   !1, ~5
   74     5        FETCH_OBJ_R                                      ~7      'config'
          6        FETCH_DIM_R                                      ~8      ~7, 'offset_map'
          7        FETCH_DIM_R                                      ~9      ~8, !1
          8        ASSIGN                                                   !2, ~9
   75     9        INIT_FCALL                                               'fseek'
         10        FETCH_OBJ_R                                      ~11     'fh'
         11        SEND_VAL                                                 ~11
         12        SEND_VAR                                                 !2
         13        SEND_VAL                                                 0
         14        DO_ICALL                                                 
   76    15        INIT_STATIC_METHOD_CALL                                  'MimeHalt', 'readNextBodyChunk'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $13     'fh'
         18        SEND_FUNC_ARG                                            $13
         19        CHECK_FUNC_ARG                                           
         20        FETCH_OBJ_FUNC_ARG                               $14     'mime_boundary'
         21        SEND_FUNC_ARG                                            $14
         22        DO_FCALL                                      0  $15     
         23      > RETURN                                                   $15
   77    24*     > RETURN                                                   null

End of function getfile

Function readnextheaderchunk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cuNo4
function name:  readNextHeaderChunk
number of ops:  14
compiled vars:  !0 = $fh, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1        INIT_FCALL                                               'stream_get_line'
          2        SEND_VAR                                                 !0
          3        FETCH_STATIC_PROP_R          global lock         ~2      'max_read_length'
          4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 '%0A%0A'
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   81     8        TYPE_CHECK                                    4          !1
          9      > JMPZ                                                     ~5, ->11
   82    10    > > RETURN                                                   <false>
   83    11    >   CONCAT                                           ~6      !1, '%0A'
         12      > RETURN                                                   ~6
   84    13*     > RETURN                                                   null

End of function readnextheaderchunk

Function readnextbodychunk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/cuNo4
function name:  readNextBodyChunk
number of ops:  35
compiled vars:  !0 = $fh, !1 = $boundary, !2 = $line, !3 = $end_of_body_string, !4 = $eobs_length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   87     2        INIT_FCALL                                               'rtrim'
          3        INIT_FCALL                                               'stream_get_line'
          4        SEND_VAR                                                 !0
          5        FETCH_STATIC_PROP_R          unknown             ~5      'max_read_length'
          6        SEND_VAL                                                 ~5
          7        CONCAT                                           ~6      '%0A', !1
          8        CONCAT                                           ~7      ~6, '%0A'
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !2, $9
   88    14        CONCAT                                           ~11     '%0A', !1
         15        CONCAT                                           ~12     ~11, '--'
         16        ASSIGN                                                   !3, ~12
   89    17        STRLEN                                           ~14     !3
         18        ASSIGN                                                   !4, ~14
   90    19        INIT_FCALL                                               'substr'
         20        SEND_VAR                                                 !2
         21        MUL                                              ~16     !4, -1
         22        SEND_VAL                                                 ~16
         23        DO_ICALL                                         $17     
         24        IS_EQUAL                                                 !3, $17
         25      > JMPZ                                                     ~18, ->33
   91    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !2
         28        SEND_VAL                                                 0
         29        MUL                                              ~19     !4, -1
         30        SEND_VAL                                                 ~19
         31        DO_ICALL                                         $20     
         32        ASSIGN                                                   !2, $20
   92    33    > > RETURN                                                   !2
   93    34*     > RETURN                                                   null

End of function readnextbodychunk

Function processheader:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 19
filename:       /in/cuNo4
function name:  processHeader
number of ops:  21
compiled vars:  !0 = $header_text, !1 = $headers, !2 = $matches, !3 = $found, !4 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   RECV                                             !0      
   96     1        ASSIGN                                                   !1, <array>
   97     2        ASSIGN                                                   !2, <array>
   98     3        INIT_FCALL                                               'preg_match_all'
          4        SEND_VAL                                                 '%2F%5E%28.%2B%29%3A+%28%28.%7C%5Cr%5Cn%5Cs%29%2B%29%5Cr%3F%5Cn%2Fm'
          5        SEND_VAR                                                 !0
          6        SEND_REF                                                 !2
          7        SEND_VAL                                                 2
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
   99    10      > JMPZ                                                     !3, ->19
  100    11    > > FE_RESET_R                                       $9      !2, ->18
         12    > > FE_FETCH_R                                               $9, !4, ->18
  101    13    >   FETCH_DIM_R                                      ~10     !4, 1
         14        FETCH_DIM_R                                      ~12     !4, 2
         15        ASSIGN_DIM                                               !1, ~10
         16        OP_DATA                                                  ~12
  100    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $9
  103    19    > > RETURN                                                   !1
  104    20*     > RETURN                                                   null

End of function processheader

End of class MimeHalt.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
211.16 ms | 1424 KiB | 33 Q