/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_BootConsoleIo
#define TC_HEADER_Boot_BootConsoleIo
#include "Platform.h"
#define TC_DEBUG_PORT 0
#define TC_BIOS_KEY_ESC 1
#define TC_BIOS_KEY_BACKSPACE 14
#define TC_BIOS_KEY_ENTER 28
#define TC_BIOS_KEY_F1 0x3b
#define TC_BIOS_KEY_F2 0x3c
#define TC_BIOS_KEY_F3 0x3d
#define TC_BIOS_KEY_F4 0x3e
#define TC_BIOS_KEY_F5 0x3f
#define TC_BIOS_KEY_F6 0x40
#define TC_BIOS_KEY_F7 0x41
#define TC_BIOS_KEY_F8 0x42
#define TC_BIOS_KEY_F9 0x43
#define TC_BIOS_KEY_F10 0x44
#define TC_BIOS_SHIFTMASK_CAPSLOCK (1 << 6)
#define TC_BIOS_SHIFTMASK_LSHIFT (1 << 1)
#define TC_BIOS_SHIFTMASK_RSHIFT (1 << 0)
#define TC_BIOS_CHAR_BACKSPACE 8
#define TC_BIOS_MAX_CHARS_PER_LINE 80
void Beep ();.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long *//*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#if !defined(_UEFI)
#include <windows.h>
#include <stdio.h>
#else
#include "Tcdefs.h"
#pragma warning( disable : 4706 ) // assignment within conditional expression
#endif
#include "Xml.h"
static BOOL BeginsWith (char *string, char *subString)
{
while (*string++ == *subString++)
{
if (*subString == 0) return TRUE;
if (*string == 0) return FALSE;
}
return FALSE;
}
char *XmlNextNode (char *xmlNode)
{
char *t = xmlNode + 1;
while ((t = strchr (t, '<')) != NULL)
{
if (t[1] != '/')
return t;
t++;
}
return NULL;
}
char *XmlFindElement (char *xmlNode, char *nodeName)
{
char *t = xmlNode;
size_t nameLen = strlen (nodeName);
do
{
if (BeginsWith (t + 1, nodeName)
&& (t[nameLen + 1] == '>'
|| t[nameLen + 1] == ' ')) return t;
} while (t = XmlNextNode (t));
return NULL;
}
char *XmlFindElementByAttributeValue (char *xml, char *nodeName, const char *attrName, const char *attrValue)
{
char attr[2048];
while (xml = XmlFindElement (xml, nodeName))
{
XmlGetAttributeText (xml, attrName, attr, sizeof (attr));
if (strcmp (attr, attrValue) == 0)
return xml;
xml++;
}
return NULL;
}
char *XmlGetAttributeText (char *xmlNode, const char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize)
{
char *t = xmlNode;
char *e = xmlNode;
int l = 0;
xmlAttrValue[0] = 0;
if (t[0] != '<') return NULL;
e = strchr (e, '>');
if (e == NULL) return NULL;
while ((t = strstr (t, xmlAttrName)) && t < e)
{
char *o = t + strlen (xmlAttrName);
if (t[-1] == ' '
&&
(BeginsWith (o, "=\"")
|| BeginsWith (o, "= \"")
|| BeginsWith (o, " =\"")
|| BeginsWith (o, " = \""))
)
break;
t++;
}
if (t == NULL || t > e) return NULL;
t = ((char*)strchr (t, '"')) + 1;
e = strchr (t, '"');
l = (int)(e - t);
if (e == NULL || l > xmlAttrValueSize) return NULL;
memcpy (xmlAttrValue, t, l);
xmlAttrValue[l] = 0;
return xmlAttrValue;
}
char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize)
{
char *t = xmlNode;
char *e = xmlNode + 1;
int l = 0, i = 0, j = 0;
xmlText[0] = 0;
if (t[0] != '<')
return NULL;
t = (char*) strchr (t, '>');
if (t == NULL) return NULL;
t++;
e = strchr (e, '<');
if (e == NULL) return NULL;
l = (int)(e - t);
if (e == NULL || l > xmlTextSize) return NULL;
while (i < l)
{
if (BeginsWith (&t[i], "<"))
{
xmlText[j++] = '<';
i += 4;
continue;
}
if (BeginsWith (&t[i], ">"))
{
xmlText[j++] = '>';
i += 4;
continue;
}
if (BeginsWith (&t[i], "&"))
{
xmlText[j++] = '&';
i += 5;
continue;
}
xmlText[j++] = t[i++];
}
xmlText[j] = 0;
return t;
}
char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
{
char *textDstLast = textDst + textDstMaxSize - 1;
if (textDstMaxSize == 0)
return NULL;
while (*textSrc != 0 && textDst <= textDstLast)
{
char c = *textSrc++;
switch (c)
{
case '&':
if (textDst + 6 > textDstLast)
return NULL;
strcpy (textDst, "&");
textDst += 5;
continue;
case '>':
if (textDst + 5 > textDstLast)
return NULL;
strcpy (textDst, ">");
textDst += 4;
continue;
case '<':
if (textDst + 5 > textDstLast)
return NULL;
strcpy (textDst, "<");
textDst += 4;
continue;
default:
*textDst++ = c;
}
}
if (textDst > textDstLast)
return NULL;
*textDst = 0;
return textDst;
}
wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
{
wchar_t *textDstLast = textDst + textDstMaxSize - 1;
if (textDstMaxSize == 0)
return NULL;
while (*textSrc != 0 && textDst <= textDstLast)
{
wchar_t c = *textSrc++;
switch (c)
{
case L'&':
if (textDst + 6 > textDstLast)
return NULL;
wcscpy (textDst, L"&");
textDst += 5;
continue;
case L'>':
if (textDst + 5 > textDstLast)
return NULL;
wcscpy (textDst, L">");
textDst += 4;
continue;
case L'<':
if (textDst + 5 > textDstLast)
return NULL;
wcscpy (textDst, L"<");
textDst += 4;
continue;
default:
*textDst++ = c;
}
}
if (textDst > textDstLast)
return NULL;
*textDst = 0;
return textDst;
}
#if !defined(_UEFI)
#pragma warning( default : 4706 )
int XmlWriteHeader (FILE *file)
{
return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
}
int XmlWriteFooter (FILE *file)
{
return fputws (L"\n</VeraCrypt>", file);
}
#endif !defined(_UEFI)