1
0
Fork 0

Decompiler: add support for "run dboth" = both decompile and dump

master
Xuefer 2015-06-23 18:52:29 +08:00
parent 3f3d56cfd2
commit 4e5cb618a4
3 changed files with 29 additions and 15 deletions

View File

@ -15,7 +15,7 @@ if (!isset($argv)) {
}
$inputType = 'php';
$outputType = 'decompile';
$outputTypes = array();
$files = array();
reset($argv);
@ -30,11 +30,11 @@ while (($arg = next($argv)) !== false) {
break;
case '-c':
$outputType = 'php';
$outputTypes[] = 'php';
break;
case '-d':
$outputType = 'opcode';
$outputTypes[] = 'opcode';
break;
case '--':
@ -50,6 +50,13 @@ while (($arg = next($argv)) !== false) {
}
}
if ($outputTypes) {
$outputTypes = array_unique($outputTypes);
}
else {
$outputTypes[] = 'php';
}
if (!$files) {
$phpcode = '';
if (!defined('stdin')) {
@ -58,7 +65,7 @@ if (!$files) {
while (!feof(stdin)) {
$phpcode .= fgets(stdin);
}
$dc = new Decompiler($outputType);
$dc = new Decompiler($outputTypes);
if ($dc->decompileString($phpcode) === false) {
exit(2);
}
@ -66,7 +73,7 @@ if (!$files) {
}
else {
foreach ($files as $file) {
$dc = new Decompiler($outputType);
$dc = new Decompiler($outputTypes);
switch ($inputType) {
case 'opcode':
eval('$opcode = ' . file_get_contents($file) . ';');

View File

@ -310,11 +310,17 @@ run() {
cmd=(./php-cli -c devel.ini)
phpApp=(./bin/phpdc.phpr)
;;
dboth)
shift
cmd=(./php-cli -c devel.ini)
phpApp=(./bin/phpdc.phpr)
set -- -c -d "$@"
;;
dop)
shift
cmd=(./php-cli -c devel.ini)
phpApp=(./bin/phpdc.phpr)
set -- -d "$@"
set -- -c -d "$@"
;;
fcgi)
shift

View File

@ -591,11 +591,14 @@ class Decompiler
var $activeClass;
var $activeMethod;
var $activeFunction;
var $dumpOnly;
var $outputPhp;
var $outputOpcode;
var $inComment = 0;
function Decompiler($outputType)
function Decompiler($outputTypes)
{
$this->dumpOnly = $outputType == 'opcode';
$this->outputPhp = in_array('php', $outputTypes);
$this->outputOpcode = in_array('opcode', $outputTypes);
$GLOBALS['__xcache_decompiler'] = $this;
// {{{ testing
// XC_UNDEF XC_OP_DATA
@ -763,7 +766,7 @@ class Decompiler
case XC_IS_TMP_VAR:
$T = &$EX['Ts'];
if (!isset($T[$op['var']])) {
if (!$this->dumpOnly) {
if ($this->outputPhp && isset($free)) {
printBacktrace();
}
return null;
@ -1566,12 +1569,13 @@ class Decompiler
}
$range = array(0, count($opcodes) - 1, 'EX' => &$EX);
if ($this->dumpOnly) {
if ($this->outputOpcode) {
$this->keepTs = true;
$this->dasmBasicBlock($range);
$this->dumpRange($range);
$this->keepTs = false;
}
else {
if ($this->outputPhp) {
// decompile in a tree way
$this->recognizeAndDecompileClosedBlocks($range);
}
@ -2902,9 +2906,6 @@ class Decompiler
function output() // {{{
{
echo "<?". "php";
if ($this->dumpOnly) {
echo " // dump opcode only";
}
echo PHP_EOL, PHP_EOL;
foreach ($this->dc['class_table'] as $key => $class) {
if ($key{0} != "\0") {