File: nvramparser.cpp

package info (click to toggle)
uefitool 0.28.0%2BA73-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,728 kB
  • sloc: ansic: 55,322; cpp: 23,375; sh: 43; xml: 23; makefile: 5
file content (1546 lines) | stat: -rw-r--r-- 82,594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
/* nvramparser.cpp
 
 Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.
 
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 */

#ifdef U_ENABLE_NVRAM_PARSING_SUPPORT
#include <map>

#include "nvramparser.h"
#include "parsingdata.h"
#include "ustring.h"
#include "utility.h"
#include "nvram.h"
#include "ffs.h"
#include "intel_microcode.h"

#include "umemstream.h"
#include "kaitai/kaitaistream.h"
#include "generated/ami_nvar.h"
#include "generated/apple_sysf.h"
#include "generated/edk2_vss.h"
#include "generated/edk2_vss2.h"
#include "generated/edk2_ftw.h"
#include "generated/insyde_fdc.h"
#include "generated/ms_slic_pubkey.h"
#include "generated/ms_slic_marker.h"
#include "generated/phoenix_flm.h"
#include "generated/phoenix_evsa.h"

#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif

USTATUS NvramParser::parseNvarStore(const UModelIndex & index, const bool probe)
{
    // Sanity check
    if (!index.isValid())
        return U_INVALID_PARAMETER;

    UByteArray nvar = model->body(index);

    // Nothing to parse in an empty store
    if (nvar.isEmpty())
        return probe ? U_STORES_NOT_FOUND : U_SUCCESS;

    // Obtain required fields from parsing data
    UINT8 emptyByte = 0xFF;
    if (model->hasEmptyParsingData(index) == false) {
        UByteArray data = model->parsingData(index);
        const VOLUME_PARSING_DATA* pdata = (const VOLUME_PARSING_DATA*)data.constData();
        emptyByte = pdata->emptyByte;
    }
    
    try {
        const UINT32 localOffset = (UINT32)model->header(index).size();
        umemstream is(nvar.constData(), nvar.size());
        kaitai::kstream ks(&is);
        ami_nvar_t parsed(&ks);

        UINT16 guidsInStore = 0;
        UINT32 currentEntryIndex = 0;
        for (const auto & entry : *parsed.entries()) {
            UINT8 subtype = Subtypes::FullNvarEntry;
            UString name;
            UString text;
            UString info;
            UString guid;
            UByteArray header;
            UByteArray body;
            UByteArray tail;

            // This is a terminating entry, needs special processing
            if (entry->_is_null_signature_rest()) {
                UINT32 guidAreaSize = guidsInStore * sizeof(EFI_GUID);
                UINT32 unparsedSize = (UINT32)nvar.size() - entry->offset() - guidAreaSize;

                // Check if the data left is a free space or a padding
                UByteArray padding = nvar.mid(entry->offset(), unparsedSize);

                // Get info
                UString info = usprintf("Full size: %Xh (%u)", (UINT32)padding.size(), (UINT32)padding.size());

                if (isUniformByte(padding, emptyByte)) { // Free space
                    if (probe && nvar.size() == padding.size())
                        return U_STORES_NOT_FOUND;
                    // Add tree item
                    model->addItem(localOffset + entry->offset(), Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), padding, UByteArray(), Fixed, index);
                }
                else {
                    // Nothing is parsed yet, but the file is not empty
                    if (entry->offset() == 0) {
                        if (!probe)
                            msg(usprintf("%s: file can't be parsed as NVAR variable store", __FUNCTION__), index);
                        return U_INVALID_FILE;
                    }

                    // Add tree item
                    model->addItem(localOffset + entry->offset(), Types::Padding, getPaddingType(padding), UString("Padding"), UString(), info, UByteArray(), padding, UByteArray(), Fixed, index);
                }

                // Add GUID store area
                UByteArray guidArea = nvar.right(guidAreaSize);
                // Get info
                name = UString("GUID store");
                info = usprintf("Full size: %Xh (%u)\nGUIDs in store: %u",
                                (UINT32)guidArea.size(), (UINT32)guidArea.size(),
                                guidsInStore);
                // Add tree item
                model->addItem((UINT32)(localOffset + entry->offset() + padding.size()), Types::NvarGuidStore, 0, name, UString(), info, UByteArray(), guidArea, UByteArray(), Fixed, index);

                return U_SUCCESS;
            }

            // This is a normal entry
            const auto entry_body = entry->body();

            // Set default next to predefined last value
            NVAR_ENTRY_PARSING_DATA pdata = {};
            pdata.emptyByte = emptyByte;
            pdata.next = 0xFFFFFF;
            pdata.isValid = TRUE;

            // Check for invalid entry
            if (!entry->attributes()->valid()) {
                subtype = Subtypes::InvalidNvarEntry;
                name = UString("Invalid");
                pdata.isValid = FALSE;
                goto processing_done;
            }

            // Check for link entry
            if (entry->next() != 0xFFFFFF) {
                subtype = Subtypes::LinkNvarEntry;
                pdata.next = (UINT32)entry->next();
            }

            // Check for data-only entry (nameless and GUIDless entry or link)
            if (entry->attributes()->data_only()) {
                // Search backwards for a previous entry with a link to this variable
                UModelIndex prevEntryIndex;
                if (currentEntryIndex > 0) {
                    for (UINT32 i = currentEntryIndex - 1; i > 0; i--) {
                        const auto & previousEntry = parsed.entries()->at(i);

                        if (previousEntry == entry)
                            break;

                        if ((UINT32)previousEntry->next() + (UINT32)previousEntry->offset() == (UINT32)entry->offset()) { // Previous link is present and valid
                            prevEntryIndex = index.model()->index(i, 0, index);
                            // Make sure that we are linking to a valid entry
                            NVAR_ENTRY_PARSING_DATA pd = readUnaligned((NVAR_ENTRY_PARSING_DATA*)model->parsingData(prevEntryIndex).constData());
                            if (!pd.isValid) {
                                prevEntryIndex = UModelIndex();
                            }
                            break;
                        }
                    }
                }
                // Check if the link is valid
                if (prevEntryIndex.isValid()) {
                    // Use the name and text of the previous entry
                    name = model->name(prevEntryIndex);
                    text = model->text(prevEntryIndex);

                    if (entry->next() == 0xFFFFFF)
                        subtype = Subtypes::DataNvarEntry;
                }
                else {
                    subtype = Subtypes::InvalidLinkNvarEntry;
                    name = UString("InvalidLink");
                    pdata.isValid = FALSE;
                }
                goto processing_done;
            }

            // Obtain text
            if (!entry_body->_is_null_ascii_name()) {
                text = entry_body->ascii_name().c_str();
            }
            else if (!entry_body->_is_null_ucs2_name()) {
                UByteArray temp;
                for (const auto & ch : *entry_body->ucs2_name()->ucs2_chars()) {
                    temp += UByteArray((const char*)&ch, sizeof(ch));
                }
                text = uFromUcs2(temp.constData());
            }

            // Obtain GUID
            if (!entry_body->_is_null_guid()) { // GUID is stored in the entry itself
                const EFI_GUID g = readUnaligned((EFI_GUID*)entry_body->guid().c_str());
                name = guidToUString(g);
                guid = guidToUString(g, false);
            }
            else { // GUID is stored in GUID store at the end of the NVAR store
                // Grow the GUID store if needed
                if (guidsInStore < entry_body->guid_index() + 1)
                    guidsInStore = entry_body->guid_index() + 1;

                // The list begins at the end of the store and goes backwards
                const EFI_GUID g = readUnaligned((EFI_GUID*)(nvar.constData() + nvar.size()) - (entry_body->guid_index() + 1));
                name = guidToUString(g);
                guid = guidToUString(g, false);
            }

processing_done:
            // This feels hacky, but I haven't found a way to ask Kaitai for raw bytes
            header = nvar.mid(entry->offset(), sizeof(NVAR_ENTRY_HEADER) + entry_body->data_start_offset());
            body = nvar.mid(entry->offset() + sizeof(NVAR_ENTRY_HEADER) + entry_body->data_start_offset(), entry_body->data_size());
            tail = nvar.mid(entry->end_offset() - entry_body->extended_header_size(), entry_body->extended_header_size());

            // Add GUID info for valid entries
            if (!guid.isEmpty())
                info += UString("Variable GUID: ") + guid + "\n";

            // Add GUID index information
            if (!entry_body->_is_null_guid_index())
                info += usprintf("GUID index: %u\n", entry_body->guid_index());

            // Add header, body and extended data info
            info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nTail size: %Xh (%u)",
                             entry->size(), entry->size(),
                             (UINT32)header.size(), (UINT32)header.size(),
                             (UINT32)body.size(), (UINT32)body.size(),
                             (UINT32)tail.size(), (UINT32)tail.size());

            // Add attributes info
            const NVAR_ENTRY_HEADER entryHeader = readUnaligned((NVAR_ENTRY_HEADER*)header.constData());
            info += usprintf("\nAttributes: %02Xh", entryHeader.Attributes);

            // Translate attributes to text
            if (entryHeader.Attributes != 0x00 && entryHeader.Attributes != 0xFF)
                info += UString(" (") + nvarAttributesToUString(entryHeader.Attributes) + UString(")");

            // Add next node info
            if (entry->next() != 0xFFFFFF)
                info += usprintf("\nNext node at offset: %Xh", localOffset + entry->offset() + (UINT32)entry->next());

            // Add extended header info
            if (entry_body->extended_header_size() > 0) {
                info += usprintf("\nExtended header size: %Xh (%u)",
                                 entry_body->extended_header_size(), entry_body->extended_header_size());

                const UINT8 extendedAttributes = *tail.constData();
                info += usprintf("\nExtended attributes: %02Xh (", extendedAttributes) + nvarExtendedAttributesToUString(extendedAttributes) + UString(")");

                // Add checksum
                if (!entry_body->_is_null_extended_header_checksum()) {
                    UINT8 calculatedChecksum = 0;
                    UByteArray wholeBody = body + tail;

                    // Include entry body
                    UINT8* start = (UINT8*)wholeBody.constData();
                    for (UINT8* p = start; p < start + wholeBody.size(); p++) {
                        calculatedChecksum += *p;
                    }
                    // Include entry size and flags
                    start = (UINT8*)&entryHeader.Size;
                    for (UINT8*p = start; p < start + sizeof(UINT16); p++) {
                        calculatedChecksum += *p;
                    }
                    // Include entry attributes
                    calculatedChecksum += entryHeader.Attributes;
                    info += usprintf("\nChecksum: %02Xh, ", entry_body->extended_header_checksum())
                     + (calculatedChecksum ? usprintf(", invalid, should be %02Xh", 0x100 - calculatedChecksum) : UString(", valid"));
                }

                // Add timestamp
                if (!entry_body->_is_null_extended_header_timestamp())
                    info += usprintf("\nTimestamp: %" PRIX64 "h", entry_body->extended_header_timestamp());

                // Add hash
                if (!entry_body->_is_null_extended_header_hash()) {
                    UByteArray hash = UByteArray(entry_body->extended_header_hash().c_str(), entry_body->extended_header_hash().size());
                    info += UString("\nHash: ") + UString(hash.toHex().constData());
                }
            }

            // Add tree item
            UModelIndex varIndex = model->addItem(localOffset + entry->offset(), Types::NvarEntry, subtype, name, text, info, header, body, tail, Fixed, index);
            currentEntryIndex++;

            // Set parsing data
            model->setParsingData(varIndex, UByteArray((const char*)&pdata, sizeof(pdata)));

            // Try parsing the entry data as NVAR storage if it begins with NVAR signature
            if ((subtype == Subtypes::DataNvarEntry || subtype == Subtypes::FullNvarEntry)
                && body.size() >= 4 && readUnaligned((const UINT32*)body.constData()) == NVRAM_NVAR_ENTRY_SIGNATURE)
                (void)parseNvarStore(varIndex);
        }
    }
    catch (...) {
        if (!probe)
            msg(usprintf("%s: unable to parse AMI NVAR storage", __FUNCTION__), index);
        return U_INVALID_STORE;
    }

    return U_SUCCESS;
}

USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index,const UINT32 fdcStoreSizeOverride)
{
    // Sanity check
    if (!index.isValid())
        return U_INVALID_PARAMETER;
    
    // Obtain required fields from parsing data
    UINT8 emptyByte = 0xFF;
    if (model->hasEmptyParsingData(index) == false) {
        UByteArray data = model->parsingData(index);
        const VOLUME_PARSING_DATA* pdata = (const VOLUME_PARSING_DATA*)data.constData();
        emptyByte = pdata->emptyByte;
    }
    
    // Get local offset
    const UINT32 localOffset = (UINT32)model->header(index).size();
    
    // Get item data
    UByteArray volumeBody = model->body(index);
    const UINT32 volumeBodySize = (UINT32)volumeBody.size();

    // Iterate over all bytes inside the volume body, trying to parse every next byte offset by one of the known parsers
    UByteArray outerPadding;
    UINT32 previousStoreEndOffset = 0;
    for (UINT32 storeOffset = 0;
         storeOffset < volumeBodySize;
         storeOffset++) {
        UString name, text, info;
        UByteArray header, body;
        
        // VSS
        try {
            if (volumeBodySize - storeOffset < sizeof(VSS_VARIABLE_STORE_HEADER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_vss;
            }
            
            // Perform initial sanity check
            const VSS_VARIABLE_STORE_HEADER* storeHeader = (const VSS_VARIABLE_STORE_HEADER*)(volumeBody.constData() + storeOffset);
            if ((storeHeader->Signature != NVRAM_VSS_STORE_SIGNATURE
                && storeHeader->Signature != NVRAM_APPLE_SVS_STORE_SIGNATURE
                && storeHeader->Signature != NVRAM_APPLE_NSS_STORE_SIGNATURE)
                || storeHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) {
                // No need to parse further, not a VSS store
                goto not_vss;
            }
            UINT32 storeSize = MIN(volumeBodySize - storeOffset, storeHeader->Size); //TODO: consider this check to become hard bail as it was before
            
            // This copy is required for possible FDC workaround
            UByteArray vss = volumeBody.mid(storeOffset, storeSize);
            
            // Check if we are here to parse a special case of FDC store with size override
            UINT32 originalStoreSize = 0;
            bool fdcHeaderSizeOverrideRequired = (fdcStoreSizeOverride > 0 && storeHeader->Signature == NVRAM_VSS_STORE_SIGNATURE && storeHeader->Size == 0xFFFFFFFF);
            if (fdcHeaderSizeOverrideRequired) {
                VSS_VARIABLE_STORE_HEADER* vssHeader = (VSS_VARIABLE_STORE_HEADER*)vss.data();
                originalStoreSize = vssHeader->Size;
                vssHeader->Size = fdcStoreSizeOverride;
            }
            
            // Try parsing VSS store candidate
            umemstream is(vss.constData(), vss.size());
            kaitai::kstream ks(&is);
            edk2_vss_t parsed(&ks);
            
            // Restore original store size, if needed
            if (fdcHeaderSizeOverrideRequired) {
                VSS_VARIABLE_STORE_HEADER* vssHeader = (VSS_VARIABLE_STORE_HEADER*)vss.data();
                vssHeader->Size = originalStoreSize;
            }

            // VSS store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                UString info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }

            // Construct header and body
            header = vss.left(parsed.len_vss_store_header());
            body = vss.mid(header.size(), storeSize - header.size());
            
            // Add info
            if (parsed.signature() == NVRAM_APPLE_SVS_STORE_SIGNATURE) {
                name = UString("Apple SVS store");
            }
            else if (parsed.signature() == NVRAM_APPLE_NSS_STORE_SIGNATURE) {
                name = UString("Apple NSS store");
            }
            else {
                name = UString("VSS store");
            }
            
            info = usprintf("Signature: %Xh (", parsed.signature()) + fourCC(parsed.signature()) + UString(")\n");
            info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nFormat: %02Xh\nState: %02Xh\nReserved: %02Xh\nReserved1: %04Xh",
                            storeSize , storeSize,
                            (UINT32)header.size(), (UINT32)header.size(),
                            (UINT32)body.size(), (UINT32)body.size(),
                            parsed.format(),
                            parsed.state(),
                            parsed.reserved(),
                            parsed.reserved1());
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::VssStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Add variables
            UINT32 entryOffset = parsed.len_vss_store_header();
            for (const auto & variable : *parsed.body()->variables()) {
                UINT8 subtype;
                
                // This is the terminating entry, needs special processing
                if (variable->_is_null_signature_last()) {
                    // Add free space or padding after all variables, if needed
                    if (entryOffset < storeSize) {
                        UByteArray freeSpace = vss.mid(entryOffset, storeSize - entryOffset);
                        // Add info
                        info = usprintf("Full size: %Xh (%u)", (UINT32)freeSpace.size(), (UINT32)freeSpace.size());
                        
                        // Check that remaining unparsed bytes are actually empty
                        if (isUniformByte(freeSpace, emptyByte)) { // Free space
                            // Add tree item
                            model->addItem(entryOffset, Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                        else {
                            // Add tree item
                            model->addItem(entryOffset, Types::Padding, getPaddingType(freeSpace), UString("Padding"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                    }
                    break;
                }
                
                // This is a normal entry
                UINT32 variableSize;
                if (variable->is_intel_legacy()) { // Intel legacy
                    subtype = Subtypes::IntelVssEntry;
                    // Needs some additional parsing of variable->intel_legacy_data to separate the name from the value
                    text = uFromUcs2(variable->intel_legacy_data().c_str());
                    UINT32 textLengthInBytes = (UINT32)text.length()*2+2;
                    header = vss.mid(entryOffset, variable->len_intel_legacy_header() + textLengthInBytes);
                    body = vss.mid(entryOffset + header.size(), variable->len_total() - variable->len_intel_legacy_header() - textLengthInBytes);
                    variableSize = (UINT32)(header.size() + body.size());
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                else if (variable->is_auth()) { // Authenticated
                    subtype = Subtypes::AuthVssEntry;
                    header = vss.mid(entryOffset, variable->len_auth_header() + variable->len_name_auth());
                    body = vss.mid(entryOffset + header.size(), variable->len_data_auth());
                    variableSize = (UINT32)(header.size() + body.size());
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    text = uFromUcs2(variable->name_auth().c_str());
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                else if (!variable->_is_null_apple_data_crc32()) { // Apple CRC32
                    subtype = Subtypes::AppleVssEntry;
                    header = vss.mid(entryOffset, variable->len_apple_header() + variable->len_name());
                    body = vss.mid(entryOffset + header.size(), variable->len_data());
                    variableSize = (UINT32)(header.size() + body.size());
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    text = uFromUcs2(variable->name().c_str());
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                else { // Standard
                    subtype = Subtypes::StandardVssEntry;
                    header = vss.mid(entryOffset, variable->len_standard_header() + variable->len_name());
                    body = vss.mid(entryOffset + header.size(), variable->len_data());
                    variableSize = (UINT32)(header.size() + body.size());
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    text = uFromUcs2(variable->name().c_str());
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                
                // Override variable type to Invalid, if needed
                if (!variable->is_valid()) {
                    subtype = Subtypes::InvalidVssEntry;
                    name = UString("Invalid");
                    text.clear();
                }
                
                const UINT32 variableAttributes = variable->attributes()->non_volatile()
                + (variable->attributes()->boot_service() << 1)
                + (variable->attributes()->runtime() << 2)
                + (variable->attributes()->hw_error_record() << 3)
                + (variable->attributes()->auth_write() << 4)
                + (variable->attributes()->time_based_auth() << 5)
                + (variable->attributes()->append_write() << 6)
                + (UINT32)(variable->attributes()->reserved() << 7)
                + (UINT32)(variable->attributes()->apple_data_checksum() << 31);
                
                // Add generic info
                info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nState: %02Xh\nReserved: %02Xh\nAttributes: %08Xh (",
                                 variableSize, variableSize,
                                 (UINT32)header.size(), (UINT32)header.size(),
                                 (UINT32)body.size(), (UINT32)body.size(),
                                 variable->state(),
                                 variable->reserved(),
                                 variableAttributes) + vssAttributesToUString(variableAttributes) + UString(")");
                
                // Add specific info
                if (variable->is_auth()) {
                    UINT64 monotonicCounter = (UINT64)variable->len_name() + ((UINT64)variable->len_data() << 32);
                    info += usprintf("\nMonotonic counter: %" PRIX64 "h\nTimestamp: ", monotonicCounter) + efiTimeToUString(*(const EFI_TIME*)variable->timestamp().c_str())
                    + usprintf("\nPubKey index: %u", variable->pubkey_index());
                }
                else if (!variable->_is_null_apple_data_crc32()) {
                    // Calculate CRC32 of the variable data
                    UINT32 calculatedCrc32 = (UINT32)crc32(0, (const UINT8*)body.constData(), (uInt)body.size());
                    
                    info += usprintf("\nData checksum: %08Xh", variable->apple_data_crc32()) +
                    (variable->apple_data_crc32() != calculatedCrc32 ? usprintf(", invalid, should be %08Xh", calculatedCrc32) : UString(", valid"));
                }
                
                // Add tree item
                model->addItem(entryOffset, Types::VssEntry, subtype, name, text, info, header, body, UByteArray(), Fixed, headerIndex);
                
                entryOffset += variableSize;
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
           // Parsing failed, try something else
        }
not_vss:
        // VSS2
        try {
            if (volumeBodySize - storeOffset < sizeof(VSS2_VARIABLE_STORE_HEADER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_vss2;
            }
            
            // Perform initial sanity check
            const VSS2_VARIABLE_STORE_HEADER* storeHeader = (const VSS2_VARIABLE_STORE_HEADER*)(volumeBody.constData() + storeOffset);
            UByteArray guid = UByteArray((const char*)&storeHeader->Signature, sizeof(EFI_GUID));
            
            if ((guid != NVRAM_VSS2_AUTH_VAR_KEY_DATABASE_GUID
                && guid != NVRAM_VSS2_STORE_GUID
                && guid != NVRAM_FDC_STORE_GUID)
                || storeHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) {
                // No need to parse further, not a VSS2 store
                goto not_vss2;
            }
            UINT32 storeSize = MIN(volumeBodySize - storeOffset, storeHeader->Size);
            
            // This copy is required for possible FDC workaround
            UByteArray vss2 = volumeBody.mid(storeOffset, storeSize);
            
            // Check if we are here to parse a special case of FDC store with size override
            UINT32 originalStoreSize = 0;
            bool fdcHeaderSizeOverrideRequired = (fdcStoreSizeOverride > 0 && guid == NVRAM_FDC_STORE_GUID && storeHeader->Size == 0xFFFFFFFF);
            if (fdcHeaderSizeOverrideRequired) {
                VSS2_VARIABLE_STORE_HEADER* vss2Header = (VSS2_VARIABLE_STORE_HEADER*)vss2.data();
                originalStoreSize = vss2Header->Size;
                vss2Header->Size = fdcStoreSizeOverride;
            }
            
            // Try parsing VSS store candidate
            umemstream is(vss2.constData(), vss2.size());
            kaitai::kstream ks(&is);
            edk2_vss2_t parsed(&ks);
            
            // Restore original store size, if needed
            if (fdcHeaderSizeOverrideRequired) {
                VSS2_VARIABLE_STORE_HEADER* vss2Header = (VSS2_VARIABLE_STORE_HEADER*)vss2.data();
                vss2Header->Size = originalStoreSize;
            }
            
            // VSS2 store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }

            // Construct header and body
            header = vss2.left(parsed.len_vss2_store_header());
            body = vss2.mid(header.size(), storeSize - header.size());
            
            // Add info
            name = UString("VSS2 store");
            if (guid == NVRAM_VSS2_AUTH_VAR_KEY_DATABASE_GUID) {
                info = UString("Signature: AAF32C78-947B-439A-A180-2E144EC37792\n");
            }
            else if (guid == NVRAM_FDC_STORE_GUID) {
                info = UString("Signature: DDCF3616-3275-4164-98B6-FE85707FFE7D\n");
            }
            else {
                info = UString("Signature: DDCF3617-3275-4164-98B6-FE85707FFE7D\n");
            }
            
            info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nFormat: %02Xh\nState: %02Xh\nReserved: %02Xh\nReserved1: %04Xh",
                            storeSize, storeSize,
                            (UINT32)header.size(), (UINT32)header.size(),
                            (UINT32)body.size(), (UINT32)body.size(),
                            parsed.format(),
                            parsed.state(),
                            parsed.reserved(),
                            parsed.reserved1());
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::Vss2Store, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Add variables
            UINT32 entryOffset = parsed.len_vss2_store_header();
            for (const auto & variable : *parsed.body()->variables()) {
                UINT8 subtype;
                
                // This is the terminating entry, needs special processing
                if (variable->_is_null_signature_last()) {
                    // Add free space or padding after all variables, if needed
                    if (entryOffset < storeSize) {
                        UByteArray freeSpace = vss2.mid(entryOffset, storeSize - entryOffset);
                        // Add info
                        info = usprintf("Full size: %Xh (%u)", (UINT32)freeSpace.size(), (UINT32)freeSpace.size());
                        
                        // Check that remaining unparsed bytes are actually empty
                        if (isUniformByte(freeSpace, emptyByte)) { // Free space
                            // Add tree item
                            model->addItem(entryOffset, Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                        else {
                            // Add tree item
                            model->addItem(entryOffset, Types::Padding, getPaddingType(freeSpace), UString("Padding"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                    }
                    break;
                }
                
                // This is a normal entry
                UINT32 variableSize;
                UINT32 alignmentSize;
                if (variable->is_auth()) { // Authenticated
                    subtype = Subtypes::AuthVssEntry;
                    header = vss2.mid(entryOffset, variable->len_auth_header() + variable->len_name_auth());
                    body = vss2.mid(entryOffset + header.size(), variable->len_data_auth());
                    variableSize = (UINT32)(header.size() + body.size());
                    alignmentSize = variable->len_alignment_padding_auth();
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    text = uFromUcs2(variable->name_auth().c_str());
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                else { // Standard
                    subtype = Subtypes::StandardVssEntry;
                    header = vss2.mid(entryOffset, variable->len_standard_header() + variable->len_name());
                    body = vss2.mid(entryOffset + header.size(), variable->len_data());
                    variableSize = (UINT32)(header.size() + body.size());
                    alignmentSize = variable->len_alignment_padding();
                    const EFI_GUID variableGuid = readUnaligned((const EFI_GUID*)(variable->vendor_guid().c_str()));
                    name = guidToUString(variableGuid);
                    text = uFromUcs2(variable->name().c_str());
                    info = UString("Variable GUID: ") + guidToUString(variableGuid, false) + "\n";
                }
                
                // Override variable type to Invalid if needed
                if (!variable->is_valid()) {
                    subtype = Subtypes::InvalidVssEntry;
                    name = UString("Invalid");
                    text.clear();
                }
                
                const UINT32 variableAttributes = variable->attributes()->non_volatile()
                + (variable->attributes()->boot_service() << 1)
                + (variable->attributes()->runtime() << 2)
                + (variable->attributes()->hw_error_record() << 3)
                + (variable->attributes()->auth_write() << 4)
                + (variable->attributes()->time_based_auth() << 5)
                + (variable->attributes()->append_write() << 6)
                + (UINT32)(variable->attributes()->reserved() << 7);
                
                // Add generic info
                info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nState: %02Xh\nReserved: %02Xh\nAttributes: %08Xh (",
                                 variableSize, variableSize,
                                 (UINT32)header.size(), (UINT32)header.size(),
                                 (UINT32)body.size(), (UINT32)body.size(),
                                 variable->state(),
                                 variable->reserved(),
                                 variableAttributes) + vssAttributesToUString(variableAttributes) + UString(")");
                
                // Add specific info
                if (variable->is_auth()) {
                    UINT64 monotonicCounter = (UINT64)variable->len_name() + ((UINT64)variable->len_data() << 32);
                    info += usprintf("\nMonotonic counter: %" PRIX64 "h\nTimestamp: ", monotonicCounter) + efiTimeToUString(*(const EFI_TIME*)variable->timestamp().c_str())
                    + usprintf("\nPubKey index: %u", variable->pubkey_index());
                }
                
                // Add tree item
                model->addItem(entryOffset, Types::VssEntry, subtype, name, text, info, header, body, UByteArray(), Fixed, headerIndex);
                
                entryOffset += (variableSize + alignmentSize);
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
           // Parsing failed, try something else
        }
not_vss2:
        // Do not try any other parsers if we are here for FDC store parsing
        if (fdcStoreSizeOverride != 0) {
            continue;
        }
        
        // FTW
        try {
            if (volumeBodySize - storeOffset < sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32)) {
                // No need to parse further, the rest of the volume is too small
                goto not_ftw;
            }
            // Perform initial sanity check
            const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32* storeHeader = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32*)(volumeBody.constData() + storeOffset);
            UByteArray guid = UByteArray((const char*)&storeHeader->Signature, sizeof(EFI_GUID));
            if (guid != NVRAM_MAIN_STORE_VOLUME_GUID
                && guid != EDKII_WORKING_BLOCK_SIGNATURE_GUID
                && guid != VSS2_WORKING_BLOCK_SIGNATURE_GUID) {
                // No need to parse further, not a FTW store
                goto not_ftw;
            }
            // Determine store size
            UINT32 storeSize;
            if (storeHeader->WriteQueueSize % 0x10 == 4) {
                storeSize = sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32) + storeHeader->WriteQueueSize;
            }
            else if (storeHeader->WriteQueueSize % 0x10 == 0) {
                const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64* storeHeader64 = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64*)(volumeBody.constData() + storeOffset);
                storeSize = (UINT32)(sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64) + storeHeader64->WriteQueueSize);
            }
            else {
                // No need to parse further, unknown FTW store size
                msg(usprintf("%s: can not determine FTW store size for candidate at base %08Xh", __FUNCTION__, model->base(index) + localOffset + storeOffset), index);
                goto not_ftw;
            }
            storeSize = MIN(volumeBodySize - storeOffset, storeSize);
        
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            edk2_ftw_t parsed(&ks);
            
            // Construct header and calculate header checksum
            UINT32 headerSize;
            UINT32 calculatedCrc;
            if (parsed._is_null_len_write_queue_64()) {
                headerSize = sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32);
                header = volumeBody.mid(storeOffset, headerSize);
                
                // Check block header checksum
                UByteArray crcHeader = header;
                EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32* crcFtwBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32*)crcHeader.data();
                crcFtwBlockHeader->Crc = emptyByte ? 0xFFFFFFFF : 0;
                crcFtwBlockHeader->State = emptyByte ? 0xFF : 0;
                calculatedCrc = (UINT32)crc32(0, (const UINT8*)crcFtwBlockHeader, (UINT32)headerSize);
            }
            else {
                headerSize = sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64);
                header = volumeBody.mid(storeOffset, headerSize);
                
                // Check block header checksum
                UByteArray crcHeader = header;
                EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64* crcFtwBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64*)crcHeader.data();
                crcFtwBlockHeader->Crc = emptyByte ? 0xFFFFFFFF : 0;
                crcFtwBlockHeader->State = emptyByte ? 0xFF : 0;
                calculatedCrc = (UINT32)crc32(0, (const UINT8*)crcFtwBlockHeader, (UINT32)headerSize);
            }
            
            // FTW store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                UString info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct body
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Add info
            name = UString("FTW store");
            info = UString("Signature: ") + guidToUString(*(const EFI_GUID*)guid.constData(), false);
            info += usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nState: %02Xh\nHeader CRC32: %08Xh",
                             (UINT32)storeSize, (UINT32)storeSize,
                             (UINT32)header.size(), (UINT32)header.size(),
                             (UINT32)body.size(), (UINT32)body.size(),
                             parsed.state(),
                             parsed.crc()) + (parsed.crc() != calculatedCrc ? usprintf(", invalid, should be %08Xh", calculatedCrc) : UString(", valid"));
            
            // Add header tree item
            model->addItem(localOffset + storeOffset, Types::FtwStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_ftw:
        // Insyde FDC
        try {
            if (volumeBodySize - storeOffset < sizeof(INSYDE_FDC_STORE_HEADER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_fdc;
            }
            // Perform initial sanity check
            const INSYDE_FDC_STORE_HEADER* storeHeader = (const INSYDE_FDC_STORE_HEADER*)(volumeBody.constData() + storeOffset);
            if (storeHeader->Signature != INSYDE_FDC_STORE_SIGNATURE) {
                // No need to parse further, not a FDC store
                goto not_fdc;
            }
            UINT32 storeSize = MIN(volumeBodySize - storeOffset, storeHeader->Size);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            insyde_fdc_t parsed(&ks);
            
            // Insyde FDC store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                UString info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header and body
            header = volumeBody.mid(storeOffset, sizeof(INSYDE_FDC_STORE_HEADER));
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Add info
            name = UString("Insyde FDC store");
            info = usprintf("Signature: _FDC\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)",
                                    storeSize, storeSize,
                                    (UINT32)header.size(), (UINT32)header.size(),
                                    (UINT32)body.size(), (UINT32)body.size());
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::FdcStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Parse FDC body as normal VSS/VSS2 storage with size override
            parseNvramVolumeBody(headerIndex, (UINT32)body.size());
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_fdc:
        // Apple SysF
        try {
            if (volumeBodySize - storeOffset < sizeof(APPLE_SYSF_STORE_HEADER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_sysf;
            }
            // Perform initial sanity check
            const APPLE_SYSF_STORE_HEADER* storeHeader = (const APPLE_SYSF_STORE_HEADER*)(volumeBody.constData() + storeOffset);
            if (storeHeader->Signature != NVRAM_APPLE_SYSF_STORE_SIGNATURE
                && storeHeader->Signature != NVRAM_APPLE_DIAG_STORE_SIGNATURE) {
                // No need to parse further, not a SysF/Diag store
                goto not_sysf;
            }
            UINT32 storeSize = MIN(volumeBodySize - storeOffset, storeHeader->Size);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            apple_sysf_t parsed(&ks);
            
            // Apple SysF/Diag store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header and body
            header = volumeBody.mid(storeOffset, sizeof(APPLE_SYSF_STORE_HEADER));
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Check store checksum
            UINT32 calculatedCrc = (UINT32)crc32(0, (const UINT8*)(volumeBody.constData() + storeOffset), storeSize - sizeof(UINT32));
            
            // Add info
            if (storeHeader->Signature == NVRAM_APPLE_SYSF_STORE_SIGNATURE) {
                name = UString("Apple SysF store");
                info = UString("Signature: Fsys\n");
            }
            else {
                name = UString("Apple Diag store");
                info = UString("Signature: Gaid\n");
            }
            info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nUnknown: %02Xh\nUnknown1: %08Xh\nCRC32: %08Xh",
                            storeSize, storeSize,
                            (UINT32)header.size(), (UINT32)header.size(),
                            (UINT32)body.size(), (UINT32)body.size(),
                            parsed.unknown(),
                            parsed.unknown1(),
                            parsed.crc())  + (parsed.crc() != calculatedCrc ? usprintf(", invalid, should be %08Xh", calculatedCrc) : UString(", valid"));
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::SysFStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Add variables
            UINT32 entryOffset = sizeof(APPLE_SYSF_STORE_HEADER);
            for (const auto & variable : *parsed.body()->variables()) {
                UINT8 subtype;
                
                if (variable->invalid_flag()) {
                    subtype = Subtypes::InvalidSysFEntry;
                    name = UString("Invalid");
                }
                else {
                    subtype = Subtypes::NormalSysFEntry;
                    name = usprintf("%s", variable->name().c_str());
                }
                
                if (variable->len_name() == 3 && variable->name() == "EOF") {
                    header = volumeBody.mid(storeOffset + entryOffset, 4);
                    body.clear();
                }
                else {
                    header = volumeBody.mid(storeOffset + entryOffset, sizeof(UINT8) + (UINT32)variable->len_name() + sizeof(UINT16));
                    body = volumeBody.mid(storeOffset + entryOffset + header.size(), (UINT32)variable->len_data());
                }
                // Add generic info
                UINT32 variableSize = (UINT32)header.size() + (UINT32)body.size();
                info = usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\n",
                                 variableSize, variableSize,
                                 (UINT32)header.size(), (UINT32)header.size(),
                                 (UINT32)body.size(), (UINT32)body.size());
                
                // Add tree item
                model->addItem(entryOffset, Types::SysFEntry, subtype, name, UString(), info, header, body, UByteArray(), Fixed, headerIndex);
                
                entryOffset += variableSize;
            }
            
            // Add free space or padding after all variables, if needed
            if (entryOffset < storeSize) {
                UByteArray freeSpace = volumeBody.mid(storeOffset + entryOffset, storeSize - entryOffset);
                // Add info
                info = usprintf("Full size: %Xh (%u)", (UINT32)freeSpace.size(), (UINT32)freeSpace.size());
                
                // Check that remaining unparsed bytes are actually zeroes
                if (isUniformByte(freeSpace.left(freeSpace.size() - 4), 0)) { // Free space, 4 last bytes are always CRC32
                    // Add tree item
                    model->addItem(entryOffset, Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                }
                else {
                    // Add tree item
                    model->addItem(entryOffset, Types::Padding, getPaddingType(freeSpace), UString("Padding"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                }
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_sysf:
        // Phoenix Flash Map
        try {
            if (volumeBodySize - storeOffset < sizeof(PHOENIX_FLASH_MAP_HEADER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_flm;
            }
            // Perform initial sanity check
            const PHOENIX_FLASH_MAP_HEADER* storeHeader = (const PHOENIX_FLASH_MAP_HEADER*)(volumeBody.constData() + storeOffset);
            if (UByteArray((const char*)storeHeader->Signature, NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_LENGTH) != NVRAM_PHOENIX_FLASH_MAP_SIGNATURE
                || storeHeader->NumEntries > NVRAM_PHOENIX_FLASH_MAP_MAX_ENTRIES) {
                // No need to parse further, not a Phoenix Flash Map
                goto not_flm;
            }
            UINT32 storeSize = sizeof(PHOENIX_FLASH_MAP_HEADER) + storeHeader->NumEntries * sizeof(PHOENIX_FLASH_MAP_ENTRY);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            phoenix_flm_t parsed(&ks);
            
            // Phoenix FlashMap store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header and body
            header = volumeBody.mid(storeOffset, sizeof(PHOENIX_FLASH_MAP_HEADER));
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Add info
            name = UString("Phoenix SCT flash map");
            info = usprintf("Signature: _FLASH_MAP\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nEntries: %u\nReserved: %08Xh",
                                    storeSize, storeSize,
                                    (UINT32)header.size(), (UINT32)header.size(),
                                    (UINT32)body.size(), (UINT32)body.size(),
                                    parsed.num_entries(),
                                    parsed.reserved());
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::PhoenixFlashMapStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Add entries
            UINT32 entryOffset = sizeof(PHOENIX_FLASH_MAP_HEADER);
            for (const auto & entry : *parsed.entries()) {
                UINT8 subtype;
                
                if (entry->data_type() == NVRAM_PHOENIX_FLASH_MAP_ENTRY_DATA_TYPE_VOLUME) {
                    subtype = Subtypes::VolumeFlashMapEntry;
                }
                else if (entry->data_type() == NVRAM_PHOENIX_FLASH_MAP_ENTRY_DATA_TYPE_DATA_BLOCK) {
                    subtype = Subtypes::DataFlashMapEntry;
                }
                else {
                    subtype = Subtypes::UnknownFlashMapEntry;
                }
                
                const EFI_GUID guid = readUnaligned((const EFI_GUID*)entry->guid().c_str());
                name = guidToUString(guid);
                text = phoenixFlashMapGuidToUString(guid);
                header = volumeBody.mid(storeOffset + entryOffset, sizeof(PHOENIX_FLASH_MAP_ENTRY));

                // Add info
                UINT32 entrySize = (UINT32)header.size();
                info = usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: 0h (0)\nData type: %04Xh\nEntry type: %04Xh\nSize: %08Xh\nOffset: %08Xh\nPhysical address: %" PRIX64 "h",
                                entrySize, entrySize,
                                (UINT32)header.size(), (UINT32)header.size(),
                                entry->data_type(),
                                entry->entry_type(),
                                entry->size(),
                                entry->offset(),
                                entry->physical_address());
                
                // Add tree item
                model->addItem(entryOffset, Types::PhoenixFlashMapEntry, subtype, name, text, info, header, UByteArray(), UByteArray(), Fixed, headerIndex);
                
                entryOffset += entrySize;
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_flm:
        // Phoenix EVSA store
        try {
            if (volumeBodySize - storeOffset < sizeof(EVSA_STORE_ENTRY)) {
                // No need to parse further, the rest of the volume is too small
                goto not_evsa;
            }
            // Perform initial sanity check
            const EVSA_STORE_ENTRY* storeHeader = (const EVSA_STORE_ENTRY*)(volumeBody.constData() + storeOffset);
            if (storeHeader->Signature != NVRAM_EVSA_STORE_SIGNATURE
                || storeHeader->Header.Type != NVRAM_EVSA_ENTRY_TYPE_STORE
                || storeHeader->Header.Size != sizeof(EVSA_STORE_ENTRY)) {
                // No need to parse further, not a EVSA store
                goto not_evsa;
            }
            UINT32 storeSize = MIN(volumeBodySize - storeOffset, storeHeader->StoreSize);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            phoenix_evsa_t parsed(&ks);
            
            // Phoenix EVSA store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header and body
            header = volumeBody.mid(storeOffset, sizeof(EVSA_STORE_ENTRY));
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Calculate header checksum
            UINT8 calculated = calculateChecksum8(((const UINT8*)storeHeader) + 2, storeHeader->Header.Size - 2);
            
            // Add info
            name = UString("Phoenix EVSA store");
            info = usprintf("Signature: EVSA\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nAttributes: %08Xh\nReserved: %08Xh\nChecksum: %02Xh",
                            storeSize, storeSize,
                            (UINT32)header.size(), (UINT32)header.size(),
                            (UINT32)body.size(), (UINT32)body.size(),
                            parsed.attributes(),
                            parsed.reserved(),
                            parsed.checksum())
            + (parsed.checksum() != calculated ? usprintf(", invalid, should be %02Xh", calculated) : UString(", valid"));
            
            // Add header tree item
            UModelIndex headerIndex = model->addItem(localOffset + storeOffset, Types::EvsaStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            // Add entries
            std::map<UINT16, EFI_GUID> guidMap;
            std::map<UINT16, UString> nameMap;
            UINT32 entryOffset = parsed.len_evsa_store_header();
            for (const auto & entry : *parsed.body()->entries()) {
                UINT8 subtype;
                UINT32 entrySize;
                
                // This is the terminating entry, needs special processing
                if (entry->_is_null_checksum()) {
                    // Add free space or padding after all variables, if needed
                    if (entryOffset < storeSize) {
                        UByteArray freeSpace = volumeBody.mid(storeOffset + entryOffset, storeSize - entryOffset);
                        // Add info
                        info = usprintf("Full size: %Xh (%u)", (UINT32)freeSpace.size(), (UINT32)freeSpace.size());
                        
                        // Check that remaining unparsed bytes are actually empty
                        if (isUniformByte(freeSpace, emptyByte)) { // Free space
                            // Add tree item
                            model->addItem(entryOffset, Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                        else {
                            // Add tree item
                            model->addItem(entryOffset, Types::Padding, getPaddingType(freeSpace), UString("Padding"), UString(), info, UByteArray(), freeSpace, UByteArray(), Fixed, headerIndex);
                        }
                    }
                    break;
                }
                
                const EVSA_ENTRY_HEADER* entryHeader = (const EVSA_ENTRY_HEADER*)(volumeBody.constData() + storeOffset + entryOffset);
                calculated = calculateChecksum8(((const UINT8*)entryHeader) + 2, entryHeader->Size - 2);
                
                // GUID entry
                if (entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_GUID1 || entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_GUID2) {
                    const phoenix_evsa_t::evsa_guid_t* guidEntry = (const phoenix_evsa_t::evsa_guid_t*)(entry->body());
                    header = volumeBody.mid(storeOffset + entryOffset, sizeof(EVSA_GUID_ENTRY));
                    body = volumeBody.mid(storeOffset + entryOffset + sizeof(EVSA_GUID_ENTRY), entry->len_evsa_entry() - header.size());
                    entrySize = (UINT32)(header.size() + body.size());
                    EFI_GUID guid = *(const EFI_GUID*)(guidEntry->guid().c_str());
                    name = guidToUString(guid);
                    info = UString("GUID: ") + guidToUString(guid, false)
                    + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh",
                               entrySize, entrySize,
                               (UINT32)header.size(), (UINT32)header.size(),
                               (UINT32)body.size(), (UINT32)body.size(),
                               entry->entry_type(),
                               entry->checksum())
                    + (entry->checksum() != calculated ? usprintf(", invalid, should be %02Xh", calculated) : UString(", valid"))
                    + usprintf("\nGuidId: %04Xh", guidEntry->guid_id());
                    subtype = Subtypes::GuidEvsaEntry;
                    guidMap.insert(std::pair<UINT16, EFI_GUID>(guidEntry->guid_id(), guid));
                }
                // Name entry
                else if (entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_NAME1 || entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_NAME2) {
                    const phoenix_evsa_t::evsa_name_t* nameEntry = (const phoenix_evsa_t::evsa_name_t*)(entry->body());
                    header = volumeBody.mid(storeOffset + entryOffset, sizeof(EVSA_NAME_ENTRY));
                    body = volumeBody.mid(storeOffset + entryOffset + sizeof(EVSA_NAME_ENTRY), entry->len_evsa_entry() - header.size());
                    entrySize = (UINT32)(header.size() + body.size());
                    name = uFromUcs2(body.constData());
                    info = UString("Name: ") + name
                    + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh",
                               entrySize, entrySize,
                               (UINT32)header.size(), (UINT32)header.size(),
                               (UINT32)body.size(), (UINT32)body.size(),
                               entry->entry_type(),
                               entry->checksum())
                    + (entry->checksum() != calculated ? usprintf(", invalid, should be %02Xh", calculated) : UString(", valid"))
                    + usprintf("\nVarId: %04Xh", nameEntry->var_id());
                    subtype = Subtypes::NameEvsaEntry;
                    nameMap.insert(std::pair<UINT16, UString>(nameEntry->var_id(), name));
                }
                // Data entry
                else if (entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_DATA1
                         || entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_DATA2
                         || entry->entry_type() == NVRAM_EVSA_ENTRY_TYPE_DATA_INVALID) {
                    phoenix_evsa_t::evsa_data_t* dataEntry = (phoenix_evsa_t::evsa_data_t*)(entry->body());
                    if (dataEntry->_is_null_len_data_ext()) {
                        header = volumeBody.mid(storeOffset + entryOffset, sizeof(EVSA_DATA_ENTRY));
                        body = volumeBody.mid(storeOffset + entryOffset + sizeof(EVSA_DATA_ENTRY), entry->len_evsa_entry() - header.size());
                    }
                    else {
                        header = volumeBody.mid(storeOffset + entryOffset, sizeof(EVSA_DATA_ENTRY_EXTENDED));
                        body = volumeBody.mid(storeOffset + entryOffset + sizeof(EVSA_DATA_ENTRY_EXTENDED), dataEntry->len_data_ext());
                    }
                    entrySize = (UINT32)(header.size() + body.size());
                    name = UString("Data");
                    subtype = Subtypes::DataEvsaEntry;
                    
                    const UINT32 attributes = dataEntry->attributes()->non_volatile()
                    + (dataEntry->attributes()->boot_service() << 1)
                    + (dataEntry->attributes()->runtime() << 2)
                    + (dataEntry->attributes()->hw_error_record() << 3)
                    + (dataEntry->attributes()->auth_write() << 4)
                    + (dataEntry->attributes()->time_based_auth() << 5)
                    + (dataEntry->attributes()->append_write() << 6)
                    + (UINT32)(dataEntry->attributes()->reserved() << 7)
                    + (dataEntry->attributes()->extended_header() << 28)
                    + (UINT32)(dataEntry->attributes()->reserved1() << 29);
                    
                    info = usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh",
                                    entrySize, entrySize,
                                    (UINT32)header.size(), (UINT32)header.size(),
                                    (UINT32)body.size(), (UINT32)body.size(),
                                    entry->entry_type(),
                                    entry->checksum())
                    + (entry->checksum() != calculated ? usprintf(", invalid, should be %02Xh", calculated) : UString(", valid"))
                    + usprintf("\nVarId: %04Xh\nGuidId: %04Xh\nAttributes: %08Xh (",
                               dataEntry->var_id(),
                               dataEntry->guid_id(),
                               attributes)
                    + evsaAttributesToUString(attributes) + UString(")");
                }
                
                // Add tree item
                model->addItem(entryOffset, Types::EvsaEntry, subtype, name, text, info, header, body, UByteArray(), Fixed, headerIndex);
                
                entryOffset += entrySize;
            }
            
            // Reparse all data variables to detect invalid ones and assign name and text to valid ones
            for (int i = 0; i < model->rowCount(headerIndex); i++) {
                UModelIndex current = headerIndex.model()->index(i, 0, headerIndex);
                
                if (model->subtype(current) == Subtypes::DataEvsaEntry) {
                    UByteArray header = model->header(current);
                    const EVSA_DATA_ENTRY* dataHeader = (const EVSA_DATA_ENTRY*)header.constData();
                    UString guid;
                    if (guidMap.count(dataHeader->GuidId))
                        guid = guidToUString(guidMap[dataHeader->GuidId], false);
                    UString name;
                    if (nameMap.count(dataHeader->VarId))
                        name = nameMap[dataHeader->VarId];
                    
                    // Check for variable validity
                    if (guid.isEmpty() && name.isEmpty()) { // Both name and guid aren't found
                        model->setSubtype(current, Subtypes::InvalidEvsaEntry);
                        model->setName(current, UString("Invalid"));
                        model->setText(current, UString());
                        msg(usprintf("%s: data variable with invalid GuidId and invalid VarId", __FUNCTION__), current);
                    }
                    else if (guid.isEmpty()) { // Guid not found
                        model->setSubtype(current, Subtypes::InvalidEvsaEntry);
                        model->setName(current, UString("Invalid"));
                        model->setText(current, UString());
                        msg(usprintf("%s: data variable with invalid GuidId", __FUNCTION__), current);
                    }
                    else if (name.isEmpty()) { // Name not found
                        model->setSubtype(current, Subtypes::InvalidEvsaEntry);
                        model->setName(current, UString("Invalid"));
                        model->setText(current, UString());
                        msg(usprintf("%s: data variable with invalid VarId", __FUNCTION__), current);
                    }
                    else { // Variable is OK, rename it
                        if (dataHeader->Header.Type == NVRAM_EVSA_ENTRY_TYPE_DATA_INVALID) {
                            model->setSubtype(current, Subtypes::InvalidEvsaEntry);
                            model->setName(current, UString("Invalid"));
                            model->setText(current, UString());
                        }
                        else {
                            model->setName(current, guid);
                            model->setText(current, name);
                            model->addInfo(current, UString("GUID: ") + guid + UString("\nName: ") + name + "\n", false);
                        }
                    }
                }
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
 not_evsa:
        // Phoenix CMDB store
        try {
            if (volumeBodySize - storeOffset < NVRAM_PHOENIX_CMDB_SIZE) {
                // No need to parse further, the rest of the volume is too small
                goto not_cmdb;
            }
            // Perform initial sanity check
            const PHOENIX_CMDB_HEADER* storeHeader = (const PHOENIX_CMDB_HEADER*)(volumeBody.constData() + storeOffset);
            if (storeHeader->Signature != NVRAM_PHOENIX_CMDB_HEADER_SIGNATURE) {
                // No need to parse further, not a Phoenix CMDB store
                goto not_cmdb;
            }
            UINT32 storeSize = NVRAM_PHOENIX_CMDB_SIZE;
            
            // CMDB store at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header and body
            header = volumeBody.mid(storeOffset, storeHeader->TotalSize);
            body = volumeBody.mid(storeOffset + header.size(), storeSize - header.size());
            
            // Add info
            name = UString("Phoenix CMDB store");
            info = usprintf("Signature: CMDB\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)",
                            storeSize, storeSize,
                            (UINT32)header.size(), (UINT32)header.size(),
                            (UINT32)body.size(), (UINT32)body.size());
            
            // Add tree item
            model->addItem(localOffset + storeOffset, Types::CmdbStore, 0, name, UString(), info, header, body, UByteArray(), Fixed, index);
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_cmdb:
        // SLIC PubKey
        try {
            if (volumeBodySize - storeOffset < sizeof(OEM_ACTIVATION_PUBKEY)) {
                // No need to parse further, the rest of the volume is too small
                goto not_pubkey;
            }
            // Perform initial sanity check
            const OEM_ACTIVATION_PUBKEY* storeHeader = (const OEM_ACTIVATION_PUBKEY*)(volumeBody.constData() + storeOffset);
            if (storeHeader->Magic != OEM_ACTIVATION_PUBKEY_MAGIC
                || storeHeader->Type != OEM_ACTIVATION_PUBKEY_TYPE
                || storeHeader->Size != sizeof(OEM_ACTIVATION_PUBKEY)) {
                // No need to parse further, not a SLIC PubKey
                goto not_pubkey;
            }
            UINT32 storeSize = sizeof(OEM_ACTIVATION_PUBKEY);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            ms_slic_pubkey_t parsed(&ks);
            
            // SLIC PubKey at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header
            header = volumeBody.mid(storeOffset, storeSize);
            
            // Add info
            name = UString("SLIC pubkey");
            info = usprintf("Type: 0h\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: 0h (0)\n"
                            "Key type: %02Xh\nVersion: %02Xh\nAlgorithm: %08Xh\nMagic: RSA1\nBit length: %08Xh\nExponent: %08Xh",
                            parsed.len_pubkey(), parsed.len_pubkey(),
                            parsed.len_pubkey(), parsed.len_pubkey(),
                            parsed.key_type(),
                            parsed.version(),
                            parsed.algorithm(),
                            parsed.bit_length(),
                            parsed.exponent());
            
            // Add tree item
            model->addItem(localOffset + storeOffset, Types::SlicData, Subtypes::PubkeySlicData, name, UString(), info, header, UByteArray(), UByteArray(), Fixed, index);
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_pubkey:
        // SLIC marker
        try {
            if (volumeBodySize - storeOffset < sizeof(OEM_ACTIVATION_MARKER)) {
                // No need to parse further, the rest of the volume is too small
                goto not_marker;
            }
            // Perform initial sanity check
            const OEM_ACTIVATION_MARKER* storeHeader = (const OEM_ACTIVATION_MARKER*)(volumeBody.constData() + storeOffset);
            if (storeHeader->WindowsFlag != OEM_ACTIVATION_MARKER_WINDOWS_FLAG
                || storeHeader->Type != OEM_ACTIVATION_MARKER_TYPE
                || storeHeader->Size != sizeof(OEM_ACTIVATION_MARKER)) {
                // No need to parse further, not a SLIC marker
                goto not_marker;
            }
            // Check reserved bytes
            for (UINT8 i = 0; i < sizeof(storeHeader->Reserved); i++) {
                if (storeHeader->Reserved[i] != OEM_ACTIVATION_MARKER_RESERVED_BYTE) {
                    // No need to parse further, not a SLIC marker
                    goto not_marker;
                }
            }
            UINT32 storeSize = sizeof(OEM_ACTIVATION_MARKER);
            
            umemstream is(volumeBody.constData() + storeOffset, storeSize);
            kaitai::kstream ks(&is);
            ms_slic_marker_t parsed(&ks);
            
            // SLIC marker at current offset parsed correctly
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Construct header
            header = volumeBody.mid(storeOffset, storeSize);
            
            // Add info
            name = UString("SLIC marker");
            info = usprintf("Type: 1h\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: 0h (0)\n"
                            "Version: %08Xh\nOEM ID: %s\nOEM table ID: %s\nWindows flag: WINDOWS \nSLIC version: %08Xh",
                            parsed.len_marker(), parsed.len_marker(),
                            parsed.len_marker(), parsed.len_marker(),
                            parsed.version(),
                            parsed.oem_id().c_str(),
                            parsed.oem_table_id().c_str(),
                            parsed.slic_version());
            
            // Add tree item
            model->addItem(localOffset + storeOffset, Types::SlicData, Subtypes::MarkerSlicData, name, UString(), info, header, UByteArray(), UByteArray(), Fixed, index);
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_marker:
        // Intel uCode
        try {
            // Check data size
            if (volumeBodySize - storeOffset < sizeof(INTEL_MICROCODE_HEADER)) {
                goto not_ucode;
            }
            
            const UINT32 currentUint32 = readUnaligned((const UINT32*)(volumeBody.constData() + storeOffset));
            if (currentUint32 != INTEL_MICROCODE_HEADER_VERSION_1) {
                goto not_ucode;
            }
            
            // Check microcode header candidate
            const INTEL_MICROCODE_HEADER* ucodeHeader = (const INTEL_MICROCODE_HEADER*)(volumeBody.constData() + storeOffset);
            if (FALSE == ffsParser->microcodeHeaderValid(ucodeHeader)) {
                goto not_ucode;
            }
            
            // Check candidate size
            if (ucodeHeader->TotalSize == 0) {
                goto not_ucode;
            }
            
            // We still have enough data left to fit the whole TotalSize
            UINT32 storeSize = ucodeHeader->TotalSize;
            if (volumeBodySize - storeOffset < storeSize) {
                goto not_ucode;
            }
            
            // All checks passed, microcode found
            // Check if we need to add a padding before it
            if (!outerPadding.isEmpty()) {
                info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
                model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
                outerPadding.clear();
            }
            
            // Parse microcode header
            UByteArray ucode = volumeBody.mid(storeOffset);
            UModelIndex ucodeIndex;
            if (U_SUCCESS != ffsParser->parseIntelMicrocodeHeader(ucode, localOffset + storeOffset, index, ucodeIndex)) {
                goto not_ucode;
            }
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_ucode:
        // FFS volume
        try {
            // Check data size
            if (volumeBodySize - storeOffset < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) {
                goto not_ffs_volume;
            }
            
            // Check volume header candidate
            const EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (const EFI_FIRMWARE_VOLUME_HEADER*)(volumeBody.constData() + storeOffset);
            if (volumeHeader->Signature != EFI_FV_SIGNATURE) {
                goto not_ffs_volume;
            }
            
            // All checks passed, volume found
            UByteArray volume = volumeBody.mid(storeOffset);
            UModelIndex volumeIndex;
            if (U_SUCCESS != ffsParser->parseVolumeHeader(volume, localOffset + storeOffset, index, volumeIndex)) {
                goto not_ffs_volume;
            }
            
            (VOID)ffsParser->parseVolumeBody(volumeIndex);
            UINT32 storeSize = (UINT32)(model->header(volumeIndex).size() + model->body(volumeIndex).size());
            
            storeOffset += storeSize - 1;
            previousStoreEndOffset = storeOffset + 1;
            continue;
        } catch (...) {
            // Parsing failed, try something else
        }
not_ffs_volume:
        // Padding
        if (storeOffset < volumeBodySize) {
            outerPadding += volumeBody[storeOffset];
        }
    }

    // Add padding at the very end
    if (!outerPadding.isEmpty()) {
        // Add info
        UString info = usprintf("Full size: %Xh (%u)", (UINT32)outerPadding.size(), (UINT32)outerPadding.size());
        
        // Check that remaining unparsed bytes are actually empty
        if (isUniformByte(outerPadding, emptyByte)) {
            // Add tree item
            model->addItem(localOffset + previousStoreEndOffset, Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
        }
        else {
            // Add tree item
            model->addItem(localOffset + previousStoreEndOffset, Types::Padding, getPaddingType(outerPadding), UString("Padding"), UString(), info, UByteArray(), outerPadding, UByteArray(), Fixed, index);
        }
    }

    return U_SUCCESS;
}
#endif // U_ENABLE_NVRAM_PARSING_SUPPORT