@@ -976,7 +976,6 @@ USTATUS FfsParser::parseRawArea(const UModelIndex & index)
976976 parsed.num_extensions (),
977977 (UINT32 )parsed.fd_base_address (),
978978 parsed.checksum ());
979-
980979 // Check header checksum
981980 {
982981 UByteArray tempHeader = data.mid (itemOffset, sizeof (INSYDE_FLASH_DEVICE_MAP_HEADER ));
@@ -991,89 +990,92 @@ USTATUS FfsParser::parseRawArea(const UModelIndex & index)
991990 }
992991 }
993992
994- // Add board IDs
995- if (!parsed._is_null_board_ids ()) {
996- info += usprintf (" \n Region index: %Xh\n BoardId Count: %u" ,
997- parsed.board_ids ()->region_index (),
998- parsed.board_ids ()->num_board_ids ());
999- UINT32 i = 0 ;
1000- for (const auto & boardId : *parsed.board_ids ()->board_ids ()) {
1001- info += usprintf (" \n BoardId #%u: %" PRIX64 " \n " , i++, boardId);
1002- }
1003- }
1004-
1005993 // Add header tree item
1006994 UModelIndex headerIndex = model->addItem (headerSize + itemOffset, Types::InsydeFlashDeviceMapStore, 0 , name, UString (), info, header, body, UByteArray (), Fixed, index);
1007995
1008- // Add entries
1009- UINT32 entryOffset = parsed.data_offset ();
1010- bool protectedRangeFound = false ;
1011- for (const auto & entry : *parsed.entries ()->entries ()) {
1012- const EFI_GUID guid = readUnaligned ((const EFI_GUID *)entry->guid ().c_str ());
1013- name = insydeFlashDeviceMapEntryTypeGuidToUString (guid);
1014- UString text;
1015- header = data.mid (itemOffset + entryOffset, sizeof (INSYDE_FLASH_DEVICE_MAP_ENTRY ));
1016- body = data.mid (itemOffset + entryOffset + header.size (), parsed.entry_size () - header.size ());
1017-
1018- // Add info
1019- UINT32 entrySize = (UINT32 )header.size () + (UINT32 )body.size ();
1020- info = UString (" Region type: " ) + guidToUString (guid, false ) + " \n " ;
1021- info += UString (" Region id: " );
1022- for (UINT8 i = 0 ; i < 16 ; i++) {
1023- info += usprintf (" %02X" , *(const UINT8 *)(entry->region_id ().c_str () + i));
1024- }
1025- info += usprintf (" \n Region address: %08Xh\n Region size: %08Xh\n Attributes: %08Xh (" ,
1026- (UINT32 )entry->region_base (),
1027- (UINT32 )entry->region_size (),
1028- entry->attributes ());
1029-
1030- // Add atributes
1031- if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == 0 ) {
1032- info += UString (" HashVerified" );
1033- }
1034- else if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) {
1035- info += UString (" HashIgnored" );
1036- }
1037- else if (entry->attributes () > INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) {
1038- info += usprintf (" , Unknown %08X" , entry->attributes () - INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE );
1039- msg (usprintf (" %s: FlashDeviceMap entry with unknown attributes %08X" , __FUNCTION__, entry->attributes ()), headerIndex);
1040- }
1041- info += UString (" )" );
1042-
1043- // Add hash
1044- info += UString (" \n SHA256: " );
1045- for (UINT16 j = 0 ; j < (UINT16 )body.size (); j++) {
1046- info += usprintf (" %02X" , (UINT8 )body.constData ()[j]);
1047- }
1048-
1049- if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == 0 ) {
1050- if (!protectedRangeFound) {
1051- securityInfo += usprintf (" Insyde Flash Device Map found at base %08Xh\n Protected ranges:\n " , model->base (headerIndex));
1052- protectedRangeFound = true ;
996+ // Check if we can add entries
997+ if (parsed._is_null_entries ()) {
998+ msg (usprintf (" %s: FDM store with unknown entry format or size" , __FUNCTION__), headerIndex);
999+ }
1000+ else {
1001+ // Add entries
1002+ UINT32 entryOffset = parsed.data_offset ();
1003+ bool protectedRangeFound = false ;
1004+ for (const auto & entry : *parsed.entries ()->entries ()) {
1005+ const EFI_GUID guid = readUnaligned ((const EFI_GUID *)entry->guid ().c_str ());
1006+ name = insydeFlashDeviceMapEntryTypeGuidToUString (guid);
1007+ UString text;
1008+ header = data.mid (itemOffset + entryOffset, sizeof (INSYDE_FLASH_DEVICE_MAP_ENTRY ));
1009+ body = data.mid (itemOffset + entryOffset + header.size (), parsed.entry_size () - header.size ());
1010+
1011+ // Add info
1012+ UINT32 entrySize = (UINT32 )header.size () + (UINT32 )body.size ();
1013+ info = UString (" Region type: " ) + guidToUString (guid, false ) + " \n " ;
1014+ info += UString (" Region id: " );
1015+ for (UINT8 i = 0 ; i < 16 ; i++) {
1016+ info += usprintf (" %02X" , *(const UINT8 *)(entry->region_id ().c_str () + i));
10531017 }
1018+ info += usprintf (" \n Region address: %08Xh\n Region size: %08Xh\n Attributes: %08Xh (" ,
1019+ (UINT32 )entry->region_base (),
1020+ (UINT32 )entry->region_size (),
1021+ entry->attributes ());
10541022
1055- // TODO: make sure that the only hash possible here is SHA256
1023+ // Add atributes
1024+ // Ignored or Valid
1025+ if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_IGNORED ) == 0 ) {
1026+ info += UString (" EntryValid" );
1027+ }
1028+ else if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_IGNORED ) == INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_IGNORED ) {
1029+ info += UString (" EntryIgnored" );
1030+ }
1031+ // HashIgnored or HashVerified
1032+ if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == 0 ) {
1033+ info += UString (" , HashVerified" );
1034+ }
1035+ else if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) {
1036+ info += UString (" , HashIgnored" );
1037+ }
1038+ // Unknown atributes other than the two known above
1039+ if (entry->attributes () > INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_IGNORED + INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) {
1040+ UINT32 unknown_attributes = entry->attributes () & ((UINT32 )(0xFFFFFFFFC ));
1041+ info += usprintf (" , Unknown %08Xh" , unknown_attributes);
1042+ msg (usprintf (" %s: FlashDeviceMap entry with unknown attributes %08Xh" , __FUNCTION__, unknown_attributes), headerIndex);
1043+ }
1044+ info += UString (" )" );
10561045
1057- // Add this region to the list of Insyde protected regions
1058- PROTECTED_RANGE range = {};
1059- range.Offset = (UINT32 )entry->region_base ();
1060- range.Size = (UINT32 )entry->region_size ();
1061- range.AlgorithmId = TCG_HASH_ALGORITHM_ID_SHA256 ;
1062- range.Type = PROTECTED_RANGE_VENDOR_HASH_INSYDE ;
1063- range.Hash = body;
1064- protectedRanges.push_back (range);
1046+ // Add hash
1047+ info += UString (" \n SHA256: " );
1048+ for (UINT16 j = 0 ; j < (UINT16 )body.size (); j++) {
1049+ info += usprintf (" %02X" , (UINT8 )body.constData ()[j]);
1050+ }
10651051
1066- securityInfo += usprintf (" Address: %08Xh Size: %Xh\n Hash: " , range.Offset , range.Size ) + UString (body.toHex ().constData ()) + " \n " ;
1052+ if ((entry->attributes () & INSYDE_FLASH_DEVICE_MAP_ENTRY_ATTRIBUTE_MODIFIABLE ) == 0 ) {
1053+ if (!protectedRangeFound) {
1054+ securityInfo += usprintf (" Insyde Flash Device Map found at base %08Xh\n Protected ranges:\n " , model->base (headerIndex));
1055+ protectedRangeFound = true ;
1056+ }
1057+
1058+ // Add this region to the list of Insyde protected regions
1059+ PROTECTED_RANGE range = {};
1060+ range.Offset = (UINT32 )entry->region_base ();
1061+ range.Size = (UINT32 )entry->region_size ();
1062+ range.AlgorithmId = TCG_HASH_ALGORITHM_ID_SHA256 ;
1063+ range.Type = PROTECTED_RANGE_VENDOR_HASH_INSYDE ;
1064+ range.Hash = body;
1065+ protectedRanges.push_back (range);
1066+
1067+ securityInfo += usprintf (" Address: %08Xh Size: %Xh\n Hash: " , range.Offset , range.Size ) + UString (body.toHex ().constData ()) + " \n " ;
1068+ }
1069+
1070+ // Add tree item
1071+ model->addItem (entryOffset, Types::InsydeFlashDeviceMapEntry, 0 , name, text, info, header, body, UByteArray (), Fixed, headerIndex);
1072+
1073+ entryOffset += entrySize;
10671074 }
10681075
1069- // Add tree item
1070- model->addItem (entryOffset, Types::InsydeFlashDeviceMapEntry, 0 , name, text, info, header, body, UByteArray (), Fixed, headerIndex);
1071-
1072- entryOffset += entrySize;
1073- }
1074-
1075- if (protectedRangeFound) {
1076- securityInfo += " \n " ;
1076+ if (protectedRangeFound) {
1077+ securityInfo += " \n " ;
1078+ }
10771079 }
10781080 }
10791081 catch (...) {
0 commit comments