-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathphpdc.phpr
executable file
·95 lines (81 loc) · 1.73 KB
/
phpdc.phpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /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]", PHP_EOL;
echo " -c: decompile into PHP code", PHP_EOL;
echo " -d: dump into opcode", PHP_EOL;
echo " -a: input file is dasm opcode return from xcache_dasm_*", PHP_EOL;
echo " -h: this help page", PHP_EOL;
exit();
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();
}
}