Fix an issue with search result text

This commit is contained in:
Nikolaj Schlej 2023-01-28 21:48:16 -08:00
parent 5437efc2c5
commit fa5d744aac

View File

@ -75,10 +75,18 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
// For patterns that cross header|body boundary, skip patterns entirely located in body, since // For patterns that cross header|body boundary, skip patterns entirely located in body, since
// children search above has already found them. // children search above has already found them.
if (!(hasChildren && mode == SEARCH_MODE_ALL && offset/2 >= model->header(index).size())) { if (!(hasChildren && mode == SEARCH_MODE_ALL && offset/2 >= model->header(index).size())) {
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
UString name = model->name(index);
if (model->parent(index) == parentFileIndex) {
name = model->name(parentFileIndex) + UString("/") + name;
}
else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
}
msg(UString("Hex pattern \"") + UString(hexPattern) msg(UString("Hex pattern \"") + UString(hexPattern)
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper() + UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
+ UString("\" in ") + model->name(model->parent(index)) + UString("\" in ") + name
+ UString("/") + model->name(index)
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2), + usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index); index);
} }
@ -160,10 +168,18 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
while (offset >= 0) { while (offset >= 0) {
if (offset % 2 == 0) { if (offset % 2 == 0) {
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
UString name = model->name(index);
if (model->parent(index) == parentFileIndex) {
name = model->name(parentFileIndex) + UString("/") + name;
}
else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
}
msg(UString("GUID pattern \"") + UString(guidPattern) msg(UString("GUID pattern \"") + UString(guidPattern)
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper() + UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
+ UString("\" in ") + model->name(model->parent(index)) + UString("\" in ") + name
+ UString("/") + model->name(index)
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2), + usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index); index);
} }
@ -210,7 +226,7 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
#if QT_VERSION_MAJOR >= 6 #if QT_VERSION_MAJOR >= 6
data = UString::fromUtf16((const char16_t*)body.constData(), (int)(body.length() / 2)); data = UString::fromUtf16((const char16_t*)body.constData(), (int)(body.length() / 2));
#else #else
data = UString::fromUtf16((const ushort*)body.constData(), (int)(body.length() / 2)); data = UString::fromUtf16((const ushort*)body.constData(), (int)(body.length() / 2));
#endif #endif
else else
data = UString::fromLatin1((const char*)body.constData(), body.length()); data = UString::fromLatin1((const char*)body.constData(), body.length());
@ -218,9 +234,17 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
int offset = -1; int offset = -1;
while ((offset = (int)data.indexOf(pattern, (int)(offset + 1), caseSensitive)) >= 0) { while ((offset = (int)data.indexOf(pattern, (int)(offset + 1), caseSensitive)) >= 0) {
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
UString name = model->name(index);
if (model->parent(index) == parentFileIndex) {
name = model->name(parentFileIndex) + UString("/") + name;
}
else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
}
msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"") + UString(pattern) msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"") + UString(pattern)
+ UString("\" in ") + model->name(model->parent(index)) + UString("\" found in ") + name
+ UString("/") + model->name(index)
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", (unicode ? offset * 2 : offset)), + usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", (unicode ? offset * 2 : offset)),
index); index);
} }