1
0
Fork 0
mirror of https://github.com/LongSoft/UEFITool.git synced 2025-05-23 19:47:06 -04:00

Improve parsing error detection for DVARs

This commit is contained in:
Nikolaj Schlej 2025-04-28 17:28:06 +07:00
parent c235533f22
commit 7237a29b17

View file

@ -1171,28 +1171,46 @@ USTATUS FfsParser::parseRawArea(const UModelIndex & index)
break;
}
// This is a normal entry
// Check entry format to be known
bool formatKnown = true;
// Check state to be known
if (entry->state() != DVAR_ENTRY_STATE_STORING &&
entry->state() != DVAR_ENTRY_STATE_STORED &&
entry->state() != DVAR_ENTRY_STATE_DELETING &&
entry->state() != DVAR_ENTRY_STATE_DELETED){
// TODO: Add the rest as padding, as we encountered an unexpected entry and can't guarantee that the rest got parsed correctly
formatKnown = false;
msg(usprintf("%s: DVAR entry with unknown state %02X", __FUNCTION__, entry->state()), headerIndex);
}
// Check flags to be known
if (entry->flags() != DVAR_ENTRY_FLAG_NAME_ID &&
entry->flags() != DVAR_ENTRY_FLAG_NAME_ID + DVAR_ENTRY_FLAG_NAMESPACE_GUID) {
// TODO: Add the rest as padding, as we encountered an unexpected entry and can't guarantee that the rest got parsed correctly
formatKnown = false;
msg(usprintf("%s: DVAR entry with unknown flags %02X", __FUNCTION__, entry->flags()), headerIndex);
}
// Check type to be known
if (entry->type() != DVAR_ENTRY_TYPE_NAME_ID_8_DATA_SIZE_8 &&
entry->type() != DVAR_ENTRY_TYPE_NAME_ID_16_DATA_SIZE_8 &&
entry->type() != DVAR_ENTRY_TYPE_NAME_ID_16_DATA_SIZE_16) {
// TODO: Add the rest as padding, as we encountered an unexpected entry and can't guarantee that the rest got parsed correctly
formatKnown = false;
msg(usprintf("%s: DVAR entry with unknown type %02X", __FUNCTION__, entry->type()), headerIndex);
}
// This is an unknown entry
if (!formatKnown) {
// No way to continue from here, because we can not be sure that the rest of the store got parsed correctly
UByteArray padding = data.mid(entryOffset, storeSize - entryOffset);
// Get info
name = UString("Padding");
info = usprintf("Full size: %Xh (%u)", (UINT32)padding.size(), (UINT32)padding.size());
// Add tree item
model->addItem(entryOffset, Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), Fixed, headerIndex);
}
// This is a normal entry
else {
UINT32 headerSize;
UINT32 bodySize;
UINT32 entrySize;
@ -1200,8 +1218,6 @@ USTATUS FfsParser::parseRawArea(const UModelIndex & index)
UINT8 subtype;
UString text;
// TODO: find a Dell image with NameUtf8 entries
// NamespaceGUID entry
if (entry->flags() == DVAR_ENTRY_FLAG_NAME_ID + DVAR_ENTRY_FLAG_NAMESPACE_GUID) {
// State of this variable only applies to the NameId part, not the NamespaceGuid part
@ -1294,6 +1310,7 @@ USTATUS FfsParser::parseRawArea(const UModelIndex & index)
entryOffset += entrySize;
}
}
}
catch (...) {
// Parsing failed, need to add the candidate as Padding
UByteArray padding = data.mid(itemOffset, itemSize);