Browse Source

merge from trunk: disassembler/decompiler improvements

git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.3@817 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.3
Xuefer 11 years ago
parent
commit
8c960e1d69
  1. 1
      ChangeLog
  2. 2380
      Decompiler.class.php
  3. 162
      decompilesample.php
  4. 2
      processor/main.m4
  5. 4
      utils.c

1
ChangeLog

@ -3,6 +3,7 @@
* avoid possible filename injection in admin page
* adds 30 seconds timeout to "compiling" flag
* decompiler: improves decompiling
* disassembler: improper handling of null field
* disassembler: DECLARE_INHERITED_CLASS/DELAYED class not found
* disassembler: don't dump builtin functions
* fix win32 build against win32 native gnu tools

2380
Decompiler.class.php

File diff suppressed because it is too large

162
decompilesample.php

@ -64,8 +64,8 @@ abstract class ClassName
/** doc */
protected function protectedMethod(ClassName $a, $b = array(
array('array')
))
array('array')
))
{
$runtimeArray = array('1');
$runtimeArray2 = array(
@ -154,13 +154,17 @@ final class Child extends ClassName implements IInterface
}
if ($late) {
class LateBindingClass
{}
class LateBindingClass
{
public function __construct()
{
}
}
function lateBindingFunction($arg)
{
echo 'lateFunction';
}
function lateBindingFunction($arg)
{
echo 'lateFunction';
}
}
echo "\r\n";
@ -203,7 +207,6 @@ $a = $b--;
$a = --$b;
$a = $obj->b--;
$a = --$obj->b;
$a = $b xor $c;
$a = !$b;
$a = $b === $c;
$a = $b !== $c;
@ -249,34 +252,51 @@ $a = (unset) $b;
$a = (array) $b;
$a = (object) $b;
// PHP6+ $a = (scalar) $b;
$a = $b ? $c : $d;
$a = f1() ? f2() : f3();
$a = $b and $c;
$a = $b or $c;
$a = ($b ? $c : $d);
$a = (f1() ? f2() : f3());
($a = $b) xor $c;
($a = $b) and $c;
($a = $b) or $c;
$a = $b && $c;
$a = $b || $c;
try {
echo 'outer try 1';
do {
try {
echo 'inner try';
echo 'outer try 1';
try {
echo 'inner try';
}
catch (InnerException $e) {
echo $e;
}
echo 'outer try 2';
}
catch (InnerException $e) {
catch (OuterException $e) {
echo $e;
}
echo 'outer try 2';
}
catch (OuterException $e) {
echo $e;
}
} while (0);
if (if_()) {
echo 'if';
if ($a) {
echo 'if ($a)';
if (innerIf_()) {
echo 'if innerIf';
}
}
else if ($b) {
echo 'else if ($b)';
else if (elseif_()) {
echo 'else if';
if (innerIf_()) {
echo 'if innerIf';
}
}
else {
if (innerIf_()) {
echo 'if innerIf';
}
echo 'else';
}
@ -288,20 +308,45 @@ do {
echo 'do/while';
} while (false);
for ($i = 1; $i < 10; ++$i) {
$i = 1;
for (; $i < 10; ++$i) {
echo $i;
break;
}
foreach ($array as $key => $value) {
foreach ($array as $key => $value) {
foreach ($value as $key => $value) {
echo $key . ' = ' . $value . "\n";
break 2;
continue;
}
}
switch ($switch) {
switch ($normalSwitch) {
case 'case1':
echo 'case1';
switch ($nestedSwitch) {
case 1:
}
break;
case 'case2':
echo 'case2';
break;
default:
switch ($nestedSwitch) {
case 1:
}
echo 'default';
break;
}
switch ($switchWithoutDefault) {
case 'case1':
echo 'case1';
break;
@ -309,15 +354,48 @@ case 'case1':
case 'case2':
echo 'case2';
break;
}
switch ($switchWithMiddleDefault) {
case 'case1':
echo 'case1';
break;
default:
echo 'default';
break;
case 'case2':
echo 'case2';
break;
}
switch ($switchWithInitialDefault) {
default:
echo 'default';
break;
case 'case1':
echo 'case1';
break;
case 'case2':
echo 'case2';
break;
}
switch (emptySwitch()) {
}
switch (emptySwitch()) {
default:
}
declare (ticks=1) {
echo 1;
echo 2;
while (1) {
echo 2;
}
}
require 'require.php';
@ -335,24 +413,40 @@ echo $a::CONST_VALUE;
echo CONST_VALUE;
$this::__construct();
$obj::__construct();
$a = $b ?: $d;
$a = ($b ?: $d) + $c;
$a = f1() ?: f2();
$a = ($b ? $c : $d);
$a = ($b ? $c : $d) + $c;
$a = (f1() ? f3() : f2());
if ($b ?: $d) {
echo 'if ($b ?: $d)';
}
if (($b ?: $d) + $c) {
echo 'if (($b ?: $d) + $c)';
}
if (f1() ?: f2()) {
echo 'if (f1() ?: f2())';
}
echo 'goto a';
goto a;
for ($i = 1; $i <= 2; ++$i) {
$i = 1;
for (; $i <= 2; ++$i) {
goto a;
}
a:
echo 'label a';
echo preg_replace_callback('~-([a-z])~', function ($match) {
echo preg_replace_callback('~-([a-z])~', function($match) {
return strtoupper($match[1]);
}, 'hello-world');
$greet = function ($name) {
$greet = function($name) {
printf("Hello %s\r\n", $name);
};
$greet('World');

2
processor/main.m4

@ -164,7 +164,7 @@ define(`COPYNULL_EX', `
dnl }}}
dnl {{{ COPYNULL(1:elm)
define(`COPYNULL', `
COPYNULL_EX(`dst->$1', `$2')DONE(`$1')
COPYNULL_EX(`dst->$1', `$1')DONE(`$1')
')
dnl }}}
dnl {{{ LIST_DIFF(1:left-list, 2:right-list)

4
utils.c

@ -149,7 +149,7 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
case ZEND_GOTO:
#endif
case ZEND_JMP:
assert(Z_OP(opline->op1).jmp_addr - op_array->opcodes < op_array->last);
assert(Z_OP(opline->op1).jmp_addr >= op_array->opcodes && Z_OP(opline->op1).jmp_addr - op_array->opcodes < op_array->last);
Z_OP(opline->op1).opline_num = Z_OP(opline->op1).jmp_addr - op_array->opcodes;
break;
case ZEND_JMPZ:
@ -159,7 +159,7 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
#ifdef ZEND_JMP_SET
case ZEND_JMP_SET:
#endif
assert(Z_OP(opline->op2).jmp_addr - op_array->opcodes < op_array->last);
assert(Z_OP(opline->op2).jmp_addr >= op_array->opcodes && Z_OP(opline->op2).jmp_addr - op_array->opcodes < op_array->last);
Z_OP(opline->op2).opline_num = Z_OP(opline->op2).jmp_addr - op_array->opcodes;
break;
}

Loading…
Cancel
Save