2006-05-09 10:58:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
define('INDENT', "\t");
|
|
|
|
ini_set('error_reporting', E_ALL);
|
|
|
|
|
|
|
|
function color($str, $color = 33)
|
|
|
|
{
|
|
|
|
return "\x1B[{$color}m$str\x1B[0m";
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($src, $indent = '') // {{{
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
if (is_array($indent)) {
|
|
|
|
$indent = $indent['indent'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_object($src)) {
|
2011-04-10 09:31:17 +00:00
|
|
|
if (!method_exists($src, 'toCode')) {
|
2006-05-09 10:58:38 +00:00
|
|
|
var_dump($src);
|
2011-04-10 09:31:17 +00:00
|
|
|
exit('no toCode');
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
return $src->toCode($indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $src;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function value($value) // {{{
|
|
|
|
{
|
|
|
|
$spec = xcache_get_special_value($value);
|
|
|
|
if (isset($spec)) {
|
|
|
|
$value = $spec;
|
|
|
|
if (!is_array($value)) {
|
|
|
|
// constant
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 11:48:12 +00:00
|
|
|
if ($value instanceof Decompiler_Object) {
|
|
|
|
// use as is
|
|
|
|
}
|
|
|
|
else if (is_array($value)) {
|
2011-04-08 18:27:55 +00:00
|
|
|
$value = new Decompiler_Array($value);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-08 18:27:55 +00:00
|
|
|
$value = new Decompiler_Value($value);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Object // {{{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Value extends Decompiler_Object // {{{
|
|
|
|
{
|
|
|
|
var $value;
|
|
|
|
|
|
|
|
function Decompiler_Value($value = null)
|
|
|
|
{
|
|
|
|
$this->value = $value;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
return var_export($this->value, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Code extends Decompiler_Object // {{{
|
|
|
|
{
|
|
|
|
var $src;
|
|
|
|
|
|
|
|
function Decompiler_Code($src)
|
|
|
|
{
|
|
|
|
$this->src = $src;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
return $this->src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Binop extends Decompiler_Code // {{{
|
|
|
|
{
|
|
|
|
var $opc;
|
|
|
|
var $op1;
|
|
|
|
var $op2;
|
|
|
|
var $parent;
|
2011-04-10 09:31:17 +00:00
|
|
|
var $indent;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
function Decompiler_Binop($parent, $op1, $opc, $op2)
|
|
|
|
{
|
|
|
|
$this->parent = &$parent;
|
|
|
|
$this->opc = $opc;
|
|
|
|
$this->op1 = $op1;
|
|
|
|
$this->op2 = $op2;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2011-04-10 09:31:17 +00:00
|
|
|
$op1 = toCode($this->op1, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) {
|
|
|
|
$op1 = "($op1)";
|
|
|
|
}
|
|
|
|
$opstr = $this->parent->binops[$this->opc];
|
|
|
|
if ($op1 == '0' && $this->opc == XC_SUB) {
|
2011-04-10 09:31:17 +00:00
|
|
|
return $opstr . toCode($this->op2, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Fetch extends Decompiler_Code // {{{
|
|
|
|
{
|
|
|
|
var $src;
|
|
|
|
var $fetchType;
|
|
|
|
|
|
|
|
function Decompiler_Fetch($src, $type, $globalsrc)
|
|
|
|
{
|
|
|
|
$this->src = $src;
|
|
|
|
$this->fetchType = $type;
|
|
|
|
$this->globalsrc = $globalsrc;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
switch ($this->fetchType) {
|
|
|
|
case ZEND_FETCH_LOCAL:
|
|
|
|
return '$' . substr($this->src, 1, -1);
|
|
|
|
case ZEND_FETCH_STATIC:
|
|
|
|
die('static fetch cant to string');
|
|
|
|
case ZEND_FETCH_GLOBAL:
|
|
|
|
case ZEND_FETCH_GLOBAL_LOCK:
|
|
|
|
return $this->globalsrc;
|
|
|
|
default:
|
|
|
|
var_dump($this->fetchType);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Box // {{{
|
|
|
|
{
|
|
|
|
var $obj;
|
|
|
|
|
|
|
|
function Decompiler_Box(&$obj)
|
|
|
|
{
|
|
|
|
$this->obj = &$obj;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2011-04-10 09:31:17 +00:00
|
|
|
return $this->obj->toCode($indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Dim extends Decompiler_Value // {{{
|
|
|
|
{
|
|
|
|
var $offsets = array();
|
|
|
|
var $isLast = false;
|
|
|
|
var $assign = null;
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
if (is_a($this->value, 'Decompiler_ListBox')) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$exp = toCode($this->value->obj->src, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-10 09:31:17 +00:00
|
|
|
$exp = toCode($this->value, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
foreach ($this->offsets as $dim) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$exp .= '[' . toCode($dim, $indent) . ']';
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
return $exp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_DimBox extends Decompiler_Box // {{{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_List extends Decompiler_Code // {{{
|
|
|
|
{
|
|
|
|
var $src;
|
|
|
|
var $dims = array();
|
|
|
|
var $everLocked = false;
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
if (count($this->dims) == 1 && !$this->everLocked) {
|
|
|
|
$dim = $this->dims[0];
|
|
|
|
unset($dim->value);
|
|
|
|
$dim->value = $this->src;
|
|
|
|
if (!isset($dim->assign)) {
|
2011-04-10 09:31:17 +00:00
|
|
|
return toCode($dim, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* flatten dims */
|
|
|
|
$assigns = array();
|
|
|
|
foreach ($this->dims as $dim) {
|
|
|
|
$assign = &$assigns;
|
|
|
|
foreach ($dim->offsets as $offset) {
|
|
|
|
$assign = &$assign[$offset];
|
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
$assign = toCode($dim->assign, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
return $this->toList($assigns) . ' = ' . toCode($this->src, $indent);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toList($assigns)
|
|
|
|
{
|
|
|
|
$keys = array_keys($assigns);
|
|
|
|
if (count($keys) < 2) {
|
|
|
|
$keys[] = 0;
|
|
|
|
}
|
|
|
|
$max = call_user_func_array('max', $keys);
|
|
|
|
$list = 'list(';
|
|
|
|
for ($i = 0; $i <= $max; $i ++) {
|
|
|
|
if ($i) {
|
|
|
|
$list .= ', ';
|
|
|
|
}
|
|
|
|
if (!isset($assigns[$i])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (is_array($assigns[$i])) {
|
|
|
|
$list .= $this->toList($assigns[$i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$list .= $assigns[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $list . ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_ListBox extends Decompiler_Box // {{{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_Array extends Decompiler_Value // {{{
|
|
|
|
{
|
2011-04-10 09:31:17 +00:00
|
|
|
function Decompiler_Array($value = array())
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
$this->value = $value;
|
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
$exp = "array(";
|
2011-04-10 09:31:17 +00:00
|
|
|
$indent = $indent . INDENT;
|
2011-04-10 14:09:17 +00:00
|
|
|
$assocWidth = 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
$multiline = 0;
|
|
|
|
$i = 0;
|
|
|
|
foreach ($this->value as $k => $v) {
|
|
|
|
if ($i !== $k) {
|
2011-04-10 14:09:17 +00:00
|
|
|
$assocWidth = 1;
|
|
|
|
}
|
|
|
|
++$i;
|
|
|
|
}
|
|
|
|
foreach ($this->value as $k => $v) {
|
|
|
|
if ($assocWidth) {
|
2006-05-09 10:58:38 +00:00
|
|
|
$len = strlen($k);
|
2011-04-10 14:09:17 +00:00
|
|
|
if ($assocWidth < $len) {
|
|
|
|
$assocWidth = $len;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
$spec = xcache_get_special_value($v);
|
|
|
|
if (is_array(isset($spec) ? $spec : $v)) {
|
2006-05-09 10:58:38 +00:00
|
|
|
$multiline ++;
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 14:09:17 +00:00
|
|
|
if ($assocWidth) {
|
|
|
|
$assocWidth += 2;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$subindent = $indent . INDENT;
|
|
|
|
foreach ($this->value as $k => $v) {
|
|
|
|
if ($multiline) {
|
|
|
|
if ($i) {
|
|
|
|
$exp .= ",";
|
|
|
|
}
|
|
|
|
$exp .= "\n";
|
|
|
|
$exp .= $indent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($i) {
|
|
|
|
$exp .= ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 18:27:55 +00:00
|
|
|
$k = var_export($k, true);
|
2011-04-10 14:09:17 +00:00
|
|
|
if ($assocWidth) {
|
|
|
|
if ($multiline) {
|
|
|
|
$exp .= sprintf("%{$assocWidth}s => ", $k);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$exp .= $k . ' => ';
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
$exp .= toCode(value($v), $subindent);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
$i ++;
|
|
|
|
}
|
|
|
|
if ($multiline) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$exp .= "\n$indent)";
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$exp .= ")";
|
|
|
|
}
|
|
|
|
return $exp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
class Decompiler_ForeachBox extends Decompiler_Box // {{{
|
|
|
|
{
|
|
|
|
var $iskey;
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
function toCode($indent)
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
return 'foreach (' . '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
class Decompiler
|
|
|
|
{
|
|
|
|
var $rName = '!^[\\w_][\\w\\d_]*$!';
|
|
|
|
var $rQuotedName = "!^'[\\w_][\\w\\d_]*'\$!";
|
|
|
|
|
|
|
|
function Decompiler()
|
|
|
|
{
|
|
|
|
// {{{ opinfo
|
|
|
|
$this->unaryops = array(
|
|
|
|
XC_BW_NOT => '~',
|
|
|
|
XC_BOOL_NOT => '!',
|
|
|
|
);
|
|
|
|
$this->binops = array(
|
|
|
|
XC_ADD => "+",
|
|
|
|
XC_ASSIGN_ADD => "+=",
|
|
|
|
XC_SUB => "-",
|
|
|
|
XC_ASSIGN_SUB => "-=",
|
|
|
|
XC_MUL => "*",
|
|
|
|
XC_ASSIGN_MUL => "*=",
|
|
|
|
XC_DIV => "/",
|
|
|
|
XC_ASSIGN_DIV => "/=",
|
|
|
|
XC_MOD => "%",
|
|
|
|
XC_ASSIGN_MOD => "%=",
|
|
|
|
XC_SL => "<<",
|
|
|
|
XC_ASSIGN_SL => "<<=",
|
|
|
|
XC_SR => ">>",
|
|
|
|
XC_ASSIGN_SR => ">>=",
|
|
|
|
XC_CONCAT => ".",
|
|
|
|
XC_ASSIGN_CONCAT => ".=",
|
|
|
|
XC_IS_IDENTICAL => "===",
|
|
|
|
XC_IS_NOT_IDENTICAL => "!==",
|
|
|
|
XC_IS_EQUAL => "==",
|
|
|
|
XC_IS_NOT_EQUAL => "!=",
|
|
|
|
XC_IS_SMALLER => "<",
|
|
|
|
XC_IS_SMALLER_OR_EQUAL => "<=",
|
|
|
|
XC_BW_OR => "|",
|
|
|
|
XC_ASSIGN_BW_OR => "|=",
|
|
|
|
XC_BW_AND => "&",
|
|
|
|
XC_ASSIGN_BW_AND => "&=",
|
|
|
|
XC_BW_XOR => "^",
|
|
|
|
XC_ASSIGN_BW_XOR => "^=",
|
|
|
|
XC_BOOL_XOR => "xor",
|
|
|
|
);
|
|
|
|
// }}}
|
|
|
|
$this->includeTypes = array( // {{{
|
|
|
|
ZEND_EVAL => 'eval',
|
|
|
|
ZEND_INCLUDE => 'include',
|
|
|
|
ZEND_INCLUDE_ONCE => 'include_once',
|
|
|
|
ZEND_REQUIRE => 'require',
|
|
|
|
ZEND_REQUIRE_ONCE => 'require_once',
|
|
|
|
);
|
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
function outputPhp(&$opcodes, $opline, $last, $indent) // {{{
|
|
|
|
{
|
|
|
|
$origindent = $indent;
|
|
|
|
$curticks = 0;
|
|
|
|
for ($i = $opline; $i <= $last; $i ++) {
|
|
|
|
$op = $opcodes[$i];
|
|
|
|
if (isset($op['php'])) {
|
|
|
|
$toticks = isset($op['ticks']) ? $op['ticks'] : 0;
|
|
|
|
if ($curticks != $toticks) {
|
|
|
|
if (!$toticks) {
|
|
|
|
echo $origindent, "}\n";
|
|
|
|
$indent = $origindent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($curticks) {
|
|
|
|
echo $origindent, "}\n";
|
|
|
|
}
|
|
|
|
else if (!$curticks) {
|
|
|
|
$indent .= INDENT;
|
|
|
|
}
|
|
|
|
echo $origindent, "declare(ticks=$curticks) {\n";
|
|
|
|
}
|
|
|
|
$curticks = $toticks;
|
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
echo $indent, toCode($op['php'], $indent), ";\n";
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($curticks) {
|
|
|
|
echo $origindent, "}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function getOpVal($op, &$EX, $tostr = true, $free = false) // {{{
|
|
|
|
{
|
|
|
|
switch ($op['op_type']) {
|
|
|
|
case XC_IS_CONST:
|
2011-04-10 09:31:17 +00:00
|
|
|
return toCode(value($op['constant']), $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
case XC_IS_VAR:
|
|
|
|
case XC_IS_TMP_VAR:
|
|
|
|
$T = &$EX['Ts'];
|
2011-04-09 07:07:48 +00:00
|
|
|
$ret = $T[$op['var']];
|
2006-05-09 10:58:38 +00:00
|
|
|
if ($tostr) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$ret = toCode($ret, $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
if ($free) {
|
2011-04-09 07:07:48 +00:00
|
|
|
unset($T[$op['var']]);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case XC_IS_CV:
|
2011-04-09 07:07:48 +00:00
|
|
|
$var = $op['var'];
|
2006-05-09 10:58:38 +00:00
|
|
|
$var = $EX['op_array']['vars'][$var];
|
|
|
|
return '$' . $var['name'];
|
|
|
|
|
|
|
|
case XC_IS_UNUSED:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
2011-04-09 07:07:48 +00:00
|
|
|
function removeKeyPrefix($array, $prefix) // {{{
|
|
|
|
{
|
|
|
|
$prefixLen = strlen($prefix);
|
|
|
|
$ret = array();
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
if (substr($key, 0, $prefixLen) == $prefix) {
|
|
|
|
$key = substr($key, $prefixLen);
|
|
|
|
}
|
|
|
|
$ret[$key] = $value;
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
// }}}
|
2011-04-10 14:09:17 +00:00
|
|
|
function &fixOpcode($opcodes, $removeTailing = false, $defaultReturnValue = null) // {{{
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2011-04-09 07:07:48 +00:00
|
|
|
for ($i = 0, $cnt = count($opcodes); $i < $cnt; $i ++) {
|
|
|
|
if (function_exists('xcache_get_fixed_opcode')) {
|
|
|
|
$opcodes[$i]['opcode'] = xcache_get_fixed_opcode($opcodes[$i]['opcode'], $i);
|
|
|
|
}
|
|
|
|
if (isset($opcodes[$i]['op1'])) {
|
|
|
|
$opcodes[$i]['op1'] = $this->removeKeyPrefix($opcodes[$i]['op1'], 'u.');
|
|
|
|
$opcodes[$i]['op2'] = $this->removeKeyPrefix($opcodes[$i]['op2'], 'u.');
|
|
|
|
$opcodes[$i]['result'] = $this->removeKeyPrefix($opcodes[$i]['result'], 'u.');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$op = array(
|
|
|
|
'op1' => array(),
|
|
|
|
'op2' => array(),
|
|
|
|
'op3' => array(),
|
|
|
|
);
|
|
|
|
foreach ($opcodes[$i] as $name => $value) {
|
|
|
|
if (preg_match('!^(op1|op2|result)\\.(.*)!', $name, $m)) {
|
|
|
|
list(, $which, $field) = $m;
|
|
|
|
$op[$which][$field] = $value;
|
|
|
|
}
|
|
|
|
else if (preg_match('!^(op1|op2|result)_type$!', $name, $m)) {
|
|
|
|
list(, $which) = $m;
|
|
|
|
$op[$which]['op_type'] = $value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$op[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$opcodes[$i] = $op;
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 14:09:17 +00:00
|
|
|
|
|
|
|
if ($removeTailing) {
|
|
|
|
$last = count($opcodes) - 1;
|
|
|
|
if ($opcodes[$last]['opcode'] == XC_HANDLE_EXCEPTION) {
|
|
|
|
unset($opcodes[$last]);
|
|
|
|
--$last;
|
|
|
|
}
|
|
|
|
if ($opcodes[$last]['opcode'] == XC_RETURN) {
|
|
|
|
$op1 = $opcodes[$last]['op1'];
|
|
|
|
if ($op1['op_type'] == XC_IS_CONST && array_key_exists('constant', $op1) && $op1['constant'] === $defaultReturnValue) {
|
|
|
|
unset($opcodes[$last]);
|
|
|
|
--$last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 09:07:58 +00:00
|
|
|
return $opcodes;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function &dop_array($op_array, $indent = '') // {{{
|
|
|
|
{
|
2011-04-10 14:09:17 +00:00
|
|
|
$op_array['opcodes'] = $this->fixOpcode($op_array['opcodes'], true, $indent == '' ? 1 : null);
|
2011-04-10 09:07:58 +00:00
|
|
|
$opcodes = &$op_array['opcodes'];
|
|
|
|
$EX['indent'] = '';
|
2006-05-09 10:58:38 +00:00
|
|
|
// {{{ build jmp array
|
|
|
|
for ($i = 0, $cnt = count($opcodes); $i < $cnt; $i ++) {
|
|
|
|
$op = &$opcodes[$i];
|
|
|
|
/*
|
|
|
|
if ($op['opcode'] == XC_JMPZ) {
|
|
|
|
$this->dumpop($op, $EX);
|
|
|
|
var_dump($op);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
*/
|
|
|
|
$op['line'] = $i;
|
|
|
|
switch ($op['opcode']) {
|
|
|
|
case XC_JMP:
|
2011-04-09 07:07:48 +00:00
|
|
|
$target = $op['op1']['var'];
|
2006-05-09 10:58:38 +00:00
|
|
|
$op['jmpouts'] = array($target);
|
|
|
|
$opcodes[$target]['jmpins'][] = $i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XC_JMPZNZ:
|
2011-04-09 07:07:48 +00:00
|
|
|
$jmpz = $op['op2']['opline_num'];
|
2006-05-09 10:58:38 +00:00
|
|
|
$jmpnz = $op['extended_value'];
|
|
|
|
$op['jmpouts'] = array($jmpz, $jmpnz);
|
|
|
|
$opcodes[$jmpz]['jmpins'][] = $i;
|
|
|
|
$opcodes[$jmpnz]['jmpins'][] = $i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XC_JMPZ:
|
|
|
|
case XC_JMPNZ:
|
|
|
|
case XC_JMPZ_EX:
|
|
|
|
case XC_JMPNZ_EX:
|
|
|
|
// case XC_FE_RESET:
|
|
|
|
case XC_FE_FETCH:
|
|
|
|
// case XC_JMP_NO_CTOR:
|
2011-04-09 07:07:48 +00:00
|
|
|
$target = $op['op2']['opline_num'];
|
2006-05-09 10:58:38 +00:00
|
|
|
//if (!isset($target)) {
|
|
|
|
// $this->dumpop($op, $EX);
|
|
|
|
// var_dump($op); exit;
|
|
|
|
//}
|
|
|
|
$op['jmpouts'] = array($target);
|
|
|
|
$opcodes[$target]['jmpins'][] = $i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
case XC_RETURN:
|
|
|
|
$op['jmpouts'] = array();
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($op);
|
|
|
|
// }}}
|
|
|
|
// build semi-basic blocks
|
|
|
|
$nextbbs = array();
|
|
|
|
$starti = 0;
|
|
|
|
for ($i = 1, $cnt = count($opcodes); $i < $cnt; $i ++) {
|
|
|
|
if (isset($opcodes[$i]['jmpins'])
|
|
|
|
|| isset($opcodes[$i - 1]['jmpouts'])) {
|
|
|
|
$nextbbs[$starti] = $i;
|
|
|
|
$starti = $i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$nextbbs[$starti] = $cnt;
|
|
|
|
|
|
|
|
$EX = array();
|
|
|
|
$EX['Ts'] = array();
|
|
|
|
$EX['indent'] = $indent;
|
|
|
|
$EX['nextbbs'] = $nextbbs;
|
|
|
|
$EX['op_array'] = &$op_array;
|
|
|
|
$EX['opcodes'] = &$opcodes;
|
|
|
|
// func call
|
|
|
|
$EX['object'] = null;
|
2011-04-09 11:02:07 +00:00
|
|
|
$EX['called_scope'] = null;
|
2006-05-09 10:58:38 +00:00
|
|
|
$EX['fbc'] = null;
|
|
|
|
$EX['argstack'] = array();
|
|
|
|
$EX['arg_types_stack'] = array();
|
|
|
|
$EX['last'] = count($opcodes) - 1;
|
|
|
|
$EX['silence'] = 0;
|
|
|
|
|
|
|
|
for ($next = 0, $last = $EX['last'];
|
|
|
|
$loop = $this->outputCode($EX, $next, $last, $indent, true);
|
|
|
|
list($next, $last) = $loop) {
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
return $EX;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function outputCode(&$EX, $opline, $last, $indent, $loop = false) // {{{
|
|
|
|
{
|
|
|
|
$op = &$EX['opcodes'][$opline];
|
|
|
|
$next = $EX['nextbbs'][$opline];
|
|
|
|
|
|
|
|
$end = $next - 1;
|
|
|
|
if ($end > $last) {
|
|
|
|
$end = $last;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($op['jmpins'])) {
|
|
|
|
echo "\nline", $op['line'], ":\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// echo ";;;\n";
|
|
|
|
}
|
|
|
|
$this->dasmBasicBlock($EX, $opline, $end);
|
|
|
|
$this->outputPhp($EX['opcodes'], $opline, $end, $indent);
|
|
|
|
// jmpout op
|
|
|
|
$op = &$EX['opcodes'][$end];
|
|
|
|
$op1 = $op['op1'];
|
|
|
|
$op2 = $op['op2'];
|
|
|
|
$ext = $op['extended_value'];
|
|
|
|
$line = $op['line'];
|
|
|
|
|
|
|
|
if (isset($EX['opcodes'][$next])) {
|
|
|
|
if (isset($last) && $next > $last) {
|
|
|
|
$next = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$next = null;
|
|
|
|
}
|
|
|
|
if ($op['opcode'] == XC_FE_FETCH) {
|
|
|
|
$opline = $next;
|
2011-04-09 07:07:48 +00:00
|
|
|
$next = $op['op2']['opline_num'];
|
2006-05-09 10:58:38 +00:00
|
|
|
$end = $next - 1;
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$this->outputCode($EX, $opline, $end /* - 1 skip last jmp */, $indent . INDENT);
|
|
|
|
$body = ob_get_clean();
|
|
|
|
|
2011-04-10 09:31:17 +00:00
|
|
|
$as = toCode($op['fe_as'], $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (isset($op['fe_key'])) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$as = toCode($op['fe_key'], $EX) . ' => ' . $as;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n";
|
2006-05-09 10:58:38 +00:00
|
|
|
echo $body;
|
|
|
|
echo "{$indent}}";
|
|
|
|
// $this->outputCode($EX, $next, $last, $indent);
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if ($op['opcode'] == XC_JMPZ) {
|
2011-04-09 07:07:48 +00:00
|
|
|
$target = $op2['opline_num'];
|
2006-05-09 10:58:38 +00:00
|
|
|
if ($line + 1) {
|
|
|
|
$nextblock = $EX['nextbbs'][$next];
|
|
|
|
$jmpop = end($nextblock);
|
|
|
|
if ($jmpop['opcode'] == XC_JMP) {
|
2011-04-09 07:07:48 +00:00
|
|
|
$ifendline = $op2['opline_num'];
|
2006-05-09 10:58:38 +00:00
|
|
|
if ($ifendline >= $line) {
|
|
|
|
$cond = $op['cond'];
|
|
|
|
echo "{$indent}if ($cond) {\n";
|
|
|
|
$this->outputCode($EX, $next, $last, INDENT . $indent);
|
|
|
|
echo "$indent}\n";
|
|
|
|
$this->outputCode($EX, $target, $last, $indent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (!isset($next)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!empty($op['jmpouts']) && isset($op['isjmp'])) {
|
|
|
|
if (isset($op['cond'])) {
|
|
|
|
echo "{$indent}check ($op[cond]) {\n";
|
|
|
|
echo INDENT;
|
|
|
|
}
|
|
|
|
echo $indent;
|
|
|
|
echo xcache_get_opcode($op['opcode']), ' line', $op['jmpouts'][0];
|
|
|
|
if (isset($op['jmpouts'][1])) {
|
|
|
|
echo ', line', $op['jmpouts'][1];
|
|
|
|
}
|
|
|
|
echo ";";
|
|
|
|
// echo ' // <- line', $op['line'];
|
|
|
|
echo "\n";
|
|
|
|
if (isset($op['cond'])) echo "$indent}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// proces JMPZ_EX/JMPNZ_EX for AND,OR
|
|
|
|
$op = &$EX['opcodes'][$next];
|
|
|
|
/*
|
|
|
|
if (isset($op['jmpins'])) {
|
|
|
|
foreach (array_reverse($op['jmpins']) as $fromline) {
|
|
|
|
$fromop = $EX['opcodes'][$fromline];
|
|
|
|
switch ($fromop['opcode']) {
|
|
|
|
case XC_JMPZ_EX: $opstr = 'and'; break;
|
|
|
|
case XC_JMPNZ_EX: $opstr = 'or'; break;
|
|
|
|
case XC_JMPZNZ: var_dump($fromop); exit;
|
|
|
|
default: continue 2;
|
|
|
|
}
|
|
|
|
|
2011-04-09 07:07:48 +00:00
|
|
|
$var = $fromop['result']['var'];
|
2006-05-09 10:58:38 +00:00
|
|
|
var_dump($EX['Ts'][$var]);
|
|
|
|
$EX['Ts'][$var] = '(' . $fromop['and_or'] . " $opstr " . $EX['Ts'][$var] . ')';
|
|
|
|
}
|
|
|
|
#$this->outputCode($EX, $next, $last, $indent);
|
|
|
|
#return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (isset($op['cond_false'])) {
|
|
|
|
// $this->dumpop($op, $EX);
|
|
|
|
// any true comes here, so it's a "or"
|
|
|
|
$cond = implode(' and ', $op['cond_false']);
|
|
|
|
// var_dump($op['cond'] = $cond);
|
|
|
|
/*
|
|
|
|
$rvalue = implode(' or ', $op['cond_true']) . ' or ' . $rvalue;
|
|
|
|
unset($op['cond_true']);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($loop) {
|
|
|
|
return array($next, $last);
|
|
|
|
}
|
|
|
|
$this->outputCode($EX, $next, $last, $indent);
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function unquoteName($str) // {{{
|
|
|
|
{
|
|
|
|
if (preg_match($this->rQuotedName, $str)) {
|
|
|
|
$str = substr($str, 1, -1);
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
function dasmBasicBlock(&$EX, $opline, $last) // {{{
|
|
|
|
{
|
|
|
|
$T = &$EX['Ts'];
|
|
|
|
$opcodes = &$EX['opcodes'];
|
|
|
|
$lastphpop = null;
|
|
|
|
|
|
|
|
for ($i = $opline, $ic = $last + 1; $i < $ic; $i ++) {
|
|
|
|
// {{{ prepair
|
|
|
|
$op = &$opcodes[$i];
|
|
|
|
$opc = $op['opcode'];
|
|
|
|
if ($opc == XC_NOP) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$op1 = $op['op1'];
|
|
|
|
$op2 = $op['op2'];
|
|
|
|
$res = $op['result'];
|
|
|
|
$ext = $op['extended_value'];
|
|
|
|
|
|
|
|
$opname = xcache_get_opcode($opc);
|
|
|
|
|
|
|
|
if ($opname == 'UNDEF' || !isset($opname)) {
|
|
|
|
echo 'UNDEF OP:';
|
|
|
|
$this->dumpop($op, $EX);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// $this->dumpop($op, $EX); //var_dump($op);
|
|
|
|
|
|
|
|
$resvar = null;
|
2011-04-10 09:07:58 +00:00
|
|
|
if ((ZEND_ENGINE_2_4 ? ($res['op_type'] & EXT_TYPE_UNUSED) : ($res['EA.type'] & EXT_TYPE_UNUSED)) || $res['op_type'] == XC_IS_UNUSED) {
|
2006-05-09 10:58:38 +00:00
|
|
|
$istmpres = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$istmpres = true;
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
// echo $opname, "\n";
|
|
|
|
|
|
|
|
$call = array(&$this, $opname);
|
|
|
|
if (is_callable($call)) {
|
|
|
|
$this->{$opname}($op, $EX);
|
|
|
|
}
|
|
|
|
else if (isset($this->binops[$opc])) { // {{{
|
|
|
|
$op1val = $this->getOpVal($op1, $EX, false);
|
|
|
|
$op2val = $this->getOpVal($op2, $EX, false);
|
|
|
|
$rvalue = new Decompiler_Binop($this, $op1val, $opc, $op2val);
|
|
|
|
$resvar = $rvalue;
|
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
else if (isset($this->unaryops[$opc])) { // {{{
|
|
|
|
$op1val = $this->getOpVal($op1, $EX);
|
|
|
|
$myop = $this->unaryops[$opc];
|
|
|
|
$rvalue = "$myop$op1val";
|
|
|
|
$resvar = $rvalue;
|
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch ($opc) {
|
|
|
|
case XC_NEW: // {{{
|
2011-04-09 11:02:07 +00:00
|
|
|
array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope']));
|
2011-04-09 07:07:48 +00:00
|
|
|
$EX['object'] = (int) $res['var'];
|
2011-04-09 11:02:07 +00:00
|
|
|
$EX['called_scope'] = null;
|
2006-05-09 10:58:38 +00:00
|
|
|
$EX['fbc'] = 'new ' . $this->unquoteName($this->getOpVal($op1, $EX));
|
2011-04-10 09:07:58 +00:00
|
|
|
if (!ZEND_ENGINE_2) {
|
2006-05-09 10:58:38 +00:00
|
|
|
$resvar = '$new object$';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
case XC_FETCH_CLASS: // {{{
|
|
|
|
if ($op2['op_type'] == XC_IS_UNUSED) {
|
2011-04-10 09:07:58 +00:00
|
|
|
switch (($ext & (defined('ZEND_FETCH_CLASS_MASK') ? ZEND_FETCH_CLASS_MASK : 0xFF))) {
|
2006-05-09 10:58:38 +00:00
|
|
|
case ZEND_FETCH_CLASS_SELF:
|
|
|
|
$class = 'self';
|
|
|
|
break;
|
|
|
|
case ZEND_FETCH_CLASS_PARENT:
|
|
|
|
$class = 'parent';
|
2011-04-09 11:41:07 +00:00
|
|
|
break;
|
|
|
|
case ZEND_FETCH_CLASS_STATIC:
|
|
|
|
$class = 'static';
|
|
|
|
break;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-09 11:41:07 +00:00
|
|
|
$istmpres = true;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-09 07:07:48 +00:00
|
|
|
$class = $op2['constant'];
|
2006-05-09 10:58:38 +00:00
|
|
|
if (is_object($class)) {
|
|
|
|
$class = get_class($class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$resvar = $class;
|
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
case XC_FETCH_CONSTANT: // {{{
|
|
|
|
if ($op1['op_type'] == XC_IS_CONST) {
|
2011-04-09 07:07:48 +00:00
|
|
|
$resvar = $op1['constant'];
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else if ($op1['op_type'] == XC_IS_UNUSED) {
|
2011-04-09 07:07:48 +00:00
|
|
|
$resvar = $op2['constant'];
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-09 07:07:48 +00:00
|
|
|
$class = $T[$op1['var']];
|
2006-05-09 10:58:38 +00:00
|
|
|
assert($class[0] == 'class');
|
2011-04-09 07:07:48 +00:00
|
|
|
$resvar = $class[1] . '::' . $op2['constant'];
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
// {{{ case XC_FETCH_*
|
|
|
|
case XC_FETCH_R:
|
|
|
|
case XC_FETCH_W:
|
|
|
|
case XC_FETCH_RW:
|
|
|
|
case XC_FETCH_FUNC_ARG:
|
|
|
|
case XC_FETCH_UNSET:
|
|
|
|
case XC_FETCH_IS:
|
|
|
|
case XC_UNSET_VAR:
|
|
|
|
$rvalue = $this->getOpVal($op1, $EX);
|
2011-04-10 09:07:58 +00:00
|
|
|
if (defined('ZEND_FETCH_TYPE_MASK')) {
|
|
|
|
$fetchtype = ($ext & ZEND_FETCH_TYPE_MASK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fetchtype = $op2[!ZEND_ENGINE_2 ? 'fetch_type' : 'EA.type'];
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
switch ($fetchtype) {
|
|
|
|
case ZEND_FETCH_STATIC_MEMBER:
|
|
|
|
$class = $this->getOpVal($op2, $EX);
|
|
|
|
$rvalue = $class . '::$' . $this->unquoteName($rvalue);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$name = $this->unquoteName($rvalue);
|
|
|
|
$globalname = xcache_is_autoglobal($name) ? "\$$name" : "\$GLOBALS[$rvalue]";
|
|
|
|
$rvalue = new Decompiler_Fetch($rvalue, $fetchtype, $globalname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($opc == XC_UNSET_VAR) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
|
2006-05-09 10:58:38 +00:00
|
|
|
$lastphpop = &$op;
|
|
|
|
}
|
|
|
|
else if ($res['op_type'] != XC_IS_UNUSED) {
|
|
|
|
$resvar = $rvalue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
// {{{ case XC_FETCH_DIM_*
|
|
|
|
case XC_FETCH_DIM_TMP_VAR:
|
|
|
|
case XC_FETCH_DIM_R:
|
|
|
|
case XC_FETCH_DIM_W:
|
|
|
|
case XC_FETCH_DIM_RW:
|
|
|
|
case XC_FETCH_DIM_FUNC_ARG:
|
|
|
|
case XC_FETCH_DIM_UNSET:
|
|
|
|
case XC_FETCH_DIM_IS:
|
|
|
|
case XC_ASSIGN_DIM:
|
|
|
|
case XC_UNSET_DIM:
|
|
|
|
case XC_UNSET_DIM_OBJ:
|
|
|
|
$src = $this->getOpVal($op1, $EX, false);
|
|
|
|
if (is_a($src, "Decompiler_ForeachBox")) {
|
|
|
|
$src->iskey = $this->getOpVal($op2, $EX);
|
|
|
|
$resvar = $src;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (is_a($src, "Decompiler_DimBox")) {
|
|
|
|
$dimbox = $src;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!is_a($src, "Decompiler_ListBox")) {
|
|
|
|
$list = new Decompiler_List($this->getOpVal($op1, $EX, false));
|
|
|
|
|
|
|
|
$src = new Decompiler_ListBox($list);
|
2011-04-09 07:07:48 +00:00
|
|
|
if (!isset($op1['var'])) {
|
2006-05-09 10:58:38 +00:00
|
|
|
$this->dumpop($op, $EX);
|
|
|
|
var_dump($op);
|
2011-04-09 07:07:48 +00:00
|
|
|
die('missing var');
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2011-04-09 07:07:48 +00:00
|
|
|
$T[$op1['var']] = $src;
|
2006-05-09 10:58:38 +00:00
|
|
|
unset($list);
|
|
|
|
}
|
|
|
|
$dim = new Decompiler_Dim($src);
|
|
|
|
$src->obj->dims[] = &$dim;
|
|
|
|
|
|
|
|
$dimbox = new Decompiler_DimBox($dim);
|
|
|
|
}
|
|
|
|
$dim = &$dimbox->obj;
|
|
|
|
$dim->offsets[] = $this->getOpVal($op2, $EX);
|
|
|
|
if ($ext == ZEND_FETCH_ADD_LOCK) {
|
|
|
|
$src->obj->everLocked = true;
|
|
|
|
}
|
|
|
|
else if ($ext == ZEND_FETCH_STANDARD) {
|
|
|
|
$dim->isLast = true;
|
|
|
|
}
|
|
|
|
unset($dim);
|
|
|
|
$rvalue = $dimbox;
|
|
|
|
|
|
|
|
if ($opc == XC_ASSIGN_DIM) {
|
|
|
|
$lvalue = $rvalue;
|
|
|
|
++ $i;
|
|
|
|
$rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX);
|
2011-04-10 09:31:17 +00:00
|
|
|
$resvar = toCode($lvalue, $EX) . ' = ' . $rvalue;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else if ($opc == XC_UNSET_DIM) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
|
2006-05-09 10:58:38 +00:00
|
|
|
$lastphpop = &$op;
|
|
|
|
}
|
|
|
|
else if ($res['op_type'] != XC_IS_UNUSED) {
|
|
|
|
$resvar = $rvalue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
case XC_ASSIGN: // {{{
|
|
|
|
$lvalue = $this->getOpVal($op1, $EX);
|
|
|
|
$rvalue = $this->getOpVal($op2, $EX, false);
|
|
|
|
if (is_a($rvalue, 'Decompiler_ForeachBox')) {
|
|
|
|
$type = $rvalue->iskey ? 'fe_key' : 'fe_as';
|
|
|
|
$rvalue->obj[$type] = $lvalue;
|
2011-04-09 07:07:48 +00:00
|
|
|
unset($T[$op2['var']]);
|
2006-05-09 10:58:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (is_a($rvalue, "Decompiler_DimBox")) {
|
|
|
|
$dim = &$rvalue->obj;
|
|
|
|
$dim->assign = $lvalue;
|
|
|
|
if ($dim->isLast) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$resvar = toCode($dim->value, $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
unset($dim);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-10 09:31:17 +00:00
|
|
|
$resvar = "$lvalue = " . toCode($rvalue, $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
break;
|
|
|
|
// }}}
|
|
|
|
case XC_ASSIGN_REF: // {{{
|
|
|
|
$lvalue = $this->getOpVal($op1, $EX);
|
|
|
|
$rvalue = $this->getOpVal($op2, $EX, false);
|
|
|
|
if (is_a($rvalue, 'Decompiler_Fetch')) {
|
2011-04-10 09:31:17 +00:00
|
|
|
$src = toCode($rvalue->src, $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
if (substr($src, 1, -1) == substr($lvalue, 1)) {
|
|
|
|
switch ($rvalue->fetchType) {
|
|
|
|
case ZEND_FETCH_GLOBAL:
|
2011-04-10 09:07:58 +00:00
|
|
|
case ZEND_FETCH_GLOBAL_LOCK:
|
2006-05-09 10:58:38 +00:00
|
|
|
$resvar = 'global ' . $lvalue;
|
|
|
|
break 2;
|
|
|
|
case ZEND_FETCH_STATIC:
|
|
|
|
$statics = &$EX['op_array']['static_variables'];
|
|
|
|
$resvar = 'static ' . $lvalue;
|
|
|
|
$name = substr($src, 1, -1);
|
|
|
|
if (isset($statics[$name])) {
|
|
|
|
$var = $statics[$name];
|
|
|
|
$resvar .= ' = ';
|
2011-04-10 09:31:17 +00:00
|
|
|
$resvar .= toCode(value($var), $EX);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
unset($statics);
|
|
|
|
break 2;
|
2011-04-10 09:07:58 +00:00
|
|
|
default:
|
2006-05-09 10:58:38 +00:00
|