RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Menu.c File Reference

Graphical/text menu interface for the user. More...

#include "EfiScannerHeaders.h"
#include "efiGraphicsOutput.h"
#include "efiUgaDraw.h"
Include dependency graph for Menu.c:

Go to the source code of this file.

Macros

#define OPTION_FORCE_EXIT   0
 
#define OPTION_CONTINUE   1
 
#define OPTION_STAY_RESIDENT   2
 
#define BOX_SZEROKOSC   50
 

Functions

CHAR8 UserWantsThisOption (VOID)
 
VOID DrawBox (VOID)
 
UINTN DrawBoxAndMenu (BOOLEAN ShouldDrawBox)
 
BOOLEAN MainLoop (VOID)
 

Variables

EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
 

Detailed Description

Graphical/text menu interface for the user.

Author
Piotr Bania
Date
Feb 2013 Graphical/text menu interface for the user

Definition in file Menu.c.

Macro Definition Documentation

#define BOX_SZEROKOSC   50

Referenced by DrawBox().

#define OPTION_CONTINUE   1

Definition at line 22 of file Menu.c.

Referenced by DrawBoxAndMenu().

#define OPTION_FORCE_EXIT   0

Definition at line 21 of file Menu.c.

Referenced by DrawBoxAndMenu(), and MainLoop().

#define OPTION_STAY_RESIDENT   2

Definition at line 23 of file Menu.c.

Referenced by DrawBoxAndMenu(), and MainLoop().

Function Documentation

VOID DrawBox ( VOID  )

Definition at line 43 of file Menu.c.

References BOX_SZEROKOSC, and ConOut.

Referenced by DrawBoxAndMenu().

44 {
45  UINTN i;
46 
47 #define BOX_SZEROKOSC 50
48 
49  ConOut->SetAttribute (ConOut, EFI_BACKGROUND_RED | EFI_BRIGHT | EFI_WHITE );
50 
51  AsciiPrint("\r\n");
52  AsciiPrint("%c", BOXDRAW_DOWN_RIGHT_DOUBLE);
53  for (i = 0; i < BOX_SZEROKOSC; i++)
54  AsciiPrint("%c", BOXDRAW_DOUBLE_HORIZONTAL);
55  AsciiPrint("%c\r\n", BOXDRAW_DOWN_LEFT_DOUBLE );
56 
57  AsciiPrint("%c RDFU ver 1.0 ready %c\r\n", BOXDRAW_VERTICAL_HORIZONTAL, BOXDRAW_VERTICAL_HORIZONTAL );
58 
59  AsciiPrint("%c", BOXDRAW_UP_RIGHT_DOUBLE);
60  for (i = 0; i < BOX_SZEROKOSC; i++)
61  AsciiPrint("%c", BOXDRAW_DOUBLE_HORIZONTAL);
62  AsciiPrint("%c\r\n", BOXDRAW_UP_LEFT_DOUBLE );
63 
64 }

Here is the caller graph for this function:

UINTN DrawBoxAndMenu ( BOOLEAN  ShouldDrawBox)

Definition at line 67 of file Menu.c.

References CheckImagesFunctionPointers(), ComConsoleStart(), ConOut, DisplayLogX64Context(), DisplayLogX86Context(), DrawBox(), DumpAllEvents(), DumpAllHandles(), DumpAllImages(), DumpEFITables(), DumpFirmwareFromROM(), DumpGDT(), DumpIDT(), DumpMemoryMap(), FreeEvents(), FreeHandles(), FreeImages(), FreeMemMap(), GetAllEvents(), GetAllHandlesWithDescription(), GetAllImagesWithDescription(), GetMemoryMapList(), GetX64Context(), GetX86Context(), InitializeEFITables(), InstallEFITableScanner(), InstallEventScanner(), InstallSniffImage(), OPTION_CONTINUE, OPTION_FORCE_EXIT, OPTION_STAY_RESIDENT, ScanMemoryForExecutables(), and UserWantsThisOption().

Referenced by MainLoop().

68 {
69  CHAR8 Option;
70 
71 #if defined(_WIN64)
72  x64_context Context;
73 #else
74  x86_context Context;
75 #endif
76 
77  handle_entry_list *HandleList;
78  image_entry_list *ImageList;
79  event_entry_list *EventList;
80  memory_map_entry_list *MemMap;
81 
82 
83  if (ShouldDrawBox)
84  DrawBox();
85 
86 
87  ConOut->SetAttribute (ConOut, EFI_BACKGROUND_BLACK | EFI_BRIGHT | EFI_WHITE );
88  AsciiPrint("\r\n\r\n");
89 
90 
91  AsciiPrint("Menu: \r\n\r\n");
92  AsciiPrint("[0] - List all handles\r\n");
93  AsciiPrint("[1] - List all images\r\n");
94  AsciiPrint("[2] - Dump all images to disk\r\n");
95  AsciiPrint("[3] - Check BootServices/RuntimeServices/SystemTable pointers in images\r\n");
96  AsciiPrint("[4] - Install image sniffer (SniffImage, requires residency)\r\n");
97  AsciiPrint("[5] - List all events\r\n");
98  AsciiPrint("[6] - Install event scanner (requires residency)\r\n");
99  AsciiPrint("[7] - Scan memory for PE images (bruteforce) and dump them to disk\r\n");
100  AsciiPrint("[8] - Display memory map\r\n");
101  AsciiPrint("[9] - Display and dump memory map\r\n");
102  AsciiPrint("[A] - Display and dump memory map (skip Reserved and MemoryMappedIO mem)\r\n");
103  AsciiPrint("[B] - Display EFI services\r\n");
104  AsciiPrint("[C] - Install EFI services scanner (requires residency)\r\n");
105  AsciiPrint("[D] - Display IDT\r\n");
106  AsciiPrint("[E] - Display GDT\r\n");
107  AsciiPrint("[F] - Display Context\r\n");
108  AsciiPrint("[G] - Dump firmware from ROM\r\n");
109  AsciiPrint("[H] - Install all resident scanners\r\n");
110  AsciiPrint("[I] - Run COM console\r\n");
111  AsciiPrint("[Q] - Quit\r\n");
112 
113 
114  Option = UserWantsThisOption();
115 
116  switch(Option)
117  {
118  //List all handles
119  case '0':
120  HandleList = GetAllHandlesWithDescription();
121  if (!HandleList)
122  {
123  AsciiPrint("Error: GetAllHandlesWithDescription return 0\r\n");
124  return FALSE;
125  }
126 
127  DumpAllHandles(HandleList);
128  FreeHandles(HandleList);
129  return OPTION_CONTINUE;
130  break;
131 
132  // List all images
133  case '1':
134  ImageList = GetAllImagesWithDescription(NULL, TRUE);
135  if (!ImageList)
136  {
137  AsciiPrint("Error: GetAllImagesWithDescription returned 0\r\n");
138  return OPTION_CONTINUE;
139  }
140 
141  DumpAllImages(ImageList, FALSE);
142  FreeImages(ImageList);
143  return OPTION_CONTINUE;
144  break;
145 
146  // Dump all images to disk
147  case '2':
148  ImageList = GetAllImagesWithDescription(NULL, TRUE);
149  if (!ImageList)
150  {
151  AsciiPrint("Error: GetAllImagesWithDescription returned 0\r\n");
152  return OPTION_CONTINUE;
153  }
154 
155  DumpAllImages(ImageList, TRUE);
156  FreeImages(ImageList);
157  return OPTION_CONTINUE;
158  break;
159 
160 
161  case '3':
162  ImageList = GetAllImagesWithDescription(NULL, TRUE);
163  if (!ImageList)
164  {
165  AsciiPrint("Error: GetAllImagesWithDescription returned 0\r\n");
166  return OPTION_CONTINUE;
167  }
168 
169  CheckImagesFunctionPointers(ImageList);
170  FreeImages(ImageList);
171  return OPTION_CONTINUE;
172  break;
173 
174 
175  // Install image sniffer (SniffImage, requires residency)
176  case '4':
177  InstallSniffImage(NULL, NULL);
178  return OPTION_STAY_RESIDENT;
179  break;
180 
181 
182  // List all events
183  case '5':
184  EventList = GetAllEvents();
185  if (!EventList)
186  {
187  AsciiPrint("Error: GetAllEvents() returned 0\r\n");
188  return OPTION_CONTINUE;
189  }
190  DumpAllEvents(EventList);
191  FreeEvents(EventList);
192  return OPTION_CONTINUE;
193  break;
194 
195  // Install event scanner (requires residency)
196  case '6':
197  InstallEventScanner(NULL);
198  return OPTION_STAY_RESIDENT;
199  break;
200 
201  // Scan for PE images (bruteforce) and dump them to disk
202  case '7':
204  return OPTION_CONTINUE;
205  break;
206 
207  // Display memory map
208  case '8':
209  MemMap = GetMemoryMapList();
210  if (!MemMap)
211  {
212  AsciiPrint("Error: GetMemoryMapList() returned 0\r\n");
213  return OPTION_CONTINUE;
214  }
215 
216  DumpMemoryMap(MemMap, FALSE, 0);
217  FreeMemMap(MemMap);
218 
219  return OPTION_CONTINUE;
220  break;
221 
222  // Display and dump memory map
223  case '9':
224  MemMap = GetMemoryMapList();
225  if (!MemMap)
226  {
227  AsciiPrint("Error: GetMemoryMapList() returned 0\r\n");
228  return OPTION_CONTINUE;
229  }
230 
231  DumpMemoryMap(MemMap, TRUE, 0);
232  FreeMemMap(MemMap);
233 
234  return OPTION_CONTINUE;
235  break;
236 
237 
238  // dump memory map to disk and skip selected types
239  case 'A':
240  case 'a':
241  MemMap = GetMemoryMapList();
242  if (!MemMap)
243  {
244  AsciiPrint("Error: GetMemoryMapList() returned 0\r\n");
245  return OPTION_CONTINUE;
246  }
247 
248  DumpMemoryMap(MemMap, TRUE, EfiMemoryMappedIO);
249  FreeMemMap(MemMap);
250  return OPTION_CONTINUE;
251  break;
252 
253 
254  // Display EFI services
255  case 'B':
256  case 'b':
258  DumpEFITables(FALSE);
259  return OPTION_CONTINUE;
260  break;
261 
262  // Install EFI services scanner (requires residency)
263  case 'C':
264  case 'c':
267  return OPTION_STAY_RESIDENT;
268  break;
269 
270  // Display IDT
271  case 'D':
272  case 'd':
273  DumpIDT();
274  return OPTION_CONTINUE;
275  break;
276 
277  // Display GDT
278  case 'E':
279  case 'e':
280  DumpGDT();
281  return OPTION_CONTINUE;
282  break;
283 
284  // Display Context
285  case 'F':
286  case 'f':
287 #if defined(_WIN64)
288  GetX64Context(&Context);
289  DisplayLogX64Context(&Context);
290 #else
291  GetX86Context(&Context);
292  DisplayLogX86Context(&Context);
293 #endif
294 
295  return OPTION_CONTINUE;
296  break;
297 
298 
299  // dump firmware from ROM
300  case 'G':
301  case 'g':
303  break;
304 
305  // install all resident scanners
306  case 'H':
307  case 'h':
308  InstallSniffImage(NULL, NULL);
309  InstallEventScanner(NULL);
312  return OPTION_STAY_RESIDENT;
313  break;
314 
315  // Quit
316  case 'Q':
317  case 'q':
318  AsciiPrint("Quiting.\r\n");
319  return OPTION_FORCE_EXIT;
320  break;
321 
322  // com console
323  case 'I':
324  case 'i':
325  ComConsoleStart();
326  return OPTION_CONTINUE;
327  break;
328 
329  }
330 
331  return OPTION_CONTINUE;
332 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOLEAN MainLoop ( VOID  )

Definition at line 336 of file Menu.c.

References ConOut, DrawBoxAndMenu(), OPTION_FORCE_EXIT, OPTION_STAY_RESIDENT, and ScreenShowSplashLogo().

Referenced by EfiScannerEntryPoint().

337 {
338 
339  UINTN Result;
340  ConOut = gST->ConOut;
341 
342 
344 
345  Result = DrawBoxAndMenu(TRUE);
346 
347  do
348  {
349 
350  if (Result == OPTION_FORCE_EXIT)
351  return FALSE;
352 
353  if (Result == OPTION_STAY_RESIDENT)
354  return TRUE;
355 
356  Result = DrawBoxAndMenu(FALSE);
357 
358  } while (1);
359 
360 
361 }

Here is the call graph for this function:

Here is the caller graph for this function:

CHAR8 UserWantsThisOption ( VOID  )

Definition at line 26 of file Menu.c.

References EFI_STATUS().

Referenced by DrawBoxAndMenu().

27 {
28  EFI_INPUT_KEY Key;
29  UINTN junk;
30  EFI_STATUS Status;
31 
32  Status = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
33  if (Status == EFI_NOT_READY)
34  {
35  gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &junk);
36  gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
37  }
38 
39  return (CHAR8)Key.UnicodeChar;
40 }

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* ConOut

Definition at line 16 of file Menu.c.

Referenced by DrawBox(), DrawBoxAndMenu(), and MainLoop().