Untitled
unknown
plain_text
2 years ago
2.6 kB
27
Indexable
#include <efi.h>
#include <efilib.h>
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
EFI_STATUS Status;
// Initialize the EFI library
InitializeLib(ImageHandle, SystemTable);
// Get the handle to the device block protocol
EFI_HANDLE *HandleBuffer;
UINTN HandleCount;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &HandleCount, &HandleBuffer);
if (EFI_ERROR(Status)) {
Print(L"Failed to locate block protocol handles\n");
return Status;
}
// Loop through each block protocol handle
for (UINTN i = 0; i < HandleCount; i++) {
EFI_BLOCK_IO_PROTOCOL *BlockIo;
Status = gBS->HandleProtocol(HandleBuffer[i], &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
if (EFI_ERROR(Status)) {
Print(L"Failed to get Block IO protocol\n");
continue;
}
// Accessing the partitions - assuming it's a GPT partition table
// You might need to handle different partition table types here
EFI_PARTITION_TABLE_HEADER *PartitionTable;
Status = uefi_call_wrapper(BlockIo->ReadBlocks, 5, BlockIo, BlockIo->Media->MediaId, 1, sizeof(EFI_PARTITION_TABLE_HEADER), (VOID **)&PartitionTable);
if (EFI_ERROR(Status)) {
Print(L"Failed to read partition table\n");
continue;
}
// Get the number of partitions
UINT32 NumberOfPartitions = PartitionTable->NumberOfPartitionEntries;
// Assuming partition entries are contiguous in memory
EFI_PARTITION_ENTRY *PartitionEntry = (EFI_PARTITION_ENTRY *)(PartitionTable + 1);
// Loop through all partition entries
for (UINTN j = 0; j < NumberOfPartitions; j++) {
EFI_LBA StartLBA = PartitionEntry[j].StartingLBA;
EFI_LBA EndLBA = PartitionEntry[j].EndingLBA;
// Loop through FAT32 partition blocks and print the first 200 bytes
for (EFI_LBA LBA = StartLBA; LBA < EndLBA; LBA++) {
CHAR8 Buffer[512];
Status = uefi_call_wrapper(BlockIo->ReadBlocks, 5, BlockIo, BlockIo->Media->MediaId, LBA, 512, Buffer);
if (EFI_ERROR(Status)) {
Print(L"Failed to read block\n");
break;
}
// Print the first 200 bytes
for (UINTN k = 0; k < 200; k++) {
Print(L"%02x ", Buffer[k]);
}
}
}
}
FreePool(HandleBuffer);
return EFI_SUCCESS;
}Editor is loading...
Leave a Comment