GCC/Clang support

This commit is contained in:
Nikolaj Schlej 2016-03-21 11:00:10 +01:00
parent 95e5ee2496
commit 1f54d73f8c
3 changed files with 40 additions and 44 deletions

View File

@ -2252,7 +2252,7 @@ STATUS FfsParser::parseSectionBody(const QModelIndex & index)
if (!index.isValid())
return ERR_INVALID_PARAMETER;
QByteArray header = model->header(index);
if (header.size() < sizeof(EFI_COMMON_SECTION_HEADER))
if ((UINT32)header.size() < sizeof(EFI_COMMON_SECTION_HEADER))
return ERR_INVALID_SECTION;
const EFI_COMMON_SECTION_HEADER* sectionHeader = (const EFI_COMMON_SECTION_HEADER*)(header.constData());
@ -2912,6 +2912,8 @@ STATUS FfsParser::parseNvarStorage(const QByteArray & data, const QModelIndex &
QByteArray body;
QByteArray extendedData;
UINT32 guidAreaSize = guidsInStorage * sizeof(EFI_GUID);
UINT32 unparsedSize = (UINT32)data.size() - offset - guidAreaSize;
@ -3077,38 +3079,39 @@ STATUS FfsParser::parseNvarStorage(const QByteArray & data, const QModelIndex &
}
// Get variable name
UINT32 nameOffset = (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_GUID) ? sizeof(EFI_GUID) : 1; // GUID can be stored with the variable or in a separate storage, so there will only be an index of it
CHAR8* namePtr = (CHAR8*)(variableHeader + 1) + nameOffset;
UINT32 nameSize = 0;
if (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_ASCII_NAME) { // Name is stored as ASCII string of CHAR8s
text = QString(namePtr);
nameSize = text.length() + 1;
}
else { // Name is stored as UCS2 string of CHAR16s
text = QString::fromUtf16((CHAR16*)namePtr);
nameSize = (text.length() + 1) * 2;
}
{
UINT32 nameOffset = (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_GUID) ? sizeof(EFI_GUID) : 1; // GUID can be stored with the variable or in a separate storage, so there will only be an index of it
CHAR8* namePtr = (CHAR8*)(variableHeader + 1) + nameOffset;
UINT32 nameSize = 0;
if (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_ASCII_NAME) { // Name is stored as ASCII string of CHAR8s
text = QString(namePtr);
nameSize = text.length() + 1;
}
else { // Name is stored as UCS2 string of CHAR16s
text = QString::fromUtf16((CHAR16*)namePtr);
nameSize = (text.length() + 1) * 2;
}
// Get variable GUID
if (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_GUID) { // GUID is strored in the variable itself
name = guidToQString(*(EFI_GUID*)(variableHeader + 1));
// Get variable GUID
if (variableHeader->Attributes & NVRAM_NVAR_VARIABLE_ATTRIB_GUID) { // GUID is strored in the variable itself
name = guidToQString(*(EFI_GUID*)(variableHeader + 1));
}
// GUID is stored in GUID list at the end of the storage
else {
guidIndex = *(UINT8*)(variableHeader + 1);
if (guidsInStorage < guidIndex + 1)
guidsInStorage = guidIndex + 1;
// The list begins at the end of the storage and goes backwards
const EFI_GUID* guidPtr = (const EFI_GUID*)(data.constData() + data.size()) - 1 - guidIndex;
name = guidToQString(*guidPtr);
hasGuidIndex = true;
}
// Include variable name and GUID into the header and remove them from body
header = data.mid(offset, sizeof(NVAR_VARIABLE_HEADER) + nameOffset + nameSize);
body = body.mid(nameOffset + nameSize);
}
// GUID is stored in GUID list at the end of the storage
else {
guidIndex = *(UINT8*)(variableHeader + 1);
if (guidsInStorage < guidIndex + 1)
guidsInStorage = guidIndex + 1;
// The list begins at the end of the storage and goes backwards
const EFI_GUID* guidPtr = (const EFI_GUID*)(data.constData() + data.size()) - 1 - guidIndex;
name = guidToQString(*guidPtr);
hasGuidIndex = true;
}
// Include variable name and GUID into the header and remove them from body
header = data.mid(offset, sizeof(NVAR_VARIABLE_HEADER) + nameOffset + nameSize);
body = body.mid(nameOffset + nameSize);
parsing_done:
QString info;
// Rename invalid variables according to their types
@ -3187,16 +3190,15 @@ parsing_done:
.hexarg(extendedData.size()), varIndex);
// Check variable name to be in the list of nesting variables
for (std::vector<const CHAR8*>::const_iterator iter = nestingVariableNames.cbegin(); iter != nestingVariableNames.cend(); ++iter)
if (QString(*iter) == text.toLatin1()) {
STATUS result = parseNvarStorage(body, varIndex);
if (result)
msg(QObject::tr("parseNvarStorage: parsing of nested NVAR storage failed with error \"%1\"").arg(errorCodeToQString(result)), varIndex);
}
if (text.toLatin1() == QString("StdDefaults") || text.toLatin1() == QString("MfgDefaults")) {
STATUS result = parseNvarStorage(body, varIndex);
if (result)
msg(QObject::tr("parseNvarStorage: parsing of nested NVAR storage failed with error \"%1\"").arg(errorCodeToQString(result)), varIndex);
}
// Move to next variable
offset += variableHeader->Size;
}
return ERR_SUCCESS;
}
}

View File

@ -41,7 +41,3 @@ QString variableAttributesToQstring(UINT8 attributes)
return str.mid(2); // Remove the first comma and space
}
std::vector<const CHAR8*> nestingVariableNames = {
"StdDefaults",
"MfgDefaults"
};

View File

@ -33,8 +33,6 @@ const QByteArray NVRAM_NVAR_EXTERNAL_DEFAULTS_FILE_GUID
extern QString variableAttributesToQstring(UINT8 attributes);
extern std::vector<const CHAR8*> nestingVariableNames;
// Make sure we use right packing rules
#pragma pack(push,1)