Skip to content

Commit 7f8bb05

Browse files
committed
Fix linter errors
1 parent b24e3ac commit 7f8bb05

24 files changed

+537
-525
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
samples/
2+
*.results

.eslintrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
"parser": "babel-eslint",
33
"extends": "google",
4+
"env": {
5+
"node": true
6+
},
47
"rules": {
58
"camelcase": [1, {
69
properties: "never"
@@ -13,11 +16,14 @@ module.exports = {
1316
"new-cap": 1,
1417
"no-else-return": 1,
1518
"no-extend-native": 0,
19+
"no-invalid-this": 1,
20+
"no-global-assign": 1,
1621
"no-loop-func": 0,
1722
"no-return-assign": [1, "except-parens"],
1823
"no-unused-vars": 1,
1924
"no-var": 1,
2025
"prefer-const": 1,
26+
"quotes": ["error", "double"],
2127
"require-jsdoc": 0
2228
}
2329
};

_controller.js

+23-21
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const uuid = require("uuid");
33
const request = require("sync-request");
44
const path = require("path");
55

6-
const commandLineArgs = require('command-line-args');
7-
const flags = JSON.parse(fs.readFileSync(path.join(__dirname, 'flags.json'), 'utf8'))
8-
.map(flag => {
6+
const commandLineArgs = require("command-line-args");
7+
const flags = JSON.parse(fs.readFileSync(path.join(__dirname, "flags.json"), "utf8"))
8+
.map((flag) => {
99
if (flag.type === "String") flag.type = String;
1010
if (flag.type === "Number") flag.type = Number;
1111
if (flag.type === "Boolean") flag.type = Boolean;
@@ -16,15 +16,15 @@ const argv = commandLineArgs(flags);
1616

1717
const directory = process.argv[3];
1818

19-
var urls = [],
20-
activeUrls = [],
21-
snippets = {},
22-
resources = {},
23-
files = [];
19+
const urls = [];
20+
const activeUrls = [];
21+
const snippets = {};
22+
const resources = {};
23+
const files = [];
2424

25-
var latestUrl = "";
25+
let latestUrl = "";
2626

27-
var logSnippet = function(filename, logContent, content) {
27+
const logSnippet = function(filename, logContent, content) {
2828
snippets[filename] = logContent;
2929
fs.writeFileSync(directory + filename, content);
3030
fs.writeFileSync(directory + "snippets.json", JSON.stringify(snippets, null, "\t"));
@@ -36,7 +36,7 @@ module.exports = {
3636
kill: function(message) {
3737
if (process.argv.indexOf("--no-kill") == -1) {
3838
console.trace(message);
39-
console.log("Exiting (use --no-kill to just simulate a runtime error).")
39+
console.log("Exiting (use --no-kill to just simulate a runtime error).");
4040
process.exit(0);
4141
} else {
4242
throw new Error(message);
@@ -53,22 +53,24 @@ module.exports = {
5353

5454
console.log(`Emulating a ${method} request to ${url}`);
5555
headers["User-Agent"] = "Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 6.0)";
56-
let options = {
56+
const options = {
5757
headers,
5858
maxRedirects: 20,
59-
timeout: 5000
59+
timeout: 5000,
6060
};
6161
if (body)
6262
options.body = body;
6363
if (argv.proxy)
6464
options.proxy = argv.proxy;
6565

66-
var file = request(method, url, options);
67-
Buffer.prototype.charCodeAt = function(index) { return this[index]; }
66+
const file = request(method, url, options);
67+
Buffer.prototype.charCodeAt = function(index) {
68+
return this[index];
69+
};
6870
console.log(`Downloaded ${file.body.length} bytes.`);
6971
return file.body;
7072
} catch (e) {
71-
console.log(`An error occurred while emulating a ${method} request to ${url}.`)
73+
console.log(`An error occurred while emulating a ${method} request to ${url}.`);
7274
// console.log(e);
7375
// throw e;
7476
return `(Content of ${url})`;
@@ -82,12 +84,12 @@ module.exports = {
8284
},
8385
logUrl: function(method, url) {
8486
if (urls.indexOf(url) == -1) urls.push(url);
85-
fs.writeFileSync(directory + "urls.json", JSON.stringify(urls, null, "\t"))
87+
fs.writeFileSync(directory + "urls.json", JSON.stringify(urls, null, "\t"));
8688
},
8789
logResource: function(resourceName, logContent, content, print = false) {
8890
resources[resourceName] = logContent;
8991
fs.writeFileSync(directory + resourceName, content);
90-
fs.writeFileSync(directory + "resources.json", JSON.stringify(resources, null, "\t"))
92+
fs.writeFileSync(directory + "resources.json", JSON.stringify(resources, null, "\t"));
9193
if (!print) return;
9294
let filetype = require("child_process").execSync("file " + JSON.stringify(directory + resourceName)).toString("utf8");
9395
filetype = filetype.replace(`${directory + resourceName}: `, "").replace("\n", "");
@@ -105,7 +107,7 @@ module.exports = {
105107
logJS: function(code) {
106108
const filename = uuid.v4() + ".js";
107109
// console.log("Code saved to", filename)
108-
logSnippet(filename, {as: "eval'd JS"}, code)
110+
logSnippet(filename, {as: "eval'd JS"}, code);
109111
return code; // Helps with tail call optimization
110-
}
111-
}
112+
},
113+
};

_emulator/ADODBRecordSet.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
// http://stackoverflow.com/a/30410454
44
function nthOfGenerator(generator, n) {
55
let i = 0;
66

7-
if (n < 0) throw new Error('Invalid index');
7+
if (n < 0) throw new Error("Invalid index");
88

99
for (const value of generator)
1010
if (i++ === n) return value;
@@ -29,16 +29,16 @@ function ProxiedField(field, updateFn) {
2929
get: function(target, name) {
3030
name = name.toLowerCase();
3131
switch (name) {
32-
case 'appendchunk':
32+
case "appendchunk":
3333
return (chunk) => {
3434
target.value = Buffer.concat([
3535
target.value,
3636
Buffer.from(chunk),
3737
]);
3838
updateFn(target.value);
3939
};
40-
case 'getchunk':
41-
return (length) => target.value.toString('utf8', 0, length);
40+
case "getchunk":
41+
return (length) => target.value.toString("utf8", 0, length);
4242
default:
4343
if (name in target.value) return target.value[name];
4444
if (name in target) return target[name];
@@ -55,7 +55,7 @@ function ADODBRecordSet() {
5555
// Contains the data contained in the fields. That's for internal use.
5656
this._fields = new Map();
5757
// Also for internal use. Used with movefirst, etc.
58-
this._currentRecordName = '';
58+
this._currentRecordName = "";
5959
this._index = 0;
6060
this._goToRecord = () => (this._currentRecordName = nthOfGenerator(this._fields.keys(), this._index));
6161

@@ -85,14 +85,14 @@ function ADODBRecordSet() {
8585
get: (target, name) => {
8686
name = name.toLowerCase();
8787
switch (name) {
88-
case 'append':
89-
return (name, type, definedSize, attrib, fieldValue = '') => {
88+
case "append":
89+
return (name, type, definedSize, attrib, fieldValue = "") => {
9090
if (Number(type) !== 204) {
9191
console.log(`Warning: unknown datatype ${type} in ADODBRecordSet`);
9292
}
9393
this._fields.set(name, Buffer.from(fieldValue));
9494
};
95-
case 'fields':
95+
case "fields":
9696
return (key) => new Proxy(target[key], {
9797
get: function(target, name) {
9898
switch (name) {

_emulator/ADODBStream.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const controller = require('../_controller');
2-
const iconv = require('iconv-lite');
1+
const controller = require("../_controller");
2+
const iconv = require("iconv-lite");
33

44
/* Includes code (ADODBStream.writetext, .loadfromfile) from
55
* https://github.com/HynekPetrak/malware-jail. The license follows.
@@ -28,8 +28,8 @@ SOFTWARE.
2828
*/
2929

3030
function ADODBStream() {
31-
this.virtual_filename = '(undefined)';
32-
this.charset = '';
31+
this.virtual_filename = "(undefined)";
32+
this.charset = "";
3333
this.position = 0;
3434
this.open = () => {};
3535
this.savetofile = function(filename) {
@@ -59,10 +59,10 @@ module.exports = function() {
5959
get: function(target, name) {
6060
name = name.toLowerCase();
6161
switch (name) {
62-
case 'size':
63-
case 'length':
62+
case "size":
63+
case "length":
6464
return target.buffer.length;
65-
case 'readtext':
65+
case "readtext":
6666
return target.buffer;
6767
default:
6868
if (!(name in target)) {

_emulator/DOM.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
function VirtualDOMTag(name) {
44
this.name = name;
@@ -10,10 +10,10 @@ module.exports = function(name) {
1010
return new Proxy(new VirtualDOMTag(name), {
1111
get: function(target, name) {
1212
switch (name) {
13-
case 'nodeTypedValue':
14-
if (target.dataType !== 'bin.base64')
13+
case "nodeTypedValue":
14+
if (target.dataType !== "bin.base64")
1515
return target.text;
16-
return new Buffer(target.text, 'base64').toString('utf8');
16+
return new Buffer(target.text, "base64").toString("utf8");
1717
default:
1818
if (!(name in target)) {
1919
controller.kill(`VirtualDOMTag.${name} not implemented!`);

_emulator/Dictionary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
function Dictionary() {
44
this.dictionary = {};

_emulator/Enumerator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
function Enumerator(array) {
44
this.item = function(index) {

_emulator/FileSystemObject.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
function TextStream(filename) {
4-
this.buffer = controller.readFile(filename) || '';
4+
this.buffer = controller.readFile(filename) || "";
55
this.uuid = controller.getUUID();
66
this.filename = filename;
77
this.write = (line) => {
@@ -10,7 +10,7 @@ function TextStream(filename) {
1010
controller.logResource(this.uuid, this.filename, this.buffer);
1111
};
1212
this.writeline = (line) => {
13-
this.buffer = this.buffer + line + '\n';
13+
this.buffer = this.buffer + line + "\n";
1414
controller.writeFile(filename, this.buffer);
1515
controller.logResource(this.uuid, this.filename, this.buffer);
1616
};
@@ -21,7 +21,7 @@ function TextStream(filename) {
2121
this.bufferarray = [];
2222
this.readline = function() {
2323
if (this.bufferarray.length === 0)
24-
this.bufferarray = this.buffer.split('\n');
24+
this.bufferarray = this.buffer.split("\n");
2525
return this.bufferarray.shift();
2626
};
2727
this.shortpath = (path) => path;
@@ -52,10 +52,10 @@ function Folder(path, autospawned) {
5252
this.attributes = 16;
5353
this.datelastmodified = new Date(new Date() - 15 * 60 * 1000); // Last changed: 15 minutes ago
5454
this.files = [];
55-
this.name = (path.replace(/\w:/i, '').match(/\\(\w*)(?:\\)?$/i) || [null, ''])[1],
55+
this.name = (path.replace(/\w:/i, "").match(/\\(\w*)(?:\\)?$/i) || [null, ""])[1],
5656
this.path = path;
57-
this.subfolders = autospawned ? [] : [new ProxiedFolder(path + '\\RandomFolder', true)];
58-
this.type = 'folder';
57+
this.subfolders = autospawned ? [] : [new ProxiedFolder(path + "\\RandomFolder", true)];
58+
this.type = "folder";
5959
}
6060

6161
function ProxiedFolder(path, name, autospawned = false) {
@@ -75,7 +75,7 @@ function ProxiedFolder(path, name, autospawned = false) {
7575

7676
function File(contents) {
7777
this.openastextstream = () => new ProxiedTextStream(contents);
78-
this.shortpath = 'C:\\PROGRA~1\\example-file.exe';
78+
this.shortpath = "C:\\PROGRA~1\\example-file.exe";
7979
this.size = Infinity;
8080
this.attributes = 32;
8181
}
@@ -120,47 +120,47 @@ function ProxiedDrive(name) {
120120

121121
function FileSystemObject() {
122122
this.createtextfile = this.opentextfile = (filename) => new ProxiedTextStream(filename);
123-
this.buildpath = (...args) => args.join('\\');
123+
this.buildpath = (...args) => args.join("\\");
124124
this.fileexists = this.deletefile = () => {
125-
const value = process.argv.indexOf('--no-file-exists') === -1;
125+
const value = process.argv.indexOf("--no-file-exists") === -1;
126126
if (value) {
127-
console.log('Returning `true` for FileSystemObject.FileExists; use --no-file-exists if nothing happens');
127+
console.log("Returning `true` for FileSystemObject.FileExists; use --no-file-exists if nothing happens");
128128
}
129129
return value;
130130
};
131131
this.getfile = (filename) => new ProxiedFile(filename);
132132
this.getspecialfolder = function(id) {
133133
switch (id) {
134134
case 0:
135-
case '0':
136-
return 'C:\\WINDOWS\\';
135+
case "0":
136+
return "C:\\WINDOWS\\";
137137
case 1:
138-
case '1':
139-
return '(System folder)';
138+
case "1":
139+
return "(System folder)";
140140
case 2:
141-
case '2':
142-
return '(Temporary folder)';
141+
case "2":
142+
return "(Temporary folder)";
143143
default:
144-
return '(Special folder ' + id + ')';
144+
return "(Special folder " + id + ")";
145145
}
146146
};
147-
this.gettempname = () => '(Temporary file)';
148-
this.createfolder = (folder) => '(Temporary new folder)';
147+
this.gettempname = () => "(Temporary file)";
148+
this.createfolder = (folder) => "(Temporary new folder)";
149149
this.folderexists = (folder) => {
150150
const defaultValue = true;
151151
console.log(`Checking if ${folder} exists, returning ${defaultValue}`);
152152
return defaultValue;
153153
};
154154
this.getfolder = (str) => new ProxiedFolder(str);
155-
this.getfileversion = () => '';
156-
this.drives = [new ProxiedDrive('C:')];
155+
this.getfileversion = () => "";
156+
this.drives = [new ProxiedDrive("C:")];
157157
this.getdrive = (drive) => new ProxiedDrive(drive);
158-
this.getdrivename = path => {
158+
this.getdrivename = (path) => {
159159
const matches = path.match(/^\w:/);
160160
if (matches == null)
161161
return "";
162162
return matches[0];
163-
}
163+
};
164164
}
165165

166166
module.exports = function() {

_emulator/ShellApplication.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
const controller = require('../_controller');
1+
const controller = require("../_controller");
22

33
function VirtualShellApplication(name) {
44
this.shellexecute = function(...args) {
5-
console.log('Executing: ' + args.join(' '));
5+
console.log("Executing: " + args.join(" "));
66
};
77
this.namespace = (folder) => {
88
let path;
99
switch (folder) {
1010
case 7:
11-
path = 'C:\\Users\\MyUsername\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp';
11+
path = "C:\\Users\\MyUsername\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp";
1212
break;
1313
default:
14-
throw new Error('Unknown ShellApplication.Namespace ' + folder);
14+
throw new Error("Unknown ShellApplication.Namespace " + folder);
1515
}
1616
return {
1717
Self: {

0 commit comments

Comments
 (0)