enhance feature of CreateObject

This commit is contained in:
Namhyeon Go 2020-10-20 11:41:26 +09:00
parent eda780811c
commit c38f6a8858
8 changed files with 164 additions and 96 deletions

View File

@ -6,27 +6,21 @@ exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
exports.global = global;
exports.require = require;
exports.createMSXMLObject = function() {
var progIDs = [
var createMSXMLObject = function() {
return CreateObject([
"Msxml2.DOMDocument.6.0",
"Msxml2.DOMDocument.5.0",
"Msxml2.DOMDocument.4.0",
"Msxml2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"MSXML.DOMDocument"
];
for (var i = 0; i < progIDs.length; i++) {
try {
return new ActiveXObject(progIDs[i]);
} catch(e) {};
}
return null;
]);
};
exports.getStream_StringToBinary = function(dText) {
var getStream_StringToBinary = function(dText) {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = new ActiveXObject("ADODB.Stream");
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
BinaryStream.Open();
@ -37,10 +31,10 @@ exports.getStream_StringToBinary = function(dText) {
return BinaryStream.Read();
};
exports.getStream_BinaryToString = function(dBinary) {
var getStream_BinaryToString = function(dBinary) {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = new ActiveXObject("ADODB.Stream");
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.Write(dBinary);
@ -51,17 +45,17 @@ exports.getStream_BinaryToString = function(dBinary) {
};
exports.encode = function(sText) {
var oXML = exports.createMSXMLObject();
var oXML = createMSXMLObject();
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
oNode.nodeTypedValue = exports.getStream_StringToBinary(sText);
oNode.nodeTypedValue = getStream_StringToBinary(sText);
return oNode.text;
};
exports.decode = function(vCode) {
var oXML = exports.createMSXMLObject();
var oXML = createMSXMLObject();
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
oNode.text = vCode;
return exports.getStream_BinaryToString(oNode.nodeTypedValue);
return getStream_BinaryToString(oNode.nodeTypedValue);
};

40
lib/httpserver.js Normal file
View File

@ -0,0 +1,40 @@
////////////////////////////////////////////////////////////////////////
// HTTPServer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var ResponseCodes = {
100: "Continue",
200: "OK",
206: "Partial Content",
301: "Moved Permanently",
302: "Found",
304: "Not Modified",
400: "Bad Request",
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
500: "Internal Server Error",
503: "Service Unavailable"
};
var listener, http = {};
var listen = function(port) {
try {
listener = CreateObject("MSWinsock.Winsock.1", "listener_");
listener.localPort = port;
listener.bind();
listener.listen();
console.info("Listening port: " + port);
} catch(e) {
console.error("port " + port " could not bind: " + e.message);
}
};
var arrival = function() {
// todo
};
// todo

View File

@ -10,29 +10,29 @@ exports.global = global;
exports.require = global.require;
exports.getList = function() {
var data = [];
var cmd = [
SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe",
"list2"
];
var result = SHELL.exec(cmd);
var lines = result.split(/\r?\n/);
for(var i = 0; i < lines.length; i++) {
var row = lines[i].split(',');
if(row.length == 7) {
data.push({
index: row[0],
title: row[1],
topWindowHandle: row[2],
binddWindowHandle: row[3],
androidStarted: row[4],
PID: row[5],
PIDVBox: row[6]
});
}
}
return data;
var data = [];
var cmd = [
SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe",
"list2"
];
var result = SHELL.exec(cmd);
var lines = result.split(/\r?\n/);
for(var i = 0; i < lines.length; i++) {
var row = lines[i].split(',');
if(row.length == 7) {
data.push({
index: row[0],
title: row[1],
topWindowHandle: row[2],
binddWindowHandle: row[3],
androidStarted: row[4],
PID: row[5],
PIDVBox: row[6]
});
}
}
return data;
};

View File

@ -21,7 +21,7 @@ exports.getDevices = function() {
var lines = result.split(/\r?\n/);
for(var i = 0; i < lines.length; i++) {
var row = lines[i].split(/\s+/);
if(row.length == 2) {
data.push({
host: row[0],
@ -34,38 +34,38 @@ exports.getDevices = function() {
};
exports.getHostname = function(host) {
return SHELL.exec([
exports.binPath,
"-s",
host,
"shell",
"getprop",
"net.hostname"
]).trim();
return SHELL.exec([
exports.binPath,
"-s",
host,
"shell",
"getprop",
"net.hostname"
]).trim();
};
exports.getPID = function(host) {
var row = host.split(':');
var addr = row[0];
var port = row[1];
var cmd = "netstat -ano | findstr :" + port + " | findstr :0";
var result = SHELL.exec(cmd);
return result.substring(result.lastIndexOf(' '));
var row = host.split(':');
var addr = row[0];
var port = row[1];
var cmd = "netstat -ano | findstr :" + port + " | findstr :0";
var result = SHELL.exec(cmd);
return result.substring(result.lastIndexOf(' '));
};
exports.getList = function() {
var data = [];
var data = [];
var devices = exports.getDevices();
for(var i = 0; i < devices.length; i++) {
var hostname = exports.getHostname(devices[i].host);
var pid = exports.getPID(devices[i].host);
var hostname = exports.getHostname(devices[i].host);
var pid = exports.getPID(devices[i].host);
data.push({
hostname: hostname,
PID: pid
});
}
data.push({
hostname: hostname,
PID: pid
});
}
return data;
};

View File

@ -8,21 +8,20 @@ var SYS = require("lib/system");
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = "bin/ss-local.exe";
exports.binPath = "bin\\ss-local.exe";
exports.getRandomInt = function(min, max) {
var x = Math.random();
return min + Math.floor((max - min) * x);
};
exports.connect = function() {
var listenPort = 1080;
//var listenPort = exports.getRandomInt(49152, 65535);
exports.connect = function(host) {
var listenPort = exports.getRandomInt(49152, 65535);
SHELL.run([
exports.binPath,
"-s",
__config.shadowsocks.host,
host,
"-p",
__config.shadowsocks.port,
"-l",
@ -35,3 +34,25 @@ exports.connect = function() {
return listenPort;
};
exports.getCountByProcessName = function(processName) {
var num = 0;
var cmd = "tasklist | findstr " + processName;
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+/);
if(row[0] == processName) {
num++;
}
}
return num;
};
exports.getCountOfSessions = function() {
return exports.getCountByProcessName("ss-local.exe");
};
exports.getCountOfBridges = function() {
return exports.getCountByProcessName("shadow.exe");
};

View File

@ -63,6 +63,7 @@ exports.run = function(cmd, fork) {
};
exports.elevatedRun = function(FN, args) {
console.info("elevatedRun() -> " + FN + " " + args.join(' '));
var oShell = CreateObject("Shell.Application");
oShell.shellExecute(FN, args, null, "runas", 0);
return oShell;

View File

@ -76,8 +76,20 @@ exports.require = global.require;
// Emulate Server.CreateObject
/////////////////////////////////////////////////////////////////////////////////
exports.CreateObject = function(n) {
return new ActiveXObject(n);
exports.CreateObject = function(objectName) {
var objectNames = [];
if(typeof(objectName) == "object") {
objectNames = objectName;
} else {
objectNames.push(objectName);
}
for (var i = 0; i < objectNames.length; i++) {
try {
return new ActiveXObject(objectNames[i]);
} catch(e) {};
}
};
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// SSloader
// ShadowLoader
////////////////////////////////////////////////////////////////////////
var SS = require("lib/shadowsocks");
@ -21,23 +21,24 @@ exports.main = function() {
console.info("Waiting new launched");
sleep(10000);
while(true) {
while (true) {
sleep(10000);
////////////////////////////////////////////////////////////////
// LDPlayer
////////////////////////////////////////////////////////////////
var LDPList = LDPlayer.getList();
for(var i = 0; i < LDPList.length; i++) {
for (var i = 0; i < LDPList.length; i++) {
var pid = parseInt(LDPList[i].PIDVBox);
var title = LDPList[i].title;
if(pid > 0 && PIDList.indexOf(pid) == -1) {
if (pid > 0 && PIDList.indexOf(pid) == -1) {
console.info("New launched LDPlayer: " + title);
PIDList.push(pid);
var listenPort;
if(!(title in __config.StaticIP.LDPlayer)) {
if (!(title in __config.StaticIP.LDPlayer)) {
console.error("Not assigned static IP: " + title);
continue;
} else {
@ -53,18 +54,18 @@ exports.main = function() {
"-p",
pid
]);
NumSessions = SS.getCountOfSessions();
NumBridges = SS.getCountOfBridges();
if(!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
console.error("Retrying...");
PIDList.pop();
}
_NumSessions = NumSessions;
_NumBridges = NumBridges;
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
console.error("Retrying...");
PIDList.pop();
}
_NumSessions = NumSessions;
_NumBridges = NumBridges;
console.info("Waiting new launched");
sleep(10000);
}
@ -75,16 +76,16 @@ exports.main = function() {
////////////////////////////////////////////////////////////////
var NoxPList = NoxPlayer.getList();
for(var i = 0; i < NoxPList.length; i++) {
for (var i = 0; i < NoxPList.length; i++) {
var pid = parseInt(NoxPList[i].PID);
var hostname = NoxPList[i].hostname;
if(pid > 0 && PIDList.indexOf(pid) == -1) {
if (pid > 0 && PIDList.indexOf(pid) == -1) {
console.info("New launched NoxPlayer: " + hostname);
PIDList.push(pid);
var listenPort;
if(!(hostname in __config.StaticIP.NoxPlayer)) {
if (!(hostname in __config.StaticIP.NoxPlayer)) {
console.error("Not assigned static IP: " + hostname);
continue;
} else {
@ -104,13 +105,13 @@ exports.main = function() {
NumSessions = SS.getCountOfSessions();
NumBridges = SS.getCountOfBridges();
if(!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
console.error("Retrying...");
PIDList.pop();
}
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
console.error("Retrying...");
PIDList.pop();
}
_NumSessions = NumSessions;
_NumBridges = NumBridges;
_NumSessions = NumSessions;
_NumBridges = NumBridges;
console.info("Waiting new launched");
sleep(10000);
@ -118,4 +119,3 @@ exports.main = function() {
}
}
};