This commit is contained in:
Namhyeon Go 2020-11-15 13:31:35 +09:00
parent 02c68cd034
commit 0014384539
7 changed files with 248 additions and 137 deletions

View File

@ -2,56 +2,59 @@
// Google Chrome API
/////////////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var SB = require("lib/sandboxie");
var binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
var Chrome = function() {
this.PID = 0;
var ChromeObject = function() {
this.binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
this.processID = 0;
this.profileName = "Default";
this.proxyPort = 1080;
this.processList = [];
this.setBinPath = function(path) {
this.binPath = path;
return this;
};
this.setProfileName = function(s) {
this.profileName = s;
return this;
};
this.setProxyPort = function(s) {
this.proxyPort = s;
return this;
};
this.getPID = function() {
return this.PID;
this.getProcessList = function() {
return this.processList;
};
this.open = function(url) {
var process = SHELL.createProcess([
binPath,
"--profile-directory=" + this.profileName,
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
url
]);
var process;
while (this.processID == 0) {
try {
process = SB.start(this.profileName, [
this.binPath,
"--profile-directory=" + this.profileName,
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
url
]);
this.processID = process.ProcessID;
} catch (e) {
console.error(e.message);
}
}
sleep(1000);
try {
this.PID = process.ProcessID;
if (this.PID > 0) {
return this;
} else {
console.info("Retrying call to open Chrome...");
return this.connect();
}
} catch(e) {
console.info("Retrying call to open Chrome...");
return this.connect();
}
return this;
};
};
exports.start = function(url, proxyPort, profileName) {
var instance = new Chrome();
instance.setProfileName(profileName);
instance.setProxyPort(proxyPort);
instance.open(url);
return instance.getPID();
exports.getProcessIDs = function() {
return (new ChromeObject()).getProcessIDs();
};
exports.start = function(url, proxyPort, profileName) {
return (new ChromeObject()).setProxyPort(proxyPort).setProfileName(profileName).open(url).processID;
};

37
lib/sandboxie.js Normal file
View File

@ -0,0 +1,37 @@
var SHELL = require("lib/shell");
var SandboxieObject = function() {
this.binPath = "%PROGRAMFILES%\\Sandboxie-Plus\\Start.exe";
this.processID = 0;
this.sandboxName = "";
this.setSandboxName = function(name) {
this.sandboxName = name;
return this;
};
this.start = function(cmd) {
var process;
while (this.processID == 0) {
try {
process = SHELL.createProcess([
this.binPath,
"/box:" + this.sandboxName,
SHELL.buildCommand(cmd)
].join(' '));
this.processID = process.ProcessID;
} catch (e) {
console.error(e.message);
}
}
return this;
};
};
exports.start = function(sandboxName, cmd) {
return (new SandboxieObject()).setSandboxName(sandboxName).start(cmd).processID;
};
exports.VERSIONINFO = "Sandboxie interface (sandboxie.js) version 0.1";
exports.global = global;
exports.require = global.require;

View File

@ -52,10 +52,10 @@ var ShadowsocksObject = function() {
};
};
exports.create = function() {
return (new ShadowsocksObject());
exports.connect = function(host) {
return (new ShadowsocksObject()).connect(host);
};
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.2";
exports.VERSIONINFO = "Shadowsocks interface (shadowsocks.js) version 0.2";
exports.global = global;
exports.require = global.require;

View File

@ -19,7 +19,7 @@ var addslashes = function(s) {
replace(/"/g, '\\"');
};
var makeCommand = function(cmd) {
exports.buildCommand = function(cmd) {
if (typeof(cmd) === "string") {
return cmd;
} else if (typeof(cmd) === "object") {
@ -41,7 +41,7 @@ exports.exec = function(cmd, stdOutPath) {
if (typeof(stdOutPath) === "undefined") {
stdOutPath = "stdout.txt";
}
var c = "%comspec% /c (" + makeCommand(cmd) + ") 1> " + stdOutPath;
var c = "%comspec% /c (" + exports.buildCommand(cmd) + ") 1> " + stdOutPath;
c += " 2>&1";
WSH.Run(c, 0, true);
console.info("exec() -> " + c);
@ -57,7 +57,7 @@ exports.exec = function(cmd, stdOutPath) {
exports.run = function(cmd, fork) {
var WSH = CreateObject("WScript.Shell");
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c (" + makeCommand(cmd) + ")";
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
console.info("run() -> " + c);
WSH.Run(c, 0, !fork);
};
@ -65,13 +65,13 @@ exports.run = function(cmd, fork) {
exports.runWindow = function(cmd, fork) {
var WSH = CreateObject("WScript.Shell");
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c (" + makeCommand(cmd) + ")";
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
console.info("run() -> " + c);
WSH.Run(c, 1, !fork);
}
exports.createProcess = function(cmd) {
var c = makeCommand(cmd);
var c = exports.buildCommand(cmd);
var WSH = CreateObject("WScript.Shell");
console.info("createProcess() -> " + c);
return WSH.Exec(c);

View File

@ -112,10 +112,16 @@ exports.getNetworkInterfaces = function() {
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
};
exports.getProcesses = function() {
exports.getProcessList = function() {
return WMI.execQuery("Select * From Win32_Process").fetchAll();
};
exports.getProcessListByName = function(name) {
return exports.getProcessList().filter(function(s) {
return (s.Caption === name);
});
};
exports.killProcess = function(pid) {
var processes = exports.getProcesses();

View File

@ -2,71 +2,6 @@
// WMI(Windows Management Instrumentation) API
////////////////////////////////////////////////////////////////////////
var WMIClassObject = function() {
this.interface = (new WMIQueryObject()).interface;
this.class = null;
this.className = "";
this.instance = null;
this.method = null;
this.methodName = "";
this.inParams = {};
this.outParams = {};
// Instance
this.setClass = function(className) {
this.className = className;
this.class = this.interface.Get(className);
return this;
};
this.create = function() {
this.instance = this.class.SpawnInstance_();
return this;
};
this.getAttribute = function(key) {
return this.instance[key];
};
this.setAttribute = function(key, value) {
this.instance[key] = value;
};
this.getInstance = function() {
return this.instance;
};
// Method
this.setMethod = function(methodName) {
this.methodName = methodName;
this.method = this.class.Methods_.Item(methodName);
return this;
};
this.setParameter = function(key, value) {
this.inParams[key] = value;
return this;
};
this.setParameters = function(params) {
if (typeof(params) !== "undefined") {
for (k in params) {
this.setParameter(k, params[k]);
}
}
return this;
};
this.execute = function() {
var params = this.method.InParameters.SpawnInstance_();
for (k in this.parameters) {
params[k] = this.inParams[k];
}
this.outParams = this.class.ExecMethod_(this.methodName, params);
return this;
};
this.get = function(key) {
if (key in this.outParams) {
return this.outParams[key];
} else {
return "";
}
};
};
var WMIQueryObject = function() {
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
@ -128,6 +63,71 @@ var WMIQueryObject = function() {
this.create();
};
var WMIClassObject = function() {
this.interface = (new WMIQueryObject()).interface;
this.classObject = null;
this.className = "";
this.instance = null;
this.methodObject = null;
this.methodName = "";
this.inParams = {};
this.outParams = {};
// Instance
this.setClass = function(className) {
this.className = className;
this.classObject = this.interface.Get(className);
return this;
};
this.create = function() {
this.instance = this.classObject.SpawnInstance_();
return this;
};
this.getAttribute = function(key) {
return this.instance[key];
};
this.setAttribute = function(key, value) {
this.instance[key] = value;
};
this.getInstance = function() {
return this.instance;
};
// Method
this.setMethod = function(methodName) {
this.methodName = methodName;
this.methodObject = this.classObject.Methods_.Item(methodName);
return this;
};
this.setParameter = function(key, value) {
this.inParams[key] = value;
return this;
};
this.setParameters = function(params) {
if (typeof(params) !== "undefined") {
for (k in params) {
this.setParameter(k, params[k]);
}
}
return this;
};
this.execute = function() {
var params = this.methodObject.InParameters.SpawnInstance_();
for (k in this.parameters) {
params[k] = this.inParams[k];
}
this.outParams = this.classObject.ExecMethod_(this.methodName, params);
return this;
};
this.get = function(key) {
if (key in this.outParams) {
return this.outParams[key];
} else {
return "";
}
};
};
exports.execQuery = function(query) {
return (new WMIQueryObject()).execQuery(query);
};

123
shadow.js
View File

@ -17,6 +17,19 @@ var Apps = {
ProcessName: {}
};
var AppsMutex = [];
var AppsPID = [];
var getAvailablePID = function() {
var items = [];
var cmd = "tasklist | findstr .exe";
var result = SHELL.exec(cmd);
var lines = result.split(/\r?\n/);
for(var i = 0; i < lines.length; i++) {
var row = lines[i].split(/\s+/);
items.push(row[1]);
}
return items;
};
var items = XML.load("staticip.xml").select("/StaticIP/Item").toArray();
for (var i = 0; i < items.length; i++) {
@ -35,32 +48,41 @@ for (var i = 0; i < items.length; i++) {
// App 1. LDPlayer
var check_LDPlayer = function() {
var listenPort;
var ssPort, ssPID, shadowPID = 0;
var items = LDPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = parseInt(items[i].PIDVBox);
var pid = 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]);
var ss = SS.create.connect(Apps.LDPlayer[title]);
ssPort = ss.listenPort;
ssPID = ss.processID;
} 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
]);
var process;
while (!(shadowPID > 0)) {
process = SHELL.createProcess([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + ssPort,
"-p",
pid
]);
sleep(1000);
shadowPID = process.ProcessID;
}
AppsPID.push([pid, ssPID, shadowPID]);
console.info("Waiting new launched");
sleep(3000);
@ -70,11 +92,11 @@ var check_LDPlayer = function() {
// App 2. NoxPlayer
var check_NoxPlayer = function() {
var listenPort;
var ssPort, ssPID, shadowPID = 0;
var items = NoxPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = parseInt(items[i].PID);
var pid = items[i].PID;
var hostname = items[i].hostname;
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
@ -82,22 +104,31 @@ var check_NoxPlayer = function() {
AppsMutex.push(pid);
if (hostname in Apps.NoxPlayer) {
listenPort = SS.connect(Apps.NoxPlayer[hostname]);
var ss = SS.create.connect(Apps.NoxPlayer[hostname]);
ssPort = ss.listenPort;
ssPID = ss.processID;
} 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
]);
var process;
while (!(shadowPID > 0)) {
process = SHELL.createProcess([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + ssPort,
"-p",
pid
]);
sleep(1000);
shadowPID = process.ProcessID;
}
AppsPID.push([pid, ssPID, shadowPID]);
console.info("Waiting new launched");
sleep(3000);
}
@ -106,18 +137,49 @@ var check_NoxPlayer = function() {
// App 3. Chrome
var check_Chrome = function() {
var listenPort, pid;
var ssPort, ssPID;
for (var uniqueId in Apps.Chrome) {
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Starting Google Chrome: " + uniqueId);
var ss = SS.connect(Apps.Chrome[uniqueId]);
ssPort = ss.listenPort;
ssPID = ss.processID;
var chromePID = Chrome.start("https://www.showmyip.com/", ssPort, uniqueId);
//AppsPID.push([ssPID, chromePID]);
AppsPID.push([ssPID]);
listenPort = SS.connect(Apps.Chrome[uniqueId]);
Chrome.start("https://www.showmyip.com/", listenPort, uniqueId);
AppsMutex.push("chrome_" + uniqueId);
}
}
};
// Check dead processes
var check_Exits = function() {
var availablePIDs = [];
var processes = SYS.getProcesses();
for (var i = 0; i < processes.length; i++) {
availablePIDs.push(processes[i].ProcessID);
}
AppsPID.forEach(function(v1) {
v1.forEach(function(v2) {
if (availablePIDs.indexOf(v2) < 0) {
//console.warn("Detected dead process: " + v2);
//console.warn("Will be kill related processes.");
//v1.forEach(function(v2) {
// SYS.killProcess(v2);
//});
return;
}
});
});
};
var main = function() {
console.info("Waiting new launched");
@ -130,6 +192,9 @@ var main = function() {
sleep(3000);
check_Chrome();
sleep(3000);
check_Exits();
}
};