Changeset 744 for trunk/Decompiler.class.php
- Timestamp:
- 04/14/2011 06:56:16 AM (2 years ago)
- Files:
-
- 1 modified
-
trunk/Decompiler.class.php (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Decompiler.class.php
r743 r744 11 11 function str($code, $indent = '') // {{{ 12 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 } 13 20 if (is_object($code)) { 14 $code = toCode($code, $indent);15 return $code-> __toString();21 $code = foldToCode($code, $indent); 22 return $code->toCode($indent); 16 23 } 17 24 … … 19 26 } 20 27 // }}} 21 function toCode($src, $indent = '') // {{{ wrap or rewrap anything to Decompiler_Code28 function foldToCode($src, $indent = '') // {{{ wrap or rewrap anything to Decompiler_Code 22 29 { 23 30 if (is_array($indent)) { … … 97 104 return $this->src; 98 105 } 99 100 function __toString()101 {102 return $this->src;103 }104 106 } 105 107 // }}} … … 122 124 function toCode($indent) 123 125 { 124 $op1 = toCode($this->op1, $indent);126 $op1 = foldToCode($this->op1, $indent); 125 127 if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) { 126 128 $op1 = "($op1)"; … … 128 130 $opstr = $this->parent->binops[$this->opc]; 129 131 if ($op1 == '0' && $this->opc == XC_SUB) { 130 return $opstr . toCode($this->op2, $indent);131 } 132 return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent);132 return $opstr . str($this->op2, $indent); 133 } 134 return $op1 . ' ' . $opstr . ' ' . foldToCodfoldToCode($this->op2, $indent); 133 135 } 134 136 } … … 187 189 { 188 190 if (is_a($this->value, 'Decompiler_ListBox')) { 189 $exp = toCode($this->value->obj->src, $indent);191 $exp = foldToCode($this->value->obj->src, $indent); 190 192 } 191 193 else { 192 $exp = toCode($this->value, $indent);194 $exp = foldToCode($this->value, $indent); 193 195 } 194 196 foreach ($this->offsets as $dim) { 195 $exp .= '[' . toCode($dim, $indent) . ']';197 $exp .= '[' . foldToCode($dim, $indent) . ']'; 196 198 } 197 199 return $exp; … … 216 218 $dim->value = $this->src; 217 219 if (!isset($dim->assign)) { 218 return toCode($dim, $indent);219 } 220 return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent);220 return foldToCode($dim, $indent); 221 } 222 return foldToCode($this->dims[0]->assign, $indent) . ' = ' . foldToCode($dim, $indent); 221 223 } 222 224 /* flatten dims */ … … 227 229 $assign = &$assign[$offset]; 228 230 } 229 $assign = toCode($dim->assign, $indent);230 } 231 return $this->toList($assigns) . ' = ' . toCode($this->src, $indent);231 $assign = foldToCode($dim->assign, $indent); 232 } 233 return $this->toList($assigns) . ' = ' . foldToCode($this->src, $indent); 232 234 } 233 235 … … 449 451 $curticks = $toticks; 450 452 } 451 echo $indent, toCode($op['php'], $indent), ";\n";453 echo $indent, str($op['php'], $indent), ";\n"; 452 454 } 453 455 } … … 461 463 switch ($op['op_type']) { 462 464 case XC_IS_CONST: 463 return toCode(value($op['constant']), $EX);465 return foldToCode(value($op['constant']), $EX); 464 466 465 467 case XC_IS_VAR: … … 468 470 $ret = $T[$op['var']]; 469 471 if ($tostr) { 470 $ret = toCode($ret, $EX);472 $ret = foldToCode($ret, $EX); 471 473 } 472 474 if ($free) { … … 682 684 $body = ob_get_clean(); 683 685 684 $as = toCode($op['fe_as'], $EX);686 $as = foldToCode($op['fe_as'], $EX); 685 687 if (isset($op['fe_key'])) { 686 $as = toCode($op['fe_key'], $EX) . ' => ' . $as;687 } 688 echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n";688 $as = str($op['fe_key'], $EX) . ' => ' . str($as); 689 } 690 echo "{$indent}foreach (" . str($op['fe_src'], $EX) . " as $as) {\n"; 689 691 echo $body; 690 692 echo "{$indent}}"; … … 755 757 // $this->dumpop($op, $EX); 756 758 // any true comes here, so it's a "or" 757 $cond = implode(' and ', $op['cond_false']);759 $cond = implode(' and ', str($op['cond_false'])); 758 760 // var_dump($op['cond'] = $cond); 759 761 /* … … 771 773 function unquoteName($str) // {{{ 772 774 { 775 $str = str($str); 773 776 if (preg_match($this->rQuotedName, $str)) { 774 777 $str = substr($str, 1, -1); … … 910 913 } 911 914 if ($opc == XC_UNSET_VAR) { 912 $op['php'] = "unset(" . toCode($rvalue, $EX) . ")";915 $op['php'] = "unset(" . str($rvalue, $EX) . ")"; 913 916 $lastphpop = &$op; 914 917 } … … 971 974 ++ $i; 972 975 $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); 973 $resvar = toCode($lvalue, $EX) . ' = ' . $rvalue;976 $resvar = str($lvalue, $EX) . ' = ' . $rvalue; 974 977 } 975 978 else if ($opc == XC_UNSET_DIM) { 976 $op['php'] = "unset(" . toCode($rvalue, $EX) . ")";979 $op['php'] = "unset(" . str($rvalue, $EX) . ")"; 977 980 $lastphpop = &$op; 978 981 } … … 995 998 $dim->assign = $lvalue; 996 999 if ($dim->isLast) { 997 $resvar = toCode($dim->value, $EX);1000 $resvar = foldToCode($dim->value, $EX); 998 1001 } 999 1002 unset($dim); 1000 1003 break; 1001 1004 } 1002 $resvar = "$lvalue = " . toCode($rvalue, $EX);1005 $resvar = "$lvalue = " . str($rvalue, $EX); 1003 1006 break; 1004 1007 // }}} … … 1007 1010 $rvalue = $this->getOpVal($op2, $EX, false); 1008 1011 if (is_a($rvalue, 'Decompiler_Fetch')) { 1009 $src = toCode($rvalue->src, $EX);1012 $src = foldToCode($rvalue->src, $EX); 1010 1013 if (substr($src, 1, -1) == substr($lvalue, 1)) { 1011 1014 switch ($rvalue->fetchType) { … … 1021 1024 $var = $statics[$name]; 1022 1025 $resvar .= ' = '; 1023 $resvar .= toCode(value($var), $EX);1026 $resvar .= str(value($var), $EX); 1024 1027 } 1025 1028 unset($statics); … … 1030 1033 } 1031 1034 // TODO: PHP_6 global 1032 $rvalue = toCode($rvalue, $EX);1035 $rvalue = foldToCode($rvalue, $EX); 1033 1036 $resvar = "$lvalue = &$rvalue"; 1034 1037 break; … … 1117 1120 case XC_SEND_VAR: // {{{ 1118 1121 $ref = ($opc == XC_SEND_REF ? '&' : ''); 1119 $EX['argstack'][] = $ref . $this->getOpVal($op1, $EX);1122 $EX['argstack'][] = $ref . str($this->getOpVal($op1, $EX)); 1120 1123 break; 1121 1124 // }}} … … 1243 1246 switch ($opc) { 1244 1247 case XC_ADD_CHAR: 1245 $op2val = toCode(chr($op2val), $EX);1248 $op2val = foldToCode(chr($op2val), $EX); 1246 1249 break; 1247 1250 case XC_ADD_STRING: 1248 $op2val = toCode($op2val, $EX);1251 $op2val = foldToCode($op2val, $EX); 1249 1252 break; 1250 1253 case XC_ADD_VAR: … … 1258 1261 } 1259 1262 else { 1260 $rvalue = $op1val . ' . ' . $op2val;1263 $rvalue = str($op1val) . ' . ' . str($op2val); 1261 1264 } 1262 1265 $resvar = $rvalue; … … 1270 1273 case XC_ECHO: // {{{ 1271 1274 $op1val = $this->getOpVal($op1, $EX); 1272 $resvar = "echo $op1val";1275 $resvar = "echo " . str($op1val); 1273 1276 break; 1274 1277 // }}} … … 1318 1321 // }}} 1319 1322 case XC_RETURN: // {{{ 1320 $resvar = "return " . $this->getOpVal($op1, $EX);1323 $resvar = "return " . str($this->getOpVal($op1, $EX)); 1321 1324 break; 1322 1325 // }}} … … 1386 1389 $targetop = &$EX['opcodes'][$op2['opline_num']]; 1387 1390 if ($opc == XC_JMPNZ_EX) { 1388 $targetop['cond_true'][] = toCode($rvalue, $EX);1391 $targetop['cond_true'][] = foldToCode($rvalue, $EX); 1389 1392 } 1390 1393 else { 1391 $targetop['cond_false'][] = toCode($rvalue, $EX);1394 $targetop['cond_false'][] = foldToCode($rvalue, $EX); 1392 1395 } 1393 1396 unset($targetop); … … 1407 1410 $switchValue = $this->getOpVal($op1, $EX); 1408 1411 $caseValue = $this->getOpVal($op2, $EX); 1409 $resvar = $switchValue . ' == ' . $caseValue;1412 $resvar = str($switchValue) . ' == ' . str($caseValue); 1410 1413 break; 1411 1414 case XC_BRK: … … 1461 1464 case XC_END_SILENCE: // {{{ 1462 1465 $EX['silence'] --; 1463 $lastresvar = '@' . toCode($lastresvar, $EX);1466 $lastresvar = '@' . str($lastresvar, $EX); 1464 1467 break; 1465 1468 // }}} … … 1531 1534 $a = array_pop($EX['argstack']); 1532 1535 if (is_array($a)) { 1533 array_unshift($args, toCode($a, $EX));1536 array_unshift($args, foldToCode($a, $EX)); 1534 1537 } 1535 1538 else { … … 1646 1649 } 1647 1650 } 1648 echo toCode($arg[0], $indent);1651 echo str($arg[0], $indent); 1649 1652 } 1650 1653 if (isset($arg[1])) { 1651 echo ' = ', toCode($arg[1], $indent);1654 echo ' = ', str($arg[1], $indent); 1652 1655 } 1653 1656 } … … 1725 1728 echo $newindent; 1726 1729 echo $prefix, $name, ' = '; 1727 echo toCode(value($v), $newindent);1730 echo str(value($v), $newindent); 1728 1731 echo ";\n"; 1729 1732 } … … 1799 1802 if (isset($value)) { 1800 1803 echo ' = '; 1801 echo toCode(value($value), $newindent);1804 echo str(value($value), $newindent); 1802 1805 } 1803 1806 echo ";\n";

