Changeset 753
- Timestamp:
- 2011-04-17T06:58:46+02:00 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
Decompiler.class.php (modified) (15 diffs)
-
decompilesample.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Decompiler.class.php
r752 r753 71 71 } 72 72 // }}} 73 function unquoteName_($str, $asProperty, $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 ($asProperty) { 80 return "{" . $str . "}"; 81 } 82 else { 83 return $str; 84 } 85 } 86 // }}} 73 87 function unquoteProperty($str, $indent = '') // {{{ 74 88 { 75 $str = str($str, $indent); 76 if (preg_match("!^'[\\w_][\\w\\d_]*'\$!", $str)) { 77 return substr($str, 1, -1); 78 } 79 else { 80 return "{" . $str . "}"; 81 } 89 return unquoteName_($str, true, $indent); 82 90 } 83 91 // }}} 84 92 function unquoteName($str, $indent = '') // {{{ 85 93 { 86 $str = str($str, $indent); 87 if (preg_match("!^'[\\w_][\\w\\d_]*'\$!", $str)) { 88 return substr($str, 1, -1); 89 } 90 else { 91 return $str; 92 } 94 return unquoteName_($str, false, $indent); 93 95 } 94 96 // }}} … … 423 425 class Decompiler 424 426 { 425 var $rName = '!^[\\w_][\\w\\d_]*$!'; 427 var $namespace; 428 var $namespaceDecided; 426 429 427 430 function Decompiler() … … 473 476 // }}} 474 477 } 478 function detectNamespace($name) // {{{ 479 { 480 if ($this->namespaceDecided) { 481 return; 482 } 483 484 if (strpos($name, '\\') !== false) { 485 $this->namespace = strtok($name, '\\'); 486 echo 'namespace ', $this->namespace, ";\n\n"; 487 } 488 489 $this->namespaceDecided = true; 490 } 491 // }}} 492 function stripNamespace($name) // {{{ 493 { 494 $len = strlen($this->namespace) + 1; 495 if (substr($name, 0, $len) == $this->namespace . '\\') { 496 return substr($name, $len); 497 } 498 else { 499 return $name; 500 } 501 } 502 // }}} 475 503 function outputPhp(&$opcodes, $opline, $last, $indent) // {{{ 476 504 { … … 922 950 $class = $this->getOpVal($op2, $EX); 923 951 if (isset($op2['constant'])) { 924 $class = unquoteName($class);952 $class = $this->stripNamespace(unquoteName($class)); 925 953 } 926 954 } … … 930 958 case XC_FETCH_CONSTANT: // {{{ 931 959 if ($op1['op_type'] == XC_IS_UNUSED) { 932 $resvar = $ op2['constant'];960 $resvar = $this->stripNamespace($op2['constant']); 933 961 break; 934 962 } 935 963 936 964 if ($op1['op_type'] == XC_IS_CONST) { 937 $resvar = $ op1['constant'];965 $resvar = $this->stripNamespace($op1['constant']); 938 966 } 939 967 else { … … 1191 1219 if ($opc == XC_INIT_STATIC_METHOD_CALL || /* PHP4 */ isset($op1['constant'])) { 1192 1220 $EX['object'] = null; 1193 $EX['called_scope'] = unquoteName($obj, $EX);1221 $EX['called_scope'] = $this->stripNamespace(unquoteName($obj, $EX)); 1194 1222 } 1195 1223 else { … … 1212 1240 break; 1213 1241 // }}} 1242 case XC_INIT_NS_FCALL_BY_NAME: 1214 1243 case XC_INIT_FCALL_BY_NAME: // {{{ 1215 1244 if (!ZEND_ENGINE_2 && ($ext & ZEND_CTOR_CALL)) { … … 1249 1278 $args = $this->popargs($EX, $ext); 1250 1279 1251 $resvar = 1252 (isset($object) ? $object . '->' : '' ) 1253 . (isset($EX['called_scope']) ? $EX['called_scope'] . '::' : '' ) 1254 . $fname . "($args)"; 1280 $prefix = (isset($object) ? $object . '->' : '' ) 1281 . (isset($EX['called_scope']) ? $EX['called_scope'] . '::' : '' ); 1282 $resvar = $prefix 1283 . (!$prefix ? $this->stripNamespace($fname) : $fname) 1284 . "($args)"; 1255 1285 unset($args); 1256 1286 … … 1305 1335 1306 1336 $fetchop = &$opcodes[$i + 1]; 1307 $i mpl = unquoteName($this->getOpVal($fetchop['op2'], $EX), $EX);1337 $interface = $this->stripNamespace(unquoteName($this->getOpVal($fetchop['op2'], $EX), $EX)); 1308 1338 $addop = &$opcodes[$i + 2]; 1309 $class['interfaces'][$addop['extended_value']] = $i mpl;1339 $class['interfaces'][$addop['extended_value']] = $interface; 1310 1340 unset($fetchop, $addop); 1311 1341 $i += 2; … … 1577 1607 // }}} 1578 1608 case XC_DECLARE_CONST: 1579 $resvar = 'const ' . unquoteName($this->getOpVal($op1, $EX), $EX) . ' = ' . str($this->getOpVal($op2, $EX)); 1609 $name = $this->stripNamespace(unquoteName($this->getOpVal($op1, $EX), $EX)); 1610 $value = str($this->getOpVal($op2, $EX)); 1611 $resvar = 'const ' . $name . ' = ' . $value; 1580 1612 break; 1581 1613 case XC_DECLARE_FUNCTION_OR_CLASS: … … 1709 1741 $ai = $op_array['arg_info'][$i]; 1710 1742 if (!empty($ai['class_name'])) { 1711 echo $ ai['class_name'], ' ';1743 echo $this->stripNamespace($ai['class_name']), ' '; 1712 1744 if (!ZEND_ENGINE_2_2 && $ai['allow_null']) { 1713 1745 echo 'or NULL '; … … 1755 1787 function dfunction($func, $indent = '', $nobody = false) // {{{ 1756 1788 { 1789 $this->detectNamespace($func['op_array']['function_name']); 1790 1757 1791 if ($nobody) { 1758 1792 $EX = array(); … … 1770 1804 } 1771 1805 1772 $functionName = $ func['op_array']['function_name'];1806 $functionName = $this->stripNamespace($func['op_array']['function_name']); 1773 1807 if ($functionName == '{closure}') { 1774 1808 $functionName = ''; … … 1799 1833 function dclass($class, $indent = '') // {{{ 1800 1834 { 1835 $this->detectNamespace($class['name']); 1836 1801 1837 // {{{ class decl 1802 1838 if (!empty($class['doc_comment'])) { … … 1819 1855 } 1820 1856 } 1821 echo $isinterface ? 'interface ' : 'class ', $ class['name'];1857 echo $isinterface ? 'interface ' : 'class ', $this->stripNamespace($class['name']); 1822 1858 if ($class['parent']) { 1823 1859 echo ' extends ', $class['parent']; -
trunk/decompilesample.php
r752 r753 1 1 <?php 2 3 //* >= PHP 5.3 4 namespace ns; 5 // */ 2 6 3 7 abstract class ClassName
Note: See TracChangeset
for help on using the changeset viewer.

