From b32301f9eab6ccf107210ab3d3652bac14a3e760 Mon Sep 17 00:00:00 2001 From: gnh1201 Date: Mon, 7 Dec 2020 12:48:37 +0900 Subject: [PATCH] fix --- bootstrap.js | 17 +++++++-- lib/chrome.js | 22 ++++++----- lib/http.js | 20 +++++----- lib/httpserver.js | 2 +- lib/ldplayer.js | 3 +- lib/noxplayer.adb.js | 71 ++++++++++++++++++++++++++++++++++ lib/noxplayer.js | 91 ++++++++++++++++++-------------------------- lib/updater.js | 25 ++++++++++++ 8 files changed, 170 insertions(+), 81 deletions(-) create mode 100644 lib/noxplayer.adb.js create mode 100644 lib/updater.js diff --git a/bootstrap.js b/bootstrap.js index 3d7d4f6..beba747 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -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++) { - var process = processList[i]; - if (process.Caption == "mshta.exe") { - SYS.killProcess(process.ProcessID); - } + 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 diff --git a/lib/chrome.js b/lib/chrome.js index 5e4f646..b28a200 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -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; }; @@ -114,14 +115,17 @@ var ChromeObject = function() { if (!this.userDataDir) { this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName; } - - var shell = SHELL.create().setWorkingDirectory(this.workingDirectory); - shell.runAs(this.binPath, [ - "--profile-directory=\"" + this.profileName + "\"", - "--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"", - "--user-data-dir=\"" + this.userDataDir + "\"", - "\"" + url + "\"" - ]); + + 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) { diff --git a/lib/http.js b/lib/http.js index b1ce380..846f9eb 100644 --- a/lib/http.js +++ b/lib/http.js @@ -2,8 +2,6 @@ // HTTP API //////////////////////////////////////////////////////////////////////// -//var WINSOCK = require("lib/winsock"); - var HTTPObject = function() { this.interface = null; this.contentType = "application/x-www-form-urlencoded"; @@ -15,7 +13,7 @@ var HTTPObject = function() { this.dataType = null; this.userAgent = "WelsonJS/0.1.4-dev (https://github.com/gnh1201/welsonjs)"; this.isAsync = false; - + this.create = function() { this.interface = CreateObject([ "Microsoft.XMLHTTP", @@ -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; }; @@ -252,7 +244,7 @@ var HTTPObject = function() { for (var key in this.headers) { this.interface.setRequestHeader(key, this.headers[key]); } - + switch (this.method) { case "GET": this.interface.send(); @@ -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 { diff --git a/lib/httpserver.js b/lib/httpserver.js index 64314d5..34881a5 100644 --- a/lib/httpserver.js +++ b/lib/httpserver.js @@ -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); } }, diff --git a/lib/ldplayer.js b/lib/ldplayer.js index 9bb53ea..86476e8 100644 --- a/lib/ldplayer.js +++ b/lib/ldplayer.js @@ -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++) { diff --git a/lib/noxplayer.adb.js b/lib/noxplayer.adb.js new file mode 100644 index 0000000..6eb247b --- /dev/null +++ b/lib/noxplayer.adb.js @@ -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; +}; diff --git a/lib/noxplayer.js b/lib/noxplayer.js index 6eb247b..a1b43db 100644 --- a/lib/noxplayer.js +++ b/lib/noxplayer.js @@ -1,71 +1,52 @@ //////////////////////////////////////////////////////////////////////// -// 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(','); - data.push({ - hostname: hostname, - PID: parseInt(pid) - }); + if(row.length == 7) { + 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: -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; }; diff --git a/lib/updater.js b/lib/updater.js new file mode 100644 index 0000000..bd5316a --- /dev/null +++ b/lib/updater.js @@ -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) + ; +}; \ No newline at end of file