|
23 | 23 | This script analyzes MZ-PE (MS-DOS) executable file. |
24 | 24 | """ |
25 | 25 |
|
26 | | -__version__ = "1.0.1" |
| 26 | +__version__ = "1.1.0" |
27 | 27 | __author__ = "Maurice Lambert" |
28 | 28 | __author_email__ = "mauricelambert434@gmail.com" |
29 | 29 | __maintainer__ = "Maurice Lambert" |
@@ -124,6 +124,62 @@ class Section: |
124 | 124 | argv.remove("-c") |
125 | 125 |
|
126 | 126 |
|
| 127 | +if name == 'nt': |
| 128 | + from ctypes.wintypes import DWORD |
| 129 | + from ctypes import windll, byref, WinDLL |
| 130 | + |
| 131 | + def active_virtual_terminal() -> bool: |
| 132 | + """ |
| 133 | + This function active terminal colors on Windows. |
| 134 | +
|
| 135 | + return True on success and False on fail. |
| 136 | +
|
| 137 | + This function come from: https://raw.githubusercontent.com/mauricelambert/PythonToolsKit/main/PythonToolsKit/WindowsTerminal.py |
| 138 | + doc: https://docs.microsoft.com/fr-fr/windows/console/console-virtual-terminal-sequences#code-try-1 |
| 139 | +
|
| 140 | + >>> print("\\x1b[32mabc\\x1b[0m") |
| 141 | + ←[32mabc←[0m |
| 142 | + >>> active_virtual_terminal() |
| 143 | + True |
| 144 | + >>> print("\\x1b[32mabc\\x1b[0m") |
| 145 | + abc |
| 146 | + >>> active_virtual_terminal() |
| 147 | + False |
| 148 | + >>> |
| 149 | + """ |
| 150 | + |
| 151 | + default_in_mode: DWORD = DWORD() |
| 152 | + default_out_mode: DWORD = DWORD() |
| 153 | + |
| 154 | + kernel32: WinDLL = windll.kernel32 |
| 155 | + _FuncPtr: type = kernel32._FuncPtr |
| 156 | + |
| 157 | + GetStdHandle: _FuncPtr = kernel32.GetStdHandle |
| 158 | + GetConsoleMode: _FuncPtr = kernel32.GetConsoleMode |
| 159 | + SetConsoleMode: _FuncPtr = kernel32.SetConsoleMode |
| 160 | + |
| 161 | + OUT_ENABLE_VIRTUAL_TERMINAL_PROCESSING: int = 0x0004 |
| 162 | + OUT_DISABLE_NEWLINE_AUTO_RETURN: int = 0x0008 |
| 163 | + |
| 164 | + STDOUT: int = GetStdHandle(-11) |
| 165 | + |
| 166 | + if not GetConsoleMode(STDOUT, byref(default_out_mode)): |
| 167 | + return False |
| 168 | + |
| 169 | + new_out_mode = ( |
| 170 | + OUT_ENABLE_VIRTUAL_TERMINAL_PROCESSING |
| 171 | + | OUT_DISABLE_NEWLINE_AUTO_RETURN |
| 172 | + ) |
| 173 | + |
| 174 | + new_out_mode = DWORD(default_out_mode.value | new_out_mode) |
| 175 | + |
| 176 | + if not SetConsoleMode(STDOUT, new_out_mode): |
| 177 | + return False |
| 178 | + |
| 179 | + return True |
| 180 | + |
| 181 | + active_virtual_terminal() |
| 182 | + |
127 | 183 | colors = [] |
128 | 184 |
|
129 | 185 |
|
@@ -431,6 +487,7 @@ class SYSTEMTIME(Structure): |
431 | 487 | print_( |
432 | 488 | "Cannot check the siganture on Linux or from URL or STDIN", file=stderr |
433 | 489 | ) |
| 490 | + status = None |
434 | 491 |
|
435 | 492 | if status in (0, 0x800B0111): |
436 | 493 | dword_encoding = DWORD() |
|
0 commit comments