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

9
bootstrap.js vendored
View File

@ -8,6 +8,7 @@ var PS = require("lib/powershell");
var REG = require("lib/registry");
var SYS = require("lib/system");
var SHELL = require("lib/shell");
var UPDATER = require("lib/updater");
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 + "\\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
console.log("Trying open GUI...");
// detect old process
var processList = SYS.getProcessList();
for (var i = 0; i < processList.length; i++) {
try {
var process = processList[i];
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

View File

@ -24,7 +24,8 @@ var ChromeObject = function() {
this.profileName = (profileName == "Default" ? "Chrome" : profileName);
this.installedDir = 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;
};
@ -115,13 +116,16 @@ var ChromeObject = function() {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory);
shell.runAs(this.binPath, [
var shell = SHELL.create()
.setWorkingDirectory(this.workingDirectory)
.setVisibleWindow(true)
.runAs(this.binPath, [
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
]);
])
;
sleep(3000);
shell.release();
} catch (e) {

View File

@ -2,8 +2,6 @@
// HTTP API
////////////////////////////////////////////////////////////////////////
//var WINSOCK = require("lib/winsock");
var HTTPObject = function() {
this.interface = null;
this.contentType = "application/x-www-form-urlencoded";
@ -33,13 +31,7 @@ var HTTPObject = function() {
"Msxml2.ServerXMLHTTP.5.0",
"Msxml2.ServerXMLHTTP.4.0",
"Msxml2.ServerXMLHTTP.3.0"
], function(obj, progId) {
switch (progId) {
case "WinHttp.WinHttpRequest.5.1":
obj.setTimeouts(30000, 30000, 30000, 0);
break;
}
});
]);
return this;
};
@ -262,6 +254,12 @@ var HTTPObject = function() {
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()) {
this.setResponseBody(JSON.parse(this.interface.responseText));
} else {

View File

@ -38,7 +38,7 @@ var HTTPServer = {
_this.Listener.listen();
console.info("Listening port: " + port);
} 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 = [
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.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++) {

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,70 +1,51 @@
////////////////////////////////////////////////////////////////////////
// LDPlayer API
// NoxPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
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.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();
var commands = [
[SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/NoxConsole", "list"]
];
for(var i = 0; i < devices.length; i++) {
var hostname = exports.getHostname(devices[i].host);
var pid = exports.getPID(devices[i].host);
for (var i = 0; i < commands.length; i++) {
var result = SHELL.exec(commands[i]);
var lines = result.split(/\r?\n/);
for(var k = 0; k < lines.length; k++) {
var row = lines[k].split(',');
if(row.length == 7) {
data.push({
hostname: hostname,
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;

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)
;
};