RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
EfiScannerHeaders.h File Reference

Main include file. More...

#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/PrintLib.h>
#include <Library/DevicePathLib.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/PciRootBridgeIo.h>
#include "PeImage.h"
#include "TeImage.h"
#include "EfiScannerLib.h"
#include "Images.h"
#include "Events.h"
#include "Arch.h"
#include "Memory.h"
Include dependency graph for EfiScannerHeaders.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG_ON   1
 
#define CHECK_BAD_ADDRS   1
 
#define USE_DXE_SERVICES   0
 
#define LOG_FILE   L"log.txt"
 
#define LOG_INIT_LINE   ": Initializing scanner ... \r\n"
 
#define LOG_EXIT_LINE   ": Everything done, quiting. \r\n"
 
#define CONF_FILE_PATH   L"conf.txt"
 
#define PAGE_SIZE   EFI_PAGE_SIZE
 
#define MAX_VALID_IMAGES   512
 
#define MAX_MEM_DUMP_SIZE   1024*1024*10
 
#define TICKS_PER_MS   10000U
 
#define SAMPLE_INTERVAL   (10 * 10 * TICKS_PER_MS)
 
#define EFI_EVENT_NOTIFY_WAIT   0x00000100
 
#define EFI_TPL_NOTIFY   16
 
#define PRINT_FUNC   if (gEfiScannerPolicy.OpUsePrint) Print
 
#define PRINT_FUNC_ASCII   if (gEfiScannerPolicy.OpUsePrint) AsciiPrint
 

Typedefs

typedef VOID(* CALLBACK_IMAGESNIFFER_NEW )(image_entry_list *OrgImageList, image_entry *NewImage)
 
typedef VOID(* CALLBACK_IMAGESNIFFER_MOD )(image_entry_list *OrgImageList, image_entry *ModifiedImage)
 
typedef VOID(* CALLBACK_EVENTSCANNER )(event_entry_list *OrgEventList, event_entry *NewEvent)
 

Functions

EFI_STATUS InitializeLogFile (VOID)
 
EFI_STATUS WriteLogFile (CHAR8 *Data)
 
EFI_STATUS WriteLogFile16 (CHAR16 *Data)
 
EFI_STATUS CloseLogFile (VOID)
 
EFI_STATUS OpenFile (IN CHAR16 *FilePathName, IN UINT64 OpenMode, OUT EFI_FILE_PROTOCOL **File)
 
EFI_STATUS RedirectConsole (VOID)
 
EFI_STATUS ResetConsole (VOID)
 
VOID * MemAllocate (UINTN Size)
 
VOID MemFree (VOID *Mem)
 
VOID MemCopy (VOID *Dest, VOID *Src, UINTN Size)
 
VOID MemZero (VOID *Mem, UINTN Size)
 
EFI_STATUS MemRead (VOID *Dest, VOID *Src, UINTN Size)
 
memory_map_entry_list * GetMemoryMapList (VOID)
 
EFI_STATUS DumpMemoryMap (memory_map_entry_list *MemMap, BOOLEAN DumpToDisk, UINT32 SkipType)
 
VOID FreeMemMap (memory_map_entry_list *MemMap)
 
memory_map_entry * FindMapEntryByAddr (memory_map_entry_list *MemMap, EFI_PHYSICAL_ADDRESS Address)
 
VOID GetMemAttributesStringAscii (CHAR8 *MemAttributesBuff, UINTN MemAttributesBuffSize, UINT64 Attributes)
 
EFI_STATUS DumpMemoryToFile (C_PTR Address, UINTN Size, CHAR16 *FilePath, BOOLEAN UseProxy)
 
VOID GetHandleTypeStringAscii (CHAR8 *HandleTypeBuff, UINTN HandleTypeBuffSize, UINT16 Flags)
 
EFI_STATUS GetLoadedImageProtocol (EFI_HANDLE Handle, EFI_LOADED_IMAGE_PROTOCOL **XLoadedImage)
 
image_entry * FindImageByHandle (image_entry_list *ImageList, EFI_HANDLE Handle)
 
image_entry * FindImageByAddr (image_entry_list *ImageList, C_PTR Address)
 
image_entry_list * GetAllImagesWithDescription (handle_entry_list *HandleList, BOOLEAN CalculateCrc)
 
handle_entry_list * GetAllHandlesWithDescription (VOID)
 
EFI_STATUS CheckImagesFunctionPointers (image_entry_list *ImageList)
 
EFI_STATUS DumpAllHandles (handle_entry_list *HandleList)
 
EFI_STATUS DumpAllImages (image_entry_list *ImageList, BOOLEAN DumpToDisk)
 
VOID FreeImages (image_entry_list *ImageList)
 
VOID FreeHandles (handle_entry_list *HandleList)
 
EFI_STATUS DumpImageToDisk (image_entry *ImageEntry)
 
image_entry * AddImageToList (image_entry_list *ImageList, EFI_HANDLE Handle, EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProt, BOOLEAN CalculateCrc)
 
EFI_STATUS ScanMemoryForExecutables (VOID)
 
EFI_STATUS DumpFirmwareFromROM (VOID)
 
EFI_STATUS DumpPEFile (C_PTR BaseAddr)
 
C_PTR IsBadAddress (C_PTR Address)
 
EFI_STATUS InstallSniffImage (CALLBACK_IMAGESNIFFER_NEW UserNewImageCallback, CALLBACK_IMAGESNIFFER_MOD UserModImageCallback)
 
EFI_STATUS UnInstallSniffImage (VOID)
 
EFI_STATUS DumpEFITables (BOOLEAN SilentMode)
 
EFI_STATUS InitializeEFITables (VOID)
 
C_PTR EFITableGetAddr (CHAR8 *FuncName)
 
EFI_STATUS InstallEFITableScanner (VOID)
 
EFI_STATUS UnInstallEFITableScanner (VOID)
 
EFI_STATUS DumpEvents (BOOLEAN WriteToTable, BOOLEAN SilentMode)
 
EFI_STATUS InstallEventScanner (CALLBACK_EVENTSCANNER UserCallback)
 
EFI_STATUS UnInstallEventScanner (VOID)
 
event_entry_list * GetAllEvents (VOID)
 
event_entry * FindEventByAddr (event_entry_list *EventList, C_PTR Address)
 
VOID FreeEvents (event_entry_list *EventList)
 
VOID GetEventTypeStringAscii (CHAR8 *EventTypeBuff, UINTN EventTypeBuffSize, UINT32 EventType)
 
EFI_STATUS DumpAllEvents (event_entry_list *EventList)
 
EFI_STATUS GetX64Context (x64_context *Context)
 
EFI_STATUS DisplayLogX64Context (x64_context *Context)
 
VOID ContextX64Test (VOID)
 
EFI_STATUS GetX86Context (x86_context *Context)
 
EFI_STATUS DisplayLogX86Context (x86_context *Context)
 
EFI_STATUS DumpGDT (VOID)
 
EFI_STATUS DumpIDT (VOID)
 
idt_entry * GetIdtEntry (ULONG IdtVectorNum)
 
EFI_STATUS IdtHookInterrupt (C_PTR NewIntHandlerAddr, ULONG IdtVectorNum, C_PTR *OutOldIntAddr)
 
EFI_STATUS IdtHookTest (VOID)
 
EFI_STATUS ReadConfiguration (CHAR16 *ConfPath)
 
EFI_STATUS EFIAPI EfiScannerInitialize (EFI_HANDLE ImageHandle, BOOLEAN OpUsePrint, BOOLEAN OpUseLog, BOOLEAN OpUseComPort)
 
EFI_STATUS ScreenTest (VOID)
 
EFI_STATUS ScreenShowSplashLogo (VOID)
 
VOID LogFullAscii (CHAR8 *FormatString,...)
 
VOID LogFullUnicode (CHAR16 *FormatString,...)
 
VOID LogFileAscii (CHAR8 *FormatString,...)
 
BOOLEAN GetPEHeaders (C_PTR Base, EFI_IMAGE_DOS_HEADER **pMZ, EFI_IMAGE_NT_HEADERS32 **pPE, EFI_IMAGE_SECTION_HEADER **pSH)
 
ULONG GetPECodeChecksum (C_PTR Base)
 
EFI_STATUS DumpTEFile (C_PTR BaseAddr)
 
VOID ComInitialize (ULONG ComPortAddr)
 
VOID ComPutString (CHAR8 *String)
 
VOID ASMEnterLock (ULONG *Lock)
 
VOID ASMLeaveLock (ULONG *Lock)
 
VOID ASMInitLock (ULONG *Lock)
 
BOOLEAN MainLoop (VOID)
 
EFI_STATUS ComConsoleStart (VOID)
 
VOID test_write (VOID)
 
VOID TestDumpHandles (VOID)
 

Variables

C_PTR gEventSignalQueueAddr
 
policy gEfiScannerPolicy
 

Detailed Description

Main include file.

Author
Piotr Bania
Date
Feb 2013 Main include file

Definition in file EfiScannerHeaders.h.

Macro Definition Documentation

#define CHECK_BAD_ADDRS   1

Definition at line 38 of file EfiScannerHeaders.h.

#define CONF_FILE_PATH   L"conf.txt"

Definition at line 50 of file EfiScannerHeaders.h.

Referenced by EfiScannerEntryPoint().

#define DEBUG_ON   1

Definition at line 37 of file EfiScannerHeaders.h.

#define EFI_EVENT_NOTIFY_WAIT   0x00000100

Definition at line 67 of file EfiScannerHeaders.h.

#define EFI_TPL_NOTIFY   16

Definition at line 68 of file EfiScannerHeaders.h.

Referenced by InstallEFITableScanner(), and InstallEventScanner().

#define LOG_EXIT_LINE   ": Everything done, quiting. \r\n"

Definition at line 48 of file EfiScannerHeaders.h.

Referenced by CloseLogFile().

#define LOG_FILE   L"log.txt"

Definition at line 46 of file EfiScannerHeaders.h.

Referenced by InitializeLogFile().

#define LOG_INIT_LINE   ": Initializing scanner ... \r\n"

Definition at line 47 of file EfiScannerHeaders.h.

Referenced by InitializeLogFile().

#define MAX_MEM_DUMP_SIZE   1024*1024*10

Definition at line 58 of file EfiScannerHeaders.h.

#define MAX_VALID_IMAGES   512

Definition at line 57 of file EfiScannerHeaders.h.

#define PAGE_SIZE   EFI_PAGE_SIZE

Definition at line 54 of file EfiScannerHeaders.h.

Referenced by GetMemoryMapList().

#define PRINT_FUNC   if (gEfiScannerPolicy.OpUsePrint) Print
#define PRINT_FUNC_ASCII   if (gEfiScannerPolicy.OpUsePrint) AsciiPrint

Definition at line 331 of file EfiScannerHeaders.h.

Referenced by DumpEFITables(), and LogFullAscii().

#define SAMPLE_INTERVAL   (10 * 10 * TICKS_PER_MS)

Definition at line 64 of file EfiScannerHeaders.h.

Referenced by InstallEFITableScanner(), and InstallEventScanner().

#define TICKS_PER_MS   10000U

Definition at line 62 of file EfiScannerHeaders.h.

Referenced by ScreenShowSplashLogo().

#define USE_DXE_SERVICES   0

Definition at line 39 of file EfiScannerHeaders.h.

Typedef Documentation

typedef VOID(* CALLBACK_EVENTSCANNER)(event_entry_list *OrgEventList, event_entry *NewEvent)

Definition at line 191 of file EfiScannerHeaders.h.

typedef VOID(* CALLBACK_IMAGESNIFFER_MOD)(image_entry_list *OrgImageList, image_entry *ModifiedImage)

Definition at line 165 of file EfiScannerHeaders.h.

typedef VOID(* CALLBACK_IMAGESNIFFER_NEW)(image_entry_list *OrgImageList, image_entry *NewImage)

Definition at line 164 of file EfiScannerHeaders.h.

Function Documentation

image_entry* AddImageToList ( image_entry_list *  ImageList,
EFI_HANDLE  Handle,
EFI_LOADED_IMAGE_PROTOCOL *  LoadedImageProt,
BOOLEAN  CalculateCrc 
)

Function creates the new ImageEntry list (based on the old one) it also adds one new image entry to it.

Parameters
ImageListPointer to selected ImageEntry
HandleImage handle
LoadedImageProtPointer to openned LOADED_IMAGE_PROTOCOL
CalculateCrcIndicates whether function should calculate the crc32 value of the image code.
Return values
image_entry*On success a pointer to newly created image_entry is returned
NULLOn error

Definition at line 642 of file Images.c.

References _image_entry::Crc32, GetImagePathAndName(), GetPECodeChecksum(), _image_entry::Handle, _image_entry::ImageBase, _image_entry_list::ImageEntry, _image_entry::ImageSize, _image_entry::LoadedImageProtocol, MemAllocate(), MemCopy(), MemFree(), and _image_entry_list::NumOfEntries.

Referenced by hooked_LoadImage().

646 {
647  image_entry *ImageEntryOld, *ImageEntryNew, *ImageEntry;
648 
649 
650  if (!ImageList)
651  return 0;
652 
653  ImageEntryOld = ImageList->ImageEntry;
654  ImageEntryNew = (image_entry*)MemAllocate((ImageList->NumOfEntries + 1) * sizeof(image_entry));
655 
656  if (!ImageEntryNew)
657  return 0;
658 
659  // copy everything from the old list
660  MemCopy(ImageEntryNew, ImageEntryOld, ImageList->NumOfEntries*sizeof(image_entry));
661 
662  // add new entry
663  ImageEntry = (image_entry*)&ImageEntryNew[ImageList->NumOfEntries];
664 
665  ImageEntry->Handle = Handle;
666  ImageEntry->LoadedImageProtocol = LoadedImageProt;
667  ImageEntry->ImageBase = LoadedImageProt->ImageBase;
668  ImageEntry->ImageSize = LoadedImageProt->ImageSize;
669 
670  if (CalculateCrc)
671  ImageEntry->Crc32 = GetPECodeChecksum((C_PTR)LoadedImageProt->ImageBase);
672 
673  GetImagePathAndName(ImageEntry, Handle, LoadedImageProt);
674 
675  // free the old list and link the new one
676  ImageList->ImageEntry = ImageEntryNew;
677  ImageList->NumOfEntries++;
678 
679  MemFree(ImageEntryOld);
680  return ImageEntry;
681 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID ASMEnterLock ( ULONG *  Lock)

Referenced by LogFileAscii(), LogFullAscii(), and LogFullUnicode().

Here is the caller graph for this function:

VOID ASMInitLock ( ULONG *  Lock)

Referenced by EfiScannerInitialize().

Here is the caller graph for this function:

VOID ASMLeaveLock ( ULONG *  Lock)

Referenced by LogFileAscii(), LogFullAscii(), and LogFullUnicode().

Here is the caller graph for this function:

EFI_STATUS CheckImagesFunctionPointers ( image_entry_list *  ImageList)

Function enumerates the entire image list and it checks whether pointers to RuntimeServices, BootServices and SystemTables are different across different images. Everything is reported to the screen, log file or serial port depending on the framework policy.

Parameters
ImageListPointer to image list
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 961 of file Images.c.

References check_modification, _image_entry::Crc32, _image_entry::FilePath, _image_entry::Handle, _image_entry::ImageBase, _image_entry_list::ImageEntry, _image_entry::ImageSize, _image_entry::LoadedImageProtocol, LogFullAscii(), _image_entry::Name, and _image_entry_list::NumOfEntries.

Referenced by DrawBoxAndMenu(), and TestDumpHandles().

962 {
963  UINTN i, MCounter;
964  image_entry *ImageEntry;
965  C_PTR LinkBootServices, OldLinkBootServices;
966  C_PTR LinkRuntimeServices, OldLinkRuntimeServices;
967  C_PTR LinkSystemTable, OldLinkSystemTable;
968 
969  if (!ImageList)
970  return EFI_NOT_FOUND;
971 
972 
973  OldLinkSystemTable = 0;
974  OldLinkBootServices = 0;
975  OldLinkRuntimeServices = 0;
976 
977  MCounter = 0;
978 
979 
980  LogFullAscii("--- CHECKING IMAGES ---\r\n");
981 
982 
983  for (i = 0; i < ImageList->NumOfEntries; i++)
984  {
985  ImageEntry = &ImageList->ImageEntry[i];
986  LinkSystemTable = (C_PTR)ImageEntry->LoadedImageProtocol->SystemTable;
987  LinkBootServices = (C_PTR)ImageEntry->LoadedImageProtocol->SystemTable->BootServices;
988  LinkRuntimeServices = (C_PTR)ImageEntry->LoadedImageProtocol->SystemTable->RuntimeServices;
989 
990 
991 
992  LogFullAscii("Index=%08x Handle=%08x ImageBase=%016lx ImageSize=%08llx Crc32=%08x Name=%a FilePath=%a\r\n",
993  i,
994  ImageEntry->Handle,
995  (MAX_PTR)ImageEntry->ImageBase,
996  ImageEntry->ImageSize,
997  ImageEntry->Crc32,
998  ImageEntry->Name,
999  ImageEntry->FilePath);
1000 
1001  LogFullAscii("Index=%08x SystemTable=%016lx BootServices=%016lx RuntimeServices=%016lx\r\n",
1002  i,
1003  (MAX_PTR)LinkSystemTable,
1004  (MAX_PTR)LinkBootServices,
1005  (MAX_PTR)LinkRuntimeServices);
1006 
1007 
1008 #define check_modification(val1, val2, text) if (val1 != val2) { \
1009  LogFullAscii("Index=%08x Found modification of %a %016lx -> %016lx\r\n", i, text, (MAX_PTR)val1, (MAX_PTR)val2); \
1010  MCounter++; }
1011 
1012 
1013  // first pass? nope so apply the checks
1014  if (OldLinkSystemTable)
1015  {
1016  check_modification(OldLinkSystemTable, LinkSystemTable, "SystemTable");
1017  check_modification(OldLinkBootServices, LinkBootServices, "BootServices");
1018  check_modification(OldLinkRuntimeServices, LinkRuntimeServices, "RuntimeServices");
1019  }
1020 
1021 
1022 #undef check_modification
1023 
1024  OldLinkSystemTable = LinkSystemTable;
1025  OldLinkBootServices = LinkBootServices;
1026  OldLinkRuntimeServices = LinkRuntimeServices;
1027 
1028  }
1029 
1030 
1031 
1032 
1033  LogFullAscii("Found %d modifications\r\n", MCounter);
1034  LogFullAscii("--- DONE ---\r\n");
1035 
1036  return EFI_SUCCESS;
1037 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS CloseLogFile ( VOID  )

Function closes the log file.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 197 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, LOG_EXIT_LINE, and _policy::OpUseLog.

Referenced by EfiScannerEntryPoint().

198 {
199  UINTN Size;
200 
201  // check the policy first
203  return EFI_NOT_FOUND;
204 
205 
206  Size = sizeof(LOG_EXIT_LINE)-1;
207  gLogFile->Write(gLogFile, &Size, LOG_EXIT_LINE);
208  gLogFile->Close(gLogFile);
209 
210  return EFI_SUCCESS;
211 }

Here is the caller graph for this function:

EFI_STATUS ComConsoleStart ( VOID  )

main com console loop, function reads keys from COM port, writes them back (echo) and picks necessary action

Definition at line 433 of file ComConsole.c.

References ComGetChar(), CommandHelp(), ComPutChar(), KEY_BACKSPACE, KEY_ENTER, KEY_ESCAPE, LogFullAscii(), MemZero(), and ProcessCommand().

Referenced by DrawBoxAndMenu().

434 {
435  UCHAR Key;
436  CHAR8 Cmd[512];
437  int Index;
438 
439  //gEfiScannerPolicy.OpUseComPort = FALSE;
440 
441  Index = -1;
442  MemZero(&Cmd, sizeof(Cmd));
443 
444 
445  CommandHelp();
446 
447  while (1)
448  {
449  Key = ComGetChar();
450  ComPutChar(Key);
451 
452  if (Key == KEY_ESCAPE)
453  break;
454  else if (Key == KEY_BACKSPACE)
455  {
456  if (Index >= 0)
457  Cmd[Index--] = 0;
458  continue;
459  }
460  else if (Key == KEY_ENTER)
461  {
462  AsciiPrint("Got command: %a\r\n", Cmd);
463 
464  // add the 'space'
465  Cmd[++Index] = ' ';
466  ProcessCommand(Cmd);
467 
468  MemZero(&Cmd, sizeof(Cmd));
469  Index = -1;
470 
471  LogFullAscii("console ready\r\n");
472  continue;
473  }
474 
475  Index++;
476  if (Index >= (sizeof(Cmd) - 1))
477  {
478  Index = 0;
479  MemZero(&Cmd, sizeof(Cmd));
480  }
481  Cmd[Index] = Key;
482 
483  //AsciiPrint("read: %x", SingleChar);
484 
485  gBS->Stall(10);
486  }
487 
488 
489 
490  return EFI_SUCCESS;
491 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID ComInitialize ( ULONG  ComPortAddr)

Function initializes serial port (com port) that will be used for the communication.

Parameters
ComPortAddrAddress of the com port.
Return values
NONE

Definition at line 44 of file ComPort.c.

References ComPort.

45 {
46  if (ComPortAddr)
47  ComPort = ComPortAddr;
48 }
VOID ComPutString ( CHAR8 *  String)

Function writes selected string to the selected com port.

Parameters
StringPointer to null-terminated string to send.
Return values
NONE

Definition at line 78 of file ComPort.c.

References ComPutChar().

Referenced by LogFileAscii(), and LogFullAscii().

79 {
80  while (String[0] != 0)
81  {
82  ComPutChar((UCHAR)String[0]);
83  String++;
84  }
85 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID ContextX64Test ( VOID  )

Definition at line 227 of file Context.c.

References DisplayLogX64Context(), DisplayLogX86Context(), GetX64Context(), and GetX86Context().

Referenced by ProcessCommand(), and TestDumpHandles().

228 {
229 
230 #if defined(_WIN64)
231  x64_context Context;
232  GetX64Context(&Context);
233  DisplayLogX64Context(&Context);
234 #else
235  x86_context ContextX86;
236  GetX86Context(&ContextX86);
237  DisplayLogX86Context(&ContextX86);
238 
239 #endif
240 
241 
242 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DisplayLogX64Context ( x64_context *  Context)

Function displays the X64 context structure.

Parameters
ContextPointer to x64_context structure
Return values
EFI_SUCCESS

Definition at line 123 of file Context.c.

References _x64_context::_Cr0, _x64_context::_Cr2, _x64_context::_Cr3, _x64_context::_Cr4, _x64_context::_Cr8, _x64_context::_Cs, _x64_context::_Dr0, _x64_context::_Dr2, _x64_context::_Dr3, _x64_context::_Dr6, _x64_context::_Dr7, _x64_context::_Ds, _x64_context::_Es, _x64_context::_Fs, _x64_context::_Gs, _x64_context::_Rax, _x64_context::_Rbp, _x64_context::_Rbx, _x64_context::_Rcx, _x64_context::_Rdi, _x64_context::_Rdx, _x64_context::_Rflags, _x64_context::_Rsi, _x64_context::_Rsp, _x64_context::_Ss, LOG_VALUE, and LogFullAscii().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

124 {
125 
126 #define LOG_VALUE(name, val) LogFullAscii(name, val);
127 
128  LogFullAscii("----- X64 CONTEXT DUMP -----\r\n");
129 
130  LOG_VALUE("Rax = %016lx\r\n", Context->_Rax);
131  LOG_VALUE("Rbx = %016lx\r\n", Context->_Rbx);
132  LOG_VALUE("Rcx = %016lx\r\n", Context->_Rcx);
133  LOG_VALUE("Rdx = %016lx\r\n", Context->_Rdx);
134  LOG_VALUE("Rsi = %016lx\r\n", Context->_Rsi);
135  LOG_VALUE("Rdi = %016lx\r\n", Context->_Rdi);
136  LOG_VALUE("Rbp = %016lx\r\n", Context->_Rbp);
137  LOG_VALUE("Rsp = %016lx\r\n", Context->_Rsp);
138 
139 
140  LOG_VALUE("Dr0 = %016lx\r\n", Context->_Dr0);
141  LOG_VALUE("Dr2 = %016lx\r\n", Context->_Dr2);
142  LOG_VALUE("Dr3 = %016lx\r\n", Context->_Dr3);
143  LOG_VALUE("Dr6 = %016lx\r\n", Context->_Dr6);
144  LOG_VALUE("Dr7 = %016lx\r\n", Context->_Dr7);
145 
146  LOG_VALUE("Cr0 = %016lx\r\n", Context->_Cr0);
147  LOG_VALUE("Cr2 = %016lx\r\n", Context->_Cr2);
148  LOG_VALUE("Cr3 = %016lx\r\n", Context->_Cr3);
149  LOG_VALUE("Cr4 = %016lx\r\n", Context->_Cr4);
150  LOG_VALUE("Cr8 = %016lx\r\n", Context->_Cr8);
151 
152  LOG_VALUE("Rflags = %016lx\r\n", Context->_Rflags);
153 
154  LOG_VALUE("Cs = %04x\r\n", Context->_Cs);
155  LOG_VALUE("Ds = %04x\r\n", Context->_Ds);
156  LOG_VALUE("Es = %04x\r\n", Context->_Es);
157  LOG_VALUE("Fs = %04x\r\n", Context->_Fs);
158  LOG_VALUE("Gs = %04x\r\n", Context->_Gs);
159  LOG_VALUE("Ss = %04x\r\n", Context->_Ss);
160 
161 
162 #undef LOG_VALUE
163 
164 
165  return EFI_SUCCESS;
166 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DisplayLogX86Context ( x86_context *  Context)

Function displays the X86 context structure.

Parameters
ContextPointer to x86_context structure
Return values
EFI_SUCCESS

Definition at line 180 of file Context.c.

References _x86_context::_Cr0, _x86_context::_Cr2, _x86_context::_Cr3, _x86_context::_Cr4, _x86_context::_Cs, _x86_context::_Dr0, _x86_context::_Dr2, _x86_context::_Dr3, _x86_context::_Dr6, _x86_context::_Dr7, _x86_context::_Ds, _x86_context::_Eax, _x86_context::_Ebp, _x86_context::_Ebx, _x86_context::_Ecx, _x86_context::_Edi, _x86_context::_Edx, _x86_context::_Eflags, _x86_context::_Es, _x86_context::_Esi, _x86_context::_Esp, _x86_context::_Fs, _x86_context::_Gs, _x86_context::_Ss, LOG_VALUE, and LogFullAscii().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

181 {
182 
183 #define LOG_VALUE(name, val) LogFullAscii(name, val);
184 
185  LogFullAscii("----- X64 CONTEXT DUMP -----\r\n");
186 
187  LOG_VALUE("Rax = %08x\r\n", Context->_Eax);
188  LOG_VALUE("Rbx = %08x\r\n", Context->_Ebx);
189  LOG_VALUE("Rcx = %08x\r\n", Context->_Ecx);
190  LOG_VALUE("Rdx = %08x\r\n", Context->_Edx);
191  LOG_VALUE("Rsi = %08x\r\n", Context->_Esi);
192  LOG_VALUE("Rdi = %08x\r\n", Context->_Edi);
193  LOG_VALUE("Rbp = %08x\r\n", Context->_Ebp);
194  LOG_VALUE("Rsp = %08x\r\n", Context->_Esp);
195 
196 
197  LOG_VALUE("Dr0 = %08x\r\n", Context->_Dr0);
198  LOG_VALUE("Dr2 = %08x\r\n", Context->_Dr2);
199  LOG_VALUE("Dr3 = %08x\r\n", Context->_Dr3);
200  LOG_VALUE("Dr6 = %08x\r\n", Context->_Dr6);
201  LOG_VALUE("Dr7 = %08x\r\n", Context->_Dr7);
202 
203  LOG_VALUE("Cr0 = %08x\r\n", Context->_Cr0);
204  LOG_VALUE("Cr2 = %08x\r\n", Context->_Cr2);
205  LOG_VALUE("Cr3 = %08x\r\n", Context->_Cr3);
206  LOG_VALUE("Cr4 = %08x\r\n", Context->_Cr4);
207 
208  LOG_VALUE("Eflags = %08x\r\n", Context->_Eflags);
209 
210  LOG_VALUE("Cs = %04x\r\n", Context->_Cs);
211  LOG_VALUE("Ds = %04x\r\n", Context->_Ds);
212  LOG_VALUE("Es = %04x\r\n", Context->_Es);
213  LOG_VALUE("Fs = %04x\r\n", Context->_Fs);
214  LOG_VALUE("Gs = %04x\r\n", Context->_Gs);
215  LOG_VALUE("Ss = %04x\r\n", Context->_Ss);
216 
217 
218 #undef LOG_VALUE
219 
220 
221  return EFI_SUCCESS;
222 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpAllEvents ( event_entry_list *  EventList)

Function enumarates and dumps all events found in the event list. The output is shown on the screen, written to the log file or serial port depending on the current library policy.

Parameters
EventListPointer to the event list gathered from GetAllEvents function
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 584 of file Events.c.

References EVENT_TYPE_BUFF_SIZE, _event_entry_list::EventEntry, _image_entry::FilePath, FindImageByAddr(), FreeImages(), GetAllImagesWithDescription(), GetEventTypeStringAscii(), _image_entry::ImageBase, _image_entry::ImageSize, LogFullAscii(), _image_entry::Name, IEVENT::NotifyFunction, _event_entry_list::NumOfEntries, and IEVENT::Type.

Referenced by CommandEventInfo(), DrawBoxAndMenu(), and TestDumpHandles().

585 {
586  UINTN i;
587  event_entry *Event;
588 
589  image_entry_list *ImageList;
590  image_entry *ImageEntry;
591 
592  CHAR8 EventTypeBuff[EVENT_TYPE_BUFF_SIZE];
593 
594  if (!EventList)
595  return EFI_NOT_FOUND;
596 
597  ImageList = GetAllImagesWithDescription(NULL, FALSE);
598  if (!ImageList)
599  return EFI_NOT_FOUND;
600 
601 
602  for (i = 0; i < EventList->NumOfEntries; i++)
603  {
604  Event = (event_entry*)&EventList->EventEntry[i];
605  ImageEntry = FindImageByAddr(ImageList, (C_PTR)Event->NotifyFunction);
606 
607  GetEventTypeStringAscii(EventTypeBuff, sizeof(EventTypeBuff), Event->Type);
608 
609 
610  if (ImageEntry)
611  {
612 
613  LogFullAscii("[%08d] EventFunc = %016lx InImage: %016lx-%016lx Type: %08x - %a ImageName: %a ImagePath: %a\r\n",
614  i,
615  (MAX_PTR)Event->NotifyFunction,
616  (MAX_PTR)ImageEntry->ImageBase,
617  (MAX_PTR)((C_PTR)ImageEntry->ImageBase + ImageEntry->ImageSize),
618  Event->Type,
619  EventTypeBuff,
620  ImageEntry->Name,
621  ImageEntry->FilePath);
622  }
623  else
624  {
625 
626  LogFullAscii("[%08d] EventFunc = %016lx InImage: NO-IMAGE-FOUND Type: %08x - %a\r\n",
627  i,
628  (MAX_PTR)Event->NotifyFunction,
629  Event->Type,
630  EventTypeBuff);
631  }
632 
633  }
634 
635  FreeImages(ImageList);
636  return EFI_SUCCESS;
637 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpAllHandles ( handle_entry_list *  HandleList)

Function enumarates and dumps all handles found in the handle list. The output is shown on the screen, written to the log file or serial port depending on the current library policy.

Parameters
HandleListPointer to the handle list gathered from GetAllHandlesWithDescription function
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 530 of file Images.c.

References _handle_entry::Flags, GetHandleTypeStringAscii(), _handle_entry::Handle, _handle_entry_list::HandleEntry, LogFullAscii(), and _handle_entry_list::NumOfEntries.

Referenced by DrawBoxAndMenu(), and TestDumpHandles().

531 {
532  UINTN i;
533  CHAR8 HandleTypeAscii[256];
534 
535  if (!HandleList || !HandleList->HandleEntry)
536  return EFI_NOT_FOUND;
537 
538 #define check_flag(flag, text) if (HandleList->HandleEntry[i].Flags & flag) PRINT_FUNC_ASCII(text); WriteLogFile(text)
539 
540 
541  LogFullAscii("--- BEGINING HANDLE DUMP ---\r\n");
542 
543  for (i = 0; i < HandleList->NumOfEntries; i++)
544  {
545  /*
546  LogFullAscii("%08x HandleValue=%08x Flags=%08x ", i + 1, HandleList->HandleEntry[i].Handle, HandleList->HandleEntry[i].Flags);
547  check_flag(HTYPE_IMAGE_HANDLE, "HTYPE_IMAGE_HANDLE |");
548  check_flag(HTYPE_DRIVER_BINDING_HANDLE, "HTYPE_DRIVER_BINDING_HANDLE |");
549  check_flag(HTYPE_COMPONENT_NAME_HANDLE, "HTYPE_COMPONENT_NAME_HANDLE |");
550  check_flag(HTYPE_DEVICE_HANDLE, "HTYPE_DEVICE_HANDLE |");
551  check_flag(HTYPE_DRIVER_CONFIGURATION_HANDLE, "HTYPE_DRIVER_CONFIGURATION_HANDLE |");
552  check_flag(HTYPE_DRIVER_DIAGNOSTICS_HANDLE, "HTYPE_DRIVER_DIAGNOSTICS_HANDLE |");
553  LogFullAscii("\r\n");
554  */
555 
556  GetHandleTypeStringAscii(HandleTypeAscii,
557  sizeof(HandleTypeAscii),
558  HandleList->HandleEntry[i].Flags);
559 
560  LogFullAscii("%08x HandleValue=%08x Flags=%08x %a\r\n",
561  i + 1,
562  HandleList->HandleEntry[i].Handle,
563  HandleList->HandleEntry[i].Flags,
564  HandleTypeAscii);
565 
566  }
567 
568 #undef check_flag
569 
570  LogFullAscii("--- END OF HANDLE DUMP ---\r\n");
571 
572 
573  return EFI_SUCCESS;
574 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpAllImages ( image_entry_list *  ImageList,
BOOLEAN  DumpToDisk 
)

Function dumps all image on the ImageList either just to screen or to disk also (to "dump\ImageBase.dmp")

Parameters
ImageListPointer to image list
DumpToDiskIndicates whether images will be dumped to disk or not
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 906 of file Images.c.

References _image_entry::Crc32, DumpImageToDisk(), _image_entry::FilePath, _image_entry::Handle, _image_entry::ImageBase, _image_entry_list::ImageEntry, _image_entry::ImageSize, LogFullAscii(), _image_entry::Name, and _image_entry_list::NumOfEntries.

Referenced by CommandDriverInfo(), DrawBoxAndMenu(), and TestDumpHandles().

908 {
909 
910  UINTN i;
911  image_entry *ImageEntry;
912 
913 
914  if (!ImageList)
915  return EFI_NOT_FOUND;
916 
917 
918  LogFullAscii("--- BEGINING IMAGES DUMP ---\r\n");
919 
920 
921  for (i = 0; i < ImageList->NumOfEntries; i++)
922  {
923  ImageEntry = &ImageList->ImageEntry[i];
924 
925 
926  LogFullAscii("Index=%08x Handle=%08x ImageBase=%016lx ImageSize=%08llx Crc32=%08x Name=%a FilePath=%a\r\n",
927  i,
928  ImageEntry->Handle,
929  (MAX_PTR)ImageEntry->ImageBase,
930  ImageEntry->ImageSize,
931  ImageEntry->Crc32,
932  ImageEntry->Name,
933  ImageEntry->FilePath);
934 
935 
936  if (DumpToDisk)
937  DumpImageToDisk(ImageEntry);
938 
939  }
940 
941 
942  LogFullAscii("--- END OF IMAGE DUMP ---\r\n");
943 
944  return EFI_SUCCESS;
945 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpEFITables ( BOOLEAN  SilentMode)

Definition at line 208 of file TableMonitor.c.

References FindImageByAddr(), GetAllImagesWithDescription(), _image_entry::ImageBase, _image_entry::ImageSize, IsFunctionHooked(), _func_table::last_addr, LogFileAscii(), LogFullAscii(), _func_table::name, and PRINT_FUNC_ASCII.

Referenced by CommandFunction(), DrawBoxAndMenu(), and NotifyScannerTimer().

209 {
210  int i, change;
211  CHAR8 *p;
212 
213  C_PTR ImageBase;
214  UINT64 ImageSize;
215  C_PTR TempAddr;
216 
217  ULONG32 HookDest;
218  BOOLEAN WasHooked;
219  image_entry *HookDestImageEntry;
220 
221  image_entry_list *ImageList;
222  image_entry *ImageEntry;
223 
224 
225  if (!SilentMode)
226  LogFullAscii(": Dumping EFI Functions tables...\r\n");
227 
228 
229  ImageList = GetAllImagesWithDescription(NULL, FALSE);
230  if (!ImageList)
231  {
232  LogFullAscii("%a: Error executing GetAllImagesWithDescription failed\r\n", __FUNCTION__);
233  return EFI_NOT_FOUND;
234  }
235 
236 
237 
238  for (i = 0; gEFITables[i].name[0] != '?'; i++)
239  {
240  ImageBase = 0;
241  ImageSize = 0;
242  change = 0;
243 
244  TempAddr = *(C_PTR*)gEFITables[i].ptr_va;
245  p = (CHAR8*)&gEFITables[i].name;
246 
247  ImageEntry = FindImageByAddr(ImageList, TempAddr);
248 
249  if (ImageEntry)
250  {
251  // addr in in range of image
252  ImageBase = (C_PTR)ImageEntry->ImageBase;
253  ImageSize = ImageEntry->ImageSize;
254  }
255 
256  // check if there was a change in the values
257  if (TempAddr != gEFITables[i].last_addr)
258  {
259  change = 1;
260 
261  LogFileAscii("[%04d] Modification detected OldAddr=%016lx NewAddr=%016lx Function Name: %a\r\n",
262  i,
263  (MAX_PTR)gEFITables[i].last_addr,
264  (MAX_PTR)TempAddr,
265  p);
266 
267 
268  if (!SilentMode)
269  {
270  PRINT_FUNC_ASCII("[%04d] Modification detected OldAddr=%016lx NewAddr=%016lx Function Name: %a\r\n",
271  i,
272  (MAX_PTR)gEFITables[i].last_addr,
273  (MAX_PTR)TempAddr,
274  p);
275  }
276 
277  }
278 
279  if (!SilentMode)
280  {
281  WasHooked = FALSE;
282 
283  // on mac mini QueryCapsuleCapabilities/CreateEventEx is invalid therefore probing it
284  // will cause an access violation
285  // lets assume on x64 that every address above 4gb is not valid
286 
287 #if defined(_WIN64)
288  if ((ULONG32)(gEFITables[i].last_addr >> 32))
289  LogFullAscii("Addr: %016lx is probably invalid!\r\n", gEFITables[i].last_addr);
290  else
291  WasHooked = IsFunctionHooked(gEFITables[i].last_addr);
292 #else
293  WasHooked = IsFunctionHooked(gEFITables[i].last_addr);
294 #endif
295 
296  LogFullAscii("[%04d] Addr: %016lx M: %d InImage: %016lx-%016lx Function Name: %a \r\n",
297  i,
298  (MAX_PTR)TempAddr,
299  change,
300  (MAX_PTR)ImageBase, (
301  MAX_PTR)(ImageBase + ImageSize),
302  p);
303 
304  if (WasHooked)
305  {
306  // at this point we only know that the function prologue contains
307  // a long rel jump or a rel call
308  // so lets check the destination of it as well
309 
310  HookDest = (ULONG32)(*(INT32*)(gEFITables[i].last_addr + 1) + gEFITables[i].last_addr + 5);
311  HookDestImageEntry = FindImageByAddr(ImageList, HookDest);
312 
313  // function is hooked when HookDestImageEntry = 0 or it points to
314  // an image different from the current image
315  if (!HookDestImageEntry)
316  LogFullAscii("Function %016lx is hooked to %016lx (not in image)\r\n",
317  (MAX_PTR)gEFITables[i].last_addr,
318  (MAX_PTR)HookDest);
319  else if (HookDestImageEntry != ImageEntry)
320  LogFullAscii("Function %016lx is hooked to %016lx (image base=%016lx)\r\n",
321  (MAX_PTR)gEFITables[i].last_addr,
322  (MAX_PTR)HookDest,
323  (MAX_PTR)HookDestImageEntry->ImageBase);
324  }
325  }
326  else if (change == 1)
327  {
328  // we are now in timmer so we log only this modified entry
329 
330  LogFileAscii("[%04d] Addr: %016lx M: %d InImage: %016lx-%016lx Function Name: %a \r\n",
331  i,
332  (MAX_PTR)TempAddr,
333  change,
334  (MAX_PTR)ImageBase,
335  (MAX_PTR)(ImageBase + ImageSize),
336  p);
337 
338 
339  // update the last addr, because otherwise the log will be flooded
340  // with the same information (because of the timer)
341 
342  gEFITables[i].last_addr = TempAddr;
343 
344  }
345 
346  }
347 
348  if (!SilentMode)
349  LogFullAscii(": Dumping EFI Functions tables done.\r\n");
350 
351  return EFI_SUCCESS;
352 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpEvents ( BOOLEAN  WriteToTable,
BOOLEAN  SilentMode 
)
EFI_STATUS DumpFirmwareFromROM ( VOID  )

Function dumps firmware from ROM to file (mdump\firmware.dmp). The ROM address is constant and it is described by BIOS_ROM_BASE. Typically the size of firmware is smaller than (BIOS_ROM_END-BIOS_ROM_BASE) but in this case we have just decided to dump more.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 259 of file DumpMem.c.

References BIOS_ROM_BASE, BIOS_ROM_END, DumpMemoryToFile(), EFI_STATUS(), and LogFullAscii().

Referenced by DrawBoxAndMenu().

260 {
261  EFI_STATUS Status;
262  CHAR16 DmpFilePath[512];
263 
264 
265  UnicodeSPrint(DmpFilePath, sizeof(DmpFilePath)-1, L"mdump\\firmware.dmp");
266 
267 
268 #if DEBUG_ON == 1
269  LogFullAscii("%a: Dumping to %s (BiosRomBase=%08x BiosRomEnd=%08x)\r\n",
270  __FUNCTION__, DmpFilePath, BIOS_ROM_BASE, BIOS_ROM_END);
271 #endif
272 
273 
274  Status = DumpMemoryToFile((C_PTR)BIOS_ROM_BASE, (UINTN)(BIOS_ROM_END - BIOS_ROM_BASE), DmpFilePath, TRUE);
275  if (EFI_ERROR(Status))
276  return Status;
277 
278 
279 #if DEBUG_ON == 1
280  LogFullAscii("%a: memory dumped correctly.\r\n", __FUNCTION__);
281 #endif
282 
283  return EFI_SUCCESS;
284 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpGDT ( VOID  )

Functions dump the GDT. (even on x64 efi platform the GDT entries are not extended - meaning the GDT format stays the same)

Return values
EFI_SUCCESS

Definition at line 56 of file IdtGdt.c.

References ASMGetGdtBase(), ASMGetGdtLimit(), _gdt_entry::Base0, _gdt_entry::Base1, _gdt_entry::Base2, _gdt_entry::DPL, _gdt_entry::LimitHigh, _gdt_entry::LimitLow, LogFullAscii(), _gdt_entry::Present, _gdt_entry::s, _gdt_entry::System, and _gdt_entry::Type.

Referenced by DrawBoxAndMenu(), ProcessCommand(), and TestDumpHandles().

57 {
58  UINTN i;
59  UINT_ARCH GdtBase, EntryBase;
60  USHORT GdtLimit;
61  ULONG EntryLimit;
62  gdt_entry *GdtEntry;
63 
64  GdtBase = ASMGetGdtBase();
65  GdtLimit = ASMGetGdtLimit();
66 
67  LogFullAscii("DumpGDT: base = %016lx Limit=%04x GdEntrySize=%x\r\n",
68  (MAX_PTR)GdtBase,
69  GdtLimit,
70  sizeof(gdt_entry));
71 
72  GdtEntry = (gdt_entry*)GdtBase;
73  for (i = 0; i < (GdtLimit/sizeof(gdt_entry)); i++, GdtEntry++)
74  {
75 
76  EntryBase = GdtEntry->s.Base0 | (GdtEntry->s.Base1 << 16) | (GdtEntry->s.Base2 << 24);
77  EntryLimit = GdtEntry->s.LimitLow | (GdtEntry->s.LimitHigh << 16);
78 
79 
80  LogFullAscii("%04d : base=%08x limit=%08x System=%02d DPL=%02d Present=%02d type=(%03d)%a\r\n",
81  i,
82  EntryBase,
83  EntryLimit,
84  GdtEntry->s.System,
85  GdtEntry->s.DPL,
86  GdtEntry->s.Present,
87  GdtEntry->s.Type,
88  &GdtTypeText[GdtEntry->s.Type]);
89 
90 
91  }
92 
93  return EFI_SUCCESS;
94 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpIDT ( VOID  )

Functions dump the IDT. This function works with both x86 and x64. (on x64 the idt base calulation algo changes)

Return values
EFI_SUCCESS

Definition at line 191 of file IdtGdt.c.

References ASMGetIdtBase(), ASMGetIdtLimit(), idt_entry::Dpl, IDT_GET_BASE, LogFullAscii(), idt_entry::Present, idt_entry::SegmentSelector, and idt_entry::Type.

Referenced by DrawBoxAndMenu(), ProcessCommand(), and TestDumpHandles().

192 {
193 
194  UINTN i;
195  UINT_ARCH IdtBase, EntryBase;
196  USHORT IdtLimit;
197  idt_entry *IdtEntry;
198 
199  IdtBase = ASMGetIdtBase();
200  IdtLimit = ASMGetIdtLimit();
201 
202  IdtEntry = (idt_entry*)IdtBase;
203 
204 
205  LogFullAscii("%a: base = %016lx Limit=%04x GdEntrySize=%x\r\n",
206  __FUNCTION__,
207  (MAX_PTR)IdtBase,
208  IdtLimit,
209  sizeof(idt_entry));
210 
211 
212  for (i = 0; i < (IdtLimit/sizeof(idt_entry)); i++, IdtEntry++)
213  {
214 
215  EntryBase = IDT_GET_BASE(IdtEntry);
216 
217  LogFullAscii("%04d : base=%016lx Selector=%04x DPL=%02d Present=%02d Type=%04x\r\n",
218  i,
219  (MAX_PTR)EntryBase,
220  IdtEntry->SegmentSelector,
221  IdtEntry->Dpl,
222  IdtEntry->Present,
223  IdtEntry->Type);
224 
225  }
226 
227 
228 
229  return EFI_SUCCESS;
230 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpImageToDisk ( image_entry *  ImageEntry)

Function dumps selected image to disk (to "dump\ImageBase.dmp")

Parameters
ImageEntryPointer to the image entry which will be dumped
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 869 of file Images.c.

References DumpMemoryToFile(), _image_entry::ImageBase, _image_entry::ImageSize, and LogFullAscii().

Referenced by DumpAllImages().

870 {
871  CHAR16 DmpFilePath[512];
872 
873  //
874  // warning: do not exceed the filename length (openfile will return error)
875  //
876 
877  UnicodeSPrint(DmpFilePath, sizeof(DmpFilePath)-1, L"dump\\%p.dmp",
878  ImageEntry->ImageBase);
879 
880 
881 #if DEBUG_ON == 1
882  LogFullAscii("%a: Dumping to %s (size=%08x)\r\n",
883  __FUNCTION__,
884  DmpFilePath,
885  ImageEntry->ImageSize);
886 #endif
887 
888  return DumpMemoryToFile((C_PTR)ImageEntry->ImageBase,
889  (UINTN)ImageEntry->ImageSize,
890  DmpFilePath,
891  TRUE);
892 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpMemoryMap ( memory_map_entry_list *  MemMap,
BOOLEAN  DumpToDisk,
UINT32  SkipType 
)

Function displays and dump the memory map.

Parameters
MemMapPointer to memory map obtained from GetMemoryMapList
DumpToDiskInidicates whether the data will be dumped to disk
SkipTypeTypes of memory that will be not included in the disk dump
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 381 of file MemoryMap.c.

References _memory_map_entry::Attributes, DumpGcdMemoryMap(), DumpMemoryToFile(), GetMemAttributesStringAscii(), LogFullAscii(), _memory_map_entry_list::MapKey, memory_types, _memory_map_entry_list::MemoryMapEntry, _memory_map_entry::NumberOfPages, _memory_map_entry_list::NumOfEntries, _memory_map_entry::PhysicalStart, _memory_map_entry::Type, and _memory_map_entry::VirtualStart.

Referenced by CommandMemInfo(), and DrawBoxAndMenu().

384 {
385  UINTN i;
386  CHAR8 Attributes[256];
387  CHAR16 DmpFilePath[512];
388 
389  memory_map_entry *MapEntry;
390 
391  if (!MemMap)
392  return EFI_NOT_FOUND;
393 
394  LogFullAscii("--- BEGINING MEMORY MAP DUMP ---\r\n");
395  LogFullAscii("MapKey: %08x NumOfEntries=%08x\r\n", MemMap->MapKey, MemMap->NumOfEntries);
396 
397  for (i = 0; i < MemMap->NumOfEntries; i++)
398  {
399  MapEntry = &MemMap->MemoryMapEntry[i];
400 
401  GetMemAttributesStringAscii(Attributes, sizeof(Attributes), MapEntry->Attributes);
402 
403  LogFullAscii("%08d: PhysStart=%016lx PhysEnd=%016lx NumOfPages=%08llx VirtualStart=%016lx Attributes=%016lx (%a) Type=%08x (%a)\r\n",
404  i,
405  MapEntry->PhysicalStart,
406  MapEntry->PhysicalStart + EFI_PAGES_TO_SIZE(MapEntry->NumberOfPages),
407  MapEntry->NumberOfPages,
408  MapEntry->VirtualStart,
409  MapEntry->Attributes,
410  Attributes,
411  MapEntry->Type,
412  memory_types[MapEntry->Type]);
413 
414 
415 #if USE_DXE_SERVICES == 1
416  LogFullAscii("%08d: GcdLength=%08llx GcdMemoryType=%08x GcdBaseAddr=%016lx ImageHandle=%08x\r\n",
417  i,
418  MapEntry->Length,
419  MapEntry->GcdMemoryType,
420  MapEntry->BaseAddress,
421  MapEntry->ImageHandle);
422 #endif
423 
424  if (DumpToDisk)
425  {
426 
427  //"mdump\\%08x.dmp"
428  UnicodeSPrint(DmpFilePath, sizeof(DmpFilePath)-1, L"mdump\\%p.dmp",
429  MapEntry->PhysicalStart);
430 
431  LogFullAscii("%a: dumping to: %s \r\n", __FUNCTION__, DmpFilePath);
432 
433  // remember we always skip ReservedType (value = 0) if SkipType!=0
434  if (SkipType && ((MapEntry->Type == SkipType) || (MapEntry->Type == 0)))
435  {
436  LogFullAscii("%a: not dumping this entry to disk (type skipped)\r\n",
437  __FUNCTION__);
438  continue;
439  }
440 
441 
442  // dump it to file
444  (UINTN)EFI_PAGES_TO_SIZE(MapEntry->NumberOfPages),
445  DmpFilePath,
446  FALSE);
447 
448  } // if dump to disk
449  } // for map entry
450 
451 
452 #if USE_DXE_SERVICES == 1
454 #endif
455 
456  return EFI_SUCCESS;
457 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpMemoryToFile ( C_PTR  Address,
UINTN  Size,
CHAR16 *  FilePath,
BOOLEAN  UseProxy 
)

Function dumps memory from Address to (Address + Size) to file.

If UseProxy is set to TRUE then before we will execute File->Write the source memory will be copied to our newly allocated buffer. This decreases the performance but on the other hand it increases the stability. On real systems for example when you are trying to dump images from memory and you want to do this directly (without the memory proxy) your machine will often freeze. Obviously in some cases this method will not work due to the gigantic Size parameter. Additionally maybe we should disable this option when doing a full memory dump (just to keep the memory layout intact).

Parameters
AddressAddress inidicating memory to dump
SizeSize of memory to dump
FilePathPointer to file path (unicode)
UseProxyShould we copy the source to our memory firstly
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 174 of file Memory.c.

References EFI_STATUS(), LogFullAscii(), MemAllocate(), MemCopy(), MemFree(), and OpenFile().

Referenced by CommandDumpMem(), DumpFirmwareFromROM(), DumpImageToDisk(), DumpMemoryMap(), DumpPEFile(), DumpTEFile(), and hooked_LoadImage().

178 {
179  EFI_STATUS Status;
180  EFI_FILE_PROTOCOL *File;
181  UINTN SizeCopy;
182  UCHAR *Mem;
183 
184  if ((FilePath == 0) || (Size == 0))
185  return EFI_NOT_FOUND;
186 
187  // create destination file
188  Status = OpenFile(FilePath,
189  EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE,
190  &File);
191 
192  if (EFI_ERROR(Status))
193  {
194 
195 #if DEBUG_ON == 1
196  LogFullAscii("%a: unable to create dump file, status = %08x\r\n",
197  __FUNCTION__, Status);
198 #endif
199 
200  // after EFI_DEVICE_ERROR all the file system operations are not working
201  if (Status == EFI_DEVICE_ERROR)
202  LogFullAscii("%a: OpenFile returned EFI_DEVICE_ERROR (FATAL), trying to reset!\r\n",
203  __FUNCTION__);
204 
205  return Status;
206  }
207 
208 #if DEBUG_ON == 1
209  LogFullAscii("%a: writing %08x bytes\r\n", __FUNCTION__, Size);
210 #endif
211 
212  SizeCopy = Size;
213 
214  if (UseProxy)
215  {
216  // allocate memory and copy the data there firstly
217  Mem = (UCHAR*)MemAllocate(Size);
218  if (Mem)
219  {
220 #if DEBUG_ON == 1
221  LogFullAscii("%a: storing to mem firstly Mem=%p\r\n", __FUNCTION__, Mem);
222 #endif
223 
224  MemCopy((VOID*)Mem, (VOID*)Address, Size);
225  Status = File->Write(File, &SizeCopy, (VOID*)Mem);
226  File->Close(File);
227  MemFree(Mem);
228 
229 
230  if (EFI_ERROR(Status))
231  {
232 #if DEBUG_ON == 1
233  LogFullAscii("%a: Error writing to file failed, status = %08x\r\n",
234  __FUNCTION__, Status);
235 #endif
236  return Status;
237  }
238 
239 
240 #if DEBUG_ON == 1
241  LogFullAscii("%a: region %016lx-%016lx (size=%08x) dumped (written %08x bytes)\r\n",
242  __FUNCTION__,
243  (MAX_PTR)Address,
244  (MAX_PTR)(Address + Size),
245  Size,
246  SizeCopy);
247 #endif
248 
249  return EFI_SUCCESS;
250  }
251  }
252 
253 #if DEBUG_ON == 1
254  LogFullAscii("%a: using direct read mode\r\n", __FUNCTION__);
255 #endif
256 
257  Status = File->Write(File, &SizeCopy, (VOID*)Address);
258  File->Close(File);
259 
260  if (EFI_ERROR(Status))
261  {
262 #if DEBUG_ON == 1
263  LogFullAscii("%a: Error writing to file failed, status = %08x\r\n",
264  __FUNCTION__, Status);
265 #endif
266  return Status;
267  }
268 
269 
270 #if DEBUG_ON == 1
271  LogFullAscii("%a: region %016lx-%016lx (size=%08x) dumped (written %08x bytes)\r\n",
272  __FUNCTION__,
273  (MAX_PTR)Address,
274  (MAX_PTR)(Address + Size),
275  Size,
276  SizeCopy);
277 #endif
278 
279  return EFI_SUCCESS;
280 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpPEFile ( C_PTR  BaseAddr)

Function dumps Portable Executable file to file. (by default "bdump\ADDR.dmp")

Parameters
BaseAddrAddress to the located Portable Executable file in memory.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 30 of file DumpMem.c.

References DumpMemoryToFile(), EFI_IMAGE_DOS_HEADER::e_lfanew, EFI_IMAGE_NT_SIGNATURE, LogFullAscii(), MAX_PE_MEM, EFI_IMAGE_NT_HEADERS64::OptionalHeader, EFI_IMAGE_NT_HEADERS64::Signature, and EFI_IMAGE_OPTIONAL_HEADER64::SizeOfImage.

Referenced by ScanMemoryForExecutables().

31 {
32 
35  UINTN Size;
36  VOID *Mem;
37 
38  CHAR16 DmpFilePath[512];
39  CHAR8 *p;
40 
41  Mem = (VOID*)BaseAddr;
42 
43 #if DEBUG_ON == 1
44  LogFullAscii("%a: trying to dump %016lx.\r\n", __FUNCTION__, (MAX_PTR)BaseAddr);
45 #endif
46 
47 
48  pMZ = (EFI_IMAGE_DOS_HEADER*)Mem;
49 
50  if (pMZ->e_lfanew >= (MAX_PE_MEM/2))
51  {
52  LogFullAscii("%a: error invalid e_lfanew.\r\n", __FUNCTION__);
53  return EFI_NOT_FOUND;
54  }
55 
56  pPE = (EFI_IMAGE_NT_HEADERS64*)((C_PTR)Mem + pMZ->e_lfanew);
57  p = (CHAR8*)((C_PTR)Mem + pMZ->e_lfanew);
58 
60  {
61 #if DEBUG_ON == 1
62  LogFullAscii("%a: error invalid PE signature.\r\n", __FUNCTION__);
63 #endif
64 
65  return EFI_NOT_FOUND;
66  }
67 
68  // check the image size now
69  if (((BaseAddr + pPE->OptionalHeader.SizeOfImage) < BaseAddr) ||
70  (pPE->OptionalHeader.SizeOfImage == 0))
71  {
72 #if DEBUG_ON == 1
73  LogFullAscii("%a: error invalid size of image.\r\n", __FUNCTION__);
74 #endif
75 
76  return EFI_NOT_FOUND;
77  }
78 
79 
80  // everything seems to be ok, lets dump it
81  Size = pPE->OptionalHeader.SizeOfImage;
82 
83  //
84  // warning: do not exceed the filename length (openfile will return error)
85  //
86 
87  UnicodeSPrint(DmpFilePath, sizeof(DmpFilePath)-1, L"bdump\\%p.dmp", BaseAddr);
88 
89 #if DEBUG_ON == 1
90  LogFullAscii("%a: Dumping to %s (ImageSize=%08x)\r\n",
91  __FUNCTION__, DmpFilePath, Size);
92 #endif
93 
94  // dump the file
95  DumpMemoryToFile(BaseAddr, Size, DmpFilePath, FALSE);
96 
97 
98 #if DEBUG_ON == 1
99  LogFullAscii("%a: memory dumped correctly.\r\n", __FUNCTION__);
100 #endif
101 
102  return EFI_SUCCESS;
103 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpTEFile ( C_PTR  BaseAddr)

Function dumps TE file to file. (by default "bdump\ADDR.dmp")

Parameters
BaseAddrAddress to the located TE file in memory.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 29 of file Te.c.

References DumpMemoryToFile(), EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, LogFullAscii(), TE_IMAGE_HEADER::NumberOfSections, TE_IMAGE_HEADER::Signature, EFI_IMAGE_SECTION_HEADER::SizeOfRawData, TE_IMAGE_HEADER::Subsystem, and TE_SIGNATURE.

Referenced by ScanMemoryForExecutables().

30 {
31  CHAR16 DmpFilePath[512];
32  TE_IMAGE_HEADER *TEHeader;
34  UINT32 Size;
35  UINTN i;
36 
37 
38  TEHeader = (TE_IMAGE_HEADER*)BaseAddr;
39 
40 
41 #if DEBUG_ON == 1
42  LogFullAscii("%a: trying to dump %016lx.\r\n", __FUNCTION__, (MAX_PTR)BaseAddr);
43 #endif
44 
45 
46  if (TEHeader->Signature != TE_SIGNATURE)
47  {
48 #if DEBUG_ON == 1
49  LogFullAscii("%a: invalid TE file signature at %016lx, sig = %08x\r\n",
50  __FUNCTION__, (MAX_PTR)BaseAddr, TEHeader->Signature);
51 #endif
52  return EFI_NOT_FOUND;
53  }
54 
55 
56  // add some additional checks for subsystem
57  // (it should be EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) but
58  // lets write down all the possibilities
59 
62  {
63 #if DEBUG_ON == 1
64  LogFullAscii("%a: invalid TE subsystem %d\r\n",
65  __FUNCTION__, TEHeader->Subsystem);
66 #endif
67  return EFI_NOT_FOUND;
68  }
69 
70 
71  // calculate total size
72  Size = sizeof(TE_IMAGE_HEADER) +
73  ((sizeof(EFI_IMAGE_SECTION_HEADER)*TEHeader->NumberOfSections)) + 16; // (plus pad)
74 
75 
76  TESec = (EFI_IMAGE_SECTION_HEADER*)(BaseAddr + sizeof(TE_IMAGE_HEADER));
77 
78  for (i = 0; i < TEHeader->NumberOfSections; i++, TESec++)
79  Size += TESec->SizeOfRawData;
80 
81  // at this point maybe it would be nice to check the correctness
82  // of the format. on the other hand everyone who can load
83  // their image on the UEFI system has a total control of the
84  // system, so it is kinda not necessary
85 
86 
87  UnicodeSPrint(DmpFilePath, sizeof(DmpFilePath)-1, L"bdump\\%p.dmp", BaseAddr);
88 
89 #if DEBUG_ON == 1
90  LogFullAscii("%a: Dumping to %s (CalculatedSize=%08x)\r\n",
91  __FUNCTION__, DmpFilePath, Size);
92 #endif
93 
94  // dump the file
95  DumpMemoryToFile(BaseAddr, Size, DmpFilePath, FALSE);
96 
97 
98 #if DEBUG_ON == 1
99  LogFullAscii("%a: TE memory dumped correctly.\r\n", __FUNCTION__);
100 #endif
101 
102 
103  return EFI_SUCCESS;
104 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS EFIAPI EfiScannerInitialize ( EFI_HANDLE  ImageHandle,
BOOLEAN  OpUsePrint,
BOOLEAN  OpUseLog,
BOOLEAN  OpUseComPort 
)

Initializes the gEfiScannerPolicy. This function must be executed before any other function of RDFU framework.

Parameters
ImageHandleImage handle
OpUsePrintPrint output to screen
OpUseLogPrint output to log file (log.txt)
OpUseComPortPrint output to com port (COM1 by default)
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 42 of file EfiScannerLib.c.

References ASMInitLock(), EFI_STATUS(), gLogLock, gSelfLoadedImage, InitializeLogFile(), LogFullAscii(), _policy::NumOfBadAddrs, _policy::OpUseComPort, _policy::OpUseLog, _policy::OpUsePrint, and PRINT_FUNC.

Referenced by EfiScannerEntryPoint().

47 {
48  EFI_STATUS Status;
49 
50  // disable watchdog time (for apple)
51  gBS->SetWatchdogTimer(0, 0, 0, 0);
52 
54 
56  gEfiScannerPolicy.OpUseLog = OpUseLog;
57  gEfiScannerPolicy.OpUsePrint = OpUsePrint;
58  gEfiScannerPolicy.OpUseComPort = OpUseComPort;
59 
60  Status = gBS->HandleProtocol(ImageHandle,
61  &gEfiLoadedImageProtocolGuid,
62  (VOID*)&gSelfLoadedImage);
63 
64  if (EFI_ERROR(Status))
65  {
66 #if DEBUG_ON == 1
67  PRINT_FUNC(L"EfiScannerInitialize: Error unable to locate protocol! \r\n");
68 #endif
69  return Status;
70  }
71 
72  Status = InitializeLogFile();
73 
74  if (EFI_ERROR(Status))
75  {
76 #if DEBUG_ON == 1
77  PRINT_FUNC(L"EfiScannerInitialize: InitializeLogFile returned %08x\r\n", Status);
78 #endif
79 
80  return Status;
81  }
82 
83 
84  LogFullAscii("EfiScannerInitialize: Scanner initialized (UseLog=%d | UsePrint=%d | UseComPort=%d)\r\n",
85  OpUseLog,
86  OpUsePrint,
87  OpUseComPort);
88 
89  return EFI_SUCCESS;
90 }

Here is the call graph for this function:

Here is the caller graph for this function:

C_PTR EFITableGetAddr ( CHAR8 *  FuncName)

Function gets addr of selected function (search is done by function name case sensitive);

Return values
AddrOn success
NULLOn error

Definition at line 398 of file TableMonitor.c.

References _func_table::last_addr, and _func_table::name.

Referenced by CommandFunction().

399 {
400  UINTN i;
401 
402  if (!FuncName)
403  return 0;
404 
405  for (i = 0; gEFITables[i].name[0] != '?'; i++)
406  {
407  if (strcmp(gEFITables[i].name, FuncName) == 0)
408  return gEFITables[i].last_addr;
409  }
410 
411  return 0;
412 }

Here is the caller graph for this function:

event_entry* FindEventByAddr ( event_entry_list *  EventList,
C_PTR  Address 
)

Function finds event entry in the events list by address of the notify function.

Parameters
EventListPointer to the event list gathered from GetAllEvents function
AddressAddress of wanted notify function
Return values
PointerOn success function returns pointer to the located event_entry
NULLOn error

Definition at line 531 of file Events.c.

References _event_entry_list::EventEntry, IEVENT::NotifyFunction, and _event_entry_list::NumOfEntries.

Referenced by CommandEventInfo(), and NotifyEventScannerTimer().

532 {
533 
534  UINTN i;
535  event_entry *EventEntry;
536 
537  if (!EventList)
538  return 0;
539 
540  for (i = 0; i < EventList->NumOfEntries; i++)
541  {
542  EventEntry = &EventList->EventEntry[i];
543 
544  if ((C_PTR)EventEntry->NotifyFunction == Address)
545  return EventEntry;
546  }
547 
548  return 0;
549 }

Here is the caller graph for this function:

image_entry* FindImageByAddr ( image_entry_list *  ImageList,
C_PTR  Address 
)

Function finds image entry in the image list by address. Function checks if the selected address points somewhere inside the image body.

Parameters
ImageListPointer to the image list gathered from GetAllImagesWithDescription function
AddressAddress of wanted image (doesn't have to be exact image base)
Return values
PointerOn success function returns pointer to the located image_entry
NULLOn error

Definition at line 804 of file Images.c.

References _image_entry::ImageBase, _image_entry_list::ImageEntry, _image_entry::ImageSize, and _image_entry_list::NumOfEntries.

Referenced by BruteFind_gEventSignalQueueAddr(), CommandDriverInfo(), DumpAllEvents(), DumpEFITables(), and ScanMemoryForExecutables().

806 {
807  UINTN i;
808  image_entry *ImageEntry;
809 
810  if (!ImageList)
811  return 0;
812 
813  for (i = 0; i < ImageList->NumOfEntries; i++)
814  {
815  ImageEntry = &ImageList->ImageEntry[i];
816 
817  if ((Address >= (C_PTR)ImageEntry->ImageBase) &&
818  (Address < ((C_PTR)ImageEntry->ImageBase + ImageEntry->ImageSize)))
819  return ImageEntry;
820  }
821 
822  return 0;
823 }

Here is the caller graph for this function:

image_entry* FindImageByHandle ( image_entry_list *  ImageList,
EFI_HANDLE  Handle 
)

Function finds image entry in the image list by handle value

Parameters
ImageListPointer to the image list gathered from GetAllImagesWithDescription function
HandleValue of wanted handle
Return values
PointerOn success function returns pointer to the located image_entry
NULLOn error

Definition at line 838 of file Images.c.

References _image_entry::Handle, _image_entry_list::ImageEntry, and _image_entry_list::NumOfEntries.

Referenced by NotifyExitBootServices().

840 {
841  UINTN i;
842  image_entry *ImageEntry;
843 
844  if (!ImageList)
845  return 0;
846 
847  for (i = 0; i < ImageList->NumOfEntries; i++)
848  {
849  ImageEntry = &ImageList->ImageEntry[i];
850 
851  if (ImageEntry->Handle == Handle)
852  return ImageEntry;
853  }
854 
855  return 0;
856 }

Here is the caller graph for this function:

memory_map_entry* FindMapEntryByAddr ( memory_map_entry_list *  MemMap,
EFI_PHYSICAL_ADDRESS  Address 
)

Function finds memory map entry in the memory map list by address. Function checks if the selected address points somewhere inside the map memory entry range.

Parameters
MemMapPointer to the memory map
AddressMemory address
Return values
PointerOn success function returns pointer to the located image_entry
NULLOn error

Definition at line 343 of file MemoryMap.c.

References _memory_map_entry_list::MemoryMapEntry, _memory_map_entry::NumberOfPages, _memory_map_entry_list::NumOfEntries, and _memory_map_entry::PhysicalStart.

Referenced by CommandMemInfo().

345 {
346  UINTN i;
347  memory_map_entry *MapEntry;
348  EFI_PHYSICAL_ADDRESS PhysEnd;
349 
350 
351  if (!MemMap)
352  return 0;
353 
354  for (i = 0; i < MemMap->NumOfEntries; i++)
355  {
356  MapEntry = &MemMap->MemoryMapEntry[i];
357  PhysEnd = MapEntry->PhysicalStart + EFI_PAGES_TO_SIZE(MapEntry->NumberOfPages);
358 
359  if ((Address >= MapEntry->PhysicalStart) && (Address < PhysEnd))
360  return MapEntry;
361 
362  }
363 
364  return 0;
365 }

Here is the caller graph for this function:

VOID FreeEvents ( event_entry_list *  EventList)

Function frees the event list

Parameters
EventListPointer to the event list gathered from GetAllEvents function
Return values
NONE

Definition at line 563 of file Events.c.

References _event_entry_list::EventEntry, and MemFree().

Referenced by CommandEventInfo(), DrawBoxAndMenu(), and UnInstallEventScanner().

564 {
565  MemFree(EventList->EventEntry);
566  MemFree(EventList);
567 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID FreeHandles ( handle_entry_list *  HandleList)

Function frees the handle list

Parameters
HandleListPointer to the handle list gathered from GetAllHandlesWithDescription function
Return values
NONE

Definition at line 400 of file Images.c.

References _handle_entry_list::HandleEntry, and MemFree().

Referenced by DrawBoxAndMenu(), GetAllImagesWithDescription(), and TestDumpHandles().

401 {
402  MemFree(HandleList->HandleEntry);
403  MemFree(HandleList);
404 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID FreeImages ( image_entry_list *  ImageList)

Function frees the image list

Parameters
ImageListPointer to the image list gathered from GetAllImagesWithDescription function
Return values
NONE

Definition at line 1051 of file Images.c.

References CloseLoadedImageProtocol(), _image_entry::Handle, _image_entry_list::ImageEntry, _image_entry::LoadedImageProtocol, MemFree(), and _image_entry_list::NumOfEntries.

Referenced by BruteFind_gEventSignalQueueAddr(), CommandDriverInfo(), DrawBoxAndMenu(), DumpAllEvents(), InstallSniffImage(), NotifyExitBootServices(), ScanMemoryForExecutables(), TestDumpHandles(), and UnInstallSniffImage().

1052 {
1053  UINTN i;
1054  image_entry *ImageEntry;
1055 
1056  for (i = 0; i < ImageList->NumOfEntries; i++)
1057  {
1058  ImageEntry = &ImageList->ImageEntry[i];
1059 
1060  if (ImageEntry->LoadedImageProtocol)
1061  CloseLoadedImageProtocol(ImageEntry->Handle);
1062  }
1063 
1064  MemFree(ImageList->ImageEntry);
1065  MemFree(ImageList);
1066 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID FreeMemMap ( memory_map_entry_list *  MemMap)

Function displays the GCD memory map obtained through GetMemorySpaceMap. This function is only available in DXE drivers due to DxeServicesTableLib requirements.

Parameters
MemMapPointer to memory map obtained from GetMemoryMapList

Definition at line 270 of file MemoryMap.c.

References MemFree(), and _memory_map_entry_list::MemoryMapEntry.

Referenced by CommandMemInfo(), and DrawBoxAndMenu().

271 {
272  MemFree(MemMap->MemoryMapEntry);
273  MemFree(MemMap);
274 }

Here is the call graph for this function:

Here is the caller graph for this function:

event_entry_list* GetAllEvents ( VOID  )

Function is responsible for gathering all events from the queue. Unfortunatelly it may be vulnerable to the race condition since we haven't takedovered the original spinlock. In other words we are forced to use the gEventSignalQueueAddr without synchronization.

EFI events are constructs that are used to provide communication between EFI modules.

The event_entry_list returned by this function must be freed by the FreeEvents function.

Return values
PointerOn success pointer to event_entry_list
NULLOn error

Definition at line 448 of file Events.c.

References EVENT_SIGNATURE, _event_entry_list::EventEntry, gEventSignalQueueAddr, IsEventSignalQueueAddrResolved(), LogFullAscii(), MemAllocate(), MemCopy(), MemFree(), _event_entry_list::NumOfEntries, and IEVENT::Signature.

Referenced by CommandEventInfo(), DrawBoxAndMenu(), InstallEventScanner(), and TestDumpHandles().

449 {
450  event_entry_list *EventList;
451  event_entry *EventEntry;
452 
453  IEVENT *Event;
454  LIST_ENTRY *Head;
455  LIST_ENTRY *Link;
456 
457 
458  UINTN i, NumOfEvents;
459 
461  return 0;
462 
463 
464  // firstly calculate the number of IEVENTs structures
465  NumOfEvents = 0;
466  Head = (LIST_ENTRY*)gEventSignalQueueAddr;
467 
468  // check the event signature
469  Link = Head->ForwardLink;
470  Event = CR(Link, IEVENT, SignalLink, EVENT_SIGNATURE);
471 
472  if (Event->Signature != EVENT_SIGNATURE)
473  {
474 #if DEBUG_ON == 1
475  LogFullAscii("%a: invalid Event signature %08x -> %08x\r\n",
476  __FUNCTION__, Event->Signature, EVENT_SIGNATURE);
477 #endif
478  return 0;
479  }
480 
481  for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink)
482  NumOfEvents++;
483 
484 
485  //LogFullAscii("GetAllEvents: Event signature %08x -> %08x | NumOfEvents=%d \r\n",
486  // Event->Signature, EVENT_SIGNATURE, NumOfEvents);
487 
488 
489  // allocate memory
490  EventList = (event_entry_list*)MemAllocate(sizeof(event_entry_list));
491  if (!EventList)
492  return 0;
493 
494  EventEntry = (event_entry*)MemAllocate((NumOfEvents+1)*sizeof(event_entry));
495  if (!EventEntry)
496  {
497  MemFree(EventList);
498  return 0;
499  }
500 
501  for (i = 0, Link = Head->ForwardLink; ((Link != Head) && (i < NumOfEvents));
502  Link = Link->ForwardLink, i++)
503  {
504  Event = CR(Link, IEVENT, SignalLink, EVENT_SIGNATURE);
505 
506  // copy each event structure (ievent == event_entry)
507  MemCopy(&EventEntry[i], Event, sizeof(IEVENT));
508  }
509 
510  EventList->NumOfEntries = NumOfEvents;
511  EventList->EventEntry = EventEntry;
512 
513 
514  return EventList;
515 }

Here is the call graph for this function:

Here is the caller graph for this function:

handle_entry_list* GetAllHandlesWithDescription ( VOID  )

Function is responsible for gathering all system handles. Requestor is responsible for deallocating the memory through FreeHandles function.

Return values
PointerOn success pointer to handle_entry_list
NULLOn error

Definition at line 419 of file Images.c.

References EFI_STATUS(), GetAllHandles(), _handle_entry::Handle, _handle_entry_list::HandleEntry, LogFullAscii(), MemAllocate(), MemFree(), _handle_entry_list::NumOfEntries, setHANDLE_TYPE_COMPONENT_NAME_HANDLE(), setHANDLE_TYPE_DEVICE_HANDLE(), setHANDLE_TYPE_DRIVER_BINDING_HANDLE(), setHANDLE_TYPE_DRIVER_CONFIGURATION_HANDLE(), setHANDLE_TYPE_DRIVER_DIAGNOSTICS_HANDLE(), and setHANDLE_TYPE_IMAGE_HANDLE().

Referenced by DrawBoxAndMenu(), GetAllImagesWithDescription(), and TestDumpHandles().

420 {
421  UINTN i, MemSize;
422  EFI_STATUS Status;
423  EFI_HANDLE *AllHandles;
424 
425  EFI_GUID **ProtocolGuidArray;
426  UINTN ProtoArrayCount;
427  UINTN ProtoIndex;
428 
429  handle_entry_list *HandleList;
430  handle_entry *HandleEntry;
431 
432 
433  Status = GetAllHandles(&AllHandles);
434 
435  if (EFI_ERROR(Status))
436  {
437 #if DEBUG_ON == 1
438  LogFullAscii("%a: calling GetAllHandles() failed\r\n",
439  __FUNCTION__);
440 #endif
441  return 0;
442  }
443 
444 
445  // calculate the needed memory
446  MemSize = sizeof(handle_entry);
447  for (i = 0; AllHandles[i] != NULL; i++)
448  MemSize += sizeof(handle_entry);
449 
450 
451  HandleList = (handle_entry_list*)MemAllocate(sizeof(handle_entry_list));
452  if (!HandleList)
453  {
454  MemFree(AllHandles);
455  return 0;
456  }
457 
458  HandleEntry = (handle_entry*)MemAllocate(MemSize);
459  if (!HandleEntry)
460  {
461  MemFree(HandleList);
462  MemFree(AllHandles);
463  return 0;
464  }
465 
466  HandleList->HandleEntry = HandleEntry;
467  HandleList->NumOfEntries = (MemSize / sizeof(handle_entry)) - 1;
468 
469 
470  // get the handle information (protocols per handle)
471  for (i = 0; AllHandles[i] != NULL; i++)
472  {
473  Status = gBS->ProtocolsPerHandle(AllHandles[i],
474  &ProtocolGuidArray,
475  &ProtoArrayCount);
476 
477  HandleEntry[i].Handle = AllHandles[i];
478 
479  if (EFI_ERROR(Status))
480  continue;
481 
482 
483  // user needs to free the ProtocolGuidArray
484  for (ProtoIndex = 0; ProtoIndex < ProtoArrayCount; ProtoIndex++)
485  {
486 
487  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiLoadedImageProtocolGuid))
488  setHANDLE_TYPE_IMAGE_HANDLE(&HandleEntry[i].Flags);
489 
490  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiDriverBindingProtocolGuid))
491  setHANDLE_TYPE_DRIVER_BINDING_HANDLE(&HandleEntry[i].Flags);
492 
493  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiComponentNameProtocolGuid))
494  setHANDLE_TYPE_COMPONENT_NAME_HANDLE(&HandleEntry[i].Flags);
495 
496  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiDevicePathProtocolGuid))
497  setHANDLE_TYPE_DEVICE_HANDLE(&HandleEntry[i].Flags);
498 
499  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiDriverConfigurationProtocolGuid))
500  setHANDLE_TYPE_DRIVER_CONFIGURATION_HANDLE(&HandleEntry[i].Flags);
501 
502  if (CompareGuid(ProtocolGuidArray[ProtoIndex], &gEfiDriverDiagnosticsProtocolGuid))
503  setHANDLE_TYPE_DRIVER_DIAGNOSTICS_HANDLE(&HandleEntry[i].Flags);
504  }
505 
506  MemFree(ProtocolGuidArray);
507  }
508 
509 
510 
511  MemFree(AllHandles);
512  return HandleList;
513 }

Here is the call graph for this function:

Here is the caller graph for this function:

image_entry_list* GetAllImagesWithDescription ( handle_entry_list *  HandleList,
BOOLEAN  CalculateCrc 
)

Function creates the image list based on the system handles. Requestor is responsible for deallocating the memory through FreeImages function.

Parameters
HandleListPointer to handle list (can be null)
CalculateCrcIndicates whether function should calculate the crc32 value of the image code.
Return values
image_entry_list*On success a pointer to created image_entry_list
NULLOn error

Definition at line 701 of file Images.c.

References _image_entry::Crc32, EFI_STATUS(), FreeHandles(), GetAllHandlesWithDescription(), GetImagePathAndName(), GetLoadedImageProtocol(), GetPECodeChecksum(), _handle_entry::Handle, _image_entry::Handle, _handle_entry_list::HandleEntry, _image_entry::ImageBase, _image_entry_list::ImageEntry, _image_entry::ImageSize, _image_entry::LoadedImageProtocol, MAX_IMAGE_TEXTBUFF_LEN, MemAllocate(), MemFree(), _handle_entry_list::NumOfEntries, and _image_entry_list::NumOfEntries.

Referenced by BruteFind_gEventSignalQueueAddr(), CommandDriverInfo(), DrawBoxAndMenu(), DumpAllEvents(), DumpEFITables(), InstallSniffImage(), NotifyExitBootServices(), ScanMemoryForExecutables(), and TestDumpHandles().

703 {
704  UINTN i, j, MemSize;
705  image_entry *ImageEntry;
706  image_entry_list *ImageList;
707  EFI_STATUS Status;
708 
709  BOOLEAN NewHandleList;
710  EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProt;
711 
712 
713 
714  NewHandleList = FALSE;
715 
716  if (!HandleList)
717  {
718  NewHandleList = TRUE;
719  HandleList = GetAllHandlesWithDescription();
720  }
721 
722  if (!HandleList)
723  return 0;
724 
725  MemSize = HandleList->NumOfEntries * sizeof(image_entry);
726  ImageList = (image_entry_list*)MemAllocate(sizeof(image_entry_list));
727 
728  if (!ImageList)
729  {
730  if (NewHandleList)
731  FreeHandles(HandleList);
732  return 0;
733  }
734 
735  // allocate memory for maximum number of entries
736  ImageEntry = (image_entry*)MemAllocate(MemSize);
737  if (!ImageEntry)
738  {
739  MemFree(ImageList);
740  if (NewHandleList)
741  FreeHandles(HandleList);
742  return 0;
743  }
744 
745  ImageList->ImageEntry = ImageEntry;
746  ImageList->NumOfEntries = 0;
747 
748  // parse all handles and try to open the LoadedImageProtocol for it
749  // it looks like a bruteforcing method but there is a possibility
750  // to limit it by checking whether selected handle has
751  // image bit on
752 
753 
754  for (i = 0, j = 0; i < HandleList->NumOfEntries; i++)
755  {
756  Status = GetLoadedImageProtocol(HandleList->HandleEntry[i].Handle, &LoadedImageProt);
757 
758  // not an image or unknown error
759  if (EFI_ERROR(Status) || !LoadedImageProt)
760  continue;
761 
762  ImageEntry[j].Handle = HandleList->HandleEntry[i].Handle;
763  ImageEntry[j].LoadedImageProtocol = LoadedImageProt;
764  ImageEntry[j].ImageBase = LoadedImageProt->ImageBase;
765  ImageEntry[j].ImageSize = LoadedImageProt->ImageSize;
766 
767 
768  if (CalculateCrc)
769  ImageEntry[j].Crc32 = GetPECodeChecksum((C_PTR)LoadedImageProt->ImageBase);
770 
771  AsciiSPrint(ImageEntry[j].FilePath, MAX_IMAGE_TEXTBUFF_LEN, "UNKNOWN");
772  AsciiSPrint(ImageEntry[j].Name, MAX_IMAGE_TEXTBUFF_LEN, "UNKNOWN");
773 
774  // try to get the name and path
775  GetImagePathAndName(&ImageEntry[j], ImageEntry[j].Handle, LoadedImageProt);
776 
777  ImageList->NumOfEntries++;
778  j++;
779 
780  }
781 
782  if (NewHandleList)
783  FreeHandles(HandleList);
784 
785 
786  return ImageList;
787 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID GetEventTypeStringAscii ( CHAR8 *  EventTypeBuff,
UINTN  EventTypeBuffSize,
UINT32  EventType 
)

Function converts EventType to text representation.

Parameters
EventTypeBuffPointer to output buffer
EventTypeBuffSizeSize of the output buffer
EventTypeValue of the selected event type
Return values
NONE

Definition at line 36 of file Events.c.

References isEVENT_TYPE_EXIT_BOOT_SERVICES(), isEVENT_TYPE_NOTIFY_SIGNAL(), isEVENT_TYPE_NOTIFY_WAIT(), isEVENT_TYPE_RUNTIME(), isEVENT_TYPE_TIMER(), and isEVENT_TYPE_VIRTUAL_ADDRESS_CHANGE().

Referenced by CommandEventInfo(), DumpAllEvents(), and NotifyEventScannerTimer().

39 {
40  gBS->SetMem(EventTypeBuff, EventTypeBuffSize, 0);
41 
42  if (isEVENT_TYPE_TIMER(EventType))
43  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, " TIMER |");
44  if (isEVENT_TYPE_RUNTIME(EventType))
45  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, "%a RUNTIME |", EventTypeBuff);
46  if (isEVENT_TYPE_NOTIFY_WAIT(EventType))
47  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, "%a NOTIFY_WAIT |", EventTypeBuff);
48  if (isEVENT_TYPE_NOTIFY_SIGNAL(EventType))
49  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, "%a NOTIFY_SIGNAL |", EventTypeBuff);
50  if (isEVENT_TYPE_EXIT_BOOT_SERVICES(EventType))
51  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, "%a SIGNAL_EXIT_BOOT_SERVICES |", EventTypeBuff);
53  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, "%a SIGNAL_VADDR_CHANGE |", EventTypeBuff);
54 
55  if ((EventTypeBuff[0] == 0) || (EventType == 0))
56  AsciiSPrint(EventTypeBuff, EventTypeBuffSize-1, " UNKNOWN");
57 
58 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID GetHandleTypeStringAscii ( CHAR8 *  HandleTypeBuff,
UINTN  HandleTypeBuffSize,
UINT16  Flags 
)

Function converts HandleType to text representation.

Parameters
HandleTypeBuffPointer to output buffer
HandleTypeBuffSizeSize of the output buffer
FlagsValue of the selected handle type
Return values
NONE

Definition at line 39 of file Images.c.

References isHANDLE_TYPE_BUS_DRIVER(), isHANDLE_TYPE_CHILD_HANDLE(), isHANDLE_TYPE_COMPONENT_NAME_HANDLE(), isHANDLE_TYPE_CONTROLLER_HANDLE(), isHANDLE_TYPE_DEVICE_DRIVER(), isHANDLE_TYPE_DEVICE_HANDLE(), isHANDLE_TYPE_DRIVER_BINDING_HANDLE(), isHANDLE_TYPE_DRIVER_CONFIGURATION_HANDLE(), isHANDLE_TYPE_DRIVER_DIAGNOSTICS_HANDLE(), isHANDLE_TYPE_IMAGE_HANDLE(), isHANDLE_TYPE_PARENT_HANDLE(), and isHANDLE_TYPE_UNKNOWN().

Referenced by DumpAllHandles().

42 {
43  gBS->SetMem(HandleTypeBuff, HandleTypeBuffSize, 0);
44 
45  if (isHANDLE_TYPE_UNKNOWN(Flags))
46  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, " TYPE_UNKNOWN |");
47  if (isHANDLE_TYPE_IMAGE_HANDLE(Flags))
48  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_IMAGE_HANDLE |", HandleTypeBuff);
50  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_DRIVER_BINDING_HANDLE |", HandleTypeBuff);
51  if (isHANDLE_TYPE_DEVICE_DRIVER(Flags))
52  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_DEVICE_DRIVER |", HandleTypeBuff);
53  if (isHANDLE_TYPE_BUS_DRIVER(Flags))
54  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_BUS_DRIVER |", HandleTypeBuff);
56  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_DRIVER_CONFIGURATION_HANDLE |", HandleTypeBuff);
58  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_DRIVER_DIAGNOSTICS_HANDLE |", HandleTypeBuff);
60  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_COMPONENT_NAME_HANDLE |", HandleTypeBuff);
61  if (isHANDLE_TYPE_DEVICE_HANDLE(Flags))
62  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_DEVICE_HANDLE |", HandleTypeBuff);
63  if (isHANDLE_TYPE_PARENT_HANDLE(Flags))
64  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_PARENT_HANDLE |", HandleTypeBuff);
66  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_CONTROLLER_HANDLE |", HandleTypeBuff);
67  if (isHANDLE_TYPE_CHILD_HANDLE(Flags))
68  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, "%a TYPE_CHILD_HANDLE |", HandleTypeBuff);
69 
70  if (HandleTypeBuff[0] == 0)
71  AsciiSPrint(HandleTypeBuff, HandleTypeBuffSize-1, " UNKNOWN");
72 }

Here is the call graph for this function:

Here is the caller graph for this function:

idt_entry* GetIdtEntry ( ULONG  IdtVectorNum)

Returns IDT entry for selected entry.

Parameters
IdtVectorNumindex of wanted entry
Return values
ptrto idt_entry

Definition at line 106 of file IdtGdt.c.

References ASMGetIdtBase().

Referenced by IdtHookInterrupt().

107 {
108  idt_entry *IdtEntry;
109  IdtEntry = (idt_entry*)ASMGetIdtBase();
110  return &IdtEntry[IdtVectorNum];
111 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS GetLoadedImageProtocol ( EFI_HANDLE  Handle,
EFI_LOADED_IMAGE_PROTOCOL **  OutLoadedImage 
)

Function returns pointer to EFI_LOADED_IMAGE_PROTOCOL for specified Handle. HandleProtocol queries a handle to determine if it supports a specified protocol.

Parameters
HandleSpecified handle
OutLoadedImagePointer to variable that will hold the EFI_LOADED_IMAGE_PROTOCOL
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 151 of file Images.c.

References EFI_STATUS(), GetDevicePathTextForHandle(), and LogFullAscii().

Referenced by GetAllImagesWithDescription(), and hooked_LoadImage().

153 {
154  EFI_STATUS Status;
155 
156  Status = gBS->HandleProtocol(Handle,
157  &gEfiLoadedImageProtocolGuid,
158  (VOID*)OutLoadedImage);
159 
160  if (EFI_ERROR(Status))
161  {
162 #if DEBUG_ON == 2
163  LogFullAscii("%a: error in HandleProtocol, error = %08x \r\n",
164  __FUNCTION__, Status);
165 #endif
166 
167  return Status;
168  }
169 
170 
171 #if DEBUG_ON == 2
172  LogFullAscii("%a: Imagebase: %016lx \r\n", __FUNCTION__, XLoadedImage->ImageBase);
173  LogFullAscii("%a: Name: %s\r\n", __FUNCTION__, GetDevicePathTextForHandle(XLoadedImage->FilePath));
174 #endif
175 
176  return EFI_SUCCESS;
177 
178 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID GetMemAttributesStringAscii ( CHAR8 *  MemAttributesBuff,
UINTN  MemAttributesBuffSize,
UINT64  Attributes 
)

Function converts memory Attributes to text representation.

Parameters
MemAttributesBuffPointer to output buffer
MemAttributesBuffSizeSize of the output buffer
AttributesValue of memory attributes
Return values
NONE

Definition at line 42 of file MemoryMap.c.

References isMEM_ATTR_MEMORY_RP(), isMEM_ATTR_MEMORY_RUNTIME(), isMEM_ATTR_MEMORY_UC(), isMEM_ATTR_MEMORY_UCE(), isMEM_ATTR_MEMORY_WB(), isMEM_ATTR_MEMORY_WC(), isMEM_ATTR_MEMORY_WP(), isMEM_ATTR_MEMORY_WT(), and isMEM_ATTR_MEMORY_XP().

Referenced by CommandMemInfo(), and DumpMemoryMap().

45 {
46  gBS->SetMem(MemAttributesBuff, MemAttributesBuffSize, 0);
47 
48  if (isMEM_ATTR_MEMORY_UC(Attributes))
49  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_UC |", MemAttributesBuff);
50  if (isMEM_ATTR_MEMORY_WC(Attributes))
51  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_WC |", MemAttributesBuff);
52  if (isMEM_ATTR_MEMORY_WT(Attributes))
53  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_WT |", MemAttributesBuff);
54  if (isMEM_ATTR_MEMORY_WB(Attributes))
55  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_WB |", MemAttributesBuff);
56  if (isMEM_ATTR_MEMORY_UCE(Attributes))
57  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_UCE |", MemAttributesBuff);
58  if (isMEM_ATTR_MEMORY_WP(Attributes))
59  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_WP |", MemAttributesBuff);
60  if (isMEM_ATTR_MEMORY_RP(Attributes))
61  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_RP |", MemAttributesBuff);
62  if (isMEM_ATTR_MEMORY_XP(Attributes))
63  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_XP |", MemAttributesBuff);
64  if (isMEM_ATTR_MEMORY_RUNTIME(Attributes))
65  AsciiSPrint(MemAttributesBuff, MemAttributesBuffSize-1, "%a EFI_MEMORY_RUNTIME |", MemAttributesBuff);
66 
67 }

Here is the call graph for this function:

Here is the caller graph for this function:

memory_map_entry_list* GetMemoryMapList ( VOID  )

Function generates current memory map. Caller is responsible for deallocating the memory.

Return values
PointerOn success pointer to memory_map_entry_list
NULLOn error

Definition at line 114 of file MemoryMap.c.

References _memory_map_entry::Attributes, EFI_STATUS(), GetMemoryEntryGcdInformation(), LogFullAscii(), _memory_map_entry_list::MapKey, MemAllocate(), MemFree(), _memory_map_entry_list::MemoryMapEntry, NUM_OF_MAP_ENTRIES, _memory_map_entry::NumberOfPages, _memory_map_entry_list::NumOfEntries, PAGE_SIZE, _memory_map_entry::PhysicalStart, _memory_map_entry::Type, and _memory_map_entry::VirtualStart.

Referenced by CommandMemInfo(), and DrawBoxAndMenu().

115 {
116  EFI_STATUS Status;
117  UINTN MemoryMapSize;
118  EFI_MEMORY_DESCRIPTOR *MemoryMap;
119  UINTN MapKey;
120  UINTN DescriptorSize;
121  UINT32 DescriptorVersion;
122  UINTN Pages;
123  UINTN i;
124 
125  EFI_MEMORY_DESCRIPTOR *EfiMemoryMapEnd;
126  EFI_MEMORY_DESCRIPTOR *EfiEntry;
127  EFI_MEMORY_DESCRIPTOR *NextEfiEntry;
128 
129  memory_map_entry_list *MemMap;
130  memory_map_entry *MemMapEntry;
131 
132 
133  MemoryMap = NULL;
134  MemoryMapSize = 0;
135  Pages = 0;
136 
137 
138  Status = gBS->GetMemoryMap(&MemoryMapSize,
139  MemoryMap,
140  &MapKey,
141  &DescriptorSize,
142  &DescriptorVersion);
143 
144  if (Status == EFI_BUFFER_TOO_SMALL)
145  {
146 
147 #if DEBUG_ON == 1
148  LogFullAscii("%a: Buffer to small, need = 0x%08x(%d) bytes\r\n",
149  __FUNCTION__, MemoryMapSize, MemoryMapSize);
150 #endif
151 
152  MemoryMapSize += PAGE_SIZE;
153  Pages = EFI_SIZE_TO_PAGES(MemoryMapSize);
154 
155  // do not use AllocatePages here, mac apple firmware is buggy
156  // and it will fault when GetMemoryMap will be executed
157  // with memory from AllocatePages as a parameter
158 
159  //MemoryMap = AllocatePages (Pages);
160  MemoryMap = MemAllocate(MemoryMapSize);
161 
162 
163  // get memory map again
164  Status = gBS->GetMemoryMap(
165  &MemoryMapSize,
166  MemoryMap,
167  &MapKey,
168  &DescriptorSize,
169  &DescriptorVersion
170  );
171 
172  if (EFI_ERROR(Status))
173  {
174 #if DEBUG_ON == 1
175  LogFullAscii("%a: GetMemoryMap returned unknown error (2nd time), status = %08d\r\n",
176  __FUNCTION__, Status);
177 #endif
178  return 0;
179  }
180  }
181  else
182  {
183 #if DEBUG_ON == 1
184  LogFullAscii("%a: GetMemoryMap returned unknown error, status = %08x \n",
185  __FUNCTION__, Status);
186 #endif
187 
188  return 0;
189  }
190 
191 
192 #if DEBUG_ON == 1
193  LogFullAscii("%a: Memory map recevied, processing!\r\n", __FUNCTION__);
194 #endif
195 
196 
197  // initialize variables
198  EfiEntry = MemoryMap;
199  NextEfiEntry = NEXT_MEMORY_DESCRIPTOR(EfiEntry, DescriptorSize);
200  EfiMemoryMapEnd = (EFI_MEMORY_DESCRIPTOR*)((UINT8*)MemoryMap + MemoryMapSize);
201 
202 #define NUM_OF_MAP_ENTRIES ((MemoryMapSize / DescriptorSize)+1)
203 
204 
205  // allocate the memory for our structures
207  if (!MemMap)
208  {
209 #if DEBUG_ON == 1
210  LogFullAscii("%a: unable to allocate memory for MemMap\r\n",
211  __FUNCTION__);
212 #endif
213 
214  MemFree(MemoryMap);
215  return 0;
216  }
217 
219 
220  if (!MemMapEntry)
221  {
222 #if DEBUG_ON == 1
223  LogFullAscii("%a: unable to allocate memory for MemMapEntry\r\n",
224  __FUNCTION__);
225 #endif
226 
227  MemFree(MemMap);
228  MemFree(MemoryMap);
229  return 0;
230  }
231 
232 
233 
234  for (i = 0; i < (NUM_OF_MAP_ENTRIES - 1); i++)
235  {
236 
237  MemMapEntry[i].Type = EfiEntry->Type;
238  MemMapEntry[i].PhysicalStart = EfiEntry->PhysicalStart;
239  MemMapEntry[i].VirtualStart = EfiEntry->VirtualStart;
240  MemMapEntry[i].NumberOfPages = EfiEntry->NumberOfPages;
241  MemMapEntry[i].Attributes = EfiEntry->Attribute;
242  GetMemoryEntryGcdInformation(EfiEntry->PhysicalStart, &MemMapEntry[i]);
243 
244  EfiEntry = NEXT_MEMORY_DESCRIPTOR(EfiEntry, DescriptorSize);
245  }
246 
247 
248  MemMap->NumOfEntries = NUM_OF_MAP_ENTRIES - 1;
249  MemMap->MemoryMapEntry = MemMapEntry;
250  MemMap->MapKey = MapKey;
251 
252 
253 #undef NUM_OF_MAP_ENTRIES
254 
255  MemFree(MemoryMap);
256  return MemMap;
257 }

Here is the call graph for this function:

Here is the caller graph for this function:

ULONG GetPECodeChecksum ( C_PTR  Base)

Function computes the checksum from code section of the selected PE file. Code sections that are writable are not included in the checksum.

Parameters
BaseBase of PE file in memory
Return values
ChecksumOn success
NULLOn error

Definition at line 144 of file Pe.c.

References EFI_IMAGE_SECTION_HEADER::Characteristics, EFI_IMAGE_SCN_MEM_EXECUTE, EFI_IMAGE_SCN_MEM_WRITE, EFI_IMAGE_NT_HEADERS32::FileHeader, GetPEHeaders(), EFI_IMAGE_FILE_HEADER::NumberOfSections, EFI_IMAGE_SECTION_HEADER::SizeOfRawData, and EFI_IMAGE_SECTION_HEADER::VirtualAddress.

Referenced by AddImageToList(), and GetAllImagesWithDescription().

145 {
146  UINTN i;
150 
151  ULONG Crc32, Crc32Copy;
152 
153 
154  if (!GetPEHeaders(Base, &pMZ, &pPE, &pSH))
155  return 0;
156 
157 
158  // number of sections field is correct for both peh32/peh64
159  Crc32 = 0;
160  for (i = 0; i < pPE->FileHeader.NumberOfSections; i++, pSH++)
161  {
162  // skip writable sections
164  continue;
165 
166  // skip sections without code
168  continue;
169 
170  // calculate the checksum
171  // adding the various calculated checksum together is probably not safe in terms of crypto
172  // but the crc32 even without it is still available to forging
173  Crc32Copy = Crc32;
174  gBS->CalculateCrc32((VOID*)(Base + pSH->VirtualAddress), pSH->SizeOfRawData, &Crc32);
175  Crc32 += Crc32Copy;
176 
177  }
178 
179  return Crc32;
180 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOLEAN GetPEHeaders ( C_PTR  Base,
EFI_IMAGE_DOS_HEADER **  pMZ,
EFI_IMAGE_NT_HEADERS32 **  pPE,
EFI_IMAGE_SECTION_HEADER **  pSH 
)

Function initializes the IMAGE_DOS_HEADER, IMAGE_NT_HEADERS and IMAGE_SECTION_HEADER.

Parameters
BaseBase of PE file in memory
pMZPointer to variable which receives the EFI_IMAGE_DOS_HEADER pointer
pPEPointer to variable which receives the EFI_IMAGE_NT_HEADERS pointer
pSHPointer to variable which receives the EFI_IMAGE_SECTION_HEADER pointer
Return values
TRUEOn success
FALSEOn error

Definition at line 76 of file Pe.c.

References EFI_IMAGE_DOS_HEADER::e_lfanew, EFI_IMAGE_DOS_HEADER::e_magic, EFI_IMAGE_DOS_SIGNATURE, EFI_IMAGE_NT_SIGNATURE, EFI_IMAGE_NT_HEADERS32::FileHeader, IMAGE_FILE_MACHINE_X64, IMAGE_FIRST_SECTION32, IMAGE_FIRST_SECTION64, LogFullAscii(), EFI_IMAGE_FILE_HEADER::Machine, and EFI_IMAGE_NT_HEADERS32::Signature.

Referenced by BruteFind_gEventSignalQueueAddr(), and GetPECodeChecksum().

81 {
83  EFI_IMAGE_NT_HEADERS32 *plPE32;
84  EFI_IMAGE_NT_HEADERS32 *plPE64;
86 
87  *pMZ = 0;
88  *pPE = 0;
89  *pSH = 0;
90 
91  plMZ = (EFI_IMAGE_DOS_HEADER*)Base;
92 
93  if (plMZ->e_magic != EFI_IMAGE_DOS_SIGNATURE)
94  {
95 #if DEBUG_ON == 1
96  LogFullAscii("GetPEHeaders: invalid MZ signature at %016lx\r\n", (MAX_PTR)Base);
97 #endif
98  return FALSE;
99  }
100 
101  plPE32 = (EFI_IMAGE_NT_HEADERS32*)(Base + plMZ->e_lfanew);
102  plPE64 = (EFI_IMAGE_NT_HEADERS32*)plPE32;
103 
104  if (plPE32->Signature != EFI_IMAGE_NT_SIGNATURE)
105  {
106 #if DEBUG_ON == 1
107  LogFullAscii("GetPEHeaders: invalid PE signature at %016lx\r\n", (MAX_PTR)Base);
108 #endif
109 
110  return FALSE;
111  }
112 
113 
114  // is it a x64 pe?
116  plSH = IMAGE_FIRST_SECTION32(plPE32);
117  else
118  plSH = IMAGE_FIRST_SECTION64(plPE64);
119 
120 
121  *pMZ = plMZ;
122  *pPE = plPE32;
123  *pSH = plSH;
124 
125  return TRUE;
126 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS GetX64Context ( x64_context *  Context)

Function fills the X64 Context structure.

Parameters
ContextPointer to x64_context structure
Return values
EFI_SUCCESS

Definition at line 24 of file Context.c.

References _x64_context::_Cr0, _x64_context::_Cr2, _x64_context::_Cr3, _x64_context::_Cr4, _x64_context::_Cr8, _x64_context::_Cs, _x64_context::_Dr0, _x64_context::_Dr2, _x64_context::_Dr3, _x64_context::_Dr6, _x64_context::_Dr7, _x64_context::_Ds, _x64_context::_Es, _x64_context::_Fs, _x64_context::_Gs, _x64_context::_Rax, _x64_context::_Rbp, _x64_context::_Rbx, _x64_context::_Rcx, _x64_context::_Rdi, _x64_context::_Rdx, _x64_context::_Rflags, _x64_context::_Rsi, _x64_context::_Rsp, _x64_context::_Ss, ASMGetRegCr0(), ASMGetRegCr2(), ASMGetRegCr3(), ASMGetRegCr4(), ASMGetRegCr8(), ASMGetRegCs(), ASMGetRegDr0(), ASMGetRegDr2(), ASMGetRegDr3(), ASMGetRegDr6(), ASMGetRegDr7(), ASMGetRegDs(), ASMGetRegEs(), ASMGetRegFs(), ASMGetRegGs(), ASMGetRegRax(), ASMGetRegRbp(), ASMGetRegRbx(), ASMGetRegRcx(), ASMGetRegRdi(), ASMGetRegRdx(), ASMGetRegRflags(), ASMGetRegRsi(), ASMGetRegRsp(), and ASMGetRegSs().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

25 {
26 
27  Context->_Rax = ASMGetRegRax();
28  Context->_Rbx = ASMGetRegRbx();
29  Context->_Rcx = ASMGetRegRcx();
30  Context->_Rdx = ASMGetRegRdx();
31  Context->_Rsi = ASMGetRegRsi();
32  Context->_Rdi = ASMGetRegRdi();
33  Context->_Rbp = ASMGetRegRbp();
34  Context->_Rsp = ASMGetRegRsp();
35 
36  Context->_Rflags = ASMGetRegRflags();
37 
38 
39  Context->_Cs = ASMGetRegCs();
40  Context->_Ds = ASMGetRegDs();
41  Context->_Es = ASMGetRegEs();
42  Context->_Fs = ASMGetRegFs();
43  Context->_Gs = ASMGetRegGs();
44  Context->_Ss = ASMGetRegSs();
45 
46  Context->_Dr0 = ASMGetRegDr0();
47  Context->_Dr2 = ASMGetRegDr2();
48  Context->_Dr3 = ASMGetRegDr3();
49  Context->_Dr6 = ASMGetRegDr6();
50  Context->_Dr7 = ASMGetRegDr7();
51 
52  Context->_Cr0 = ASMGetRegCr0();
53  Context->_Cr2 = ASMGetRegCr2();
54  Context->_Cr3 = ASMGetRegCr3();
55  Context->_Cr4 = ASMGetRegCr4();
56  Context->_Cr8 = ASMGetRegCr8();
57 
58 
59  return EFI_SUCCESS;
60 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS GetX86Context ( x86_context *  Context)

Function fills the X86 Context structure.

Parameters
ContextPointer to x86_context structure
Return values
EFI_SUCCESS

Definition at line 73 of file Context.c.

References _x86_context::_Cr0, _x86_context::_Cr2, _x86_context::_Cr3, _x86_context::_Cr4, _x86_context::_Cs, _x86_context::_Dr0, _x86_context::_Dr2, _x86_context::_Dr3, _x86_context::_Dr6, _x86_context::_Dr7, _x86_context::_Ds, _x86_context::_Eax, _x86_context::_Ebp, _x86_context::_Ebx, _x86_context::_Ecx, _x86_context::_Edi, _x86_context::_Edx, _x86_context::_Eflags, _x86_context::_Es, _x86_context::_Esi, _x86_context::_Esp, _x86_context::_Fs, _x86_context::_Gs, _x86_context::_Ss, ASMGetRegCr0(), ASMGetRegCr2(), ASMGetRegCr3(), ASMGetRegCr4(), ASMGetRegCs(), ASMGetRegDr0(), ASMGetRegDr2(), ASMGetRegDr3(), ASMGetRegDr6(), ASMGetRegDr7(), ASMGetRegDs(), ASMGetRegEs(), ASMGetRegFs(), ASMGetRegGs(), ASMGetRegRax(), ASMGetRegRbp(), ASMGetRegRbx(), ASMGetRegRcx(), ASMGetRegRdi(), ASMGetRegRdx(), ASMGetRegRflags(), ASMGetRegRsi(), ASMGetRegRsp(), and ASMGetRegSs().

Referenced by ContextX64Test(), and DrawBoxAndMenu().

74 {
75 
76  Context->_Eax = (ULONG)ASMGetRegRax();
77  Context->_Ebx = (ULONG)ASMGetRegRbx();
78  Context->_Ecx = (ULONG)ASMGetRegRcx();
79  Context->_Edx = (ULONG)ASMGetRegRdx();
80  Context->_Esi = (ULONG)ASMGetRegRsi();
81  Context->_Edi = (ULONG)ASMGetRegRdi();
82  Context->_Ebp = (ULONG)ASMGetRegRbp();
83  Context->_Esp = (ULONG)ASMGetRegRsp();
84 
85  Context->_Eflags = (ULONG)ASMGetRegRflags();
86 
87  Context->_Cs = ASMGetRegCs();
88  Context->_Ds = ASMGetRegDs();
89  Context->_Es = ASMGetRegEs();
90  Context->_Fs = ASMGetRegFs();
91  Context->_Gs = ASMGetRegGs();
92  Context->_Ss = ASMGetRegSs();
93 
94  Context->_Dr0 = (ULONG)ASMGetRegDr0();
95  Context->_Dr2 = (ULONG)ASMGetRegDr2();
96  Context->_Dr3 = (ULONG)ASMGetRegDr3();
97  Context->_Dr6 = (ULONG)ASMGetRegDr6();
98  Context->_Dr7 = (ULONG)ASMGetRegDr7();
99 
100  Context->_Cr0 = (ULONG)ASMGetRegCr0();
101  Context->_Cr2 = (ULONG)ASMGetRegCr2();
102  Context->_Cr3 = (ULONG)ASMGetRegCr3();
103  Context->_Cr4 = (ULONG)ASMGetRegCr4();
104  //Context->_Cr8 = ASMGetRegCr8();
105 
106 
107  return EFI_SUCCESS;
108 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS IdtHookInterrupt ( C_PTR  NewIntHandlerAddr,
ULONG  IdtVectorNum,
C_PTR *  OutOldIntAddr 
)

Function hooks selected IDT entry (vector) and points it to the NewIntHandlerAddr (supplied by the requestor).

Parameters
NewIntHandlerAddrNew interrupt vector handler
IdtVectorNumSpecified vector number
OutOldIntAddrPointer to variable which will hold the old interrupt vector handler
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 137 of file IdtGdt.c.

References GetIdtEntry(), IDT_GET_BASE, LogFullAscii(), idt_entry::OffsetHigh, and idt_entry::OffsetLow.

Referenced by IdtHookTest().

138 {
139  UINT_ARCH OldBase;
140  idt_entry *IdtEntry;
141 
142  IdtEntry = GetIdtEntry(IdtVectorNum);
143  OldBase = IDT_GET_BASE(IdtEntry);
144 
145  *OutOldIntAddr = OldBase;
146 
147 #if DEBUG_ON == 1
148  LogFullAscii("%a: Interrupt: %d OldBase=%016lx NewBase=%016lx\r\n",
149  __FUNCTION__,
150  IdtVectorNum,
151  (MAX_PTR)OldBase,
152  (MAX_PTR)NewIntHandlerAddr);
153 #endif
154 
155  IdtEntry->OffsetHigh = (USHORT)(NewIntHandlerAddr >> 16);
156  IdtEntry->OffsetLow = (USHORT)(NewIntHandlerAddr & 0xFFFF);
157 
158 #if defined(_WIN64)
159  IdtEntry->HighOffset64 = (ULONG)((ULONG64)NewIntHandlerAddr >> 32);
160 #endif
161 
162 
163 #if DEBUG_ON == 1
164  LogFullAscii("IdtHookInterrupt: hooked!\r\n");
165 #endif
166 
167  return EFI_SUCCESS;
168 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS IdtHookTest ( VOID  )

Definition at line 171 of file IdtGdt.c.

References ASMDbgBreak(), IdtHookInterrupt(), and Int03Handler().

172 {
173  ULONG64 OldAddr;
174 
175  IdtHookInterrupt((C_PTR)&Int03Handler, 3, (C_PTR*)&OldAddr);
176  ASMDbgBreak();
177 
178  return EFI_SUCCESS;
179 }

Here is the call graph for this function:

EFI_STATUS InitializeEFITables ( VOID  )

Function initializes wanted offsets and values to the EFITables.

Definition at line 103 of file TableMonitor.c.

References write_entry.

Referenced by CommandFunction(), and DrawBoxAndMenu().

104 {
105 #define write_entry(index, api) { gEFITables[index].ptr_va = (UINT64)&api; gEFITables[index].last_addr = (UINT64)api; }
106 
107 
108  write_entry(0, gRT->GetTime);
109  write_entry(1, gRT->SetTime);
110  write_entry(2, gRT->GetWakeupTime);
111  write_entry(3, gRT->SetWakeupTime);
112  write_entry(4, gRT->SetVirtualAddressMap);
113  write_entry(5, gRT->ConvertPointer);
114  write_entry(6, gRT->GetVariable);
115  write_entry(7, gRT->GetNextVariableName);
116  write_entry(8, gRT->SetVariable);
117  write_entry(9, gRT->GetNextHighMonotonicCount);
118  write_entry(10, gRT->ResetSystem);
119  write_entry(11, gRT->UpdateCapsule);
120  write_entry(12, gRT->QueryCapsuleCapabilities);
121  write_entry(13, gRT->QueryVariableInfo);
122 
123 
124  // boot time services
125  write_entry(14, gBS->RaiseTPL);
126  write_entry(15, gBS->RestoreTPL);
127  write_entry(16, gBS->AllocatePages);
128  write_entry(17, gBS->FreePages);
129  write_entry(18, gBS->GetMemoryMap);
130  write_entry(19, gBS->AllocatePool);
131  write_entry(20, gBS->FreePool);
132  write_entry(21, gBS->CreateEvent);
133  write_entry(22, gBS->SetTimer);
134  write_entry(23, gBS->WaitForEvent);
135  write_entry(24, gBS->SignalEvent);
136  write_entry(25, gBS->CloseEvent);
137  write_entry(26, gBS->CheckEvent);
138  write_entry(27, gBS->InstallProtocolInterface);
139  write_entry(28, gBS->ReinstallProtocolInterface);
140  write_entry(29, gBS->UninstallProtocolInterface);
141  write_entry(30, gBS->HandleProtocol);
142  write_entry(31, gBS->RegisterProtocolNotify);
143  write_entry(32, gBS->LocateHandle);
144  write_entry(33, gBS->LocateDevicePath);
145  write_entry(34, gBS->InstallConfigurationTable);
146  write_entry(35, gBS->LoadImage);
147  write_entry(36, gBS->StartImage);
148  write_entry(37, gBS->Exit);
149  write_entry(38, gBS->UnloadImage);
150  write_entry(39, gBS->ExitBootServices);
151  write_entry(40, gBS->GetNextMonotonicCount);
152  write_entry(41, gBS->Stall);
153  write_entry(42, gBS->SetWatchdogTimer);
154  write_entry(43, gBS->ConnectController);
155  write_entry(44, gBS->DisconnectController);
156  write_entry(45, gBS->OpenProtocol);
157  write_entry(46, gBS->CloseProtocol);
158  write_entry(47, gBS->OpenProtocolInformation);
159  write_entry(48, gBS->ProtocolsPerHandle);
160  write_entry(49, gBS->LocateHandleBuffer);
161  write_entry(50, gBS->LocateProtocol);
162  write_entry(51, gBS->InstallMultipleProtocolInterfaces);
163  write_entry(52, gBS->UninstallMultipleProtocolInterfaces);
164  write_entry(53, gBS->CalculateCrc32);
165  write_entry(54, gBS->CopyMem);
166  write_entry(55, gBS->SetMem);
167  write_entry(56, gBS->CreateEventEx);
168 
169 
170  // EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
171  write_entry(57, gST->ConIn->ReadKeyStroke);
172 
173 
174 #undef write_entry
175 
176  return EFI_SUCCESS;
177 }

Here is the caller graph for this function:

EFI_STATUS InitializeLogFile ( VOID  )

Function initializes the log file

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 137 of file FileSystemWrap.c.

References EFI_STATUS(), gEfiScannerPolicy, gImageHandle, gLogFile, gRoot, gSelfLoadedImage, gVolFileSystemProto, LOG_FILE, LOG_INIT_LINE, OpenFile(), OpenVolume(), _policy::OpUseLog, and PRINT_FUNC.

Referenced by EfiScannerInitialize().

138 {
139  UINTN Size;
140  EFI_STATUS Status;
141 
142  // check the policy first
144  return EFI_NOT_FOUND;
145 
146  if (gSelfLoadedImage->DeviceHandle && gVolFileSystemProto)
147  gBS->CloseProtocol(gSelfLoadedImage->DeviceHandle,
148  &gEfiSimpleFileSystemProtocolGuid,
150  gImageHandle);
151 
152  if (gRoot)
153  gRoot->Close(gRoot);
154 
155  Status = OpenVolume(gSelfLoadedImage->FilePath);
156  ASSERT(!EFI_ERROR(Status));
157 
158 
159  Status = OpenFile(LOG_FILE,
160  EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE,
161  &gLogFile);
162 
163  if (EFI_ERROR(Status))
164  {
165  PRINT_FUNC(L"%a: unable to create log file, status = %08x \r\n",
166  __FUNCTION__, Status);
167  return Status;
168  }
169 
170 
171  // seek to the end of file
172  gLogFile->SetPosition(gLogFile, 0xFFFFFFFFFFFFFFFF);
173 
174  Size = sizeof(LOG_INIT_LINE)-1;
175  Status = gLogFile->Write(gLogFile, &Size, LOG_INIT_LINE);
176 
177 
178  if (EFI_ERROR(Status))
179  {
180  PRINT_FUNC(L"%a: unable to write, status = %08x \r\n",
181  __FUNCTION__, Status);
182  return Status;
183  }
184 
185  return Status;
186 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS InstallEFITableScanner ( VOID  )

Function installs EFI timer which checks runtime/boottime functions periodically - it also logs every change to file.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 426 of file TableMonitor.c.

References EFI_STATUS(), EFI_TPL_NOTIFY, gScannerEvent, LogFullAscii(), NotifyScannerTimer(), and SAMPLE_INTERVAL.

Referenced by DrawBoxAndMenu().

427 {
428  EFI_STATUS Status;
429 
430  LogFullAscii(": Installing the EFI table scanner\r\n");
431 
432  Status = gBS->CreateEvent(EVT_NOTIFY_SIGNAL | EVT_TIMER,
435  NULL,
436  &gScannerEvent);
437  if (EFI_ERROR(Status))
438  {
439  LogFullAscii("%a: Unable to install the table scanner, status = %08x\r\n",
440  __FUNCTION__, Status);
441  return Status;
442  }
443 
444 
445  Status = gBS->SetTimer(gScannerEvent,
446  TimerPeriodic,
447  SAMPLE_INTERVAL);
448 
449 
450  if (EFI_ERROR(Status))
451  {
452  gBS->CloseEvent(gScannerEvent);
453 
454  LogFullAscii("%a: Unable to install the timer for table scanner, status = %08x\r\n",
455  __FUNCTION__, Status);
456 
457  return Status;
458  }
459 
460  return EFI_SUCCESS;
461 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS InstallEventScanner ( CALLBACK_EVENTSCANNER  UserCallback)

Function installs EFI timer which checks the events for changes

Parameters
UserCallbackOptional address to user function which will be executed when new event will be found.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 125 of file EventsScanner.c.

References EFI_STATUS(), EFI_TPL_NOTIFY, GetAllEvents(), gEventScannerEvent, gUserEventScannerCallback, LogFullAscii(), MemZero(), NewEventNotifyFunctions, NotifyEventScannerTimer(), NumOfNewEventNotifyFunctions, and SAMPLE_INTERVAL.

Referenced by DrawBoxAndMenu(), and TestDumpHandles().

126 {
127  EFI_STATUS Status;
128 
129  LogFullAscii(": Installing the event scanner\r\n");
130 
131 
134 
135 
136  if (UserCallback)
137  gUserEventScannerCallback = UserCallback;
138 
139 
140 
141  // firstly get the current event list
143  if (!gEventList)
144  {
145  LogFullAscii("%a: Error unable to get event list!\r\n", __FUNCTION__);
146  return EFI_NOT_FOUND;
147  }
148 
149 
150 
151  Status = gBS->CreateEvent(EVT_NOTIFY_SIGNAL | EVT_TIMER,
154  NULL,
156  if (EFI_ERROR(Status))
157  {
158  LogFullAscii("%a: Unable to install the event scanner, status = %08x\r\n",
159  __FUNCTION__, Status);
160 
161  return Status;
162  }
163 
164  Status = gBS->SetTimer(gEventScannerEvent, TimerPeriodic, SAMPLE_INTERVAL);
165 
166  if (EFI_ERROR(Status))
167  {
168  gBS->CloseEvent(gEventScannerEvent);
169 
170  LogFullAscii("%a: Unable to install the timer for event scanner, status = %08x\r\n",
171  __FUNCTION__, Status);
172 
173  return Status;
174  }
175 
176  return EFI_SUCCESS;
177 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS InstallSniffImage ( CALLBACK_IMAGESNIFFER_NEW  UserNewImageCallback,
CALLBACK_IMAGESNIFFER_MOD  UserModImageCallback 
)

Function installs hook for BootServices->LoadImage. At this point it is able to monitor which images are being loaded by the system.

Parameters
UserNewImageCallbackUser callback which will be executed when new image is detected
UserModImageCallbackUser callback which will be executed when a modified image will be detected
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 243 of file SniffImage.c.

References EFI_STATUS(), FreeImages(), GetAllImagesWithDescription(), gOrg_ExitBootServices, gOrg_LoadImage, gSetExitBootServicesEvent, gUserImageSnifferModImageCallback, gUserImageSnifferNewImageCallback, hooked_LoadImage(), LogFullAscii(), and NotifyExitBootServices().

Referenced by DrawBoxAndMenu(), and TestDumpHandles().

245 {
246  EFI_STATUS Status;
247 
248  LogFullAscii(": Installing image sniffer...");
249 
250  if (UserNewImageCallback)
251  gUserImageSnifferNewImageCallback = UserNewImageCallback;
252  if (UserModImageCallback)
253  gUserImageSnifferModImageCallback = UserModImageCallback;
254 
255  gOrg_LoadImage = gBS->LoadImage;
256  gOrg_ExitBootServices = gBS->ExitBootServices;
257 
259  if (!gImageList)
260  {
261  LogFullAscii("%a: error executing GetAllImagesWithDescription\r\n",
262  __FUNCTION__);
263  return EFI_NOT_FOUND;
264  }
265 
266 
267  Status = gBS->CreateEvent(EVT_SIGNAL_EXIT_BOOT_SERVICES,
268  TPL_NOTIFY,
270  NULL,
272 
273  if (EFI_ERROR(Status))
274  {
275  LogFullAscii("%a: unable to create event, status = %08x\r\n",
276  __FUNCTION__, Status);
278  gImageList = 0;
279  return EFI_NOT_FOUND;
280 
281  }
282 
283 
284  gBS->LoadImage = &hooked_LoadImage;
285  //gBS->ExitBootServices = &hooked_ExitBootServices;
286 
287  LogFullAscii("done.\r\n");
288 
289  return EFI_SUCCESS;
290 }

Here is the call graph for this function:

Here is the caller graph for this function:

C_PTR IsBadAddress ( C_PTR  Address)

Functions tests if Address equals to StartAddr from bad addrs list (from the policy). If so it returns the EndAddr from the policy. This is done to filter the memory areas which cause machine freeze. Otherwise it returns 0.

Definition at line 295 of file DumpMem.c.

References _policy::BadAddrs, _bad_addr_entry::EndAddr, gEfiScannerPolicy, _policy::NumOfBadAddrs, and _bad_addr_entry::StartAddr.

Referenced by ScanMemoryForExecutables().

296 {
297  UINTN i;
298 
300  return 0;
301 
302  for (i = 0; i < gEfiScannerPolicy.NumOfBadAddrs; i++)
303  if (gEfiScannerPolicy.BadAddrs[i].StartAddr == Address)
305 
306  return 0;
307 }

Here is the caller graph for this function:

VOID LogFileAscii ( CHAR8 *  FormatString,
  ... 
)

Depending on the policy function writes the provided text data to log file or serial port.

Parameters
FormatStringFormat string (printf style)
...Additional arguments
Return values
NONE

Definition at line 40 of file Logs.c.

References ASMEnterLock(), ASMLeaveLock(), ComPutString(), gEfiScannerPolicy, gLogLock, _policy::OpUseComPort, and WriteLogFile().

Referenced by DumpEFITables(), hooked_LoadImage(), MyModImageNotify(), MyNewEventCallback(), MyNewImageNotify(), NotifyEventScannerTimer(), NotifyExitBootServices(), and ReadConfiguration().

41 {
42  VA_LIST VList;
43  CHAR8 LogBuffer[1024];
44 
45  VA_START(VList, FormatString);
46  AsciiVSPrint(LogBuffer, sizeof(LogBuffer)-1, FormatString, VList);
47  VA_END(VList);
48 
49 
51 
52  WriteLogFile(LogBuffer);
54  ComPutString(LogBuffer);
55 
57 
58 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID LogFullAscii ( CHAR8 *  FormatString,
  ... 
)

Depending on the policy function writes the provided text data to screen, log file or serial port.

Parameters
FormatStringFormat string (printf style)
...Additional arguments
Return values
NONE

Definition at line 73 of file Logs.c.

References ASMEnterLock(), ASMLeaveLock(), ComPutString(), gEfiScannerPolicy, gLogLock, _policy::OpUseComPort, PRINT_FUNC_ASCII, and WriteLogFile().

Referenced by BruteFind_gEventSignalQueueAddr(), BruteFind_gEventSignalQueueAddr2(), CheckImagesFunctionPointers(), ComConsoleStart(), CommandDriverInfo(), CommandDumpMem(), CommandEventInfo(), CommandFunction(), CommandHelp(), CommandMemInfo(), DisplayLogX64Context(), DisplayLogX86Context(), DumpAllEvents(), DumpAllHandles(), DumpAllImages(), DumpEFITables(), DumpFirmwareFromROM(), DumpGcdMemoryMap(), DumpGDT(), DumpIDT(), DumpImageToDisk(), DumpMemoryMap(), DumpMemoryToFile(), DumpPEFile(), DumpTEFile(), EfiScannerEntryPoint(), EfiScannerInitialize(), GetAllEvents(), GetAllHandles(), GetAllHandlesWithDescription(), GetgEventSignalQueueMacMini(), GetLoadedImageProtocol(), GetMemoryEntryGcdInformation(), GetMemoryMapList(), GetPEHeaders(), GetStringFromHandle(), GetStringFromHandle2(), IdtHookInterrupt(), InstallEFITableScanner(), InstallEventScanner(), InstallSniffImage(), IsEventSignalQueueAddrResolved(), MemAllocate(), ParseConfiguration(), PickBestTextMode(), ProcessCommand(), ReadConfiguration(), ScanMemoryForExecutables(), ScreenGetResolution(), ScreenInit(), ScreenShowSplashLogo(), UnInstallEFITableScanner(), UnInstallEventScanner(), and UnInstallSniffImage().

74 {
75  VA_LIST VList;
76  CHAR8 LogBuffer[1024];
77 
78  VA_START(VList, FormatString);
79  AsciiVSPrint(LogBuffer, sizeof(LogBuffer)-1, FormatString, VList);
80  VA_END(VList);
81 
83 
84  PRINT_FUNC_ASCII(LogBuffer);
85  WriteLogFile(LogBuffer);
86 
88  ComPutString(LogBuffer);
89 
91 
92 }

Here is the call graph for this function:

VOID LogFullUnicode ( CHAR16 *  FormatString,
  ... 
)

Depending on the policy function writes the provided text data to screen, log file or serial port. (unicode version)

Parameters
FormatStringFormat string (printf style)
...Additional arguments
Return values
NONE

Definition at line 108 of file Logs.c.

References ASMEnterLock(), ASMLeaveLock(), gLogLock, PRINT_FUNC, and WriteLogFile16().

109 {
110  VA_LIST VList;
111  CHAR16 LogBuffer[1024];
112 
113  VA_START(VList, FormatString);
114  UnicodeVSPrint(LogBuffer, sizeof(LogBuffer)-1, FormatString, VList);
115  VA_END(VList);
116 
118 
119  PRINT_FUNC(LogBuffer);
120  WriteLogFile16(LogBuffer);
121 
123 }

Here is the call 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:

VOID* MemAllocate ( UINTN  Size)

Function allocates memory and fills it with zeros.

Parameters
SizeRequested size
Return values
PointerOn success function returns pointer to the newly allocated memory
NULLOn error

Definition at line 25 of file Memory.c.

References EFI_STATUS(), and LogFullAscii().

Referenced by AddImageToList(), DumpMemoryToFile(), GetAllEvents(), GetAllHandles(), GetAllHandlesWithDescription(), GetAllImagesWithDescription(), GetMemoryMapList(), ImageAllocateStruct(), and ReadConfiguration().

26 {
27  EFI_STATUS Status;
28  VOID *Mem;
29 
30  Status = gBS->AllocatePool(EfiRuntimeServicesData,
31  Size,
32  (VOID**)&Mem);
33 
34  if (EFI_ERROR(Status))
35  {
36 #if DEBUG_ON == 1
37  LogFullAscii("%a: Unable to allocate memory size = %08x # FATAL ERROR\r\n",
38  __FUNCTION__, Size);
39 #endif
40  ASSERT(!EFI_ERROR(Status));
41  return 0;
42  }
43 
44  gBS->SetMem(Mem, Size, 0);
45  return Mem;
46 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID MemCopy ( VOID *  Dest,
VOID *  Src,
UINTN  Size 
)

Function copies source memory to destination memory.

Parameters
DestPointer to destination memory
SrcPointer to source memory
SizeSize of data to copy
Return values
NONE

Definition at line 77 of file Memory.c.

Referenced by AddImageToList(), DumpMemoryToFile(), GetAllEvents(), GetArguments(), MemRead(), and ParseConfiguration().

78 {
79  gBS->CopyMem(Dest, Src, Size);
80 }

Here is the caller graph for this function:

VOID MemFree ( VOID *  Mem)

Function frees allocated memory.

Parameters
MemPointer to the allocated memory
Return values
NONE

Definition at line 58 of file Memory.c.

Referenced by AddImageToList(), DumpMemoryToFile(), FreeEvents(), FreeHandles(), FreeImages(), FreeMemMap(), GetAllEvents(), GetAllHandles(), GetAllHandlesWithDescription(), GetAllImagesWithDescription(), GetImagePathAndName(), GetMemoryMapList(), ImageAllocateStruct(), ImageFree(), and ReadConfiguration().

59 {
60  if (Mem)
61  gBS->FreePool(Mem);
62 
63 }

Here is the caller graph for this function:

EFI_STATUS MemRead ( VOID *  Dest,
VOID *  Src,
UINTN  Size 
)

Function reads selected portion (Size) of memory (Src) to Dest. In current states it uses CopyMem from BootServices but it can be freely changed to other "memcpy" implementation. Due to EFI memory characteristics you can probe all available memory without a page fault (at least in theory).

Parameters
DestPointer to destination memory
SrcPointer to source memory
SizeSize of data to copy
Return values
EFI_SUCCESS

Definition at line 117 of file Memory.c.

References MemCopy().

Referenced by ScanMemoryForExecutables().

118 {
119  switch (Size)
120  {
121  default:
122  MemCopy(Dest, Src, Size);
123  break;
124 
125  case 1:
126  *(UINT8*)Dest = *(UINT8*)Src;
127  break;
128 
129  case 2:
130  *(UINT16*)Dest = *(UINT16*)Src;
131  break;
132 
133  case 4:
134  *(UINT32*)Dest = *(UINT32*)Src;
135  break;
136 
137  case 8:
138  *(UINT64*)Dest = *(UINT64*)Src;
139  break;
140  }
141 
142 
143  return EFI_SUCCESS;
144 }

Here is the call graph for this function:

Here is the caller graph for this function:

VOID MemZero ( VOID *  Mem,
UINTN  Size 
)

Function zeros memory.

Parameters
MemPointer to destination memory
SizeSize of data to nullify
Return values
NONE

Definition at line 94 of file Memory.c.

Referenced by ComConsoleStart(), InstallEventScanner(), and ProcessCommand().

95 {
96  gBS->SetMem(Mem, Size, 0);
97 }

Here is the caller graph for this function:

EFI_STATUS OpenFile ( IN CHAR16 *  FilePathName,
IN UINT64  OpenMode,
OUT EFI_FILE_PROTOCOL **  File 
)

Referenced by DumpMemoryToFile(), InitializeLogFile(), and ReadConfiguration().

Here is the caller graph for this function:

EFI_STATUS ReadConfiguration ( CHAR16 *  ConfPath)

Function reads the configuration file. Currently the configuration file is only used for the bad addr filtering (not needed by vmware).

Parameters
ConfPathPath to the configuration path (unicode)
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 102 of file Conf.c.

References EFI_STATUS(), LogFileAscii(), LogFullAscii(), MAX_CONF_DATA, MemAllocate(), MemFree(), OpenFile(), and ParseConfiguration().

Referenced by EfiScannerEntryPoint().

103 {
104  EFI_STATUS Status;
105  EFI_FILE_PROTOCOL *File;
106  UINTN ConfSize;
107 
108  CHAR8 *ConfData;
109 #define MAX_CONF_DATA 512*10
110 
111 
112  // read the configuration file
113  Status = OpenFile(ConfPath, EFI_FILE_MODE_READ, &File);
114 
115  if (EFI_ERROR(Status))
116  {
117 
118 #if DEBUG_ON == 1
119  LogFullAscii("%a: unable to open configuration file, status = %08x\r\n",
120  __FUNCTION__, Status);
121 #endif
122 
123  return Status;
124  }
125 
126  ConfData = (CHAR8*)MemAllocate(MAX_CONF_DATA + 32);
127  if (!ConfData)
128  {
129  LogFileAscii("%a: MemAllocate returned error!\r\n", __FUNCTION__);
130  File->Close(File);
131  return EFI_NOT_FOUND;
132  }
133 
134  ConfSize = MAX_CONF_DATA;
135  Status = File->Read(File, &ConfSize, ConfData);
136  File->Close(File);
137 
138  ParseConfiguration(ConfData, ConfSize);
139 
140  MemFree(ConfData);
141  return EFI_SUCCESS;
142 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS RedirectConsole ( VOID  )
EFI_STATUS ResetConsole ( VOID  )
EFI_STATUS ScanMemoryForExecutables ( VOID  )

Function scans memory for Portable Executable files and dumps them to file. It can cause machine freeze on custom mobos.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 121 of file DumpMem.c.

References DumpPEFile(), DumpTEFile(), EFI_STATUS(), FindImageByAddr(), FreeImages(), GetAllImagesWithDescription(), IsBadAddress(), LogFullAscii(), MEM_END_PROBE, MEM_START_PROBE, MemRead(), and TE_SIGNATURE.

Referenced by DrawBoxAndMenu(), and TestDumpHandles().

122 {
123  EFI_STATUS Status;
124  ULONG32 MemProbe;
125 
126  image_entry_list *ImageList;
127  image_entry *ImageEntry;
128 
129  C_PTR MemStart;
130  C_PTR MemEnd;
131  C_PTR NewAddr;
132 
133 
134  LogFullAscii(": Probing memory for executables...\r\n");
135 
136  ImageList = GetAllImagesWithDescription(NULL, FALSE);
137  if (!ImageList)
138  return EFI_NOT_FOUND;
139 
140 
141  // I have tried various tricks to pass the system-freeze
142  // effect which happens while probing specific memory addresses
143  // on mac and asrock mobo. I have tried hooking page fault
144  // and general protection fault handlers however they are not
145  // even executed - machine just freezes that is all.
146  // At this point it would be probably best to create some sort of
147  // black list of addresses although on the other hand
148  // it is still far from perfect solution. Additionally maybe
149  // the user should try dumping the memory map without the
150  // "ReservedMemory" type since it seems this is the only type
151  // causes those problems.
152  // "Memory mapped hardware that causes the computer to freeze
153  // when your memory probe steps on it"
154 
155  // asrock fails:
156  // 0xcf800000 - 0xdfa10000 (0xdf9ffff8)
157  // 0xf7500000 - 0xf7600000
158  // it took 14hours on virtualbox to parse entire 4gb range
159 
160 
161  MemEnd = MEM_END_PROBE;
162  for (MemStart = MEM_START_PROBE; MemStart < MemEnd; MemStart++)
163  {
164 
165 #if CHECK_BAD_ADDRS == 1
166  NewAddr = IsBadAddress(MemStart);
167 
168  if (NewAddr)
169  {
170 #if DEBUG_ON == 1
171  LogFullAscii("%a: changing Addr=%016lx to %016lx because it was found in the bad addr list!\r\n",
172  __FUNCTION__, (MAX_PTR)MemStart, (MAX_PTR)NewAddr);
173 #endif
174 
175  MemStart = NewAddr - 1;
176  continue;
177  }
178 #endif
179 
180  //
181  // On mac mini probing ~0x8b800000 causes machine hang
182  //
183  // On vmware it causes panic when reaching the PCI space (?)
184  // - W110: MONITOR PANIC: vcpu-0:NOT_IMPLEMENTED devices/pci/pci_monitor.c:243
185  // apparently this happens when we are trying to read 32bit value across page boundaries
186  // so lets skip such cases. (0xE2078FFD was one of such regions)
187 
188  if ((MemStart & EFI_PAGE_MASK) >= 0xFFC)
189  {
190  MemStart = MemStart + (EFI_PAGE_MASK - (MemStart & EFI_PAGE_MASK));
191  continue;
192  }
193 
194 
195 #if DEBUG_ON == 1
196  if (((ULONG32)MemStart & 0xFFFFF) == 0)
197  LogFullAscii("%a: scanning %llx\r\n", __FUNCTION__, (MAX_PTR)MemStart);
198 #endif
199 
200  Status = MemRead(&MemProbe, (VOID*)MemStart, sizeof(MemProbe));
201 
202  // MZ signature
203  if (MemProbe == 0x00005a4d)
204  {
205  ImageEntry = FindImageByAddr(ImageList, MemStart);
206 
207  if (!ImageEntry)
208  {
209  LogFullAscii("Found MZ signature at: %016lx, hidden executable? \r\n", (MAX_PTR)MemStart);
210  DumpPEFile(MemStart);
211  }
212  else
213  {
214  LogFullAscii("Found MZ signature at: %016lx, not hidden. \r\n", (MAX_PTR)MemStart);
215  DumpPEFile(MemStart);
216  }
217  }
218  // TE signature
219  else if ((USHORT)MemProbe == TE_SIGNATURE)
220  {
221  ImageEntry = FindImageByAddr(ImageList, MemStart);
222 
223  if (!ImageEntry)
224  {
225  LogFullAscii("Found TE signature at: %016lx, hidden executable? \r\n", (MAX_PTR)MemStart);
226  DumpTEFile(MemStart);
227  }
228  else
229  {
230  LogFullAscii("Found TE signature at: %016lx, not hidden. \r\n", (MAX_PTR)MemStart);
231  DumpTEFile(MemStart);
232  }
233  }
234 
235  }
236 
237  LogFullAscii("Scanning memory done! \r\n");
238  FreeImages(ImageList);
239 
240  return EFI_SUCCESS;
241 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS ScreenShowSplashLogo ( VOID  )

Function shows the main logo on the screen (for 5 seconds) and then switches back to console mode.

Definition at line 295 of file Screen.c.

References _GIMAGE::Data, EFI_STATUS(), _GIMAGE::Height, ImageLoadBMPFromMem(), LogFullAscii(), logo, ScreenClearToColor(), ScreenDrawImage(), ScreenEnableGraphicsMode(), ScreenHeightProbed, ScreenInit(), ScreenWidthProbed, TICKS_PER_MS, and _GIMAGE::Width.

Referenced by MainLoop(), and TestDumpHandles().

296 {
297  EFI_STATUS Status;
298  GIMAGE *Image;
299  UINTN x, y;
300 
301 
302  Status = ScreenInit();
303  if (EFI_ERROR(Status))
304  {
305  LogFullAscii("ScreenShowSplashLogo: unable to initialize screen!\r\n");
306  return EFI_NOT_FOUND;
307  }
308 
310 
311  Image = ImageLoadBMPFromMem((UINT8*)&logo, sizeof(logo));
312  if (!Image)
313  {
314  LogFullAscii("ScreenShowSplashLogo: unable to load splash image!\r\n");
315  return EFI_NOT_FOUND;
316  }
317 
318 
319  // clear screen to the color of first pixel
320  ScreenClearToColor(&Image->Data[0]);
321 
322  // draw it
323  x = (ScreenWidthProbed/2) - (Image->Width/2);
324  y = (ScreenHeightProbed/2) - (Image->Height/2);
325 
326  ScreenDrawImage(Image, x, y);
327 
328  // sleep for 5 sec (5000000 us)
329  gBS->Stall(500*TICKS_PER_MS);
330 
331  // switch back to console mode
333 
334  return EFI_SUCCESS;
335 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS ScreenTest ( VOID  )
VOID test_write ( VOID  )
VOID TestDumpHandles ( VOID  )

Definition at line 1097 of file Images.c.

References CheckImagesFunctionPointers(), ContextX64Test(), DumpAllEvents(), DumpAllHandles(), DumpAllImages(), DumpGDT(), DumpIDT(), FreeHandles(), FreeImages(), GetAllEvents(), GetAllHandlesWithDescription(), GetAllImagesWithDescription(), InstallEventScanner(), InstallSniffImage(), MyModImageNotify(), MyNewEventCallback(), MyNewImageNotify(), PRINT_FUNC, ScanMemoryForExecutables(), and ScreenShowSplashLogo().

1098 {
1099 
1100  handle_entry_list *HandleList;
1101  image_entry_list *ImageList;
1102  event_entry_list *EventList;
1103 
1105 
1106  HandleList = GetAllHandlesWithDescription();
1107  if (!HandleList)
1108  {
1109  PRINT_FUNC(L"TestDumpHandles: error executing GetAllHandlesWithDescription\r\n");
1110  return;
1111  }
1112 
1113 
1114  ImageList = GetAllImagesWithDescription(HandleList, TRUE);
1115  if (!ImageList)
1116  {
1117  PRINT_FUNC(L"TestDumpHandles: error executing GetAllImagesWithDescription\r\n");
1118  return;
1119  }
1120 
1121 
1122  DumpAllHandles(HandleList);
1123 
1124  DumpAllImages(ImageList, TRUE);
1125  CheckImagesFunctionPointers(ImageList);
1126 
1127  FreeImages(ImageList);
1128  FreeHandles(HandleList);
1129 
1130 
1131  // ImageList = GetAllImagesWithDescription(NULL, TRUE);
1132  //DumpAllImages(ImageList, TRUE);
1133 
1134 
1135  EventList = GetAllEvents();
1136  if (!EventList)
1137  {
1138  PRINT_FUNC(L"TestDumpHandles: error executing GetAllEvents \r\n");
1139  return;
1140  }
1141 
1142  DumpAllEvents(EventList);
1143 
1144  ContextX64Test();
1145 
1146  DumpIDT();
1147  DumpGDT();
1148 
1150 
1151  //DisplayDumpMemoryMap(TRUE);
1153 
1155 
1156 }

Here is the call graph for this function:

EFI_STATUS UnInstallEFITableScanner ( VOID  )

function uninstalls the scanner event

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 471 of file TableMonitor.c.

References gScannerEvent, and LogFullAscii().

472 {
473  LogFullAscii(": UnInstalling the EFI table scanner\r\n");
474 
475  if (gScannerEvent)
476  gBS->CloseEvent(gScannerEvent);
477 
478  return EFI_SUCCESS;
479 }

Here is the call graph for this function:

EFI_STATUS UnInstallEventScanner ( VOID  )

Function uninstalls EFI timer which checks the events for changes

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 188 of file EventsScanner.c.

References FreeEvents(), gEventScannerEvent, and LogFullAscii().

189 {
190  LogFullAscii(": UnInstalling the event scanner\r\n");
191 
192  if (gEventScannerEvent)
193  gBS->CloseEvent(gEventScannerEvent);
194 
195 
196  if (gEventList)
197  {
199  gEventList = 0;
200  }
201 
202  return EFI_SUCCESS;
203 }

Here is the call graph for this function:

EFI_STATUS UnInstallSniffImage ( VOID  )

Function uninstalls the image sniffer.

Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 305 of file SniffImage.c.

References FreeImages(), gOrg_LoadImage, gSetExitBootServicesEvent, and LogFullAscii().

306 {
307  LogFullAscii(": Uninstalling image sniffer...");
308 
309  gBS->LoadImage = gOrg_LoadImage;
310  //gBS->ExitBootServices = org_ExitBootServices;
311 
313  gBS->CloseEvent(gSetExitBootServicesEvent);
314 
315  LogFullAscii("done.\r\n");
316 
317 
319  gImageList = 0;
320  return EFI_SUCCESS;
321 }

Here is the call graph for this function:

EFI_STATUS WriteLogFile ( CHAR8 *  Data)

Function writes ascii null-terminated string to the log file.

Parameters
DataAscii string to write.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 256 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, and _policy::OpUseLog.

Referenced by LogFileAscii(), and LogFullAscii().

257 {
258  UINTN Size;
259 
260  // check the policy first
262  return EFI_NOT_FOUND;
263 
264 
265  Size = strlen(Data);
266  gLogFile->Write(gLogFile, &Size, Data);
267  gLogFile->Flush(gLogFile);
268 
269  return EFI_SUCCESS;
270 }

Here is the caller graph for this function:

EFI_STATUS WriteLogFile16 ( CHAR16 *  Data)

Function writes unicode string to the log file.

Parameters
DataUnicode string to write.
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 225 of file FileSystemWrap.c.

References gEfiScannerPolicy, gLogFile, and _policy::OpUseLog.

Referenced by LogFullUnicode().

226 {
227  CHAR8 Buffer[2014];
228  UINTN Size;
229 
230  // check the policy first
232  return EFI_NOT_FOUND;
233 
234 
235 
236  UnicodeStrToAsciiStr(Data, Buffer);
237 
238  Size = strlen(Buffer);
239  gLogFile->Write(gLogFile, &Size, Buffer);
240  gLogFile->Flush(gLogFile);
241 
242  return EFI_SUCCESS;
243 }

Here is the caller graph for this function:

Variable Documentation