This commit is contained in:
Namhyeon Go 2020-12-07 12:48:37 +09:00
parent 3fb0613444
commit b32301f9ea
8 changed files with 170 additions and 81 deletions

17
bootstrap.js vendored
View File

@ -8,6 +8,7 @@ var PS = require("lib/powershell");
var REG = require("lib/registry"); var REG = require("lib/registry");
var SYS = require("lib/system"); var SYS = require("lib/system");
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var UPDATER = require("lib/updater");
var appName = "welsonjs"; var appName = "welsonjs";
@ -28,16 +29,24 @@ exports.main = function(args) {
REG.write(REG.HKCR, appName + "\\DefaultIcon", "", SYS.getCurrentScriptDirectory() + "\\app\\favicon.ico,0", REG.STRING); REG.write(REG.HKCR, appName + "\\DefaultIcon", "", SYS.getCurrentScriptDirectory() + "\\app\\favicon.ico,0", REG.STRING);
REG.write(REG.HKCR, appName + "\\shell\\open\\command", "", "cmd.exe /c cscript " + SYS.getCurrentScriptDirectory() + "\\app.js uriloader \"%1\"", REG.STRING); REG.write(REG.HKCR, appName + "\\shell\\open\\command", "", "cmd.exe /c cscript " + SYS.getCurrentScriptDirectory() + "\\app.js uriloader \"%1\"", REG.STRING);
// check updates
console.log("Checking updates...");
UPDATER.checkUpdates();
// open web application // open web application
console.log("Trying open GUI..."); console.log("Trying open GUI...");
// detect old process // detect old process
var processList = SYS.getProcessList(); var processList = SYS.getProcessList();
for (var i = 0; i < processList.length; i++) { for (var i = 0; i < processList.length; i++) {
var process = processList[i]; try {
if (process.Caption == "mshta.exe") { var process = processList[i];
SYS.killProcess(process.ProcessID); if (process.Caption == "mshta.exe") {
} console.warn("Will be kill process ID: " + process.ProcessID);
SYS.killProcess(process.ProcessID);
sleep(1000);
}
} catch (e) {}
} }
// open web application // open web application

View File

@ -24,7 +24,8 @@ var ChromeObject = function() {
this.profileName = (profileName == "Default" ? "Chrome" : profileName); this.profileName = (profileName == "Default" ? "Chrome" : profileName);
this.installedDir = installedDir; this.installedDir = installedDir;
//this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir); //this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", this.installedDir); //this.binPath = this.binPath.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", "Chrome");
return this; return this;
}; };
@ -114,14 +115,17 @@ var ChromeObject = function() {
if (!this.userDataDir) { if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName; this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
} }
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory); var shell = SHELL.create()
shell.runAs(this.binPath, [ .setWorkingDirectory(this.workingDirectory)
"--profile-directory=\"" + this.profileName + "\"", .setVisibleWindow(true)
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"", .runAs(this.binPath, [
"--user-data-dir=\"" + this.userDataDir + "\"", "--profile-directory=\"" + this.profileName + "\"",
"\"" + url + "\"" "--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
]); "--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
])
;
sleep(3000); sleep(3000);
shell.release(); shell.release();
} catch (e) { } catch (e) {

View File

@ -2,8 +2,6 @@
// HTTP API // HTTP API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//var WINSOCK = require("lib/winsock");
var HTTPObject = function() { var HTTPObject = function() {
this.interface = null; this.interface = null;
this.contentType = "application/x-www-form-urlencoded"; this.contentType = "application/x-www-form-urlencoded";
@ -15,7 +13,7 @@ var HTTPObject = function() {
this.dataType = null; this.dataType = null;
this.userAgent = "WelsonJS/0.1.4-dev (https://github.com/gnh1201/welsonjs)"; this.userAgent = "WelsonJS/0.1.4-dev (https://github.com/gnh1201/welsonjs)";
this.isAsync = false; this.isAsync = false;
this.create = function() { this.create = function() {
this.interface = CreateObject([ this.interface = CreateObject([
"Microsoft.XMLHTTP", "Microsoft.XMLHTTP",
@ -33,13 +31,7 @@ var HTTPObject = function() {
"Msxml2.ServerXMLHTTP.5.0", "Msxml2.ServerXMLHTTP.5.0",
"Msxml2.ServerXMLHTTP.4.0", "Msxml2.ServerXMLHTTP.4.0",
"Msxml2.ServerXMLHTTP.3.0" "Msxml2.ServerXMLHTTP.3.0"
], function(obj, progId) { ]);
switch (progId) {
case "WinHttp.WinHttpRequest.5.1":
obj.setTimeouts(30000, 30000, 30000, 0);
break;
}
});
return this; return this;
}; };
@ -252,7 +244,7 @@ var HTTPObject = function() {
for (var key in this.headers) { for (var key in this.headers) {
this.interface.setRequestHeader(key, this.headers[key]); this.interface.setRequestHeader(key, this.headers[key]);
} }
switch (this.method) { switch (this.method) {
case "GET": case "GET":
this.interface.send(); this.interface.send();
@ -262,6 +254,12 @@ var HTTPObject = function() {
this.interface.send(this.serialize(this.requestBody)); this.interface.send(this.serialize(this.requestBody));
} }
while (this.interface.readyState < 4) {
console.debug("Waiting a response...");
sleep(1000);
}
console.debug(this.interface.responseText);
if (this.isJSONResponse()) { if (this.isJSONResponse()) {
this.setResponseBody(JSON.parse(this.interface.responseText)); this.setResponseBody(JSON.parse(this.interface.responseText));
} else { } else {

View File

@ -38,7 +38,7 @@ var HTTPServer = {
_this.Listener.listen(); _this.Listener.listen();
console.info("Listening port: " + port); console.info("Listening port: " + port);
} catch (e) { } catch (e) {
console.error("port " + port " could not bind: " + e.message); console.error("port ", port, " could not bind: ", e.message);
} }
}, },

View File

@ -14,7 +14,8 @@ exports.getList = function() {
var commands = [ var commands = [
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.0/ldconsole.exe", "list2"], [SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.0/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe", "list2"], [SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/NOXGAMES/MOMO/ldconsole.exe", "list2"] [SYS.getEnvString("SYSTEMDRIVE") + "/NOXGAMES/MOMO/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/XuanZhi/LDPlayer/ldconsole.exe", "list2"]
]; ];
for (var i = 0; i < commands.length; i++) { for (var i = 0; i < commands.length; i++) {

71
lib/noxplayer.adb.js Normal file
View File

@ -0,0 +1,71 @@
////////////////////////////////////////////////////////////////////////
// LDPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/nox_adb.exe";
exports.getDevices = function() {
var data = [];
var cmd = [
exports.binPath,
"devices"
]
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.length == 2) {
data.push({
host: row[0],
type: row[1]
});
}
}
return data;
};
exports.getHostname = function(host) {
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(' '));
};
exports.getList = function() {
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);
data.push({
hostname: hostname,
PID: parseInt(pid)
});
}
return data;
};

View File

@ -1,71 +1,52 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// LDPlayer API // NoxPlayer API
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var SYS = require("lib/system"); var SYS = require("lib/system");
exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.1"; exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.2";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;
exports.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/nox_adb.exe";
exports.getDevices = function() {
var data = [];
var cmd = [
exports.binPath,
"devices"
]
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.length == 2) {
data.push({
host: row[0],
type: row[1]
});
}
}
return data;
};
exports.getHostname = function(host) {
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(' '));
};
exports.getList = function() { exports.getList = function() {
var data = []; var data = [];
var devices = exports.getDevices(); var commands = [
[SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/NoxConsole", "list"]
];
for(var i = 0; i < devices.length; i++) { for (var i = 0; i < commands.length; i++) {
var hostname = exports.getHostname(devices[i].host); var result = SHELL.exec(commands[i]);
var pid = exports.getPID(devices[i].host); var lines = result.split(/\r?\n/);
for(var k = 0; k < lines.length; k++) {
var row = lines[k].split(',');
data.push({ if(row.length == 7) {
hostname: hostname, data.push({
PID: parseInt(pid) index: row[0],
}); name: row[1],
title: row[2],
handle1: row[3],
handle2: row[4],
handle3: row[5],
PID: parseInt(row[6]),
handle4: -1
});
} else if(row.length == 8) {
data.push({
index: row[0],
name: row[1],
title: row[2],
handle1: row[3],
handle2: row[4],
handle3: row[5],
PID: parseInt(row[6]),
handle4: row[7]
});
}
}
} }
return data; return data;
}; };

25
lib/updater.js Normal file
View File

@ -0,0 +1,25 @@
var FILE = require("lib/file");
var HTTP = require("lib/http");
var CONFIG = require("lib/config");
exports.checkUpdates = function() {
var token = FILE.readFile("token.txt", "utf-8");
var apiUrl = CONFIG.getValue("ApiUrl");
var onSuccess = function(res) {
var data = res.data;
for (var i = 0; i < data.length; i++) {
console.log("UPDATE ID: ", data.file);
}
}
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.setParameters({
"status": "published",
"sort": "-created_on",
"limit": 1
})
.get(apiUrl + "/netsolid/items/updates", onSuccess)
;
};