2013-10-15 23:19:15 +08:00
|
|
|
/* ffsengine.h
|
|
|
|
|
2014-01-11 17:20:58 +08:00
|
|
|
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
2013-10-15 23:19:15 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __FFSENGINE_H__
|
|
|
|
#define __FFSENGINE_H__
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QByteArray>
|
2013-11-07 21:46:28 +08:00
|
|
|
#include <QQueue>
|
2013-10-15 23:19:15 +08:00
|
|
|
|
|
|
|
#include "basetypes.h"
|
|
|
|
#include "treemodel.h"
|
2013-11-17 17:01:11 +08:00
|
|
|
#include "messagelistitem.h"
|
2014-01-09 18:45:49 +08:00
|
|
|
#include "peimage.h"
|
2013-10-15 23:19:15 +08:00
|
|
|
|
|
|
|
class TreeModel;
|
|
|
|
|
|
|
|
class FfsEngine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-11-07 21:46:28 +08:00
|
|
|
// Default constructor and destructor
|
2013-10-15 23:19:15 +08:00
|
|
|
FfsEngine(QObject *parent = 0);
|
|
|
|
~FfsEngine(void);
|
2013-12-29 23:13:46 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Returns model for Qt view classes
|
2013-12-29 23:13:46 +08:00
|
|
|
TreeModel* treeModel() const;
|
2013-11-15 18:48:14 +08:00
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
// Returns message items queue
|
2013-12-29 00:02:26 +08:00
|
|
|
QQueue<MessageListItem> messages() const;
|
2013-12-05 04:27:12 +08:00
|
|
|
|
2013-12-29 23:13:46 +08:00
|
|
|
// Clears message items queue
|
|
|
|
void clearMessages();
|
2013-10-15 23:19:15 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Firmware image parsing
|
2013-10-15 23:19:15 +08:00
|
|
|
UINT8 parseInputFile(const QByteArray & buffer);
|
2014-01-11 17:20:58 +08:00
|
|
|
UINT8 parseIntelImage(const QByteArray & intelImage, QModelIndex & index, const QModelIndex & parent = QModelIndex());
|
2013-12-12 19:28:39 +08:00
|
|
|
UINT8 parseGbeRegion(const QByteArray & gbe, QModelIndex & index, const QModelIndex & parent);
|
|
|
|
UINT8 parseMeRegion(const QByteArray & me, QModelIndex & index, const QModelIndex & parent);
|
|
|
|
UINT8 parseBiosRegion(const QByteArray & bios, QModelIndex & index, const QModelIndex & parent);
|
|
|
|
UINT8 parsePdrRegion(const QByteArray & pdr, QModelIndex & index, const QModelIndex & parent);
|
2013-10-15 23:19:15 +08:00
|
|
|
UINT8 parseBios(const QByteArray & bios, const QModelIndex & parent = QModelIndex());
|
2013-11-07 21:46:28 +08:00
|
|
|
UINT8 findNextVolume(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & nextVolumeOffset);
|
|
|
|
UINT8 getVolumeSize(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize);
|
2013-12-12 19:28:39 +08:00
|
|
|
UINT8 parseVolume(const QByteArray & volume, QModelIndex & index, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
2013-11-07 21:46:28 +08:00
|
|
|
UINT8 getFileSize(const QByteArray & volume, const UINT32 fileOffset, UINT32 & fileSize);
|
2013-12-12 19:28:39 +08:00
|
|
|
UINT8 parseFile(const QByteArray & file, QModelIndex & index, const UINT8 erasePolarity = ERASE_POLARITY_UNKNOWN, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
2013-11-07 21:46:28 +08:00
|
|
|
UINT8 getSectionSize(const QByteArray & file, const UINT32 sectionOffset, UINT32 & sectionSize);
|
2013-11-18 23:23:59 +08:00
|
|
|
UINT8 parseSections(const QByteArray & body, const QModelIndex & parent = QModelIndex());
|
2013-12-12 19:28:39 +08:00
|
|
|
UINT8 parseSection(const QByteArray & section, QModelIndex & index, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
2013-10-15 23:19:15 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Compression routines
|
2013-11-14 18:40:39 +08:00
|
|
|
UINT8 decompress(const QByteArray & compressed, const UINT8 compressionType, QByteArray & decompressedData, UINT8 * algorithm = NULL);
|
2013-11-07 21:46:28 +08:00
|
|
|
UINT8 compress(const QByteArray & data, const UINT8 algorithm, QByteArray & compressedData);
|
2013-12-29 23:13:46 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Construction routines
|
2013-11-18 23:23:59 +08:00
|
|
|
UINT8 constructPadFile(const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad);
|
2013-11-15 18:48:14 +08:00
|
|
|
UINT8 growVolume(QByteArray & header, const UINT32 size, UINT32 & newSize);
|
2014-01-11 17:20:58 +08:00
|
|
|
UINT8 reconstruct(const QModelIndex &index, QByteArray & reconstructed);
|
|
|
|
UINT8 reconstructIntelImage(const QModelIndex& index, QByteArray & reconstructed);
|
|
|
|
UINT8 reconstructRegion(const QModelIndex& index, QByteArray & reconstructed);
|
|
|
|
UINT8 reconstructBios(const QModelIndex& index, QByteArray & reconstructed);
|
|
|
|
UINT8 reconstructVolume(const QModelIndex& index, QByteArray & reconstructed);
|
|
|
|
UINT8 reconstructFile(const QModelIndex& index, const UINT8 revision, const UINT8 erasePolarity, const UINT32 base, QByteArray& reconstructed);
|
|
|
|
UINT8 reconstructSection(const QModelIndex& index, const UINT32 base, QByteArray & reconstructed);
|
2013-11-15 18:48:14 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Operations on tree items
|
2013-12-29 23:13:46 +08:00
|
|
|
UINT8 extract(const QModelIndex & index, QByteArray & extracted, const UINT8 mode);
|
|
|
|
|
|
|
|
UINT8 create(const QModelIndex & index, const UINT8 type, const QByteArray & header, const QByteArray & body, const UINT8 mode, const UINT8 action, const UINT8 algorithm = COMPRESSION_ALGORITHM_NONE);
|
|
|
|
UINT8 insert(const QModelIndex & index, const QByteArray & object, const UINT8 mode);
|
|
|
|
UINT8 replace(const QModelIndex & index, const QByteArray & object, const UINT8 mode);
|
|
|
|
|
|
|
|
UINT8 remove(const QModelIndex & index);
|
|
|
|
|
|
|
|
UINT8 rebuild(const QModelIndex & index);
|
|
|
|
|
|
|
|
// Search routines
|
|
|
|
UINT8 findHexPattern(const QByteArray & pattern, const UINT8 mode);
|
|
|
|
UINT8 findHexPatternIn(const QModelIndex & index, const QByteArray & pattern, const UINT8 mode);
|
|
|
|
UINT8 findTextPattern(const QString & pattern, const bool unicode, const Qt::CaseSensitivity caseSensitive);
|
|
|
|
UINT8 findTextPatternIn(const QModelIndex & index, const QString & pattern, const bool unicode, const Qt::CaseSensitivity caseSensitive);
|
2013-12-29 00:02:26 +08:00
|
|
|
|
2014-01-11 17:20:58 +08:00
|
|
|
private:
|
|
|
|
TreeModel *model;
|
2014-01-12 07:02:54 +08:00
|
|
|
|
|
|
|
// PEI Core entry point
|
2014-01-11 17:20:58 +08:00
|
|
|
UINT32 oldPeiCoreEntryPoint;
|
|
|
|
UINT32 newPeiCoreEntryPoint;
|
|
|
|
|
2014-01-09 18:45:49 +08:00
|
|
|
// Rebase routines
|
2014-01-12 07:02:54 +08:00
|
|
|
UINT8 getBase(const QByteArray& file, UINT32& base);
|
|
|
|
UINT8 getEntryPoint(const QByteArray& file, UINT32 &peiCoreEntryPoint);
|
2014-01-09 18:45:49 +08:00
|
|
|
UINT8 rebase(QByteArray & executable, const UINT32 base);
|
|
|
|
|
2014-01-11 17:20:58 +08:00
|
|
|
// Patch routines
|
|
|
|
UINT8 patchVtf(QByteArray &vtf);
|
2013-12-29 23:13:46 +08:00
|
|
|
|
|
|
|
// Message helper
|
2013-11-17 19:13:37 +08:00
|
|
|
QQueue<MessageListItem> messageItems;
|
2013-11-15 18:48:14 +08:00
|
|
|
void msg(const QString & message, const QModelIndex index = QModelIndex());
|
2013-12-29 23:13:46 +08:00
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
// Internal operations
|
|
|
|
bool hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2);
|
2013-10-15 23:19:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|