| 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 str($code, $indent = '') // {{{ |
|---|
| 12 | { |
|---|
| 13 | if (is_array($code)) { |
|---|
| 14 | $array = array(); |
|---|
| 15 | foreach ($code as $key => $value) { |
|---|
| 16 | $array[$key] = str($value, $indent); |
|---|
| 17 | } |
|---|
| 18 | return $array; |
|---|
| 19 | } |
|---|
| 20 | if (is_object($code)) { |
|---|
| 21 | $code = foldToCode($code, $indent); |
|---|
| 22 | return $code->toCode($indent); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | return (string) $code; |
|---|
| 26 | } |
|---|
| 27 | // }}} |
|---|
| 28 | function foldToCode($src, $indent = '') // {{{ wrap or rewrap anything to Decompiler_Code |
|---|
| 29 | { |
|---|
| 30 | if (is_array($indent)) { |
|---|
| 31 | $indent = $indent['indent']; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | if (!is_object($src)) { |
|---|
| 35 | return new Decompiler_Code($src); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | if (!method_exists($src, 'toCode')) { |
|---|
| 39 | var_dump($src); |
|---|
| 40 | exit('no toCode'); |
|---|
| 41 | } |
|---|
| 42 | if (get_class($src) != 'Decompiler_Code') { |
|---|
| 43 | // rewrap it |
|---|
| 44 | $src = new Decompiler_Code($src->toCode($indent)); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | return $src; |
|---|
| 48 | } |
|---|
| 49 | // }}} |
|---|
| 50 | function value($value) // {{{ |
|---|
| 51 | { |
|---|
| 52 | $spec = xcache_get_special_value($value); |
|---|
| 53 | if (isset($spec)) { |
|---|
| 54 | $value = $spec; |
|---|
| 55 | if (!is_array($value)) { |
|---|
| 56 | // constant |
|---|
| 57 | return $value; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if (is_a($value, 'Decompiler_Object')) { |
|---|
| 62 | // use as is |
|---|
| 63 | } |
|---|
| 64 | else if (is_array($value)) { |
|---|
| 65 | $value = new Decompiler_ConstArray($value); |
|---|
| 66 | } |
|---|
| 67 | else { |
|---|
| 68 | $value = new Decompiler_Value($value); |
|---|
| 69 | } |
|---|
| 70 | return $value; |
|---|
| 71 | } |
|---|
| 72 | // }}} |
|---|
| 73 | function unquoteName_($str, $asVariableName, $indent = '') // {{{ |
|---|
| 74 | { |
|---|
| 75 | $str = str($str, $indent); |
|---|
| 76 | if (preg_match("!^'[\\w_][\\w\\d_\\\\]*'\$!", $str)) { |
|---|
| 77 | return str_replace('\\\\', '\\', substr($str, 1, -1)); |
|---|
| 78 | } |
|---|
| 79 | else if ($asVariableName) { |
|---|
| 80 | return "{" . $str . "}"; |
|---|
| 81 | } |
|---|
| 82 | else { |
|---|
| 83 | return $str; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | // }}} |
|---|
| 87 | function unquoteVariableName($str, $indent = '') // {{{ |
|---|
| 88 | { |
|---|
| 89 | return unquoteName_($str, true, $indent); |
|---|
| 90 | } |
|---|
| 91 | // }}} |
|---|
| 92 | function unquoteName($str, $indent = '') // {{{ |
|---|
| 93 | { |
|---|
| 94 | return unquoteName_($str, false, $indent); |
|---|
| 95 | } |
|---|
| 96 | // }}} |
|---|
| 97 | class Decompiler_Object // {{{ |
|---|
| 98 | { |
|---|
| 99 | } |
|---|
| 100 | // }}} |
|---|
| 101 | class Decompiler_Value extends Decompiler_Object // {{{ |
|---|
| 102 | { |
|---|
| 103 | var $value; |
|---|
| 104 | |
|---|
| 105 | function Decompiler_Value($value = null) |
|---|
| 106 | { |
|---|
| 107 | $this->value = $value; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | function toCode($indent) |
|---|
| 111 | { |
|---|
| 112 | $code = var_export($this->value, true); |
|---|
| 113 | if (gettype($this->value) == 'string') { |
|---|
| 114 | switch ($this->value) { |
|---|
| 115 | case "\r": |
|---|
| 116 | return '"\\r"'; |
|---|
| 117 | case "\n": |
|---|
| 118 | return '"\\n"'; |
|---|
| 119 | case "\r\n": |
|---|
| 120 | return '"\\r\\n"'; |
|---|
| 121 | } |
|---|
| 122 | $code = str_replace("\r\n", '\' . "\\r\\n" . \'', $code); |
|---|
| 123 | $code = str_replace("\r", '\' . "\\r" . \'', $code); |
|---|
| 124 | $code = str_replace("\n", '\' . "\\n" . \'', $code); |
|---|
| 125 | } |
|---|
| 126 | return $code; |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | // }}} |
|---|
| 130 | class Decompiler_Code extends Decompiler_Object // {{{ |
|---|
| 131 | { |
|---|
| 132 | var $src; |
|---|
| 133 | |
|---|
| 134 | function Decompiler_Code($src) |
|---|
| 135 | { |
|---|
| 136 | assert('isset($src)'); |
|---|
| 137 | $this->src = $src; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | function toCode($indent) |
|---|
| 141 | { |
|---|
| 142 | return $this->src; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | // }}} |
|---|
| 146 | class Decompiler_Binop extends Decompiler_Code // {{{ |
|---|
| 147 | { |
|---|
| 148 | var $opc; |
|---|
| 149 | var $op1; |
|---|
| 150 | var $op2; |
|---|
| 151 | var $parent; |
|---|
| 152 | |
|---|
| 153 | function Decompiler_Binop($parent, $op1, $opc, $op2) |
|---|
| 154 | { |
|---|
| 155 | $this->parent = &$parent; |
|---|
| 156 | $this->opc = $opc; |
|---|
| 157 | $this->op1 = $op1; |
|---|
| 158 | $this->op2 = $op2; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | function toCode($indent) |
|---|
| 162 | { |
|---|
| 163 | $opstr = $this->parent->binops[$this->opc]; |
|---|
| 164 | |
|---|
| 165 | if (is_a($this->op1, 'Decompiler_TriOp') || is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) { |
|---|
| 166 | $op1 = "(" . str($this->op1, $indent) . ")"; |
|---|
| 167 | } |
|---|
| 168 | else { |
|---|
| 169 | $op1 = $this->op1; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | if (is_a($this->op2, 'Decompiler_TriOp') || is_a($this->op2, 'Decompiler_Binop') && $this->op2->opc != $this->opc && substr($opstr, -1) != '=') { |
|---|
| 173 | $op2 = "(" . str($this->op2, $indent) . ")"; |
|---|
| 174 | } |
|---|
| 175 | else { |
|---|
| 176 | $op2 = $this->op2; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | if (str($op1) == '0' && ($this->opc == XC_ADD || $this->opc == XC_SUB)) { |
|---|
| 180 | return $opstr . str($op2, $indent); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | return str($op1, $indent) . ' ' . $opstr . ($this->opc == XC_ASSIGN_REF ? '' : ' ') . str($op2, $indent); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | // }}} |
|---|
| 187 | class Decompiler_TriOp extends Decompiler_Code // {{{ |
|---|
| 188 | { |
|---|
| 189 | var $condition; |
|---|
| 190 | var $trueValue; |
|---|
| 191 | var $falseValue; |
|---|
| 192 | |
|---|
| 193 | function Decompiler_TriOp($condition, $trueValue, $falseValue) |
|---|
| 194 | { |
|---|
| 195 | $this->condition = $condition; |
|---|
| 196 | $this->trueValue = $trueValue; |
|---|
| 197 | $this->falseValue = $falseValue; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | function toCode($indent) |
|---|
| 201 | { |
|---|
| 202 | $trueValue = $this->trueValue; |
|---|
| 203 | if (is_a($this->trueValue, 'Decompiler_TriOp')) { |
|---|
| 204 | $trueValue = "(" . str($trueValue, $indent) . ")"; |
|---|
| 205 | } |
|---|
| 206 | $falseValue = $this->falseValue; |
|---|
| 207 | if (is_a($this->falseValue, 'Decompiler_TriOp')) { |
|---|
| 208 | $falseValue = "(" . str($falseValue, $indent) . ")"; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | return str($this->condition) . ' ? ' . str($trueValue) . ' : ' . str($falseValue); |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | // }}} |
|---|
| 215 | class Decompiler_Fetch extends Decompiler_Code // {{{ |
|---|
| 216 | { |
|---|
| 217 | var $src; |
|---|
| 218 | var $fetchType; |
|---|
| 219 | |
|---|
| 220 | function Decompiler_Fetch($src, $type, $globalsrc) |
|---|
| 221 | { |
|---|
| 222 | $this->src = $src; |
|---|
| 223 | $this->fetchType = $type; |
|---|
| 224 | $this->globalsrc = $globalsrc; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | function toCode($indent) |
|---|
| 228 | { |
|---|
| 229 | switch ($this->fetchType) { |
|---|
| 230 | case ZEND_FETCH_LOCAL: |
|---|
| 231 | return '$' . substr($this->src, 1, -1); |
|---|
| 232 | case ZEND_FETCH_STATIC: |
|---|
| 233 | if (ZEND_ENGINE_2_3) { |
|---|
| 234 | // closure local variable? |
|---|
| 235 | return str($this->src); |
|---|
| 236 | } |
|---|
| 237 | die('static fetch cant to string'); |
|---|
| 238 | case ZEND_FETCH_GLOBAL: |
|---|
| 239 | case ZEND_FETCH_GLOBAL_LOCK: |
|---|
| 240 | return $this->globalsrc; |
|---|
| 241 | default: |
|---|
| 242 | var_dump($this->fetchType); |
|---|
| 243 | assert(0); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | // }}} |
|---|
| 248 | class Decompiler_Box // {{{ |
|---|
| 249 | { |
|---|
| 250 | var $obj; |
|---|
| 251 | |
|---|
| 252 | function Decompiler_Box(&$obj) |
|---|
| 253 | { |
|---|
| 254 | $this->obj = &$obj; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | function toCode($indent) |
|---|
| 258 | { |
|---|
| 259 | return $this->obj->toCode($indent); |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | // }}} |
|---|
| 263 | class Decompiler_Dim extends Decompiler_Value // {{{ |
|---|
| 264 | { |
|---|
| 265 | var $offsets = array(); |
|---|
| 266 | var $isLast = false; |
|---|
| 267 | var $isObject = false; |
|---|
| 268 | var $assign = null; |
|---|
| 269 | |
|---|
| 270 | function toCode($indent) |
|---|
| 271 | { |
|---|
| 272 | if (is_a($this->value, 'Decompiler_ListBox')) { |
|---|
| 273 | $exp = str($this->value->obj->src, $indent); |
|---|
| 274 | } |
|---|
| 275 | else { |
|---|
| 276 | $exp = str($this->value, $indent); |
|---|
| 277 | } |
|---|
| 278 | $last = count($this->offsets) - 1; |
|---|
| 279 | foreach ($this->offsets as $i => $dim) { |
|---|
| 280 | if ($this->isObject && $i == $last) { |
|---|
| 281 | $exp .= '->' . unquoteVariableName($dim, $indent); |
|---|
| 282 | } |
|---|
| 283 | else { |
|---|
| 284 | $exp .= '[' . str($dim, $indent) . ']'; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | return $exp; |
|---|
| 288 | } |
|---|
| 289 | } |
|---|
| 290 | // }}} |
|---|
| 291 | class Decompiler_DimBox extends Decompiler_Box // {{{ |
|---|
| 292 | { |
|---|
| 293 | } |
|---|
| 294 | // }}} |
|---|
| 295 | class Decompiler_List extends Decompiler_Code // {{{ |
|---|
| 296 | { |
|---|
| 297 | var $src; |
|---|
| 298 | var $dims = array(); |
|---|
| 299 | var $everLocked = false; |
|---|
| 300 | |
|---|
| 301 | function toCode($indent) |
|---|
| 302 | { |
|---|
| 303 | if (count($this->dims) == 1 && !$this->everLocked) { |
|---|
| 304 | $dim = $this->dims[0]; |
|---|
| 305 | unset($dim->value); |
|---|
| 306 | $dim->value = $this->src; |
|---|
| 307 | if (!isset($dim->assign)) { |
|---|
| 308 | return str($dim, $indent); |
|---|
| 309 | } |
|---|
| 310 | return str($this->dims[0]->assign, $indent) . ' = ' . str($dim, $indent); |
|---|
| 311 | } |
|---|
| 312 | /* flatten dims */ |
|---|
| 313 | $assigns = array(); |
|---|
| 314 | foreach ($this->dims as $dim) { |
|---|
| 315 | $assign = &$assigns; |
|---|
| 316 | foreach ($dim->offsets as $offset) { |
|---|
| 317 | $assign = &$assign[$offset]; |
|---|
| 318 | } |
|---|
| 319 | $assign = foldToCode($dim->assign, $indent); |
|---|
| 320 | } |
|---|
| 321 | return str($this->toList($assigns)) . ' = ' . str($this->src, $indent); |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | function toList($assigns) |
|---|
| 325 | { |
|---|
| 326 | $keys = array_keys($assigns); |
|---|
| 327 | if (count($keys) < 2) { |
|---|
| 328 | $keys[] = 0; |
|---|
| 329 | } |
|---|
| 330 | $max = call_user_func_array('max', $keys); |
|---|
| 331 | $list = 'list('; |
|---|
| 332 | for ($i = 0; $i <= $max; $i ++) { |
|---|
| 333 | if ($i) { |
|---|
| 334 | $list .= ', '; |
|---|
| 335 | } |
|---|
| 336 | if (!isset($assigns[$i])) { |
|---|
| 337 | continue; |
|---|
| 338 | } |
|---|
| 339 | if (is_array($assigns[$i])) { |
|---|
| 340 | $list .= $this->toList($assigns[$i]); |
|---|
| 341 | } |
|---|
| 342 | else { |
|---|
| 343 | $list .= $assigns[$i]; |
|---|
| 344 | } |
|---|
| 345 | } |
|---|
| 346 | return $list . ')'; |
|---|
| 347 | } |
|---|
| 348 | } |
|---|
| 349 | // }}} |
|---|
| 350 | class Decompiler_ListBox extends Decompiler_Box // {{{ |
|---|
| 351 | { |
|---|
| 352 | } |
|---|
| 353 | // }}} |
|---|
| 354 | class Decompiler_Array extends Decompiler_Value // {{{ |
|---|
| 355 | { |
|---|
| 356 | // emenets |
|---|
| 357 | function Decompiler_Array() |
|---|
| 358 | { |
|---|
| 359 | $this->value = array(); |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | function toCode($indent) |
|---|
| 363 | { |
|---|
| 364 | $subindent = $indent . INDENT; |
|---|
| 365 | |
|---|
| 366 | $elementsCode = array(); |
|---|
| 367 | $index = 0; |
|---|
| 368 | foreach ($this->value as $element) { |
|---|
| 369 | list($key, $value) = $element; |
|---|
| 370 | if (!isset($key)) { |
|---|
| 371 | $key = $index++; |
|---|
| 372 | } |
|---|
| 373 | $elementsCode[] = array(str($key, $subindent), str($value, $subindent), $key, $value); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | $exp = "array("; |
|---|
| 377 | $indent = $indent . INDENT; |
|---|
| 378 | $assocWidth = 0; |
|---|
| 379 | $multiline = 0; |
|---|
| 380 | $i = 0; |
|---|
| 381 | foreach ($elementsCode as $element) { |
|---|
| 382 | list($keyCode, $valueCode) = $element; |
|---|
| 383 | if ((string) $i !== $keyCode) { |
|---|
| 384 | $assocWidth = 1; |
|---|
| 385 | break; |
|---|
| 386 | } |
|---|
| 387 | ++$i; |
|---|
| 388 | } |
|---|
| 389 | foreach ($elementsCode as $element) { |
|---|
| 390 | list($keyCode, $valueCode, $key, $value) = $element; |
|---|
| 391 | if ($assocWidth) { |
|---|
| 392 | $len = strlen($keyCode); |
|---|
| 393 | if ($assocWidth < $len) { |
|---|
| 394 | $assocWidth = $len; |
|---|
| 395 | } |
|---|
| 396 | } |
|---|
| 397 | if (is_array($value) || is_a($value, 'Decompiler_Array')) { |
|---|
| 398 | $multiline ++; |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | $i = 0; |
|---|
| 403 | foreach ($elementsCode as $element) { |
|---|
| 404 | list($keyCode, $value) = $element; |
|---|
| 405 | if ($multiline) { |
|---|
| 406 | if ($i) { |
|---|
| 407 | $exp .= ","; |
|---|
| 408 | } |
|---|
| 409 | $exp .= "\n"; |
|---|
| 410 | $exp .= $indent; |
|---|
| 411 | } |
|---|
| 412 | else { |
|---|
| 413 | if ($i) { |
|---|
| 414 | $exp .= ", "; |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | if ($assocWidth) { |
|---|
| 419 | if ($multiline) { |
|---|
| 420 | $exp .= sprintf("%-{$assocWidth}s => ", $keyCode); |
|---|
| 421 | } |
|---|
| 422 | else { |
|---|
| 423 | $exp .= $keyCode . ' => '; |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | $exp .= $value; |
|---|
| 428 | |
|---|
| 429 | $i ++; |
|---|
| 430 | } |
|---|
| 431 | if ($multiline) { |
|---|
| 432 | $exp .= "\n$indent)"; |
|---|
| 433 | } |
|---|
| 434 | else { |
|---|
| 435 | $exp .= ")"; |
|---|
| 436 | } |
|---|
| 437 | return $exp; |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | // }}} |
|---|
| 441 | class Decompiler_ConstArray extends Decompiler_Array // {{{ |
|---|
| 442 | { |
|---|
| 443 | function Decompiler_ConstArray($array) |
|---|
| 444 | { |
|---|
| 445 | $elements = array(); |
|---|
| 446 | foreach ($array as $key => $value) { |
|---|
| 447 | $elements[] = array(value($key), value($value)); |
|---|
| 448 | } |
|---|
| 449 | $this->value = $elements; |
|---|
| 450 | } |
|---|
| 451 | } |
|---|
| 452 | // }}} |
|---|
| 453 | class Decompiler_ForeachBox extends Decompiler_Box // {{{ |
|---|
| 454 | { |
|---|
| 455 | var $iskey; |
|---|
| 456 | |
|---|
| 457 | function toCode($indent) |
|---|
| 458 | { |
|---|
| 459 | return 'foreach (' . ''; |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | // }}} |
|---|
| 463 | |
|---|
| 464 | class Decompiler |
|---|
| 465 | { |
|---|
| 466 | var $namespace; |
|---|
| 467 | var $namespaceDecided; |
|---|
| 468 | |
|---|
| 469 | function Decompiler() |
|---|
| 470 | { |
|---|
| 471 | // {{{ testing |
|---|
| 472 | // XC_UNDEF XC_OP_DATA |
|---|
| 473 | $this->test = !empty($_ENV['XCACHE_DECOMPILER_TEST']); |
|---|
| 474 | $this->usedOps = array(); |
|---|
| 475 | |
|---|
| 476 | if ($this->test) { |
|---|
| 477 | $content = file_get_contents(__FILE__); |
|---|
| 478 | for ($i = 0; $opname = xcache_get_opcode($i); $i ++) { |
|---|
| 479 | if (!preg_match("/\\bXC_" . $opname . "\\b(?!')/", $content)) { |
|---|
| 480 | echo "not recognized opcode ", $opname, "\n"; |
|---|
| 481 | } |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | // }}} |
|---|
| 485 | // {{{ opinfo |
|---|
| 486 | $this->unaryops = array( |
|---|
| 487 | XC_BW_NOT => '~', |
|---|
| 488 | XC_BOOL_NOT => '!', |
|---|
| 489 | ); |
|---|
| 490 | $this->binops = array( |
|---|
| 491 | XC_ADD => "+", |
|---|
| 492 | XC_ASSIGN_ADD => "+=", |
|---|
| 493 | XC_SUB => "-", |
|---|
| 494 | XC_ASSIGN_SUB => "-=", |
|---|
| 495 | XC_MUL => "*", |
|---|
| 496 | XC_ASSIGN_MUL => "*=", |
|---|
| 497 | XC_DIV => "/", |
|---|
| 498 | XC_ASSIGN_DIV => "/=", |
|---|
| 499 | XC_MOD => "%", |
|---|
| 500 | XC_ASSIGN_MOD => "%=", |
|---|
| 501 | XC_SL => "<<", |
|---|
| 502 | XC_ASSIGN_SL => "<<=", |
|---|
| 503 | XC_SR => ">>", |
|---|
| 504 | XC_ASSIGN_SR => ">>=", |
|---|
| 505 | XC_CONCAT => ".", |
|---|
| 506 | XC_ASSIGN_CONCAT => ".=", |
|---|
| 507 | XC_IS_IDENTICAL => "===", |
|---|
| 508 | XC_IS_NOT_IDENTICAL => "!==", |
|---|
| 509 | XC_IS_EQUAL => "==", |
|---|
| 510 | XC_IS_NOT_EQUAL => "!=", |
|---|
| 511 | XC_IS_SMALLER => "<", |
|---|
| 512 | XC_IS_SMALLER_OR_EQUAL => "<=", |
|---|
| 513 | XC_BW_OR => "|", |
|---|
| 514 | XC_ASSIGN_BW_OR => "|=", |
|---|
| 515 | XC_BW_AND => "&", |
|---|
| 516 | XC_ASSIGN_BW_AND => "&=", |
|---|
| 517 | XC_BW_XOR => "^", |
|---|
| 518 | XC_ASSIGN_BW_XOR => "^=", |
|---|
| 519 | XC_BOOL_XOR => "xor", |
|---|
| 520 | XC_ASSIGN => "=", |
|---|
| 521 | XC_ASSIGN_REF => "= &", |
|---|
| 522 | XC_JMP_SET => "?:", |
|---|
| 523 | XC_JMPZ_EX => "&&", |
|---|
| 524 | XC_JMPNZ_EX => "||", |
|---|
| 525 | ); |
|---|
| 526 | // }}} |
|---|
| 527 | $this->includeTypes = array( // {{{ |
|---|
| 528 | ZEND_EVAL => 'eval', |
|---|
| 529 | ZEND_INCLUDE => 'include', |
|---|
| 530 | ZEND_INCLUDE_ONCE => 'include_once', |
|---|
| 531 | ZEND_REQUIRE => 'require', |
|---|
| 532 | ZEND_REQUIRE_ONCE => 'require_once', |
|---|
| 533 | ); |
|---|
| 534 | // }}} |
|---|
| 535 | } |
|---|
| 536 | function detectNamespace($name) // {{{ |
|---|
| 537 | { |
|---|
| 538 | if ($this->namespaceDecided) { |
|---|
| 539 | return; |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | if (strpos($name, '\\') !== false) { |
|---|
| 543 | $this->namespace = strtok($name, '\\'); |
|---|
| 544 | echo 'namespace ', $this->namespace, ";\n\n"; |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | $this->namespaceDecided = true; |
|---|
| 548 | } |
|---|
| 549 | // }}} |
|---|
| 550 | function stripNamespace($name) // {{{ |
|---|
| 551 | { |
|---|
| 552 | $len = strlen($this->namespace) + 1; |
|---|
| 553 | if (substr($name, 0, $len) == $this->namespace . '\\') { |
|---|
| 554 | return substr($name, $len); |
|---|
| 555 | } |
|---|
| 556 | else { |
|---|
| 557 | return $name; |
|---|
| 558 | } |
|---|
| 559 | } |
|---|
| 560 | // }}} |
|---|
| 561 | function outputPhp(&$EX, $range, $indent) // {{{ |
|---|
| 562 | { |
|---|
| 563 | $needBlankline = isset($EX['lastBlock']); |
|---|
| 564 | $origindent = $indent; |
|---|
| 565 | $curticks = 0; |
|---|
| 566 | for ($i = $range[0]; $i <= $range[1]; $i ++) { |
|---|
| 567 | $op = $EX['opcodes'][$i]; |
|---|
| 568 | if (isset($op['gofrom'])) { |
|---|
| 569 | if ($needBlankline) { |
|---|
| 570 | $needBlankline = false; |
|---|
| 571 | echo PHP_EOL; |
|---|
| 572 | } |
|---|
| 573 | echo 'label' . $i, ":\n"; |
|---|
| 574 | } |
|---|
| 575 | if (isset($op['php'])) { |
|---|
| 576 | $toticks = isset($op['ticks']) ? (int) str($op['ticks']) : 0; |
|---|
| 577 | if ($curticks != $toticks) { |
|---|
| 578 | $oldticks = $curticks; |
|---|
| 579 | $curticks = $toticks; |
|---|
| 580 | if (!$curticks) { |
|---|
| 581 | echo $origindent, "}\n\n"; |
|---|
| 582 | $indent = $origindent; |
|---|
| 583 | } |
|---|
| 584 | else { |
|---|
| 585 | if ($oldticks) { |
|---|
| 586 | echo $origindent, "}\n\n"; |
|---|
| 587 | } |
|---|
| 588 | else if (!$oldticks) { |
|---|
| 589 | $indent .= INDENT; |
|---|
| 590 | } |
|---|
| 591 | if ($needBlankline) { |
|---|
| 592 | $needBlankline = false; |
|---|
| 593 | echo PHP_EOL; |
|---|
| 594 | } |
|---|
| 595 | echo $origindent, "declare (ticks=$curticks) {\n"; |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | if ($needBlankline) { |
|---|
| 599 | $needBlankline = false; |
|---|
| 600 | echo PHP_EOL; |
|---|
| 601 | } |
|---|
| 602 | echo $indent, str($op['php'], $indent), ";\n"; |
|---|
| 603 | $EX['lastBlock'] = 'basic'; |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | if ($curticks) { |
|---|
| 607 | echo $origindent, "}\n"; |
|---|
| 608 | } |
|---|
| 609 | } |
|---|
| 610 | // }}} |
|---|
| 611 | function getOpVal($op, &$EX, $free = false) // {{{ |
|---|
| 612 | { |
|---|
| 613 | switch ($op['op_type']) { |
|---|
| 614 | case XC_IS_CONST: |
|---|
| 615 | return value($op['constant']); |
|---|
| 616 | |
|---|
| 617 | case XC_IS_VAR: |
|---|
| 618 | case XC_IS_TMP_VAR: |
|---|
| 619 | $T = &$EX['Ts']; |
|---|
| 620 | $ret = $T[$op['var']]; |
|---|
| 621 | if ($free && empty($this->keepTs)) { |
|---|
| 622 | unset($T[$op['var']]); |
|---|
| 623 | } |
|---|
| 624 | return $ret; |
|---|
| 625 | |
|---|
| 626 | case XC_IS_CV: |
|---|
| 627 | $var = $op['var']; |
|---|
| 628 | $var = $EX['op_array']['vars'][$var]; |
|---|
| 629 | return '$' . $var['name']; |
|---|
| 630 | |
|---|
| 631 | case XC_IS_UNUSED: |
|---|
| 632 | return null; |
|---|
| 633 | } |
|---|
| 634 | } |
|---|
| 635 | // }}} |
|---|
| 636 | function removeKeyPrefix($array, $prefix) // {{{ |
|---|
| 637 | { |
|---|
| 638 | $prefixLen = strlen($prefix); |
|---|
| 639 | $ret = array(); |
|---|
| 640 | foreach ($array as $key => $value) { |
|---|
| 641 | if (substr($key, 0, $prefixLen) == $prefix) { |
|---|
| 642 | $key = substr($key, $prefixLen); |
|---|
| 643 | } |
|---|
| 644 | $ret[$key] = $value; |
|---|
| 645 | } |
|---|
| 646 | return $ret; |
|---|
| 647 | } |
|---|
| 648 | // }}} |
|---|
| 649 | function &fixOpcode($opcodes, $removeTailing = false, $defaultReturnValue = null) // {{{ |
|---|
| 650 | { |
|---|
| 651 | $last = count($opcodes) - 1; |
|---|
| 652 | for ($i = 0; $i <= $last; $i ++) { |
|---|
| 653 | if (function_exists('xcache_get_fixed_opcode')) { |
|---|
| 654 | $opcodes[$i]['opcode'] = xcache_get_fixed_opcode($opcodes[$i]['opcode'], $i); |
|---|
| 655 | } |
|---|
| 656 | if (isset($opcodes[$i]['op1'])) { |
|---|
| 657 | $opcodes[$i]['op1'] = $this->removeKeyPrefix($opcodes[$i]['op1'], 'u.'); |
|---|
| 658 | $opcodes[$i]['op2'] = $this->removeKeyPrefix($opcodes[$i]['op2'], 'u.'); |
|---|
| 659 | $opcodes[$i]['result'] = $this->removeKeyPrefix($opcodes[$i]['result'], 'u.'); |
|---|
| 660 | } |
|---|
| 661 | else { |
|---|
| 662 | $op = array( |
|---|
| 663 | 'op1' => array(), |
|---|
| 664 | 'op2' => array(), |
|---|
| 665 | 'op3' => array(), |
|---|
| 666 | ); |
|---|
| 667 | foreach ($opcodes[$i] as $name => $value) { |
|---|
| 668 | if (preg_match('!^(op1|op2|result)\\.(.*)!', $name, $m)) { |
|---|
| 669 | list(, $which, $field) = $m; |
|---|
| 670 | $op[$which][$field] = $value; |
|---|
| 671 | } |
|---|
| 672 | else if (preg_match('!^(op1|op2|result)_type$!', $name, $m)) { |
|---|
| 673 | list(, $which) = $m; |
|---|
| 674 | $op[$which]['op_type'] = $value; |
|---|
| 675 | } |
|---|
| 676 | else { |
|---|
| 677 | $op[$name] = $value; |
|---|
| 678 | } |
|---|
| 679 | } |
|---|
| 680 | $opcodes[$i] = $op; |
|---|
| 681 | } |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | if ($removeTailing) { |
|---|
| 685 | $last = count($opcodes) - 1; |
|---|
| 686 | if ($opcodes[$last]['opcode'] == XC_HANDLE_EXCEPTION) { |
|---|
| 687 | $this->usedOps[XC_HANDLE_EXCEPTION] = true; |
|---|
| 688 | $opcodes[$last]['opcode'] = XC_NOP; |
|---|
| 689 | --$last; |
|---|
| 690 | } |
|---|
| 691 | if ($opcodes[$last]['opcode'] == XC_RETURN) { |
|---|
| 692 | $op1 = $opcodes[$last]['op1']; |
|---|
| 693 | if ($op1['op_type'] == XC_IS_CONST && array_key_exists('constant', $op1) && $op1['constant'] === $defaultReturnValue) { |
|---|
| 694 | $opcodes[$last]['opcode'] = XC_NOP; |
|---|
| 695 | --$last; |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | } |
|---|
| 699 | return $opcodes; |
|---|
| 700 | } |
|---|
| 701 | // }}} |
|---|
| 702 | function decompileBasicBlock(&$EX, $range, $indent, $unhandled = false) // {{{ |
|---|
| 703 | { |
|---|
| 704 | $this->dasmBasicBlock($EX, $range); |
|---|
| 705 | if ($unhandled) { |
|---|
| 706 | $this->dumpRange($EX, $range, $indent); |
|---|
| 707 | } |
|---|
| 708 | $this->outputPhp($EX, $range, $indent); |
|---|
| 709 | } |
|---|
| 710 | // }}} |
|---|
| 711 | function removeJmpInfo(&$EX, $line) // {{{ |
|---|
| 712 | { |
|---|
| 713 | $opcodes = &$EX['opcodes']; |
|---|
| 714 | foreach ($opcodes[$line]['jmpouts'] as $jmpTo) { |
|---|
| 715 | $jmpins = &$opcodes[$jmpTo]['jmpins']; |
|---|
| 716 | $jmpins = array_flip($jmpins); |
|---|
| 717 | unset($jmpins[$line]); |
|---|
| 718 | $jmpins = array_keys($jmpins); |
|---|
| 719 | } |
|---|
| 720 | // $opcodes[$line]['opcode'] = XC_NOP; |
|---|
| 721 | unset($opcodes[$line]['jmpouts']); |
|---|
| 722 | } |
|---|
| 723 | // }}} |
|---|
| 724 | function beginComplexBlock(&$EX) // {{{ |
|---|
| 725 | { |
|---|
| 726 | if (isset($EX['lastBlock'])) { |
|---|
| 727 | echo PHP_EOL; |
|---|
| 728 | $EX['lastBlock'] = null; |
|---|
| 729 | } |
|---|
| 730 | } |
|---|
| 731 | // }}} |
|---|
| 732 | function endComplexBlock(&$EX) // {{{ |
|---|
| 733 | { |
|---|
| 734 | $EX['lastBlock'] = 'complex'; |
|---|
| 735 | } |
|---|
| 736 | // }}} |
|---|
| 737 | function decompileComplexBlock(&$EX, $range, $indent) // {{{ |
|---|
| 738 | { |
|---|
| 739 | $T = &$EX['Ts']; |
|---|
| 740 | $opcodes = &$EX['opcodes']; |
|---|
| 741 | |
|---|
| 742 | $firstOp = &$opcodes[$range[0]]; |
|---|
| 743 | $lastOp = &$opcodes[$range[1]]; |
|---|
| 744 | |
|---|
| 745 | // {{{ && || and or |
|---|
| 746 | if (($firstOp['opcode'] == XC_JMPZ_EX || $firstOp['opcode'] == XC_JMPNZ_EX) && !empty($firstOp['jmpouts']) |
|---|
| 747 | && $firstOp['jmpouts'][0] == $range[1] + 1 |
|---|
| 748 | && $lastOp['opcode'] == XC_BOOL |
|---|
| 749 | && $firstOp['opcode']['result']['var'] == $lastOp['opcode']['result']['var'] |
|---|
| 750 | ) { |
|---|
| 751 | $this->removeJmpInfo($EX, $range[0]); |
|---|
| 752 | |
|---|
| 753 | $this->recognizeAndDecompileClosedBlocks($EX, array($range[0], $range[0]), $indent . INDENT); |
|---|
| 754 | $op1 = $this->getOpVal($firstOp['result'], $EX, true); |
|---|
| 755 | |
|---|
| 756 | $this->recognizeAndDecompileClosedBlocks($EX, array($range[0] + 1, $range[1]), $indent . INDENT); |
|---|
| 757 | $op2 = $this->getOpVal($lastOp['result'], $EX, true); |
|---|
| 758 | |
|---|
| 759 | $T[$firstOp['result']['var']] = new Decompiler_Binop($this, $op1, $firstOp['opcode'], $op2); |
|---|
| 760 | return false; |
|---|
| 761 | } |
|---|
| 762 | // }}} |
|---|
| 763 | // {{{ ?: excluding JMP_SET |
|---|
| 764 | if ($firstOp['opcode'] == XC_JMPZ && !empty($firstOp['jmpouts']) |
|---|
| 765 | && $range[1] >= $range[0] + 3 |
|---|
| 766 | && $opcodes[$firstOp['jmpouts'][0] - 2]['opcode'] == XC_QM_ASSIGN |
|---|
| 767 | && $opcodes[$firstOp['jmpouts'][0] - 1]['opcode'] == XC_JMP && $opcodes[$firstOp['jmpouts'][0] - 1]['jmpouts'][0] == $range[1] + 1 |
|---|
| 768 | && $lastOp['opcode'] == XC_QM_ASSIGN |
|---|
| 769 | ) { |
|---|
| 770 | $trueRange = array($range[0] + 1, $firstOp['jmpouts'][0] - 2); |
|---|
| 771 | $falseRange = array($firstOp['jmpouts'][0], $range[1]); |
|---|
| 772 | $this->removeJmpInfo($EX, $range[0]); |
|---|
| 773 | |
|---|
| 774 | $condition = $this->getOpVal($firstOp['op1'], $EX); |
|---|
| 775 | $this->recognizeAndDecompileClosedBlocks($EX, $trueRange, $indent . INDENT); |
|---|
| 776 | $trueValue = $this->getOpVal($opcodes[$trueRange[1]]['result'], $EX, true); |
|---|
| 777 | $this->recognizeAndDecompileClosedBlocks($EX, $falseRange, $indent . INDENT); |
|---|
| 778 | $falseValue = $this->getOpVal($opcodes[$falseRange[1]]['result'], $EX, true); |
|---|
| 779 | $T[$opcodes[$trueRange[1]]['result']['var']] = new Decompiler_TriOp($condition, $trueValue, $falseValue); |
|---|
| 780 | return false; |
|---|
| 781 | } |
|---|
| 782 | // }}} |
|---|
| 783 | // {{{ goto |
|---|
| 784 | if ($firstOp['opcode'] == XC_JMP && !empty($firstOp['jmpouts']) && $firstOp['jmpouts'][0] == $range[1] + 1) { |
|---|
| 785 | $this->removeJmpInfo($EX, $range[0]); |
|---|
| 786 | $firstOp['opcode'] = XC_GOTO; |
|---|
| 787 | $target = $firstOp['op1']['var']; |
|---|
| 788 | $firstOp['goto'] = $target; |
|---|
| 789 | $opcodes[$target]['gofrom'][] = $range[0]; |
|---|
| 790 | |
|---|
| 791 | $this->recognizeAndDecompileClosedBlocks($EX, $range, $indent); |
|---|
| 792 | return false; |
|---|
| 793 | } |
|---|
| 794 | // }}} |
|---|
| 795 | // {{{ try/catch |
|---|
| 796 | if (!empty($firstOp['jmpins']) && $opcodes[$firstOp['jmpins'][0]]['opcode'] == XC_JMP |
|---|
| 797 | && $lastOp['opcode'] == XC_JMP && !empty($lastOp['jmpouts']) && $lastOp['jmpouts'][0] <= $firstOp['jmpins'][0] |
|---|
| 798 | && !empty($opcodes[$range[1] + 1]['jmpins']) && $opcodes[$opcodes[$range[1] + 1]['jmpins'][0]]['opcode'] == XC_JMPZNZ |
|---|
| 799 | ) { |
|---|
| 800 | $nextRange = array($lastOp['jmpouts'][0], $firstOp['jmpins'][0]); |
|---|
| 801 | $conditionRange = array($range[0], $nextRange[0] - 1); |
|---|
| 802 | $this->removeJmpInfo($EX, $conditionRange[1]); |
|---|
| 803 | $bodyRange = array($nextRange[1], $range[1]); |
|---|
| 804 | $this->removeJmpInfo($EX, $bodyRange[1]); |
|---|
| 805 | |
|---|
| 806 | $initial = ''; |
|---|
| 807 | $this->dasmBasicBlock($EX, $conditionRange, $indent . INDENT); |
|---|
| 808 | $conditionCodes = array(); |
|---|
| 809 | for ($i = $conditionRange[0]; $i <= $conditionRange[1]; ++$i) { |
|---|
| 810 | if (isset($opcodes[$i]['php'])) { |
|---|
| 811 | $conditionCodes[] = str($opcodes[$i]['php'], $EX); |
|---|
| 812 | } |
|---|
| 813 | } |
|---|
| 814 | $conditionCodes[] = str($this->getOpVal($opcodes[$conditionRange[1]]['op1'], $EX), $EX); |
|---|
| 815 | if (implode(',', $conditionCodes) == 'true') { |
|---|
| 816 | $conditionCodes = array(); |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | $this->dasmBasicBlock($EX, $nextRange, $indent . INDENT); |
|---|
| 820 | $nextCodes = array(); |
|---|
| 821 | for ($i = $nextRange[0]; $i <= $nextRange[1]; ++$i) { |
|---|
| 822 | if (isset($opcodes[$i]['php'])) { |
|---|
| 823 | $nextCodes[] = str($opcodes[$i]['php'], $EX); |
|---|
| 824 | } |
|---|
| 825 | } |
|---|
| 826 | $this->beginComplexBlock($EX); |
|---|
| 827 | echo $indent, 'for (', str($initial, $EX), '; ', implode(', ', $conditionCodes), '; ', implode(', ', $nextCodes), ') ', '{', PHP_EOL; |
|---|
| 828 | $this->recognizeAndDecompileClosedBlocks($EX, $bodyRange, $indent . INDENT); |
|---|
| 829 | echo $indent, '}', PHP_EOL; |
|---|
| 830 | $this->endComplexBlock($EX); |
|---|
| 831 | return; |
|---|
| 832 | } |
|---|
| 833 | // }}} |
|---|
| 834 | // {{{ try/catch |
|---|
| 835 | if (!empty($firstOp['jmpins']) && !empty($opcodes[$firstOp['jmpins'][0]]['isCatchBegin'])) { |
|---|
| 836 | $catchBlocks = array(); |
|---|
| 837 | $catchFirst = $firstOp['jmpins'][0]; |
|---|
| 838 | |
|---|
| 839 | $tryRange = array($range[0], $catchFirst - 1); |
|---|
| 840 | |
|---|
| 841 | // search for XC_CATCH |
|---|
| 842 | $this->removeJmpInfo($EX, $catchFirst); |
|---|
| 843 | for ($i = $catchFirst; $i <= $range[1]; ) { |
|---|
| 844 | if ($opcodes[$i]['opcode'] == XC_CATCH) { |
|---|
| 845 | $catchOpLine = $i; |
|---|
| 846 | $this->removeJmpInfo($EX, $catchOpLine); |
|---|
| 847 | |
|---|
| 848 | $catchNext = $opcodes[$catchOpLine]['extended_value']; |
|---|
| 849 | $catchBodyLast = $catchNext - 1; |
|---|
| 850 | if ($opcodes[$catchBodyLast]['opcode'] == XC_JMP) { |
|---|
| 851 | --$catchBodyLast; |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | $catchBlocks[$catchFirst] = array($catchOpLine, $catchBodyLast); |
|---|
| 855 | |
|---|
| 856 | $i = $catchFirst = $catchNext; |
|---|
| 857 | } |
|---|
| 858 | else { |
|---|
| 859 | ++$i; |
|---|
| 860 | } |
|---|
| 861 | } |
|---|
| 862 | |
|---|
| 863 | if ($opcodes[$tryRange[1]]['opcode'] == XC_JMP) { |
|---|
| 864 | --$tryRange[1]; |
|---|
| 865 | } |
|---|
| 866 | |
|---|
| 867 | $this->beginComplexBlock($EX); |
|---|
| 868 | echo $indent, "try {", PHP_EOL; |
|---|
| 869 | $this->recognizeAndDecompileClosedBlocks($EX, $tryRange, $indent . INDENT); |
|---|
| 870 | echo $indent, '}', PHP_EOL; |
|---|
| 871 | foreach ($catchBlocks as $catchFirst => $catchInfo) { |
|---|
| 872 | list($catchOpLine, $catchBodyLast) = $catchInfo; |
|---|
| 873 | $catchBodyFirst = $catchOpLine + 1; |
|---|
| 874 | $this->recognizeAndDecompileClosedBlocks($EX, array($catchFirst, $catchOpLine), $indent); |
|---|
| 875 | $catchOp = &$opcodes[$catchOpLine]; |
|---|
| 876 | echo $indent, 'catch (', str($this->getOpVal($catchOp['op1'], $EX)), ' ', str($this->getOpVal($catchOp['op2'], $EX)), ") {", PHP_EOL; |
|---|
| 877 | unset($catchOp); |
|---|
| 878 | |
|---|
| 879 | $EX['lastBlock'] = null; |
|---|
| 880 | $this->recognizeAndDecompileClosedBlocks($EX, array($catchBodyFirst, $catchBodyLast), $indent . INDENT); |
|---|
| 881 | echo $indent, '}', PHP_EOL; |
|---|
| 882 | } |
|---|
| 883 | $this->endComplexBlock($EX); |
|---|
| 884 | return; |
|---|
| 885 | } |
|---|
| 886 | // }}} |
|---|
| 887 | // {{{ switch/case |
|---|
| 888 | if ($firstOp['opcode'] == XC_SWITCH_FREE && isset($T[$firstOp['op1']['var']])) { |
|---|
| 889 | // TODO: merge this code to CASE code. use SWITCH_FREE to detect begin of switch by using $Ts if possible |
|---|
| 890 | $this->beginComplexBlock($EX); |
|---|
| 891 | echo $indent, 'switch (', str($this->getOpVal($firstOp['op1'], $EX)), ") {", PHP_EOL; |
|---|
| 892 | echo $indent, '}', PHP_EOL; |
|---|
| 893 | $this->endComplexBlock($EX); |
|---|
| 894 | return; |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | if ( |
|---|
| 898 | ($firstOp['opcode'] == XC_CASE |
|---|
| 899 | || $firstOp['opcode'] == XC_JMP && !empty($firstOp['jmpouts']) && $opcodes[$firstOp['jmpouts'][0]]['opcode'] == XC_CASE |
|---|
| 900 | ) |
|---|
| 901 | && !empty($lastOp['jmpouts']) |
|---|
| 902 | ) { |
|---|
| 903 | $cases = array(); |
|---|
| 904 | $caseDefault = null; |
|---|
| 905 | $caseOp = null; |
|---|
| 906 | for ($i = $range[0]; $i <= $range[1]; ) { |
|---|
| 907 | $op = $opcodes[$i]; |
|---|
| 908 | if ($op['opcode'] == XC_CASE) { |
|---|
| 909 | if (!isset($caseOp)) { |
|---|
| 910 | $caseOp = $op; |
|---|
| 911 | } |
|---|
| 912 | $jmpz = $opcodes[$i + 1]; |
|---|
| 913 | assert('$jmpz["opcode"] == XC_JMPZ'); |
|---|
| 914 | $caseNext = $jmpz['jmpouts'][0]; |
|---|
| 915 | $cases[$i] = $caseNext - 1; |
|---|
| 916 | $i = $caseNext; |
|---|
| 917 | } |
|---|
| 918 | else if ($op['opcode'] == XC_JMP && $op['jmpouts'][0] >= $i) { |
|---|
| 919 | // default |
|---|
| 920 | $caseNext = $op['jmpouts'][0]; |
|---|
| 921 | $caseDefault = $i; |
|---|
| 922 | $cases[$i] = $caseNext - 1; |
|---|
| 923 | $i = $caseNext; |
|---|
| 924 | } |
|---|
| 925 | else { |
|---|
| 926 | ++$i; |
|---|
| 927 | } |
|---|
| 928 | } |
|---|
| 929 | |
|---|
| 930 | $this->beginComplexBlock($EX); |
|---|
| 931 | |
|---|
| 932 | echo $indent, 'switch (', str($this->getOpVal($caseOp['op1'], $EX), $EX), ") {", PHP_EOL; |
|---|
| 933 | $caseIsOut = false; |
|---|
| 934 | foreach ($cases as $caseFirst => $caseLast) { |
|---|
| 935 | if ($caseIsOut && !empty($EX['lastBlock']) && empty($lastCaseFall)) { |
|---|
| 936 | echo PHP_EOL; |
|---|
| 937 | } |
|---|
| 938 | unset($EX['lastBlock']); |
|---|
| 939 | |
|---|
| 940 | $caseOp = $opcodes[$caseFirst]; |
|---|
| 941 | |
|---|
| 942 | echo $indent; |
|---|
| 943 | if ($caseOp['opcode'] == XC_CASE) { |
|---|
| 944 | echo 'case '; |
|---|
| 945 | echo str($this->getOpVal($caseOp['op2'], $EX), $EX); |
|---|
| 946 | echo ':', PHP_EOL; |
|---|
| 947 | |
|---|
| 948 | $this->removeJmpInfo($EX, $caseFirst); |
|---|
| 949 | ++$caseFirst; |
|---|
| 950 | |
|---|
| 951 | assert('$opcodes[$caseFirst]["opcode"] == XC_JMPZ'); |
|---|
| 952 | $this->removeJmpInfo($EX, $caseFirst); |
|---|
| 953 | ++$caseFirst; |
|---|
| 954 | } |
|---|
| 955 | else { |
|---|
| 956 | echo 'default'; |
|---|
| 957 | echo ':', PHP_EOL; |
|---|
| 958 | |
|---|
| 959 | assert('$opcodes[$caseFirst]["opcode"] == XC_JMP'); |
|---|
| 960 | $this->removeJmpInfo($EX, $caseFirst); |
|---|
| 961 | ++$caseFirst; |
|---|
| 962 | } |
|---|
| 963 | |
|---|
| 964 | assert('$opcodes[$caseLast]["opcode"] == XC_JMP'); |
|---|
| 965 | $this->removeJmpInfo($EX, $caseLast); |
|---|
| 966 | --$caseLast; |
|---|
| 967 | switch ($opcodes[$caseLast]['opcode']) { |
|---|
| 968 | case XC_BRK: |
|---|
| 969 | case XC_CONT: |
|---|
| 970 | case XC_GOTO: |
|---|
| 971 | $lastCaseFall = false; |
|---|
| 972 | break; |
|---|
| 973 | |
|---|
| 974 | default: |
|---|
| 975 | $lastCaseFall = true; |
|---|
| 976 | } |
|---|
| 977 | |
|---|
| 978 | $this->recognizeAndDecompileClosedBlocks($EX, array($caseFirst, $caseLast), $indent . INDENT); |
|---|
| 979 | $caseIsOut = true; |
|---|
| 980 | } |
|---|
| 981 | echo $indent, '}', PHP_EOL; |
|---|
| 982 | |
|---|
| 983 | $this->endComplexBlock($EX); |
|---|
| 984 | return; |
|---|
| 985 | } |
|---|
| 986 | // }}} |
|---|
| 987 | // {{{ do/while |
|---|
| 988 | if ($lastOp['opcode'] == XC_JMPNZ && !empty($lastOp['jmpouts']) |
|---|
| 989 | && $lastOp['jmpouts'][0] == $range[0]) { |
|---|
| 990 | $this->removeJmpInfo($EX, $range[1]); |
|---|
| 991 | $this->beginComplexBlock($EX); |
|---|
| 992 | |
|---|
| 993 | echo $indent, "do {", PHP_EOL; |
|---|
| 994 | $this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT); |
|---|
| 995 | echo $indent, "} while (", str($this->getOpVal($lastOp['op1'], $EX)), ');', PHP_EOL; |
|---|
| 996 | |
|---|
| 997 | $this->endComplexBlock($EX); |
|---|
| 998 | return; |
|---|
| 999 | } |
|---|
| 1000 | // }}} |
|---|
| 1001 | |
|---|
| 1002 | // {{{ search firstJmpOp |
|---|
| 1003 | $firstJmp = null; |
|---|
| 1004 | $firstJmpOp = null; |
|---|
| 1005 | for ($i = $range[0]; $i <= $range[1]; ++$i) { |
|---|
| 1006 | if (!empty($opcodes[$i]['jmpouts'])) { |
|---|
| 1007 | $firstJmp = $i; |
|---|
| 1008 | $firstJmpOp = &$opcodes[$firstJmp]; |
|---|
| 1009 | break; |
|---|
| 1010 | } |
|---|
| 1011 | } |
|---|
| 1012 | // }}} |
|---|
| 1013 | |
|---|
| 1014 | // {{{ while |
|---|
| 1015 | if (isset($firstJmpOp) |
|---|
| 1016 | && $firstJmpOp['opcode'] == XC_JMPZ |
|---|
| 1017 | && $firstJmpOp['jmpouts'][0] > $range[1] |
|---|
| 1018 | && $lastOp['opcode'] == XC_JMP && !empty($lastOp['jmpouts']) |
|---|
| 1019 | && $lastOp['jmpouts'][0] == $range[0]) { |
|---|
| 1020 | $this->removeJmpInfo($EX, $firstJmp); |
|---|
| 1021 | $this->removeJmpInfo($EX, $range[1]); |
|---|
| 1022 | $this->beginComplexBlock($EX); |
|---|
| 1023 | |
|---|
| 1024 | ob_start(); |
|---|
| 1025 | $this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT); |
|---|
| 1026 | $body = ob_get_clean(); |
|---|
| 1027 | |
|---|
| 1028 | echo $indent, 'while (', str($this->getOpVal($firstJmpOp['op1'], $EX)), ") {", PHP_EOL; |
|---|
| 1029 | echo $body; |
|---|
| 1030 | echo $indent, '}', PHP_EOL; |
|---|
| 1031 | |
|---|
| 1032 | $this->endComplexBlock($EX); |
|---|
| 1033 | return; |
|---|
| 1034 | } |
|---|
| 1035 | // }}} |
|---|
| 1036 | // {{{ foreach |
|---|
| 1037 | if (isset($firstJmpOp) |
|---|
| 1038 | && $firstJmpOp['opcode'] == XC_FE_FETCH |
|---|
| 1039 | && $firstJmpOp['jmpouts'][0] > $range[1] |
|---|
| 1040 | && $lastOp['opcode'] == XC_JMP && !empty($lastOp['jmpouts']) |
|---|
| 1041 | && $lastOp['jmpouts'][0] == $firstJmp) { |
|---|
| 1042 | $this->removeJmpInfo($EX, $firstJmp); |
|---|
| 1043 | $this->removeJmpInfo($EX, $range[1]); |
|---|
| 1044 | $this->beginComplexBlock($EX); |
|---|
| 1045 | |
|---|
| 1046 | ob_start(); |
|---|
| 1047 | $this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT); |
|---|
| 1048 | $body = ob_get_clean(); |
|---|
| 1049 | |
|---|
| 1050 | $as = foldToCode($firstJmpOp['fe_as'], $EX); |
|---|
| 1051 | if (isset($firstJmpOp['fe_key'])) { |
|---|
| 1052 | $as = str($firstJmpOp['fe_key'], $EX) . ' => ' . str($as); |
|---|
| 1053 | } |
|---|
| 1054 | |
|---|
| 1055 | echo $indent, 'foreach (', str($firstJmpOp['fe_src'], $EX), " as $as) {", PHP_EOL; |
|---|
| 1056 | echo $body; |
|---|
| 1057 | echo $indent, '}', PHP_EOL; |
|---|
| 1058 | |
|---|
| 1059 | $this->endComplexBlock($EX); |
|---|
| 1060 | if ($opcodes[$range[1] + 1]['opcode'] == XC_SWITCH_FREE) { |
|---|
| 1061 | $this->removeJmpInfo($EX, $range[1] + 1); |
|---|
| 1062 | } |
|---|
| 1063 | return; |
|---|
| 1064 | } |
|---|
| 1065 | // }}} |
|---|
| 1066 | |
|---|
| 1067 | $this->decompileBasicBlock($EX, $range, $indent, true); |
|---|
| 1068 | } |
|---|
| 1069 | // }}} |
|---|
| 1070 | function recognizeAndDecompileClosedBlocks(&$EX, $range, $indent) // {{{ decompile in a tree way |
|---|
| 1071 | { |
|---|
| 1072 | $opcodes = &$EX['opcodes']; |
|---|
| 1073 | |
|---|
| 1074 | $starti = $range[0]; |
|---|
| 1075 | for ($i = $starti; $i <= $range[1]; ) { |
|---|
| 1076 | if (!empty($opcodes[$i]['jmpins']) || !empty($opcodes[$i]['jmpouts'])) { |
|---|
| 1077 | $blockFirst = $i; |
|---|
| 1078 | $blockLast = -1; |
|---|
| 1079 | $j = $blockFirst; |
|---|
| 1080 | do { |
|---|
| 1081 | $op = $opcodes[$j]; |
|---|
| 1082 | if (!empty($op['jmpins'])) { |
|---|
| 1083 | // care about jumping from blocks behind, not before |
|---|
| 1084 | foreach ($op['jmpins'] as $oplineNumber) { |
|---|
| 1085 | if ($oplineNumber <= $range[1] && $blockLast < $oplineNumber) { |
|---|
| 1086 | $blockLast = $oplineNumber; |
|---|
| 1087 | } |
|---|
| 1088 | } |
|---|
| 1089 | } |
|---|
| 1090 | if (!empty($op['jmpouts'])) { |
|---|
| 1091 | $blockLast = max($blockLast, max($op['jmpouts']) - 1); |
|---|
| 1092 | } |
|---|
| 1093 | ++$j; |
|---|
| 1094 | } while ($j <= $blockLast); |
|---|
| 1095 | if (!assert('$blockLast <= $range[1]')) { |
|---|
| 1096 | var_dump($blockLast, $range[1]); |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | if ($blockLast >= $blockFirst) { |
|---|
| 1100 | if ($blockFirst > $starti) { |
|---|
| 1101 | $this->decompileBasicBlock($EX, array($starti, $blockFirst - 1), $indent); |
|---|
| 1102 | } |
|---|
| 1103 | if ($this->decompileComplexBlock($EX, array($blockFirst, $blockLast), $indent) === false) { |
|---|
| 1104 | if ($EX['lastBlock'] == 'complex') { |
|---|
| 1105 | echo PHP_EOL; |
|---|
| 1106 | } |
|---|
| 1107 | $EX['lastBlock'] = null; |
|---|
| 1108 | } |
|---|
| 1109 | $starti = $blockLast + 1; |
|---|
| 1110 | $i = $starti; |
|---|
| 1111 | } |
|---|
| 1112 | else { |
|---|
| 1113 | ++$i; |
|---|
| 1114 | } |
|---|
| 1115 | } |
|---|
| 1116 | else { |
|---|
| 1117 | ++$i; |
|---|
| 1118 | } |
|---|
| 1119 | } |
|---|
| 1120 | if ($starti <= $range[1]) { |
|---|
| 1121 | $this->decompileBasicBlock($EX, array($starti, $range[1]), $indent); |
|---|
| 1122 | } |
|---|
| 1123 | } |
|---|
| 1124 | // }}} |
|---|
| 1125 | function &dop_array($op_array, $indent = '') // {{{ |
|---|
| 1126 | { |
|---|
| 1127 | $op_array['opcodes'] = $this->fixOpcode($op_array['opcodes'], true, $indent == '' ? 1 : null); |
|---|
| 1128 | $opcodes = &$op_array['opcodes']; |
|---|
| 1129 | $last = count($opcodes) - 1; |
|---|
| 1130 | // {{{ build jmpins/jmpouts to op_array |
|---|
| 1131 | for ($i = 0; $i <= $last; $i ++) { |
|---|
| 1132 | $op = &$opcodes[$i]; |
|---|
| 1133 | $op['line'] = $i; |
|---|
| 1134 | switch ($op['opcode']) { |
|---|
| 1135 | case XC_CONT: |
|---|
| 1136 | case XC_BRK: |
|---|
| 1137 | $op['jmpouts'] = array(); |
|---|
| 1138 | break; |
|---|
| 1139 | |
|---|
| 1140 | case XC_GOTO: |
|---|
| 1141 | $target = $op['op1']['var']; |
|---|
| 1142 | $op['goto'] = $target; |
|---|
| 1143 | $opcodes[$target]['gofrom'][] = $i; |
|---|
| 1144 | break; |
|---|
| 1145 | |
|---|
| 1146 | case XC_JMP: |
|---|
| 1147 | $target = $op['op1']['var']; |
|---|
| 1148 | $op['jmpouts'] = array($target); |
|---|
| 1149 | $opcodes[$target]['jmpins'][] = $i; |
|---|
| 1150 | break; |
|---|
| 1151 | |
|---|
| 1152 | case XC_JMPZNZ: |
|---|
| 1153 | $jmpz = $op['op2']['opline_num']; |
|---|
| 1154 | $jmpnz = $op['extended_value']; |
|---|
| 1155 | $op['jmpouts'] = array($jmpz, $jmpnz); |
|---|
| 1156 | $opcodes[$jmpz]['jmpins'][] = $i; |
|---|
| 1157 | $opcodes[$jmpnz]['jmpins'][] = $i; |
|---|
| 1158 | break; |
|---|
| 1159 | |
|---|
| 1160 | case XC_JMPZ: |
|---|
| 1161 | case XC_JMPNZ: |
|---|
| 1162 | case XC_JMPZ_EX: |
|---|
| 1163 | case XC_JMPNZ_EX: |
|---|
| 1164 | // case XC_JMP_SET: |
|---|
| 1165 | // case XC_FE_RESET: |
|---|
| 1166 | case XC_FE_FETCH: |
|---|
| 1167 | // case XC_JMP_NO_CTOR: |
|---|
| 1168 | $target = $op['op2']['opline_num']; |
|---|
| 1169 | //if (!isset($target)) { |
|---|
| 1170 | // $this->dumpop($op, $EX); |
|---|
| 1171 | // var_dump($op); exit; |
|---|
| 1172 | //} |
|---|
| 1173 | $op['jmpouts'] = array($target); |
|---|
| 1174 | $opcodes[$target]['jmpins'][] = $i; |
|---|
| 1175 | break; |
|---|
| 1176 | |
|---|
| 1177 | /* |
|---|
| 1178 | case XC_RETURN: |
|---|
| 1179 | $op['jmpouts'] = array(); |
|---|
| 1180 | break; |
|---|
| 1181 | */ |
|---|
| 1182 | |
|---|
| 1183 | case XC_SWITCH_FREE: |
|---|
| 1184 | $op['jmpouts'] = array($i + 1); |
|---|
| 1185 | $opcodes[$i + 1]['jmpins'][] = $i; |
|---|
| 1186 | break; |
|---|
| 1187 | |
|---|
| 1188 | case XC_CASE: |
|---|
| 1189 | // just to link together |
|---|
| 1190 | $op['jmpouts'] = array($i + 2); |
|---|
| 1191 | $opcodes[$i + 2]['jmpins'][] = $i; |
|---|
| 1192 | break; |
|---|
| 1193 | |
|---|
| 1194 | case XC_CATCH: |
|---|
| 1195 | $catchNext = $op['extended_value']; |
|---|
| 1196 | $op['jmpouts'] = array($catchNext); |
|---|
| 1197 | $opcodes[$catchNext]['jmpins'][] = $i; |
|---|
| 1198 | break; |
|---|
| 1199 | } |
|---|
| 1200 | /* |
|---|
| 1201 | if (!empty($op['jmpouts']) || !empty($op['jmpins'])) { |
|---|
| 1202 | echo $i, "\t", xcache_get_opcode($op['opcode']), PHP_EOL; |
|---|
| 1203 | } |
|---|
| 1204 | // */ |
|---|
| 1205 | } |
|---|
| 1206 | unset($op); |
|---|
| 1207 | if ($op_array['try_catch_array']) { |
|---|
| 1208 | foreach ($op_array['try_catch_array'] as $try_catch_element) { |
|---|
| 1209 | $catch_op = $try_catch_element['catch_op']; |
|---|
| 1210 | $try_op = $try_catch_element['try_op']; |
|---|
| 1211 | $opcodes[$try_op]['jmpins'][] = $catch_op; |
|---|
| 1212 | $opcodes[$catch_op]['jmpouts'][] = $try_op; |
|---|
| 1213 | $opcodes[$catch_op]['isCatchBegin'] = true; |
|---|
| 1214 | } |
|---|
| 1215 | } |
|---|
| 1216 | // }}} |
|---|
| 1217 | // build semi-basic blocks |
|---|
| 1218 | $nextbbs = array(); |
|---|
| 1219 | $starti = 0; |
|---|
| 1220 | for ($i = 1; $i <= $last; $i ++) { |
|---|
| 1221 | if (isset($opcodes[$i]['jmpins']) |
|---|
| 1222 | || isset($opcodes[$i - 1]['jmpouts'])) { |
|---|
| 1223 | $nextbbs[$starti] = $i; |
|---|
| 1224 | $starti = $i; |
|---|
| 1225 | } |
|---|
| 1226 | } |
|---|
| 1227 | $nextbbs[$starti] = $last + 1; |
|---|
| 1228 | |
|---|
| 1229 | $EX = array(); |
|---|
| 1230 | $EX['Ts'] = array(); |
|---|
| 1231 | $EX['indent'] = $indent; |
|---|
| 1232 | $EX['nextbbs'] = $nextbbs; |
|---|
| 1233 | $EX['op_array'] = &$op_array; |
|---|
| 1234 | $EX['opcodes'] = &$opcodes; |
|---|
| 1235 | $EX['range'] = array(0, count($opcodes) - 1); |
|---|
| 1236 | // func call |
|---|
| 1237 | $EX['object'] = null; |
|---|
| 1238 | $EX['called_scope'] = null; |
|---|
| 1239 | $EX['fbc'] = null; |
|---|
| 1240 | $EX['argstack'] = array(); |
|---|
| 1241 | $EX['arg_types_stack'] = array(); |
|---|
| 1242 | $EX['silence'] = 0; |
|---|
| 1243 | $EX['recvs'] = array(); |
|---|
| 1244 | $EX['uses'] = array(); |
|---|
| 1245 | $EX['lastBlock'] = null; |
|---|
| 1246 | |
|---|
| 1247 | /* dump whole array |
|---|
| 1248 | $this->keepTs = true; |
|---|
| 1249 | $this->dasmBasicBlock($EX, $range); |
|---|
| 1250 | for ($i = $range[0]; $i <= $range[1]; ++$i) { |
|---|
| 1251 | echo $i, "\t", $this->dumpop($opcodes[$i], $EX); |
|---|
| 1252 | } |
|---|
| 1253 | // */ |
|---|
| 1254 | // decompile in a tree way |
|---|
| 1255 | $this->recognizeAndDecompileClosedBlocks($EX, $EX['range'], $EX['indent']); |
|---|
| 1256 | return $EX; |
|---|
| 1257 | } |
|---|
| 1258 | // }}} |
|---|
| 1259 | function outputCode(&$EX, $range, $indent, $loop = false) // {{{ |
|---|
| 1260 | { |
|---|
| 1261 | $op = &$EX['opcodes'][$range[0]]; |
|---|
| 1262 | $next = $EX['nextbbs'][$range[0]]; |
|---|
| 1263 | |
|---|
| 1264 | $end = $next - 1; |
|---|
| 1265 | if ($end > $range[1]) { |
|---|
| 1266 | $end = $range[1]; |
|---|
| 1267 | } |
|---|
| 1268 | |
|---|
| 1269 | if (isset($op['jmpins'])) { |
|---|
| 1270 | echo "\nline", $op['line'], ":\n"; |
|---|
| 1271 | } |
|---|
| 1272 | else { |
|---|
| 1273 | // echo ";;;\n"; |
|---|
| 1274 | } |
|---|
| 1275 | $this->dasmBasicBlock($EX, array($opline, $end)); |
|---|
| 1276 | $this->outputPhp($EX, array($opline, $end), $indent); |
|---|
| 1277 | // jmpout op |
|---|
| 1278 | $op = &$EX['opcodes'][$end]; |
|---|
| 1279 | $op1 = $op['op1']; |
|---|
| 1280 | $op2 = $op['op2']; |
|---|
| 1281 | $ext = $op['extended_value']; |
|---|
| 1282 | $line = $op['line']; |
|---|
| 1283 | |
|---|
| 1284 | if (isset($EX['opcodes'][$next])) { |
|---|
| 1285 | if (isset($range[1]) && $next > $range[1]) { |
|---|
| 1286 | $next = null; |
|---|
| 1287 | } |
|---|
| 1288 | } |
|---|
| 1289 | else { |
|---|
| 1290 | $next = null; |
|---|
| 1291 | } |
|---|
| 1292 | /* |
|---|
| 1293 | if ($op['opcode'] == XC_JMPZ) { |
|---|
| 1294 | $target = $op2['opline_num']; |
|---|
| 1295 | if ($line + 1) { |
|---|
| 1296 | $nextblock = $EX['nextbbs'][$next]; |
|---|
| 1297 | $jmpop = end($nextblock); |
|---|
| 1298 | if ($jmpop['opcode'] == XC_JMP) { |
|---|
| 1299 | $ifendline = $op2['opline_num']; |
|---|
| 1300 | if ($ifendline >= $line) { |
|---|
| 1301 | $cond = $op['cond']; |
|---|
| 1302 | echo "{$indent}if ($cond) {\n"; |
|---|
| 1303 | $this->outputCode($EX, $next, $range[1], INDENT . $indent); |
|---|
| 1304 | echo "$indent}\n"; |
|---|
| 1305 | $this->outputCode($EX, $target, $range[1], $indent); |
|---|
| 1306 | return; |
|---|
| 1307 | } |
|---|
| 1308 | } |
|---|
| 1309 | } |
|---|
| 1310 | } |
|---|
| 1311 | */ |
|---|
| 1312 | if (!isset($next)) { |
|---|
| 1313 | return; |
|---|
| 1314 | } |
|---|
| 1315 | if (isset($op['jmpouts']) && isset($op['isjmp'])) { |
|---|
| 1316 | if (isset($op['cond'])) { |
|---|
| 1317 | echo "{$indent}check (" . str($op["cond"]) . ") {\n"; |
|---|
| 1318 | echo INDENT; |
|---|
| 1319 | } |
|---|
| 1320 | switch ($op['opcode']) { |
|---|
| 1321 | case XC_CONT: |
|---|
| 1322 | case XC_BRK: |
|---|
| 1323 | break; |
|---|
| 1324 | |
|---|
| 1325 | default: |
|---|
| 1326 | echo $indent; |
|---|
| 1327 | echo xcache_get_opcode($op['opcode']), ' line', $op['jmpouts'][0]; |
|---|
| 1328 | if (isset($op['jmpouts'][1])) { |
|---|
| 1329 | echo ', line', $op['jmpouts'][1]; |
|---|
| 1330 | } |
|---|
| 1331 | echo ";"; |
|---|
| 1332 | // echo ' // <- line', $op['line']; |
|---|
| 1333 | echo "\n"; |
|---|
| 1334 | } |
|---|
| 1335 | if (isset($op['cond'])) echo "$indent}\n"; |
|---|
| 1336 | } |
|---|
| 1337 | |
|---|
| 1338 | // proces JMPZ_EX/JMPNZ_EX for AND,OR |
|---|
| 1339 | $op = &$EX['opcodes'][$next]; |
|---|
| 1340 | /* |
|---|
| 1341 | if (isset($op['jmpins'])) { |
|---|
| 1342 | foreach (array_reverse($op['jmpins']) as $fromline) { |
|---|
| 1343 | $fromop = $EX['opcodes'][$fromline]; |
|---|
| 1344 | switch ($fromop['opcode']) { |
|---|
| 1345 | case XC_JMPZ_EX: $opstr = 'and'; break; |
|---|
| 1346 | case XC_JMPNZ_EX: $opstr = 'or'; break; |
|---|
| 1347 | case XC_JMPZNZ: var_dump($fromop); exit; |
|---|
| 1348 | default: continue 2; |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | $var = $fromop['result']['var']; |
|---|
| 1352 | var_dump($EX['Ts'][$var]); |
|---|
| 1353 | $EX['Ts'][$var] = '(' . $fromop['and_or'] . " $opstr " . $EX['Ts'][$var] . ')'; |
|---|
| 1354 | } |
|---|
| 1355 | #$this->outputCode($EX, $next, $range[1], $indent); |
|---|
| 1356 | #return; |
|---|
| 1357 | } |
|---|
| 1358 | */ |
|---|
| 1359 | if (isset($op['cond_false'])) { |
|---|
| 1360 | // $this->dumpop($op, $EX); |
|---|
| 1361 | // any true comes here, so it's a "or" |
|---|
| 1362 | $cond = implode(' and ', str($op['cond_false'])); |
|---|
| 1363 | // var_dump($op['cond'] = $cond); |
|---|
| 1364 | /* |
|---|
| 1365 | $rvalue = implode(' or ', $op['cond_true']) . ' or ' . $rvalue; |
|---|
| 1366 | unset($op['cond_true']); |
|---|
| 1367 | */ |
|---|
| 1368 | } |
|---|
| 1369 | |
|---|
| 1370 | $nextRange = array($next, $range[1]); |
|---|
| 1371 | if ($loop) { |
|---|
| 1372 | return $nextRange; |
|---|
| 1373 | } |
|---|
| 1374 | $this->outputCode($EX, $nextRange, $indent); |
|---|
| 1375 | } |
|---|
| 1376 | // }}} |
|---|
| 1377 | function dasmBasicBlock(&$EX, $range) // {{{ |
|---|
| 1378 | { |
|---|
| 1379 | $T = &$EX['Ts']; |
|---|
| 1380 | $opcodes = &$EX['opcodes']; |
|---|
| 1381 | $lastphpop = null; |
|---|
| 1382 | |
|---|
| 1383 | for ($i = $range[0]; $i <= $range[1]; $i ++) { |
|---|
| 1384 | // {{{ prepair |
|---|
| 1385 | $op = &$opcodes[$i]; |
|---|
| 1386 | $opc = $op['opcode']; |
|---|
| 1387 | if ($opc == XC_NOP) { |
|---|
| 1388 | $this->usedOps[$opc] = true; |
|---|
| 1389 | continue; |
|---|
| 1390 | } |
|---|
| 1391 | |
|---|
| 1392 | $op1 = $op['op1']; |
|---|
| 1393 | $op2 = $op['op2']; |
|---|
| 1394 | $res = $op['result']; |
|---|
| 1395 | $ext = $op['extended_value']; |
|---|
| 1396 | |
|---|
| 1397 | $opname = xcache_get_opcode($opc); |
|---|
| 1398 | |
|---|
| 1399 | if ($opname == 'UNDEF' || !isset($opname)) { |
|---|
| 1400 | echo 'UNDEF OP:'; |
|---|
| 1401 | $this->dumpop($op, $EX); |
|---|
| 1402 | continue; |
|---|
| 1403 | } |
|---|
| 1404 | // echo $i, ' '; $this->dumpop($op, $EX); //var_dump($op); |
|---|
| 1405 | |
|---|
| 1406 | $resvar = null; |
|---|
| 1407 | unset($curResVar); |
|---|
| 1408 | if (array_key_exists($res['var'], $T)) { |
|---|
| 1409 | $curResVar = &$T[$res['var']]; |
|---|
| 1410 | } |
|---|
| 1411 | if ((ZEND_ENGINE_2_4 ? ($res['op_type'] & EXT_TYPE_UNUSED) : ($res['EA.type'] & EXT_TYPE_UNUSED)) || $res['op_type'] == XC_IS_UNUSED) { |
|---|
| 1412 | $istmpres = false; |
|---|
| 1413 | } |
|---|
| 1414 | else { |
|---|
| 1415 | $istmpres = true; |
|---|
| 1416 | } |
|---|
| 1417 | // }}} |
|---|
| 1418 | // echo $opname, "\n"; |
|---|
| 1419 | |
|---|
| 1420 | $notHandled = false; |
|---|
| 1421 | switch ($opc) { |
|---|
| 1422 | case XC_NEW: // {{{ |
|---|
| 1423 | array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); |
|---|
| 1424 | $EX['object'] = (int) $res['var']; |
|---|
| 1425 | $EX['called_scope'] = null; |
|---|
| 1426 | $EX['fbc'] = 'new ' . unquoteName($this->getOpVal($op1, $EX), $EX); |
|---|
| 1427 | if (!ZEND_ENGINE_2) { |
|---|
| 1428 | $resvar = '$new object$'; |
|---|
| 1429 | } |
|---|
| 1430 | break; |
|---|
| 1431 | // }}} |
|---|
| 1432 | case XC_THROW: // {{{ |
|---|
| 1433 | $resvar = 'throw ' . str($this->getOpVal($op1, $EX)); |
|---|
| 1434 | break; |
|---|
| 1435 | // }}} |
|---|
| 1436 | case XC_CLONE: // {{{ |
|---|
| 1437 | $resvar = 'clone ' . str($this->getOpVal($op1, $EX)); |
|---|
| 1438 | break; |
|---|
| 1439 | // }}} |
|---|
| 1440 | case XC_CATCH: // {{{ |
|---|
| 1441 | break; |
|---|
| 1442 | // }}} |
|---|
| 1443 | case XC_INSTANCEOF: // {{{ |
|---|
| 1444 | $resvar = str($this->getOpVal($op1, $EX)) . ' instanceof ' . str($this->getOpVal($op2, $EX)); |
|---|
| 1445 | break; |
|---|
| 1446 | // }}} |
|---|
| 1447 | case XC_FETCH_CLASS: // {{{ |
|---|
| 1448 | if ($op2['op_type'] == XC_IS_UNUSED) { |
|---|
| 1449 | switch (($ext & (defined('ZEND_FETCH_CLASS_MASK') ? ZEND_FETCH_CLASS_MASK : 0xFF))) { |
|---|
| 1450 | case ZEND_FETCH_CLASS_SELF: |
|---|
| 1451 | $class = 'self'; |
|---|
| 1452 | break; |
|---|
| 1453 | case ZEND_FETCH_CLASS_PARENT: |
|---|
| 1454 | $class = 'parent'; |
|---|
| 1455 | break; |
|---|
| 1456 | case ZEND_FETCH_CLASS_STATIC: |
|---|
| 1457 | $class = 'static'; |
|---|
| 1458 | break; |
|---|
| 1459 | } |
|---|
| 1460 | $istmpres = true; |
|---|
| 1461 | } |
|---|
| 1462 | else { |
|---|
| 1463 | $class = $this->getOpVal($op2, $EX); |
|---|
| 1464 | if (isset($op2['constant'])) { |
|---|
| 1465 | $class = $this->stripNamespace(unquoteName($class)); |
|---|
| 1466 | } |
|---|
| 1467 | } |
|---|
| 1468 | $resvar = $class; |
|---|
| 1469 | break; |
|---|
| 1470 | // }}} |
|---|
| 1471 | case XC_FETCH_CONSTANT: // {{{ |
|---|
| 1472 | if ($op1['op_type'] == XC_IS_UNUSED) { |
|---|
| 1473 | $resvar = $this->stripNamespace($op2['constant']); |
|---|
| 1474 | break; |
|---|
| 1475 | } |
|---|
| 1476 | |
|---|
| 1477 | if ($op1['op_type'] == XC_IS_CONST) { |
|---|
| 1478 | $resvar = $this->stripNamespace($op1['constant']); |
|---|
| 1479 | } |
|---|
| 1480 | else { |
|---|
| 1481 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1482 | } |
|---|
| 1483 | |
|---|
| 1484 | $resvar = str($resvar) . '::' . unquoteName($this->getOpVal($op2, $EX)); |
|---|
| 1485 | break; |
|---|
| 1486 | // }}} |
|---|
| 1487 | // {{{ case XC_FETCH_* |
|---|
| 1488 | case XC_FETCH_R: |
|---|
| 1489 | case XC_FETCH_W: |
|---|
| 1490 | case XC_FETCH_RW: |
|---|
| 1491 | case XC_FETCH_FUNC_ARG: |
|---|
| 1492 | case XC_FETCH_UNSET: |
|---|
| 1493 | case XC_FETCH_IS: |
|---|
| 1494 | case XC_UNSET_VAR: |
|---|
| 1495 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 1496 | if (defined('ZEND_FETCH_TYPE_MASK')) { |
|---|
| 1497 | $fetchtype = ($ext & ZEND_FETCH_TYPE_MASK); |
|---|
| 1498 | } |
|---|
| 1499 | else { |
|---|
| 1500 | $fetchtype = $op2[!ZEND_ENGINE_2 ? 'fetch_type' : 'EA.type']; |
|---|
| 1501 | } |
|---|
| 1502 | switch ($fetchtype) { |
|---|
| 1503 | case ZEND_FETCH_STATIC_MEMBER: |
|---|
| 1504 | $class = $this->getOpVal($op2, $EX); |
|---|
| 1505 | $rvalue = str($class) . '::$' . unquoteName($rvalue, $EX); |
|---|
| 1506 | break; |
|---|
| 1507 | default: |
|---|
| 1508 | $name = unquoteName($rvalue, $EX); |
|---|
| 1509 | $globalname = xcache_is_autoglobal($name) ? "\$$name" : "\$GLOBALS[" . str($rvalue) . "]"; |
|---|
| 1510 | $rvalue = new Decompiler_Fetch($rvalue, $fetchtype, $globalname); |
|---|
| 1511 | break; |
|---|
| 1512 | } |
|---|
| 1513 | if ($opc == XC_UNSET_VAR) { |
|---|
| 1514 | $op['php'] = "unset(" . str($rvalue, $EX) . ")"; |
|---|
| 1515 | $lastphpop = &$op; |
|---|
| 1516 | } |
|---|
| 1517 | else if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 1518 | $resvar = $rvalue; |
|---|
| 1519 | } |
|---|
| 1520 | break; |
|---|
| 1521 | // }}} |
|---|
| 1522 | // {{{ case XC_FETCH_DIM_* |
|---|
| 1523 | case XC_FETCH_DIM_TMP_VAR: |
|---|
| 1524 | case XC_FETCH_DIM_R: |
|---|
| 1525 | case XC_FETCH_DIM_W: |
|---|
| 1526 | case XC_FETCH_DIM_RW: |
|---|
| 1527 | case XC_FETCH_DIM_FUNC_ARG: |
|---|
| 1528 | case XC_FETCH_DIM_UNSET: |
|---|
| 1529 | case XC_FETCH_DIM_IS: |
|---|
| 1530 | case XC_ASSIGN_DIM: |
|---|
| 1531 | case XC_UNSET_DIM_OBJ: // PHP 4 only |
|---|
| 1532 | case XC_UNSET_DIM: |
|---|
| 1533 | case XC_UNSET_OBJ: |
|---|
| 1534 | $src = $this->getOpVal($op1, $EX); |
|---|
| 1535 | if (is_a($src, "Decompiler_ForeachBox")) { |
|---|
| 1536 | $src->iskey = $this->getOpVal($op2, $EX); |
|---|
| 1537 | $resvar = $src; |
|---|
| 1538 | break; |
|---|
| 1539 | } |
|---|
| 1540 | |
|---|
| 1541 | if (is_a($src, "Decompiler_DimBox")) { |
|---|
| 1542 | $dimbox = $src; |
|---|
| 1543 | } |
|---|
| 1544 | else { |
|---|
| 1545 | if (!is_a($src, "Decompiler_ListBox")) { |
|---|
| 1546 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1547 | $list = new Decompiler_List(isset($op1val) ? $op1val : '$this'); |
|---|
| 1548 | |
|---|
| 1549 | $src = new Decompiler_ListBox($list); |
|---|
| 1550 | if (!isset($op1['var'])) { |
|---|
| 1551 | $this->dumpop($op, $EX); |
|---|
| 1552 | var_dump($op); |
|---|
| 1553 | die('missing var'); |
|---|
| 1554 | } |
|---|
| 1555 | $T[$op1['var']] = $src; |
|---|
| 1556 | unset($list); |
|---|
| 1557 | } |
|---|
| 1558 | $dim = new Decompiler_Dim($src); |
|---|
| 1559 | $src->obj->dims[] = &$dim; |
|---|
| 1560 | |
|---|
| 1561 | $dimbox = new Decompiler_DimBox($dim); |
|---|
| 1562 | } |
|---|
| 1563 | $dim = &$dimbox->obj; |
|---|
| 1564 | $dim->offsets[] = $this->getOpVal($op2, $EX); |
|---|
| 1565 | if ($ext == ZEND_FETCH_ADD_LOCK) { |
|---|
| 1566 | $src->obj->everLocked = true; |
|---|
| 1567 | } |
|---|
| 1568 | else if ($ext == ZEND_FETCH_STANDARD) { |
|---|
| 1569 | $dim->isLast = true; |
|---|
| 1570 | } |
|---|
| 1571 | if ($opc == XC_UNSET_OBJ) { |
|---|
| 1572 | $dim->isObject = true; |
|---|
| 1573 | } |
|---|
| 1574 | unset($dim); |
|---|
| 1575 | $rvalue = $dimbox; |
|---|
| 1576 | unset($dimbox); |
|---|
| 1577 | |
|---|
| 1578 | if ($opc == XC_ASSIGN_DIM) { |
|---|
| 1579 | $lvalue = $rvalue; |
|---|
| 1580 | ++ $i; |
|---|
| 1581 | $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); |
|---|
| 1582 | $resvar = str($lvalue, $EX) . ' = ' . str($rvalue); |
|---|
| 1583 | } |
|---|
| 1584 | else if ($opc == XC_UNSET_DIM || $opc == XC_UNSET_OBJ) { |
|---|
| 1585 | $op['php'] = "unset(" . str($rvalue, $EX) . ")"; |
|---|
| 1586 | $lastphpop = &$op; |
|---|
| 1587 | } |
|---|
| 1588 | else if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 1589 | $resvar = $rvalue; |
|---|
| 1590 | } |
|---|
| 1591 | break; |
|---|
| 1592 | // }}} |
|---|
| 1593 | case XC_ASSIGN: // {{{ |
|---|
| 1594 | $lvalue = $this->getOpVal($op1, $EX); |
|---|
| 1595 | $rvalue = $this->getOpVal($op2, $EX); |
|---|
| 1596 | if (is_a($rvalue, 'Decompiler_ForeachBox')) { |
|---|
| 1597 | $type = $rvalue->iskey ? 'fe_key' : 'fe_as'; |
|---|
| 1598 | $rvalue->obj[$type] = $lvalue; |
|---|
| 1599 | unset($T[$op2['var']]); |
|---|
| 1600 | break; |
|---|
| 1601 | } |
|---|
| 1602 | if (is_a($rvalue, "Decompiler_DimBox")) { |
|---|
| 1603 | $dim = &$rvalue->obj; |
|---|
| 1604 | $dim->assign = $lvalue; |
|---|
| 1605 | if ($dim->isLast) { |
|---|
| 1606 | $resvar = foldToCode($dim->value, $EX); |
|---|
| 1607 | } |
|---|
| 1608 | unset($dim); |
|---|
| 1609 | break; |
|---|
| 1610 | } |
|---|
| 1611 | if (is_a($rvalue, 'Decompiler_Fetch')) { |
|---|
| 1612 | $src = str($rvalue->src, $EX); |
|---|
| 1613 | if ('$' . unquoteName($src) == $lvalue) { |
|---|
| 1614 | switch ($rvalue->fetchType) { |
|---|
| 1615 | case ZEND_FETCH_STATIC: |
|---|
| 1616 | $statics = &$EX['op_array']['static_variables']; |
|---|
| 1617 | if ((xcache_get_type($statics[$name]) & IS_LEXICAL_VAR)) { |
|---|
| 1618 | $EX['uses'][] = str($lvalue); |
|---|
| 1619 | unset($statics); |
|---|
| 1620 | break 2; |
|---|
| 1621 | } |
|---|
| 1622 | unset($statics); |
|---|
| 1623 | } |
|---|
| 1624 | } |
|---|
| 1625 | } |
|---|
| 1626 | $resvar = new Decompiler_Binop($this, $lvalue, XC_ASSIGN, $rvalue); |
|---|
| 1627 | break; |
|---|
| 1628 | // }}} |
|---|
| 1629 | case XC_ASSIGN_REF: // {{{ |
|---|
| 1630 | $lvalue = $this->getOpVal($op1, $EX); |
|---|
| 1631 | $rvalue = $this->getOpVal($op2, $EX); |
|---|
| 1632 | if (is_a($rvalue, 'Decompiler_Fetch')) { |
|---|
| 1633 | $src = str($rvalue->src, $EX); |
|---|
| 1634 | if ('$' . unquoteName($src) == $lvalue) { |
|---|
| 1635 | switch ($rvalue->fetchType) { |
|---|
| 1636 | case ZEND_FETCH_GLOBAL: |
|---|
| 1637 | case ZEND_FETCH_GLOBAL_LOCK: |
|---|
| 1638 | $resvar = 'global ' . $lvalue; |
|---|
| 1639 | break 2; |
|---|
| 1640 | case ZEND_FETCH_STATIC: |
|---|
| 1641 | $statics = &$EX['op_array']['static_variables']; |
|---|
| 1642 | if ((xcache_get_type($statics[$name]) & IS_LEXICAL_REF)) { |
|---|
| 1643 | $EX['uses'][] = '&' . str($lvalue); |
|---|
| 1644 | unset($statics); |
|---|
| 1645 | break 2; |
|---|
| 1646 | } |
|---|
| 1647 | |
|---|
| 1648 | $resvar = 'static ' . $lvalue; |
|---|
| 1649 | $name = unquoteName($src); |
|---|
| 1650 | if (isset($statics[$name])) { |
|---|
| 1651 | $var = $statics[$name]; |
|---|
| 1652 | $resvar .= ' = '; |
|---|
| 1653 | $resvar .= str(value($var), $EX); |
|---|
| 1654 | } |
|---|
| 1655 | unset($statics); |
|---|
| 1656 | break 2; |
|---|
| 1657 | default: |
|---|
| 1658 | } |
|---|
| 1659 | } |
|---|
| 1660 | } |
|---|
| 1661 | // TODO: PHP_6 global |
|---|
| 1662 | $resvar = new Decompiler_Binop($this, $lvalue, XC_ASSIGN_REF, $rvalue); |
|---|
| 1663 | break; |
|---|
| 1664 | // }}} |
|---|
| 1665 | // {{{ case XC_FETCH_OBJ_* |
|---|
| 1666 | case XC_FETCH_OBJ_R: |
|---|
| 1667 | case XC_FETCH_OBJ_W: |
|---|
| 1668 | case XC_FETCH_OBJ_RW: |
|---|
| 1669 | case XC_FETCH_OBJ_FUNC_ARG: |
|---|
| 1670 | case XC_FETCH_OBJ_UNSET: |
|---|
| 1671 | case XC_FETCH_OBJ_IS: |
|---|
| 1672 | case XC_ASSIGN_OBJ: |
|---|
| 1673 | $obj = $this->getOpVal($op1, $EX); |
|---|
| 1674 | if (!isset($obj)) { |
|---|
| 1675 | $obj = '$this'; |
|---|
| 1676 | } |
|---|
| 1677 | $rvalue = str($obj) . "->" . unquoteVariableName($this->getOpVal($op2, $EX), $EX); |
|---|
| 1678 | if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 1679 | $resvar = $rvalue; |
|---|
| 1680 | } |
|---|
| 1681 | if ($opc == XC_ASSIGN_OBJ) { |
|---|
| 1682 | ++ $i; |
|---|
| 1683 | $lvalue = $rvalue; |
|---|
| 1684 | $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); |
|---|
| 1685 | $resvar = "$lvalue = " . str($rvalue); |
|---|
| 1686 | } |
|---|
| 1687 | break; |
|---|
| 1688 | // }}} |
|---|
| 1689 | case XC_ISSET_ISEMPTY_DIM_OBJ: |
|---|
| 1690 | case XC_ISSET_ISEMPTY_PROP_OBJ: |
|---|
| 1691 | case XC_ISSET_ISEMPTY: |
|---|
| 1692 | case XC_ISSET_ISEMPTY_VAR: // {{{ |
|---|
| 1693 | if ($opc == XC_ISSET_ISEMPTY_VAR) { |
|---|
| 1694 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 1695 | // for < PHP_5_3 |
|---|
| 1696 | if ($op1['op_type'] == XC_IS_CONST) { |
|---|
| 1697 | $rvalue = '$' . unquoteVariableName($this->getOpVal($op1, $EX)); |
|---|
| 1698 | } |
|---|
| 1699 | if ($op2['EA.type'] == ZEND_FETCH_STATIC_MEMBER) { |
|---|
| 1700 | $class = $this->getOpVal($op2, $EX); |
|---|
| 1701 | $rvalue = $class . '::' . $rvalue; |
|---|
| 1702 | } |
|---|
| 1703 | } |
|---|
| 1704 | else if ($opc == XC_ISSET_ISEMPTY) { |
|---|
| 1705 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 1706 | } |
|---|
| 1707 | else { |
|---|
| 1708 | $container = $this->getOpVal($op1, $EX); |
|---|
| 1709 | $dim = $this->getOpVal($op2, $EX); |
|---|
| 1710 | if ($opc == XC_ISSET_ISEMPTY_PROP_OBJ) { |
|---|
| 1711 | if (!isset($container)) { |
|---|
| 1712 | $container = '$this'; |
|---|
| 1713 | } |
|---|
| 1714 | $rvalue = $container . "->" . unquoteVariableName($dim); |
|---|
| 1715 | } |
|---|
| 1716 | else { |
|---|
| 1717 | $rvalue = $container . '[' . str($dim) .']'; |
|---|
| 1718 | } |
|---|
| 1719 | } |
|---|
| 1720 | |
|---|
| 1721 | switch ((!ZEND_ENGINE_2 ? $op['op2']['var'] /* constant */ : $ext) & (ZEND_ISSET|ZEND_ISEMPTY)) { |
|---|
| 1722 | case ZEND_ISSET: |
|---|
| 1723 | $rvalue = "isset(" . str($rvalue) . ")"; |
|---|
| 1724 | break; |
|---|
| 1725 | case ZEND_ISEMPTY: |
|---|
| 1726 | $rvalue = "empty(" . str($rvalue) . ")"; |
|---|
| 1727 | break; |
|---|
| 1728 | } |
|---|
| 1729 | $resvar = $rvalue; |
|---|
| 1730 | break; |
|---|
| 1731 | // }}} |
|---|
| 1732 | case XC_SEND_VAR_NO_REF: |
|---|
| 1733 | case XC_SEND_VAL: |
|---|
| 1734 | case XC_SEND_REF: |
|---|
| 1735 | case XC_SEND_VAR: // {{{ |
|---|
| 1736 | $ref = ($opc == XC_SEND_REF ? '&' : ''); |
|---|
| 1737 | $EX['argstack'][] = $ref . str($this->getOpVal($op1, $EX)); |
|---|
| 1738 | break; |
|---|
| 1739 | // }}} |
|---|
| 1740 | case XC_INIT_STATIC_METHOD_CALL: |
|---|
| 1741 | case XC_INIT_METHOD_CALL: // {{{ |
|---|
| 1742 | array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); |
|---|
| 1743 | if ($opc == XC_INIT_STATIC_METHOD_CALL || $opc == XC_INIT_METHOD_CALL || $op1['op_type'] != XC_IS_UNUSED) { |
|---|
| 1744 | $obj = $this->getOpVal($op1, $EX); |
|---|
| 1745 | if (!isset($obj)) { |
|---|
| 1746 | $obj = '$this'; |
|---|
| 1747 | } |
|---|
| 1748 | if ($opc == XC_INIT_STATIC_METHOD_CALL || /* PHP4 */ isset($op1['constant'])) { |
|---|
| 1749 | $EX['object'] = null; |
|---|
| 1750 | $EX['called_scope'] = $this->stripNamespace(unquoteName($obj, $EX)); |
|---|
| 1751 | } |
|---|
| 1752 | else { |
|---|
| 1753 | $EX['object'] = $obj; |
|---|
| 1754 | $EX['called_scope'] = null; |
|---|
| 1755 | } |
|---|
| 1756 | if ($res['op_type'] != XC_IS_UNUSED) { |
|---|
| 1757 | $resvar = '$obj call$'; |
|---|
| 1758 | } |
|---|
| 1759 | } |
|---|
| 1760 | else { |
|---|
| 1761 | $EX['object'] = null; |
|---|
| 1762 | $EX['called_scope'] = null; |
|---|
| 1763 | } |
|---|
| 1764 | |
|---|
| 1765 | $EX['fbc'] = $this->getOpVal($op2, $EX); |
|---|
| 1766 | if (($opc == XC_INIT_STATIC_METHOD_CALL || $opc == XC_INIT_METHOD_CALL) && !isset($EX['fbc'])) { |
|---|
| 1767 | $EX['fbc'] = '__construct'; |
|---|
| 1768 | } |
|---|
| 1769 | break; |
|---|
| 1770 | // }}} |
|---|
| 1771 | case XC_INIT_NS_FCALL_BY_NAME: |
|---|
| 1772 | case XC_INIT_FCALL_BY_NAME: // {{{ |
|---|
| 1773 | array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); |
|---|
| 1774 | if (!ZEND_ENGINE_2 && ($ext & ZEND_CTOR_CALL)) { |
|---|
| 1775 | break; |
|---|
| 1776 | } |
|---|
| 1777 | $EX['object'] = null; |
|---|
| 1778 | $EX['called_scope'] = null; |
|---|
| 1779 | $EX['fbc'] = $this->getOpVal($op2, $EX); |
|---|
| 1780 | break; |
|---|
| 1781 | // }}} |
|---|
| 1782 | case XC_INIT_FCALL_BY_FUNC: // {{{ deprecated even in PHP 4? |
|---|
| 1783 | $EX['object'] = null; |
|---|
| 1784 | $EX['called_scope'] = null; |
|---|
| 1785 | $which = $op1['var']; |
|---|
| 1786 | $EX['fbc'] = $EX['op_array']['funcs'][$which]['name']; |
|---|
| 1787 | break; |
|---|
| 1788 | // }}} |
|---|
| 1789 | case XC_DO_FCALL_BY_FUNC: |
|---|
| 1790 | $which = $op1['var']; |
|---|
| 1791 | $fname = $EX['op_array']['funcs'][$which]['name']; |
|---|
| 1792 | $args = $this->popargs($EX, $ext); |
|---|
| 1793 | $resvar = $fname . "($args)"; |
|---|
| 1794 | break; |
|---|
| 1795 | case XC_DO_FCALL: |
|---|
| 1796 | $fname = unquoteName($this->getOpVal($op1, $EX), $EX); |
|---|
| 1797 | $args = $this->popargs($EX, $ext); |
|---|
| 1798 | $resvar = $fname . "($args)"; |
|---|
| 1799 | break; |
|---|
| 1800 | case XC_DO_FCALL_BY_NAME: // {{{ |
|---|
| 1801 | $object = null; |
|---|
| 1802 | |
|---|
| 1803 | $fname = unquoteName($EX['fbc'], $EX); |
|---|
| 1804 | if (!is_int($EX['object'])) { |
|---|
| 1805 | $object = $EX['object']; |
|---|
| 1806 | } |
|---|
| 1807 | |
|---|
| 1808 | $args = $this->popargs($EX, $ext); |
|---|
| 1809 | |
|---|
| 1810 | $prefix = (isset($object) ? $object . '->' : '' ) |
|---|
| 1811 | . (isset($EX['called_scope']) ? $EX['called_scope'] . '::' : '' ); |
|---|
| 1812 | $resvar = $prefix |
|---|
| 1813 | . (!$prefix ? $this->stripNamespace($fname) : $fname) |
|---|
| 1814 | . "($args)"; |
|---|
| 1815 | unset($args); |
|---|
| 1816 | |
|---|
| 1817 | if (is_int($EX['object'])) { |
|---|
| 1818 | $T[$EX['object']] = $resvar; |
|---|
| 1819 | $resvar = null; |
|---|
| 1820 | } |
|---|
| 1821 | list($EX['fbc'], $EX['object'], $EX['called_scope']) = array_pop($EX['arg_types_stack']); |
|---|
| 1822 | break; |
|---|
| 1823 | // }}} |
|---|
| 1824 | case XC_VERIFY_ABSTRACT_CLASS: // {{{ |
|---|
| 1825 | //unset($T[$op1['var']]); |
|---|
| 1826 | break; |
|---|
| 1827 | // }}} |
|---|
| 1828 | case XC_DECLARE_CLASS: |
|---|
| 1829 | case XC_DECLARE_INHERITED_CLASS: |
|---|
| 1830 | case XC_DECLARE_INHERITED_CLASS_DELAYED: // {{{ |
|---|
| 1831 | $key = $op1['constant']; |
|---|
| 1832 | if (!isset($this->dc['class_table'][$key])) { |
|---|
| 1833 | echo 'class not found: ', $key, 'existing classes are:', "\n"; |
|---|
| 1834 | var_dump(array_keys($this->dc['class_table'])); |
|---|
| 1835 | exit; |
|---|
| 1836 | } |
|---|
| 1837 | $class = &$this->dc['class_table'][$key]; |
|---|
| 1838 | if (!isset($class['name'])) { |
|---|
| 1839 | $class['name'] = unquoteName($this->getOpVal($op2, $EX), $EX); |
|---|
| 1840 | } |
|---|
| 1841 | if ($opc == XC_DECLARE_INHERITED_CLASS || $opc == XC_DECLARE_INHERITED_CLASS_DELAYED) { |
|---|
| 1842 | $ext /= XC_SIZEOF_TEMP_VARIABLE; |
|---|
| 1843 | $class['parent'] = $T[$ext]; |
|---|
| 1844 | unset($T[$ext]); |
|---|
| 1845 | } |
|---|
| 1846 | else { |
|---|
| 1847 | $class['parent'] = null; |
|---|
| 1848 | } |
|---|
| 1849 | |
|---|
| 1850 | for (;;) { |
|---|
| 1851 | if ($i + 1 <= $range[1] |
|---|
| 1852 | && $opcodes[$i + 1]['opcode'] == XC_ADD_INTERFACE |
|---|
| 1853 | && $opcodes[$i + 1]['op1']['var'] == $res['var']) { |
|---|
| 1854 | // continue |
|---|
| 1855 | } |
|---|
| 1856 | else if ($i + 2 <= $range[1] |
|---|
| 1857 | && $opcodes[$i + 2]['opcode'] == XC_ADD_INTERFACE |
|---|
| 1858 | && $opcodes[$i + 2]['op1']['var'] == $res['var'] |
|---|
| 1859 | && $opcodes[$i + 1]['opcode'] == XC_FETCH_CLASS) { |
|---|
| 1860 | // continue |
|---|
| 1861 | } |
|---|
| 1862 | else { |
|---|
| 1863 | break; |
|---|
| 1864 | } |
|---|
| 1865 | $this->usedOps[XC_ADD_INTERFACE] = true; |
|---|
| 1866 | |
|---|
| 1867 | $fetchop = &$opcodes[$i + 1]; |
|---|
| 1868 | $interface = $this->stripNamespace(unquoteName($this->getOpVal($fetchop['op2'], $EX), $EX)); |
|---|
| 1869 | $addop = &$opcodes[$i + 2]; |
|---|
| 1870 | $class['interfaces'][$addop['extended_value']] = $interface; |
|---|
| 1871 | unset($fetchop, $addop); |
|---|
| 1872 | $i += 2; |
|---|
| 1873 | } |
|---|
| 1874 | $this->dclass($class); |
|---|
| 1875 | echo "\n"; |
|---|
| 1876 | unset($class); |
|---|
| 1877 | break; |
|---|
| 1878 | // }}} |
|---|
| 1879 | case XC_INIT_STRING: // {{{ |
|---|
| 1880 | $resvar = "''"; |
|---|
| 1881 | break; |
|---|
| 1882 | // }}} |
|---|
| 1883 | case XC_ADD_CHAR: |
|---|
| 1884 | case XC_ADD_STRING: |
|---|
| 1885 | case XC_ADD_VAR: // {{{ |
|---|
| 1886 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1887 | $op2val = $this->getOpVal($op2, $EX); |
|---|
| 1888 | switch ($opc) { |
|---|
| 1889 | case XC_ADD_CHAR: |
|---|
| 1890 | $op2val = value(chr(str($op2val))); |
|---|
| 1891 | break; |
|---|
| 1892 | case XC_ADD_STRING: |
|---|
| 1893 | break; |
|---|
| 1894 | case XC_ADD_VAR: |
|---|
| 1895 | break; |
|---|
| 1896 | } |
|---|
| 1897 | if (str($op1val) == "''") { |
|---|
| 1898 | $rvalue = $op2val; |
|---|
| 1899 | } |
|---|
| 1900 | else if (str($op2val) == "''") { |
|---|
| 1901 | $rvalue = $op1val; |
|---|
| 1902 | } |
|---|
| 1903 | else { |
|---|
| 1904 | $rvalue = str($op1val) . ' . ' . str($op2val); |
|---|
| 1905 | } |
|---|
| 1906 | $resvar = $rvalue; |
|---|
| 1907 | // }}} |
|---|
| 1908 | break; |
|---|
| 1909 | case XC_PRINT: // {{{ |
|---|
| 1910 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1911 | $resvar = "print(" . str($op1val) . ")"; |
|---|
| 1912 | break; |
|---|
| 1913 | // }}} |
|---|
| 1914 | case XC_ECHO: // {{{ |
|---|
| 1915 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1916 | $resvar = "echo " . str($op1val); |
|---|
| 1917 | break; |
|---|
| 1918 | // }}} |
|---|
| 1919 | case XC_EXIT: // {{{ |
|---|
| 1920 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 1921 | $resvar = "exit($op1val)"; |
|---|
| 1922 | break; |
|---|
| 1923 | // }}} |
|---|
| 1924 | case XC_INIT_ARRAY: |
|---|
| 1925 | case XC_ADD_ARRAY_ELEMENT: // {{{ |
|---|
| 1926 | $rvalue = $this->getOpVal($op1, $EX, true); |
|---|
| 1927 | |
|---|
| 1928 | if ($opc == XC_ADD_ARRAY_ELEMENT) { |
|---|
| 1929 | $assoc = $this->getOpVal($op2, $EX); |
|---|
| 1930 | if (isset($assoc)) { |
|---|
| 1931 | $curResVar->value[] = array($assoc, $rvalue); |
|---|
| 1932 | } |
|---|
| 1933 | else { |
|---|
| 1934 | $curResVar->value[] = array(null, $rvalue); |
|---|
| 1935 | } |
|---|
| 1936 | } |
|---|
| 1937 | else { |
|---|
| 1938 | if ($opc == XC_INIT_ARRAY) { |
|---|
| 1939 | $resvar = new Decompiler_Array(); |
|---|
| 1940 | if (!isset($rvalue)) { |
|---|
| 1941 | continue; |
|---|
| 1942 | } |
|---|
| 1943 | } |
|---|
| 1944 | |
|---|
| 1945 | $assoc = $this->getOpVal($op2, $EX); |
|---|
| 1946 | if (isset($assoc)) { |
|---|
| 1947 | $resvar->value[] = array($assoc, $rvalue); |
|---|
| 1948 | } |
|---|
| 1949 | else { |
|---|
| 1950 | $resvar->value[] = array(null, $rvalue); |
|---|
| 1951 | } |
|---|
| 1952 | } |
|---|
| 1953 | break; |
|---|
| 1954 | // }}} |
|---|
| 1955 | case XC_QM_ASSIGN: // {{{ |
|---|
| 1956 | if (isset($curResVar) && is_a($curResVar, 'Decompiler_Binop')) { |
|---|
| 1957 | $curResVar->op2 = $this->getOpVal($op1, $EX); |
|---|
| 1958 | } |
|---|
| 1959 | else { |
|---|
| 1960 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1961 | } |
|---|
| 1962 | break; |
|---|
| 1963 | // }}} |
|---|
| 1964 | case XC_BOOL: // {{{ |
|---|
| 1965 | $resvar = /*'(bool) ' .*/ $this->getOpVal($op1, $EX); |
|---|
| 1966 | break; |
|---|
| 1967 | // }}} |
|---|
| 1968 | case XC_RETURN: // {{{ |
|---|
| 1969 | $resvar = "return " . str($this->getOpVal($op1, $EX)); |
|---|
| 1970 | break; |
|---|
| 1971 | // }}} |
|---|
| 1972 | case XC_INCLUDE_OR_EVAL: // {{{ |
|---|
| 1973 | $type = $op2['var']; // hack |
|---|
| 1974 | $keyword = $this->includeTypes[$type]; |
|---|
| 1975 | $resvar = "$keyword " . str($this->getOpVal($op1, $EX)); |
|---|
| 1976 | break; |
|---|
| 1977 | // }}} |
|---|
| 1978 | case XC_FE_RESET: // {{{ |
|---|
| 1979 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 1980 | break; |
|---|
| 1981 | // }}} |
|---|
| 1982 | case XC_FE_FETCH: // {{{ |
|---|
| 1983 | $op['fe_src'] = $this->getOpVal($op1, $EX, true); |
|---|
| 1984 | $fe = new Decompiler_ForeachBox($op); |
|---|
| 1985 | $fe->iskey = false; |
|---|
| 1986 | $T[$res['var']] = $fe; |
|---|
| 1987 | |
|---|
| 1988 | ++ $i; |
|---|
| 1989 | if (($ext & ZEND_FE_FETCH_WITH_KEY)) { |
|---|
| 1990 | $fe = new Decompiler_ForeachBox($op); |
|---|
| 1991 | $fe->iskey = true; |
|---|
| 1992 | |
|---|
| 1993 | $res = $opcodes[$i]['result']; |
|---|
| 1994 | $T[$res['var']] = $fe; |
|---|
| 1995 | } |
|---|
| 1996 | break; |
|---|
| 1997 | // }}} |
|---|
| 1998 | case XC_SWITCH_FREE: // {{{ |
|---|
| 1999 | break; |
|---|
| 2000 | // }}} |
|---|
| 2001 | case XC_FREE: // {{{ |
|---|
| 2002 | $free = $T[$op1['var']]; |
|---|
| 2003 | if (!is_a($free, 'Decompiler_Array') && !is_a($free, 'Decompiler_Box')) { |
|---|
| 2004 | $op['php'] = is_object($free) ? $free : $this->unquote($free, '(', ')'); |
|---|
| 2005 | $lastphpop = &$op; |
|---|
| 2006 | } |
|---|
| 2007 | unset($T[$op1['var']], $free); |
|---|
| 2008 | break; |
|---|
| 2009 | // }}} |
|---|
| 2010 | case XC_JMP_NO_CTOR: |
|---|
| 2011 | break; |
|---|
| 2012 | case XC_JMP_SET: // ?: |
|---|
| 2013 | $resvar = new Decompiler_Binop($this, $this->getOpVal($op1, $EX), XC_JMP_SET, null); |
|---|
| 2014 | break; |
|---|
| 2015 | case XC_JMPZ_EX: // and |
|---|
| 2016 | case XC_JMPNZ_EX: // or |
|---|
| 2017 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 2018 | break; |
|---|
| 2019 | |
|---|
| 2020 | case XC_JMPNZ: // while |
|---|
| 2021 | case XC_JMPZNZ: // for |
|---|
| 2022 | case XC_JMPZ: // {{{ |
|---|
| 2023 | if ($opc == XC_JMP_NO_CTOR && $EX['object']) { |
|---|
| 2024 | $rvalue = $EX['object']; |
|---|
| 2025 | } |
|---|
| 2026 | else { |
|---|
| 2027 | $rvalue = $this->getOpVal($op1, $EX); |
|---|
| 2028 | } |
|---|
| 2029 | |
|---|
| 2030 | if (isset($op['cond_true'])) { |
|---|
| 2031 | // any true comes here, so it's a "or" |
|---|
| 2032 | $rvalue = implode(' or ', $op['cond_true']) . ' or ' . $rvalue; |
|---|
| 2033 | unset($op['cond_true']); |
|---|
| 2034 | } |
|---|
| 2035 | if (isset($op['cond_false'])) { |
|---|
| 2036 | echo "TODO(cond_false):\n"; |
|---|
| 2037 | var_dump($op);// exit; |
|---|
| 2038 | } |
|---|
| 2039 | $op['cond'] = $rvalue; |
|---|
| 2040 | $op['isjmp'] = true; |
|---|
| 2041 | break; |
|---|
| 2042 | // }}} |
|---|
| 2043 | case XC_CONT: |
|---|
| 2044 | case XC_BRK: |
|---|
| 2045 | $op['cond'] = null; |
|---|
| 2046 | $op['isjmp'] = true; |
|---|
| 2047 | $resvar = $opc == XC_CONT ? 'continue' : 'break'; |
|---|
| 2048 | $count = str($this->getOpVal($op2, $EX)); |
|---|
| 2049 | if ($count != '1') { |
|---|
| 2050 | $resvar .= ' ' . $count; |
|---|
| 2051 | } |
|---|
| 2052 | break; |
|---|
| 2053 | case XC_GOTO: |
|---|
| 2054 | $resvar = 'goto label' . $op['op1']['var']; |
|---|
| 2055 | $istmpres = false; |
|---|
| 2056 | break; |
|---|
| 2057 | |
|---|
| 2058 | case XC_JMP: // {{{ |
|---|
| 2059 | $op['cond'] = null; |
|---|
| 2060 | $op['isjmp'] = true; |
|---|
| 2061 | break; |
|---|
| 2062 | // }}} |
|---|
| 2063 | case XC_CASE: |
|---|
| 2064 | // $switchValue = $this->getOpVal($op1, $EX); |
|---|
| 2065 | $caseValue = $this->getOpVal($op2, $EX); |
|---|
| 2066 | $resvar = $caseValue; |
|---|
| 2067 | break; |
|---|
| 2068 | case XC_RECV_INIT: |
|---|
| 2069 | case XC_RECV: |
|---|
| 2070 | $offset = $this->getOpVal($op1, $EX); |
|---|
| 2071 | $lvalue = $this->getOpVal($op['result'], $EX); |
|---|
| 2072 | if ($opc == XC_RECV_INIT) { |
|---|
| 2073 | $default = value($op['op2']['constant']); |
|---|
| 2074 | } |
|---|
| 2075 | else { |
|---|
| 2076 | $default = null; |
|---|
| 2077 | } |
|---|
| 2078 | $EX['recvs'][str($offset)] = array($lvalue, $default); |
|---|
| 2079 | break; |
|---|
| 2080 | case XC_POST_DEC: |
|---|
| 2081 | case XC_POST_INC: |
|---|
| 2082 | case XC_POST_DEC_OBJ: |
|---|
| 2083 | case XC_POST_INC_OBJ: |
|---|
| 2084 | case XC_PRE_DEC: |
|---|
| 2085 | case XC_PRE_INC: |
|---|
| 2086 | case XC_PRE_DEC_OBJ: |
|---|
| 2087 | case XC_PRE_INC_OBJ: // {{{ |
|---|
| 2088 | $flags = array_flip(explode('_', $opname)); |
|---|
| 2089 | if (isset($flags['OBJ'])) { |
|---|
| 2090 | $resvar = $this->getOpVal($op1, $EX) . '->' . unquoteVariableName($this->getOpVal($op2, $EX), $EX); |
|---|
| 2091 | } |
|---|
| 2092 | else { |
|---|
| 2093 | $resvar = $this->getOpVal($op1, $EX); |
|---|
| 2094 | } |
|---|
| 2095 | $opstr = isset($flags['DEC']) ? '--' : '++'; |
|---|
| 2096 | if (isset($flags['POST'])) { |
|---|
| 2097 | $resvar .= $opstr; |
|---|
| 2098 | } |
|---|
| 2099 | else { |
|---|
| 2100 | $resvar = "$opstr$resvar"; |
|---|
| 2101 | } |
|---|
| 2102 | break; |
|---|
| 2103 | // }}} |
|---|
| 2104 | |
|---|
| 2105 | case XC_BEGIN_SILENCE: // {{{ |
|---|
| 2106 | $EX['silence'] ++; |
|---|
| 2107 | break; |
|---|
| 2108 | // }}} |
|---|
| 2109 | case XC_END_SILENCE: // {{{ |
|---|
| 2110 | $EX['silence'] --; |
|---|
| 2111 | $lastresvar = '@' . str($lastresvar, $EX); |
|---|
| 2112 | break; |
|---|
| 2113 | // }}} |
|---|
| 2114 | case XC_CAST: // {{{ |
|---|
| 2115 | $type = $ext; |
|---|
| 2116 | static $type2cast = array( |
|---|
| 2117 | IS_LONG => '(int)', |
|---|
| 2118 | IS_DOUBLE => '(double)', |
|---|
| 2119 | IS_STRING => '(string)', |
|---|
| 2120 | IS_ARRAY => '(array)', |
|---|
| 2121 | IS_OBJECT => '(object)', |
|---|
| 2122 | IS_BOOL => '(bool)', |
|---|
| 2123 | IS_NULL => '(unset)', |
|---|
| 2124 | ); |
|---|
| 2125 | assert(isset($type2cast[$type])); |
|---|
| 2126 | $cast = $type2cast[$type]; |
|---|
| 2127 | $resvar = $cast . ' ' . $this->getOpVal($op1, $EX); |
|---|
| 2128 | break; |
|---|
| 2129 | // }}} |
|---|
| 2130 | case XC_EXT_STMT: |
|---|
| 2131 | case XC_EXT_FCALL_BEGIN: |
|---|
| 2132 | case XC_EXT_FCALL_END: |
|---|
| 2133 | case XC_EXT_NOP: |
|---|
| 2134 | break; |
|---|
| 2135 | case XC_DECLARE_FUNCTION: |
|---|
| 2136 | $this->dfunction($this->dc['function_table'][$op1['constant']], $EX['indent']); |
|---|
| 2137 | break; |
|---|
| 2138 | case XC_DECLARE_LAMBDA_FUNCTION: // {{{ |
|---|
| 2139 | ob_start(); |
|---|
| 2140 | $this->dfunction($this->dc['function_table'][$op1['constant']], $EX['indent']); |
|---|
| 2141 | $resvar = ob_get_clean(); |
|---|
| 2142 | $istmpres = true; |
|---|
| 2143 | break; |
|---|
| 2144 | // }}} |
|---|
| 2145 | case XC_DECLARE_CONST: |
|---|
| 2146 | $name = $this->stripNamespace(unquoteName($this->getOpVal($op1, $EX), $EX)); |
|---|
| 2147 | $value = str($this->getOpVal($op2, $EX)); |
|---|
| 2148 | $resvar = 'const ' . $name . ' = ' . $value; |
|---|
| 2149 | break; |
|---|
| 2150 | case XC_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 2151 | /* always removed by compiler */ |
|---|
| 2152 | break; |
|---|
| 2153 | case XC_TICKS: |
|---|
| 2154 | $lastphpop['ticks'] = $this->getOpVal($op1, $EX); |
|---|
| 2155 | // $EX['tickschanged'] = true; |
|---|
| 2156 | break; |
|---|
| 2157 | case XC_RAISE_ABSTRACT_ERROR: |
|---|
| 2158 | // abstract function body is empty, don't need this code |
|---|
| 2159 | break; |
|---|
| 2160 | case XC_USER_OPCODE: |
|---|
| 2161 | echo '// ZEND_USER_OPCODE, impossible to decompile'; |
|---|
| 2162 | break; |
|---|
| 2163 | case XC_OP_DATA: |
|---|
| 2164 | break; |
|---|
| 2165 | default: // {{{ |
|---|
| 2166 | $call = array(&$this, $opname); |
|---|
| 2167 | if (is_callable($call)) { |
|---|
| 2168 | $this->usedOps[$opc] = true; |
|---|
| 2169 | $this->{$opname}($op, $EX); |
|---|
| 2170 | } |
|---|
| 2171 | else if (isset($this->binops[$opc])) { // {{{ |
|---|
| 2172 | $this->usedOps[$opc] = true; |
|---|
| 2173 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 2174 | $op2val = $this->getOpVal($op2, $EX); |
|---|
| 2175 | $rvalue = new Decompiler_Binop($this, $op1val, $opc, $op2val); |
|---|
| 2176 | $resvar = $rvalue; |
|---|
| 2177 | // }}} |
|---|
| 2178 | } |
|---|
| 2179 | else if (isset($this->unaryops[$opc])) { // {{{ |
|---|
| 2180 | $this->usedOps[$opc] = true; |
|---|
| 2181 | $op1val = $this->getOpVal($op1, $EX); |
|---|
| 2182 | $myop = $this->unaryops[$opc]; |
|---|
| 2183 | $rvalue = $myop . str($op1val); |
|---|
| 2184 | $resvar = $rvalue; |
|---|
| 2185 | // }}} |
|---|
| 2186 | } |
|---|
| 2187 | else { |
|---|
| 2188 | $notHandled = true; |
|---|
| 2189 | } |
|---|
| 2190 | // }}} |
|---|
| 2191 | } |
|---|
| 2192 | if ($notHandled) { |
|---|
| 2193 | echo "\x1B[31m * TODO ", $opname, "\x1B[0m\n"; |
|---|
| 2194 | } |
|---|
| 2195 | else { |
|---|
| 2196 | $this->usedOps[$opc] = true; |
|---|
| 2197 | } |
|---|
| 2198 | |
|---|
| 2199 | if (isset($resvar)) { |
|---|
| 2200 | if ($istmpres) { |
|---|
| 2201 | $T[$res['var']] = $resvar; |
|---|
| 2202 | $lastresvar = &$T[$res['var']]; |
|---|
| 2203 | } |
|---|
| 2204 | else { |
|---|
| 2205 | $op['php'] = $resvar; |
|---|
| 2206 | $lastphpop = &$op; |
|---|
| 2207 | $lastresvar = &$op['php']; |
|---|
| 2208 | } |
|---|
| 2209 | } |
|---|
| 2210 | } |
|---|
| 2211 | return $T; |
|---|
| 2212 | } |
|---|
| 2213 | // }}} |
|---|
| 2214 | function unquote($str, $st, $ed) // {{{ |
|---|
| 2215 | { |
|---|
| 2216 | $l1 = strlen($st); |
|---|
| 2217 | $l2 = strlen($ed); |
|---|
| 2218 | if (substr($str, 0, $l1) === $st && substr($str, -$l2) === $ed) { |
|---|
| 2219 | $str = substr($str, $l1, -$l2); |
|---|
| 2220 | } |
|---|
| 2221 | return $str; |
|---|
| 2222 | } |
|---|
| 2223 | // }}} |
|---|
| 2224 | function popargs(&$EX, $n) // {{{ |
|---|
| 2225 | { |
|---|
| 2226 | $args = array(); |
|---|
| 2227 | for ($i = 0; $i < $n; $i ++) { |
|---|
| 2228 | $a = array_pop($EX['argstack']); |
|---|
| 2229 | if (is_array($a)) { |
|---|
| 2230 | array_unshift($args, foldToCode($a, $EX)); |
|---|
| 2231 | } |
|---|
| 2232 | else { |
|---|
| 2233 | array_unshift($args, $a); |
|---|
| 2234 | } |
|---|
| 2235 | } |
|---|
| 2236 | return implode(', ', $args); |
|---|
| 2237 | } |
|---|
| 2238 | // }}} |
|---|
| 2239 | function dumpop($op, &$EX) // {{{ |
|---|
| 2240 | { |
|---|
| 2241 | assert('isset($op)'); |
|---|
| 2242 | $op1 = $op['op1']; |
|---|
| 2243 | $op2 = $op['op2']; |
|---|
| 2244 | $d = array(xcache_get_opcode($op['opcode']), $op['opcode']); |
|---|
| 2245 | |
|---|
| 2246 | foreach (array('op1' => '1:', 'op2' => '2:', 'result' => '>') as $k => $kk) { |
|---|
| 2247 | switch ($op[$k]['op_type']) { |
|---|
| 2248 | case XC_IS_UNUSED: |
|---|
| 2249 | $d[$kk] = 'U:' . $op[$k]['opline_num']; |
|---|
| 2250 | break; |
|---|
| 2251 | |
|---|
| 2252 | case XC_IS_VAR: |
|---|
| 2253 | $d[$kk] = '$' . $op[$k]['var']; |
|---|
| 2254 | if ($k != 'result') { |
|---|
| 2255 | $d[$kk] .= ':' . str($this->getOpVal($op[$k], $EX)); |
|---|
| 2256 | } |
|---|
| 2257 | break; |
|---|
| 2258 | |
|---|
| 2259 | case XC_IS_TMP_VAR: |
|---|
| 2260 | $d[$kk] = '#' . $op[$k]['var']; |
|---|
| 2261 | if ($k != 'result') { |
|---|
| 2262 | $d[$kk] .= ':' . str($this->getOpVal($op[$k], $EX)); |
|---|
| 2263 | } |
|---|
| 2264 | break; |
|---|
| 2265 | |
|---|
| 2266 | case XC_IS_CV: |
|---|
| 2267 | $d[$kk] = $this->getOpVal($op[$k], $EX); |
|---|
| 2268 | break; |
|---|
| 2269 | |
|---|
| 2270 | default: |
|---|
| 2271 | if ($k == 'result') { |
|---|
| 2272 | var_dump($op); |
|---|
| 2273 | assert(0); |
|---|
| 2274 | exit; |
|---|
| 2275 | } |
|---|
| 2276 | else { |
|---|
| 2277 | $d[$kk] = $this->getOpVal($op[$k], $EX); |
|---|
| 2278 | } |
|---|
| 2279 | } |
|---|
| 2280 | } |
|---|
| 2281 | $d[';'] = $op['extended_value']; |
|---|
| 2282 | if (!empty($op['jmpouts'])) { |
|---|
| 2283 | $d['>>'] = implode(',', $op['jmpouts']); |
|---|
| 2284 | } |
|---|
| 2285 | if (!empty($op['jmpins'])) { |
|---|
| 2286 | $d['<<'] = implode(',', $op['jmpins']); |
|---|
| 2287 | } |
|---|
| 2288 | |
|---|
| 2289 | foreach ($d as $k => $v) { |
|---|
| 2290 | echo is_int($k) ? '' : $k, str($v), "\t"; |
|---|
| 2291 | } |
|---|
| 2292 | echo PHP_EOL; |
|---|
| 2293 | } |
|---|
| 2294 | // }}} |
|---|
| 2295 | function dumpRange(&$EX, $range, $indent = '') // {{{ |
|---|
| 2296 | { |
|---|
| 2297 | for ($i = $range[0]; $i <= $range[1]; ++$i) { |
|---|
| 2298 | echo $indent, $i, "\t"; $this->dumpop($EX['opcodes'][$i], $EX); |
|---|
| 2299 | } |
|---|
| 2300 | echo $indent, "==", PHP_EOL; |
|---|
| 2301 | } |
|---|
| 2302 | // }}} |
|---|
| 2303 | function dargs(&$EX, $indent) // {{{ |
|---|
| 2304 | { |
|---|
| 2305 | $op_array = &$EX['op_array']; |
|---|
| 2306 | |
|---|
| 2307 | if (isset($op_array['num_args'])) { |
|---|
| 2308 | $c = $op_array['num_args']; |
|---|
| 2309 | } |
|---|
| 2310 | else if ($op_array['arg_types']) { |
|---|
| 2311 | $c = count($op_array['arg_types']); |
|---|
| 2312 | } |
|---|
| 2313 | else { |
|---|
| 2314 | // php4 |
|---|
| 2315 | $c = count($EX['recvs']); |
|---|
| 2316 | } |
|---|
| 2317 | |
|---|
| 2318 | $refrest = false; |
|---|
| 2319 | for ($i = 0; $i < $c; $i ++) { |
|---|
| 2320 | if ($i) { |
|---|
| 2321 | echo ', '; |
|---|
| 2322 | } |
|---|
| 2323 | $arg = $EX['recvs'][$i + 1]; |
|---|
| 2324 | if (isset($op_array['arg_info'])) { |
|---|
| 2325 | $ai = $op_array['arg_info'][$i]; |
|---|
| 2326 | if (!empty($ai['class_name'])) { |
|---|
| 2327 | echo $this->stripNamespace($ai['class_name']), ' '; |
|---|
| 2328 | if (!ZEND_ENGINE_2_2 && $ai['allow_null']) { |
|---|
| 2329 | echo 'or NULL '; |
|---|
| 2330 | } |
|---|
| 2331 | } |
|---|
| 2332 | else if (!empty($ai['array_type_hint'])) { |
|---|
| 2333 | echo 'array '; |
|---|
| 2334 | if (!ZEND_ENGINE_2_2 && $ai['allow_null']) { |
|---|
| 2335 | echo 'or NULL '; |
|---|
| 2336 | } |
|---|
| 2337 | } |
|---|
| 2338 | if ($ai['pass_by_reference']) { |
|---|
| 2339 | echo '&'; |
|---|
| 2340 | } |
|---|
| 2341 | printf("\$%s", $ai['name']); |
|---|
| 2342 | } |
|---|
| 2343 | else { |
|---|
| 2344 | if ($refrest) { |
|---|
| 2345 | echo '&'; |
|---|
| 2346 | } |
|---|
| 2347 | else if (isset($op_array['arg_types'][$i])) { |
|---|
| 2348 | switch ($op_array['arg_types'][$i]) { |
|---|
| 2349 | case BYREF_FORCE_REST: |
|---|
| 2350 | $refrest = true; |
|---|
| 2351 | /* fall */ |
|---|
| 2352 | case BYREF_FORCE: |
|---|
| 2353 | echo '&'; |
|---|
| 2354 | break; |
|---|
| 2355 | |
|---|
| 2356 | case BYREF_NONE: |
|---|
| 2357 | case BYREF_ALLOW: |
|---|
| 2358 | break; |
|---|
| 2359 | default: |
|---|
| 2360 | assert(0); |
|---|
| 2361 | } |
|---|
| 2362 | } |
|---|
| 2363 | echo str($arg[0], $indent); |
|---|
| 2364 | } |
|---|
| 2365 | if (isset($arg[1])) { |
|---|
| 2366 | echo ' = ', str($arg[1], $indent); |
|---|
| 2367 | } |
|---|
| 2368 | } |
|---|
| 2369 | } |
|---|
| 2370 | // }}} |
|---|
| 2371 | function duses(&$EX, $indent) // {{{ |
|---|
| 2372 | { |
|---|
| 2373 | if ($EX['uses']) { |
|---|
| 2374 | echo ' use(', implode(', ', $EX['uses']), ')'; |
|---|
| 2375 | } |
|---|
| 2376 | } |
|---|
| 2377 | // }}} |
|---|
| 2378 | function dfunction($func, $indent = '', $nobody = false) // {{{ |
|---|
| 2379 | { |
|---|
| 2380 | $this->detectNamespace($func['op_array']['function_name']); |
|---|
| 2381 | |
|---|
| 2382 | if ($nobody) { |
|---|
| 2383 | $EX = array(); |
|---|
| 2384 | $EX['op_array'] = &$func['op_array']; |
|---|
| 2385 | $EX['recvs'] = array(); |
|---|
| 2386 | $EX['uses'] = array(); |
|---|
| 2387 | } |
|---|
| 2388 | else { |
|---|
| 2389 | ob_start(); |
|---|
| 2390 | $newindent = INDENT . $indent; |
|---|
| 2391 | $EX = &$this->dop_array($func['op_array'], $newindent); |
|---|
| 2392 | $body = ob_get_clean(); |
|---|
| 2393 | } |
|---|
| 2394 | |
|---|
| 2395 | $functionName = $this->stripNamespace($func['op_array']['function_name']); |
|---|
| 2396 | if ($functionName == '{closure}') { |
|---|
| 2397 | $functionName = ''; |
|---|
| 2398 | } |
|---|
| 2399 | echo 'function', $functionName ? ' ' . $functionName : '', '('; |
|---|
| 2400 | $this->dargs($EX, $indent); |
|---|
| 2401 | echo ")"; |
|---|
| 2402 | $this->duses($EX, $indent); |
|---|
| 2403 | if ($nobody) { |
|---|
| 2404 | echo ";\n"; |
|---|
| 2405 | } |
|---|
| 2406 | else { |
|---|
| 2407 | if ($functionName !== '') { |
|---|
| 2408 | echo "\n"; |
|---|
| 2409 | echo $indent, "{\n"; |
|---|
| 2410 | } |
|---|
| 2411 | else { |
|---|
| 2412 | echo " {\n"; |
|---|
| 2413 | } |
|---|
| 2414 | |
|---|
| 2415 | echo $body; |
|---|
| 2416 | echo "$indent}"; |
|---|
| 2417 | if ($functionName !== '') { |
|---|
| 2418 | echo "\n"; |
|---|
| 2419 | } |
|---|
| 2420 | } |
|---|
| 2421 | } |
|---|
| 2422 | // }}} |
|---|
| 2423 | function dclass($class, $indent = '') // {{{ |
|---|
| 2424 | { |
|---|
| 2425 | $this->detectNamespace($class['name']); |
|---|
| 2426 | |
|---|
| 2427 | // {{{ class decl |
|---|
| 2428 | if (!empty($class['doc_comment'])) { |
|---|
| 2429 | echo $indent; |
|---|
| 2430 | echo $class['doc_comment']; |
|---|
| 2431 | echo "\n"; |
|---|
| 2432 | } |
|---|
| 2433 | $isinterface = false; |
|---|
| 2434 | if (!empty($class['ce_flags'])) { |
|---|
| 2435 | if ($class['ce_flags'] & ZEND_ACC_INTERFACE) { |
|---|
| 2436 | $isinterface = true; |
|---|
| 2437 | } |
|---|
| 2438 | else { |
|---|
| 2439 | if ($class['ce_flags'] & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) { |
|---|
| 2440 | echo "abstract "; |
|---|
| 2441 | } |
|---|
| 2442 | if ($class['ce_flags'] & ZEND_ACC_FINAL_CLASS) { |
|---|
| 2443 | echo "final "; |
|---|
| 2444 | } |
|---|
| 2445 | } |
|---|
| 2446 | } |
|---|
| 2447 | echo $isinterface ? 'interface ' : 'class ', $this->stripNamespace($class['name']); |
|---|
| 2448 | if ($class['parent']) { |
|---|
| 2449 | echo ' extends ', $class['parent']; |
|---|
| 2450 | } |
|---|
| 2451 | /* TODO */ |
|---|
| 2452 | if (!empty($class['interfaces'])) { |
|---|
| 2453 | echo ' implements '; |
|---|
| 2454 | echo implode(', ', $class['interfaces']); |
|---|
| 2455 | } |
|---|
| 2456 | echo "\n"; |
|---|
| 2457 | echo $indent, "{"; |
|---|
| 2458 | // }}} |
|---|
| 2459 | $newindent = INDENT . $indent; |
|---|
| 2460 | // {{{ const, static |
|---|
| 2461 | foreach (array('constants_table' => 'const ' |
|---|
| 2462 | , 'static_members' => 'static $') as $type => $prefix) { |
|---|
| 2463 | if (!empty($class[$type])) { |
|---|
| 2464 | echo "\n"; |
|---|
| 2465 | // TODO: skip shadow? |
|---|
| 2466 | foreach ($class[$type] as $name => $v) { |
|---|
| 2467 | echo $newindent; |
|---|
| 2468 | echo $prefix, $name, ' = '; |
|---|
| 2469 | echo str(value($v), $newindent); |
|---|
| 2470 | echo ";\n"; |
|---|
| 2471 | } |
|---|
| 2472 | } |
|---|
| 2473 | } |
|---|
| 2474 | // }}} |
|---|
| 2475 | // {{{ properties |
|---|
| 2476 | $member_variables = isset($class['properties_info']) ? $class['properties_info'] : ($class['default_static_members'] + $class['default_properties']); |
|---|
| 2477 | if ($member_variables) { |
|---|
| 2478 | echo "\n"; |
|---|
| 2479 | $infos = !empty($class['properties_info']) ? $class['properties_info'] : null; |
|---|
| 2480 | foreach ($member_variables as $name => $dummy) { |
|---|
| 2481 | $info = (isset($infos) && isset($infos[$name])) ? $infos[$name] : null; |
|---|
| 2482 | if (isset($info)) { |
|---|
| 2483 | if (!empty($info['doc_comment'])) { |
|---|
| 2484 | echo $newindent; |
|---|
| 2485 | echo $info['doc_comment']; |
|---|
| 2486 | echo "\n"; |
|---|
| 2487 | } |
|---|
| 2488 | } |
|---|
| 2489 | |
|---|
| 2490 | echo $newindent; |
|---|
| 2491 | $static = false; |
|---|
| 2492 | if (isset($info)) { |
|---|
| 2493 | if ($info['flags'] & ZEND_ACC_STATIC) { |
|---|
| 2494 | $static = true; |
|---|
| 2495 | } |
|---|
| 2496 | } |
|---|
| 2497 | else if (isset($class['default_static_members'][$name])) { |
|---|
| 2498 | $static = true; |
|---|
| 2499 | } |
|---|
| 2500 | |
|---|
| 2501 | if ($static) { |
|---|
| 2502 | echo "static "; |
|---|
| 2503 | } |
|---|
| 2504 | |
|---|
| 2505 | $mangled = false; |
|---|
| 2506 | if (!ZEND_ENGINE_2) { |
|---|
| 2507 | echo 'var '; |
|---|
| 2508 | } |
|---|
| 2509 | else if (!isset($info)) { |
|---|
| 2510 | echo 'public '; |
|---|
| 2511 | } |
|---|
| 2512 | else { |
|---|
| 2513 | if ($info['flags'] & ZEND_ACC_SHADOW) { |
|---|
| 2514 | continue; |
|---|
| 2515 | } |
|---|
| 2516 | switch ($info['flags'] & ZEND_ACC_PPP_MASK) { |
|---|
| 2517 | case ZEND_ACC_PUBLIC: |
|---|
| 2518 | echo "public "; |
|---|
| 2519 | break; |
|---|
| 2520 | case ZEND_ACC_PRIVATE: |
|---|
| 2521 | echo "private "; |
|---|
| 2522 | $mangled = true; |
|---|
| 2523 | break; |
|---|
| 2524 | case ZEND_ACC_PROTECTED: |
|---|
| 2525 | echo "protected "; |
|---|
| 2526 | $mangled = true; |
|---|
| 2527 | break; |
|---|
| 2528 | } |
|---|
| 2529 | } |
|---|
| 2530 | |
|---|
| 2531 | echo '$', $name; |
|---|
| 2532 | |
|---|
| 2533 | if (isset($info['offset'])) { |
|---|
| 2534 | $value = $class[$static ? 'default_static_members_table' : 'default_properties_table'][$info['offset']]; |
|---|
| 2535 | } |
|---|
| 2536 | else { |
|---|
| 2537 | $key = isset($info) ? $info['name'] . ($mangled ? "\000" : "") : $name; |
|---|
| 2538 | |
|---|
| 2539 | $value = $class[$static ? 'default_static_members' : 'default_properties'][$key]; |
|---|
| 2540 | } |
|---|
| 2541 | if (isset($value)) { |
|---|
| 2542 | echo ' = '; |
|---|
| 2543 | echo str(value($value), $newindent); |
|---|
| 2544 | } |
|---|
| 2545 | echo ";\n"; |
|---|
| 2546 | } |
|---|
| 2547 | } |
|---|
| 2548 | // }}} |
|---|
| 2549 | // {{{ function_table |
|---|
| 2550 | if (isset($class['function_table'])) { |
|---|
| 2551 | foreach ($class['function_table'] as $func) { |
|---|
| 2552 | if (!isset($func['scope']) || $func['scope'] == $class['name']) { |
|---|
| 2553 | // TODO: skip shadow here |
|---|
| 2554 | echo "\n"; |
|---|
| 2555 | $opa = $func['op_array']; |
|---|
| 2556 | if (!empty($opa['doc_comment'])) { |
|---|
| 2557 | echo $newindent; |
|---|
| 2558 | echo $opa['doc_comment']; |
|---|
| 2559 | echo "\n"; |
|---|
| 2560 | } |
|---|
| 2561 | echo $newindent; |
|---|
| 2562 | $isAbstractMethod = false; |
|---|
| 2563 | if (isset($opa['fn_flags'])) { |
|---|
| 2564 | if (($opa['fn_flags'] & ZEND_ACC_ABSTRACT) && !$isinterface) { |
|---|
| 2565 | echo "abstract "; |
|---|
| 2566 | $isAbstractMethod = true; |
|---|
| 2567 | } |
|---|
| 2568 | if ($opa['fn_flags'] & ZEND_ACC_FINAL) { |
|---|
| 2569 | echo "final "; |
|---|
| 2570 | } |
|---|
| 2571 | if ($opa['fn_flags'] & ZEND_ACC_STATIC) { |
|---|
| 2572 | echo "static "; |
|---|
| 2573 | } |
|---|
| 2574 | |
|---|
| 2575 | switch ($opa['fn_flags'] & ZEND_ACC_PPP_MASK) { |
|---|
| 2576 | case ZEND_ACC_PUBLIC: |
|---|
| 2577 | echo "public "; |
|---|
| 2578 | break; |
|---|
| 2579 | case ZEND_ACC_PRIVATE: |
|---|
| 2580 | echo "private "; |
|---|
| 2581 | break; |
|---|
| 2582 | case ZEND_ACC_PROTECTED: |
|---|
| 2583 | echo "protected "; |
|---|
| 2584 | break; |
|---|
| 2585 | default: |
|---|
| 2586 | echo "<visibility error> "; |
|---|
| 2587 | break; |
|---|
| 2588 | } |
|---|
| 2589 | } |
|---|
| 2590 | $this->dfunction($func, $newindent, $isinterface || $isAbstractMethod); |
|---|
| 2591 | if ($opa['function_name'] == 'Decompiler') { |
|---|
| 2592 | //exit; |
|---|
| 2593 | } |
|---|
| 2594 | } |
|---|
| 2595 | } |
|---|
| 2596 | } |
|---|
| 2597 | // }}} |
|---|
| 2598 | echo $indent, "}\n"; |
|---|
| 2599 | } |
|---|
| 2600 | // }}} |
|---|
| 2601 | function decompileString($string) // {{{ |
|---|
| 2602 | { |
|---|
| 2603 | $this->dc = xcache_dasm_string($string); |
|---|
| 2604 | if ($this->dc === false) { |
|---|
| 2605 | echo "error compling string\n"; |
|---|
| 2606 | return false; |
|---|
| 2607 | } |
|---|
| 2608 | } |
|---|
| 2609 | // }}} |
|---|
| 2610 | function decompileFile($file) // {{{ |
|---|
| 2611 | { |
|---|
| 2612 | $this->dc = xcache_dasm_file($file); |
|---|
| 2613 | if ($this->dc === false) { |
|---|
| 2614 | echo "error compling $file\n"; |
|---|
| 2615 | return false; |
|---|
| 2616 | } |
|---|
| 2617 | } |
|---|
| 2618 | // }}} |
|---|
| 2619 | function output() // {{{ |
|---|
| 2620 | { |
|---|
| 2621 | echo "<?". "php\n\n"; |
|---|
| 2622 | foreach ($this->dc['class_table'] as $key => $class) { |
|---|
| 2623 | if ($key{0} != "\0") { |
|---|
| 2624 | $this->dclass($class); |
|---|
| 2625 | echo "\n"; |
|---|
| 2626 | } |
|---|
| 2627 | } |
|---|
| 2628 | |
|---|
| 2629 | foreach ($this->dc['function_table'] as $key => $func) { |
|---|
| 2630 | if ($key{0} != "\0") { |
|---|
| 2631 | $this->dfunction($func); |
|---|
| 2632 | echo "\n"; |
|---|
| 2633 | } |
|---|
| 2634 | } |
|---|
| 2635 | |
|---|
| 2636 | $this->dop_array($this->dc['op_array']); |
|---|
| 2637 | echo "\n?" . ">\n"; |
|---|
| 2638 | |
|---|
| 2639 | if (!empty($this->test)) { |
|---|
| 2640 | $this->outputUnusedOp(); |
|---|
| 2641 | } |
|---|
| 2642 | return true; |
|---|
| 2643 | } |
|---|
| 2644 | // }}} |
|---|
| 2645 | function outputUnusedOp() // {{{ |
|---|
| 2646 | { |
|---|
| 2647 | for ($i = 0; $opname = xcache_get_opcode($i); $i ++) { |
|---|
| 2648 | if ($opname == 'UNDEF') { |
|---|
| 2649 | continue; |
|---|
| 2650 | } |
|---|
| 2651 | |
|---|
| 2652 | if (!isset($this->usedOps[$i])) { |
|---|
| 2653 | echo "not covered opcode ", $opname, "\n"; |
|---|
| 2654 | } |
|---|
| 2655 | } |
|---|
| 2656 | } |
|---|
| 2657 | // }}} |
|---|
| 2658 | } |
|---|
| 2659 | |
|---|
| 2660 | // {{{ defines |
|---|
| 2661 | define('ZEND_ENGINE_2_4', PHP_VERSION >= "5.3.99"); |
|---|
| 2662 | define('ZEND_ENGINE_2_3', ZEND_ENGINE_2_4 || PHP_VERSION >= "5.3."); |
|---|
| 2663 | define('ZEND_ENGINE_2_2', ZEND_ENGINE_2_3 || PHP_VERSION >= "5.2."); |
|---|
| 2664 | define('ZEND_ENGINE_2_1', ZEND_ENGINE_2_2 || PHP_VERSION >= "5.1."); |
|---|
| 2665 | define('ZEND_ENGINE_2', ZEND_ENGINE_2_1 || PHP_VERSION >= "5.0."); |
|---|
| 2666 | |
|---|
| 2667 | define('ZEND_ACC_STATIC', 0x01); |
|---|
| 2668 | define('ZEND_ACC_ABSTRACT', 0x02); |
|---|
| 2669 | define('ZEND_ACC_FINAL', 0x04); |
|---|
| 2670 | define('ZEND_ACC_IMPLEMENTED_ABSTRACT', 0x08); |
|---|
| 2671 | |
|---|
| 2672 | define('ZEND_ACC_IMPLICIT_ABSTRACT_CLASS', 0x10); |
|---|
| 2673 | define('ZEND_ACC_EXPLICIT_ABSTRACT_CLASS', 0x20); |
|---|
| 2674 | define('ZEND_ACC_FINAL_CLASS', 0x40); |
|---|
| 2675 | define('ZEND_ACC_INTERFACE', 0x80); |
|---|
| 2676 | if (ZEND_ENGINE_2_4) { |
|---|
| 2677 | define('ZEND_ACC_TRAIT', 0x120); |
|---|
| 2678 | } |
|---|
| 2679 | define('ZEND_ACC_PUBLIC', 0x100); |
|---|
| 2680 | define('ZEND_ACC_PROTECTED', 0x200); |
|---|
| 2681 | define('ZEND_ACC_PRIVATE', 0x400); |
|---|
| 2682 | define('ZEND_ACC_PPP_MASK', (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)); |
|---|
| 2683 | |
|---|
| 2684 | define('ZEND_ACC_CHANGED', 0x800); |
|---|
| 2685 | define('ZEND_ACC_IMPLICIT_PUBLIC', 0x1000); |
|---|
| 2686 | |
|---|
| 2687 | define('ZEND_ACC_CTOR', 0x2000); |
|---|
| 2688 | define('ZEND_ACC_DTOR', 0x4000); |
|---|
| 2689 | define('ZEND_ACC_CLONE', 0x8000); |
|---|
| 2690 | |
|---|
| 2691 | define('ZEND_ACC_ALLOW_STATIC', 0x10000); |
|---|
| 2692 | |
|---|
| 2693 | define('ZEND_ACC_SHADOW', 0x2000); |
|---|
| 2694 | |
|---|
| 2695 | if (ZEND_ENGINE_2_4) { |
|---|
| 2696 | define('ZEND_FETCH_GLOBAL', 0x00000000); |
|---|
| 2697 | define('ZEND_FETCH_LOCAL', 0x10000000); |
|---|
| 2698 | define('ZEND_FETCH_STATIC', 0x20000000); |
|---|
| 2699 | define('ZEND_FETCH_STATIC_MEMBER', 0x30000000); |
|---|
| 2700 | define('ZEND_FETCH_GLOBAL_LOCK', 0x40000000); |
|---|
| 2701 | define('ZEND_FETCH_LEXICAL', 0x50000000); |
|---|
| 2702 | |
|---|
| 2703 | define('ZEND_FETCH_TYPE_MASK', 0x70000000); |
|---|
| 2704 | } |
|---|
| 2705 | else { |
|---|
| 2706 | define('ZEND_FETCH_GLOBAL', 0); |
|---|
| 2707 | define('ZEND_FETCH_LOCAL', 1); |
|---|
| 2708 | define('ZEND_FETCH_STATIC', 2); |
|---|
| 2709 | define('ZEND_FETCH_STATIC_MEMBER', 3); |
|---|
| 2710 | define('ZEND_FETCH_GLOBAL_LOCK', 4); |
|---|
| 2711 | } |
|---|
| 2712 | |
|---|
| 2713 | define('ZEND_FETCH_CLASS_DEFAULT', 0); |
|---|
| 2714 | define('ZEND_FETCH_CLASS_SELF', 1); |
|---|
| 2715 | define('ZEND_FETCH_CLASS_PARENT', 2); |
|---|
| 2716 | define('ZEND_FETCH_CLASS_MAIN', 3); |
|---|
| 2717 | define('ZEND_FETCH_CLASS_GLOBAL', 4); |
|---|
| 2718 | define('ZEND_FETCH_CLASS_AUTO', 5); |
|---|
| 2719 | define('ZEND_FETCH_CLASS_INTERFACE', 6); |
|---|
| 2720 | define('ZEND_FETCH_CLASS_STATIC', 7); |
|---|
| 2721 | if (ZEND_ENGINE_2_4) { |
|---|
| 2722 | define('ZEND_FETCH_CLASS_TRAIT', 14); |
|---|
| 2723 | } |
|---|
| 2724 | if (ZEND_ENGINE_2_3) { |
|---|
| 2725 | define('ZEND_FETCH_CLASS_MASK', 0xF); |
|---|
| 2726 | } |
|---|
| 2727 | |
|---|
| 2728 | define('ZEND_EVAL', (1<<0)); |
|---|
| 2729 | define('ZEND_INCLUDE', (1<<1)); |
|---|
| 2730 | define('ZEND_INCLUDE_ONCE', (1<<2)); |
|---|
| 2731 | define('ZEND_REQUIRE', (1<<3)); |
|---|
| 2732 | define('ZEND_REQUIRE_ONCE', (1<<4)); |
|---|
| 2733 | |
|---|
| 2734 | define('ZEND_ISSET', (1<<0)); |
|---|
| 2735 | define('ZEND_ISEMPTY', (1<<1)); |
|---|
| 2736 | if (ZEND_ENGINE_2_4) { |
|---|
| 2737 | define('EXT_TYPE_UNUSED', (1<<5)); |
|---|
| 2738 | } |
|---|
| 2739 | else { |
|---|
| 2740 | define('EXT_TYPE_UNUSED', (1<<0)); |
|---|
| 2741 | } |
|---|
| 2742 | |
|---|
| 2743 | define('ZEND_FETCH_STANDARD', 0); |
|---|
| 2744 | define('ZEND_FETCH_ADD_LOCK', 1); |
|---|
| 2745 | |
|---|
| 2746 | define('ZEND_FE_FETCH_BYREF', 1); |
|---|
| 2747 | define('ZEND_FE_FETCH_WITH_KEY', 2); |
|---|
| 2748 | |
|---|
| 2749 | define('ZEND_MEMBER_FUNC_CALL', 1<<0); |
|---|
| 2750 | define('ZEND_CTOR_CALL', 1<<1); |
|---|
| 2751 | |
|---|
| 2752 | define('ZEND_ARG_SEND_BY_REF', (1<<0)); |
|---|
| 2753 | define('ZEND_ARG_COMPILE_TIME_BOUND', (1<<1)); |
|---|
| 2754 | define('ZEND_ARG_SEND_FUNCTION', (1<<2)); |
|---|
| 2755 | |
|---|
| 2756 | define('BYREF_NONE', 0); |
|---|
| 2757 | define('BYREF_FORCE', 1); |
|---|
| 2758 | define('BYREF_ALLOW', 2); |
|---|
| 2759 | define('BYREF_FORCE_REST', 3); |
|---|
| 2760 | define('IS_NULL', 0); |
|---|
| 2761 | define('IS_LONG', 1); |
|---|
| 2762 | define('IS_DOUBLE', 2); |
|---|
| 2763 | define('IS_BOOL', ZEND_ENGINE_2 ? 3 : 6); |
|---|
| 2764 | define('IS_ARRAY', 4); |
|---|
| 2765 | define('IS_OBJECT', 5); |
|---|
| 2766 | define('IS_STRING', ZEND_ENGINE_2 ? 6 : 3); |
|---|
| 2767 | define('IS_RESOURCE', 7); |
|---|
| 2768 | define('IS_CONSTANT', 8); |
|---|
| 2769 | define('IS_CONSTANT_ARRAY', 9); |
|---|
| 2770 | /* Ugly hack to support constants as static array indices */ |
|---|
| 2771 | define('IS_CONSTANT_TYPE_MASK', 0x0f); |
|---|
| 2772 | define('IS_CONSTANT_UNQUALIFIED', 0x10); |
|---|
| 2773 | define('IS_CONSTANT_INDEX', 0x80); |
|---|
| 2774 | define('IS_LEXICAL_VAR', 0x20); |
|---|
| 2775 | define('IS_LEXICAL_REF', 0x40); |
|---|
| 2776 | |
|---|
| 2777 | @define('XC_IS_CV', 16); |
|---|
| 2778 | |
|---|
| 2779 | /* |
|---|
| 2780 | if (preg_match_all('!XC_[A-Z_]+!', file_get_contents(__FILE__), $ms)) { |
|---|
| 2781 | $verdiff = array(); |
|---|
| 2782 | foreach ($ms[0] as $k) { |
|---|
| 2783 | if (!defined($k)) { |
|---|
| 2784 | $verdiff[$k] = -1; |
|---|
| 2785 | define($k, -1); |
|---|
| 2786 | } |
|---|
| 2787 | } |
|---|
| 2788 | var_export($verdiff); |
|---|
| 2789 | } |
|---|
| 2790 | /*/ |
|---|
| 2791 | foreach (array ( |
|---|
| 2792 | 'XC_HANDLE_EXCEPTION' => -1, |
|---|
| 2793 | 'XC_FETCH_CLASS' => -1, |
|---|
| 2794 | 'XC_FETCH_' => -1, |
|---|
| 2795 | 'XC_FETCH_DIM_' => -1, |
|---|
| 2796 | 'XC_ASSIGN_DIM' => -1, |
|---|
| 2797 | 'XC_UNSET_DIM' => -1, |
|---|
| 2798 | 'XC_UNSET_OBJ' => -1, |
|---|
| 2799 | 'XC_ASSIGN_OBJ' => -1, |
|---|
| 2800 | 'XC_ISSET_ISEMPTY_DIM_OBJ' => -1, |
|---|
| 2801 | 'XC_ISSET_ISEMPTY_PROP_OBJ' => -1, |
|---|
| 2802 | 'XC_ISSET_ISEMPTY_VAR' => -1, |
|---|
| 2803 | 'XC_INIT_STATIC_METHOD_CALL' => -1, |
|---|
| 2804 | 'XC_INIT_METHOD_CALL' => -1, |
|---|
| 2805 | 'XC_VERIFY_ABSTRACT_CLASS' => -1, |
|---|
| 2806 | 'XC_DECLARE_CLASS' => -1, |
|---|
| 2807 | 'XC_DECLARE_INHERITED_CLASS' => -1, |
|---|
| 2808 | 'XC_DECLARE_INHERITED_CLASS_DELAYED' => -1, |
|---|
| 2809 | 'XC_ADD_INTERFACE' => -1, |
|---|
| 2810 | 'XC_POST_DEC_OBJ' => -1, |
|---|
| 2811 | 'XC_POST_INC_OBJ' => -1, |
|---|
| 2812 | 'XC_PRE_DEC_OBJ' => -1, |
|---|
| 2813 | 'XC_PRE_INC_OBJ' => -1, |
|---|
| 2814 | 'XC_UNSET_OBJ' => -1, |
|---|
| 2815 | 'XC_JMP_NO_CTOR' => -1, |
|---|
| 2816 | 'XC_FETCH_' => -1, |
|---|
| 2817 | 'XC_FETCH_DIM_' => -1, |
|---|
| 2818 | 'XC_UNSET_DIM_OBJ' => -1, |
|---|
| 2819 | 'XC_ISSET_ISEMPTY' => -1, |
|---|
| 2820 | 'XC_INIT_FCALL_BY_FUNC' => -1, |
|---|
| 2821 | 'XC_DO_FCALL_BY_FUNC' => -1, |
|---|
| 2822 | 'XC_DECLARE_FUNCTION_OR_CLASS' => -1, |
|---|
| 2823 | 'XC_INIT_NS_FCALL_BY_NAME' => -1, |
|---|
| 2824 | 'XC_GOTO' => -1, |
|---|
| 2825 | 'XC_CATCH' => -1, |
|---|
| 2826 | 'XC_THROW' => -1, |
|---|
| 2827 | 'XC_INSTANCEOF' => -1, |
|---|
| 2828 | 'XC_DECLARE_FUNCTION' => -1, |
|---|
| 2829 | 'XC_RAISE_ABSTRACT_ERROR' => -1, |
|---|
| 2830 | 'XC_DECLARE_CONST' => -1, |
|---|
| 2831 | 'XC_USER_OPCODE' => -1, |
|---|
| 2832 | 'XC_JMP_SET' => -1, |
|---|
| 2833 | 'XC_DECLARE_LAMBDA_FUNCTION' => -1, |
|---|
| 2834 | ) as $k => $v) { |
|---|
| 2835 | if (!defined($k)) { |
|---|
| 2836 | define($k, $v); |
|---|
| 2837 | } |
|---|
| 2838 | } |
|---|
| 2839 | // }}} |
|---|
| 2840 | |
|---|