forked from tdyhacker/reverse-php-malware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.php
More file actions
125 lines (102 loc) · 2.61 KB
/
SymbolTable.php
File metadata and controls
125 lines (102 loc) · 2.61 KB
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
<?php
# $Id: SymbolTable.php,v 1.4 2016/03/22 02:02:23 bediger Exp $
class SymbolTable {
var $symbol_tables;
var $global_symbols;
public function __construct() {
$this->symbol_tables = array();
$this->global_symbols = array(); // Names are the indexes of $GLOBALS[], too.
}
public function pushScope() {
$this->symbol_tables[] = array();
}
public function popScope() {
array_pop($this->symbol_tables);
}
public function addSymbol($name, $value, $set = TRUE) {
$cnt = count($this->symbol_tables);
if ($cnt === 0) {
$this->addGlobalSymbol($name, $value, $set);
return;
}
$this->symbol_tables[$cnt-1][$name] = array('set'=>$set, 'value'=>$value);
}
public function addGlobalSymbol($name, $value, $set = TRUE) {
$this->global_symbols[$name] = array('set'=>$set, 'value'=>$value);
}
public function symbolValue($name, &$value) {
$found_value = FALSE;
$cnt = count($this->symbol_tables);
if ($cnt === 0) {
$found_value = $this->globalSymbolValue($name, $value);
} else {
$cnt -= 1;
if (isset($this->symbol_tables[$cnt][$name])) {
$sym = $this->symbol_tables[$cnt][$name];
if ($sym['set']) {
$value = $sym['value'];
$found_value = TRUE;
}
}
}
return $found_value;
}
public function updateValue($name, $value) {
$found_value = FALSE;
$cnt = count($this->symbol_tables);
$scope = 0;
while ($cnt > 0) {
$scope = $cnt - 1;
if (isset($this->symbol_tables[$scope][$name])) {
$sym = $this->symbol_tables[$scope][$name];
$sym['value'] = $value;
$sym['set'] = TRUE;
$found_value = TRUE;
break;
}
$cnt = $scope;
}
if (!$found_value) {
if (isset($this->global_symbols[$name])) {
$sym = $this->global_symbols[$name];
$sym['value'] = $value;
$sym['set'] = TRUE;
$this->global_symbols[$name] = $sym;
$found_value = TRUE;
}
}
return $found_value;
}
public function isSymbol($candidate_string) {
$found_symbol = FALSE;
$cnt = count($this->symbol_tables);
if ($cnt === 0) {
if (isset($this->global_symbols[$candidate_string]))
$found_symbol = TRUE;
} else {
if (isset($this->symbol_tables[$cnt-1][$candidate_string]))
$found_symbol = TRUE;
}
return $found_symbol;
}
public function globalSymbolValue($name, &$value) {
$found_value = FALSE;
if (is_object($name)) {
debug_print_backtrace();
}
#echo "+++++\nglobalSymbolValue: ".print_r($name, TRUE)."\n-------\n";
if (array_key_exists($name, $this->global_symbols)) {
$sym = $this->global_symbols[$name];
if ($sym['set']) {
$value = $sym['value'];
$found_value = TRUE;
}
}
return $found_value;
}
public function __destruct() {
$this->symbol_table = null;
$this->global_symbols = null;
}
}
?>