You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
1.7 KiB
PHP
95 lines
1.7 KiB
PHP
#! /usr/bin/php -dopen_basedir=
|
|
<?php
|
|
|
|
// you should write your own phpdc.phpr file if you want to do batch decompile
|
|
// using glob and/or Recursive Directory Iterator
|
|
|
|
$srcdir = dirname(__FILE__);
|
|
require_once("$srcdir/../lib/Decompiler.class.php");
|
|
if (file_exists("$srcdir/phpdc.debug.php")) {
|
|
include("$srcdir/phpdc.debug.php");
|
|
}
|
|
|
|
if (!isset($argv)) {
|
|
$argv = $_SERVER['argv'];
|
|
}
|
|
|
|
$inputType = 'php';
|
|
$outputTypes = array();
|
|
$files = array();
|
|
|
|
reset($argv);
|
|
while (($arg = next($argv)) !== false) {
|
|
switch ($arg) {
|
|
case '-h':
|
|
echo "Usage: phpdc.phpr [-dca] [filename]";
|
|
echo " -c: decompile into PHP code";
|
|
echo " -d: dump into opcode";
|
|
echo " -a: input file is dasm opcode return from xcache_dasm_*";
|
|
echo " -h: this help page";
|
|
break;
|
|
|
|
case '-c':
|
|
$outputTypes[] = 'php';
|
|
break;
|
|
|
|
case '-d':
|
|
$outputTypes[] = 'opcode';
|
|
break;
|
|
|
|
case '--':
|
|
break 2;
|
|
|
|
case '-a':
|
|
$inputType = 'opcode';
|
|
break;
|
|
|
|
default:
|
|
$files[] = $arg;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($outputTypes) {
|
|
$outputTypes = array_unique($outputTypes);
|
|
}
|
|
else {
|
|
$outputTypes[] = 'php';
|
|
}
|
|
|
|
if (!$files) {
|
|
$phpcode = '';
|
|
if (!defined('stdin')) {
|
|
define('stdin', fopen('php://stdin', 'rb'));
|
|
}
|
|
while (!feof(stdin)) {
|
|
$phpcode .= fgets(stdin);
|
|
}
|
|
$dc = new Decompiler($outputTypes);
|
|
if ($dc->decompileString($phpcode) === false) {
|
|
exit(2);
|
|
}
|
|
$dc->output();
|
|
}
|
|
else {
|
|
foreach ($files as $file) {
|
|
$dc = new Decompiler($outputTypes);
|
|
switch ($inputType) {
|
|
case 'opcode':
|
|
eval('$opcode = ' . file_get_contents($file) . ';');
|
|
if ($dc->decompileDasm($opcode) === false) {
|
|
exit(2);
|
|
}
|
|
break;
|
|
|
|
case 'php';
|
|
if ($dc->decompileFile($file) === false) {
|
|
exit(2);
|
|
}
|
|
break;
|
|
}
|
|
$dc->output();
|
|
}
|
|
}
|
|
|