NE A21: deQtization begins

- added FfsBuilder code and UI, but reconstruction routines for volumes,
files and sections are still not ready
- FfsOps moved to common
- QVector and QPair aren't used anymore, replaces with std::vector and
std::pair
- common classes are now independent from QObject
- next step is to replace QString with CBString from bstrlib
This commit is contained in:
Nikolaj Schlej 2016-03-01 08:20:44 +01:00
parent b7ec76e091
commit 2024c1898b
21 changed files with 729 additions and 658 deletions

View File

@ -13,8 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsfinder.h"
FfsFinder::FfsFinder(const TreeModel* treeModel, QObject *parent)
: QObject(parent), model(treeModel)
FfsFinder::FfsFinder(const TreeModel* treeModel)
: model(treeModel)
{
}
@ -24,10 +24,10 @@ FfsFinder::~FfsFinder()
void FfsFinder::msg(const QString & message, const QModelIndex & index)
{
messagesVector.push_back(QPair<QString, QModelIndex>(message, index));
messagesVector.push_back(std::pair<QString, QModelIndex>(message, index));
}
QVector<QPair<QString, QModelIndex> > FfsFinder::getMessages() const
std::vector<std::pair<QString, QModelIndex> > FfsFinder::getMessages() const
{
return messagesVector;
}
@ -73,11 +73,11 @@ STATUS FfsFinder::findHexPattern(const QModelIndex & index, const QByteArray & h
INT32 offset = regexp.indexIn(hexBody);
while (offset >= 0) {
if (offset % 2 == 0) {
msg(tr("Hex pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h")
msg(QObject::tr("Hex pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h")
.arg(QString(hexPattern))
.arg(hexBody.mid(offset, hexPattern.length()).toUpper())
.arg(model->name(index))
.arg(mode == SEARCH_MODE_BODY ? tr("body") : tr("header"))
.arg(mode == SEARCH_MODE_BODY ? QObject::tr("body") : QObject::tr("header"))
.hexarg(offset / 2),
index);
}
@ -142,11 +142,11 @@ STATUS FfsFinder::findGuidPattern(const QModelIndex & index, const QByteArray &
INT32 offset = regexp.indexIn(hexBody);
while (offset >= 0) {
if (offset % 2 == 0) {
msg(tr("GUID pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h")
msg(QObject::tr("GUID pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h")
.arg(QString(guidPattern))
.arg(hexBody.mid(offset, hexPattern.length()).toUpper())
.arg(model->name(index))
.arg(mode == SEARCH_MODE_BODY ? tr("body") : tr("header"))
.arg(mode == SEARCH_MODE_BODY ? QObject::tr("body") : QObject::tr("header"))
.hexarg(offset / 2),
index);
}
@ -180,7 +180,7 @@ STATUS FfsFinder::findTextPattern(const QModelIndex & index, const QString & pat
int offset = -1;
while ((offset = data.indexOf(pattern, offset + 1, caseSensitive)) >= 0) {
msg(tr("%1 text \"%2\" found in %3 at offset %4h")
msg(QObject::tr("%1 text \"%2\" found in %3 at offset %4h")
.arg(unicode ? "Unicode" : "ASCII")
.arg(pattern)
.arg(model->name(index))

View File

@ -14,26 +14,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __FFSFINDER_H__
#define __FFSFINDER_H__
#include <vector>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QModelIndex>
#include <QPair>
#include <QRegExp>
#include <QVector>
#include "../common/basetypes.h"
#include "../common/treemodel.h"
class FfsFinder : public QObject
class FfsFinder
{
Q_OBJECT
public:
explicit FfsFinder(const TreeModel * treeModel, QObject *parent = 0);
explicit FfsFinder(const TreeModel * treeModel);
~FfsFinder();
QVector<QPair<QString, QModelIndex> > getMessages() const;
std::vector<std::pair<QString, QModelIndex> > getMessages() const;
void clearMessages();
STATUS findHexPattern(const QModelIndex & index, const QByteArray & hexPattern, const UINT8 mode);
@ -42,10 +40,9 @@ public:
private:
const TreeModel* model;
QVector<QPair<QString, QModelIndex> > messagesVector;
std::vector<std::pair<QString, QModelIndex> > messagesVector;
void msg(const QString & message, const QModelIndex &index = QModelIndex());
};
#endif

View File

@ -17,7 +17,7 @@
UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UEFITool),
version(tr("0.30.0_alpha20"))
version(tr("0.30.0_alpha21"))
{
clipboard = QApplication::clipboard();
@ -29,6 +29,7 @@ version(tr("0.30.0_alpha20"))
fitParser = NULL;
ffsFinder = NULL;
ffsOps = NULL;
ffsBuilder = NULL;
// Set window title
this->setWindowTitle(tr("UEFITool %1").arg(version));
@ -91,6 +92,7 @@ UEFITool::~UEFITool()
delete ffsFinder;
delete fitParser;
delete ffsParser;
delete ffsBuilder;
delete model;
delete searchDialog;
delete ui;
@ -110,7 +112,7 @@ void UEFITool::init()
ui->fitTableWidget->setRowCount(0);
ui->fitTableWidget->setColumnCount(0);
ui->infoEdit->clear();
ui->messagesTabWidget->setTabEnabled(2, false);
ui->messagesTabWidget->setTabEnabled(1, false);
// Set window title
this->setWindowTitle(tr("UEFITool %1").arg(version));
@ -157,7 +159,7 @@ void UEFITool::populateUi(const QModelIndex &current)
return;
UINT8 type = model->type(current);
//UINT8 subtype = model->subtype(current);
UINT8 subtype = model->subtype(current);
// Set info text
ui->infoEdit->setPlainText(model->info(current));
@ -173,6 +175,11 @@ void UEFITool::populateUi(const QModelIndex &current)
// Enable actions
ui->actionExtract->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current));
// Disable rebuild for now
//ui->actionRebuild->setDisabled(type == Types::Region && subtype == Subtypes::DescriptorRegion);
//ui->actionReplace->setDisabled(type == Types::Region && subtype == Subtypes::DescriptorRegion);
//ui->actionRebuild->setEnabled(type == Types::Volume || type == Types::File || type == Types::Section);
ui->actionExtractBody->setDisabled(model->hasEmptyBody(current));
ui->actionExtractBodyUncompressed->setEnabled(enableExtractBodyUncompressed(current));
@ -196,7 +203,8 @@ bool UEFITool::enableExtractBodyUncompressed(const QModelIndex &current)
if (model->subtype(current) == EFI_SECTION_COMPRESSION &&
pdata.section.compressed.algorithm != COMPRESSION_ALGORITHM_NONE &&
pdata.section.compressed.algorithm != COMPRESSION_ALGORITHM_UNKNOWN) { //Compressed section
pdata.section.compressed.algorithm != COMPRESSION_ALGORITHM_UNKNOWN &&
pdata.section.compressed.algorithm != COMPRESSION_ALGORITHM_UNDECIDED) { //Compressed section
return true;
}
else if (model->subtype(current) == EFI_SECTION_GUID_DEFINED) {
@ -261,30 +269,6 @@ void UEFITool::search()
}
}
void UEFITool::rebuild()
{
/*QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
UINT8 result = ffsEngine->rebuild(index);
if (result == ERR_SUCCESS)
ui->actionSaveImageFile->setEnabled(true);*/
}
void UEFITool::remove()
{
/*QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
UINT8 result = ffsEngine->remove(index);
if (result == ERR_SUCCESS)
ui->actionSaveImageFile->setEnabled(true);*/
}
void UEFITool::insert(const UINT8 mode)
{
/*QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
@ -366,59 +350,62 @@ void UEFITool::replaceBody()
void UEFITool::replace(const UINT8 mode)
{
/*QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
QString path;
if (model->type(index) == Types::Region) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select region file to replace selected object"), currentDir, "Region files (*.rgn *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select region file to replace %1").arg(model->name(index)), currentDir, "Region files (*.rgn *.bin);;All files (*)");
}
else
return;
}
else if (model->type(index) == Types::Volume) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace selected object"), currentDir, "Volume files (*.vol *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace selected volume"), currentDir, "Volume files (*.vol *.bin);;All files (*)");
}
else if (mode == REPLACE_MODE_BODY) {
path = QFileDialog::getOpenFileName(this, tr("Select volume body file to replace body"), currentDir, "Volume body files (*.vbd *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select volume body file to replace the body of selected volume"), currentDir, "Volume body files (*.vbd *.bin);;All files (*)");
}
else
return;
}
else if (model->type(index) == Types::File) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to replace selected object"), currentDir, "FFS files (*.ffs *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to replace %1 file").arg(model->text(index).isEmpty() ? model->name(index) : model->text(index)),
currentDir, "FFS files (*.ffs *.bin);;All files (*)");
}
else if (mode == REPLACE_MODE_BODY) {
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"), currentDir, "Raw files (*.raw *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace the body of %1 file").arg(model->text(index).isEmpty() ? model->name(index) : model->text(index)),
currentDir, "Raw files (*.raw *.bin);;All files (*)");
else if (model->subtype(index) == EFI_FV_FILETYPE_PAD) // Pad file body can't be replaced
//!TODO: handle non-empty pad files
return;
else
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body to replace body"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body to replace the body of %1 file").arg(model->text(index).isEmpty() ? model->name(index) : model->text(index)),
currentDir, "FFS file body files (*.fbd *.bin);;All files (*)");
}
else
return;
}
else if (model->type(index) == Types::Section) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select section file to replace selected object"), currentDir, "Section files (*.sct *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select section file to replace selected section"), currentDir, "Section files (*.sct *.bin);;All files (*)");
}
else if (mode == REPLACE_MODE_BODY) {
if (model->subtype(index) == EFI_SECTION_COMPRESSION || model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_DISPOSABLE)
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body file to replace body"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body file to replace the body of selected section"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*)");
else if (model->subtype(index) == EFI_SECTION_FIRMWARE_VOLUME_IMAGE)
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace body"), currentDir, "Volume files (*.vol *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace the body of selected section"), currentDir, "Volume files (*.vol *.bin);;All files (*)");
else if (model->subtype(index) == EFI_SECTION_RAW)
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"), currentDir, "Raw files (*.raw *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace the body of selected section"), currentDir, "Raw files (*.raw *.bin);;All files (*)");
else if (model->subtype(index) == EFI_SECTION_PE32 || model->subtype(index) == EFI_SECTION_TE || model->subtype(index) == EFI_SECTION_PIC)
path = QFileDialog::getOpenFileName(this, tr("Select EFI executable file to replace body"), currentDir, "EFI executable files (*.efi *.dxe *.pei *.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select EFI executable file to replace the body of selected section"), currentDir, "EFI executable files (*.efi *.dxe *.pei *.bin);;All files (*)");
else
path = QFileDialog::getOpenFileName(this, tr("Select file to replace body"), currentDir, "Binary files (*.bin);;All files (*)");
path = QFileDialog::getOpenFileName(this, tr("Select file to replace the body of selected section"), currentDir, "Binary files (*.bin);;All files (*)");
}
else
return;
@ -431,7 +418,7 @@ void UEFITool::replace(const UINT8 mode)
QFileInfo fileInfo = QFileInfo(path);
if (!fileInfo.exists()) {
ui->statusBar->showMessage(tr("Please select existing file"));
ui->statusBar->showMessage(tr("Please select an existing file"));
return;
}
@ -446,12 +433,12 @@ void UEFITool::replace(const UINT8 mode)
QByteArray buffer = inputFile.readAll();
inputFile.close();
UINT8 result = ffsEngine->replace(index, buffer, mode);
UINT8 result = ffsOps->replace(index, buffer, mode);
if (result) {
QMessageBox::critical(this, tr("Replacing failed"), errorMessage(result), QMessageBox::Ok);
QMessageBox::critical(this, tr("Replacing failed"), errorCodeToQString(result), QMessageBox::Ok);
return;
}
ui->actionSaveImageFile->setEnabled(true);*/
ui->actionSaveImageFile->setEnabled(true);
}
void UEFITool::extractAsIs()
@ -563,6 +550,26 @@ void UEFITool::extract(const UINT8 mode)
outputFile.close();
}
void UEFITool::rebuild()
{
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
if (ERR_SUCCESS == ffsOps->rebuild(index))
ui->actionSaveImageFile->setEnabled(true);
}
void UEFITool::remove()
{
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;
if (ERR_SUCCESS == ffsOps->remove(index))
ui->actionSaveImageFile->setEnabled(true);
}
void UEFITool::about()
{
QMessageBox::about(this, tr("About UEFITool"), tr(
@ -588,33 +595,35 @@ void UEFITool::exit()
void UEFITool::saveImageFile()
{
/*QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi *.dec);;All files (*)");
QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *.scap *.bio *.fd *.wph *.dec);;All files (*)");
if (path.isEmpty())
return;
QByteArray reconstructed;
UINT8 result = ffsEngine->reconstructImageFile(reconstructed);
showMessages();
// Create ffsBuilder
if (!ffsBuilder)
delete ffsBuilder;
ffsBuilder = new FfsBuilder(model);
STATUS result = ffsBuilder->build(model->index(0,0), reconstructed);
showBuilderMessages();
if (result) {
QMessageBox::critical(this, tr("Image reconstruction failed"), errorMessage(result), QMessageBox::Ok);
QMessageBox::critical(this, tr("Image build failed"), errorCodeToQString(result), QMessageBox::Ok);
return;
}
QFile outputFile;
outputFile.setFileName(path);
if (!outputFile.open(QFile::WriteOnly)) {
QMessageBox::critical(this, tr("Image reconstruction failed"), tr("Can't open output file for rewriting"), QMessageBox::Ok);
QMessageBox::critical(this, tr("Image build failed"), tr("Can't open output file for rewriting"), QMessageBox::Ok);
return;
}
outputFile.resize(0);
outputFile.write(reconstructed);
outputFile.close();
if (QMessageBox::information(this, tr("Image reconstruction successful"), tr("Open reconstructed file?"), QMessageBox::Yes, QMessageBox::No)
== QMessageBox::Yes)
openImageFile(path);*/
if (QMessageBox::Yes == QMessageBox::information(this, tr("Image build successful"), tr("Open the resulting file?"), QMessageBox::Yes, QMessageBox::No))
openImageFile(path);
}
void UEFITool::openImageFile()
@ -692,10 +701,12 @@ void UEFITool::copyMessage()
clipboard->clear();
if (ui->messagesTabWidget->currentIndex() == 0) // Parser tab
clipboard->setText(ui->parserMessagesListWidget->currentItem()->text());
else if (ui->messagesTabWidget->currentIndex() == 1) // Search tab
clipboard->setText(ui->finderMessagesListWidget->currentItem()->text());
else if (ui->messagesTabWidget->currentIndex() == 2) // FIT tab
else if (ui->messagesTabWidget->currentIndex() == 1) // FIT tab
clipboard->setText(ui->fitMessagesListWidget->currentItem()->text());
else if (ui->messagesTabWidget->currentIndex() == 2) // Search tab
clipboard->setText(ui->finderMessagesListWidget->currentItem()->text());
else if (ui->messagesTabWidget->currentIndex() == 3) // Builder tab
clipboard->setText(ui->builderMessagesListWidget->currentItem()->text());
}
void UEFITool::copyAllMessages()
@ -707,14 +718,19 @@ void UEFITool::copyAllMessages()
text.append(ui->parserMessagesListWidget->item(i)->text()).append("\n");
clipboard->setText(text);
}
else if (ui->messagesTabWidget->currentIndex() == 1) { // Search tab
else if (ui->messagesTabWidget->currentIndex() == 1) { // FIT tab
for (INT32 i = 0; i < ui->fitMessagesListWidget->count(); i++)
text.append(ui->fitMessagesListWidget->item(i)->text()).append("\n");
clipboard->setText(text);
}
else if (ui->messagesTabWidget->currentIndex() == 2) { // Search tab
for (INT32 i = 0; i < ui->finderMessagesListWidget->count(); i++)
text.append(ui->finderMessagesListWidget->item(i)->text()).append("\n");
clipboard->setText(text);
}
else if (ui->messagesTabWidget->currentIndex() == 2) { // FIT tab
for (INT32 i = 0; i < ui->fitMessagesListWidget->count(); i++)
text.append(ui->fitMessagesListWidget->item(i)->text()).append("\n");
else if (ui->messagesTabWidget->currentIndex() == 3) { // Builder tab
for (INT32 i = 0; i < ui->builderMessagesListWidget->count(); i++)
text.append(ui->builderMessagesListWidget->item(i)->text()).append("\n");
clipboard->setText(text);
}
}
@ -728,17 +744,22 @@ void UEFITool::enableMessagesCopyActions(QListWidgetItem* item)
void UEFITool::clearMessages()
{
if (ui->messagesTabWidget->currentIndex() == 0) { // Parser tab
ffsParser->clearMessages();
if (ffsParser) ffsParser->clearMessages();
ui->parserMessagesListWidget->clear();
}
else if (ui->messagesTabWidget->currentIndex() == 1) { // Search tab
ffsFinder->clearMessages();
ui->finderMessagesListWidget->clear();
}
else if (ui->messagesTabWidget->currentIndex() == 2) { // FIT tab
fitParser->clearMessages();
else if (ui->messagesTabWidget->currentIndex() == 1) { // FIT tab
if (fitParser) fitParser->clearMessages();
ui->fitMessagesListWidget->clear();
}
else if (ui->messagesTabWidget->currentIndex() == 2) { // Search tab
if (ffsFinder) ffsFinder->clearMessages();
ui->finderMessagesListWidget->clear();
}
else if (ui->messagesTabWidget->currentIndex() == 3) { // Builder tab
if (ffsBuilder) ffsBuilder->clearMessages();
ui->builderMessagesListWidget->clear();
}
ui->actionMessagesCopy->setEnabled(false);
ui->actionMessagesCopyAll->setEnabled(false);
}
@ -761,8 +782,8 @@ void UEFITool::showParserMessages()
if (!ffsParser)
return;
QVector<QPair<QString, QModelIndex> > messages = ffsParser->getMessages();
QPair<QString, QModelIndex> msg;
std::vector<std::pair<QString, QModelIndex> > messages = ffsParser->getMessages();
std::pair<QString, QModelIndex> msg;
foreach (msg, messages) {
ui->parserMessagesListWidget->addItem(new MessageListItem(msg.first, NULL, 0, msg.second));
}
@ -771,37 +792,53 @@ void UEFITool::showParserMessages()
ui->parserMessagesListWidget->scrollToBottom();
}
void UEFITool::showFinderMessages()
{
ui->finderMessagesListWidget->clear();
if (!ffsParser)
return;
QVector<QPair<QString, QModelIndex> > messages = ffsFinder->getMessages();
QPair<QString, QModelIndex> msg;
foreach (msg, messages) {
ui->finderMessagesListWidget->addItem(new MessageListItem(msg.first, NULL, 0, msg.second));
}
ui->messagesTabWidget->setCurrentIndex(1);
ui->finderMessagesListWidget->scrollToBottom();
}
void UEFITool::showFitMessages()
{
ui->fitMessagesListWidget->clear();
if (!fitParser)
return;
QVector<QPair<QString, QModelIndex> > messages = fitParser->getMessages();
QPair<QString, QModelIndex> msg;
foreach(msg, messages) {
std::vector<std::pair<QString, QModelIndex> > messages = fitParser->getMessages();
std::pair<QString, QModelIndex> msg;
foreach (msg, messages) {
ui->fitMessagesListWidget->addItem(new MessageListItem(msg.first, NULL, 0, msg.second));
}
ui->fitMessagesListWidget->scrollToBottom();
}
void UEFITool::showFinderMessages()
{
ui->finderMessagesListWidget->clear();
if (!ffsParser)
return;
std::vector<std::pair<QString, QModelIndex> > messages = ffsFinder->getMessages();
std::pair<QString, QModelIndex> msg;
foreach (msg, messages) {
ui->finderMessagesListWidget->addItem(new MessageListItem(msg.first, NULL, 0, msg.second));
}
ui->messagesTabWidget->setCurrentIndex(2);
ui->finderMessagesListWidget->scrollToBottom();
}
void UEFITool::showBuilderMessages()
{
ui->builderMessagesListWidget->clear();
if (!ffsBuilder)
return;
std::vector<std::pair<QString, QModelIndex> > messages = ffsBuilder->getMessages();
std::pair<QString, QModelIndex> msg;
foreach (msg, messages) {
ui->builderMessagesListWidget->addItem(new MessageListItem(msg.first, NULL, 0, msg.second));
}
ui->messagesTabWidget->setCurrentIndex(3);
ui->builderMessagesListWidget->scrollToBottom();
}
void UEFITool::scrollTreeView(QListWidgetItem* item)
{
MessageListItem* messageItem = static_cast<MessageListItem*>(item);
@ -889,12 +926,12 @@ void UEFITool::writeSettings()
void UEFITool::showFitTable()
{
QVector<QVector<QString> > fitTable = fitParser->getFitTable();
if (fitTable.isEmpty()) {
std::vector<std::vector<QString> > fitTable = fitParser->getFitTable();
if (fitTable.empty()) {
return;
}
// Enable FIT tab
ui->messagesTabWidget->setTabEnabled(2, true);
ui->messagesTabWidget->setTabEnabled(1, true);
// Set up the FIT table
ui->fitTableWidget->clear();
@ -907,7 +944,7 @@ void UEFITool::showFitTable()
ui->fitTableWidget->horizontalHeader()->setStretchLastSection(true);
// Add all data to the table widget
for (INT32 i = 0; i < fitTable.size(); i++) {
for (size_t i = 0; i < fitTable.size(); i++) {
for (UINT8 j = 0; j < 5; j++) {
ui->fitTableWidget->setItem(i, j, new QTableWidgetItem(fitTable[i][j]));
}
@ -915,5 +952,5 @@ void UEFITool::showFitTable()
ui->fitTableWidget->resizeColumnsToContents();
ui->fitTableWidget->resizeRowsToContents();
ui->messagesTabWidget->setCurrentIndex(2);
ui->messagesTabWidget->setCurrentIndex(1);
}

View File

@ -39,10 +39,12 @@
#include "../common/ffs.h"
#include "../common/ffsparser.h"
#include "../common/fitparser.h"
#include "../common/ffsops.h"
#include "../common/ffsbuilder.h"
#include "searchdialog.h"
#include "messagelistitem.h"
#include "ffsfinder.h"
#include "ffsops.h"
namespace Ui {
class UEFITool;
@ -105,6 +107,7 @@ private:
FitParser* fitParser;
FfsFinder* ffsFinder;
FfsOperations* ffsOps;
FfsBuilder* ffsBuilder;
SearchDialog* searchDialog;
QClipboard* clipboard;
QString currentDir;
@ -121,6 +124,7 @@ private:
void showFinderMessages();
void showFitMessages();
void showFitTable();
void showBuilderMessages();
};
#endif

View File

@ -10,7 +10,7 @@ SOURCES += uefitool_main.cpp \
messagelistitem.cpp \
guidlineedit.cpp \
ffsfinder.cpp \
ffsops.cpp \
../common/ffsops.cpp \
../common/types.cpp \
../common/descriptor.cpp \
../common/ffs.cpp \
@ -35,7 +35,7 @@ HEADERS += uefitool.h \
messagelistitem.h \
guidlineedit.h \
ffsfinder.h \
ffsops.h \
../common/ffsops.h \
../common/basetypes.h \
../common/descriptor.h \
../common/gbe.h \

View File

@ -29,7 +29,7 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<property name="spacing">
<number>0</number>
</property>
@ -58,7 +58,7 @@
<property name="title">
<string>Structure</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
@ -105,7 +105,7 @@
<property name="title">
<string>Information</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
@ -148,7 +148,7 @@
<attribute name="title">
<string>Parser</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
@ -173,40 +173,11 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="finderTab">
<attribute name="title">
<string>Search</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QListWidget" name="finderMessagesListWidget">
<property name="mouseTracking">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="fitTab">
<attribute name="title">
<string>FIT</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
@ -237,6 +208,64 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="finderTab">
<attribute name="title">
<string>Search</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QListWidget" name="finderMessagesListWidget">
<property name="mouseTracking">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="builderTab">
<attribute name="title">
<string>Builder</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QListWidget" name="builderMessagesListWidget">
<property name="mouseTracking">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
@ -294,6 +323,8 @@
</property>
<addaction name="actionExtract"/>
<addaction name="separator"/>
<addaction name="actionRebuild"/>
<addaction name="separator"/>
<addaction name="actionReplace"/>
</widget>
<widget class="QMenu" name="menuPaddingActions">

View File

@ -72,13 +72,14 @@ typedef UINT8 STATUS;
#define ERR_UNKNOWN_COMPRESSION_TYPE 26
#define ERR_DEPEX_PARSE_FAILED 27
#define ERR_UNKNOWN_EXTRACT_MODE 28
#define ERR_UNKNOWN_IMAGE_TYPE 29
#define ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE 30
#define ERR_UNKNOWN_RELOCATION_TYPE 31
#define ERR_DIR_ALREADY_EXIST 32
#define ERR_DIR_CREATE 33
#define ERR_TRUNCATED_IMAGE 34
#define ERR_INVALID_CAPSULE 35
#define ERR_UNKNOWN_REPLACE_MODE 29
#define ERR_UNKNOWN_IMAGE_TYPE 30
#define ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE 31
#define ERR_UNKNOWN_RELOCATION_TYPE 32
#define ERR_DIR_ALREADY_EXIST 33
#define ERR_DIR_CREATE 34
#define ERR_TRUNCATED_IMAGE 35
#define ERR_INVALID_CAPSULE 36
#define ERR_NOT_IMPLEMENTED 0xFF
// UDK porting definitions

View File

@ -10,7 +10,6 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include <QObject>
#include "descriptor.h"
// Calculate address of data structure addressed by descriptor address format

View File

@ -13,7 +13,6 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __DESCRIPTOR_H__
#define __DESCRIPTOR_H__
#include <QString>
#include "basetypes.h"
// Make sure we use right packing rules

View File

@ -13,19 +13,19 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <QObject>
#include "ffs.h"
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;
const std::vector<QByteArray> FFSv2Volumes({
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
});
const QVector<QByteArray> FFSv3Volumes =
QVector<QByteArray>()
<< EFI_FIRMWARE_FILE_SYSTEM3_GUID;
const std::vector<QByteArray> FFSv3Volumes({
EFI_FIRMWARE_FILE_SYSTEM3_GUID
});
const UINT8 ffsAlignmentTable[] =
{ 0, 4, 7, 9, 10, 12, 15, 16 };

View File

@ -15,7 +15,6 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <QByteArray>
#include <QString>
#include <QVector>
#include "basetypes.h"
// C++ functions
@ -138,13 +137,13 @@ const QByteArray EFI_SONY_FILE_SYSTEM_GUID
// 4F494156-AED6-4D64-A537-B8A5557BCEEC // Sony 1
// Vector of volume GUIDs with FFSv2-compatible files
extern const QVector<QByteArray> FFSv2Volumes;
extern const std::vector<QByteArray> FFSv2Volumes;
const QByteArray EFI_FIRMWARE_FILE_SYSTEM3_GUID // 5473C07A-3DCB-4dca-BD6F-1E9689E7349A
("\x7A\xC0\x73\x54\xCB\x3D\xCA\x4D\xBD\x6F\x1E\x96\x89\xE7\x34\x9A", 16);
// Vector of volume GUIDs with FFSv3-compatible files
extern const QVector<QByteArray> FFSv3Volumes;
extern const std::vector<QByteArray> FFSv3Volumes;
// Firmware volume signature
const QByteArray EFI_FV_SIGNATURE("_FVH", 4);

View File

@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "ffsbuilder.h"
FfsBuilder::FfsBuilder(const TreeModel* treeModel, QObject *parent)
: QObject(parent), model(treeModel)
FfsBuilder::FfsBuilder(const TreeModel* treeModel)
: model(treeModel)
{
}
@ -23,10 +23,10 @@ FfsBuilder::~FfsBuilder()
void FfsBuilder::msg(const QString & message, const QModelIndex & index)
{
messagesVector.push_back(QPair<QString, QModelIndex>(message, index));
messagesVector.push_back(std::pair<QString, QModelIndex>(message, index));
}
QVector<QPair<QString, QModelIndex> > FfsBuilder::getMessages() const
std::vector<std::pair<QString, QModelIndex> > FfsBuilder::getMessages() const
{
return messagesVector;
}
@ -47,6 +47,27 @@ STATUS FfsBuilder::erase(const QModelIndex & index, QByteArray & erased)
return ERR_SUCCESS;
}
STATUS FfsBuilder::build(const QModelIndex & root, QByteArray & image)
{
// Sanity check
if (!root.isValid())
return ERR_INVALID_PARAMETER;
if (model->type(root) == Types::Capsule) {
return buildCapsule(root, image);
}
else if (model->type(root) == Types::Image) {
if (model->subtype(root) == Subtypes::IntelImage) {
return buildIntelImage(root, image);
}
else if (model->subtype(root) == Subtypes::IntelImage) {
return buildRawArea(root, image);
}
}
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::buildCapsule(const QModelIndex & index, QByteArray & capsule)
{
// Sanity check
@ -69,7 +90,7 @@ STATUS FfsBuilder::buildCapsule(const QModelIndex & index, QByteArray & capsule)
// Right now there is only one capsule image element supported
if (model->rowCount(index) != 1) {
msg(tr("buildCapsule: building of capsules with %1 elements are not supported, original item data is used").arg(model->rowCount(index)), index);
msg(QObject::tr("buildCapsule: building of capsules with %1 elements are not supported, original item data is used").arg(model->rowCount(index)), index);
// Use original item data
capsule = model->header(index).append(model->body(index));
return ERR_SUCCESS;
@ -82,21 +103,27 @@ STATUS FfsBuilder::buildCapsule(const QModelIndex & index, QByteArray & capsule)
// Check image type
if (model->type(imageIndex) == Types::Image) {
STATUS result;
if (model->subtype(imageIndex) == Subtypes::IntelImage)
if (model->subtype(imageIndex) == Subtypes::IntelImage) {
result = buildIntelImage(imageIndex, imageData);
else
}
else if (model->subtype(imageIndex) == Subtypes::UefiImage) {
result = buildRawArea(imageIndex, imageData);
}
else {
msg(QObject::tr("buildCapsule: unexpected item of subtype %1 can't be processed, original item data is used").arg(model->subtype(imageIndex)), imageIndex);
capsule.append(model->header(imageIndex)).append(model->body(imageIndex));
}
// Check build result
if (result) {
msg(tr("buildCapsule: building of \"%1\" failed with error \"%2\", original item data is used").arg(model->name(imageIndex)).arg(errorCodeToQString(result)), imageIndex);
msg(QObject::tr("buildCapsule: building of \"%1\" failed with error \"%2\", original item data is used").arg(model->name(imageIndex)).arg(errorCodeToQString(result)), imageIndex);
capsule.append(model->header(imageIndex)).append(model->body(imageIndex));
}
else
capsule.append(imageData);
}
else {
msg(tr("buildCapsule: unexpected child item of type \"%1\" can't be processed, original item data is used").arg(itemTypeToQString(model->type(imageIndex))), imageIndex);
msg(QObject::tr("buildCapsule: unexpected item of type %1 can't be processed, original item data is used").arg(model->type(imageIndex)), imageIndex);
capsule.append(model->header(imageIndex)).append(model->body(imageIndex));
}
@ -104,12 +131,12 @@ STATUS FfsBuilder::buildCapsule(const QModelIndex & index, QByteArray & capsule)
UINT32 newSize = capsule.size();
UINT32 oldSize = model->body(index).size();
if (newSize > oldSize) {
msg(tr("buildCapsule: new capsule body size %1h (%2) is bigger than the original %3h (%4)")
msg(QObject::tr("buildCapsule: new capsule body size %1h (%2) is bigger than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize),index);
return ERR_INVALID_PARAMETER;
}
else if (newSize < oldSize) {
msg(tr("buildCapsule: new capsule body size %1h (%2) is smaller than the original %3h (%4)")
msg(QObject::tr("buildCapsule: new capsule body size %1h (%2) is smaller than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize), index);
return ERR_INVALID_PARAMETER;
}
@ -122,7 +149,7 @@ STATUS FfsBuilder::buildCapsule(const QModelIndex & index, QByteArray & capsule)
return ERR_SUCCESS;
}
msg(tr("buildCapsule: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
msg(QObject::tr("buildCapsule: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -138,22 +165,17 @@ STATUS FfsBuilder::buildIntelImage(const QModelIndex & index, QByteArray & intel
return ERR_SUCCESS;
}
// Other supported actions
// Rebuild
else if (model->action(index) == Actions::Rebuild) {
intelImage.clear();
// First child will always be descriptor for this type of image, and it's read only
QByteArray descriptor = model->header(index.child(0, 0)).append(model->body(index.child(0, 0)));
// Other regions can be in different order, GbE, PDR and EC may be skipped
QByteArray gbe;
QByteArray me;
QByteArray bios;
QByteArray pdr;
QByteArray ec;
QByteArray padding;
intelImage.append(model->header(index.child(0, 0)).append(model->body(index.child(0, 0))));
// Process other regions
for (int i = 1; i < model->rowCount(index); i++) {
QModelIndex currentRegion = index.child(i, 0);
// Skip regions with Remove action
if (model->action(currentRegion) == Actions::Remove)
continue;
@ -161,89 +183,53 @@ STATUS FfsBuilder::buildIntelImage(const QModelIndex & index, QByteArray & intel
// Check item type to be either region or padding
UINT8 type = model->type(currentRegion);
if (type == Types::Padding) {
if (!padding.isEmpty()) {
msg(tr("buildIntelImage: more than one padding found during image rebuild, the latest one is used"), index);
}
padding = model->header(currentRegion).append(model->body(currentRegion));
// Add padding as is
intelImage.append(model->header(currentRegion).append(model->body(currentRegion)));
continue;
}
// Check region subtype
STATUS result;
QByteArray region;
UINT8 regionType = model->subtype(currentRegion);
switch (regionType) {
case Subtypes::GbeRegion:
if (!gbe.isEmpty()) {
msg(tr("buildIntelImage: more than one GbE region found during image rebuild, the latest one is used"), index);
}
result = buildGbeRegion(currentRegion, gbe);
if (result) {
msg(tr("buildIntelImage: building of GbE region failed with error \"%1\", original item data is used").arg(errorCodeToQString(result)), currentRegion);
gbe = model->header(currentRegion).append(model->body(currentRegion));
}
break;
case Subtypes::MeRegion:
if (!me.isEmpty()) {
msg(tr("buildIntelImage: more than one ME region found during image rebuild, the latest one is used"), index);
}
result = buildMeRegion(currentRegion, me);
if (result) {
msg(tr("buildIntelImage: building of ME region failed with error \"%1\", original item data is used").arg(errorCodeToQString(result)), currentRegion);
me = model->header(currentRegion).append(model->body(currentRegion));
}
break;
case Subtypes::BiosRegion:
if (!bios.isEmpty()) {
msg(tr("buildIntelImage: more than one BIOS region found during image rebuild, the latest one is used"), index);
}
result = buildRawArea(currentRegion, bios);
if (result) {
msg(tr("buildIntelImage: building of BIOS region failed with error \"%1\", original item data is used").arg(errorCodeToQString(result)), currentRegion);
bios = model->header(currentRegion).append(model->body(currentRegion));
}
break;
case Subtypes::PdrRegion:
if (!pdr.isEmpty()) {
msg(tr("buildIntelImage: more than one PDR region found during image rebuild, the latest one is used"), index);
}
result = buildPdrRegion(currentRegion, pdr);
result = buildRawArea(currentRegion, region);
if (result) {
msg(tr("buildIntelImage: building of PDR region failed with error \"%1\", original item data is used").arg(errorCodeToQString(result)), currentRegion);
pdr = model->header(currentRegion).append(model->body(currentRegion));
msg(QObject::tr("buildIntelImage: building of %1 region failed with error \"%2\", original item data is used").arg(regionTypeToQString(regionType)).arg(errorCodeToQString(result)), currentRegion);
region = model->header(currentRegion).append(model->body(currentRegion));
}
break;
case Subtypes::GbeRegion:
case Subtypes::MeRegion:
case Subtypes::EcRegion:
if (!ec.isEmpty()) {
msg(tr("buildIntelImage: more than one EC region found during image rebuild, the latest one is used"), index);
}
result = buildEcRegion(currentRegion, ec);
if (result) {
msg(tr("buildIntelImage: building of EC region failed with error \"%1\", original item data is used").arg(errorCodeToQString(result)), currentRegion);
ec = model->header(currentRegion).append(model->body(currentRegion));
}
case Subtypes::Reserved1Region:
case Subtypes::Reserved2Region:
case Subtypes::Reserved3Region:
case Subtypes::Reserved4Region:
// Add region as is
region = model->header(currentRegion).append(model->body(currentRegion));
break;
default:
msg(tr("buildIntelImage: don't know how to build region of unknown type"), index);
msg(QObject::tr("buildIntelImage: don't know how to build region of unknown type"), index);
return ERR_UNKNOWN_ITEM_TYPE;
}
// Append the resulting region
intelImage.append(region);
}
// Check size of new image, it must be same as old one
UINT32 newSize = intelImage.size();
UINT32 oldSize = model->body(index).size();
if (newSize > oldSize) {
msg(tr("buildIntelImage: new image size %1h (%2) is bigger than the original %3h (%4)")
msg(QObject::tr("buildIntelImage: new image size %1h (%2) is bigger than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize), index);
return ERR_INVALID_PARAMETER;
}
else if (newSize < oldSize) {
msg(tr("buildIntelImage: new image size %1h (%2) is smaller than the original %3h (%4)")
msg(QObject::tr("buildIntelImage: new image size %1h (%2) is smaller than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize), index);
return ERR_INVALID_PARAMETER;
}
@ -252,27 +238,7 @@ STATUS FfsBuilder::buildIntelImage(const QModelIndex & index, QByteArray & intel
return ERR_SUCCESS;
}
msg(tr("buildIntelImage: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::buildGbeRegion(const QModelIndex & index, QByteArray & region)
{
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::buildMeRegion(const QModelIndex & index, QByteArray & region)
{
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::buildPdrRegion(const QModelIndex & index, QByteArray & region)
{
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::buildEcRegion(const QModelIndex & index, QByteArray & region)
{
msg(QObject::tr("buildIntelImage: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -282,8 +248,6 @@ STATUS FfsBuilder::buildRawArea(const QModelIndex & index, QByteArray & rawArea,
if (!index.isValid())
return ERR_INVALID_PARAMETER;
STATUS result;
// No action required
if (model->action(index) == Actions::NoAction) {
rawArea = model->header(index).append(model->body(index));
@ -299,6 +263,7 @@ STATUS FfsBuilder::buildRawArea(const QModelIndex & index, QByteArray & rawArea,
// Build children
for (int i = 0; i < model->rowCount(index); i++) {
STATUS result = ERR_SUCCESS;
QModelIndex currentChild = index.child(i, 0);
QByteArray currentData;
// Check child type
@ -309,13 +274,12 @@ STATUS FfsBuilder::buildRawArea(const QModelIndex & index, QByteArray & rawArea,
result = buildPadding(currentChild, currentData);
}
else {
msg(tr("buildRawArea: unexpected child item of type \"%1\" can't be processed, original item data is used").arg(itemTypeToQString(model->type(currentChild))), currentChild);
result = ERR_SUCCESS;
msg(QObject::tr("buildRawArea: unexpected item of type %1 can't be processed, original item data is used").arg(model->type(currentChild)), currentChild);
currentData = model->header(currentChild).append(model->body(currentChild));
}
// Check build result
if (result) {
msg(tr("buildRawArea: building of \"%1\" failed with error \"%2\", original item data is used").arg(model->name(currentChild)).arg(errorCodeToQString(result)), currentChild);
msg(QObject::tr("buildRawArea: building of %1 failed with error \"%2\", original item data is used").arg(model->name(currentChild)).arg(errorCodeToQString(result)), currentChild);
currentData = model->header(currentChild).append(model->body(currentChild));
}
// Append current data
@ -326,12 +290,12 @@ STATUS FfsBuilder::buildRawArea(const QModelIndex & index, QByteArray & rawArea,
UINT32 newSize = rawArea.size();
UINT32 oldSize = model->body(index).size();
if (newSize > oldSize) {
msg(tr("buildRawArea: new area size %1h (%2) is bigger than the original %3h (%4)")
msg(QObject::tr("buildRawArea: new area size %1h (%2) is bigger than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize), index);
return ERR_INVALID_PARAMETER;
}
else if (newSize < oldSize) {
msg(tr("buildRawArea: new area size %1h (%2) is smaller than the original %3h (%4)")
msg(QObject::tr("buildRawArea: new area size %1h (%2) is smaller than the original %3h (%4)")
.hexarg(newSize).arg(newSize).hexarg(oldSize).arg(oldSize), index);
return ERR_INVALID_PARAMETER;
}
@ -345,7 +309,7 @@ STATUS FfsBuilder::buildRawArea(const QModelIndex & index, QByteArray & rawArea,
return ERR_SUCCESS;
}
msg(tr("buildRawArea: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
msg(QObject::tr("buildRawArea: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -365,11 +329,11 @@ STATUS FfsBuilder::buildPadding(const QModelIndex & index, QByteArray & padding)
else if (model->action(index) == Actions::Erase) {
padding = model->header(index).append(model->body(index));
if(erase(index, padding))
msg(tr("buildPadding: erase failed, original item data is used"), index);
msg(QObject::tr("buildPadding: erase failed, original item data is used"), index);
return ERR_SUCCESS;
}
msg(tr("buildPadding: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
msg(QObject::tr("buildPadding: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -389,11 +353,11 @@ STATUS FfsBuilder::buildNonUefiData(const QModelIndex & index, QByteArray & data
else if (model->action(index) == Actions::Erase) {
data = model->header(index).append(model->body(index));
if (erase(index, data))
msg(tr("buildNonUefiData: erase failed, original item data is used"), index);
msg(QObject::tr("buildNonUefiData: erase failed, original item data is used"), index);
return ERR_SUCCESS;
}
msg(tr("buildNonUefiData: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
msg(QObject::tr("buildNonUefiData: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -409,7 +373,7 @@ STATUS FfsBuilder::buildFreeSpace(const QModelIndex & index, QByteArray & freeSp
return ERR_SUCCESS;
}
msg(tr("buildFreeSpace: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
msg(QObject::tr("buildFreeSpace: unexpected action \"%1\"").arg(actionTypeToQString(model->action(index))), index);
return ERR_NOT_IMPLEMENTED;
}
@ -433,7 +397,4 @@ STATUS FfsBuilder::buildSection(const QModelIndex & index, QByteArray & section)
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsBuilder::build(const QModelIndex & root, QByteArray & image)
{
return ERR_NOT_IMPLEMENTED;
}

View File

@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __FFSBUILDER_H__
#define __FFSBUILDER_H__
#include <vector>
#include <QObject>
#include <QByteArray>
#include <QString>
@ -25,31 +27,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffs.h"
#include "utility.h"
class FfsBuilder : public QObject
class FfsBuilder
{
Q_OBJECT
public:
explicit FfsBuilder(const TreeModel * treeModel, QObject *parent = 0);
explicit FfsBuilder(const TreeModel * treeModel);
~FfsBuilder();
QVector<QPair<QString, QModelIndex> > getMessages() const;
std::vector<std::pair<QString, QModelIndex> > getMessages() const;
void clearMessages();
STATUS build(const QModelIndex & root, QByteArray & image);
private:
const TreeModel* model;
QVector<QPair<QString, QModelIndex> > messagesVector;
std::vector<std::pair<QString, QModelIndex> > messagesVector;
void msg(const QString & message, const QModelIndex &index = QModelIndex());
// UEFI standard structures
STATUS buildCapsule(const QModelIndex & index, QByteArray & capsule);
STATUS buildIntelImage(const QModelIndex & index, QByteArray & intelImage);
STATUS buildGbeRegion(const QModelIndex & index, QByteArray & region);
STATUS buildMeRegion(const QModelIndex & index, QByteArray & region);
STATUS buildPdrRegion(const QModelIndex & index, QByteArray & region);
STATUS buildEcRegion(const QModelIndex & index, QByteArray & region);
STATUS buildRawArea(const QModelIndex & index, QByteArray & rawArea, bool addHeader = true);
STATUS buildPadding(const QModelIndex & index, QByteArray & padding);
STATUS buildVolume(const QModelIndex & index, QByteArray & volume);

View File

@ -13,8 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsops.h"
FfsOperations::FfsOperations(const TreeModel* treeModel, QObject *parent)
: QObject(parent), model(treeModel)
FfsOperations::FfsOperations(TreeModel* treeModel)
: model(treeModel)
{
}
@ -24,10 +24,10 @@ FfsOperations::~FfsOperations()
void FfsOperations::msg(const QString & message, const QModelIndex & index)
{
messagesVector.push_back(QPair<QString, QModelIndex>(message, index));
messagesVector.push_back(std::pair<QString, QModelIndex>(message, index));
}
QVector<QPair<QString, QModelIndex> > FfsOperations::getMessages() const
std::vector<std::pair<QString, QModelIndex> > FfsOperations::getMessages() const
{
return messagesVector;
}
@ -89,13 +89,13 @@ STATUS FfsOperations::extract(const QModelIndex & index, QString & name, QByteAr
}
}
else if (mode == EXTRACT_MODE_BODY) {
name += tr("_body");
name += QObject::tr("_body");
// Extract without header and tail
extracted.clear();
extracted.append(model->body(index));
}
else if (mode == EXTRACT_MODE_BODY_UNCOMPRESSED) {
name += tr("_body_unc");
name += QObject::tr("_body_unc");
// Extract without header and tail, uncompressed
extracted.clear();
// There is no need to redo decompression, we can use child items
@ -111,3 +111,58 @@ STATUS FfsOperations::extract(const QModelIndex & index, QString & name, QByteAr
return ERR_SUCCESS;
}
STATUS FfsOperations::replace(const QModelIndex & index, const QString & data, const UINT8 mode)
{
// Sanity check
if (!index.isValid())
return ERR_INVALID_PARAMETER;
// Get data from parsing data
//PARSING_DATA pdata = parsingDataFromQModelIndex(index);
if (mode == REPLACE_MODE_AS_IS) {
return ERR_NOT_IMPLEMENTED;
}
else if (mode == REPLACE_MODE_BODY) {
return ERR_NOT_IMPLEMENTED;
}
else
return ERR_UNKNOWN_REPLACE_MODE;
return ERR_NOT_IMPLEMENTED;
}
STATUS FfsOperations::remove(const QModelIndex & index)
{
// Sanity check
if (!index.isValid())
return ERR_INVALID_PARAMETER;
// Set remove action
model->setAction(index, Actions::Remove);
return ERR_SUCCESS;
}
STATUS FfsOperations::rebuild(const QModelIndex & index)
{
// Sanity check
if (!index.isValid())
return ERR_INVALID_PARAMETER;
// On insert action, set insert action for children
//if (action == Actions::Insert)
// for (int i = 0; i < item->childCount(); i++)
// setAction(index.child(i, 0), Actions::Insert);
// Set rebuild action
model->setAction(index, Actions::Rebuild);
// Rebuild parent, if it has no action now
QModelIndex parent = index.parent();
if (parent.isValid() && model->type(parent) != Types::Root
&& model->action(parent) == Actions::NoAction)
rebuild(parent);
return ERR_SUCCESS;
}

View File

@ -14,32 +14,36 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __FFSOPS_H__
#define __FFSOPS_H__
#include <vector>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QModelIndex>
#include "../common/basetypes.h"
#include "../common/treemodel.h"
#include "../common/ffs.h"
#include "../common/utility.h"
#include "basetypes.h"
#include "treemodel.h"
#include "ffs.h"
#include "utility.h"
class FfsOperations : public QObject
class FfsOperations
{
Q_OBJECT
public:
explicit FfsOperations(const TreeModel * treeModel, QObject *parent = 0);
explicit FfsOperations(TreeModel * treeModel);
~FfsOperations();
QVector<QPair<QString, QModelIndex> > getMessages() const;
std::vector<std::pair<QString, QModelIndex> > getMessages() const;
void clearMessages();
STATUS extract(const QModelIndex & index, QString & name, QByteArray & extracted, const UINT8 mode);
STATUS replace(const QModelIndex & index, const QString & data, const UINT8 mode);
STATUS remove(const QModelIndex & index);
STATUS rebuild(const QModelIndex & index);
private:
const TreeModel* model;
QVector<QPair<QString, QModelIndex> > messagesVector;
TreeModel* model;
std::vector<std::pair<QString, QModelIndex> > messagesVector;
void msg(const QString & message, const QModelIndex &index = QModelIndex());
};

File diff suppressed because it is too large Load Diff

View File

@ -13,13 +13,11 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __FFSPARSER_H__
#define __FFSPARSER_H__
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <vector>
#include <QObject>
#include <QModelIndex>
#include <QByteArray>
#include <QVector>
#include "basetypes.h"
#include "treemodel.h"
@ -36,22 +34,30 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
class TreeModel;
class FfsParser : public QObject
class FfsParser
{
Q_OBJECT
public:
// Default constructor and destructor
FfsParser(TreeModel* treeModel, QObject *parent = 0);
FfsParser(TreeModel* treeModel);
~FfsParser();
// Returns messages
QVector<QPair<QString, QModelIndex> > getMessages() const;
std::vector<std::pair<QString, QModelIndex> > getMessages() const;
// Clears messages
void clearMessages();
// Firmware image parsing
STATUS parse(const QByteArray &buffer);
// Retuns index of the last VTF after parsing is done
const QModelIndex getLastVtf() {return lastVtf;};
private:
TreeModel *model;
std::vector<std::pair<QString, QModelIndex> > messagesVector;
QModelIndex lastVtf;
UINT32 capsuleOffsetFixup;
STATUS parseRawArea(const QByteArray & data, const QModelIndex & index);
STATUS parseVolumeHeader(const QByteArray & volume, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index);
STATUS parseVolumeBody(const QModelIndex & index);
@ -60,15 +66,6 @@ public:
STATUS parseSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse = false);
STATUS parseSectionBody(const QModelIndex & index);
// Retuns index of the last VTF after parsing is done
const QModelIndex getLastVtf() {return lastVtf;};
private:
TreeModel *model;
QVector<QPair<QString, QModelIndex> > messagesVector;
QModelIndex lastVtf;
UINT32 capsuleOffsetFixup;
STATUS parseIntelImage(const QByteArray & intelImage, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & root);
STATUS parseGbeRegion(const QByteArray & gbe, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index);
STATUS parseMeRegion(const QByteArray & me, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index);
@ -78,8 +75,8 @@ private:
STATUS parsePadFileBody(const QModelIndex & index);
STATUS parseVolumeNonUefiData(const QByteArray & data, const UINT32 parentOffset, const QModelIndex & index);
STATUS parseSections(const QByteArray & sections, const QModelIndex & index, const bool preparse = false);
STATUS parseSections(const QByteArray & sections, const QModelIndex & index, const bool preparse = false);
STATUS parseCommonSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse);
STATUS parseCompressedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse);
STATUS parseGuidedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse);

View File

@ -10,12 +10,10 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "fitparser.h"
#include "types.h"
#include "treemodel.h"
FitParser::FitParser(TreeModel* treeModel, QObject *parent)
: QObject(parent), model(treeModel)
FitParser::FitParser(TreeModel* treeModel)
: model(treeModel)
{
}
@ -25,10 +23,10 @@ FitParser::~FitParser()
void FitParser::msg(const QString & message, const QModelIndex & index)
{
messagesVector.push_back(QPair<QString, QModelIndex>(message, index));
messagesVector.push_back(std::pair<QString, QModelIndex>(message, index));
}
QVector<QPair<QString, QModelIndex> > FitParser::getMessages() const
std::vector<std::pair<QString, QModelIndex> > FitParser::getMessages() const
{
return messagesVector;
}
@ -73,23 +71,23 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
tempFitHeader->Checksum = 0;
UINT8 calculated = calculateChecksum8((const UINT8*)tempFitHeader, fitSize);
if (calculated != fitHeader->Checksum) {
msg(tr("Invalid FIT table checksum %1h, should be %2h").hexarg2(fitHeader->Checksum, 2).hexarg2(calculated, 2), fitIndex);
msg(QObject::tr("Invalid FIT table checksum %1h, should be %2h").hexarg2(fitHeader->Checksum, 2).hexarg2(calculated, 2), fitIndex);
}
}
// Check fit header type
if ((fitHeader->Type & 0x7F) != FIT_TYPE_HEADER) {
msg(tr("Invalid FIT header type"), fitIndex);
msg(QObject::tr("Invalid FIT header type"), fitIndex);
}
// Add FIT header to fitTable
QVector<QString> currentStrings;
currentStrings += tr("_FIT_ ");
currentStrings += tr("%1").hexarg2(fitSize, 8);
currentStrings += tr("%1").hexarg2(fitHeader->Version, 4);
currentStrings += fitEntryTypeToQString(fitHeader->Type);
currentStrings += tr("%1").hexarg2(fitHeader->Checksum, 2);
fitTable.append(currentStrings);
std::vector<QString> currentStrings;
currentStrings.push_back(QObject::tr("_FIT_ "));
currentStrings.push_back(QObject::tr("%1").hexarg2(fitSize, 8));
currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Version, 4));
currentStrings.push_back(fitEntryTypeToQString(fitHeader->Type));
currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Checksum, 2));
fitTable.push_back(currentStrings);
// Process all other entries
bool msgModifiedImageMayNotWork = false;
@ -100,7 +98,7 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
// Check entry type
switch (currentEntry->Type & 0x7F) {
case FIT_TYPE_HEADER:
msg(tr("Second FIT header found, the table is damaged"), fitIndex);
msg(QObject::tr("Second FIT header found, the table is damaged"), fitIndex);
break;
case FIT_TYPE_EMPTY:
@ -120,16 +118,16 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
}
// Add entry to fitTable
currentStrings += tr("%1").hexarg2(currentEntry->Address, 16);
currentStrings += tr("%1").hexarg2(currentEntry->Size, 8);
currentStrings += tr("%1").hexarg2(currentEntry->Version, 4);
currentStrings += fitEntryTypeToQString(currentEntry->Type);
currentStrings += tr("%1").hexarg2(currentEntry->Checksum, 2);
fitTable.append(currentStrings);
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Address, 16));
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Size, 8));
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Version, 4));
currentStrings.push_back(fitEntryTypeToQString(currentEntry->Type));
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Checksum, 2));
fitTable.push_back(currentStrings);
}
if (msgModifiedImageMayNotWork)
msg(tr("Opened image may not work after any modification"));
msg(QObject::tr("Opened image may not work after any modification"));
return ERR_SUCCESS;
}
@ -137,17 +135,17 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
QString FitParser::fitEntryTypeToQString(UINT8 type)
{
switch (type & 0x7F) {
case FIT_TYPE_HEADER: return tr("Header");
case FIT_TYPE_MICROCODE: return tr("Microcode");
case FIT_TYPE_BIOS_AC_MODULE: return tr("BIOS ACM");
case FIT_TYPE_BIOS_INIT_MODULE: return tr("BIOS Init");
case FIT_TYPE_TPM_POLICY: return tr("TPM Policy");
case FIT_TYPE_BIOS_POLICY_DATA: return tr("BIOS Policy Data");
case FIT_TYPE_TXT_CONF_POLICY: return tr("TXT Configuration Policy");
case FIT_TYPE_AC_KEY_MANIFEST: return tr("BootGuard Key Manifest");
case FIT_TYPE_AC_BOOT_POLICY: return tr("BootGuard Boot Policy");
case FIT_TYPE_EMPTY: return tr("Empty");
default: return tr("Unknown");
case FIT_TYPE_HEADER: return QObject::tr("Header");
case FIT_TYPE_MICROCODE: return QObject::tr("Microcode");
case FIT_TYPE_BIOS_AC_MODULE: return QObject::tr("BIOS ACM");
case FIT_TYPE_BIOS_INIT_MODULE: return QObject::tr("BIOS Init");
case FIT_TYPE_TPM_POLICY: return QObject::tr("TPM Policy");
case FIT_TYPE_BIOS_POLICY_DATA: return QObject::tr("BIOS Policy Data");
case FIT_TYPE_TXT_CONF_POLICY: return QObject::tr("TXT Configuration Policy");
case FIT_TYPE_AC_KEY_MANIFEST: return QObject::tr("BootGuard Key Manifest");
case FIT_TYPE_AC_BOOT_POLICY: return QObject::tr("BootGuard Boot Policy");
case FIT_TYPE_EMPTY: return QObject::tr("Empty");
default: return QObject::tr("Unknown");
}
}
@ -179,11 +177,11 @@ STATUS FitParser::findFitRecursive(const QModelIndex & index, QModelIndex & foun
if (*(const UINT32*)(lastVtfBody.constData() + lastVtfBody.size() - FIT_POINTER_OFFSET) == fitAddress) {
found = index;
fitOffset = offset;
msg(tr("Real FIT table found at physical address %1h").hexarg(fitAddress), found);
msg(QObject::tr("Real FIT table found at physical address %1h").hexarg(fitAddress), found);
return ERR_SUCCESS;
}
else if (model->rowCount(index) == 0) // Show messages only to leaf items
msg(tr("FIT table candidate found, but not referenced from the last VTF"), index);
msg(QObject::tr("FIT table candidate found, but not referenced from the last VTF"), index);
}
return ERR_SUCCESS;

View File

@ -13,42 +13,41 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __FITPARSER_H__
#define __FITPARSER_H__
#include <vector>
#include <QObject>
#include <QModelIndex>
#include <QByteArray>
#include <QStringList>
#include <QVector>
#include "basetypes.h"
#include "treemodel.h"
#include "utility.h"
#include "parsingdata.h"
#include "fit.h"
#include "types.h"
#include "treemodel.h"
class TreeModel;
class FitParser : public QObject
class FitParser
{
Q_OBJECT
public:
// Default constructor and destructor
FitParser(TreeModel* treeModel, QObject *parent = 0);
FitParser(TreeModel* treeModel);
~FitParser();
// Returns messages
QVector<QPair<QString, QModelIndex> > getMessages() const;
std::vector<std::pair<QString, QModelIndex> > getMessages() const;
// Clears messages
void clearMessages();
STATUS parse(const QModelIndex & index, const QModelIndex & lastVtf);
QVector<QVector<QString> > getFitTable() const { return fitTable; }
std::vector<std::vector<QString> > getFitTable() const { return fitTable; }
private:
TreeModel *model;
QVector<QPair<QString, QModelIndex> > messagesVector;
std::vector<std::pair<QString, QModelIndex> > messagesVector;
QModelIndex lastVtf;
QVector<QVector<QString> > fitTable;
std::vector<std::vector<QString> > fitTable;
STATUS findFitRecursive(const QModelIndex & index, QModelIndex & found, UINT32 & fitOffset);
QString fitEntryTypeToQString(UINT8 type);

View File

@ -345,17 +345,6 @@ void TreeModel::setAction(const QModelIndex &index, const UINT8 action)
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setAction(action);
// On insert action, set insert action for children
if (action == Actions::Insert)
for (int i = 0; i < item->childCount(); i++)
setAction(index.child(i, 0), Actions::Insert);
// Set rebuild action for parent, if it has no action now
if (index.parent().isValid() && this->type(index.parent()) != Types::Root
&& this->action(index.parent()) == Actions::NoAction)
setAction(index.parent(), Actions::Rebuild);
emit dataChanged(index, index);
}

View File

@ -76,6 +76,7 @@ QString errorCodeToQString(UINT8 errorCode)
case ERR_CUSTOMIZED_DECOMPRESSION_FAILED: return QObject::tr("Customized compression failed");
case ERR_UNKNOWN_COMPRESSION_TYPE: return QObject::tr("Unknown compression type");
case ERR_UNKNOWN_EXTRACT_MODE: return QObject::tr("Unknown extract mode");
case ERR_UNKNOWN_REPLACE_MODE: return QObject::tr("Unknown replace mode");
//case ERR_UNKNOWN_INSERT_MODE: return QObject::tr("Unknown insert mode");
case ERR_UNKNOWN_IMAGE_TYPE: return QObject::tr("Unknown executable image type");
case ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE: return QObject::tr("Unknown PE optional header type");