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.
|
|
|
|
*/
|
|
|
|
|
2013-10-15 23:19:15 +08:00
|
|
|
#include <QObject>
|
2013-10-08 15:07:03 +08:00
|
|
|
#include "ffs.h"
|
|
|
|
|
2015-01-31 22:46:17 +08:00
|
|
|
const QVector<QByteArray> FFSv2Volumes =
|
|
|
|
QVector<QByteArray>()
|
|
|
|
<< 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;
|
|
|
|
|
2015-02-13 03:51:23 +08:00
|
|
|
const QVector<QByteArray> FFSv3Volumes =
|
|
|
|
QVector<QByteArray>()
|
|
|
|
<< EFI_FIRMWARE_FILE_SYSTEM3_GUID;
|
|
|
|
|
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
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
UINT8 calculateChecksum8(const UINT8* buffer, UINT32 bufferSize)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2014-07-25 07:59:51 +08:00
|
|
|
if (!buffer)
|
2013-12-05 04:27:12 +08:00
|
|
|
return 0;
|
2014-07-25 07:59:51 +08:00
|
|
|
|
2013-12-05 04:27:12 +08:00
|
|
|
UINT8 counter = 0;
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2014-07-25 07:59:51 +08:00
|
|
|
while (bufferSize--)
|
2013-10-08 15:07:03 +08:00
|
|
|
counter += buffer[bufferSize];
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2015-03-13 14:48:53 +08:00
|
|
|
return (UINT8)(0x100 - counter);
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2014-07-25 07:59:51 +08:00
|
|
|
if (!buffer)
|
2013-12-05 04:27:12 +08:00
|
|
|
return 0;
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2013-12-05 04:27:12 +08:00
|
|
|
UINT16 counter = 0;
|
|
|
|
UINT32 index = 0;
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2013-12-05 04:27:12 +08:00
|
|
|
bufferSize /= sizeof(UINT16);
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2013-12-05 04:27:12 +08:00
|
|
|
for (; index < bufferSize; index++) {
|
2014-07-25 07:59:51 +08:00
|
|
|
counter = (UINT16)(counter + buffer[index]);
|
2013-12-05 04:27:12 +08:00
|
|
|
}
|
2013-11-19 03:11:22 +08:00
|
|
|
|
2015-03-13 14:48:53 +08:00
|
|
|
return (UINT16)(0x10000 - counter);
|
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
|
|
|
}
|
|
|
|
|
2015-03-13 14:48:53 +08:00
|
|
|
QString guidToQString(const EFI_GUID & guid)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
|
|
|
return QString("%1-%2-%3-%4%5-%6%7%8%9%10%11")
|
2015-03-13 14:48:53 +08:00
|
|
|
.arg(*(const UINT32*)&guid.Data[0], 8, 16, QChar('0'))
|
|
|
|
.arg(*(const UINT16*)&guid.Data[4], 4, 16, QChar('0'))
|
|
|
|
.arg(*(const UINT16*)&guid.Data[6], 4, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[8], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[9], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[10], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[11], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[12], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[13], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[14], 2, 16, QChar('0'))
|
|
|
|
.arg(guid.Data[15], 2, 16, QChar('0')).toUpper();
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QString fileTypeToQString(const UINT8 type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2015-01-31 22:00:00 +08:00
|
|
|
case EFI_FV_FILETYPE_RAW: return QObject::tr("Raw");
|
|
|
|
case EFI_FV_FILETYPE_FREEFORM: return QObject::tr("Freeform");
|
|
|
|
case EFI_FV_FILETYPE_SECURITY_CORE: return QObject::tr("SEC core");
|
|
|
|
case EFI_FV_FILETYPE_PEI_CORE: return QObject::tr("PEI core");
|
|
|
|
case EFI_FV_FILETYPE_DXE_CORE: return QObject::tr("DXE core");
|
|
|
|
case EFI_FV_FILETYPE_PEIM: return QObject::tr("PEI module");
|
|
|
|
case EFI_FV_FILETYPE_DRIVER: return QObject::tr("DXE driver");
|
|
|
|
case EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER: return QObject::tr("Combined PEI/DXE");
|
|
|
|
case EFI_FV_FILETYPE_APPLICATION: return QObject::tr("Application");
|
|
|
|
case EFI_FV_FILETYPE_SMM: return QObject::tr("SMM module");
|
|
|
|
case EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE: return QObject::tr("Volume image");
|
|
|
|
case EFI_FV_FILETYPE_COMBINED_SMM_DXE: return QObject::tr("Combined SMM/DXE");
|
|
|
|
case EFI_FV_FILETYPE_SMM_CORE: return QObject::tr("SMM core");
|
|
|
|
case EFI_FV_FILETYPE_PAD: return QObject::tr("Pad");
|
|
|
|
default: return QObject::tr("Unknown");
|
2013-10-08 15:07:03 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QString sectionTypeToQString(const UINT8 type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2015-01-31 22:00:00 +08:00
|
|
|
case EFI_SECTION_COMPRESSION: return QObject::tr("Compressed");
|
|
|
|
case EFI_SECTION_GUID_DEFINED: return QObject::tr("GUID defined");
|
|
|
|
case EFI_SECTION_DISPOSABLE: return QObject::tr("Disposable");
|
2015-02-06 16:47:19 +08:00
|
|
|
case EFI_SECTION_PE32: return QObject::tr("PE32 image");
|
2015-01-31 22:00:00 +08:00
|
|
|
case EFI_SECTION_PIC: return QObject::tr("PIC image");
|
|
|
|
case EFI_SECTION_TE: return QObject::tr("TE image");
|
|
|
|
case EFI_SECTION_DXE_DEPEX: return QObject::tr("DXE dependency");
|
|
|
|
case EFI_SECTION_VERSION: return QObject::tr("Version");
|
2015-03-13 14:48:53 +08:00
|
|
|
case EFI_SECTION_USER_INTERFACE: return QObject::tr("UI");
|
2015-01-31 22:00:00 +08:00
|
|
|
case EFI_SECTION_COMPATIBILITY16: return QObject::tr("16-bit image");
|
|
|
|
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: return QObject::tr("Volume image");
|
|
|
|
case EFI_SECTION_FREEFORM_SUBTYPE_GUID: return QObject::tr("Freeform subtype GUID");
|
|
|
|
case EFI_SECTION_RAW: return QObject::tr("Raw");
|
|
|
|
case EFI_SECTION_PEI_DEPEX: return QObject::tr("PEI dependency");
|
|
|
|
case EFI_SECTION_SMM_DEPEX: return QObject::tr("SMM dependency");
|
2015-02-13 03:51:23 +08:00
|
|
|
case INSYDE_SECTION_POSTCODE: return QObject::tr("Insyde postcode");
|
2015-01-31 22:00:00 +08:00
|
|
|
case SCT_SECTION_POSTCODE: return QObject::tr("SCT postcode");
|
|
|
|
default: return QObject::tr("Unknown");
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
2013-10-09 16:30:58 +08:00
|
|
|
}
|
|
|
|
|