MCPcopy Create free account
hub / github.com/LongSoft/UEFITool / parseFile

Method parseFile

ffsengine.cpp:1218–1396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1216}
1217
1218UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const UINT8 revision, const UINT8 erasePolarity, const QModelIndex & parent, const UINT8 mode)
1219{
1220 bool msgInvalidHeaderChecksum = false;
1221 bool msgInvalidDataChecksum = false;
1222 bool msgInvalidTailValue = false;
1223 bool msgInvalidType = false;
1224
1225 // Populate file header
1226 if ((UINT32)file.size() < sizeof(EFI_FFS_FILE_HEADER))
1227 return ERR_INVALID_FILE;
1228 const EFI_FFS_FILE_HEADER* fileHeader = (const EFI_FFS_FILE_HEADER*)file.constData();
1229
1230 // Construct empty byte for this file
1231 char empty = erasePolarity ? '\xFF' : '\x00';
1232
1233 // Get file header
1234 QByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER));
1235 if (revision > 1 && (fileHeader->Attributes & FFS_ATTRIB_LARGE_FILE)) {
1236 if ((UINT32)file.size() < sizeof(EFI_FFS_FILE_HEADER2))
1237 return ERR_INVALID_FILE;
1238 header = file.left(sizeof(EFI_FFS_FILE_HEADER2));
1239 }
1240
1241 // Check header checksum
1242 UINT8 calculatedHeader = 0x100 - (calculateSum8((const UINT8*)header.constData(), header.size()) - fileHeader->IntegrityCheck.Checksum.Header - fileHeader->IntegrityCheck.Checksum.File - fileHeader->State);
1243 if (fileHeader->IntegrityCheck.Checksum.Header != calculatedHeader)
1244 msgInvalidHeaderChecksum = true;
1245
1246 // Get file body
1247 QByteArray body = file.mid(header.size());
1248
1249 // Check for file tail presence
1250 QByteArray tail;
1251 if (revision == 1 && fileHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
1252 //Check file tail;
1253 tail = body.right(sizeof(UINT16));
1254 UINT16 tailValue = *(UINT16*)tail.constData();
1255 if (fileHeader->IntegrityCheck.TailReference != (UINT16)~tailValue)
1256 msgInvalidTailValue = true;
1257
1258 // Remove tail from file body
1259 body = body.left(body.size() - sizeof(UINT16));
1260 }
1261
1262 // Check data checksum
1263 // Data checksum must be calculated
1264 UINT8 calculatedData = 0;
1265 if (fileHeader->Attributes & FFS_ATTRIB_CHECKSUM) {
1266 calculatedData = calculateChecksum8((const UINT8*)body.constData(), body.size());
1267 }
1268 // Data checksum must be one of predefined values
1269 else if (revision == 1) {
1270 calculatedData = FFS_FIXED_CHECKSUM;
1271 }
1272 else {
1273 calculatedData = FFS_FIXED_CHECKSUM2;
1274 }
1275

Callers

nothing calls this directly

Calls 6

calculateSum8Function · 0.85
calculateChecksum8Function · 0.85
guidToQStringFunction · 0.85
errorMessageFunction · 0.85
addItemMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected