-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (51 loc) · 1.97 KB
/
index.js
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
#!/usr/bin/env node
const tasklist = require("tasklist");
const taskkill = require("taskkill");
const minimatch = require("minimatch");
const path = require("path");
const chalk = require("chalk");
const figlet = require("figlet");
console.log(chalk.red(figlet.textSync("killswitch", { font: "graffiti" })));
const getTargets = () => {
const KILLSWITCH_PATH = path.resolve(process.env["USERPROFILE"], "Desktop", "killswitch.json");
try {
const targets = require(KILLSWITCH_PATH);
if (Array.isArray(targets)) {
return targets;
}
console.error(`No readable file of correct array format exists at: ${KILLSWITCH_PATH}\nCreate a file on desktop named killswitch.json containing a single array of process names. Supports wildcards.`);
process.exit(1);
} catch(err) {
console.error(`No readable file exists at: ${KILLSWITCH_PATH}\nCreate a file on desktop named killswitch.json containing a single array of process names. Supports wildcards.`);
process.exit(1);
}
}
const targets = getTargets();
const targetFilter = task => targets.some(target => {
try {
return minimatch(task.imageName, target);
} catch(err) {
console.error(`Error occurred filtering task "${task.imageName}" with target "${target}"`);
process.exit(1);
}
});
const work = async () => {
const tasks = await tasklist();
const hits = tasks.filter(targetFilter);
console.log("CONTRACTING HITS...");
console.log(hits.map(task => `\t${task.imageName}`).join("\n"));
console.log(chalk.red(figlet.textSync("engage", { font: "graffiti" })));
const pids = hits.map(task => task.pid);
try {
await taskkill(pids, { force: true, tree: true });
console.log(`${pids.length} tasks murdered.`)
} catch(err) {
if (err.message.includes("Access is denied")) {
console.error("I can't kill anything if you don't give me the privilege...");
process.exit(1);
} else {
throw err;
}
}
};
work();