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