forked from dawwinci/decode-Zend-Guard-php-5.6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpdop.phpr
130 lines (115 loc) · 2.6 KB
/
phpdop.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/php
<?php
$srcdir = dirname(__FILE__);
require_once("$srcdir/Decompiler.class.php");
if (file_exists("$srcdir/phpdc.debug.php")) {
include("$srcdir/phpdc.debug.php");
}
function get_op($op)
{
switch ($op['op_type']) {
case 1: // CONST
return var_export($op['constant'], true);
case 2: // IS_TMP_VAR
return 't@' . $op['var'];
case 4:
return 'v$' . $op['var'];
case 8: // UNUSED
if (isset($op['opline_num'])) {
return 'l#' . $op['opline_num'];
}
else {
return '-';
}
default:
return $op['op_type'] . $op['var'];
}
}
function dump_opcodes($opcodes, $indent = '')
{
global $decompiler;
$types = array('result' => 5, 'op1' => 20, 'op2' => 20);
foreach ($decompiler->fixOpcode($opcodes) as $line => $op) {
echo $indent;
echo sprintf("%3d ", $op['lineno']);
echo sprintf("%3x ", $line);
$name = xcache_get_opcode($op['opcode']);
if (substr($name, 0, 5) == 'ZEND_') {
$name = substr($name, 5);
}
echo str_pad($name, 25);
foreach ($types as $t => $len) {
echo str_pad(isset($op[$t]) ? get_op($op[$t]) : "", $len);
}
printf("%5s", isset($op['extended_value']) ? $op['extended_value'] : "");
echo "\n";
}
}
function dump_function($name, $func, $indent = '')
{
if (isset($func['op_array'])) {
$op_array = $func['op_array'];
unset($func['op_array']);
}
else {
$op_array = null;
}
var_dump($func);
echo $indent, 'function ', $name, "\n";
if (isset($op_array)) {
dump_opcodes($op_array['opcodes'], " " . $indent);
}
}
function dump_class($name, $class, $indent = '')
{
if (isset($class['function_table'])) {
$funcs = $class['function_table'];
unset($class['function_table']);
}
else {
$funcs = null;
}
echo $indent, 'class ', $name, "\n";
if (isset($funcs)) {
foreach ($funcs as $name => $func) {
dump_function($name, $func, " " . $indent);
}
}
}
if (!isset($argv[1])) {
die("Usage: $argv[0] <file>\n");
}
$decompiler = new Decompiler();
if (isset($argv[2])) {
eval('$pk = ' . file_get_contents($argv[2]) . ';');
}
else {
$pk = xcache_dasm_file($argv[1]);
}
$op_array = $funcs = $classes = null;
if (isset($pk['op_array'])) {
$op_array = $pk['op_array'];
unset($pk['op_array']);
}
if (isset($pk['function_table'])) {
$funcs = $pk['function_table'];
unset($pk['function_table']);
}
if (isset($pk['class_table'])) {
$classes = $pk['class_table'];
unset($pk['class_table']);
}
var_dump($pk);
if (isset($classes)) {
foreach ($classes as $name => $class) {
dump_class($name, $class);
}
}
if (isset($funcs)) {
foreach ($funcs as $name => $func) {
dump_function($name, $func);
}
}
if (isset($op_array)) {
dump_opcodes($op_array['opcodes']);
}