Skip to content

Instantly share code, notes, and snippets.

@no1xsyzy
Created Jul 22, 2021
Embed
What would you like to do?
import ctypes
import os
import msvcrt
from ctypes import wintypes
kernel32 = ctypes.windll.kernel32
def get_console_mode(output=False):
'''Get the mode of the active console input or output
buffer. Note that if the process isn't attached to a
console, this function raises an EBADF IOError.
'''
device = r'\\.\CONOUT$' if output else r'\\.\CONIN$'
with open(device, 'w' if output else 'r') as con:
mode = wintypes.DWORD()
hCon = msvcrt.get_osfhandle(con.fileno())
kernel32.GetConsoleMode(hCon, ctypes.byref(mode))
return mode.value
print(f'{get_console_mode():016b}::{get_console_mode(True):016b}::::\033[35mcolored\033[39mreset')
os.system('')
print(f'{get_console_mode():016b}::{get_console_mode(True):016b}::::\033[35mcolored\033[39mreset')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment