-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbootgui.cpp
227 lines (174 loc) · 4.16 KB
/
bootgui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*++
This is the part of NGdbg kernel debugger
bootgui.cpp
Contains implementation of GUI used at system startup
--*/
#include <ntifs.h>
#include "gui.h"
#include "bootvid.h"
#include <stdarg.h>
#define KdfPrint(X) do \
{ \
KdPrint ((__FUNCTION__ " : ")); \
KdPrint (X); \
} \
while (0);
//
// Stubs that should not be called...
//
NTSTATUS
BootGuiLoadBitmap(
PWSTR BitmapFileName,
PLOADED_BITMAP Bitmap
)
{
// Should not be called during boot-time
ASSERT (FALSE);
return STATUS_NOT_IMPLEMENTED;
}
VOID
BootGuiUnloadBitmap(
PLOADED_BITMAP Bitmap
)
{
// Should not be called during boot-time
ASSERT (FALSE);
}
NTSTATUS
BootGuiLoadActiveFont(
)
{
// Should not be called during boot-time
ASSERT (FALSE);
return STATUS_NOT_IMPLEMENTED;
}
VOID
BootGuiUnloadFont(
)
{
// Should not be called during boot-time
ASSERT (FALSE);
}
ULONG
BootGuiGetCharFontPosition(
IN CHAR c
)
{
// Should not be called during boot-time
ASSERT (FALSE);
return -1;
}
VOID
BootGuiScrollLines(
IN ULONG nLines
)
{
// Should not be called during boot-time
ASSERT (FALSE);
}
//
// Really defined functions
//
UCHAR PositionY = 0;
VOID
BootGuiTextOut(
IN PCHAR Text
)
{
InbvDisplayString (Text);
}
extern CHAR TempPrintBuffer[1024];
extern "C" extern int _cdecl _vsnprintf (char*, int, const char*, va_list);
VOID
_cdecl
BootGuiPrintf(
IN PCHAR Format,
...
)
{
va_list va;
va_start (va, Format);
_vsnprintf (TempPrintBuffer, sizeof(TempPrintBuffer)-1, Format, va);
InbvDisplayString (TempPrintBuffer);
}
UCHAR
KbdGetKeyPolled(
IN BOOLEAN AllowMouseCallback
);
VOID
BootGuiInitialize(
)
{
KdfPrint (("Setting up GUI entry points\n"));
// Setup GUI entry points.
GuiLoadBitmap = &BootGuiLoadBitmap;
GuiUnloadBitmap = &BootGuiUnloadBitmap;
GuiLoadActiveFont = &BootGuiLoadActiveFont;
GuiUnloadFont = &BootGuiUnloadFont;
GuiGetCharFontPosition = &BootGuiGetCharFontPosition;
GuiScrollLines = &BootGuiScrollLines;
GuiTextOut = &BootGuiTextOut;
GuiPrintf = &BootGuiPrintf;
KdfPrint (("Resetting display\n"));
if (!InbvIsBootDriverInstalled())
{
KdfPrint (("Bootvid is not installed!\n"));
ASSERT (FALSE);
}
//
// Borrowed from ntos kernel =)
//
// Reset display
InbvAcquireDisplayOwnership ();
InbvResetDisplay ();
//
// InbvDisplayString incorrecly scrolls lines, so
// reserve 2 pixels from each side
//
ULONG x1 = 2, y1 = 2, x2 = 637, y2 = 477;
UCHAR SpareColor = 4; // blue
UCHAR BackColor = 3; // green
UCHAR TextColor = 15; // white
// Make the screen blue
InbvSolidColorFill(0,0,639,479,SpareColor); // blue, 640x480
InbvSolidColorFill(x1,y1,x2,y2,BackColor); // green, (x1,y1)x(x2,y2)
InbvSetTextColor (TextColor); // white
// Enable InbvDisplayString
InbvInstallDisplayStringFilter((INBV_DISPLAY_STRING_FILTER)NULL);
InbvEnableDisplayString(TRUE);
// Set scroll region for InbvDisplayString
InbvSetScrollRegion(x1,y1,x2,y2);
KdfPrint(("NGdbg boot-GUI loaded\n"));
//InbvDisplayString ("NGdbg boot-GUI loaded\n");
char *Str = "Press ESC to cancel loading NGdbg ... (%d seconds remaining) \r";
KIRQL Irql = KfRaiseIrql (HIGH_LEVEL);
UCHAR Byte;
ULARGE_INTEGER TickCountStart;
ULARGE_INTEGER TickCount;
ULARGE_INTEGER Difference;
ULONG TickIncrement = KeQueryTimeIncrement ();
ULONG Seconds = 10;
KeQueryTickCount (&TickCountStart);
do
{
KeQueryTickCount (&TickCount);
Difference.QuadPart = (TickCount.QuadPart - TickCountStart.QuadPart) / TickIncrement;
Difference.QuadPart /= 10000; // 100 ns -> 1 ms
ULONG SecondsElapsed = (ULONG)(Difference.QuadPart/1000);
ULONG SecondsRemaining = Seconds - SecondsElapsed;
GuiPrintf (Str, SecondsRemaining);
if (SecondsRemaining == 0)
break;
//
// Get key
//
Byte = KbdGetKeyPolled(FALSE);
if (Byte == 0)
continue;
if (Byte == 1)
break;
}
while (TRUE);
InbvDisplayString ("NGdbg kernel debugger : boot-gui loaded successfully \n");
KfLowerIrql (Irql);
}