Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring round 1 #271

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions UEFITool/ffsfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &

bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
findHexPattern(index.child(i, index.column()), hexPattern, mode);
#else
findHexPattern(index.model()->index(i, index.column(), index), hexPattern, mode);
#endif

}

UByteArray data;
Expand Down Expand Up @@ -109,11 +104,7 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &

bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
findGuidPattern(index.child(i, index.column()), guidPattern, mode);
#else
findGuidPattern(index.model()->index(i, index.column(), index), guidPattern, mode);
#endif
}

UByteArray data;
Expand Down Expand Up @@ -197,11 +188,7 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa

bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
findTextPattern(index.child(i, index.column()), pattern, mode, unicode, caseSensitive);
#else
findTextPattern(index.model()->index(i, index.column(), index), pattern, mode, unicode, caseSensitive);
#endif
}

UByteArray body;
Expand Down
30 changes: 22 additions & 8 deletions UEFITool/hexviewdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,32 @@ void HexViewDialog::setFont(const QFont &font)
hexView->setFont(font);
}

void HexViewDialog::setItem(const UModelIndex & index, bool bodyOnly)
void HexViewDialog::setItem(const UModelIndex & index, HexViewType type)
{
const TreeModel * model = (const TreeModel*)index.model();

// Set dialog title
UString itemName = model->name(index);
UString itemText = model->text(index);
setWindowTitle(UString("Hex view: ") + (itemText.isEmpty() ? itemName : itemName + " | " + itemText));

// Set hex data
// Set hex data and dialog title
QByteArray hexdata;
if (bodyOnly) hexdata = model->body(index);
else hexdata = model->header(index) + model->body(index) + model->tail(index);
UString dialogTitle;

switch (type) {
case fullHexView:
dialogTitle = UString("Hex view: ");
hexdata = model->header(index) + model->body(index) + model->tail(index);
break;
case bodyHexView:
dialogTitle = UString("Body hex view: ");
hexdata = model->body(index);
break;
case uncompressedHexView:
dialogTitle = UString("Uncompressed hex view: ");
hexdata = model->uncompressedData(index);
break;
}

dialogTitle += itemText.isEmpty() ? itemName : itemName + " | " + itemText;
setWindowTitle(dialogTitle);
hexView->setData(hexdata);
}
}
10 changes: 8 additions & 2 deletions UEFITool/hexviewdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ class HexViewDialog : public QDialog
Q_OBJECT

public:
enum HexViewType {
fullHexView,
bodyHexView,
uncompressedHexView
};

HexViewDialog(QWidget *parent = 0);
~HexViewDialog();
Ui::HexViewDialog* ui;

void setItem(const UModelIndex & index, bool bodyOnly);
void setItem(const UModelIndex & index, HexViewType dataType);
void setFont(const QFont &font);

private:
QHexEdit * hexView;
};
Expand Down
29 changes: 15 additions & 14 deletions UEFITool/uefitool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ markingEnabled(true)
connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search()));
connect(ui->actionHexView, SIGNAL(triggered()), this, SLOT(hexView()));
connect(ui->actionBodyHexView, SIGNAL(triggered()), this, SLOT(bodyHexView()));
connect(ui->actionUncompressedHexView, SIGNAL(triggered()), this, SLOT(uncompressedHexView()));
connect(ui->actionExtract, SIGNAL(triggered()), this, SLOT(extractAsIs()));
connect(ui->actionExtractBody, SIGNAL(triggered()), this, SLOT(extractBody()));
connect(ui->actionExtractBodyUncompressed, SIGNAL(triggered()), this, SLOT(extractBodyUncompressed()));
Expand Down Expand Up @@ -231,6 +232,7 @@ void UEFITool::populateUi(const QModelIndex &current)
// Enable actions
ui->actionHexView->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current) && model->hasEmptyTail(current));
ui->actionBodyHexView->setDisabled(model->hasEmptyBody(current));
ui->actionUncompressedHexView->setDisabled(model->hasEmptyUncompressedData(current));
ui->actionExtract->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current) && model->hasEmptyTail(current));
ui->actionGoToData->setEnabled(type == Types::NvarEntry && subtype == Subtypes::LinkNvarEntry);

Expand All @@ -240,7 +242,7 @@ void UEFITool::populateUi(const QModelIndex &current)

//ui->actionRebuild->setEnabled(type == Types::Volume || type == Types::File || type == Types::Section);
ui->actionExtractBody->setDisabled(model->hasEmptyBody(current));
ui->actionExtractBodyUncompressed->setEnabled(enableExtractBodyUncompressed(current));
ui->actionExtractBodyUncompressed->setDisabled(model->hasEmptyUncompressedData(current));
//ui->actionRemove->setEnabled(type == Types::Volume || type == Types::File || type == Types::Section);
//ui->actionInsertInto->setEnabled((type == Types::Volume && subtype != Subtypes::UnknownVolume) ||
// (type == Types::File && subtype != EFI_FV_FILETYPE_ALL && subtype != EFI_FV_FILETYPE_RAW && subtype != EFI_FV_FILETYPE_PAD) ||
Expand All @@ -253,13 +255,6 @@ void UEFITool::populateUi(const QModelIndex &current)
ui->menuMessageActions->setEnabled(false);
}

bool UEFITool::enableExtractBodyUncompressed(const QModelIndex &current)
{
// TODO: rewrite based on model->compressed()
U_UNUSED_PARAMETER(current);
return false;
}

void UEFITool::search()
{
if (searchDialog->exec() != QDialog::Accepted)
Expand Down Expand Up @@ -323,7 +318,7 @@ void UEFITool::hexView()
if (!index.isValid())
return;

hexViewDialog->setItem(index, false);
hexViewDialog->setItem(index, HexViewDialog::HexViewType::fullHexView);
hexViewDialog->exec();
}

Expand All @@ -333,7 +328,17 @@ void UEFITool::bodyHexView()
if (!index.isValid())
return;

hexViewDialog->setItem(index, true);
hexViewDialog->setItem(index, HexViewDialog::HexViewType::bodyHexView);
hexViewDialog->exec();
}

void UEFITool::uncompressedHexView()
{
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
if (!index.isValid())
return;

hexViewDialog->setItem(index, HexViewDialog::HexViewType::uncompressedHexView);
hexViewDialog->exec();
}

Expand Down Expand Up @@ -390,11 +395,7 @@ void UEFITool::goToData()
}

for (int j = i + 1; j < model->rowCount(parent); j++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
QModelIndex currentIndex = parent.child(j, 0);
#else
QModelIndex currentIndex = parent.model()->index(j, 0, parent);
#endif

if (model->hasEmptyParsingData(currentIndex))
continue;
Expand Down
3 changes: 1 addition & 2 deletions UEFITool/uefitool.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private slots:

void hexView();
void bodyHexView();
void uncompressedHexView();
void goToData();

void extract(const UINT8 mode);
Expand Down Expand Up @@ -144,8 +145,6 @@ private slots:
const QString version;
bool markingEnabled;

bool enableExtractBodyUncompressed(const QModelIndex &current);

bool eventFilter(QObject* obj, QEvent* event);
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
Expand Down
3 changes: 1 addition & 2 deletions UEFITool/uefitool.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui widgets

TARGET = UEFITool
TEMPLATE = app
Expand Down
17 changes: 17 additions & 0 deletions UEFITool/uefitool.ui
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionExtract"/>
<addaction name="actionExtractBody"/>
Expand Down Expand Up @@ -401,6 +402,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionExtract"/>
<addaction name="actionExtractBody"/>
Expand All @@ -421,6 +423,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionExtract"/>
<addaction name="actionExtractBody"/>
Expand All @@ -445,6 +448,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionExtract"/>
<addaction name="actionExtractBody"/>
Expand Down Expand Up @@ -482,6 +486,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionGoToData"/>
<addaction name="separator"/>
Expand All @@ -507,6 +512,7 @@
</property>
<addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/>
<addaction name="actionExtract"/>
<addaction name="actionExtractBody"/>
Expand Down Expand Up @@ -845,6 +851,17 @@
<string>Ctrl+Shift+D</string>
</property>
</action>
<action name="actionUncompressedHexView">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Un&amp;compressed hex view...</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+D</string>
</property>
</action>
<action name="actionLoadGuidDatabase">
<property name="text">
<string>Load &amp;GUID database...</string>
Expand Down
3 changes: 0 additions & 3 deletions common/ffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ typedef struct EFI_COMMON_SECTION_HEADER_APPLE {
// Section2 usage indicator
#define EFI_SECTION2_IS_USED 0xFFFFFF

// Apple section usage indicator
#define EFI_SECTION_APPLE_USED 0x7FFF

// File section types
#define EFI_SECTION_ALL 0x00 // Impossible attribute for file in the FS

Expand Down
20 changes: 1 addition & 19 deletions common/ffsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ USTATUS FfsBuilder::buildCapsule(const UModelIndex & index, UByteArray & capsule
}

// Build image
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
UModelIndex imageIndex = index.child(0, 0);
#else
UModelIndex imageIndex = index.model()->index(0, 0, index);
#endif

UByteArray imageData;

// Check image type
Expand Down Expand Up @@ -170,19 +165,11 @@ USTATUS FfsBuilder::buildIntelImage(const UModelIndex & index, UByteArray & inte
// Rebuild
else if (model->action(index) == Actions::Rebuild) {
// First child will always be descriptor for this type of image, and it's read only for now
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
intelImage = model->header(index.child(0, 0)) + model->body(index.child(0, 0)) + model->tail(index.child(0, 0));
#else
intelImage = model->header(index.model()->index(0, 0, index)) + model->body(index.model()->index(0, 0, index)) + model->tail(index.model()->index(0, 0, index));
#endif

// Process other regions
for (int i = 1; i < model->rowCount(index); i++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
UModelIndex currentRegion = index.child(i, 0);
#else
UModelIndex currentRegion = index.model()->index(i, 0, index);
#endif

// Skip regions with Remove action
if (model->action(currentRegion) == Actions::Remove)
Expand Down Expand Up @@ -282,14 +269,9 @@ USTATUS FfsBuilder::buildRawArea(const UModelIndex & index, UByteArray & rawArea
// Build children
for (int i = 0; i < model->rowCount(index); i++) {
USTATUS result = U_SUCCESS;

#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
UModelIndex currentChild = index.child(i, 0);
#else
UModelIndex currentChild = index.model()->index(i, 0, index);
#endif

UByteArray currentData;

// Check child type
if (model->type(currentChild) == Types::Volume) {
result = buildVolume(currentChild, currentData);
Expand Down
19 changes: 2 additions & 17 deletions common/ffsops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,9 @@ USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteA
extracted += model->body(index);
}
else if (mode == EXTRACT_MODE_BODY_UNCOMPRESSED) {
name += UString("_body_unc");
// Extract without header and tail, uncompressed
name += UString("_body_uncompressed");
extracted.clear();
// There is no need to redo decompression, we can use child items
for (int i = 0; i < model->rowCount(index); i++) {
#if ((QT_VERSION_MAJOR == 5) && (QT_VERSION_MINOR < 6)) || (QT_VERSION_MAJOR < 5)
UModelIndex childIndex = index.child(i, 0);
#else
UModelIndex childIndex = index.model()->index(i, 0, index);
#endif

// Ensure 4-byte alignment of current section
extracted += UByteArray(ALIGN4((UINT32)extracted.size()) - (UINT32)extracted.size(), '\x00');
// Add current section header, body and tail
extracted += model->header(childIndex);
extracted += model->body(childIndex);
extracted += model->tail(childIndex);
}
extracted += model->uncompressedData(index);
}
else
return U_UNKNOWN_EXTRACT_MODE;
Expand Down
Loading