Update powershell.js

This commit is contained in:
Namhyeon Go 2023-03-10 11:26:53 +09:00 committed by GitHub
parent 4867faab16
commit 8b1722cedb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,27 +4,33 @@
var SHELL = require("lib/shell");
/*
// new powershell interface
function PowershellInterface() {
this.type = -1;
this.execType = "ps1";
this.dataType = -1;
this.target = null;
this.setExecType = function(execType;) {
this.execType = execType;
};
this.load = function(script) {
this.target = script;
this.type = 0;
this.dataType = 0;
};
this.loadCommand = function(command) {
this.target = command;
this.dataType = 1;
};
this.loadFile = function(filename) {
this.target = filename;
this.type = 1;
this.dataType = 2;
};
this.loadRemoteUrl = function(url) {
this.loadUrl = function(url) {
this.target = url;
this.type = 2;
this.dataType = 3;
};
// For example:
@ -40,77 +46,99 @@ function PowershellInterface() {
switch (scheme) {
case 'http':
case 'https':
this.loadRemoteUrl(target);
this.loadUrl(target);
break;
case 'file':
this.loadFile(target);
break;
case 'data':
this.load(target);
break;
default:
console.error("Invalid scheme");
}
};
this.exec = function() {
switch (this.type) {
case 2:
// todo
this.exec = function(args) {
if (this.execType != "ps1") {
console.warn("The execType is not set 'ps1'. Will be forward this request to the default shell.");
SHELL.exec(this.target);
return;
}
// default arguments
var cmd = [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo"
];
switch (this.dataType) {
case 3: // dataType: URL(3)
break;
case 2: // dataType: file(2)
cmd.push("-file");
cmd.push(scriptName + ".ps1");
break;
case 1:
case 1: // dataType: command(1)
cmd.push("-Command");
if (typeof this.target === "string") {
cmd.push("& {" + cmd + "}");
} else {
cmd.push("& {" + SHELL.build(cmd) + "}");
}
break;
case 0: // dataType: script(0)
// todo
break;
case 0:
// todo
break;
default:
break;
}
if (typeof(cmd) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(cmd);
};
this.runAs = function() {
if (this.execType != "ps1") {
console.warn("The execType is not set 'ps1'. Will be forward this request to the default shell.");
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(this.target)) + "\" -Verb RunAs");
} else {
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(cmd)) + "\" -Verb RunAs");
}
};
}
*/
function execScript(scriptName, args) {
var cmd = [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-file",
scriptName + ".ps1"
];
if (typeof(cmd) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(cmd);
return (new PowershellInterface()).loadFile(scriptName).exec(args);
};
function execCommand(cmd) {
return SHELL.exec([
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-Command",
"& {" + cmd + "}"
]);
return (new PowershellInterface()).loadCommand(cmd).exec();
};
function runAs(cmd) {
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
return (new PowershellInterface()).setExecType("cmd").runAs();
};
exports.execScript = execScript;
exports.execCommand = execCommand;
exports.runAs = runAs;
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1.1";
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1.2";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;