MeshCentral/agents/modules_meshcore_min/win-terminal.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

2019-10-24 16:14:00 -04:00
var promise=require("promise");var duplex=require("stream").Duplex;var SW_HIDE=0;var SW_MINIMIZE=6;var STARTF_USESHOWWINDOW=1;var STD_INPUT_HANDLE=-10;var STD_OUTPUT_HANDLE=-11;var EVENT_CONSOLE_CARET=16385;var EVENT_CONSOLE_END_APPLICATION=16391;var WINEVENT_OUTOFCONTEXT=0;var WINEVENT_SKIPOWNPROCESS=2;var CREATE_NEW_PROCESS_GROUP=512;var EVENT_CONSOLE_UPDATE_REGION=16386;var EVENT_CONSOLE_UPDATE_SIMPLE=16387;var EVENT_CONSOLE_UPDATE_SCROLL=16388;var EVENT_CONSOLE_LAYOUT=16389;var EVENT_CONSOLE_START_APPLICATION=16390;var KEY_EVENT=1;var MAPVK_VK_TO_VSC=0;var WM_QUIT=18;var GM=require("_GenericMarshal");var si=GM.CreateVariable(GM.PointerSize==4?68:104);var pi=GM.CreateVariable(GM.PointerSize==4?16:24);si.Deref(0,4).toBuffer().writeUInt32LE(GM.PointerSize==4?68:104);si.Deref(GM.PointerSize==4?48:64,2).toBuffer().writeUInt16LE(SW_HIDE|SW_MINIMIZE);si.Deref(GM.PointerSize==4?44:60,4).toBuffer().writeUInt32LE(STARTF_USESHOWWINDOW);var MSG=GM.CreateVariable(GM.PointerSize==4?28:48);function windows_terminal(){this._ObjectID="windows_terminal";this._user32=GM.CreateNativeProxy("User32.dll");this._user32.CreateMethod("DispatchMessageA");this._user32.CreateMethod("GetMessageA");this._user32.CreateMethod("MapVirtualKeyA");this._user32.CreateMethod("PostThreadMessageA");this._user32.CreateMethod("SetWinEventHook");this._user32.CreateMethod("ShowWindow");this._user32.CreateMethod("TranslateMessage");this._user32.CreateMethod("UnhookWinEvent");this._user32.CreateMethod("VkKeyScanA");this._user32.terminal=this;this._kernel32=GM.CreateNativeProxy("Kernel32.dll");this._kernel32.CreateMethod("AllocConsole");this._kernel32.CreateMethod("CreateProcessA");this._kernel32.CreateMethod("CloseHandle");this._kernel32.CreateMethod("FillConsoleOutputAttribute");this._kernel32.CreateMethod("FillConsoleOutputCharacterA");this._kernel32.CreateMethod("GetConsoleScreenBufferInfo");this._kernel32.CreateMethod("GetConsoleWindow");this._kernel32.CreateMethod("GetLastError");this._kernel32.CreateMethod("GetStdHandle");this._kernel32.CreateMethod("GetThreadId");this._kernel32.CreateMethod("ReadConsoleOutputA");this._kernel32.CreateMethod("SetConsoleCursorPosition");this._kernel32.CreateMethod("SetConsoleScreenBufferSize");this._kernel32.CreateMethod("SetConsoleWindowInfo");this._kernel32.CreateMethod("TerminateProcess");this._kernel32.CreateMethod("WaitForSingleObject");this._kernel32.CreateMethod("WriteConsoleInputA");var b=0;var c=0;this._scrx=0;this._scry=0;this.SendCursorUpdate=function(){var g=GM.CreateVariable(22);if(this._kernel32.GetConsoleScreenBufferInfo(this._stdoutput,g).Val==0){return}if(g.Deref(4,2).toBuffer().readUInt16LE()!=this.currentX||g.Deref(6,2).toBuffer().readUInt16LE()!=this.currentY){this.currentX=g.Deref(4,2).toBuffer().readUInt16LE();this.currentY=g.Deref(6,2).toBuffer().readUInt16LE()}};this.ClearScreen=function(){var h=GM.CreateVariable(22);if(this._kernel32.GetConsoleScreenBufferInfo(this._stdoutput,h).Val==0){return}var i=GM.CreateVariable(4);var j=h.Deref(0,2).toBuffer().readUInt16LE(0)*h.Deref(2,2).toBuffer().readUInt16LE(0);var g=GM.CreateVariable(4);if(this._kernel32.FillConsoleOutputCharacterA(this._stdoutput,32,j,i.Deref(0,4).toBuffer().readUInt32LE(),g).Val==0){return}if(this._kernel32.GetConsoleScreenBufferInfo(this._stdoutput,h).Val==0){return}if(this._kernel32.FillConsoleOutputAttribute(this._stdoutput,h.Deref(8,2).toBuffer().readUInt16LE(0),j,i.Deref(0,4).toBuffer().readUInt32LE(),g).Val==0){return}this._kernel32.SetConsoleCursorPosition(this._stdoutput,i.Deref(0,4).toBuffer().readUInt32LE());var k=GM.CreateVariable(8);var l=h.Deref(10,8).toBuffer();k.Deref(4,2).toBuffer().writeUInt16LE(l.readUInt16LE(4)-l.readUInt16LE(0));k.Deref(6,2).toBuffer().writeUInt16LE(l.readUInt16LE(6)-l.readUInt16LE(2));this._kernel32.SetConsoleWindowInfo(this._stdoutput,1,k)};this.PowerShellCapable=function(){if(require("os").arch()=="x64"){return(require("fs").existsSync(process.env.windir+"\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe"))}else{return(require("fs").existsSync(process.env.windir+"\\System32\\WindowsPowerShell\\v1