forked from LongSoft/Universal-IFR-Extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UEFI.cpp
1303 lines (1009 loc) · 54.6 KB
/
UEFI.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
#include "UEFI.h"
#include "UEFIHeader.h"
#if defined (__unix__) || defined (__APPLE__)
#include <cstring>
#define _strcmpi strcasecmp
#endif
// Supporting function implementation
void getUEFIStringPackages(vector<UEFI_IFR_STRING_PACK> &stringPackages, const string &buffer) {
// Initialize variables
UEFI_IFR_STRING_PACK tempStringPackage;
// Go through buffer
for (uint32_t i = 0; i < buffer.size() - 48; i++)
// Check if string pakage was found
if ((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00') && buffer[i + 3] == '\x04' && buffer[i + 4] == '\x34' && (buffer[i + 44] == '\x01' || buffer[i + 44] == '\x02') && buffer[i + 45] == '\x00' && buffer[i + 48] == '\x2D' && i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) <= buffer.size() && buffer[i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) - 2] == '\x00') {
// Set temp string package
tempStringPackage.header.offset = i;
tempStringPackage.header.length = static_cast<uint32_t>(static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16));
tempStringPackage.header.type = static_cast<unsigned char>(buffer[i + 3]);
tempStringPackage.headerSize = static_cast<uint32_t>(static_cast<unsigned char>(buffer[i + 4]) + (static_cast<unsigned char>(buffer[i + 5]) << 8) + (static_cast<unsigned char>(buffer[i + 6]) << 16) + (static_cast<unsigned char>(buffer[i + 7]) << 24));
tempStringPackage.stringOffset = i + static_cast<uint32_t>(static_cast<unsigned char>(buffer[i + 8]) + (static_cast<unsigned char>(buffer[i + 9]) << 8) + (static_cast<unsigned char>(buffer[i + 10]) << 16) + (static_cast<unsigned char>(buffer[i + 11]) << 24));
for (uint32_t j = 0; j < 16; j++)
tempStringPackage.languageWindow.push_back(static_cast<uint16_t>(static_cast<unsigned char>(buffer[i + 12 + j * 2]) + (static_cast<unsigned char>(buffer[i + 13 + j * 2]) << 8)));
for (uint32_t j = i + 46; buffer[j] != '\x00'; j++)
tempStringPackage.language.push_back(buffer[j]);
tempStringPackage.structureOffset = 0;
// Add string package to list
stringPackages.push_back(tempStringPackage);
// Clear temp string package
tempStringPackage.languageWindow.clear();
tempStringPackage.language.clear();
}
}
void displayUEFIStringPackages(const vector<UEFI_IFR_STRING_PACK> &stringPackages) {
// Display string packages info
cout << "String Packages Information:" << endl;
// Go through string packages
for (uint32_t i = 0; i < stringPackages.size(); i++) {
// Display string package info
cout << "\tString Package " << i << " Information:" << endl;
cout << "\t\tOffset: " << dec << stringPackages[i].header.offset << hex << uppercase << " (0x" << stringPackages[i].header.offset << ')' << endl;
cout << "\t\tLength: " << dec << stringPackages[i].header.length << hex << uppercase << " (0x" << stringPackages[i].header.length << ')' << endl;
cout << "\t\tLanguage: " << stringPackages[i].language << endl;
}
cout << endl;
}
void getUEFIStrings(vector<UEFI_IFR_STRING_PACK> &stringPackages, vector<string> &strings, const string &buffer) {
// Go through string packages
for (uint32_t i = 0; i < stringPackages.size(); i++) {
// Check if language isn't english
if (_strcmpi(stringPackages[i].language.c_str(), "en-US") != 0)
// Continue
continue;
// Set structure offset
stringPackages[i].structureOffset = strings.size();
//// Add language string to list
strings.push_back("");
EFI_HII_STRING_PACKAGE_HDR* strPackage = (EFI_HII_STRING_PACKAGE_HDR*)(&buffer[stringPackages[i].header.offset]);
EFI_HII_STRING_BLOCK* strBlock = (EFI_HII_STRING_BLOCK*)((char*)strPackage + strPackage->StringInfoOffset);
for (uint32_t offset = 0; offset < strPackage->Header.Length - strPackage->HdrSize;) {
if ((strBlock + offset)->BlockType == EFI_HII_SIBT_STRING_UCS2) {
EFI_HII_SIBT_STRING_UCS2_BLOCK* str = (EFI_HII_SIBT_STRING_UCS2_BLOCK*)(strBlock + offset);
std::u16string ws = (CHAR16*)&(str->StringText);
std::string s = std::string(ws.begin(), ws.end());
strings.push_back(s);
offset += (s.length() + 1) * sizeof(CHAR16) + 1;
}
else if ((strBlock + offset)->BlockType == EFI_HII_SIBT_SKIP2) {
EFI_HII_SIBT_SKIP2_BLOCK* skipBlock = (EFI_HII_SIBT_SKIP2_BLOCK*)(strBlock + offset);
for (uint16_t skipCount = 0; skipCount < skipBlock->SkipCount; skipCount++)
strings.push_back("");
offset += sizeof(EFI_HII_SIBT_SKIP2_BLOCK);
}
else if ((strBlock + offset)->BlockType == EFI_HII_SIBT_END) {
offset += sizeof(EFI_HII_SIBT_END_BLOCK);
}
else {
// Don't know how to handle this one
break;
}
}
}
// Go through strings
for (uint32_t i = 0; i < strings.size(); i++) {
// Change carriage return characters to spaces
for (uint32_t j = 0; j < strings[i].size(); j++)
if (strings[i][j] == '\r')
strings[i][j] = ' ';
// Remove leading spaces
while (strings[i].size() > 1 && strings[i][0] == ' ')
strings[i].erase(0, 1);
// Change double spaces
for (uint32_t j = 0; strings[i].size() && j < strings[i].size() - 1; j++)
if (strings[i][j] == ' ' && strings[i][j + 1] == ' ')
strings[i].erase(j, 1);
}
}
void displayUEFIStrings(const vector<string> &strings) {
// Print strings
cout << "Strings:" << endl;
// Go through strings
for (uint32_t i = 0; i < strings.size(); i++)
// Print string
cout << '\t' << dec << i << " (0x" << hex << uppercase << i << ") " << strings[i] << endl;
cout << endl;
}
void getUEFIFormSets(vector<UEFI_IFR_FORM_SET_PACK> &formSets, const string &buffer, const vector<UEFI_IFR_STRING_PACK> &stringPackages, const vector<string> &strings) {
// Initialize variables
UEFI_IFR_FORM_SET_PACK tempFormSet;
vector<uint32_t> stringCandidates;
uint32_t chosenCandidate;
// Go through string packages
for (uint32_t i = 0; i < stringPackages.size(); i++) {
// Check if language isn't english
if (_strcmpi(stringPackages[i].language.c_str(), "en-US") != 0)
// Continue
continue;
// Get string candidate
stringCandidates.push_back(i);
}
// Go through buffer
//FIXME: This is a very rough hack to workaround https://github.com/LongSoft/Universal-IFR-Extractor/issues/10,
// where a spurious section is detected within PE header. Address it later.
static const uint32_t DosHeaderSize = 64;
static const uint32_t DosStubSize = 128;
static const uint32_t ImageNtHeader = 24;
for (uint32_t i = DosHeaderSize + DosStubSize + ImageNtHeader; i < buffer.size() - 4; i++) {
// Check if form set was found
if ((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00')
&& buffer[i + 3] == '\x02'
&& buffer[i + 4] == '\x0E'
&& i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) <= buffer.size()
&& buffer[i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) - 1] == '\x02'
&& buffer[i + static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16) - 2] == '\x29') {
// Get chosen candidate for form set's string package
chosenCandidate = stringCandidates[0];
for (uint32_t j = 1; j < stringCandidates.size(); j++)
if (abs(static_cast<signed>(stringPackages[stringCandidates[j]].header.offset - i)) < abs(static_cast<signed>(stringPackages[chosenCandidate].header.offset - i)))
chosenCandidate = stringCandidates[j];
// Set temp form set
tempFormSet.header.offset = i;
tempFormSet.header.length = static_cast<uint32_t>(static_cast<unsigned char>(buffer[i]) + (static_cast<unsigned char>(buffer[i + 1]) << 8) + (static_cast<unsigned char>(buffer[i + 2]) << 16));
tempFormSet.header.type = static_cast<unsigned char>(buffer[i + 3]);
tempFormSet.titleString = static_cast<uint16_t>(static_cast<unsigned char>(buffer[i + 22]) + (static_cast<unsigned char>(buffer[i + 23]) << 8));
tempFormSet.usingStringPackage = chosenCandidate;
// Avoid overflow
if(tempFormSet.titleString > strings.size() || tempFormSet.usingStringPackage > stringPackages.size()) {
continue;
}
// Fix when the selected string package is not enough to decode the string
if (tempFormSet.titleString + stringPackages[chosenCandidate].structureOffset < strings.size()) {
tempFormSet.usingStringPackage = chosenCandidate;
}
else {
tempFormSet.usingStringPackage = stringCandidates[0];
}
tempFormSet.title = strings[tempFormSet.titleString + stringPackages[tempFormSet.usingStringPackage].structureOffset];
// Add temp form set to list
formSets.push_back(tempFormSet);
}
}
}
void displayUEFIFormSets(const vector<UEFI_IFR_FORM_SET_PACK> &formSets) {
// Print form sets information
cout << "Form Sets Information:" << endl;
// Go through form sets
for (uint32_t i = 0; i < formSets.size(); i++) {
// Print form set information
cout << "\tForm Set " << i << " Information:" << endl;
cout << "\t\tOffset: " << dec << formSets[i].header.offset << hex << uppercase << " (0x" << formSets[i].header.offset << ')' << endl;
cout << "\t\tLength: " << dec << formSets[i].header.length << hex << uppercase << " (0x" << formSets[i].header.length << ')' << endl;
cout << "\t\tTitle ID: " << dec << formSets[i].titleString << hex << uppercase << " (0x" << formSets[i].titleString << ')' << endl;
cout << "\t\tTitle: " << formSets[i].title << endl;
}
cout << endl;
}
vector<uint8_t> conditionalStack;
uint8_t numberOfTabs = 0;
void IndentText(uint8_t reason)
{
// Increment number of tabs
numberOfTabs++;
// Add to conditional stack
conditionalStack.push_back(reason);
}
std::string GuidToString(EFI_GUID &guid)
{
char guid_cstr[37];
sprintf(guid_cstr, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return std::string(guid_cstr);
}
void generateUEFIIFRDump(const string &outputFile, const vector<UEFI_IFR_STRING_PACK> &stringPackages, const vector<UEFI_IFR_FORM_SET_PACK> &formSets, const string &buffer, const vector<string> &strings) {
// Initialize variables
ofstream fout(outputFile.c_str());
// Display protocol
fout << setfill(' ') << setw(32) << "" << "UEFI Protocol Detected" << endl;
fout << setfill('-') << setw(80) << "" << endl;
fout << endl << endl;
// Display string packages info
fout << setfill(' ') << setw(32) << "" << "String Packages" << endl;
fout << setfill('-') << setw(80) << "" << endl;
fout << "Offset:\t\tLanguage:" << endl;
fout << setfill('-') << setw(80) << "" << endl;
for (uint8_t i = 0; i < stringPackages.size(); i++) {
fout << "0x" << hex << uppercase << stringPackages[i].header.offset;
fout << "\t\t" << stringPackages[i].language << " (0x" << hex << uppercase << (uint16_t)i << ')' << endl;
}
fout << endl << endl;
// Display form sets info
fout << setfill(' ') << setw(35) << "" << "Form Sets" << endl;
fout << setfill('-') << setw(80) << "" << endl;
fout << "Offset:\t\tTitle:" << endl;
fout << setfill('-') << setw(80) << "" << endl;
for (uint8_t i = 0; i < formSets.size(); i++) {
fout << "0x" << hex << uppercase << formSets[i].header.offset;
fout << "\t\t" << formSets[i].title << " (0x" << hex << uppercase << formSets[i].titleString << " from string package 0x" << formSets[i].usingStringPackage << ')' << endl;
}
fout << endl << endl;
// Display IFR
fout << setfill(' ') << setw(25) << "" << "Internal Forms Representation" << endl;
fout << setfill('-') << setw(80) << "" << endl;
fout << "Offset:\t\tInstruction:" << endl;
fout << setfill('-') << setw(80) << "" << endl;
// Go through form sets
for (uint32_t i = 0; i < formSets.size(); i++) {
uint32_t strPackageOffset = stringPackages[formSets[i].usingStringPackage].structureOffset;
// Go through all the form set's operations
for (uint32_t j = formSets[i].header.offset + 4; j < formSets[i].header.offset + formSets[i].header.length; j += static_cast<unsigned char>(buffer[j + 1]) & 0x7F) {
// Display offset
fout << "0x" << hex << uppercase << j << ' ';
if (buffer[j] == EFI_IFR_END_OP) {
// Decrement number of tabs
numberOfTabs--;
}
// Display tabs
for (uint8_t k = 0; k < numberOfTabs; k++)
fout << '\t';
// Check opcodes
if (buffer[j] == EFI_IFR_FORM_OP) {
// Create temp
EFI_IFR_FORM *temp = (EFI_IFR_FORM*)&buffer[j];
// Display temp
fout << "Form: " << strings[temp->FormTitle + strPackageOffset] << ", FormId: 0x" << hex << uppercase << temp->FormId;
}
else if (buffer[j] == EFI_IFR_SUBTITLE_OP) {
// Create temp
EFI_IFR_SUBTITLE *temp = (EFI_IFR_SUBTITLE*)&buffer[j];
// Display temp
fout << "Subtitle: Statement.Prompt: " << strings[temp->Statement.Prompt + strPackageOffset];
//fout << ", Statement.Help: " << strings[temp->Statement.Help + strPackageOffset];
fout << ", Flags: 0x" << hex << uppercase << (uint16_t)temp->Flags;
}
else if (buffer[j] == EFI_IFR_TEXT_OP) {
// Create temp
EFI_IFR_TEXT *temp = (EFI_IFR_TEXT*)&buffer[j];
// Display temp
fout << "Text: Statement.Prompt: " << strings[temp->Statement.Prompt + strPackageOffset];
//fout << ", Statement.Help: " << strings[temp->Statement.Help + strPackageOffset];
fout << ", TextTwo: " << strings[temp->TextTwo + strPackageOffset];
}
else if (buffer[j] == EFI_IFR_IMAGE_OP) {
// Create temp
EFI_IFR_IMAGE *temp = (EFI_IFR_IMAGE*)&buffer[j];
// Display temp
fout << "Image: Id: 0x" << hex << uppercase << temp->Id;
}
else if (buffer[j] == EFI_IFR_ONE_OF_OP) {
// Create temp
EFI_IFR_ONE_OF *temp = (EFI_IFR_ONE_OF*)&buffer[j];
// If VarStoreId refers to Buffer Storage (EFI_IFR_VARSTORE or EFI_IFR_VARSTORE_EFI), then VarStoreInfo contains a 16-bit Buffer Storage offset (VarOffset). If VarStoreId refers to Name/Value Storage (EFI_IFR_VARSTORE_NAME_VALUE), then VarStoreInfo contains the String ID of the name (VarName) for this name/value pair.
// Display temp
fout << "One Of: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_1) {
fout << ", Size: 1";
fout << ", Min: 0x" << (uint16_t)temp->data.u8.MinValue;
fout << ", Max 0x" << (uint16_t)temp->data.u8.MaxValue;
fout << ", Step: 0x" << (uint16_t)temp->data.u8.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_2) {
fout << ", Size: 2";
fout << ", Min: 0x" << temp->data.u16.MinValue;
fout << ", Max 0x" << temp->data.u16.MaxValue;
fout << ", Step: 0x" << temp->data.u16.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_4) {
fout << ", Size: 4";
fout << ", Min: 0x" << temp->data.u32.MinValue;
fout << ", Max 0x" << temp->data.u32.MaxValue;
fout << ", Step: 0x" << temp->data.u32.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_8) {
fout << ", Size: 8";
fout << ", Min: 0x" << temp->data.u64.MinValue;
fout << ", Max 0x" << temp->data.u64.MaxValue;
fout << ", Step: 0x" << temp->data.u64.Step;
}
}
else if (buffer[j] == EFI_IFR_CHECKBOX_OP) {
// Create temp
EFI_IFR_CHECKBOX *temp = (EFI_IFR_CHECKBOX*)&buffer[j];
// Display temp
fout << "Checkbox: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
}
else if (buffer[j] == EFI_IFR_NUMERIC_OP) {
// Create temp
EFI_IFR_NUMERIC *temp = (EFI_IFR_NUMERIC*)&buffer[j];
// Display temp
fout << "Numeric: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_1) {
fout << ", Size: 1";
fout << ", Min: 0x" << (uint16_t)temp->data.u8.MinValue;
fout << ", Max 0x" << (uint16_t)temp->data.u8.MaxValue;
fout << ", Step: 0x" << (uint16_t)temp->data.u8.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_2) {
fout << ", Size: 2";
fout << ", Min: 0x" << temp->data.u16.MinValue;
fout << ", Max 0x" << temp->data.u16.MaxValue;
fout << ", Step: 0x" << temp->data.u16.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_4) {
fout << ", Size: 4";
fout << ", Min: 0x" << temp->data.u32.MinValue;
fout << ", Max 0x" << temp->data.u32.MaxValue;
fout << ", Step: 0x" << temp->data.u32.Step;
}
else if ((temp->Flags & EFI_IFR_NUMERIC_SIZE) == EFI_IFR_NUMERIC_SIZE_8) {
fout << ", Size: 8";
fout << ", Min: 0x" << temp->data.u64.MinValue;
fout << ", Max 0x" << temp->data.u64.MaxValue;
fout << ", Step: 0x" << temp->data.u64.Step;
}
}
else if (buffer[j] == EFI_IFR_PASSWORD_OP) {
// Create temp
EFI_IFR_PASSWORD *temp = (EFI_IFR_PASSWORD*)&buffer[j];
// Display temp
fout << "Password: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
fout << ", MinSize: 0x" << temp->MinSize;
fout << ", MaxSize 0x" << temp->MaxSize;
}
else if (buffer[j] == EFI_IFR_ONE_OF_OPTION_OP) {
// Create temp
EFI_IFR_ONE_OF_OPTION *temp = (EFI_IFR_ONE_OF_OPTION*)&buffer[j];
// Display temp
fout << "One Of Option: " << strings[temp->Option + strPackageOffset] << ", Value ";
if (temp->Type == EFI_IFR_TYPE_NUM_SIZE_8)
fout << "(8 bit): 0x" << hex << uppercase << (uint16_t)temp->Value.u8;
else if (temp->Type == EFI_IFR_TYPE_NUM_SIZE_16)
fout << "(16 bit): 0x" << hex << uppercase << temp->Value.u16;
else if (temp->Type == EFI_IFR_TYPE_NUM_SIZE_32)
fout << "(32 bit): 0x" << hex << uppercase << temp->Value.u32;
else if (temp->Type == EFI_IFR_TYPE_NUM_SIZE_64)
fout << "(64 bit): 0x" << hex << uppercase << temp->Value.u64;
else if (temp->Type == EFI_IFR_TYPE_BOOLEAN)
fout << "(Bool): " << (temp->Value.b ? "true" : "false");
else if (temp->Type == EFI_IFR_TYPE_TIME)
fout << "(Time)";
else if (temp->Type == EFI_IFR_TYPE_DATE)
fout << "(Date)";
else if (temp->Type == EFI_IFR_TYPE_STRING)
fout << "(String): " << strings[temp->Value.string + strPackageOffset];
else if (temp->Type == EFI_IFR_TYPE_OTHER)
fout << "(Other)";
else if (temp->Type == EFI_IFR_TYPE_UNDEFINED)
fout << "(Undefined)";
else if (temp->Type == EFI_IFR_TYPE_ACTION)
fout << "(Action)";
else if (temp->Type == EFI_IFR_TYPE_BUFFER)
fout << "(Buffer)";
else if (temp->Type == EFI_IFR_TYPE_REF)
fout << "(Ref)";
if (temp->Flags & EFI_IFR_OPTION_DEFAULT)
fout << " (default)";
else if (temp->Flags & EFI_IFR_OPTION_DEFAULT_MFG)
fout << " (default MFG)";
}
else if (buffer[j] == EFI_IFR_SUPPRESS_IF_OP) {
// Create temp
EFI_IFR_SUPPRESS_IF *temp = (EFI_IFR_SUPPRESS_IF*)&buffer[j];
// Display temp
fout << "Suppress If";
}
else if (buffer[j] == EFI_IFR_LOCKED_OP) {
// Create temp
EFI_IFR_LOCKED *temp = (EFI_IFR_LOCKED*)&buffer[j];
// Display temp
fout << "Locked";
}
else if (buffer[j] == EFI_IFR_ACTION_OP) {
// Create temp
EFI_IFR_ACTION *temp = (EFI_IFR_ACTION*)&buffer[j];
// Display temp
fout << "Action: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId << ", QuestionConfig: " << strings[temp->QuestionConfig + strPackageOffset];
}
else if (buffer[j] == EFI_IFR_RESET_BUTTON_OP) {
// Create temp
EFI_IFR_RESET_BUTTON *temp = (EFI_IFR_RESET_BUTTON*)&buffer[j];
// Display temp
fout << "Reset Button: " << strings[temp->Statement.Prompt + strPackageOffset] << ", DefaultId: " << hex << uppercase << temp->DefaultId;
}
else if (buffer[j] == EFI_IFR_FORM_SET_OP) {
// Create temp
EFI_IFR_FORM_SET *temp = (EFI_IFR_FORM_SET*)&buffer[j];
// Display temp
fout << "Form Set: " << strings[temp->FormSetTitle + strPackageOffset] << " [" << GuidToString(temp->Guid) << "]";
for (uint8_t idx = 0; idx < (temp->Flags & 0x3); idx++)
fout << ", ClassGuid" << (uint16_t)idx << " [" << GuidToString(temp->ClassGuid[idx]) << "]";
}
else if (buffer[j] == EFI_IFR_REF_OP) {
// Create temp
EFI_IFR_REF *temp = (EFI_IFR_REF*)&buffer[j];
// Display temp
fout << "Ref: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId << ", FormId: 0x" << hex << uppercase << temp->FormId;
}
else if (buffer[j] == EFI_IFR_NO_SUBMIT_IF_OP) {
// Create temp
EFI_IFR_NO_SUBMIT_IF *temp = (EFI_IFR_NO_SUBMIT_IF*)&buffer[j];
// Display temp
fout << "No Submit If: " << strings[temp->Error + strPackageOffset];
}
else if (buffer[j] == EFI_IFR_INCONSISTENT_IF_OP) {
// Create temp
EFI_IFR_INCONSISTENT_IF *temp = (EFI_IFR_INCONSISTENT_IF*)&buffer[j];
// Display temp
fout << "Inconsistent If: " << strings[temp->Error + strPackageOffset];
}
else if (buffer[j] == EFI_IFR_EQ_ID_VAL_OP) {
// Create temp
EFI_IFR_EQ_ID_VAL *temp = (EFI_IFR_EQ_ID_VAL*)&buffer[j];
// Display temp
fout << "QuestionId: 0x" << hex << uppercase << temp->QuestionId << " equals value 0x" << hex << uppercase << temp->Value;
}
else if (buffer[j] == EFI_IFR_EQ_ID_ID_OP) {
// Create temp
EFI_IFR_EQ_ID_ID *temp = (EFI_IFR_EQ_ID_ID*)&buffer[j];
// Display temp
fout << "QuestionId: 0x" << hex << uppercase << temp->QuestionId1 << " equals QuestionId 0x" << hex << uppercase << temp->QuestionId2;
}
else if (buffer[j] == EFI_IFR_EQ_ID_VAL_LIST_OP) {
// Create temp
EFI_IFR_EQ_ID_VAL_LIST *temp = (EFI_IFR_EQ_ID_VAL_LIST*)&buffer[j];
// Display temp
fout << "QuestionId: 0x" << hex << uppercase << temp->QuestionId << " equals value in list (";
for (uint8_t k = 0; k < temp->ListLength; k++) {
fout << "0x" << hex << uppercase << temp->ValueList[k];
if (k != temp->ListLength - 1)
fout << ", ";
else
fout << ')';
}
}
else if (buffer[j] == EFI_IFR_AND_OP) {
// Create temp
EFI_IFR_AND *temp = (EFI_IFR_AND*)&buffer[j];
// Display temp
fout << "And";
}
else if (buffer[j] == EFI_IFR_OR_OP) {
// Create temp
EFI_IFR_OR *temp = (EFI_IFR_OR*)&buffer[j];
// Display temp
fout << "Or";
}
else if (buffer[j] == EFI_IFR_NOT_OP) {
// Create temp
EFI_IFR_NOT *temp = (EFI_IFR_NOT*)&buffer[j];
// Display temp
fout << "Not";
}
else if (buffer[j] == EFI_IFR_RULE_OP) {
// Create temp
EFI_IFR_RULE *temp = (EFI_IFR_RULE*)&buffer[j];
// Display temp
fout << "Rule: RuleId: 0x" << hex << uppercase << (uint16_t)temp->RuleId;
}
else if (buffer[j] == EFI_IFR_GRAY_OUT_IF_OP) {
// Create temp
EFI_IFR_GRAY_OUT_IF *temp = (EFI_IFR_GRAY_OUT_IF*)&buffer[j];
// Display temp
fout << "Gray Out If";
}
else if (buffer[j] == EFI_IFR_DATE_OP) {
// Create temp
EFI_IFR_DATE *temp = (EFI_IFR_DATE*)&buffer[j];
// Display temp
fout << "Date: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
}
else if (buffer[j] == EFI_IFR_TIME_OP) {
// Create temp
EFI_IFR_TIME *temp = (EFI_IFR_TIME*)&buffer[j];
// Display temp
fout << "Time: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId;
}
else if (buffer[j] == EFI_IFR_STRING_OP) {
// Create temp
EFI_IFR_STRING *temp = (EFI_IFR_STRING*)&buffer[j];
// Display temp
fout << "String: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId << ", MinSize: 0x" << temp->MinSize << ", MaxSize: 0x" << temp->MaxSize;
}
else if (buffer[j] == EFI_IFR_REFRESH_OP) {
// Create temp
EFI_IFR_REFRESH *temp = (EFI_IFR_REFRESH*)&buffer[j];
// Display temp
fout << "Refresh: RefreshInterval: 0x" << hex << uppercase << (uint16_t)temp->RefreshInterval;
}
else if (buffer[j] == EFI_IFR_DISABLE_IF_OP) {
// Create temp
EFI_IFR_DISABLE_IF *temp = (EFI_IFR_DISABLE_IF*)&buffer[j];
// Display temp
fout << "Disable If";
}
else if (buffer[j] == EFI_IFR_ANIMATION_OP) {
// Create temp
EFI_IFR_ANIMATION *temp = (EFI_IFR_ANIMATION*)&buffer[j];
// Display temp
fout << "Animation: Id: 0x" << hex << uppercase << temp->Id;
}
else if (buffer[j] == EFI_IFR_TO_LOWER_OP) {
// Create temp
EFI_IFR_TO_LOWER *temp = (EFI_IFR_TO_LOWER*)&buffer[j];
// Display temp
fout << "Convert to Lower";
}
else if (buffer[j] == EFI_IFR_TO_UPPER_OP) {
// Create temp
EFI_IFR_TO_UPPER *temp = (EFI_IFR_TO_UPPER*)&buffer[j];
// Display temp
fout << "Convert to Upper";
}
else if (buffer[j] == EFI_IFR_MAP_OP) {
// Create temp
EFI_IFR_MAP *temp = (EFI_IFR_MAP*)&buffer[j];
// Display temp
fout << "Map";
}
else if (buffer[j] == EFI_IFR_ORDERED_LIST_OP) {
// Create temp
EFI_IFR_ORDERED_LIST *temp = (EFI_IFR_ORDERED_LIST*)&buffer[j];
// Display temp
fout << "Ordered List: " << strings[temp->Question.Header.Prompt + strPackageOffset] << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->Question.VarStoreInfo.VarOffset << ", VarStore: 0x" << temp->Question.VarStoreId << ", QuestionId: 0x" << temp->Question.QuestionId << ", MaxContainers: 0x" << (uint16_t)temp->MaxContainers << ", Flags: 0x" << (uint16_t)temp->Flags;
}
else if (buffer[j] == EFI_IFR_VARSTORE_OP) {
// Create temp
EFI_IFR_VARSTORE *temp = (EFI_IFR_VARSTORE*)&buffer[j];
// Display temp
fout << "VarStore: VarStoreId: 0x" << hex << uppercase << temp->VarStoreId << " [" << GuidToString(temp->Guid) << "]" << ", Size: 0x" << hex << uppercase << temp->Size << ", Name: " << temp->Name;
}
else if (buffer[j] == EFI_IFR_VARSTORE_NAME_VALUE_OP) {
// Create temp
EFI_IFR_VARSTORE_NAME_VALUE *temp = (EFI_IFR_VARSTORE_NAME_VALUE*)&buffer[j];
// Display temp
fout << "VarStoreNameValue: VarStoreId: 0x" << hex << uppercase << temp->VarStoreId << " [" << GuidToString(temp->Guid) << "]";
}
else if (buffer[j] == EFI_IFR_VARSTORE_EFI_OP) {
// Create temp
EFI_IFR_VARSTORE_EFI *temp = (EFI_IFR_VARSTORE_EFI*)&buffer[j];
// Display temp
fout << "VarStoreEFI: VarStoreId: 0x" << hex << uppercase << temp->VarStoreId << " [" << GuidToString(temp->Guid) << "]" << ", Attrubutes: " << hex << uppercase << temp->Attributes << ", Size: " << hex << uppercase << temp->Size << ", Name: " << temp->Name;
}
else if (buffer[j] == EFI_IFR_VARSTORE_DEVICE_OP) {
// Create temp
EFI_IFR_VARSTORE_DEVICE *temp = (EFI_IFR_VARSTORE_DEVICE*)&buffer[j];
// Display temp
fout << "VarStoreDevice: " << strings[temp->DevicePath + strPackageOffset];
}
else if (buffer[j] == EFI_IFR_VERSION_OP) {
// Create temp
EFI_IFR_VERSION *temp = (EFI_IFR_VERSION*)&buffer[j];
// Display temp
fout << "Version";
}
else if (buffer[j] == EFI_IFR_END_OP) {
// Create temp
EFI_IFR_END *temp = (EFI_IFR_END*)&buffer[j];
// Get condition
uint8_t condition = conditionalStack.back();
// Decrement conditional stack
conditionalStack.pop_back();
// Display temp
fout << "End";
if (condition == FORM_SET)
fout << " Form Set";
else if (condition == FORM)
fout << " Form";
else if (condition == CONDITION)
fout << " If";
else if (condition == OPTION)
fout << " One Of";
}
else if (buffer[j] == EFI_IFR_MATCH_OP) {
// Create temp
EFI_IFR_MATCH *temp = (EFI_IFR_MATCH*)&buffer[j];
// Display temp
fout << "Match";
}
else if (buffer[j] == EFI_IFR_GET_OP) {
// Create temp
EFI_IFR_GET *temp = (EFI_IFR_GET*)&buffer[j];
fout << "Get: VarStoreId: 0x" << hex << uppercase << temp->VarStoreId << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->VarStoreInfo.VarOffset << ", VarStoreType: 0x" << (uint16_t)temp->VarStoreType;
}
else if (buffer[j] == EFI_IFR_SET_OP) {
// Create temp
EFI_IFR_SET *temp = (EFI_IFR_SET*)&buffer[j];
// Display temp
fout << "Set: VarStoreId: 0x" << hex << uppercase << temp->VarStoreId << ", VarStoreInfo (VarOffset/VarName): 0x" << hex << uppercase << temp->VarStoreInfo.VarOffset << ", VarStoreType: 0x" << (uint16_t)temp->VarStoreType;
}
else if (buffer[j] == EFI_IFR_READ_OP) {
// Create temp
EFI_IFR_READ *temp = (EFI_IFR_READ*)&buffer[j];
// Display temp
fout << "Read";
}
else if (buffer[j] == EFI_IFR_WRITE_OP) {
// Create temp
EFI_IFR_WRITE *temp = (EFI_IFR_WRITE*)&buffer[j];
// Display temp
fout << "Write";
}
else if (buffer[j] == EFI_IFR_EQUAL_OP) {
// Create temp
EFI_IFR_EQUAL *temp = (EFI_IFR_EQUAL*)&buffer[j];
// Display temp
fout << "Equal";
}
else if (buffer[j] == EFI_IFR_NOT_EQUAL_OP) {
// Create temp
EFI_IFR_NOT_EQUAL *temp = (EFI_IFR_NOT_EQUAL*)&buffer[j];
// Display temp
fout << "Not Equal";
}
else if (buffer[j] == EFI_IFR_GREATER_THAN_OP) {
// Create temp
EFI_IFR_GREATER_THAN *temp = (EFI_IFR_GREATER_THAN*)&buffer[j];
// Display temp
fout << "Greater Than";
}
else if (buffer[j] == EFI_IFR_GREATER_EQUAL_OP) {
// Create temp
EFI_IFR_GREATER_EQUAL *temp = (EFI_IFR_GREATER_EQUAL*)&buffer[j];
// Display temp
fout << "Greater Than or Equal";
}
else if (buffer[j] == EFI_IFR_LESS_THAN_OP) {
// Create temp
EFI_IFR_LESS_THAN *temp = (EFI_IFR_LESS_THAN*)&buffer[j];
// Display temp
fout << "Less Than";
}
else if (buffer[j] == EFI_IFR_LESS_EQUAL_OP) {
// Create temp
EFI_IFR_LESS_EQUAL *temp = (EFI_IFR_LESS_EQUAL*)&buffer[j];
// Display temp
fout << "Less Than or Equal";
}
else if (buffer[j] == EFI_IFR_BITWISE_AND_OP) {
// Create temp
EFI_IFR_BITWISE_AND *temp = (EFI_IFR_BITWISE_AND*)&buffer[j];
// Display temp
fout << "Bitwise And";
}
else if (buffer[j] == EFI_IFR_BITWISE_OR_OP) {
// Create temp
EFI_IFR_BITWISE_OR *temp = (EFI_IFR_BITWISE_OR*)&buffer[j];
// Display temp
fout << "Bitwise Or";
}
else if (buffer[j] == EFI_IFR_BITWISE_NOT_OP) {
// Create temp
EFI_IFR_BITWISE_NOT *temp = (EFI_IFR_BITWISE_NOT*)&buffer[j];
// Display temp
fout << "Bitwise Not";
}
else if (buffer[j] == EFI_IFR_SHIFT_LEFT_OP) {
// Create temp
EFI_IFR_SHIFT_LEFT *temp = (EFI_IFR_SHIFT_LEFT*)&buffer[j];
// Display temp
fout << "Shift Left";
}
else if (buffer[j] == EFI_IFR_SHIFT_RIGHT_OP) {
// Create temp
EFI_IFR_SHIFT_RIGHT *temp = (EFI_IFR_SHIFT_RIGHT*)&buffer[j];
// Display temp
fout << "Shift Right";
}
else if (buffer[j] == EFI_IFR_ADD_OP) {
// Create temp
EFI_IFR_ADD *temp = (EFI_IFR_ADD*)&buffer[j];
// Display temp
fout << "Add";
}
else if (buffer[j] == EFI_IFR_SUBTRACT_OP) {
// Create temp
EFI_IFR_SUBTRACT *temp = (EFI_IFR_SUBTRACT*)&buffer[j];
// Display temp
fout << "Subtract";
}
else if (buffer[j] == EFI_IFR_MULTIPLY_OP) {
// Create temp
EFI_IFR_MULTIPLY *temp = (EFI_IFR_MULTIPLY*)&buffer[j];
// Display temp
fout << "Multiply";
}
else if (buffer[j] == EFI_IFR_DIVIDE_OP) {
// Create temp
EFI_IFR_DIVIDE *temp = (EFI_IFR_DIVIDE*)&buffer[j];
// Display temp
fout << "Divide";
}
else if (buffer[j] == EFI_IFR_MODULO_OP) {
// Create temp
EFI_IFR_MODULO *temp = (EFI_IFR_MODULO*)&buffer[j];
// Display temp
fout << "Modulo";
}
else if (buffer[j] == EFI_IFR_RULE_REF_OP) {
// Create temp
EFI_IFR_RULE_REF *temp = (EFI_IFR_RULE_REF*)&buffer[j];
// Display temp
fout << "Rule Ref: RuleId: 0x" << hex << uppercase << (uint16_t)temp->RuleId;
}
else if (buffer[j] == EFI_IFR_QUESTION_REF1_OP) {
// Create temp
EFI_IFR_QUESTION_REF1 *temp = (EFI_IFR_QUESTION_REF1*)&buffer[j];
// Display temp
fout << "Question Ref1: QuestionId: 0x" << hex << uppercase << temp->QuestionId;
}
else if (buffer[j] == EFI_IFR_QUESTION_REF2_OP) {
// Create temp
EFI_IFR_QUESTION_REF2 *temp = (EFI_IFR_QUESTION_REF2*)&buffer[j];
// Display temp
fout << "Question Ref2";
}
else if (buffer[j] == EFI_IFR_UINT8_OP) {
// Create temp
EFI_IFR_UINT8 *temp = (EFI_IFR_UINT8*)&buffer[j];
// Display temp
fout << "8 Bit Unsigned Int: 0x" << hex << uppercase << (uint16_t)temp->Value;
}
else if (buffer[j] == EFI_IFR_UINT16_OP) {
// Create temp
EFI_IFR_UINT16 *temp = (EFI_IFR_UINT16*)&buffer[j];
// Display temp
fout << "16 Bit Unsigned Int: 0x" << hex << uppercase << temp->Value;
}
else if (buffer[j] == EFI_IFR_UINT32_OP) {
// Create temp
EFI_IFR_UINT32 *temp = (EFI_IFR_UINT32*)&buffer[j];
// Display temp
fout << "32 Bit Unsigned Int: 0x" << hex << uppercase << temp->Value;
}
else if (buffer[j] == EFI_IFR_UINT64_OP) {
// Create temp
EFI_IFR_UINT64 *temp = (EFI_IFR_UINT64*)&buffer[j];
// Display temp
fout << "64 Bit Unsigned Int: 0x" << hex << uppercase << temp->Value;
}
else if (buffer[j] == EFI_IFR_TRUE_OP) {
// Create temp
EFI_IFR_TRUE *temp = (EFI_IFR_TRUE*)&buffer[j];
// Display temp
fout << "True";
}
else if (buffer[j] == EFI_IFR_FALSE_OP) {
// Create temp