Skip to content

Commit ccff751

Browse files
Fixed bug in ADODBStream.ReadText().
1 parent d142fae commit ccff751

File tree

3 files changed

+86
-82
lines changed

3 files changed

+86
-82
lines changed

appended-code.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ for (varName in this) {
99
try {
1010
const script = new vm.Script(varValue);
1111
logJS(varValue)
12-
eval(varValue)
12+
// Automatically evaling all JS can result in the program state getting polluted.
13+
//eval(varValue)
1314
}
1415
catch (err) {}
1516
}
16-
}
17+
}

emulator/ADODBStream.js

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,82 @@ const iconv = require("iconv-lite");
44
/* Includes code (ADODBStream.writetext, .loadfromfile) from
55
* https://github.com/HynekPetrak/malware-jail. The license follows.
66
7-
The MIT License (MIT)
7+
The MIT License (MIT)
88
9-
Copyright (c) 2016 Hynek Petrak
9+
Copyright (c) 2016 Hynek Petrak
1010
11-
Permission is hereby granted, free of charge, to any person obtaining a copy
12-
of this software and associated documentation files (the "Software"), to deal
13-
in the Software without restriction, including without limitation the rights
14-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15-
copies of the Software, and to permit persons to whom the Software is
16-
furnished to do so, subject to the following conditions:
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
1717
18-
The above copyright notice and this permission notice shall be included in all
19-
copies or substantial portions of the Software.
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
2020
21-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27-
SOFTWARE.
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
2828
*/
2929

3030
function ADODBStream() {
31-
this.virtual_filename = "(undefined)";
32-
this.charset = "";
33-
this.position = 0;
34-
this.open = () => {};
35-
this.savetofile = function(filename) {
36-
this.virtual_filename = filename;
37-
lib.writeFile(filename, this.buffer);
38-
lib.logResource(lib.getUUID(), this.virtual_filename, this.buffer, true);
39-
};
40-
this.close = () => {};
41-
this.read = () => this.buffer;
42-
43-
this.write = this.writetext = function(text) {
44-
if (this.charset)
45-
this.buffer = iconv.encode(text, this.charset);
46-
else
47-
this.buffer = text;
48-
};
49-
this.loadfromfile = function(filename) {
50-
if (this.charset)
51-
this.buffer = iconv.decode(lib.readFile(filename), this.charset);
52-
else
53-
this.buffer = lib.readFile(filename);
54-
};
55-
this.copyto = (target) => target.write(this.buffer);
31+
this.virtual_filename = "(undefined)";
32+
this.charset = "";
33+
this.position = 0;
34+
this.open = () => {};
35+
this.savetofile = function(filename) {
36+
this.virtual_filename = filename;
37+
lib.writeFile(filename, this.buffer);
38+
lib.logResource(lib.getUUID(), this.virtual_filename, this.buffer, true);
39+
};
40+
this.close = () => {};
41+
this.read = this.readtext = function() {
42+
return this.buffer;
43+
};
44+
this.write = this.writetext = function(text) {
45+
if (this.charset)
46+
this.buffer = iconv.encode(text, this.charset);
47+
else
48+
this.buffer = text;
49+
};
50+
this.loadfromfile = function(filename) {
51+
if (this.charset)
52+
this.buffer = iconv.decode(lib.readFile(filename), this.charset);
53+
else
54+
this.buffer = lib.readFile(filename);
55+
};
56+
this.tojson = function(data) {
57+
console.log(data);
58+
return "[1]";
59+
}
60+
this.copyto = (target) => target.write(this.buffer);
5661
}
5762

5863
module.exports = function() {
59-
return new Proxy(new ADODBStream(), {
60-
get: function(target, name) {
61-
name = name.toLowerCase();
62-
switch (name) {
63-
case "size":
64-
case "length":
65-
return target.buffer.length;
66-
case "readtext":
67-
return target.buffer;
68-
default:
69-
if (name in target) return target[name];
70-
lib.kill(`ADODBStream.${name} not implemented!`);
71-
}
72-
},
73-
set: function(a, b, c) {
74-
b = b.toLowerCase();
75-
/* if (c.length < 1024)
76-
console.log(`ADODBStream[${b}] = ${c};`);
77-
*/
78-
a[b] = c;
79-
return true;
80-
},
81-
});
64+
return new Proxy(new ADODBStream(), {
65+
get: function(target, name) {
66+
name = name.toLowerCase();
67+
switch (name) {
68+
case "size":
69+
case "length":
70+
return target.buffer.length;
71+
default:
72+
if (name in target) return target[name];
73+
lib.kill(`ADODBStream.${name} not implemented!`);
74+
}
75+
},
76+
set: function(a, b, c) {
77+
b = b.toLowerCase();
78+
/* if (c.length < 1024)
79+
console.log(`ADODBStream[${b}] = ${c};`);
80+
*/
81+
a[b] = c;
82+
return true;
83+
},
84+
});
8285
};

emulator/DOM.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
const lib = require("../lib");
22

33
function VirtualDOMTag(name) {
4-
this.name = name;
4+
this.name = name;
55
}
66

77
// Catches requests to <tag>.nodeTypedValue in order to emulate them correctly
88
module.exports = function(name) {
9-
return new Proxy(new VirtualDOMTag(name), {
10-
get: function(target, name) {
11-
name = name.toLowerCase();
12-
switch (name) {
13-
case "nodetypedvalue":
14-
if (target.dataType !== "bin.base64") return target.text;
15-
return new Buffer(target.text, "base64").toString("utf8");
16-
default:
17-
if (name in target) return target[name];
18-
lib.kill(`VirtualDOMTag.${name} not implemented!`);
19-
}
20-
},
21-
});
22-
};
9+
return new Proxy(new VirtualDOMTag(name), {
10+
get: function(target, name) {
11+
name = name.toLowerCase();
12+
switch (name) {
13+
case "nodetypedvalue":
14+
if (target.dataType !== "bin.base64") return target.text;
15+
return new Buffer(target.text, "base64").toString("utf8");
16+
default:
17+
if (name in target) return target[name];
18+
lib.kill(`VirtualDOMTag.${name} not implemented!`);
19+
}
20+
},
21+
});
22+
};

0 commit comments

Comments
 (0)