welsonjs/shadow.js

137 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-10-19 08:11:56 +00:00
////////////////////////////////////////////////////////////////////////
2020-10-20 02:41:26 +00:00
// ShadowLoader
2020-10-19 08:11:56 +00:00
////////////////////////////////////////////////////////////////////////
var SS = require("lib/shadowsocks");
var SHELL = require("lib/shell");
2020-11-05 08:51:09 +00:00
var SYS = require("lib/system");
2020-11-09 19:43:19 +00:00
var XML = require("lib/xml");
2020-10-19 08:11:56 +00:00
var LDPlayer = require("lib/ldplayer");
var NoxPlayer = require("lib/noxplayer");
2020-11-09 19:43:19 +00:00
var Chrome = require("lib/chrome");
2020-10-19 08:11:56 +00:00
2020-11-09 19:43:19 +00:00
var Apps = {
LDPlayer: {},
NoxPlayer: {},
Chrome: {},
ProcessName: {}
};
var AppsMutex = [];
2020-11-09 19:45:54 +00:00
2020-11-09 19:43:19 +00:00
var items = XML.load("staticip.xml").select("/StaticIP/Item").toArray();
for (var i = 0; i < items.length; i++) {
try {
var name = items[i].select("Name").first().getText();
var uniqueId = items[i].select("UniqueID").first().getText();
var ipAddress = items[i].select("IPAddress").first().getText();
if (name in Apps) {
Apps[name][uniqueId] = ipAddress;
}
} catch(e) {
console.error(e.message);
}
}
2020-10-19 08:11:56 +00:00
2020-11-09 19:43:19 +00:00
// App 1. LDPlayer
var check_LDPlayer = function() {
var listenPort;
var items = LDPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = parseInt(items[i].PIDVBox);
var title = items[i].title;
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
console.info("New launched LDPlayer: " + title);
AppsMutex.push(pid);
if (title in Apps.LDPlayer) {
listenPort = SS.connect(Apps.LDPlayer[title]);
} else {
console.error("Not assigned static IP: " + title);
continue;
}
SHELL.run([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + listenPort,
"-p",
pid
]);
console.info("Waiting new launched");
sleep(3000);
}
}
};
2020-10-19 08:11:56 +00:00
2020-11-09 19:43:19 +00:00
// App 2. NoxPlayer
var check_NoxPlayer = function() {
var listenPort;
var items = NoxPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = parseInt(items[i].PID);
var hostname = items[i].hostname;
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
console.info("New launched NoxPlayer: " + title);
AppsMutex.push(pid);
if (title in Apps.NoxPlayer) {
listenPort = SS.connect(Apps.NoxPlayer[title]);
} else {
console.error("Not assigned static IP: " + hostname);
continue;
}
SHELL.run([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + listenPort,
"-p",
pid
]);
console.info("Waiting new launched");
sleep(3000);
}
}
2020-11-05 07:50:05 +00:00
};
2020-11-09 19:43:19 +00:00
// App 3. Chrome
var check_Chrome = function() {
var listenPort, pid;
for (var uniqueId in Apps.Chrome) {
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Starting Google Chrome: " + uniqueId);
listenPort = SS.connect(Apps.Chrome[uniqueId]);
Chrome.start("https://naver.com", listenPort, uniqueId);
AppsMutex.push("chrome_" + uniqueId);
}
}
};
var main = function() {
console.info("Waiting new launched");
2020-11-05 07:50:05 +00:00
2020-11-09 19:43:19 +00:00
while (true) {
sleep(3000);
check_LDPlayer();
sleep(3000);
check_NoxPlayer();
sleep(3000);
check_Chrome();
}
2020-10-19 08:11:56 +00:00
};
2020-11-09 19:43:19 +00:00
exports.main = main;