Display message when search fails

Display a message 'could not be found' when the UEFITool search fails.
This commit is contained in:
Julian Prein 2023-07-07 16:31:44 +02:00 committed by Nikolaj Schlej
parent a7cf9cc3e3
commit a5675bda90
3 changed files with 50 additions and 14 deletions

View File

@ -19,6 +19,14 @@
#include <QRegExp>
#endif
USTATUS FfsFinder::findHexPattern(const UByteArray & hexPattern, const UINT8 mode) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findHexPattern(rootIndex, hexPattern, mode);
if (ret != U_SUCCESS)
msg(UString("Hex pattern \"") + UString(hexPattern) + UString("\" could not be found"), rootIndex);
return ret;
}
USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode)
{
if (!index.isValid())
@ -31,9 +39,11 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
if (hexPattern.count('.') == hexPattern.length())
return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
findHexPattern(index.model()->index(i, index.column(), index), hexPattern, mode);
if (U_SUCCESS == findHexPattern(index.model()->index(i, index.column(), index), hexPattern, mode))
ret = U_SUCCESS;
}
UByteArray data;
@ -83,6 +93,7 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
+ UString("\" in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index);
ret = U_SUCCESS;
}
}
@ -93,7 +104,15 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
#endif
}
return U_SUCCESS;
return ret;
}
USTATUS FfsFinder::findGuidPattern(const UByteArray & guidPattern, const UINT8 mode) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findGuidPattern(rootIndex, guidPattern, mode);
if (ret != U_SUCCESS)
msg(UString("GUID pattern \"") + UString(guidPattern) + UString("\" could not be found"), rootIndex);
return ret;
}
USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode)
@ -104,9 +123,11 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
if (!index.isValid())
return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
findGuidPattern(index.model()->index(i, index.column(), index), guidPattern, mode);
if (U_SUCCESS == findGuidPattern(index.model()->index(i, index.column(), index), guidPattern, mode))
ret = U_SUCCESS;
}
UByteArray data;
@ -174,6 +195,7 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
+ UString("\" in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index);
ret = U_SUCCESS;
}
#if QT_VERSION_MAJOR >= 6
@ -183,7 +205,16 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
#endif
}
return U_SUCCESS;
return ret;
}
USTATUS FfsFinder::findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findTextPattern(rootIndex, pattern, mode, unicode, caseSensitive);
if (ret != U_SUCCESS)
msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"")
+ UString(pattern) + UString("\" could not be found"), rootIndex);
return ret;
}
USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive)
@ -194,9 +225,11 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
if (!index.isValid())
return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
findTextPattern(index.model()->index(i, index.column(), index), pattern, mode, unicode, caseSensitive);
if (U_SUCCESS == findTextPattern(index.model()->index(i, index.column(), index), pattern, mode, unicode, caseSensitive))
ret = U_SUCCESS;
}
UByteArray body;
@ -236,7 +269,8 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
+ UString("\" found in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset),
index);
ret = U_SUCCESS;
}
return U_SUCCESS;
return ret;
}

View File

@ -30,9 +30,9 @@ public:
std::vector<std::pair<UString, UModelIndex> > getMessages() const { return messagesVector; }
void clearMessages() { messagesVector.clear(); }
USTATUS findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode);
USTATUS findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode);
USTATUS findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
USTATUS findHexPattern(const UByteArray & hexPattern, const UINT8 mode);
USTATUS findGuidPattern(const UByteArray & guidPattern, const UINT8 mode);
USTATUS findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
private:
const TreeModel* model;
@ -41,6 +41,10 @@ private:
void msg(const UString & message, const UModelIndex &index = UModelIndex()) {
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
}
USTATUS findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode);
USTATUS findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode);
USTATUS findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
};
#endif // FFSFINDER_H

View File

@ -305,8 +305,6 @@ void UEFITool::search()
if (searchDialog->exec() != QDialog::Accepted)
return;
QModelIndex rootIndex = model->index(0, 0);
int index = searchDialog->ui->tabWidget->currentIndex();
if (index == 0) { // Hex pattern
searchDialog->ui->hexEdit->setFocus();
@ -320,7 +318,7 @@ void UEFITool::search()
mode = SEARCH_MODE_BODY;
else
mode = SEARCH_MODE_ALL;
ffsFinder->findHexPattern(rootIndex, pattern, mode);
ffsFinder->findHexPattern(pattern, mode);
showFinderMessages();
}
else if (index == 1) { // GUID
@ -336,7 +334,7 @@ void UEFITool::search()
mode = SEARCH_MODE_BODY;
else
mode = SEARCH_MODE_ALL;
ffsFinder->findGuidPattern(rootIndex, pattern, mode);
ffsFinder->findGuidPattern(pattern, mode);
showFinderMessages();
}
else if (index == 2) { // Text string
@ -351,7 +349,7 @@ void UEFITool::search()
mode = SEARCH_MODE_BODY;
else
mode = SEARCH_MODE_ALL;
ffsFinder->findTextPattern(rootIndex, pattern, mode, searchDialog->ui->textUnicodeCheckBox->isChecked(),
ffsFinder->findTextPattern(pattern, mode, searchDialog->ui->textUnicodeCheckBox->isChecked(),
(Qt::CaseSensitivity) searchDialog->ui->textCaseSensitiveCheckBox->isChecked());
showFinderMessages();
}