| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | define('INDENT', "\t"); |
|---|
| 4 | ini_set('error_reporting', E_ALL); |
|---|
| 5 | |
|---|
| 6 | function color($str, $color = 33) |
|---|
| 7 | { |
|---|
| 8 | return "\x1B[{$color}m$str\x1B[0m"; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | function toCode($src, $indent = '') // {{{ |
|---|
| 12 | { |
|---|
| 13 | if (is_array($indent)) { |
|---|
| 14 | $indent = $indent['indent']; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | if (is_object($src)) { |
|---|
| 18 | if (!method_exists($src, 'toCode')) { |
|---|
| 19 | var_dump($src); |
|---|
| 20 | exit('no toCode'); |
|---|
| 21 | } |
|---|
| 22 | return $src->toCode($indent); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | return $src; |
|---|
| 26 | } |
|---|
| 27 | // }}} |
|---|
| 28 | function value($value) // {{{ |
|---|
| 29 | { |
|---|
| 30 | $spec = xcache_get_special_value($value); |
|---|
| 31 | if (isset($spec)) { |
|---|
| 32 | $value = $spec; |
|---|
| 33 | if (!is_array($value)) { |
|---|
| 34 | // constant |
|---|
| 35 | return $value; |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | if ($value instanceof Decompiler_Object) { |
|---|
| 40 | // use as is |
|---|
| 41 | } |
|---|
| 42 | else if (is_array($value)) { |
|---|
| 43 | $value = new Decompiler_Array($value); |
|---|
| 44 | } |
|---|
| 45 | else { |
|---|
| 46 | $value = new Decompiler_Value($value); |
|---|
| 47 | } |
|---|
| 48 | return $value; |
|---|
| 49 | } |
|---|
| 50 | // }}} |
|---|
| 51 | class Decompiler_Object // {{{ |
|---|
| 52 | { |
|---|
| 53 | } |
|---|
| 54 | // }}} |
|---|
| 55 | class Decompiler_Value extends Decompiler_Object // {{{ |
|---|
| 56 | { |
|---|
| 57 | var $value; |
|---|
| 58 | |
|---|
| 59 | function Decompiler_Value($value = null) |
|---|
| 60 | { |
|---|
| 61 | $this->value = $value; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function toCode($indent) |
|---|
| 65 | { |
|---|
| 66 | return var_export($this->value, true); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | // }}} |
|---|
| 70 | class Decompiler_Code extends Decompiler_Object // {{{ |
|---|
| 71 | { |
|---|
| 72 | var $src; |
|---|
| 73 | |
|---|
| 74 | function Decompiler_Code($src) |
|---|
| 75 | { |
|---|
| 76 | $this->src = $src; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | function toCode($indent) |
|---|
| 80 | { |
|---|
| 81 | return $this->src; |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | // }}} |
|---|
| 85 | class Decompiler_Binop extends Decompiler_Code // {{{ |
|---|
| 86 | { |
|---|
| 87 | var $opc; |
|---|
| 88 | var $op1; |
|---|
| 89 | var $op2; |
|---|
| 90 | var $parent; |
|---|
| 91 | var $indent; |
|---|
| 92 | |
|---|
| 93 | function Decompiler_Binop($parent, $op1, $opc, $op2) |
|---|
| 94 | { |
|---|
| 95 | $this->parent = &$parent; |
|---|
| 96 | $this->opc = $opc; |
|---|
| 97 | $this->op1 = $op1; |
|---|
| 98 | $this->op2 = $op2; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | function toCode($indent) |
|---|
| 102 | { |
|---|
| 103 | $op1 = toCode($this->op1, $indent); |
|---|
| 104 | if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) { |
|---|
| 105 | $op1 = "($op1)"; |
|---|
| 106 | } |
|---|
| 107 | $opstr = $this->parent->binops[$this->opc]; |
|---|
| 108 | if ($op1 == '0' && $this->opc == XC_SUB) { |
|---|
| 109 | return $opstr . toCode($this->op2, $indent); |
|---|
| 110 | } |
|---|
| 111 | return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent); |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | // }}} |
|---|
| 115 | class Decompiler_Fetch extends Decompiler_Code // {{{ |
|---|
| 116 | { |
|---|
| 117 | var $src; |
|---|
| 118 | var $fetchType; |
|---|
| 119 | |
|---|
| 120 | function Decompiler_Fetch($src, $type, $globalsrc) |
|---|
| 121 | { |
|---|
| 122 | $this->src = $src; |
|---|
| 123 | $this->fetchType = $type; |
|---|
| 124 | $this->globalsrc = $globalsrc; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | function toCode($indent) |
|---|
| 128 | { |
|---|
| 129 | switch ($this->fetchType) { |
|---|
| 130 | case ZEND_FETCH_LOCAL: |
|---|
| 131 | return '$' . substr($this->src, 1, -1); |
|---|
| 132 | case ZEND_FETCH_STATIC: |
|---|
| 133 | die('static fetch cant to string'); |
|---|
| 134 | case ZEND_FETCH_GLOBAL: |
|---|
| 135 | case ZEND_FETCH_GLOBAL_LOCK: |
|---|
| 136 | return $this->globalsrc; |
|---|
| 137 | default: |
|---|
| 138 | var_dump($this->fetchType); |
|---|
| 139 | assert(0); |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | // }}} |
|---|
| 144 | class Decompiler_Box // {{{ |
|---|
| 145 | { |
|---|
| 146 | var $obj; |
|---|
| 147 | |
|---|
| 148 | function Decompiler_Box(&$obj) |
|---|
| 149 | { |
|---|
| 150 | $this->obj = &$obj; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | function toCode($indent) |
|---|
| 154 | { |
|---|
| 155 | return $this->obj->toCode($indent); |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | // }}} |
|---|
| 159 | class Decompiler_Dim extends Decompiler_Value // {{{ |
|---|
| 160 | { |
|---|
| 161 | var $offsets = array(); |
|---|
| 162 | var $isLast = false; |
|---|
| 163 | var $assign = null; |
|---|
| 164 | |
|---|
| 165 | function toCode($indent) |
|---|
| 166 | { |
|---|
| 167 | if (is_a($this->value, 'Decompiler_ListBox')) { |
|---|
| 168 | $exp = toCode($this->value->obj->src, $indent); |
|---|
| 169 | } |
|---|
| 170 | else { |
|---|
| 171 | $exp = toCode($this->value, $indent); |
|---|
| 172 | } |
|---|
| 173 | foreach ($this->offsets as $dim) { |
|---|
| 174 | $exp .= '[' . toCode($dim, $indent) . ']'; |
|---|
| 175 | } |
|---|
| 176 | return $exp; |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | // }}} |
|---|
| 180 | class Decompiler_DimBox extends Decompiler_Box // {{{ |
|---|
| 181 | { |
|---|
| 182 | } |
|---|
| 183 | // }}} |
|---|
| 184 | class Decompiler_List extends Decompiler_Code // {{{ |
|---|
| 185 | { |
|---|
| 186 | var $src; |
|---|
| 187 | var $dims = array(); |
|---|
| 188 | var $everLocked = false; |
|---|
| 189 | |
|---|
| 190 | function toCode($indent) |
|---|
| 191 | { |
|---|
| 192 | if (count($this->dims) == 1 && !$this->everLocked) { |
|---|
| 193 | $dim = $this->dims[0]; |
|---|
| 194 | unset($dim->value); |
|---|
| 195 | $dim->value = $this->src; |
|---|
| 196 | if (!isset($dim->assign)) { |
|---|
| 197 | return toCode($dim, $indent); |
|---|
| 198 | } |
|---|
| 199 | return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent); |
|---|
| 200 | } |
|---|
| 201 | /* flatten dims */ |
|---|
| 202 | $assigns = array(); |
|---|
| 203 | foreach ($this->dims as $dim) { |
|---|
| 204 | $assign = &$assigns; |
|---|
| 205 | foreach ($dim->offsets as $offset) { |
|---|
| 206 | $assign = &$assign[$offset]; |
|---|
| 207 | } |
|---|
| 208 | $assign = toCode($dim->assign, $indent); |
|---|
| 209 | } |
|---|
| 210 | return $this->toList($assigns) . ' = ' . toCode($this->src, $indent); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | function toList($assigns) |
|---|
| 214 | { |
|---|
| 215 | $keys = array_keys($assigns); |
|---|
| 216 | if (count($keys) < 2) { |
|---|
| 217 | $keys[] = 0; |
|---|
| 218 | } |
|---|
| 219 | $max = call_user_func_array('max', $keys); |
|---|
| 220 | $list = 'list('; |
|---|
| 221 | for ($i = 0; $i <= $max; $i ++) { |
|---|
| 222 | if ($i) { |
|---|
| 223 | $list .= ', '; |
|---|
| 224 | } |
|---|
| 225 | if (!isset($assigns[$i])) { |
|---|
| 226 | continue; |
|---|
| 227 | } |
|---|
| 228 | if (is_array($assigns[$i])) { |
|---|
| 229 | $list .= $this->toList($assigns[$i]); |
|---|
| 230 | } |
|---|
| 231 | else { |
|---|
| 232 | $list .= $assigns[$i]; |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | return $list . ')'; |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| 238 | // }}} |
|---|
| 239 | class Decompiler_ListBox extends Decompiler_Box // {{{ |
|---|
| 240 | { |
|---|
| 241 | } |
|---|
| 242 | // }}} |
|---|
| 243 | class Decompiler_Array extends Decompiler_Value // {{{ |
|---|
| 244 | { |
|---|
| 245 | function Decompiler_Array($value = array()) |
|---|
| 246 | { |
|---|
| 247 | $this->value = $value; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | function toCode($indent) |
|---|
| 251 | { |
|---|
| 252 | $exp = "array("; |
|---|
| 253 | $indent = $indent . INDENT; |
|---|
| 254 | $assoclen = 0; |
|---|
| 255 | $multiline = 0; |
|---|
| 256 | $i = 0; |
|---|
| 257 | foreach ($this->value as $k => $v) { |
|---|
| 258 | if ($i !== $k) { |
|---|
| 259 | $len = strlen($k); |
|---|
| 260 | if ($assoclen < $len) { |
|---|
| 261 | $assoclen = $len; |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | $spec = xcache_get_special_value($v); |
|---|
| 265 | if (is_array(isset($spec) ? $spec : $v)) { |
|---|
| 266 | $multiline ++; |
|---|
| 267 | } |
|---|
| 268 | ++ $i; |
|---|
| 269 | } |
|---|
| 270 | if ($assoclen) { |
|---|
| 271 | $assoclen += 2; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | $i = 0; |
|---|
| 275 | $subindent = $indent . INDENT; |
|---|
| 276 | foreach ($this->value as $k => $v) { |
|---|
| 277 | if ($multiline) { |
|---|
| 278 | if ($i) { |
|---|
| 279 | $exp .= ","; |
|---|
| 280 | } |
|---|
| 281 | $exp .= "\n"; |
|---|
| 282 | $exp .= $indent; |
|---|
| 283 | } |
|---|
| 284 | else { |
|---|
| 285 | if ($i) { |
|---|
| 286 | $exp .= ", "; |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | $k = var_export($k, true); |
|---|
| 291 | if ($multiline) { |
|---|
| 292 | $exp .= sprintf("%{$assoclen}s => ", $k); |
|---|
| 293 | } |
|---|
| 294 | else if ($assoclen) { |
|---|
| 295 | $exp .= $k . ' => '; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | $exp .= toCode(value($v), $subindent); |
|---|
| 299 | |
|---|
| 300 | $i ++; |
|---|
| 301 | } |
|---|
| 302 | if ($multiline) { |
|---|
| 303 | $exp .= "\n$indent)"; |
|---|
| 304 | } |
|---|
| 305 | else { |
|---|
| 306 | $exp .= ")"; |
|---|
| 307 | } |
|---|
| 308 | return $exp; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | // }}} |
|---|
| 312 | class Decompiler_ForeachBox extends Decompiler_Box // {{{ |
|---|
| 313 | { |
|---|
| 314 | var $iskey; |
|---|
| 315 | |
|---|
| 316 | function toCode($indent) |
|---|
| 317 | { |
|---|
| 318 | return 'foreach (' . ''; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | // }}} |
|---|
| 322 | |
|---|
| 323 | class Decompiler |
|---|
| 324 | { |
|---|
| 325 | var $rName = '!^[\\w_][\\w\\d_]*$!'; |
|---|
| 326 | var $rQuotedName = "!^'[\\w_][\\w\\d_]*'\$!"; |
|---|
| 327 | |
|---|
| 328 | function Decompiler() |
|---|
| 329 | { |
|---|
| 330 | // {{{ opinfo |
|---|
| 331 | $this->unaryops = array( |
|---|
| 332 | XC_BW_NOT => '~', |
|---|
| 333 | XC_BOOL_NOT => '!', |
|---|
| 334 | ); |
|---|
| 335 | $this->binops = array( |
|---|
| 336 | XC_ADD => "+", |
|---|
| 337 | XC_ASSIGN_ADD => "+=", |
|---|
| 338 | XC_SUB => "-", |
|---|
| 339 | XC_ASSIGN_SUB => "-=", |
|---|
| 340 | XC_MUL => "*", |
|---|
| 341 | XC_ASSIGN_MUL => "*=", |
|---|
| 342 | XC_DIV => "/", |
|---|
| 343 | XC_ASSIGN_DIV => "/=", |
|---|
| 344 | XC_MOD => "%", |
|---|
| 345 | XC_ASSIGN_MOD => "%=", |
|---|
| 346 | XC_SL => "<<", |
|---|
| 347 | XC_ASSIGN_SL => "<<=", |
|---|
| 348 | XC_SR => ">>", |
|---|
| 349 | XC_ASSIGN_SR => ">>=", |
|---|
| 350 | XC_CONCAT => ".", |
|---|
| 351 | XC_ASSIGN_CONCAT => ".=", |
|---|
| 352 | XC_IS_IDENTICAL => "===", |
|---|
| 353 | XC_IS_NOT_IDENTICAL => "!==", |
|---|
| 354 | XC_IS_EQUAL => "==", |
|---|
| 355 | XC_IS_NOT_EQUAL => "!=", |
|---|
| 356 | XC_IS_SMALLER => "<", |
|---|
| 357 | XC_IS_SMALLER_OR_EQUAL => "<=", |
|---|
| 358 | XC_BW_OR => "|", |
|---|
| 359 | XC_ASSIGN_BW_OR => "|=", |
|---|
| 360 | XC_BW_AND => "&", |
|---|
| 361 | XC_ASSIGN_BW_AND => "&=", |
|---|
| 362 | XC_BW_XOR => "^", |
|---|
| 363 | XC_ASSIGN_BW_XOR => "^=", |
|---|
| 364 | XC_BOOL_XOR => "xor", |
|---|
| 365 | ); |
|---|
| 366 | // }}} |
|---|
| 367 | $this->includeTypes = array( // {{{ |
|---|
| 368 | ZEND_EVAL => 'eval', |
|---|
| 369 | ZEND_INCLUDE => 'include', |
|---|
| 370 | ZEND_INCLUDE_ONCE => 'include_once', |
|---|
| 371 | ZEND_REQUIRE => 'require', |
|---|
| 372 | ZEND_REQUIRE_ONCE => 'require_once', |
|---|
| 373 | ); |
|---|
| 374 | // }}} |
|---|
| 375 | } |
|---|
| 376 | function outputPhp(&$opcodes, $opline, $last, $indent) // {{{ |
|---|
| 377 | { |
|---|
| 378 | $origindent = $indent; |
|---|
| 379 | $curticks = 0; |
|---|
| 380 | for ($i = $opline; $i <= $last; $i ++) { |
|---|
| 381 | $op = $opcodes[$i]; |
|---|
| 382 | if (isset($op['php'])) { |
|---|
| 383 | $toticks = isset($op['ticks']) ? $op['ticks'] : 0; |
|---|
| 384 | if ($curticks != $toticks) { |
|---|
| 385 | if (!$toticks) { |
|---|
| 386 | echo $origindent, "}\n"; |
|---|
| 387 | $indent = $origindent; |
|---|
| 388 | } |
|---|
| 389 | else { |
|---|
| 390 | if ($curticks) { |
|---|
| 391 | echo $origindent, "}\n"; |
|---|
| 392 | } |
|---|
| 393 | else if (!$curticks) { |
|---|
| 394 | $indent .= INDENT; |
|---|
| 395 | } |
|---|
| 396 | echo $origindent, "declare(ticks=$curticks) {\n"; |
|---|
| 397 | } |
|---|
| 398 | $curticks = $toticks; |
|---|
| 399 | } |
|---|
| 400 | echo $indent, toCode($op['php'], $indent), ";\n"; |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | if ($curticks) { |
|---|
| 404 | echo $origindent, "}\n"; |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | // }}} |
|---|
| 408 | function getOpVal($op, &$EX, $tostr = true, $free = false) // {{{ |
|---|
| 409 | { |
|---|
| 410 | switch ($op['op_type']) { |
|---|
| 411 | case XC_IS_CONST: |
|---|
| 412 | return toCode(value($op['constant']), $EX); |
|---|
| 413 | |
|---|
| 414 | case XC_IS_VAR: |
|---|
| 415 | case XC_IS_TMP_VAR: |
|---|
| 416 | $T = &$EX['Ts']; |
|---|
| 417 | $ret = $T[$op['var']]; |
|---|
| 418 | if ($tostr) { |
|---|
| 419 | $ret = toCode($ret, $EX); |
|---|
| 420 | } |
|---|
| 421 | if ($free) { |
|---|
| 422 | unset($T[$op['var']]); |
|---|
| 423 | } |
|---|
| 424 | return $ret; |
|---|
| 425 | |
|---|
| 426 | case XC_IS_CV: |
|---|
| 427 | $var = $op['var']; |
|---|
| 428 | $var = $EX['op_array']['vars'][$var]; |
|---|
| 429 | return '$' . $var['name']; |
|---|
| 430 | |
|---|
| 431 | case XC_IS_UNUSED: |
|---|
| 432 | return null; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | // }}} |
|---|
| 436 | function removeKeyPrefix($array, $prefix) // {{{ |
|---|
| 437 | { |
|---|
| 438 | $prefixLen = strlen($prefix); |
|---|
| 439 | $ret = array(); |
|---|
| 440 | foreach ($array as $key => $value) { |
|---|
| 441 | if (substr($key, 0, $prefixLen) == $prefix) { |
|---|
| 442 | $key = substr($key, $prefixLen); |
|---|
| 443 | } |
|---|
| 444 | $ret[$key] = $value; |
|---|
| 445 | } |
|---|
| 446 | return $ret; |
|---|
| 447 | } |
|---|
| 448 | // }}} |
|---|
| 449 | function &fixOpcode($opcodes, $removeTailing = false) // {{{ |
|---|
| 450 | { |
|---|
| 451 | if ($removeTailing) { |
|---|
| 452 | $last = count($opcodes) - 1; |
|---|
| 453 | if ($opcodes[$last]['opcode'] == XC_HANDLE_EXCEPTION) { |
|---|
| 454 | unset($opcodes[$last]); |
|---|
| 455 | } |
|---|
| 456 | } |
|---|
| 457 | for ($i = 0, $cnt = count($opcodes); $i < $cnt; $i ++) { |
|---|
| 458 | if (function_exists('xcache_get_fixed_opcode')) { |
|---|
| 459 | $opcodes[$i]['opcode'] = xcache_get_fixed_opcode($opcodes[$i]['opcode'], $i); |
|---|
| 460 | } |
|---|
| 461 | if (isset($opcodes[$i]['op1'])) { |
|---|
| 462 | $opcodes[$i]['op1'] = $this->removeKeyPrefix($opcodes[$i]['op1'], 'u.'); |
|---|
| 463 | $opcodes[$i]['op2'] = $this->removeKeyPrefix($opcodes[$i]['op2'], 'u.'); |
|---|
| 464 | $opcodes[$i]['result'] = $this->removeKeyPrefix($opcodes[$i]['result'], 'u.'); |
|---|
| 465 | } |
|---|
| 466 | else { |
|---|
| 467 | $op = array( |
|---|
| 468 | 'op1' => array(), |
|---|
| 469 | 'op2' => array(), |
|---|
| 470 | 'op3' => array(), |
|---|
| 471 | ); |
|---|
| 472 | foreach ($opcodes[$i] as $name => $value) { |
|---|
| 473 | if (preg_match('!^(op1|op2|result)\\.(.*)!', $name, $m)) { |
|---|
| 474 | list(, $which, $field) = $m; |
|---|
| 475 | $op[$which][$field] = $value; |
|---|
| 476 | } |
|---|
| 477 | else if (preg_match('!^(op1|op2|result)_type$!', $name, $m)) { |
|---|
| 478 | list(, $which) = $m; |
|---|
| 479 | $op[$which]['op_type'] = $value; |
|---|
| 480 | } |
|---|
| 481 | else { |
|---|
| 482 | $op[$name] = $value; |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | $opcodes[$i] = $op; |
|---|
| 486 | } |
|---|
| 487 | } |
|---|
| 488 | return $opcodes; |
|---|
| 489 | } |
|---|
| 490 | // }}} |
|---|
| 491 | function &dop_array($op_array, $indent = '') // {{{ |
|---|
| 492 | { |
|---|
| 493 | $op_array['opcodes'] = $this->fixOpcode($op_array['opcodes'], true); |
|---|
| 494 | $opcodes = &$op_array['opcodes']; |
|---|
| 495 | $EX['indent'] = ''; |
|---|
| 496 | // {{{ build jmp array |
|---|
| 497 | for ($i = 0, $cnt = count($opcodes); $i < $cnt; $i ++) { |
|---|
| 498 | $op = &$opcodes[$i]; |
|---|
| 499 | /* |
|---|
| 500 | if ($op['opcode'] == XC_JMPZ) { |
|---|
| 501 | $this->dumpop($op, $EX); |
|---|
| 502 | var_dump($op); |
|---|
| 503 | } |
|---|
| 504 | continue; |
|---|
| 505 | */ |
|---|
| 506 | $op['line'] = $i; |
|---|
| 507 | switch ($op['opcode']) { |
|---|
| 508 | case XC_JMP: |
|---|
| 509 | $target = $op['op1']['var']; |
|---|
| 510 | $op['jmpouts'] = array($target); |
|---|
| 511 | $opcodes[$target]['jmpins'][] = $i; |
|---|
| 512 | break; |
|---|
| 513 | |
|---|
| 514 | case XC_JMPZNZ: |
|---|
| 515 | $jmpz = $op['op2']['opline_num']; |
|---|
| 516 | $jmpnz = $op['extended_value']; |
|---|
| 517 | $op['jmpouts'] = array($jmpz, $jmpnz); |
|---|
| 518 | $opcodes[$jmpz]['jmpins'][] = $i; |
|---|
| 519 | $opcodes[$jmpnz]['jmpins'][] = $i; |
|---|
| 520 | break; |
|---|
| 521 | |
|---|
| 522 | case XC_JMPZ: |
|---|
| 523 | case XC_JMPNZ: |
|---|
| 524 | case XC_JMPZ_EX: |
|---|
| 525 | case XC_JMPNZ_EX: |
|---|
| 526 | // case XC_FE_RESET: |
|---|
| 527 | case XC_FE_FETCH: |
|---|
| 528 | // case XC_JMP_NO_CTOR: |
|---|
| 529 | $target = $op['op2']['opline_num']; |
|---|
| 530 | //if (!isset($target)) { |
|---|
| 531 | // $this->dumpop($op, $EX); |
|---|
| 532 | // var_dump($op); exit; |
|---|
| 533 | //} |
|---|
| 534 | $op['jmpouts'] = array($target); |
|---|
| 535 | $opcodes[$target]['jmpins'][] = $i; |
|---|
| 536 | break; |
|---|
| 537 | |
|---|
| 538 | /* |
|---|
| 539 | case XC_RETURN: |
|---|
| 540 | $op['jmpouts'] = array(); |
|---|
| 541 | break; |
|---|
| 542 | */ |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | unset($op); |
|---|
| 546 | // }}} |
|---|
| 547 | // build semi-basic blocks |
|---|
| 548 | $nextbbs = array(); |
|---|
| 549 | $starti = 0; |
|---|
| 550 | for ($i = 1, $cnt = count($opcodes); $i < $cnt; $i ++) { |
|---|
| 551 | if (isset($opcodes[$i]['jmpins']) |
|---|
| 552 | || isset($opcodes[$i - 1]['jmpouts'])) { |
|---|
| 553 | $nextbbs[$starti] = $i; |
|---|
| 554 | $starti = $i; |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | $nextbbs[$starti] = $cnt; |
|---|
| 558 | |
|---|
| 559 | $EX = array(); |
|---|
| 560 | $EX['Ts'] = array(); |
|---|
| 561 | $EX['indent'] = $indent; |
|---|
| 562 | $EX['nextbbs'] = $nextbbs; |
|---|
| 563 | $EX['op_array'] = &$op_array; |
|---|
| 564 | $EX['opcodes'] = &$opcodes; |
|---|
| 565 | // func call |
|---|
| 566 | $EX['object'] = null; |
|---|
| 567 | $EX['called_scope'] = null; |
|---|
| 568 | $EX['fbc'] = null; |
|---|
| 569 | $EX['argstack'] = array(); |
|---|
| 570 | $EX['arg_types_stack'] = array(); |
|---|
| 571 | $EX['last'] = count($opcodes) - 1; |
|---|
| 572 | $EX['silence'] = 0; |
|---|
| 573 | |
|---|
| 574 | for ($next = 0, $last = $EX['last']; |
|---|
| 575 | $loop = $this->outputCode($EX, $next, $last, $indent, true); |
|---|
| 576 | list($next, $last) = $loop) { |
|---|
| 577 | // empty |
|---|
| 578 | } |
|---|
| 579 | return $EX; |
|---|
| 580 | } |
|---|
| 581 | // }}} |
|---|
| 582 | function outputCode(&$EX, $opline, $last, $indent, $loop = false) // {{{ |
|---|
| 583 | { |
|---|
| 584 | $op = &$EX['opcodes'][$opline]; |
|---|
| 585 | $next = $EX['nextbbs'][$opline]; |
|---|
| 586 | |
|---|
| 587 | $end = $next - 1; |
|---|
| 588 | if ($end > $last) { |
|---|
| 589 | $end = $last; |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | if (isset($op['jmpins'])) { |
|---|
| 593 | echo "\nline", $op['line'], ":\n"; |
|---|
| 594 | } |
|---|
| 595 | else { |
|---|
| 596 | // echo ";;;\n"; |
|---|
| 597 | } |
|---|
| 598 | $this->dasmBasicBlock($EX, $opline, $end); |
|---|
| 599 | $this->outputPhp($EX['opcodes'], $opline, $end, $indent); |
|---|
| 600 | // jmpout op |
|---|
| 601 | $op = &$EX['opcodes'][$end]; |
|---|
| 602 | $op1 = $op['op1']; |
|---|
| 603 | $op2 = $op['op2']; |
|---|
| 604 | $ext = $op['extended_value']; |
|---|
| 605 | $line = $op['line']; |
|---|
| 606 | |
|---|
| 607 | if (isset($EX['opcodes'][$next])) { |
|---|
| 608 | if (isset($last) && $next > $last) { |
|---|
| 609 | $next = null; |
|---|
| 610 | } |
|---|
| 611 | } |
|---|
| 612 | else { |
|---|
| 613 | $next = null; |
|---|
| 614 | } |
|---|
| 615 | if ($op['opcode'] == XC_FE_FETCH) { |
|---|
| 616 | $opline = $next; |
|---|
| 617 | $next = $op['op2']['opline_num']; |
|---|
| 618 | $end = $next - 1; |
|---|
| 619 | |
|---|
| 620 | ob_start(); |
|---|
| 621 | $this->outputCode($EX, $opline, $end /* - 1 skip last jmp */, $indent . INDENT); |
|---|
| 622 | $body = ob_get_clean(); |
|---|
| 623 | |
|---|
| 624 | $as = toCode($op['fe_as'], $EX); |
|---|
| 625 | if (isset($op['fe_key'])) { |
|---|
| 626 | $as = toCode($op['fe_key'], $EX) . ' => ' . $as; |
|---|
| 627 | } |
|---|
| 628 | echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n"; |
|---|
| 629 | echo $body; |
|---|
| 630 | echo "{$indent}}"; |
|---|
| 631 | // $this->outputCode($EX, $next, $last, $indent); |
|---|
| 632 | // return; |
|---|
| 633 | } |
|---|
| 634 | /* |
|---|
| 635 | if ($op['opcode'] == XC_JMPZ) { |
|---|
| 636 | $target = $op2['opline_num']; |
|---|
| 637 | if ($line + 1) { |
|---|
| 638 | $nextblock = $EX['nextbbs'][$next]; |
|---|
| 639 | $jmpop = end($nextblock); |
|---|
| 640 | if ($jmpop['opcode'] == XC_JMP) { |
|---|
| 641 | $ifendline = $op2['opline_num']; |
|---|
| 642 | if ($ifendline >= $line) { |
|---|
| 643 | $cond = $op['cond']; |
|---|
| 644 | echo "{$indent}if ($cond) {\n"; |
|---|
| 645 | $this->outputCode($EX, $next, $last, INDENT . $indent); |
|---|
| 646 | echo "$indent}\n"; |
|---|
| 647 | $this->outputCode($EX, $target, $last, $indent); |
|---|
| 648 | return; |
|---|
| 649 | } |
|---|
| 650 | } |
|---|
| 651 | } |
|---|
| 652 | } |
|---|
| 653 | */ |
|---|
| 654 | if (!isset($next)) { |
|---|
| 655 | return; |
|---|
| 656 | } |
|---|
| 657 | if (!empty($op['jmpouts']) && isset($op['isjmp'])) { |
|---|
| 658 | if (isset($op['cond'])) { |
|---|
| 659 | echo "{$indent}check ($op[cond]) {\n"; |
|---|
| 660 | echo INDENT; |
|---|
| 661 | } |
|---|
| 662 | echo $indent; |
|---|
| 663 | echo xcache_get_opcode($op['opcode']), ' line', $op['jmpouts'][0]; |
|---|
| 664 | if (isset($op['jmpouts'][1])) { |
|---|
| 665 | echo ', line', $op['jmpouts'][1]; |
|---|
| 666 | } |
|---|
| 667 | echo ";"; |
|---|
| 668 | // echo ' // <- line', $op['line']; |
|---|
| 669 | echo "\n"; |
|---|
| 670 | if (isset($op['cond'])) echo "$indent}\n"; |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | // proces JMPZ_EX/JMPNZ_EX for AND,OR |
|---|
| 674 | $op = &$EX['opcodes'][$next]; |
|---|
| 675 | /* |
|---|
| 676 | if (isset($op['jmpins'])) { |
|---|
| 677 | foreach (array_reverse($op['jmpins']) as $fromline) { |
|---|
| 678 | $fromop = $EX['opcodes'][$fromline]; |
|---|
| 679 | switch ($fromop['opcode']) { |
|---|
| 680 | case XC_JMPZ_EX: $opstr = 'and'; break; |
|---|
| 681 | case XC_JMPNZ_EX: $opstr = 'or'; break; |
|---|
| 682 | case XC_JMPZNZ: var_dump($fromop); exit; |
|---|
| 683 | default: continue 2; |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | $var = $fromop['result']['var']; |
|---|
| 687 | var_dump($EX['Ts'][$var]); |
|---|
| 688 | $EX['Ts'][$var] = '(' . $fromop['and_or'] . " $opstr " . $EX['Ts'][$var] . ')'; |
|---|
| 689 | } |
|---|
| 690 | #$this->outputCode($EX, $next, $last, $indent); |
|---|
| 691 | #return; |
|---|
| 692 | } |
|---|
| 693 | */ |
|---|
| 694 | if (isset($op['cond_false'])) { |
|---|
| 695 | // $this->dumpop($op, $EX); |
|---|
| 696 | // any true comes here, so it's a "or" |
|---|
| 697 | $cond = implode(' and ', $op['cond_false']); |
|---|
| 698 | // var_dump($op['cond'] = $cond); |
|---|
| 699 | /* |
|---|
| 700 | $rvalue = implode(' or ', $op['cond_true']) . ' or ' . $rvalue; |
|---|
| 701 | unset($op['cond_true']); |
|---|
| 702 | */ |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | if ($loop) { |
|---|
| 706 | return array($next, $last); |
|---|
| 707 | } |
|---|
| 708 | $this->outputCode($EX, $next, $last, $indent); |
|---|
| 709 | } |
|---|
| 710 | // }}} |
|---|
| 711 | function unquoteName($str) // {{{ |
|---|
| 712 | { |
|---|
| 713 | if (preg_match($this->rQuotedName, $str)) { |
|---|
| 714 | $str = substr($str, 1, -1); |
|---|
| 715 | } |
|---|
| 716 | return $str; |
|---|
| 717 | } |
|---|
| 718 | // }}} |
|---|
| 719 | function dasmBasicBlock(&$EX, $opline, $last) // {{{ |
|---|
| 720 | { |
|---|
| 721 | $T = &$EX['Ts']; |
|---|
| 722 | $opcodes = &$EX['opcodes']; |
|---|
| 723 | $lastphpop = null; |
|---|
| 724 | |
|---|
| 725 | for ($i = $opline, $ic = $last + 1; $i < $ic; $i ++) { |
|---|
| 726 | // {{{ prepair |
|---|
| 727 | $op = &$opcodes[$i]; |
|---|
| 728 | $opc = $op['opcode']; |
|---|
| 729 | if ($opc == XC_NOP) { |
|---|
| 730 | continue; |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | $op1 = $op['op1']; |
|---|
| 734 | $op2 = $op['op2']; |
|---|
| 735 | $res = $op['result']; |
|---|
| 736 | $ext = $op['extended_value']; |
|---|
| 737 | |
|---|
| 738 | $opname = xcache_get_opcode($opc); |
|---|
| 739 | |
|---|
| 740 | if ($opname == 'UNDEF' || !isset($opname)) { |
|---|
| 741 | echo 'UNDEF OP:'; |
|---|
| 742 | $this->dumpop($op, $EX); |
|---|
| 743 | continue; |
|---|
| 744 | } |
|---|
| 745 | // $this->dumpop($op, $EX); //var_dump($op); |
|---|
| 746 | |
|---|
| 747 | $resvar = null; |
|---|
| 748 | if ((ZEND_ENGINE_2_4 ? ($res['op_type'] & EXT_TYPE_UNUSED) : ($res['EA.type'] & EXT_TYPE_UNUSED)) || $res['op_type'] == XC_IS_UNUSED) { |
|---|
| 749 | $istmpres = false; |
|---|
| 750 | } |
|---|
| 751 | else { |
|---|
| 752 | $istmpres = true; |
|---|
| 753 | } |
|---|
| 754 | // }}} |
|---|
| 755 | // echo $opname, "\n"; |
|---|
| 756 | |
|---|
| 757 | $call = array(&$this, $opname); |
|---|
| 758 | if (is_callable($call)) { |
|---|
| 759 | $this->{$opname}($op, $EX); |
|---|
| 760 | } |
|---|
| 761 | else if (isset($this->binops[$opc])) { // {{{ |
|---|
| 762 | $op1val = $this->getOpVal($op1, $EX, false); |
|---|
| 763 | $op2val = $this->getOpVal($op2, $EX, false); |
|---|
| 764 | $rvalue = new Decompiler_Binop($this, $op1val, $opc, $op2val); |
|---|
| 765 | $resvar = $rvalue; |
|---|
| 766 | // }}} |
|---|
| 767 | } |
|---|
| 768 | else if (isset($this->unaryops[$opc])) { // {{{ |
|---|
| 769 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 770 | $myop = $this->unaryops[$opc]; |
|---|
| 771 | $rvalue = "$myop$op1val"; |
|---|
| 772 | $resvar = $rvalue; |
|---|
| 773 | // }}} |
|---|
| 774 | } |
|---|
| 775 | else { |
|---|
| 776 | switch ($opc) { |
|---|
| 777 | case XC_NEW: // {{{ |
|---|
| 778 | array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); |
|---|
| 779 | $EX['object'] = (int) $res['var']; |
|---|
| 780 | $EX['called_scope'] = null; |
|---|
| 781 | $EX['fbc'] = 'new ' . $this->unquoteName($this->getOpVal($op1, $EX)); |
|---|
| 782 | if (!ZEND_ENGINE_2) { |
|---|
| 783 | $resvar = '$new object$'; |
|---|
| 784 | } |
|---|
| 785 | break; |
|---|
| 786 | // }}} |
|---|
| 787 | case XC_FETCH_CLASS: // {{{ |
|---|
| 788 | if ($op2['op_type'] == XC_IS_UNUSED) { |
|---|
| 789 | switch (($ext & (defined('ZEND_FETCH_CLASS_MASK') ? ZEND_FETCH_CLASS_MASK : 0xFF))) { |
|---|
| 790 | case ZEND_FETCH_CLASS_SELF: |
|---|
| 791 | $class = 'self'; |
|---|
| 792 | break; |
|---|
| 793 | case ZEND_FETCH_CLASS_PARENT: |
|---|
| 794 | $class = 'parent'; |
|---|
| 795 | break; |
|---|
| 796 | case ZEND_FETCH_CLASS_STATIC: |
|---|
| 797 | $class = 'static'; |
|---|
| 798 | break; |
|---|
| 799 | } |
|---|
| 800 | $istmpres = true; |
|---|
| 801 | } |
|---|
| 802 | else { |
|---|
| 803 | $class = $op2['constant']; |
|---|
| 804 | if (is_object($class)) { |
|---|
| 805 | $class = get_class($class); |
|---|
| 806 | } |
|---|
| 807 | } |
|---|
| 808 | $resvar = $class; |
|---|
| 809 | break; |
|---|
| 810 | // }}} |
|---|
| 811 | case XC_FETCH_CONSTANT: // {{{ |
|---|
| 812 | if ($op1['op_type'] == XC_IS_CONST) { |
|---|
| 813 | $resvar = $op1['constant']; |
|---|
| 814 | } |
|---|
| 815 | else if ($op1['op_type'] == XC_IS_UNUSED) { |
|---|
| 816 | $resvar = $op2['constant']; |
|---|
| 817 | } |
|---|
| 818 | else { |
|---|
| 819 | $class = $T[$op1['var']]; |
|---|
| 820 | assert($class[0] == 'class'); |
|---|
| 821 | $resvar = $class[1] . '::' . $op2['constant']; |
|---|
| 822 | } |
|---|
| 823 | break; |
|---|
| 824 | // }}} |
|---|
| 825 | // {{{ case XC_FETCH_* |
|---|
| 826 | case XC_FETCH_R: |
|---|
| 827 | case XC_FETCH_W: |
|---|
| 828 | case XC_FETCH_RW: |
|---|
| 829 | case XC_FETCH_FUNC_ARG: |
|---|
| 830 | case XC_FETCH_UNSET: |
|---|
| 831 | case XC_FETCH_IS: |
|---|
| 832 | case XC_UNSET_VAR: |
|---|
| 833 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 834 | if (defined('ZEND_FETCH_TYPE_MASK')) { |
|---|
| 835 | $fetchtype = ($ext & ZEND_FETCH_TYPE_MASK); |
|---|
| 836 | } |
|---|
| 837 | else { |
|---|
| 838 | $fetchtype = $op2[!ZEND_ENGINE_2 ? 'fetch_type' : 'EA.type']; |
|---|
| 839 | } |
|---|
| 840 | switch ($fetchtype) { |
|---|
| 841 | case ZEND_FETCH_STATIC_MEMBER: |
|---|
| 842 | $class = $this->getOpVal($op2, $EX); |
|---|
| 843 | $rvalue = $class . '::$' . $this->unquoteName($rvalue); |
|---|
| 844 | break; |
|---|
| 845 | default: |
|---|
| 846 | $name = $this->unquoteName($rvalue); |
|---|
| 847 | $globalname = xcache_is_autoglobal($name) ? "\$$name" : "\$GLOBALS[$rvalue]"; |
|---|
| 848 | $rvalue = new Decompiler_Fetch($rvalue, $fetchtype, $globalname); |
|---|
| 849 | break; |
|---|
| 850 | } |
|---|
| 851 | if ($opc == XC_UNSET_VAR) { |
|---|
| 852 | $op['php'] = "unset(" . toCode($rvalue, $EX) . ")"; |
|---|
| 853 | $lastphpop = &$op; |
|---|
| 854 | } |
|---|
| 855 | else if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 856 | $resvar = $rvalue; |
|---|
| 857 | } |
|---|
| 858 | break; |
|---|
| 859 | // }}} |
|---|
| 860 | // {{{ case XC_FETCH_DIM_* |
|---|
| 861 | case XC_FETCH_DIM_TMP_VAR: |
|---|
| 862 | case XC_FETCH_DIM_R: |
|---|
| 863 | case XC_FETCH_DIM_W: |
|---|
| 864 | case XC_FETCH_DIM_RW: |
|---|
| 865 | case XC_FETCH_DIM_FUNC_ARG: |
|---|
| 866 | case XC_FETCH_DIM_UNSET: |
|---|
| 867 | case XC_FETCH_DIM_IS: |
|---|
| 868 | case XC_ASSIGN_DIM: |
|---|
| 869 | case XC_UNSET_DIM: |
|---|
| 870 | case XC_UNSET_DIM_OBJ: |
|---|
| 871 | $src = $this->getOpVal($op1, $EX, false); |
|---|
| 872 | if (is_a($src, "Decompiler_ForeachBox")) { |
|---|
| 873 | $src->iskey = $this->getOpVal($op2, $EX); |
|---|
| 874 | $resvar = $src; |
|---|
| 875 | break; |
|---|
| 876 | } |
|---|
| 877 | else if (is_a($src, "Decompiler_DimBox")) { |
|---|
| 878 | $dimbox = $src; |
|---|
| 879 | } |
|---|
| 880 | else { |
|---|
| 881 | if (!is_a($src, "Decompiler_ListBox")) { |
|---|
| 882 | $list = new Decompiler_List($this->getOpVal($op1, $EX, false)); |
|---|
| 883 | |
|---|
| 884 | $src = new Decompiler_ListBox($list); |
|---|
| 885 | if (!isset($op1['var'])) { |
|---|
| 886 | $this->dumpop($op, $EX); |
|---|
| 887 | var_dump($op); |
|---|
| 888 | die('missing var'); |
|---|
| 889 | } |
|---|
| 890 | $T[$op1['var']] = $src; |
|---|
| 891 | unset($list); |
|---|
| 892 | } |
|---|
| 893 | $dim = new Decompiler_Dim($src); |
|---|
| 894 | $src->obj->dims[] = &$dim; |
|---|
| 895 | |
|---|
| 896 | $dimbox = new Decompiler_DimBox($dim); |
|---|
| 897 | } |
|---|
| 898 | $dim = &$dimbox->obj; |
|---|
| 899 | $dim->offsets[] = $this->getOpVal($op2, $EX); |
|---|
| 900 | if ($ext == ZEND_FETCH_ADD_LOCK) { |
|---|
| 901 | $src->obj->everLocked = true; |
|---|
| 902 | } |
|---|
| 903 | else if ($ext == ZEND_FETCH_STANDARD) { |
|---|
| 904 | $dim->isLast = true; |
|---|
| 905 | } |
|---|
| 906 | unset($dim); |
|---|
| 907 | $rvalue = $dimbox; |
|---|
| 908 | |
|---|
| 909 | if ($opc == XC_ASSIGN_DIM) { |
|---|
| 910 | $lvalue = $rvalue; |
|---|
| 911 | ++ $i; |
|---|
| 912 | $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); |
|---|
| 913 | $resvar = toCode($lvalue, $EX) . ' = ' . $rvalue; |
|---|
| 914 | } |
|---|
| 915 | else if ($opc == XC_UNSET_DIM) { |
|---|
| 916 | $op['php'] = "unset(" . toCode($rvalue, $EX) . ")"; |
|---|
| 917 | $lastphpop = &$op; |
|---|
| 918 | } |
|---|
| 919 | else if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 920 | $resvar = $rvalue; |
|---|
| 921 | } |
|---|
| 922 | break; |
|---|
| 923 | // }}} |
|---|
| 924 | case XC_ASSIGN: // {{{ |
|---|
| 925 | $lvalue = $this->getOpVal($op1, $EX); |
|---|
| 926 | $rvalue = $this->getOpVal($op2, $EX, false); |
|---|
| 927 | if (is_a($rvalue, 'Decompiler_ForeachBox')) { |
|---|
| 928 | $type = $rvalue->iskey ? 'fe_key' : 'fe_as'; |
|---|
| 929 | $rvalue->obj[$type] = $lvalue; |
|---|
| 930 | unset($T[$op2['var']]); |
|---|
| 931 | break; |
|---|
| 932 | } |
|---|
| 933 | if (is_a($rvalue, "Decompiler_DimBox")) { |
|---|
| 934 | $dim = &$rvalue->obj; |
|---|
| 935 | $dim->assign = $lvalue; |
|---|
| 936 | if ($dim->isLast) { |
|---|
| 937 | $resvar = toCode($dim->value, $EX); |
|---|
| 938 | } |
|---|
| 939 | unset($dim); |
|---|
| 940 | break; |
|---|
| 941 | } |
|---|
| 942 | $resvar = "$lvalue = " . toCode($rvalue, $EX); |
|---|
| 943 | break; |
|---|
| 944 | // }}} |
|---|
| 945 | case XC_ASSIGN_REF: // {{{ |
|---|
| 946 | $lvalue = $this->getOpVal($op1, $EX); |
|---|
| 947 | $rvalue = $this->getOpVal($op2, $EX, false); |
|---|
| 948 | if (is_a($rvalue, 'Decompiler_Fetch')) { |
|---|
| 949 | $src = toCode($rvalue->src, $EX); |
|---|
| 950 | if (substr($src, 1, -1) == substr($lvalue, 1)) { |
|---|
| 951 | switch ($rvalue->fetchType) { |
|---|
| 952 | case ZEND_FETCH_GLOBAL: |
|---|
| 953 | case ZEND_FETCH_GLOBAL_LOCK: |
|---|
| 954 | $resvar = 'global ' . $lvalue; |
|---|
| 955 | break 2; |
|---|
| 956 | case ZEND_FETCH_STATIC: |
|---|
| 957 | $statics = &$EX['op_array']['static_variables']; |
|---|
| 958 | $resvar = 'static ' . $lvalue; |
|---|
| 959 | $name = substr($src, 1, -1); |
|---|
| 960 | if (isset($statics[$name])) { |
|---|
| 961 | $var = $statics[$name]; |
|---|
| 962 | $resvar .= ' = '; |
|---|
| 963 | $resvar .= toCode(value($var), $EX); |
|---|
| 964 | } |
|---|
| 965 | unset($statics); |
|---|
| 966 | break 2; |
|---|
| 967 | default: |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | } |
|---|
| 971 | // TODO: PHP_6 global |
|---|
| 972 | $rvalue = toCode($rvalue, $EX); |
|---|
| 973 | $resvar = "$lvalue = &$rvalue"; |
|---|
| 974 | break; |
|---|
| 975 | // }}} |
|---|
| 976 | // {{{ case XC_FETCH_OBJ_* |
|---|
| 977 | case XC_FETCH_OBJ_R: |
|---|
| 978 | case XC_FETCH_OBJ_W: |
|---|
| 979 | case XC_FETCH_OBJ_RW: |
|---|
| 980 | case XC_FETCH_OBJ_FUNC_ARG: |
|---|
| 981 | case XC_FETCH_OBJ_UNSET: |
|---|
| 982 | case XC_FETCH_OBJ_IS: |
|---|
| 983 | case XC_ASSIGN_OBJ: |
|---|
| 984 | $obj = $this->getOpVal($op1, $EX); |
|---|
| 985 | if (!isset($obj)) { |
|---|
| 986 | $obj = '$this'; |
|---|
| 987 | } |
|---|
| 988 | $prop = $this->getOpVal($op2, $EX); |
|---|
| 989 | if (preg_match($this->rQuotedName, $prop)) { |
|---|
| 990 | $prop = substr($prop, 1, -1);; |
|---|
| 991 | $rvalue = "{$obj}->$prop"; |
|---|
| 992 | } |
|---|
| 993 | else { |
|---|
| 994 | $rvalue = "{$obj}->{" . "$prop}"; |
|---|
| 995 | } |
|---|
| 996 | if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 997 | $resvar = $rvalue; |
|---|
| 998 | } |
|---|
| 999 | if ($opc == XC_ASSIGN_OBJ) { |
|---|
| 1000 | ++ $i; |
|---|
| 1001 | $lvalue = $rvalue; |
|---|
| 1002 | $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); |
|---|
| 1003 | $resvar = "$lvalue = $rvalue"; |
|---|
| 1004 | } |
|---|
| 1005 | break; |
|---|
| 1006 | // }}} |
|---|
| 1007 | case XC_ISSET_ISEMPTY_DIM_OBJ: |
|---|
| 1008 | case XC_ISSET_ISEMPTY_PROP_OBJ: |
|---|
| 1009 | case XC_ISSET_ISEMPTY: |
|---|
| 1010 | case XC_ISSET_ISEMPTY_VAR: // {{{ |
|---|
| 1011 | if ($opc == XC_ISSET_ISEMPTY_VAR) { |
|---|
| 1012 | $rvalue = $this->getOpVal($op1, $EX);; |
|---|
| 1013 | if (preg_match($this->rQuotedName, $rvalue)) { |
|---|
| 1014 | $rvalue = '$' . substr($rvalue, 1, -1); |
|---|
| 1015 | } |
|---|
| 1016 | else { |
|---|
| 1017 | $rvalue = "${" . $rvalue . "}"; |
|---|
| 1018 | } |
|---|
| 1019 | if ($op2['EA.type'] == ZEND_FETCH_STATIC_MEMBER) { |
|---|
| 1020 | $class = $this->getOpVal($op2, $EX); |
|---|
| 1021 | $rvalue = $class . '::' . $rvalue; |
|---|
| 1022 | } |
|---|
| 1023 | } |
|---|
| 1024 | else if ($opc == XC_ISSET_ISEMPTY) { |
|---|
| 1025 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 1026 | } |
|---|
| 1027 | else { |
|---|
| 1028 | $container = $this->getOpVal($op1, $EX); |
|---|
| 1029 | $dim = $this->getOpVal($op2, $EX); |
|---|
| 1030 | if ($opc == XC_ISSET_ISEMPTY_PROP_OBJ) { |
|---|
| 1031 | if (preg_match($this->rQuotedName, $dim)) { |
|---|
| 1032 | $rvalue = $container . "->" . substr($dim, 1, -1); |
|---|
| 1033 | } |
|---|
| 1034 | else { |
|---|
| 1035 | $rvalue = $container . "->{" . $dim . "}"; |
|---|
| 1036 | } |
|---|
| 1037 | } |
|---|
| 1038 | else { |
|---|
| 1039 | $rvalue = $container . "[$dim]"; |
|---|
| 1040 | } |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | switch ((!ZEND_ENGINE_2 ? $op['op2']['var'] /* constant */ : $ext) & (ZEND_ISSET|ZEND_ISEMPTY)) { |
|---|
| 1044 | case ZEND_ISSET: |
|---|
| 1045 | $rvalue = "isset($rvalue)"; |
|---|
| 1046 | break; |
|---|
| 1047 | case ZEND_ISEMPTY: |
|---|
| 1048 | $rvalue = "empty($rvalue)"; |
|---|
| 1049 | break; |
|---|
| 1050 | } |
|---|
| 1051 | $resvar = $rvalue; |
|---|
| 1052 | break; |
|---|
| 1053 | // }}} |
|---|
| 1054 | case XC_SEND_VAR_NO_REF: |
|---|
| 1055 | case XC_SEND_VAL: |
|---|
| 1056 | case XC_SEND_REF: |
|---|
| 1057 | case XC_SEND_VAR: // {{{ |
|---|
| 1058 | $ref = ($opc == XC_SEND_REF ? '&' : ''); |
|---|
| 1059 | $EX['argstack'][] = $ref . $this->getOpVal($op1, $EX); |
|---|
| 1060 | break; |
|---|
| 1061 | // }}} |
|---|
| 1062 | case XC_INIT_STATIC_METHOD_CALL: |
|---|
| 1063 | case XC_INIT_METHOD_CALL: |
|---|
| 1064 | case XC_INIT_FCALL_BY_FUNC: |
|---|
| 1065 | case XC_INIT_FCALL_BY_NAME: // {{{ |
|---|
| 1066 | if (($ext & ZEND_CTOR_CALL)) { |
|---|
| 1067 | break; |
|---|
| 1068 | } |
|---|
| 1069 | array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); |
|---|
| 1070 | if ($opc == XC_INIT_STATIC_METHOD_CALL || $opc == XC_INIT_METHOD_CALL || $op1['op_type'] != XC_IS_UNUSED) { |
|---|
| 1071 | $obj = $this->getOpVal($op1, $EX); |
|---|
| 1072 | if (!isset($obj)) { |
|---|
| 1073 | $obj = '$this'; |
|---|
| 1074 | } |
|---|
| 1075 | if ($opc == XC_INIT_STATIC_METHOD_CALL || /* PHP4 */ isset($op1['constant'])) { |
|---|
| 1076 | $EX['object'] = null; |
|---|
| 1077 | $EX['called_scope'] = $this->unquoteName($obj); |
|---|
| 1078 | } |
|---|
| 1079 | else { |
|---|
| 1080 | $EX['object'] = $obj; |
|---|
| 1081 | $EX['called_scope'] = null; |
|---|
| 1082 | } |
|---|
| 1083 | if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 1084 | $resvar = '$obj call$'; |
|---|
| 1085 | } |
|---|
| 1086 | } |
|---|
| 1087 | else { |
|---|
| 1088 | $EX['object'] = null; |
|---|
| 1089 | $EX['called_scope'] = null; |
|---|
| 1090 | } |
|---|
| 1091 | |
|---|
| 1092 | if ($opc == XC_INIT_FCALL_BY_FUNC) { |
|---|
| 1093 | $which = $op1['var']; |
|---|
| 1094 | $EX['fbc'] = $EX['op_array']['funcs'][$which]['name']; |
|---|
| 1095 | } |
|---|
| 1096 | else { |
|---|
| 1097 | $EX['fbc'] = $this->getOpVal($op2, $EX, false); |
|---|
| 1098 | } |
|---|
| 1099 | break; |
|---|
| 1100 | // }}} |
|---|
| 1101 | case XC_DO_FCALL_BY_FUNC: |
|---|
| 1102 | $which = $op1['var']; |
|---|
| 1103 | $fname = $EX['op_array']['funcs'][$which]['name']; |
|---|
| 1104 | $args = $this->popargs($EX, $ext); |
|---|
| 1105 | $resvar = $fname . "($args)"; |
|---|
| 1106 | break; |
|---|
| 1107 | case XC_DO_FCALL: |
|---|
| 1108 | $fname = $this->unquoteName($this->getOpVal($op1, $EX, false)); |
|---|
| 1109 | $args = $this->popargs($EX, $ext); |
|---|
| 1110 | $resvar = $fname . "($args)"; |
|---|
| 1111 | break; |
|---|
| 1112 | case XC_DO_FCALL_BY_NAME: // {{{ |
|---|
| 1113 | $object = null; |
|---|
| 1114 | |
|---|
| 1115 | $fname = $this->unquoteName($EX['fbc']); |
|---|
| 1116 | if (!is_int($EX['object'])) { |
|---|
| 1117 | $object = $EX['object']; |
|---|
| 1118 | } |
|---|
| 1119 | |
|---|
| 1120 | $args = $this->popargs($EX, $ext); |
|---|
| 1121 | |
|---|
| 1122 | $resvar = |
|---|
| 1123 | (isset($object) ? $object . '->' : '' ) |
|---|
| 1124 | . (isset($EX['called_scope']) ? $EX['called_scope'] . '::' : '' ) |
|---|
| 1125 | . $fname . "($args)"; |
|---|
| 1126 | unset($args); |
|---|
| 1127 | |
|---|
| 1128 | if (is_int($EX['object'])) { |
|---|
| 1129 | $T[$EX['object']] = $resvar; |
|---|
| 1130 | $resvar = null; |
|---|
| 1131 | } |
|---|
| 1132 | list($EX['fbc'], $EX['object'], $EX['called_scope']) = array_pop($EX['arg_types_stack']); |
|---|
| 1133 | break; |
|---|
| 1134 | // }}} |
|---|
| 1135 | case XC_VERIFY_ABSTRACT_CLASS: // {{{ |
|---|
| 1136 | //unset($T[$op1['var']]); |
|---|
| 1137 | break; |
|---|
| 1138 | // }}} |
|---|
| 1139 | case XC_DECLARE_CLASS: |
|---|
| 1140 | case XC_DECLARE_INHERITED_CLASS: |
|---|
| 1141 | case XC_DECLARE_INHERITED_CLASS_DELAYED: // {{{ |
|---|
| 1142 | $key = $op1['constant']; |
|---|
| 1143 | if (!isset($this->dc['class_table'][$key])) { |
|---|
| 1144 | echo 'class not found: ', $key, 'existing classes are:', "\n"; |
|---|
| 1145 | var_dump(array_keys($this->dc['class_table'])); |
|---|
| 1146 | exit; |
|---|
| 1147 | } |
|---|
| 1148 | $class = &$this->dc['class_table'][$key]; |
|---|
| 1149 | $class['name'] = $this->unquoteName($this->getOpVal($op2, $EX)); |
|---|
| 1150 | if ($opc == XC_DECLARE_INHERITED_CLASS || $opc == XC_DECLARE_INHERITED_CLASS_DELAYED) { |
|---|
| 1151 | $ext /= XC_SIZEOF_TEMP_VARIABLE; |
|---|
| 1152 | $class['parent'] = $T[$ext]; |
|---|
| 1153 | unset($T[$ext]); |
|---|
| 1154 | } |
|---|
| 1155 | else { |
|---|
| 1156 | $class['parent'] = null; |
|---|
| 1157 | } |
|---|
| 1158 | |
|---|
| 1159 | while ($i + 2 < $ic |
|---|
| 1160 | && $opcodes[$i + 2]['opcode'] == XC_ADD_INTERFACE |
|---|
| 1161 | && $opcodes[$i + 2]['op1']['var'] == $res['var'] |
|---|
| 1162 | && $opcodes[$i + 1]['opcode'] == XC_FETCH_CLASS) { |
|---|
| 1163 | $fetchop = &$opcodes[$i + 1]; |
|---|
| 1164 | $impl = $this->unquoteName($this->getOpVal($fetchop['op2'], $EX)); |
|---|
| 1165 | $addop = &$opcodes[$i + 2]; |
|---|
| 1166 | $class['interfaces'][$addop['extended_value']] = $impl; |
|---|
| 1167 | unset($fetchop, $addop); |
|---|
| 1168 | $i += 2; |
|---|
| 1169 | } |
|---|
| 1170 | $this->dclass($class); |
|---|
| 1171 | unset($class); |
|---|
| 1172 | break; |
|---|
| 1173 | // }}} |
|---|
| 1174 | case XC_INIT_STRING: // {{{ |
|---|
| 1175 | $resvar = "''"; |
|---|
| 1176 | break; |
|---|
| 1177 | // }}} |
|---|
| 1178 | case XC_ADD_CHAR: |
|---|
| 1179 | case XC_ADD_STRING: |
|---|
| 1180 | case XC_ADD_VAR: // {{{ |
|---|
| 1181 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1182 | $op2val = $this->getOpVal($op2, $EX); |
|---|
| 1183 | switch ($opc) { |
|---|
| 1184 | case XC_ADD_CHAR: |
|---|
| 1185 | $op2val = toCode(chr($op2val), $EX); |
|---|
| 1186 | break; |
|---|
| 1187 | case XC_ADD_STRING: |
|---|
| 1188 | $op2val = toCode($op2val, $EX); |
|---|
| 1189 | break; |
|---|
| 1190 | case XC_ADD_VAR: |
|---|
| 1191 | break; |
|---|
| 1192 | } |
|---|
| 1193 | if ($op1val == "''") { |
|---|
| 1194 | $rvalue = $op2val; |
|---|
| 1195 | } |
|---|
| 1196 | else if ($op2val == "''") { |
|---|
| 1197 | $rvalue = $op1val; |
|---|
| 1198 | } |
|---|
| 1199 | else { |
|---|
| 1200 | $rvalue = $op1val . ' . ' . $op2val; |
|---|
| 1201 | } |
|---|
| 1202 | $resvar = $rvalue; |
|---|
| 1203 | // }}} |
|---|
| 1204 | break; |
|---|
| 1205 | case XC_PRINT: // {{{ |
|---|
| 1206 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1207 | $resvar = "print($op1val)"; |
|---|
| 1208 | break; |
|---|
| 1209 | // }}} |
|---|
| 1210 | case XC_ECHO: // {{{ |
|---|
| 1211 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1212 | $resvar = "echo $op1val"; |
|---|
| 1213 | break; |
|---|
| 1214 | // }}} |
|---|
| 1215 | case XC_EXIT: // {{{ |
|---|
| 1216 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1217 | $resvar = "exit($op1val)"; |
|---|
| 1218 | break; |
|---|
| 1219 | // }}} |
|---|
| 1220 | case XC_INIT_ARRAY: |
|---|
| 1221 | case XC_ADD_ARRAY_ELEMENT: // {{{ |
|---|
| 1222 | $rvalue = $this->getOpVal($op1, $EX, false, true); |
|---|
| 1223 | |
|---|
| 1224 | if ($opc == XC_ADD_ARRAY_ELEMENT) { |
|---|
| 1225 | $offset = $this->getOpVal($op2, $EX); |
|---|
| 1226 | if (isset($offset)) { |
|---|
| 1227 | $T[$res['var']]->value[$offset] = $rvalue; |
|---|
| 1228 | } |
|---|
| 1229 | else { |
|---|
| 1230 | $T[$res['var']]->value[] = $rvalue; |
|---|
| 1231 | } |
|---|
| 1232 | } |
|---|
| 1233 | else { |
|---|
| 1234 | if ($opc == XC_INIT_ARRAY) { |
|---|
| 1235 | $resvar = new Decompiler_Array(); |
|---|
| 1236 | if (!isset($rvalue)) { |
|---|
| 1237 | continue; |
|---|
| 1238 | } |
|---|
| 1239 | } |
|---|
| 1240 | |
|---|
| 1241 | $offset = $this->getOpVal($op2, $EX); |
|---|
| 1242 | if (isset($offset)) { |
|---|
| 1243 | $resvar->value[$offset] = $rvalue; |
|---|
| 1244 | } |
|---|
| 1245 | else { |
|---|
| 1246 | $resvar->value[] = $rvalue; |
|---|
| 1247 | } |
|---|
| 1248 | } |
|---|
| 1249 | break; |
|---|
| 1250 | // }}} |
|---|
| 1251 | case XC_QM_ASSIGN: // {{{ |
|---|
| 1252 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1253 | break; |
|---|
| 1254 | // }}} |
|---|
| 1255 | case XC_BOOL: // {{{ |
|---|
| 1256 | $resvar = /*'(bool) ' .*/ $this->getOpVal($op1, $EX); |
|---|
| 1257 | break; |
|---|
| 1258 | // }}} |
|---|
| 1259 | case XC_RETURN: // {{{ |
|---|
| 1260 | $resvar = "return " . $this->getOpVal($op1, $EX); |
|---|
| 1261 | break; |
|---|
| 1262 | // }}} |
|---|
| 1263 | case XC_INCLUDE_OR_EVAL: // {{{ |
|---|
| 1264 | $type = $op2['var']; // hack |
|---|
| 1265 | $keyword = $this->includeTypes[$type]; |
|---|
| 1266 | $resvar = "$keyword(" . $this->getOpVal($op1, $EX) . ")"; |
|---|
| 1267 | break; |
|---|
| 1268 | // }}} |
|---|
| 1269 | case XC_FE_RESET: // {{{ |
|---|
| 1270 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1271 | break; |
|---|
| 1272 | // }}} |
|---|
| 1273 | case XC_FE_FETCH: // {{{ |
|---|
| 1274 | $op['fe_src'] = $this->getOpVal($op1, $EX); |
|---|
| 1275 | $fe = new Decompiler_ForeachBox($op); |
|---|
| 1276 | $fe->iskey = false; |
|---|
| 1277 | $T[$res['var']] = $fe; |
|---|
| 1278 | |
|---|
| 1279 | ++ $i; |
|---|
| 1280 | if (($ext & ZEND_FE_FETCH_WITH_KEY)) { |
|---|
| 1281 | $fe = new Decompiler_ForeachBox($op); |
|---|
| 1282 | $fe->iskey = true; |
|---|
| 1283 | |
|---|
| 1284 | $res = $opcodes[$i]['result']; |
|---|
| 1285 | $T[$res['var']] = $fe; |
|---|
| 1286 | } |
|---|
| 1287 | break; |
|---|
| 1288 | // }}} |
|---|
| 1289 | case XC_SWITCH_FREE: // {{{ |
|---|
| 1290 | // unset($T[$op1['var']]); |
|---|
| 1291 | break; |
|---|
| 1292 | // }}} |
|---|
| 1293 | case XC_FREE: // {{{ |
|---|
| 1294 | $free = $T[$op1['var']]; |
|---|
| 1295 | if (!is_a($free, 'Decompiler_Array') && !is_a($free, 'Decompiler_Box')) { |
|---|
| 1296 | $op['php'] = is_object($free) ? $free : $this->unquote($free, '(', ')'); |
|---|
| 1297 | $lastphpop = &$op; |
|---|
| 1298 | } |
|---|
| 1299 | unset($T[$op1['var']], $free); |
|---|
| 1300 | break; |
|---|
| 1301 | // }}} |
|---|
| 1302 | case XC_JMP_NO_CTOR: |
|---|
| 1303 | break; |
|---|
| 1304 | case XC_JMPNZ: // while |
|---|
| 1305 | case XC_JMPZNZ: // for |
|---|
| 1306 | case XC_JMPZ_EX: // and |
|---|
| 1307 | case XC_JMPNZ_EX: // or |
|---|
| 1308 | case XC_JMPZ: // {{{ |
|---|
| 1309 | if ($opc == XC_JMP_NO_CTOR && $EX['object']) { |
|---|
| 1310 | $rvalue = $EX['object']; |
|---|
| 1311 | } |
|---|
| 1312 | else { |
|---|
| 1313 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 1314 | } |
|---|
| 1315 | |
|---|
| 1316 | if (isset($op['cond_true'])) { |
|---|
| 1317 | // any true comes here, so it's a "or" |
|---|
| 1318 | $rvalue = implode(' or ', $op['cond_true']) . ' or ' . $rvalue; |
|---|
| 1319 | unset($op['cond_true']); |
|---|
| 1320 | } |
|---|
| 1321 | if (isset($op['cond_false'])) { |
|---|
| 1322 | echo "TODO(cond_false):\n"; |
|---|
| 1323 | var_dump($op);// exit; |
|---|
| 1324 | } |
|---|
| 1325 | if ($opc == XC_JMPZ_EX || $opc == XC_JMPNZ_EX || $opc == XC_JMPZ) { |
|---|
| 1326 | $targetop = &$EX['opcodes'][$op2['opline_num']]; |
|---|
| 1327 | if ($opc == XC_JMPNZ_EX) { |
|---|
| 1328 | $targetop['cond_true'][] = toCode($rvalue, $EX); |
|---|
| 1329 | } |
|---|
| 1330 | else { |
|---|
| 1331 | $targetop['cond_false'][] = toCode($rvalue, $EX); |
|---|
| 1332 | } |
|---|
| 1333 | unset($targetop); |
|---|
| 1334 | } |
|---|
| 1335 | else { |
|---|
| 1336 | $op['cond'] = $rvalue; |
|---|
| 1337 | $op['isjmp'] = true; |
|---|
| 1338 | } |
|---|
| 1339 | break; |
|---|
| 1340 | // }}} |
|---|
| 1341 | case XC_JMP: // {{{ |
|---|
| 1342 | $op['cond'] = null; |
|---|
| 1343 | $op['isjmp'] = true; |
|---|
| 1344 | break; |
|---|
| 1345 | // }}} |
|---|
| 1346 | case XC_CASE: |
|---|
| 1347 | case XC_BRK: |
|---|
| 1348 | break; |
|---|
| 1349 | case XC_RECV_INIT: |
|---|
| 1350 | case XC_RECV: |
|---|
| 1351 | $offset = $this->getOpVal($op1, $EX); |
|---|
| 1352 | $lvalue = $this->getOpVal($op['result'], $EX); |
|---|
| 1353 | if ($opc == XC_RECV_INIT) { |
|---|
| 1354 | $default = value($op['op2']['constant']); |
|---|
| 1355 | } |
|---|
| 1356 | else { |
|---|
| 1357 | $default = null; |
|---|
| 1358 | } |
|---|
| 1359 | $EX['recvs'][$offset] = array($lvalue, $default); |
|---|
| 1360 | break; |
|---|
| 1361 | case XC_POST_DEC: |
|---|
| 1362 | case XC_POST_INC: |
|---|
| 1363 | case XC_POST_DEC_OBJ: |
|---|
| 1364 | case XC_POST_INC_OBJ: |
|---|
| 1365 | case XC_PRE_DEC: |
|---|
| 1366 | case XC_PRE_INC: |
|---|
| 1367 | case XC_PRE_DEC_OBJ: |
|---|
| 1368 | case XC_PRE_INC_OBJ: // {{{ |
|---|
| 1369 | $flags = array_flip(explode('_', $opname)); |
|---|
| 1370 | if (isset($flags['OBJ'])) { |
|---|
| 1371 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1372 | $prop = $this->unquoteName($this->getOpVal($op2, $EX)); |
|---|
| 1373 | if ($prop{0} == '$') { |
|---|
| 1374 | $resvar = $resvar . "{" . $prop . "}"; |
|---|
| 1375 | } |
|---|
| 1376 | else { |
|---|
| 1377 | $resvar = $resvar . "->" . $prop; |
|---|
| 1378 | } |
|---|
| 1379 | } |
|---|
| 1380 | else { |
|---|
| 1381 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1382 | } |
|---|
| 1383 | $opstr = isset($flags['DEC']) ? '--' : '++'; |
|---|
| 1384 | if (isset($flags['POST'])) { |
|---|
| 1385 | $resvar .= ' ' . $opstr; |
|---|
| 1386 | } |
|---|
| 1387 | else { |
|---|
| 1388 | $resvar = "$opstr $resvar"; |
|---|
| 1389 | } |
|---|
| 1390 | break; |
|---|
| 1391 | // }}} |
|---|
| 1392 | |
|---|
| 1393 | case XC_BEGIN_SILENCE: // {{{ |
|---|
| 1394 | $EX['silence'] ++; |
|---|
| 1395 | break; |
|---|
| 1396 | // }}} |
|---|
| 1397 | case XC_END_SILENCE: // {{{ |
|---|
| 1398 | $EX['silence'] --; |
|---|
| 1399 | $lastresvar = '@' . toCode($lastresvar, $EX); |
|---|
| 1400 | break; |
|---|
| 1401 | // }}} |
|---|
| 1402 | case XC_CONT: // {{{ |
|---|
| 1403 | break; |
|---|
| 1404 | // }}} |
|---|
| 1405 | case XC_CAST: // {{{ |
|---|
| 1406 | $type = $ext; |
|---|
| 1407 | static $type2cast = array( |
|---|
| 1408 | IS_LONG => '(int)', |
|---|
| 1409 | IS_DOUBLE => '(double)', |
|---|
| 1410 | IS_STRING => '(string)', |
|---|
| 1411 | IS_ARRAY => '(array)', |
|---|
| 1412 | IS_OBJECT => '(object)', |
|---|
| 1413 | IS_BOOL => '(bool)', |
|---|
| 1414 | IS_NULL => '(unset)', |
|---|
| 1415 | ); |
|---|
| 1416 | assert(isset($type2cast[$type])); |
|---|
| 1417 | $cast = $type2cast[$type]; |
|---|
| 1418 | $resvar = $cast . ' ' . $this->getOpVal($op1, $EX); |
|---|
| 1419 | break; |
|---|
| 1420 | // }}} |
|---|
| 1421 | case XC_EXT_STMT: |
|---|
| 1422 | case XC_EXT_FCALL_BEGIN: |
|---|
| 1423 | case XC_EXT_FCALL_END: |
|---|
| 1424 | case XC_EXT_NOP: |
|---|
| 1425 | break; |
|---|
| 1426 | case XC_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 1427 | /* always removed by compiler */ |
|---|
| 1428 | break; |
|---|
| 1429 | case XC_TICKS: |
|---|
| 1430 | $lastphpop['ticks'] = $this->getOpVal($op1, $EX); |
|---|
| 1431 | // $EX['tickschanged'] = true; |
|---|
| 1432 | break; |
|---|
| 1433 | default: // {{{ |
|---|
| 1434 | echo "\x1B[31m * TODO ", $opname, "\x1B[0m\n"; |
|---|
| 1435 | // }}} |
|---|
| 1436 | } |
|---|
| 1437 | } |
|---|
| 1438 | if (isset($resvar)) { |
|---|
| 1439 | if ($istmpres) { |
|---|
| 1440 | $T[$res['var']] = $resvar; |
|---|
| 1441 | $lastresvar = &$T[$res['var']]; |
|---|
| 1442 | } |
|---|
| 1443 | else { |
|---|
| 1444 | $op['php'] = $resvar; |
|---|
| 1445 | $lastphpop = &$op; |
|---|
| 1446 | $lastresvar = &$op['php']; |
|---|
| 1447 | } |
|---|
| 1448 | } |
|---|
| 1449 | } |
|---|
| 1450 | return $T; |
|---|
| 1451 | } |
|---|
| 1452 | // }}} |
|---|
| 1453 | function unquote($str, $st, $ed) // {{{ |
|---|
| 1454 | { |
|---|
| 1455 | $l1 = strlen($st); |
|---|
| 1456 | $l2 = strlen($ed); |
|---|
| 1457 | if (substr($str, 0, $l1) === $st && substr($str, -$l2) === $ed) { |
|---|
| 1458 | $str = substr($str, $l1, -$l2); |
|---|
| 1459 | } |
|---|
| 1460 | return $str; |
|---|
| 1461 | } |
|---|
| 1462 | // }}} |
|---|
| 1463 | function popargs(&$EX, $n) // {{{ |
|---|
| 1464 | { |
|---|
| 1465 | $args = array(); |
|---|
| 1466 | for ($i = 0; $i < $n; $i ++) { |
|---|
| 1467 | $a = array_pop($EX['argstack']); |
|---|
| 1468 | if (is_array($a)) { |
|---|
| 1469 | array_unshift($args, toCode($a, $EX)); |
|---|
| 1470 | } |
|---|
| 1471 | else { |
|---|
| 1472 | array_unshift($args, $a); |
|---|
| 1473 | } |
|---|
| 1474 | } |
|---|
| 1475 | return implode(', ', $args); |
|---|
| 1476 | } |
|---|
| 1477 | // }}} |
|---|
| 1478 | function dumpop($op, &$EX) // {{{ |
|---|
| 1479 | { |
|---|
| 1480 | $op1 = $op['op1']; |
|---|
| 1481 | $op2 = $op['op2']; |
|---|
| 1482 | $d = array('opname' => xcache_get_opcode($op['opcode']), 'opcode' => $op['opcode']); |
|---|
| 1483 | |
|---|
| 1484 | foreach (array('op1' => 'op1', 'op2' => 'op2', 'result' => 'res') as $k => $kk) { |
|---|
| 1485 | switch ($op[$k]['op_type']) { |
|---|
| 1486 | case XC_IS_UNUSED: |
|---|
| 1487 | $d[$kk] = '*UNUSED* ' . $op[$k]['opline_num']; |
|---|
| 1488 | break; |
|---|
| 1489 | |
|---|
| 1490 | case XC_IS_VAR: |
|---|
| 1491 | $d[$kk] = '$' . $op[$k]['var']; |
|---|
| 1492 | if ($kk != 'res') { |
|---|
| 1493 | $d[$kk] .= ':' . $this->getOpVal($op[$k], $EX); |
|---|
| 1494 | } |
|---|
| 1495 | break; |
|---|
| 1496 | |
|---|
| 1497 | case XC_IS_TMP_VAR: |
|---|
| 1498 | $d[$kk] = '#' . $op[$k]['var']; |
|---|
| 1499 | if ($kk != 'res') { |
|---|
| 1500 | $d[$kk] .= ':' . $this->getOpVal($op[$k], $EX); |
|---|
| 1501 | } |
|---|
| 1502 | break; |
|---|
| 1503 | |
|---|
| 1504 | case XC_IS_CV: |
|---|
| 1505 | $d[$kk] = $this->getOpVal($op[$k], $EX); |
|---|
| 1506 | break; |
|---|
| 1507 | |
|---|
| 1508 | default: |
|---|
| 1509 | if ($kk == 'res') { |
|---|
| 1510 | var_dump($op); |
|---|
| 1511 | exit; |
|---|
| 1512 | assert(0); |
|---|
| 1513 | } |
|---|
| 1514 | else { |
|---|
| 1515 | $d[$kk] = $this->getOpVal($op[$k], $EX); |
|---|
| 1516 | } |
|---|
| 1517 | } |
|---|
| 1518 | } |
|---|
| 1519 | $d['ext'] = $op['extended_value']; |
|---|
| 1520 | |
|---|
| 1521 | var_dump($d); |
|---|
| 1522 | } |
|---|
| 1523 | // }}} |
|---|
| 1524 | function dargs(&$EX, $indent) // {{{ |
|---|
| 1525 | { |
|---|
| 1526 | $op_array = &$EX['op_array']; |
|---|
| 1527 | |
|---|
| 1528 | if (isset($op_array['num_args'])) { |
|---|
| 1529 | $c = $op_array['num_args']; |
|---|
| 1530 | } |
|---|
| 1531 | else if ($op_array['arg_types']) { |
|---|
| 1532 | $c = count($op_array['arg_types']); |
|---|
| 1533 | } |
|---|
| 1534 | else { |
|---|
| 1535 | // php4 |
|---|
| 1536 | $c = count($EX['recvs']); |
|---|
| 1537 | } |
|---|
| 1538 | |
|---|
| 1539 | $refrest = false; |
|---|
| 1540 | for ($i = 0; $i < $c; $i ++) { |
|---|
| 1541 | if ($i) { |
|---|
| 1542 | echo ', '; |
|---|
| 1543 | } |
|---|
| 1544 | if (isset($op_array['arg_info'])) { |
|---|
| 1545 | $ai = $op_array['arg_info'][$i]; |
|---|
| 1546 | if (!empty($ai['class_name'])) { |
|---|
| 1547 | echo $ai['class_name'], ' '; |
|---|
| 1548 | if ($ai['allow_null']) { |
|---|
| 1549 | echo 'or NULL '; |
|---|
| 1550 | } |
|---|
| 1551 | } |
|---|
| 1552 | else if (!empty($ai['array_type_hint'])) { |
|---|
| 1553 | echo 'array '; |
|---|
| 1554 | if ($ai['allow_null']) { |
|---|
| 1555 | echo 'or NULL '; |
|---|
| 1556 | } |
|---|
| 1557 | } |
|---|
| 1558 | if ($ai['pass_by_reference']) { |
|---|
| 1559 | echo '&'; |
|---|
| 1560 | } |
|---|
| 1561 | printf("\$%s", $ai['name']); |
|---|
| 1562 | } |
|---|
| 1563 | else { |
|---|
| 1564 | if ($refrest) { |
|---|
| 1565 | echo '&'; |
|---|
| 1566 | } |
|---|
| 1567 | else if (isset($op_array['arg_types'][$i])) { |
|---|
| 1568 | switch ($op_array['arg_types'][$i]) { |
|---|
| 1569 | case BYREF_FORCE_REST: |
|---|
| 1570 | $refrest = true; |
|---|
| 1571 | /* fall */ |
|---|
| 1572 | case BYREF_FORCE: |
|---|
| 1573 | echo '&'; |
|---|
| 1574 | break; |
|---|
| 1575 | |
|---|
| 1576 | case BYREF_NONE: |
|---|
| 1577 | case BYREF_ALLOW: |
|---|
| 1578 | break; |
|---|
| 1579 | default: |
|---|
| 1580 | assert(0); |
|---|
| 1581 | } |
|---|
| 1582 | } |
|---|
| 1583 | $arg = $EX['recvs'][$i + 1]; |
|---|
| 1584 | echo toCode($arg[0], $indent); |
|---|
| 1585 | if (isset($arg[1])) { |
|---|
| 1586 | echo ' = ', toCode($arg[1], $indent); |
|---|
| 1587 | } |
|---|
| 1588 | } |
|---|
| 1589 | } |
|---|
| 1590 | } |
|---|
| 1591 | // }}} |
|---|
| 1592 | function dfunction($func, $indent = '', $nobody = false) // {{{ |
|---|
| 1593 | { |
|---|
| 1594 | if ($nobody) { |
|---|
| 1595 | $body = ";\n"; |
|---|
| 1596 | $EX = array(); |
|---|
| 1597 | $EX['op_array'] = &$func['op_array']; |
|---|
| 1598 | $EX['recvs'] = array(); |
|---|
| 1599 | } |
|---|
| 1600 | else { |
|---|
| 1601 | ob_start(); |
|---|
| 1602 | $newindent = INDENT . $indent; |
|---|
| 1603 | $EX = &$this->dop_array($func['op_array'], $newindent); |
|---|
| 1604 | $body = ob_get_clean(); |
|---|
| 1605 | if (!isset($EX['recvs'])) { |
|---|
| 1606 | $EX['recvs'] = array(); |
|---|
| 1607 | } |
|---|
| 1608 | } |
|---|
| 1609 | |
|---|
| 1610 | echo 'function ', $func['op_array']['function_name'], '('; |
|---|
| 1611 | $this->dargs($EX, $indent); |
|---|
| 1612 | echo ")\n"; |
|---|
| 1613 | echo $indent, "{\n"; |
|---|
| 1614 | echo $body; |
|---|
| 1615 | echo "$indent}\n"; |
|---|
| 1616 | } |
|---|
| 1617 | // }}} |
|---|
| 1618 | function dclass($class, $indent = '') // {{{ |
|---|
| 1619 | { |
|---|
| 1620 | // {{{ class decl |
|---|
| 1621 | if (!empty($class['doc_comment'])) { |
|---|
| 1622 | echo $indent; |
|---|
| 1623 | echo $class['doc_comment']; |
|---|
| 1624 | echo "\n"; |
|---|
| 1625 | } |
|---|
| 1626 | $isinterface = false; |
|---|
| 1627 | if (!empty($class['ce_flags'])) { |
|---|
| 1628 | if ($class['ce_flags'] & ZEND_ACC_INTERFACE) { |
|---|
| 1629 | echo 'interface '; |
|---|
| 1630 | $isinterface = true; |
|---|
| 1631 | } |
|---|
| 1632 | else { |
|---|
| 1633 | if ($class['ce_flags'] & ZEND_ACC_IMPLICIT_ABSTRACT) { |
|---|
| 1634 | echo "abstract "; |
|---|
| 1635 | } |
|---|
| 1636 | if ($class['ce_flags'] & ZEND_ACC_FINAL) { |
|---|
| 1637 | echo "final "; |
|---|
| 1638 | } |
|---|
| 1639 | } |
|---|
| 1640 | } |
|---|
| 1641 | echo 'class ', $class['name']; |
|---|
| 1642 | if ($class['parent']) { |
|---|
| 1643 | echo ' extends ', $class['parent']; |
|---|
| 1644 | } |
|---|
| 1645 | /* TODO */ |
|---|
| 1646 | if (!empty($class['interfaces'])) { |
|---|
| 1647 | echo ' implements '; |
|---|
| 1648 | echo implode(', ', $class['interfaces']); |
|---|
| 1649 | } |
|---|
| 1650 | echo "\n"; |
|---|
| 1651 | echo $indent, "{"; |
|---|
| 1652 | // }}} |
|---|
| 1653 | $newindent = INDENT . $indent; |
|---|
| 1654 | // {{{ const, static |
|---|
| 1655 | foreach (array('constants_table' => 'const ' |
|---|
| 1656 | , 'static_members' => 'static $') as $type => $prefix) { |
|---|
| 1657 | if (!empty($class[$type])) { |
|---|
| 1658 | echo "\n"; |
|---|
| 1659 | // TODO: skip shadow? |
|---|
| 1660 | foreach ($class[$type] as $name => $v) { |
|---|
| 1661 | echo $newindent; |
|---|
| 1662 | echo $prefix, $name, ' = '; |
|---|
| 1663 | echo toCode(value($v), $newindent); |
|---|
| 1664 | echo ";\n"; |
|---|
| 1665 | } |
|---|
| 1666 | } |
|---|
| 1667 | } |
|---|
| 1668 | // }}} |
|---|
| 1669 | // {{{ properties |
|---|
| 1670 | $member_variables = isset($class['properties_info']) ? $class['properties_info'] : ($class['default_static_members'] + $class['default_properties']); |
|---|
| 1671 | if ($member_variables) { |
|---|
| 1672 | echo "\n"; |
|---|
| 1673 | $infos = !empty($class['properties_info']) ? $class['properties_info'] : null; |
|---|
| 1674 | foreach ($member_variables as $name => $dummy) { |
|---|
| 1675 | $info = (isset($infos) && isset($infos[$name])) ? $infos[$name] : null; |
|---|
| 1676 | if (isset($info)) { |
|---|
| 1677 | if (!empty($info['doc_comment'])) { |
|---|
| 1678 | echo $newindent; |
|---|
| 1679 | echo $info['doc_comment']; |
|---|
| 1680 | echo "\n"; |
|---|
| 1681 | } |
|---|
| 1682 | } |
|---|
| 1683 | |
|---|
| 1684 | echo $newindent; |
|---|
| 1685 | $static = false; |
|---|
| 1686 | if (isset($info)) { |
|---|
| 1687 | if ($info['flags'] & ZEND_ACC_STATIC) { |
|---|
| 1688 | $static = true; |
|---|
| 1689 | } |
|---|
| 1690 | } |
|---|
| 1691 | else if (isset($class['default_static_members'][$name])) { |
|---|
| 1692 | $static = true; |
|---|
| 1693 | } |
|---|
| 1694 | |
|---|
| 1695 | if ($static) { |
|---|
| 1696 | echo "static "; |
|---|
| 1697 | } |
|---|
| 1698 | |
|---|
| 1699 | $mangled = false; |
|---|
| 1700 | if (!ZEND_ENGINE_2) { |
|---|
| 1701 | echo 'var '; |
|---|
| 1702 | } |
|---|
| 1703 | else if (!isset($info)) { |
|---|
| 1704 | echo 'public '; |
|---|
| 1705 | } |
|---|
| 1706 | else { |
|---|
| 1707 | if ($info['flags'] & ZEND_ACC_SHADOW) { |
|---|
| 1708 | continue; |
|---|
| 1709 | } |
|---|
| 1710 | switch ($info['flags'] & ZEND_ACC_PPP_MASK) { |
|---|
| 1711 | case ZEND_ACC_PUBLIC: |
|---|
| 1712 | echo "public "; |
|---|
| 1713 | break; |
|---|
| 1714 | case ZEND_ACC_PRIVATE: |
|---|
| 1715 | echo "private "; |
|---|
| 1716 | $mangled = true; |
|---|
| 1717 | break; |
|---|
| 1718 | case ZEND_ACC_PROTECTED: |
|---|
| 1719 | echo "protected "; |
|---|
| 1720 | $mangled = true; |
|---|
| 1721 | break; |
|---|
| 1722 | } |
|---|
| 1723 | } |
|---|
| 1724 | |
|---|
| 1725 | echo '$', $name; |
|---|
| 1726 | |
|---|
| 1727 | if (isset($info['offset'])) { |
|---|
| 1728 | $value = $class[$static ? 'default_static_members_table' : 'default_properties_table'][$info['offset']]; |
|---|
| 1729 | } |
|---|
| 1730 | else { |
|---|
| 1731 | $key = isset($info) ? $info['name'] . ($mangled ? "\000" : "") : $name; |
|---|
| 1732 | |
|---|
| 1733 | $value = $class[$static ? 'default_static_members' : 'default_properties'][$key]; |
|---|
| 1734 | } |
|---|
| 1735 | if (isset($value)) { |
|---|
| 1736 | echo ' = '; |
|---|
| 1737 | echo toCode(value($value), $newindent); |
|---|
| 1738 | } |
|---|
| 1739 | echo ";\n"; |
|---|
| 1740 | } |
|---|
| 1741 | } |
|---|
| 1742 | // }}} |
|---|
| 1743 | // {{{ function_table |
|---|
| 1744 | if (isset($class['function_table'])) { |
|---|
| 1745 | foreach ($class['function_table'] as $func) { |
|---|
| 1746 | if (!isset($func['scope']) || $func['scope'] == $class['name']) { |
|---|
| 1747 | // TODO: skip shadow here |
|---|
| 1748 | echo "\n"; |
|---|
| 1749 | $opa = $func['op_array']; |
|---|
| 1750 | if (!empty($opa['doc_comment'])) { |
|---|
| 1751 | echo $newindent; |
|---|
| 1752 | echo $opa['doc_comment']; |
|---|
| 1753 | echo "\n"; |
|---|
| 1754 | } |
|---|
| 1755 | echo $newindent; |
|---|
| 1756 | if (isset($opa['fn_flags'])) { |
|---|
| 1757 | if ($opa['fn_flags'] & ZEND_ACC_ABSTRACT) { |
|---|
| 1758 | echo "abstract "; |
|---|
| 1759 | } |
|---|
| 1760 | if ($opa['fn_flags'] & ZEND_ACC_FINAL) { |
|---|
| 1761 | echo "final "; |
|---|
| 1762 | } |
|---|
| 1763 | if ($opa['fn_flags'] & ZEND_ACC_STATIC) { |
|---|
| 1764 | echo "static "; |
|---|
| 1765 | } |
|---|
| 1766 | |
|---|
| 1767 | switch ($opa['fn_flags'] & ZEND_ACC_PPP_MASK) { |
|---|
| 1768 | case ZEND_ACC_PUBLIC: |
|---|
| 1769 | echo "public "; |
|---|
| 1770 | break; |
|---|
| 1771 | case ZEND_ACC_PRIVATE: |
|---|
| 1772 | echo "private "; |
|---|
| 1773 | break; |
|---|
| 1774 | case ZEND_ACC_PROTECTED: |
|---|
| 1775 | echo "protected "; |
|---|
| 1776 | break; |
|---|
| 1777 | default: |
|---|
| 1778 | echo "<visibility error> "; |
|---|
| 1779 | break; |
|---|
| 1780 | } |
|---|
| 1781 | } |
|---|
| 1782 | $this->dfunction($func, $newindent, $isinterface); |
|---|
| 1783 | if ($opa['function_name'] == 'Decompiler') { |
|---|
| 1784 | //exit; |
|---|
| 1785 | } |
|---|
| 1786 | } |
|---|
| 1787 | } |
|---|
| 1788 | } |
|---|
| 1789 | // }}} |
|---|
| 1790 | echo $indent, "}\n"; |
|---|
| 1791 | } |
|---|
| 1792 | // }}} |
|---|
| 1793 | function decompileString($string) // {{{ |
|---|
| 1794 | { |
|---|
| 1795 | $this->dc = xcache_dasm_string($string); |
|---|
| 1796 | if ($this->dc === false) { |
|---|
| 1797 | echo "error compling string\n"; |
|---|
| 1798 | return false; |
|---|
| 1799 | } |
|---|
| 1800 | } |
|---|
| 1801 | // }}} |
|---|
| 1802 | function decompileFile($file) // {{{ |
|---|
| 1803 | { |
|---|
| 1804 | $this->dc = xcache_dasm_file($file); |
|---|
| 1805 | if ($this->dc === false) { |
|---|
| 1806 | echo "error compling $file\n"; |
|---|
| 1807 | return false; |
|---|
| 1808 | } |
|---|
| 1809 | } |
|---|
| 1810 | // }}} |
|---|
| 1811 | function output() // {{{ |
|---|
| 1812 | { |
|---|
| 1813 | echo "<?". "php\n"; |
|---|
| 1814 | foreach ($this->dc['class_table'] as $key => $class) { |
|---|
| 1815 | if ($key{0} != "\0") { |
|---|
| 1816 | echo "\n"; |
|---|
| 1817 | $this->dclass($class); |
|---|
| 1818 | } |
|---|
| 1819 | } |
|---|
| 1820 | |
|---|
| 1821 | foreach ($this->dc['function_table'] as $key => $func) { |
|---|
| 1822 | if ($key{0} != "\0") { |
|---|
| 1823 | echo "\n"; |
|---|
| 1824 | $this->dfunction($func); |
|---|
| 1825 | } |
|---|
| 1826 | } |
|---|
| 1827 | |
|---|
| 1828 | echo "\n"; |
|---|
| 1829 | $this->dop_array($this->dc['op_array']); |
|---|
| 1830 | echo "\n?" . ">\n"; |
|---|
| 1831 | return true; |
|---|
| 1832 | } |
|---|
| 1833 | // }}} |
|---|
| 1834 | } |
|---|
| 1835 | |
|---|
| 1836 | // {{{ defines |
|---|
| 1837 | define('ZEND_ACC_STATIC', 0x01); |
|---|
| 1838 | define('ZEND_ACC_ABSTRACT', 0x02); |
|---|
| 1839 | define('ZEND_ACC_FINAL', 0x04); |
|---|
| 1840 | define('ZEND_ACC_IMPLEMENTED_ABSTRACT', 0x08); |
|---|
| 1841 | |
|---|
| 1842 | define('ZEND_ACC_IMPLICIT_ABSTRACT_CLASS', 0x10); |
|---|
| 1843 | define('ZEND_ACC_EXPLICIT_ABSTRACT_CLASS', 0x20); |
|---|
| 1844 | define('ZEND_ACC_FINAL_CLASS', 0x40); |
|---|
| 1845 | define('ZEND_ACC_INTERFACE', 0x80); |
|---|
| 1846 | define('ZEND_ACC_PUBLIC', 0x100); |
|---|
| 1847 | define('ZEND_ACC_PROTECTED', 0x200); |
|---|
| 1848 | define('ZEND_ACC_PRIVATE', 0x400); |
|---|
| 1849 | define('ZEND_ACC_PPP_MASK', (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)); |
|---|
| 1850 | |
|---|
| 1851 | define('ZEND_ACC_CHANGED', 0x800); |
|---|
| 1852 | define('ZEND_ACC_IMPLICIT_PUBLIC', 0x1000); |
|---|
| 1853 | |
|---|
| 1854 | define('ZEND_ACC_CTOR', 0x2000); |
|---|
| 1855 | define('ZEND_ACC_DTOR', 0x4000); |
|---|
| 1856 | define('ZEND_ACC_CLONE', 0x8000); |
|---|
| 1857 | |
|---|
| 1858 | define('ZEND_ACC_ALLOW_STATIC', 0x10000); |
|---|
| 1859 | |
|---|
| 1860 | define('ZEND_ACC_SHADOW', 0x2000); |
|---|
| 1861 | |
|---|
| 1862 | define('ZEND_ENGINE_2_4', PHP_VERSION >= "5.3.99"); |
|---|
| 1863 | define('ZEND_ENGINE_2_3', ZEND_ENGINE_2_4 || PHP_VERSION >= "5.3."); |
|---|
| 1864 | define('ZEND_ENGINE_2_2', ZEND_ENGINE_2_3 || PHP_VERSION >= "5.2."); |
|---|
| 1865 | define('ZEND_ENGINE_2_1', ZEND_ENGINE_2_2 || PHP_VERSION >= "5.1."); |
|---|
| 1866 | define('ZEND_ENGINE_2', ZEND_ENGINE_2_1 || PHP_VERSION >= "5.0."); |
|---|
| 1867 | |
|---|
| 1868 | if (ZEND_ENGINE_2_4) { |
|---|
| 1869 | define('ZEND_FETCH_GLOBAL', 0x00000000); |
|---|
| 1870 | define('ZEND_FETCH_LOCAL', 0x10000000); |
|---|
| 1871 | define('ZEND_FETCH_STATIC', 0x20000000); |
|---|
| 1872 | define('ZEND_FETCH_STATIC_MEMBER', 0x30000000); |
|---|
| 1873 | define('ZEND_FETCH_GLOBAL_LOCK', 0x40000000); |
|---|
| 1874 | define('ZEND_FETCH_LEXICAL', 0x50000000); |
|---|
| 1875 | |
|---|
| 1876 | define('ZEND_FETCH_TYPE_MASK', 0x70000000); |
|---|
| 1877 | } |
|---|
| 1878 | else { |
|---|
| 1879 | define('ZEND_FETCH_GLOBAL', 0); |
|---|
| 1880 | define('ZEND_FETCH_LOCAL', 1); |
|---|
| 1881 | define('ZEND_FETCH_STATIC', 2); |
|---|
| 1882 | define('ZEND_FETCH_STATIC_MEMBER', 3); |
|---|
| 1883 | define('ZEND_FETCH_GLOBAL_LOCK', 4); |
|---|
| 1884 | } |
|---|
| 1885 | |
|---|
| 1886 | define('ZEND_FETCH_CLASS_DEFAULT', 0); |
|---|
| 1887 | define('ZEND_FETCH_CLASS_SELF', 1); |
|---|
| 1888 | define('ZEND_FETCH_CLASS_PARENT', 2); |
|---|
| 1889 | define('ZEND_FETCH_CLASS_MAIN', 3); |
|---|
| 1890 | define('ZEND_FETCH_CLASS_GLOBAL', 4); |
|---|
| 1891 | define('ZEND_FETCH_CLASS_AUTO', 5); |
|---|
| 1892 | define('ZEND_FETCH_CLASS_INTERFACE', 6); |
|---|
| 1893 | define('ZEND_FETCH_CLASS_STATIC', 7); |
|---|
| 1894 | if (ZEND_ENGINE_2_4) { |
|---|
| 1895 | define('ZEND_FETCH_CLASS_TRAIT', 14); |
|---|
| 1896 | } |
|---|
| 1897 | if (ZEND_ENGINE_2_3) { |
|---|
| 1898 | define('ZEND_FETCH_CLASS_MASK', 0xF); |
|---|
| 1899 | } |
|---|
| 1900 | |
|---|
| 1901 | define('ZEND_EVAL', (1<<0)); |
|---|
| 1902 | define('ZEND_INCLUDE', (1<<1)); |
|---|
| 1903 | define('ZEND_INCLUDE_ONCE', (1<<2)); |
|---|
| 1904 | define('ZEND_REQUIRE', (1<<3)); |
|---|
| 1905 | define('ZEND_REQUIRE_ONCE', (1<<4)); |
|---|
| 1906 | |
|---|
| 1907 | define('ZEND_ISSET', (1<<0)); |
|---|
| 1908 | define('ZEND_ISEMPTY', (1<<1)); |
|---|
| 1909 | if (ZEND_ENGINE_2_4) { |
|---|
| 1910 | define('EXT_TYPE_UNUSED', (1<<5)); |
|---|
| 1911 | } |
|---|
| 1912 | else { |
|---|
| 1913 | define('EXT_TYPE_UNUSED', (1<<0)); |
|---|
| 1914 | } |
|---|
| 1915 | |
|---|
| 1916 | define('ZEND_FETCH_STANDARD', 0); |
|---|
| 1917 | define('ZEND_FETCH_ADD_LOCK', 1); |
|---|
| 1918 | |
|---|
| 1919 | define('ZEND_FE_FETCH_BYREF', 1); |
|---|
| 1920 | define('ZEND_FE_FETCH_WITH_KEY', 2); |
|---|
| 1921 | |
|---|
| 1922 | define('ZEND_MEMBER_FUNC_CALL', 1<<0); |
|---|
| 1923 | define('ZEND_CTOR_CALL', 1<<1); |
|---|
| 1924 | |
|---|
| 1925 | define('ZEND_ARG_SEND_BY_REF', (1<<0)); |
|---|
| 1926 | define('ZEND_ARG_COMPILE_TIME_BOUND', (1<<1)); |
|---|
| 1927 | define('ZEND_ARG_SEND_FUNCTION', (1<<2)); |
|---|
| 1928 | |
|---|
| 1929 | define('BYREF_NONE', 0); |
|---|
| 1930 | define('BYREF_FORCE', 1); |
|---|
| 1931 | define('BYREF_ALLOW', 2); |
|---|
| 1932 | define('BYREF_FORCE_REST', 3); |
|---|
| 1933 | define('IS_NULL', 0); |
|---|
| 1934 | define('IS_LONG', 1); |
|---|
| 1935 | define('IS_DOUBLE', 2); |
|---|
| 1936 | define('IS_STRING', 3); |
|---|
| 1937 | define('IS_ARRAY', 4); |
|---|
| 1938 | define('IS_OBJECT', 5); |
|---|
| 1939 | define('IS_BOOL', 6); |
|---|
| 1940 | define('IS_RESOURCE', 7); |
|---|
| 1941 | define('IS_CONSTANT', 8); |
|---|
| 1942 | define('IS_CONSTANT_ARRAY', 9); |
|---|
| 1943 | |
|---|
| 1944 | @define('XC_IS_CV', 16); |
|---|
| 1945 | |
|---|
| 1946 | /* |
|---|
| 1947 | if (preg_match_all('!XC_[A-Z_]+!', file_get_contents(__FILE__), $ms)) { |
|---|
| 1948 | $verdiff = array(); |
|---|
| 1949 | foreach ($ms[0] as $k) { |
|---|
| 1950 | if (!defined($k)) { |
|---|
| 1951 | $verdiff[$k] = -1; |
|---|
| 1952 | define($k, -1); |
|---|
| 1953 | } |
|---|
| 1954 | } |
|---|
| 1955 | var_export($verdiff); |
|---|
| 1956 | } |
|---|
| 1957 | /*/ |
|---|
| 1958 | foreach (array ( |
|---|
| 1959 | 'XC_HANDLE_EXCEPTION' => -1, |
|---|
| 1960 | 'XC_FETCH_CLASS' => -1, |
|---|
| 1961 | 'XC_FETCH_' => -1, |
|---|
| 1962 | 'XC_FETCH_DIM_' => -1, |
|---|
| 1963 | 'XC_ASSIGN_DIM' => -1, |
|---|
| 1964 | 'XC_UNSET_DIM' => -1, |
|---|
| 1965 | 'XC_FETCH_OBJ_' => -1, |
|---|
| 1966 | 'XC_ASSIGN_OBJ' => -1, |
|---|
| 1967 | 'XC_ISSET_ISEMPTY_DIM_OBJ' => -1, |
|---|
| 1968 | 'XC_ISSET_ISEMPTY_PROP_OBJ' => -1, |
|---|
| 1969 | 'XC_ISSET_ISEMPTY_VAR' => -1, |
|---|
| 1970 | 'XC_INIT_STATIC_METHOD_CALL' => -1, |
|---|
| 1971 | 'XC_INIT_METHOD_CALL' => -1, |
|---|
| 1972 | 'XC_VERIFY_ABSTRACT_CLASS' => -1, |
|---|
| 1973 | 'XC_DECLARE_CLASS' => -1, |
|---|
| 1974 | 'XC_DECLARE_INHERITED_CLASS' => -1, |
|---|
| 1975 | 'XC_DECLARE_INHERITED_CLASS_DELAYED' => -1, |
|---|
| 1976 | 'XC_ADD_INTERFACE' => -1, |
|---|
| 1977 | 'XC_POST_DEC_OBJ' => -1, |
|---|
| 1978 | 'XC_POST_INC_OBJ' => -1, |
|---|
| 1979 | 'XC_PRE_DEC_OBJ' => -1, |
|---|
| 1980 | 'XC_PRE_INC_OBJ' => -1, |
|---|
| 1981 | 'XC_UNSET_OBJ' => -1, |
|---|
| 1982 | 'XC_JMP_NO_CTOR' => -1, |
|---|
| 1983 | 'XC_FETCH_' => -1, |
|---|
| 1984 | 'XC_FETCH_DIM_' => -1, |
|---|
| 1985 | 'XC_UNSET_DIM_OBJ' => -1, |
|---|
| 1986 | 'XC_FETCH_OBJ_' => -1, |
|---|
| 1987 | 'XC_ISSET_ISEMPTY' => -1, |
|---|
| 1988 | 'XC_INIT_FCALL_BY_FUNC' => -1, |
|---|
| 1989 | 'XC_DO_FCALL_BY_FUNC' => -1, |
|---|
| 1990 | 'XC_DECLARE_FUNCTION_OR_CLASS' => -1, |
|---|
| 1991 | ) as $k => $v) { |
|---|
| 1992 | if (!defined($k)) { |
|---|
| 1993 | define($k, $v); |
|---|
| 1994 | } |
|---|
| 1995 | } |
|---|
| 1996 | |
|---|
| 1997 | /* XC_UNDEF XC_OP_DATA |
|---|
| 1998 | $content = file_get_contents(__FILE__); |
|---|
| 1999 | for ($i = 0; $opname = xcache_get_opcode($i); $i ++) { |
|---|
| 2000 | if (!preg_match("/\\bXC_" . $opname . "\\b(?!')/", $content)) { |
|---|
| 2001 | echo "not done ", $opname, "\n"; |
|---|
| 2002 | } |
|---|
| 2003 | } |
|---|
| 2004 | // */ |
|---|
| 2005 | // }}} |
|---|
| 2006 | |
|---|