2015-03-13 14:48:53 +08:00
|
|
|
/* ffsparser.h
|
|
|
|
|
2016-02-02 09:08:08 +08:00
|
|
|
Copyright (c) 2016, Nikolaj Schlej. 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"
|
2016-10-10 14:05:04 +08:00
|
|
|
#include "nvramparser.h"
|
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:
|
|
|
|
// Default constructor and destructor
|
2016-10-10 14:05:04 +08:00
|
|
|
FfsParser(TreeModel* treeModel) : model(treeModel), nvramParser(treeModel), capsuleOffsetFixup(0) {}
|
2016-04-15 02:36:59 +08:00
|
|
|
~FfsParser() {}
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2015-04-02 16:04:37 +08:00
|
|
|
// Returns messages
|
2016-10-10 14:05:04 +08:00
|
|
|
std::vector<std::pair<UString, UModelIndex> > getMessages() const {
|
|
|
|
std::vector<std::pair<UString, UModelIndex> > nvramVector = nvramParser.getMessages();
|
|
|
|
std::vector<std::pair<UString, UModelIndex> > resultVector = messagesVector;
|
2016-11-03 03:40:38 +08:00
|
|
|
resultVector.insert(resultVector.end(), nvramVector.begin(), nvramVector.end());
|
2016-10-10 14:05:04 +08:00
|
|
|
return resultVector;
|
|
|
|
}
|
|
|
|
|
2015-04-02 16:04:37 +08:00
|
|
|
// Clears messages
|
2016-04-15 02:36:59 +08:00
|
|
|
void clearMessages() { messagesVector.clear(); }
|
2015-03-13 14:48:53 +08:00
|
|
|
|
|
|
|
// Firmware image parsing
|
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
|
2016-11-03 03:40:38 +08:00
|
|
|
std::vector<std::pair<std::vector<UString>, UModelIndex> > getFitTable() const { return fitTable; }
|
2015-07-07 21:57:41 +08:00
|
|
|
|
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;
|
|
|
|
void msg(const UString message, const UModelIndex index = UModelIndex()) {
|
|
|
|
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
|
2016-04-18 21:10:07 +08:00
|
|
|
};
|
|
|
|
|
2016-11-03 03:40:38 +08:00
|
|
|
NvramParser nvramParser;
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex lastVtf;
|
2015-09-13 23:32:22 +08:00
|
|
|
UINT32 capsuleOffsetFixup;
|
2016-11-03 03:40:38 +08:00
|
|
|
std::vector<std::pair<std::vector<UString>, UModelIndex> > fitTable;
|
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
|
|
|
|
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);
|
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 parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & root);
|
|
|
|
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);
|
|
|
|
USTATUS parseGeneralRegion(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);
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS findNextVolume(const UModelIndex & index, const UByteArray & bios, const UINT32 localOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset);
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS getVolumeSize(const UByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize);
|
2016-07-16 13:02:33 +08:00
|
|
|
UINT32 getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion);
|
|
|
|
UINT32 getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion);
|
2016-06-26 11:54:21 +08:00
|
|
|
|
2016-07-15 03:22:51 +08:00
|
|
|
// Second pass
|
|
|
|
USTATUS performSecondPass(const UModelIndex & index);
|
|
|
|
USTATUS addOffsetsRecursive(const UModelIndex & index);
|
|
|
|
USTATUS addMemoryAddressesRecursive(const UModelIndex & index, const UINT32 diff);
|
|
|
|
USTATUS addFixedAndCompressedRecursive(const UModelIndex & index);
|
|
|
|
USTATUS parseFit(const UModelIndex & index, const UINT32 diff);
|
|
|
|
USTATUS findFitRecursive(const UModelIndex & index, const UINT32 diff, UModelIndex & found, UINT32 & fitOffset);
|
2015-03-13 14:48:53 +08:00
|
|
|
};
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // FFSPARSER_H
|