2013-10-08 15:07:03 +08:00
|
|
|
/* ffs.cpp
|
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
|
2013-10-08 15:07:03 +08:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ffs.h"
|
2017-02-14 14:39:16 +08:00
|
|
|
#include "guiddatabase.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2016-03-01 16:52:25 +08:00
|
|
|
// This is a workaround for the lack of static std::vector initializer before C++11
|
2016-06-26 11:54:21 +08:00
|
|
|
const UByteArray FFSv2VolumesInt[] = {
|
2016-03-01 15:20:44 +08:00
|
|
|
EFI_FIRMWARE_FILE_SYSTEM_GUID,
|
|
|
|
EFI_FIRMWARE_FILE_SYSTEM2_GUID,
|
|
|
|
EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID,
|
|
|
|
EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM2_GUID,
|
|
|
|
EFI_INTEL_FILE_SYSTEM_GUID,
|
|
|
|
EFI_INTEL_FILE_SYSTEM2_GUID,
|
|
|
|
EFI_SONY_FILE_SYSTEM_GUID
|
2016-03-01 16:52:25 +08:00
|
|
|
};
|
|
|
|
// This number must be updated if the array above is grown
|
|
|
|
#define FFSv2VolumesIntSize 7
|
2016-06-26 11:54:21 +08:00
|
|
|
const std::vector<UByteArray> FFSv2Volumes(FFSv2VolumesInt, FFSv2VolumesInt + FFSv2VolumesIntSize);
|
2016-03-01 16:52:25 +08:00
|
|
|
// Luckily, FFSv3Volumes now only has 1 element
|
2016-06-26 11:54:21 +08:00
|
|
|
const std::vector<UByteArray> FFSv3Volumes(1, EFI_FIRMWARE_FILE_SYSTEM3_GUID);
|
2015-02-13 03:51:23 +08:00
|
|
|
|
2014-07-25 07:59:51 +08:00
|
|
|
const UINT8 ffsAlignmentTable[] =
|
|
|
|
{ 0, 4, 7, 9, 10, 12, 15, 16 };
|
2013-10-08 15:07:03 +08:00
|
|
|
|
|
|
|
VOID uint32ToUint24(UINT32 size, UINT8* ffsSize)
|
|
|
|
{
|
2014-07-25 07:59:51 +08:00
|
|
|
ffsSize[2] = (UINT8)((size) >> 16);
|
|
|
|
ffsSize[1] = (UINT8)((size) >> 8);
|
|
|
|
ffsSize[0] = (UINT8)((size));
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
UINT32 uint24ToUint32(const UINT8* ffsSize)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2015-03-13 14:48:53 +08:00
|
|
|
return *(UINT32*)ffsSize & 0x00FFFFFF;
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 14:39:16 +08:00
|
|
|
UString guidToUString(const EFI_GUID & guid, bool convertToString)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2017-02-14 14:39:16 +08:00
|
|
|
if (convertToString) {
|
|
|
|
UString readableName = guidDatabaseLookup(guid);
|
|
|
|
if (!readableName.isEmpty())
|
|
|
|
return readableName;
|
|
|
|
}
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
return usprintf("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
|
2016-10-28 00:31:15 +08:00
|
|
|
guid.Data1,
|
|
|
|
guid.Data2,
|
|
|
|
guid.Data3,
|
|
|
|
guid.Data4[0],
|
|
|
|
guid.Data4[1],
|
|
|
|
guid.Data4[2],
|
|
|
|
guid.Data4[3],
|
|
|
|
guid.Data4[4],
|
|
|
|
guid.Data4[5],
|
|
|
|
guid.Data4[6],
|
|
|
|
guid.Data4[7]);
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UString fileTypeToUString(const UINT8 type)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2016-06-26 11:54:21 +08:00
|
|
|
case EFI_FV_FILETYPE_RAW: return UString("Raw");
|
|
|
|
case EFI_FV_FILETYPE_FREEFORM: return UString("Freeform");
|
|
|
|
case EFI_FV_FILETYPE_SECURITY_CORE: return UString("SEC core");
|
|
|
|
case EFI_FV_FILETYPE_PEI_CORE: return UString("PEI core");
|
|
|
|
case EFI_FV_FILETYPE_DXE_CORE: return UString("DXE core");
|
|
|
|
case EFI_FV_FILETYPE_PEIM: return UString("PEI module");
|
|
|
|
case EFI_FV_FILETYPE_DRIVER: return UString("DXE driver");
|
|
|
|
case EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER: return UString("Combined PEI/DXE");
|
|
|
|
case EFI_FV_FILETYPE_APPLICATION: return UString("Application");
|
2016-10-28 00:31:15 +08:00
|
|
|
case EFI_FV_FILETYPE_MM: return UString("SMM module");
|
2016-06-26 11:54:21 +08:00
|
|
|
case EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE: return UString("Volume image");
|
2016-10-28 00:31:15 +08:00
|
|
|
case EFI_FV_FILETYPE_COMBINED_MM_DXE: return UString("Combined SMM/DXE");
|
|
|
|
case EFI_FV_FILETYPE_MM_CORE: return UString("SMM core");
|
|
|
|
case EFI_FV_FILETYPE_MM_STANDALONE: return UString("MM standalone module");
|
|
|
|
case EFI_FV_FILETYPE_MM_CORE_STANDALONE: return UString("MM standalone core");
|
2016-06-26 11:54:21 +08:00
|
|
|
case EFI_FV_FILETYPE_PAD: return UString("Pad");
|
|
|
|
default: return UString("Unknown");
|
2013-10-08 15:07:03 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UString sectionTypeToUString(const UINT8 type)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2016-06-26 11:54:21 +08:00
|
|
|
case EFI_SECTION_COMPRESSION: return UString("Compressed");
|
|
|
|
case EFI_SECTION_GUID_DEFINED: return UString("GUID defined");
|
|
|
|
case EFI_SECTION_DISPOSABLE: return UString("Disposable");
|
|
|
|
case EFI_SECTION_PE32: return UString("PE32 image");
|
|
|
|
case EFI_SECTION_PIC: return UString("PIC image");
|
|
|
|
case EFI_SECTION_TE: return UString("TE image");
|
|
|
|
case EFI_SECTION_DXE_DEPEX: return UString("DXE dependency");
|
|
|
|
case EFI_SECTION_VERSION: return UString("Version");
|
|
|
|
case EFI_SECTION_USER_INTERFACE: return UString("UI");
|
|
|
|
case EFI_SECTION_COMPATIBILITY16: return UString("16-bit image");
|
|
|
|
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: return UString("Volume image");
|
|
|
|
case EFI_SECTION_FREEFORM_SUBTYPE_GUID: return UString("Freeform subtype GUID");
|
|
|
|
case EFI_SECTION_RAW: return UString("Raw");
|
|
|
|
case EFI_SECTION_PEI_DEPEX: return UString("PEI dependency");
|
2016-10-28 00:31:15 +08:00
|
|
|
case EFI_SECTION_MM_DEPEX: return UString("MM dependency");
|
2016-06-26 11:54:21 +08:00
|
|
|
case INSYDE_SECTION_POSTCODE: return UString("Insyde postcode");
|
|
|
|
case PHOENIX_SECTION_POSTCODE: return UString("Phoenix postcode");
|
|
|
|
default: return UString("Unknown");
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
2013-10-09 16:30:58 +08:00
|
|
|
}
|
|
|
|
|