--- truecrypt/boot/windows/bootconsoleio.cpp 2018/04/24 16:50:06 1.1.1.2 +++ truecrypt/boot/windows/bootconsoleio.cpp 2018/04/24 17:09:44 1.1.1.10 @@ -1,15 +1,16 @@ /* - Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. + Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved. - Governed by the TrueCrypt License 2.4 the full text of which is contained - in the file License.txt included in TrueCrypt binary and source code - distribution packages. + Governed by the TrueCrypt License 3.0 the full text of which is contained in + the file License.txt included in TrueCrypt binary and source code distribution + packages. */ #include "Platform.h" #include "Bios.h" #include "BootConsoleIo.h" #include "BootDebug.h" +#include "BootStrings.h" static int ScreenOutputDisabled = 0; @@ -28,7 +29,7 @@ void EnableScreenOutput () void PrintChar (char c) { -#ifdef TC_TRACING_ENABLED +#ifdef TC_BOOT_TRACING_ENABLED WriteDebugPort (c); #endif @@ -37,7 +38,7 @@ void PrintChar (char c) __asm { - xor bx, bx + mov bx, 7 mov al, c mov ah, 0xe int 0x10 @@ -45,11 +46,14 @@ void PrintChar (char c) } -void PrintCharAtCusor (char c) +void PrintCharAtCursor (char c) { + if (ScreenOutputDisabled) + return; + __asm { - xor bx, bx + mov bx, 7 mov al, c mov cx, 1 mov ah, 0xa @@ -72,10 +76,10 @@ void Print (uint32 number) int pos = 0; while (number >= 10) { - str[pos++] = (number % 10) + '0'; + str[pos++] = (char) (number % 10) + '0'; number /= 10; } - str[pos] = (number % 10) + '0'; + str[pos] = (char) (number % 10) + '0'; while (pos >= 0) PrintChar (str[pos--]); @@ -144,16 +148,39 @@ void Beep () } +void InitVideoMode () +{ + if (ScreenOutputDisabled) + return; + + __asm + { + // Text mode 80x25 + mov ax, 3 + int 0x10 + + // Page 0 + mov ax, 0x500 + int 0x10 + } +} + + void ClearScreen () { + if (ScreenOutputDisabled) + return; + __asm { + // White text on black mov bh, 7 xor cx, cx mov dx, 0x184f mov ax, 0x600 int 0x10 + // Cursor at 0,0 xor bh, bh xor dx, dx mov ah, 2 @@ -165,20 +192,24 @@ void ClearScreen () void PrintBackspace () { PrintChar (TC_BIOS_CHAR_BACKSPACE); - PrintCharAtCusor (' '); + PrintCharAtCursor (' '); } -void PrintError (const char *message, bool beep, bool newLine) +void PrintError (const char *message) { - Print ("Error: "); + Print (TC_BOOT_STR_ERROR); Print (message); - - if (newLine) - PrintEndl(); + PrintEndl(); + Beep(); +} - if (beep) - Beep(); + +void PrintErrorNoEndl (const char *message) +{ + Print (TC_BOOT_STR_ERROR); + Print (message); + Beep(); } @@ -196,8 +227,17 @@ byte GetShiftFlags () } +byte GetKeyboardChar () +{ + return GetKeyboardChar (nullptr); +} + + byte GetKeyboardChar (byte *scanCode) { + // Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer) + while (!IsKeyboardCharAvailable()); + byte asciiCode; byte scan; __asm @@ -231,6 +271,19 @@ bool IsKeyboardCharAvailable () } +bool EscKeyPressed () +{ + if (IsKeyboardCharAvailable ()) + { + byte keyScanCode; + GetKeyboardChar (&keyScanCode); + return keyScanCode == TC_BIOS_KEY_ESC; + } + + return false; +} + + void ClearBiosKeystrokeBuffer () { __asm