mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update lib/system.js and related files
This commit is contained in:
parent
c4dfca7c62
commit
79bc3fe593
|
@ -1,7 +1,17 @@
|
|||
var SYS = require("lib/system");
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
function main(args) {
|
||||
console.log("Hello world");
|
||||
if (typeof WScript !== "undefined") {
|
||||
console.log("Runtime version:", WScript.Version);
|
||||
console.log("Process version:", SYS.getProcessVersion());
|
||||
}
|
||||
|
||||
try {
|
||||
var web = HTTP.create();
|
||||
console.log(web.userAgent);
|
||||
} catch (e) {
|
||||
console.error("Something wrong");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// HTTP API with PIPE-IPC
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// http.js
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
var SYS = require("lib/system");
|
||||
var FILE = require("lib/file");
|
||||
var SHELL = require("lib/shell");
|
||||
|
@ -11,6 +10,7 @@ var PipeIPC = require("lib/pipe-ipc");
|
|||
var OS_NAME = SYS.getOS();
|
||||
var OS_ARCH = SYS.getArch();
|
||||
var DEVICE_UUID = SYS.getUUID();
|
||||
var PROCESS_VERSION = SYS.getProcessVersion();
|
||||
|
||||
var HTTPObject = function(engine) {
|
||||
this.interface = null;
|
||||
|
@ -21,7 +21,7 @@ var HTTPObject = function(engine) {
|
|||
this.headers = {};
|
||||
this.parameters = {};
|
||||
this.dataType = null;
|
||||
this.userAgent = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + DEVICE_UUID + "; https://catswords.social/@catswords_oss; abuse@catswords.net)";
|
||||
this.userAgent = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + PROCESS_VERSION + "; " + DEVICE_UUID + "; abuse@catswords.net)";
|
||||
this.isAsynchronous = false;
|
||||
this.proxy = {
|
||||
"enabled": false,
|
||||
|
|
190
lib/system.js
190
lib/system.js
|
@ -1,11 +1,9 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// System API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// lib/system.js
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
var SHELL = require("lib/shell");
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var WMI = require("lib/wmi");
|
||||
|
||||
exports.createProcess = function(cmd) {
|
||||
function createProcess(cmd) {
|
||||
var SW_HIDE = 0;
|
||||
//wmi.Get("Win32_Process").Create(cmd, null, si, pid);
|
||||
return WMI.setClass("Win32_Process").setMethod("Create").setParameters({
|
||||
|
@ -20,9 +18,10 @@ exports.createProcess = function(cmd) {
|
|||
.setAttribute("ySize", 1)
|
||||
.getInstance()
|
||||
}).execute().get("ProcessID");
|
||||
};
|
||||
}
|
||||
|
||||
exports.getEnvString = function(envName) {
|
||||
function getEnvString(envName) {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
return (function(s) {
|
||||
switch(s) {
|
||||
case "PROGRAMFILES":
|
||||
|
@ -33,10 +32,10 @@ exports.getEnvString = function(envName) {
|
|||
return WSH.ExpandEnvironmentStrings('%' + s + '%');
|
||||
}
|
||||
})(envName.toUpperCase());
|
||||
};
|
||||
}
|
||||
|
||||
exports.get32BitFolder = function() {
|
||||
var base = exports.getEnvString("WINDIR");
|
||||
function get32BitFolder() {
|
||||
var base = getEnvString("WINDIR");
|
||||
var syswow64 = base + "\\SysWOW64\\";
|
||||
|
||||
if (CreateObject("Scripting.FileSystemObject").FolderExists(syswow64))
|
||||
|
@ -45,107 +44,103 @@ exports.get32BitFolder = function() {
|
|||
return base + "\\System32\\";
|
||||
}
|
||||
|
||||
exports.isElevated = function() {
|
||||
function isElevated() {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
try {
|
||||
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
||||
return true;
|
||||
} catch (e) {
|
||||
} catch (e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getOS = function() {
|
||||
function getOS() {
|
||||
return WMI.execQuery("SELECT Caption FROM Win32_OperatingSystem").fetch().get("Caption").trim();
|
||||
};
|
||||
}
|
||||
|
||||
exports.getDCName = function() {
|
||||
function getDCName() {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
try {
|
||||
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
|
||||
if (DC.length > 0)
|
||||
return DC;
|
||||
} catch (e) {}
|
||||
};
|
||||
}
|
||||
|
||||
exports.getArch = function() {
|
||||
function getArch() {
|
||||
return WMI.execQuery("SELECT OSArchitecture FROM Win32_OperatingSystem").fetch().get("OSArchitecture");
|
||||
};
|
||||
}
|
||||
|
||||
exports.getUUID = function() {
|
||||
function getUUID() {
|
||||
return WMI.execQuery("SELECT UUID FROM Win32_ComputerSystemProduct").fetch().get("UUID").toLowerCase();
|
||||
};
|
||||
}
|
||||
|
||||
exports.getCurrentWorkingDirectory = function() {
|
||||
function getCurrentWorkingDirectory() {
|
||||
try {
|
||||
cwd = SHELL.exec("cd", "cwd.txt").trim();
|
||||
return cwd;
|
||||
return SHELL.exec("cd").trim();
|
||||
} catch (e) {}
|
||||
};
|
||||
}
|
||||
|
||||
exports.getDirName = function(path) {
|
||||
var delimiter = "\\";
|
||||
var pos = path.lastIndexOf(delimiter);
|
||||
function getDirName(path) {
|
||||
var pos = Math.max.apply(null, [path.lastIndexOf("\\"), path.lastIndexOf("/")]);
|
||||
return (pos > -1 ? path.substring(0, pos) : "");
|
||||
};
|
||||
}
|
||||
|
||||
exports.getFileName = function(path) {
|
||||
var delimiter = "\\";
|
||||
var pos = path.lastIndexOf(delimiter);
|
||||
return (pos > -1 ? path.substring(pos + delimiter.length) : "");
|
||||
};
|
||||
function getFileName(path) {
|
||||
var pos = Math.max.apply(null, [path.lastIndexOf("\\"), path.lastIndexOf("/")]);
|
||||
return (pos > -1 ? path.substring(pos + 1) : "");
|
||||
}
|
||||
|
||||
exports.getCurrentScriptDirectory = function() {
|
||||
function getCurrentScriptDirectory() {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
return exports.getDirName(WScript.ScriptFullName);
|
||||
return getDirName(WScript.ScriptFullName);
|
||||
} else if (typeof(document) !== "undefined") {
|
||||
return exports.getDirName(document.location.pathname);
|
||||
return getDirName(document.location.pathname);
|
||||
} else {
|
||||
return ".";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.getCurrentScriptName = function() {
|
||||
function getCurrentScriptName() {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
return WScript.ScriptName;
|
||||
} else if (typeof(document) !== "undefined") {
|
||||
return exports.getFileName(document.location.pathname);
|
||||
return getFileName(document.location.pathname);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
exports.getNetworkInterfaces = function() {
|
||||
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
||||
};
|
||||
|
||||
exports.getProcessList = function() {
|
||||
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
||||
};
|
||||
|
||||
exports.getPIDList = function() {
|
||||
var result = [];
|
||||
var processes = exports.getProcessList();
|
||||
for (var i = 0; i < processes.length; i++) {
|
||||
result.push(processes[i].ProcessID);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.isAlivePID = function(pid) {
|
||||
function getNetworkInterfaces() {
|
||||
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
||||
}
|
||||
|
||||
function getProcessList() {
|
||||
return WMI.execQuery("SELECT * FROM Win32_Process").fetchAll();
|
||||
}
|
||||
|
||||
function getPIDList() {
|
||||
return processes.map(function(x) {
|
||||
return x.ProcessID;
|
||||
});
|
||||
}
|
||||
|
||||
function isAlivePID(pid) {
|
||||
if (!pid) {
|
||||
return false;
|
||||
} else {
|
||||
return (exports.getPIDList().indexOf(pid) > -1);
|
||||
return (getPIDList().indexOf(pid) > -1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.getProcessListByName = function(name) {
|
||||
return exports.getProcessList().filter(function(s) {
|
||||
return (s.Caption === name);
|
||||
function getProcessListByName(name) {
|
||||
return getProcessList().filter(function(x) {
|
||||
return (x.Caption === name);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.killProcess = function(pid) {
|
||||
var processes = exports.getProcessList();
|
||||
function killProcess(pid) {
|
||||
var processes = getProcessList();
|
||||
|
||||
for (var i = 0; i < processes.length; i++) {
|
||||
try {
|
||||
|
@ -154,15 +149,16 @@ exports.killProcess = function(pid) {
|
|||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Lib -> System -> killProcess() -> ", e.message);
|
||||
console.error("Failed to kill process: ", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
exports.createShortcut = function(shoutcutName, fileName) {
|
||||
var workingDirectory = exports.getCurrentWorkingDirectory();
|
||||
function createShortcut(shoutcutName, fileName) {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var workingDirectory = getCurrentWorkingDirectory();
|
||||
var desktopPath = WSH.SpecialFolders("Desktop");
|
||||
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
|
||||
link.IconLocation = fileName + ",1";
|
||||
|
@ -170,12 +166,56 @@ exports.createShortcut = function(shoutcutName, fileName) {
|
|||
link.WindowStyle = 1;
|
||||
link.WorkingDirectory = workingDirectory;
|
||||
link.Save();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ping = function(address) {
|
||||
return WMI.execQuery("Select ResponseTime From Win32_PingStatus where address='" + address + "'").fetch().get("ResponseTime");
|
||||
};
|
||||
function ping(address) {
|
||||
return WMI.execQuery("SELECT ResponseTime FROM Win32_PingStatus WHERE address='" + address + "'").fetch().get("ResponseTime");
|
||||
}
|
||||
|
||||
exports.VERSIONINFO = "System Module (system.js) version 0.1.2";
|
||||
function getProcessVersion() {
|
||||
var getIEVersion = function() {
|
||||
var rv = -1;
|
||||
if (navigator.appName == 'Microsoft Internet Explorer') {
|
||||
var ua = navigator.userAgent;
|
||||
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
|
||||
if (re.exec(ua) != null)
|
||||
rv = parseFloat( RegExp.$1 );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (typeof WScript !== "undefined") {
|
||||
return "Microsoft JScript" + (' ' + WScript.Version);
|
||||
} else if (typeof navigator !== "undefined") {
|
||||
return (function(rv) {
|
||||
return "MSIE" + (rv < 0 ? '' : (' ' + rv));
|
||||
})(getIEVersion());
|
||||
}
|
||||
}
|
||||
|
||||
exports.createProcess = createProcess;
|
||||
exports.getEnvString = getEnvString;
|
||||
exports.get32BitFolder = get32BitFolder;
|
||||
exports.isElevated = isElevated;
|
||||
exports.getOS = getOS;
|
||||
exports.getDCName = getDCName;
|
||||
exports.getArch = getArch;
|
||||
exports.getUUID = getUUID;
|
||||
exports.getCurrentWorkingDirectory = getCurrentWorkingDirectory;
|
||||
exports.getDirName = getDirName;
|
||||
exports.getFileName = getFileName;
|
||||
exports.getCurrentScriptDirectory = getCurrentScriptDirectory;
|
||||
exports.getCurrentScriptName = getCurrentScriptName;
|
||||
exports.getNetworkInterfaces = getNetworkInterfaces;
|
||||
exports.getProcessList = getProcessList;
|
||||
exports.getPIDList = getPIDList;
|
||||
exports.isAlivePID = isAlivePID;
|
||||
exports.getProcessListByName = getProcessListByName;
|
||||
exports.killProcess = killProcess;
|
||||
exports.createShortcut = createShortcut;
|
||||
exports.ping = ping;
|
||||
exports.getProcessVersion = getProcessVersion;
|
||||
|
||||
exports.VERSIONINFO = "System Module (system.js) version 0.1.5";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user