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
130
131
132
133
134
|
/** BSD-2-Clause license
*
* Copyright (c) 2018-2023 NST <www.newinfosec.ru>, smake <smake at ya dot ru>.
*
*/
webrdp.o2s = function(obj, depth) {
depth = depth || [];
if (depth.contains(obj)) {
return '{SELF}';
}
switch (typeof(obj)) {
case 'undefined':
return 'undefined';
case 'string':
return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
case 'array':
var string = [];
depth.push(obj);
for (var i = 0; i < obj.length; ++i) {
string.push(webrdp.o2s(obj[i], depth));
}
depth.pop();
return '[' + string + ']';
case 'object':
case 'hash':
var string = [];
depth.push(obj);
var isE = (obj instanceof UIEvent);
Object.each(obj, function(v, k) {
if (v instanceof HTMLElement) {
string.push(k + '={HTMLElement}');
} else if (isE && (('layerX' == k) || ('layerY' == k) ('view' == k))) {
string.push(k + '=!0');
} else {
try {
var vstr = webrdp.o2s(v, depth);
if (vstr) {
string.push(k + '=' + vstr);
}
} catch (error) {
string.push(k + '=??E??');
}
}
});
depth.pop();
return '{' + string + '}';
case 'number':
case 'boolean':
return '' + obj;
case 'null':
return 'null';
}
return null;
};
webrdp.Log = new Class({
initialize: function() {
this.ws = null;
this.history = [];
this.loglevel = null;
},
_p: function(pfx, a) {
var line = '';
var i;
for (i = 0; i < a.length; ++i) {
switch (typeof(a[i])) {
case 'string':
case 'number':
case 'boolean':
case 'null':
line += a[i] + ' ';
break;
default:
line += webrdp.o2s(a[i]) + ' ';
break;
}
}
if (0 < line.length) {
this.ws.send(pfx + line);
}
},
drop: function() {
},
debug: function() {
if (this.loglevel == "debug") {
var entry = {
"date": new Date(),
"logtype": arguments.callee.name,
"direction": arguments[0],
"data": arguments[1]
}
this.history.push(entry);
}
},
info: function() {
if (this.ws) {
var a = Array.prototype.slice.call(arguments);
a.unshift('I:');
this._p.apply(this, a);
}
},
warn: function() {
if (this.ws) {
var a = Array.prototype.slice.call(arguments);
a.unshift('W:');
this._p.apply(this, a);
}
},
err: function() {
if (this.ws) {
var a = Array.prototype.slice.call(arguments);
a.unshift('E:');
this._p.apply(this, a);
}
},
show: function(count) {
if (!count) {
var count = 30;
}
var first = this.history.length - count > 0 ? this.history.length - count : 0;
for (var i = first; i < this.history.length; i++) {
var h = this.history[i];
var header = '[' + h.date.toLocaleTimeString('ru') + '.' + h.date.getMilliseconds() + ']';
var header = '[' + h.date.toLocaleTimeString('ru') + '.' + h.date.getMilliseconds() + ']';
header += '[' + h.logtype + '] ' + h.direction + ':';
console.log(header);
console.hex(h.data);
}
},
setWS: function(_ws) {
this.ws = _ws;
}
});
|