Browse Source

getpunk windows SetConsoleMode

master
Julian Noble 4 days ago
parent
commit
cebc2f3d62
  1. 43
      getpunk.cmd
  2. 42
      src/scriptapps/getpunk.ps1

43
getpunk.cmd

@ -1029,7 +1029,48 @@ git branch --set-upstream-to=origin/master master
Set-Location $launchdir #restore original CWD
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class NativeMethods
{
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int lpMode);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode);
// Constants for standard handles
public const int STD_INPUT_HANDLE = -10;
public const int STD_OUTPUT_HANDLE = -11;
public const int STD_ERROR_HANDLE = -12;
// Console Input Modes
public const int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
// Console Output Modes
public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
}
"@
# Get the output handle
$hConsoleOutput = [NativeMethods]::GetStdHandle([NativeMethods]::STD_OUTPUT_HANDLE)
# Get the current output mode
$currentMode = 0
[NativeMethods]::GetConsoleMode($hConsoleOutput, [ref]$currentMode) | Out-Null
# Enable Virtual Terminal Processing
$newMode = $currentMode -bor [NativeMethods]::ENABLE_VIRTUAL_TERMINAL_PROCESSING
# Set the new console mode
[NativeMethods]::SetConsoleMode($hConsoleOutput, $newMode) | Out-Null
write-host "`e[92m getpunk done `e[m"
#</powershell-payload>
#<powershell-pre-launch-subprocess>

42
src/scriptapps/getpunk.ps1

@ -120,3 +120,45 @@ git branch --set-upstream-to=origin/master master
Set-Location $launchdir #restore original CWD
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class NativeMethods
{
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int lpMode);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode);
// Constants for standard handles
public const int STD_INPUT_HANDLE = -10;
public const int STD_OUTPUT_HANDLE = -11;
public const int STD_ERROR_HANDLE = -12;
// Console Input Modes
public const int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
// Console Output Modes
public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
}
"@
# Get the output handle
$hConsoleOutput = [NativeMethods]::GetStdHandle([NativeMethods]::STD_OUTPUT_HANDLE)
# Get the current output mode
$currentMode = 0
[NativeMethods]::GetConsoleMode($hConsoleOutput, [ref]$currentMode) | Out-Null
# Enable Virtual Terminal Processing
$newMode = $currentMode -bor [NativeMethods]::ENABLE_VIRTUAL_TERMINAL_PROCESSING
# Set the new console mode
[NativeMethods]::SetConsoleMode($hConsoleOutput, $newMode) | Out-Null
write-host "`e[92m getpunk done `e[m"
Loading…
Cancel
Save