2015-03-13 14:48:53 +08:00
|
|
|
/* ffsparser.h
|
|
|
|
|
2017-12-11 09:56:00 +08:00
|
|
|
Copyright (c) 2017, LongSoft. All rights reserved.
|
2015-03-13 14:48:53 +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.
|
|
|
|
*/
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#ifndef FFSPARSER_H
|
|
|
|
#define FFSPARSER_H
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2016-03-01 15:20:44 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2016-10-10 14:05:04 +08:00
|
|
|
#include "basetypes.h"
|
2016-06-26 11:54:21 +08:00
|
|
|
#include "ustring.h"
|
|
|
|
#include "ubytearray.h"
|
2016-02-02 09:08:08 +08:00
|
|
|
#include "treemodel.h"
|
2022-08-29 14:23:38 +08:00
|
|
|
#include "intel_microcode.h"
|
2022-12-24 12:24:15 +08:00
|
|
|
#include "ffs.h"
|
2022-08-29 14:23:38 +08:00
|
|
|
#include "fitparser.h"
|
2017-10-12 13:59:23 +08:00
|
|
|
|
2022-12-24 12:24:15 +08:00
|
|
|
// Region info
|
|
|
|
typedef struct REGION_INFO_ {
|
|
|
|
UINT32 offset = 0;
|
|
|
|
UINT32 length = 0;
|
|
|
|
UINT8 type = 0;
|
|
|
|
UByteArray data;
|
|
|
|
friend bool operator< (const struct REGION_INFO_ & lhs, const struct REGION_INFO_ & rhs) { return lhs.offset < rhs.offset; }
|
|
|
|
} REGION_INFO;
|
|
|
|
|
|
|
|
// BPDT partition info
|
|
|
|
typedef struct BPDT_PARTITION_INFO_ {
|
|
|
|
BPDT_ENTRY ptEntry = {};
|
|
|
|
UINT8 type = 0;
|
|
|
|
UModelIndex index;
|
|
|
|
friend bool operator< (const struct BPDT_PARTITION_INFO_ & lhs, const struct BPDT_PARTITION_INFO_ & rhs) { return lhs.ptEntry.Offset < rhs.ptEntry.Offset; }
|
|
|
|
} BPDT_PARTITION_INFO;
|
|
|
|
|
|
|
|
// CPD partition info
|
|
|
|
typedef struct CPD_PARTITION_INFO_ {
|
|
|
|
CPD_ENTRY ptEntry = {};
|
|
|
|
UINT8 type = 0;
|
|
|
|
bool hasMetaData = false;
|
|
|
|
UModelIndex index;
|
|
|
|
friend bool operator< (const struct CPD_PARTITION_INFO_ & lhs, const struct CPD_PARTITION_INFO_ & rhs) { return lhs.ptEntry.Offset.Offset < rhs.ptEntry.Offset.Offset; }
|
|
|
|
} CPD_PARTITION_INFO;
|
|
|
|
|
|
|
|
// Protected range
|
2022-08-29 14:23:38 +08:00
|
|
|
typedef struct PROTECTED_RANGE_ {
|
2017-10-12 13:59:23 +08:00
|
|
|
UINT32 Offset;
|
|
|
|
UINT32 Size;
|
2022-08-29 14:23:38 +08:00
|
|
|
UINT16 AlgorithmId;
|
2017-10-12 13:59:23 +08:00
|
|
|
UINT8 Type;
|
2022-08-29 14:23:38 +08:00
|
|
|
UINT8 : 8;
|
2017-10-12 13:59:23 +08:00
|
|
|
UByteArray Hash;
|
2022-08-29 14:23:38 +08:00
|
|
|
} PROTECTED_RANGE;
|
|
|
|
|
|
|
|
#define PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB 0x01
|
|
|
|
#define PROTECTED_RANGE_INTEL_BOOT_GUARD_POST_IBB 0x02
|
|
|
|
#define PROTECTED_RANGE_INTEL_BOOT_GUARD_OBB 0x03
|
|
|
|
#define PROTECTED_RANGE_VENDOR_HASH_PHOENIX 0x04
|
|
|
|
#define PROTECTED_RANGE_VENDOR_HASH_AMI_V1 0x05
|
|
|
|
#define PROTECTED_RANGE_VENDOR_HASH_AMI_V2 0x06
|
|
|
|
#define PROTECTED_RANGE_VENDOR_HASH_AMI_V3 0x07
|
|
|
|
#define PROTECTED_RANGE_VENDOR_HASH_MICROSOFT_PMDA 0x08
|
|
|
|
|
|
|
|
class FitParser;
|
2017-12-11 09:56:00 +08:00
|
|
|
class NvramParser;
|
|
|
|
class MeParser;
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2016-03-01 15:20:44 +08:00
|
|
|
class FfsParser
|
2015-03-13 14:48:53 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-12-11 09:56:00 +08:00
|
|
|
// Constructor and destructor
|
|
|
|
FfsParser(TreeModel* treeModel);
|
|
|
|
~FfsParser();
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2021-10-07 23:51:39 +08:00
|
|
|
// Obtain parser messages
|
2017-12-11 09:56:00 +08:00
|
|
|
std::vector<std::pair<UString, UModelIndex> > getMessages() const;
|
2017-07-09 03:31:57 +08:00
|
|
|
// Clear messages
|
2016-04-15 02:36:59 +08:00
|
|
|
void clearMessages() { messagesVector.clear(); }
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2017-07-09 03:31:57 +08:00
|
|
|
// Parse firmware image
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS parse(const UByteArray &buffer);
|
2016-03-01 15:20:44 +08:00
|
|
|
|
2016-07-15 03:22:51 +08:00
|
|
|
// Obtain parsed FIT table
|
2022-08-29 14:23:38 +08:00
|
|
|
std::vector<std::pair<std::vector<UString>, UModelIndex> > getFitTable() const;
|
2015-07-07 21:57:41 +08:00
|
|
|
|
2018-10-08 17:58:12 +08:00
|
|
|
// Obtain Security Info
|
2022-08-29 14:23:38 +08:00
|
|
|
UString getSecurityInfo() const;
|
2017-10-12 13:59:23 +08:00
|
|
|
|
2017-07-09 03:31:57 +08:00
|
|
|
// Obtain offset/address difference
|
|
|
|
UINT64 getAddressDiff() { return addressDiff; }
|
|
|
|
|
2021-10-07 23:51:39 +08:00
|
|
|
// Output some info to stdout
|
|
|
|
void outputInfo(void);
|
|
|
|
|
2015-03-13 14:48:53 +08:00
|
|
|
private:
|
|
|
|
TreeModel *model;
|
2016-06-26 11:54:21 +08:00
|
|
|
std::vector<std::pair<UString, UModelIndex> > messagesVector;
|
2018-05-08 23:42:16 +08:00
|
|
|
void msg(const UString & message, const UModelIndex & index = UModelIndex()) {
|
2016-06-26 11:54:21 +08:00
|
|
|
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
|
2016-04-18 21:10:07 +08:00
|
|
|
};
|
|
|
|
|
2022-08-29 14:23:38 +08:00
|
|
|
FitParser* fitParser;
|
2017-12-11 09:56:00 +08:00
|
|
|
NvramParser* nvramParser;
|
|
|
|
MeParser* meParser;
|
2016-11-03 03:40:38 +08:00
|
|
|
|
2017-10-12 13:59:23 +08:00
|
|
|
UByteArray openedImage;
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex lastVtf;
|
2018-04-30 13:33:19 +08:00
|
|
|
UINT32 imageBase;
|
2017-07-09 03:31:57 +08:00
|
|
|
UINT64 addressDiff;
|
2017-10-12 13:59:23 +08:00
|
|
|
|
2018-10-08 17:58:12 +08:00
|
|
|
UString securityInfo;
|
2022-08-29 14:23:38 +08:00
|
|
|
|
|
|
|
std::vector<PROTECTED_RANGE> protectedRanges;
|
|
|
|
UINT64 protectedRegionsBase;
|
|
|
|
UModelIndex dxeCore;
|
2016-10-10 14:05:04 +08:00
|
|
|
|
2016-07-15 03:22:51 +08:00
|
|
|
// First pass
|
|
|
|
USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2018-10-08 17:58:12 +08:00
|
|
|
USTATUS parseCapsule(const UByteArray & capsule, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2018-04-30 13:33:19 +08:00
|
|
|
USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
USTATUS parseGenericImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
|
2019-08-20 02:36:02 +08:00
|
|
|
USTATUS parseBpdtRegion(const UByteArray & region, const UINT32 localOffset, const UINT32 sbpdtOffsetFixup, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
USTATUS parseCpdRegion(const UByteArray & region, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2023-08-20 04:25:38 +08:00
|
|
|
USTATUS parseCpdExtensionsArea(const UModelIndex & index, const UINT32 localOffset);
|
2019-08-20 02:36:02 +08:00
|
|
|
USTATUS parseSignedPackageInfoData(const UModelIndex & index);
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS parseRawArea(const UModelIndex & index);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseVolumeHeader(const UByteArray & volume, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS parseVolumeBody(const UModelIndex & index);
|
2018-10-08 17:58:12 +08:00
|
|
|
USTATUS parseMicrocodeVolumeBody(const UModelIndex & index);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseFileHeader(const UByteArray & file, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS parseFileBody(const UModelIndex & index);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS parseSectionBody(const UModelIndex & index);
|
|
|
|
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseGbeRegion(const UByteArray & gbe, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
USTATUS parseMeRegion(const UByteArray & me, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
USTATUS parseBiosRegion(const UByteArray & bios, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
|
|
|
USTATUS parsePdrRegion(const UByteArray & pdr, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2019-09-05 08:07:18 +08:00
|
|
|
USTATUS parseDevExp1Region(const UByteArray & devExp1, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2017-12-11 09:56:00 +08:00
|
|
|
USTATUS parseGenericRegion(const UINT8 subtype, const UByteArray & region, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2016-06-26 11:54:21 +08:00
|
|
|
|
|
|
|
USTATUS parsePadFileBody(const UModelIndex & index);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseVolumeNonUefiData(const UByteArray & data, const UINT32 localOffset, const UModelIndex & index);
|
2016-06-26 11:54:21 +08:00
|
|
|
|
2016-07-16 13:02:33 +08:00
|
|
|
USTATUS parseSections(const UByteArray & sections, const UModelIndex & index, const bool insertIntoTree);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS parseCommonSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
|
|
|
USTATUS parseCompressedSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
|
|
|
USTATUS parseGuidedSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
|
|
|
USTATUS parseFreeformGuidedSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
|
|
|
USTATUS parseVersionSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
|
|
|
USTATUS parsePostcodeSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
|
2016-06-26 11:54:21 +08:00
|
|
|
|
|
|
|
USTATUS parseCompressedSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseGuidedSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseVersionSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseDepexSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseUiSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseRawSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parsePeImageSectionBody(const UModelIndex & index);
|
|
|
|
USTATUS parseTeImageSectionBody(const UModelIndex & index);
|
|
|
|
|
|
|
|
USTATUS parseAprioriRawSection(const UByteArray & body, UString & parsed);
|
2018-10-08 17:58:12 +08:00
|
|
|
USTATUS findNextRawAreaItem(const UModelIndex & index, const UINT32 localOffset, UINT8 & nextItemType, UINT32 & nextItemOffset, UINT32 & nextItemSize, UINT32 & nextItemAlternativeSize);
|
2022-10-07 20:40:20 +08:00
|
|
|
UINT32 getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion, const UINT8 revision);
|
2016-07-16 13:02:33 +08:00
|
|
|
UINT32 getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion);
|
2019-09-05 08:07:18 +08:00
|
|
|
|
|
|
|
USTATUS parseIntelMicrocodeHeader(const UByteArray & store, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
2023-01-30 07:13:37 +08:00
|
|
|
bool microcodeHeaderValid(const INTEL_MICROCODE_HEADER* ucodeHeader);
|
2016-06-26 11:54:21 +08:00
|
|
|
|
2022-08-29 14:23:38 +08:00
|
|
|
USTATUS parseVendorHashFile(const UByteArray & fileGuid, const UModelIndex & index);
|
|
|
|
|
2016-07-15 03:22:51 +08:00
|
|
|
// Second pass
|
|
|
|
USTATUS performSecondPass(const UModelIndex & index);
|
2019-01-07 21:05:57 +08:00
|
|
|
USTATUS addInfoRecursive(const UModelIndex & index);
|
|
|
|
USTATUS checkTeImageBase(const UModelIndex & index);
|
2022-08-29 14:23:38 +08:00
|
|
|
|
2017-10-12 13:59:23 +08:00
|
|
|
USTATUS checkProtectedRanges(const UModelIndex & index);
|
2022-08-29 14:23:38 +08:00
|
|
|
USTATUS markProtectedRangeRecursive(const UModelIndex & index, const PROTECTED_RANGE & range);
|
2017-10-12 13:59:23 +08:00
|
|
|
|
2019-07-25 01:30:59 +08:00
|
|
|
USTATUS parseResetVectorData();
|
2022-08-29 14:23:38 +08:00
|
|
|
|
2017-10-12 13:59:23 +08:00
|
|
|
#ifdef U_ENABLE_FIT_PARSING_SUPPORT
|
2022-08-29 14:23:38 +08:00
|
|
|
friend class FitParser; // Make FFS parsing routines accessible to FitParser
|
2017-10-12 13:59:23 +08:00
|
|
|
#endif
|
2017-12-11 09:56:00 +08:00
|
|
|
|
|
|
|
#ifdef U_ENABLE_NVRAM_PARSING_SUPPORT
|
|
|
|
friend class NvramParser; // Make FFS parsing routines accessible to NvramParser
|
|
|
|
#endif
|
2019-08-20 02:36:02 +08:00
|
|
|
|
|
|
|
#ifdef U_ENABLE_ME_PARSING_SUPPORT
|
|
|
|
friend class MeParser; // Make FFS parsing routines accessible to MeParser
|
|
|
|
#endif
|
2015-03-13 14:48:53 +08:00
|
|
|
};
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // FFSPARSER_H
|