diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e14839e --- /dev/null +++ b/.gitignore @@ -0,0 +1,239 @@ +################# +## Qt +################# +moc_*.* +ui_*.* + +################# +## Qt Creator +################# +*.pro.user.* + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini +.directory + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +############# +## qmake / make +############# +*.o +Makefile +CMakeCache.txt +CMakeFiles +CMakeScripts +DerivedData +IFRExtractor.xcodeproj +cmake_install.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..48044ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +PROJECT(IFRExtractor) + +SET(PROJECT_SOURCES_CLI + EFI.cpp + UEFI.cpp + main-cli.cpp +) + +SET(PROJECT_SOURCES_WIN + EFI.cpp + UEFI.cpp + main.cpp +) + +SET(PROJECT_HEADERS + EFI.h + UEFI.h + UEFIHeader.h +) + +ADD_EXECUTABLE(ifrextract ${PROJECT_SOURCES_CLI} ${PROJECT_HEADERS}) +IF(WIN32) + IF(MSVC) + ADD_EXECUTABLE(IRFExtractor WIN32 ${PROJECT_SOURCES_WIN} ${PROJECT_HEADERS} ifrextractor.rc) + ENDIF() +ENDIF() diff --git a/EFI.cpp b/EFI.cpp old mode 100755 new mode 100644 index 4351630..c00de7b --- a/EFI.cpp +++ b/EFI.cpp @@ -1,1660 +1,1668 @@ -// Header files -#include -#include -#include -#include "EFI.h" - - -// Supporting function implementation -void getEFIStringPackages(vector &stringPackages, const string &buffer) { - - // Initialize variables - EFI_IFR_STRING_PACK tempStringPackage; - - // Go through buffer - for(unsigned int i = 0; i < buffer.size() - 9; i++) - - // Check if string pakage was found - if((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x02' && buffer[i + 5] == '\x00' && (buffer[i + 6] != '\x00' || buffer[i + 7] != '\x00' || buffer[i + 8] != '\x00' || buffer[i + 9] != '\x00') && i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] >= 'a' && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] <= 'z' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 4] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 5] == '\x00') { - - // Set temp string package - tempStringPackage.header.offset = i; - - tempStringPackage.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24)); - - tempStringPackage.header.type = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8)); - - for(uint32_t j = i + static_cast(static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24)); buffer[j] != '\x00'; j += 2) - tempStringPackage.language.push_back(buffer[j]); - - tempStringPackage.numberOfStrings = static_cast(static_cast(buffer[i + 14]) + (static_cast(buffer[i + 15]) << 8) + (static_cast(buffer[i + 16]) << 16) + (static_cast(buffer[i + 17]) << 24)); - - tempStringPackage.attributes = static_cast(static_cast(buffer[i + 18]) + (static_cast(buffer[i + 19]) << 8) + (static_cast(buffer[i + 20]) << 16) + (static_cast(buffer[i + 21]) << 24)); - - // Add string package to list - stringPackages.push_back(tempStringPackage); - - // Clear temp string package - tempStringPackage.language.clear(); - } -} - -void displayEFIStringPackages(const vector &stringPackages) { - - // Display string packages info - cout << "String Packages Information:" << endl; - - // Go through string packages - for(unsigned int 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 << "\t\tNumber of strings: " << dec << stringPackages[i].numberOfStrings << hex << uppercase << " (0x" << stringPackages[i].numberOfStrings << ')' << endl; - cout << "\t\tAttributes: " << dec << stringPackages[i].attributes << hex << uppercase << " (0x" << stringPackages[i].attributes << ')' << endl; - } - - cout << endl; -} - -void getEFIStrings(vector &stringPackages, vector &strings, const string &buffer) { - - // Initialize variables - int index; - string temp; - - // Go through string packages - for(unsigned int i = 0; i < stringPackages.size(); i++) { - - // Check if language isn't english - if(stringPackages[i].language != "eng") - - // Continue - continue; - - // Set structure offset - stringPackages[i].structureOffset = strings.size(); - - // Set index - index = stringPackages[i].header.offset + 22; - - // Go through strings - for(uint32_t j = 0; j < stringPackages[i].numberOfStrings; j++) { - - // Fill string - for(uint32_t k = stringPackages[i].header.offset + static_cast(static_cast(buffer[index]) + (static_cast(buffer[index + 1]) << 8) + (static_cast(buffer[index + 2]) << 16) + (static_cast(buffer[index + 3]) << 24)); buffer[k] != '\x00'; k += 2) - temp.push_back(buffer[k]); - - // Add string to list - strings.push_back(temp); - - // Clear temp - temp.clear(); - - // Increment index - index += 4; - } - } - - // Go through strings - for(unsigned int i = 0; i < strings.size(); i++) { - - // Change carriage return characters to spaces - for(unsigned int 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(unsigned int 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 displayEFIStrings(const vector &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 getEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings) { - - // Initialize variables - EFI_IFR_FORM_SET_PACK tempFormSet; - vector stringCandidates; - uint32_t chosenCandidate; - - // Go through string packages - for(unsigned int i = 0; i < stringPackages.size(); i++) { - - // Check if language isn't english - if(stringPackages[i].language != "eng") - - // Continue - continue; - - // Get string candidate - stringCandidates.push_back(i); - } - - // Go through buffer - for(uint32_t i = 0; i < buffer.size() - 5; i++) - - // Check if form set was found - if((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x03' && buffer[i + 5] == '\x00' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) - 1] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) - 2] == '\x0D') { - - // Get chosen candidate for form set's string package - chosenCandidate = stringCandidates[0]; - for(unsigned int j = 1; j < stringCandidates.size(); j++) - if(abs(static_cast(stringPackages[j].header.offset - i)) < abs(static_cast(stringPackages[chosenCandidate].header.offset - i))) - chosenCandidate = j; - - // Set temp form set - tempFormSet.header.offset = i; - tempFormSet.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24)); - tempFormSet.header.type = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8)); - tempFormSet.titleString = static_cast(static_cast(buffer[i + 24]) + (static_cast(buffer[i + 25]) << 8)); - tempFormSet.usingStringPackage = stringCandidates[chosenCandidate]; - tempFormSet.title = strings[tempFormSet.titleString + stringPackages[tempFormSet.usingStringPackage].structureOffset]; - - // Add temp form set to list - formSets.push_back(tempFormSet); - } -} - -void displayEFIFormSets(const vector &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; -} - -void generateEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings) { - - // Initialize variables - uint8_t numberOfTabs = 0; - uint8_t numberOfIfs = 0; - unsigned char highNibble, lowNibble; - ofstream fout(outputFile.c_str()); - - // Display protocol - for(uint8_t i = 0; i < 32; i++) - fout << ' '; - fout << "EFI Protocol Detected" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl << endl << endl; - - // Display string packages info - for(uint8_t i = 0; i < 32; i++) - fout << ' '; - fout << "String Packages" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tLanguage:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << 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 << static_cast(i) << ')' << endl; - } - fout << endl << endl; - - // Display form sets info - for(uint8_t i = 0; i < 35; i++) - fout << ' '; - fout << "Form Sets" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tTitle:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << 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 internal forms representation - for(uint8_t i = 0; i < 25; i++) - fout << ' '; - fout << "Internal Forms Representation" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tInstruction:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - - // Go through form sets - for(uint32_t i = 0; i < formSets.size(); i++) - - // Go through all the form set's operations - for(uint32_t j = formSets[i].header.offset + 6; j < formSets[i].header.offset + formSets[i].header.length; j += static_cast(buffer[j + 1])) { - - // Check if opcode is EFI_IFR_FORM_OP 0x01 - if(buffer[j] == EFI_IFR_FORM_OP) { - - // Create temp - EFI_IFR_FORM temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.titleString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Form: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_SUBTITLE_OP 0x02 - else if(buffer[j] == EFI_IFR_SUBTITLE_OP) { - - // Create temp - EFI_IFR_SUBTITLE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.subtitleString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Subtitle: " << strings[temp.subtitleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - } - - // Otherwise check if opcode is EFI_IFR_TEXT_OP 0x03 - else if(buffer[j] == EFI_IFR_TEXT_OP) { - - // Create temp - EFI_IFR_TEXT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.helpString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.primaryTextString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.secondaryTextString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.flags = static_cast(buffer[j + 8]); - temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Text: " << strings[temp.primaryTextString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - } - - // Otherwise chec if opcode is EFI_IFR_GRAPHIC_OP 0x04 - else if(buffer[j] == EFI_IFR_GRAPHIC_OP) { - - // Display offset - fout << "0x" << hex << uppercase << j << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Graphic:"; - } - - // Otherwise check if opcode is EFI_IFR_ONE_OF_OP 0x05 - else if(buffer[j] == EFI_IFR_ONE_OF_OP) { - - // Create temp - EFI_IFR_ONE_OF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Setting: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_CHECKBOX_OP 0x06 - else if(buffer[j] == EFI_IFR_CHECKBOX_OP) { - - // Create temp - EFI_IFR_CHECKBOX temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.flags = static_cast(buffer[j + 9]); - temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Checkbox: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_NUMERIC_OP 0x07 - else if(buffer[j] == EFI_IFR_NUMERIC_OP) { - - // Create temp - EFI_IFR_NUMERIC temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.flags = static_cast(buffer[j + 9]); - temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.maximum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.minimum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.step = static_cast(static_cast(buffer[j + 16]) + (static_cast(buffer[j + 17]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Numeric: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << " (" << dec << temp.minimum << '-' << temp.maximum << "), Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_PASSWORD_OP 0x08 - else if(buffer[j] == EFI_IFR_PASSWORD_OP) { - - // Create temp - EFI_IFR_PASSWORD temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.flags = static_cast(buffer[j + 9]); - temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.minimumSize = static_cast(buffer[j + 12]); - temp.maximumSize = static_cast(buffer[j + 13]); - temp.encoding = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Password: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_ONE_OF_OPTION_OP 0x09 - else if(buffer[j] == EFI_IFR_ONE_OF_OPTION_OP) { - - // Create temp - EFI_IFR_ONE_OF_OPTION temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.optionString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.value = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.flags = static_cast(buffer[j + 6]); - temp.key = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Option: " << strings[temp.optionString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Value: 0x" << hex << uppercase << temp.value; - } - - // Otherwise check if opcode is EFI_IFR_SUPPRESS_IF_OP 0x0A - else if(buffer[j] == EFI_IFR_SUPPRESS_IF_OP) { - - // Create temp - EFI_IFR_SUPPRESS temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.flags = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Suppress If:"; - - // Increment number of ifs - numberOfIfs++; - } - - // Otherwise check if opcode is EFI_IFR_END_FORM_OP 0x0B - else if(buffer[j] == EFI_IFR_END_FORM_OP) { - - // Create temp - EFI_IFR_END_FORM temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Decrement number of tabs - numberOfTabs--; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "End Form"; - } - - // Otherwise check if opcode is EFI_IFR_HIDDEN_OP 0x0C - else if(buffer[j] == EFI_IFR_HIDDEN_OP) { - - // Create temp - EFI_IFR_HIDDEN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.value = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.key = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Hidden:"; - } - - // Otherwise check if opcode is EFI_IFR_END_FORM_SET_OP 0x0D - else if(buffer[j] == EFI_IFR_END_FORM_SET_OP) { - - // Create temp - EFI_IFR_END_FORM_SET temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Decrement number of tabs - numberOfTabs--; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "End Form Set"; - } - - // Otherwise check if opcode is EFI_IFR_FORM_SET_OP 0x0E - else if(buffer[j] == EFI_IFR_FORM_SET_OP) { - - // Create temp - EFI_IFR_FORM_SET temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.titleString = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); - temp.callbackHandle = static_cast(static_cast(buffer[j + 22]) + (static_cast(buffer[j + 23]) << 8) + (static_cast(buffer[j + 24]) << 16) + (static_cast(buffer[j + 25]) << 24) + (static_cast(static_cast(buffer[j + 26])) << 32) + (static_cast(static_cast(buffer[j + 27])) << 40) + (static_cast(static_cast(buffer[j + 28])) << 48) + (static_cast(static_cast(buffer[j + 29])) << 56)); - temp.mainClass = static_cast(static_cast(buffer[j + 30]) + (static_cast(buffer[j + 31]) << 8)); - temp.subClass = static_cast(static_cast(buffer[j + 32]) + (static_cast(buffer[j + 33]) << 8)); - temp.nvDataSize = static_cast(static_cast(buffer[j + 34]) + (static_cast(buffer[j + 25]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Form Set: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_REF_OP 0x0F - else if(buffer[j] == EFI_IFR_REF_OP) { - - // Create temp - EFI_IFR_REF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.flags = static_cast(static_cast(buffer[j + 8])); - temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Selectable: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; - } - - // Otherwise check if opcode is EFI_IFR_END_OP 0x10 - else if(buffer[j] == EFI_IFR_END_ONE_OF_OP) { - - // Create temp - EFI_IFR_END_ONE_OF temp; - - // Fill end one of - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Decrement number of tabs - numberOfTabs--; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "End of Options"; - } - - // Otherwise check if opcode is EFI_IFR_INCONSISTENT_IF_OP 0x11 - else if(buffer[j] == EFI_IFR_INCONSISTENT_IF_OP) { - - // Create temp - EFI_IFR_INCONSISTENT temp; - - // Fill inconsistent - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.popup = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.flags = static_cast(buffer[j + 4]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display inconsistent - fout << "Inconsistent If:"; - - // Increment number of ifs - numberOfIfs++; - } - - // Otherwise check if opcode is EFI_IFR_EQ_ID_VAL_OP 0x12 - else if(buffer[j] == EFI_IFR_EQ_ID_VAL_OP) { - - // Create temp - EFI_IFR_EQ_ID_VAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.value = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']' << " equals 0x" << hex << uppercase << temp.value; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_EQ_ID_ID_OP 0x13 - else if(buffer[j] == EFI_IFR_EQ_ID_ID_OP) { - - // Create temp - EFI_IFR_EQ_ID_ID temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.primaryQuestionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.secondaryQuestionId = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.primaryQuestionId << '[' << dec << static_cast(temp.width) << ']' << " equals variable 0x" << hex << uppercase << temp.secondaryQuestionId; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_EQ_ID_LIST_OP 0x14 - else if(buffer[j] == EFI_IFR_EQ_ID_LIST_OP) { - - // Create temp - EFI_IFR_EQ_ID_LIST temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.listLength = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - - // Create list - uint32_t index = j + 7; - - for(uint8_t k = 0; k < temp.listLength; k++, index += 2) - temp.valueList.push_back(static_cast(static_cast(buffer[index]) + (static_cast(buffer[index + 1]) << 8))); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']' << " 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 << ')'; - } - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_AND_OP 0x15 - else if(buffer[j] == EFI_IFR_AND_OP) { - - // Create temp - EFI_IFR_AND temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "And"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_OR_OP 0x16 - else if(buffer[j] == EFI_IFR_OR_OP) { - - // Create temp - EFI_IFR_OR temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Or"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_NOT_OP 0x17 - else if(buffer[j] == EFI_IFR_NOT_OP) { - - // Create temp - EFI_IFR_NOT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Not"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_END_IF_OP 0x18 - else if(buffer[j] == EFI_IFR_END_IF_OP) { - - // Create temp - EFI_IFR_END_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Go through ifs - for(uint8_t k = 0; k < numberOfIfs; k++) { - - // Decrement number of tabs - numberOfTabs--; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t l = 0; l < numberOfTabs; l++) - fout << '\t'; - - // Display temp - fout << "End If"; - } - - // Clear number of ifs - numberOfIfs = 0; - } - - // Otherwise check if opcode is EFI_IFR_GRAYOUT_IF_OP 0x19 - else if(buffer[j] == EFI_IFR_GRAYOUT_IF_OP) { - - // Create temp - EFI_IFR_GRAYOUT temp; - - // Fill grayout - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.flags = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Grayout If:"; - - // Increment number of ifs - numberOfIfs++; - } - - // Otherwise check if opcode is EFI_IFR_DATE_OP 0x1A - else if(buffer[j] == EFI_IFR_DATE_OP) { - - // Create temp - EFI_IFR_DATE temp; - - // Fill year - temp.year.header.offset = j; - temp.year.header.opcode = buffer[j]; - temp.year.header.length = static_cast(buffer[j + 1]); - temp.year.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.year.width = static_cast(buffer[j + 4]); - temp.year.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.year.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.year.flags = static_cast(buffer[j + 9]); - temp.year.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.year.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.year.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.year.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.year.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Increment j - j += static_cast(buffer[j + 1]); - - // Fill month - temp.month.header.offset = j; - temp.month.header.opcode = buffer[j]; - temp.month.header.length = static_cast(buffer[j + 1]); - temp.month.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.month.width = static_cast(buffer[j + 4]); - temp.month.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.month.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.month.flags = static_cast(buffer[j + 9]); - temp.month.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.month.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.month.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.month.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.month.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Increment j - j += static_cast(buffer[j + 1]); - - // Fill day - temp.day.header.offset = j; - temp.day.header.opcode = buffer[j]; - temp.day.header.length = static_cast(buffer[j + 1]); - temp.day.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.day.width = static_cast(buffer[j + 4]); - temp.day.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.day.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.day.flags = static_cast(buffer[j + 9]); - temp.day.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.day.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.day.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.day.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.day.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.year.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Date: Day (" << dec << temp.day.minimum << '-' << temp.day.maximum << "), Month (" << temp.month.minimum << '-' << temp.month.maximum << "), Year (" << temp.year.minimum << '-' << temp.year.maximum << "), Variables: 0x" << hex << uppercase << temp.day.questionId << '[' << dec << static_cast(temp.day.width) << ']' << ", 0x" << hex << uppercase << temp.month.questionId << '[' << dec << static_cast(temp.month.width) << ']' << ", 0x" << hex << uppercase << temp.year.questionId << '[' << dec << static_cast(temp.year.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_TIME_OP 0x1B - else if(buffer[j] == EFI_IFR_TIME_OP) { - - // Create temp - EFI_IFR_TIME temp; - - // Fill hour - temp.hour.header.offset = j; - temp.hour.header.opcode = buffer[j]; - temp.hour.header.length = static_cast(buffer[j + 1]); - temp.hour.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.hour.width = static_cast(buffer[j + 4]); - temp.hour.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.hour.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.hour.flags = static_cast(buffer[j + 9]); - temp.hour.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.hour.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.hour.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.hour.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.hour.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Increment j - j += static_cast(buffer[j + 1]); - - // Fill minute - temp.minute.header.offset = j; - temp.minute.header.opcode = buffer[j]; - temp.minute.header.length = static_cast(buffer[j + 1]); - temp.minute.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.minute.width = static_cast(buffer[j + 4]); - temp.minute.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.minute.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.minute.flags = static_cast(buffer[j + 9]); - temp.minute.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.minute.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.minute.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.minute.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.minute.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Increment j - j += static_cast(buffer[j + 1]); - - // Fill second - temp.second.header.offset = j; - temp.second.header.opcode = buffer[j]; - temp.second.header.length = static_cast(buffer[j + 1]); - temp.second.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.second.width = static_cast(buffer[j + 4]); - temp.second.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.second.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.second.flags = static_cast(buffer[j + 9]); - temp.second.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.second.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); - temp.second.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.second.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - temp.second.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.hour.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Time: Hour (" << dec << temp.hour.minimum << '-' << temp.hour.maximum << "), Minute (" << temp.minute.minimum << '-' << temp.minute.maximum << "), Second (" << temp.second.minimum << '-' << temp.second.maximum << "), Variables: 0x" << hex << uppercase << temp.hour.questionId << '[' << dec << static_cast(temp.hour.width) << ']' << ", 0x" << hex << uppercase << temp.minute.questionId << '[' << dec << static_cast(temp.minute.width) << ']' << ", 0x" << hex << uppercase << temp.second.questionId << '[' << dec << static_cast(temp.second.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_STRING_OP 0x1C - else if(buffer[j] == EFI_IFR_STRING_OP) { - - // Create temp - EFI_IFR_STRING temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.width = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - temp.flags = static_cast(buffer[j + 9]); - temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.minimumSize = static_cast(buffer[j + 12]); - temp.maximumSize = static_cast(buffer[j + 13]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "String: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; - } - - // Otherwise check if opcode is EFI_IFR_LABEL_OP 0x1D - else if(buffer[j] == EFI_IFR_LABEL_OP) { - - // Create temp - EFI_IFR_LABEL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.labelId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Label: 0x" << hex << uppercase << temp.labelId; - } - - // Otherwise check if opcode is EFI_IFR_SAVE_DEFAULTS_OP 0x1E - else if(buffer[j] == EFI_IFR_SAVE_DEFAULTS_OP) { - - // Create temp - EFI_IFR_SAVE_DEFAULTS temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.flags = static_cast(buffer[j + 8]); - temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Save Defaults: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; - } - - // Otherwise check if opcode is EFI_IFR_RESTORE_DEFAULTS_OP 0x1F - else if(buffer[j] == EFI_IFR_RESTORE_DEFAULTS_OP) { - - // Create temp - EFI_IFR_RESTORE_DEFAULTS temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.flags = static_cast(buffer[j + 8]); - temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Restore Defaults: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; - } - - // Otherwise check if opcode is EFI_IFR_BANNER_OP 0x20 - else if(buffer[j] == EFI_IFR_BANNER_OP) { - - // Create temp - EFI_IFR_BANNER temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.titleString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.lineNumber = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.alignment = static_cast(buffer[j + 6]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Banner: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - } - - // Otherwise check if opcode is EFI_IFR_INVENTORY_OP 0x21 - else if(buffer[j] == EFI_IFR_INVENTORY_OP) { - - // Create temp - EFI_IFR_INVENTORY temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.helpString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.primaryTextString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.secondaryTextString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Inventory: " << strings[temp.primaryTextString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - } - - // Otherwise check if opcode is EFI_IFR_EQ_VAR_VAL_OP 0x22 - else if(buffer[j] == EFI_IFR_EQ_VAR_VAL_OP) { - - // Create temp - EFI_IFR_EQ_VAR_VAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.variableId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.value = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.variableId << " equals 0x" << temp.value; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_ORDERED_LIST_OP 0x23 - else if(buffer[j] == EFI_IFR_ORDERED_LIST_OP) { - - // Create temp - EFI_IFR_ORDERED_LIST temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.maximumEntries = static_cast(buffer[j + 4]); - temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Ordered List: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId; - } - - // Otherwise check if opcode is EFI_IFR_VARSTORE_OP 0x24 - else if(buffer[j] == EFI_IFR_VARSTORE_OP) { - - // Create temp - EFI_IFR_VARSTORE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.varId = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - temp.size = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable Store: 0x" << hex << uppercase << temp.varId; - } - - // Otherwise check if opcode is EFI_IFR_VARSTORE_SELECT_OP 0x25 - else if(buffer[j] == EFI_IFR_VARSTORE_SELECT_OP) { - - // Create temp - EFI_IFR_VARSTORE_SELECT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.varId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable Store Select: 0x" << hex << uppercase << temp.varId; - } - - // Otherwise check if opcode is EFI_IFR_VARSTORE_SELECT_PAIR_OP 0x26 - else if(buffer[j] == EFI_IFR_VARSTORE_SELECT_PAIR_OP) { - - // Create temp - EFI_IFR_VARSTORE_SELECT_PAIR temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - temp.primaryVarId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.secondaryVarId = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable Store Select Pair: 0x" << hex << uppercase << temp.primaryVarId << "and 0x" << temp.secondaryVarId; - } - - // Otherwise check if opcode is EFI_IFR_TRUE_OP 0x27 - else if(buffer[j] == EFI_IFR_TRUE_OP) { - - // Create temp - EFI_IFR_TRUE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "True"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_FALSE_OP 0x28 - else if(buffer[j] == EFI_IFR_FALSE_OP) { - - // Create temp - EFI_IFR_FALSE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "False"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_GT_OP 0x29 - else if(buffer[j] == EFI_IFR_GT_OP) { - - // Create temp - EFI_IFR_GT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "GT"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_GE_OP 0x2A - else if(buffer[j] == EFI_IFR_GE_OP) { - - // Create temp - EFI_IFR_GE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "GE"; - - // Check if there isn't a following conditional statement - if(endEFICondition(buffer, j)) - - // Increment number of tabs - numberOfTabs++; - } - - // Otherwise check if opcode is EFI_IFR_OEM_DEFINED_OP 0x2B - else if(buffer[j] == EFI_IFR_OEM_DEFINED_OP) { - - // Display offset - fout << "0x" << hex << uppercase << j << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "OEM Defined:"; - } - - // Otherwise check if opcode is EFI_IFR_OEM_OP 0xFE - else if(buffer[j] == EFI_IFR_OEM_OP) { - - // Display offset - fout << "0x" << hex << uppercase << j << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "OEM:"; - } - - // Otherwise check if opcode is EFI_IFR_NV_ACCESS_COMMAND 0xFF - else if(buffer[j] == EFI_IFR_NV_ACCESS_COMMAND) { - - // Display offset - fout << "0x" << hex << uppercase << j << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "NV Access Command:"; - } - - // Display code - fout << " {"; - for(int k = 0; k < static_cast(buffer[j + 1]); k++) { - fout << hex << uppercase << setw(2) << setfill('0') << static_cast(static_cast(buffer[j + k])); - if(k != static_cast(buffer[j + 1]) - 1) - fout << ' '; - } - fout << '}' << endl; - } - - // Close file - fout.close(); -} - -bool endEFICondition(const string &buffer, uint32_t j) { - - // Return if following opcode isn't a condition - return buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_VAL_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_ID_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_LIST_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_VAR_VAL_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_AND_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_OR_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_NOT_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_TRUE_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_FALSE_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_GT_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_GE_OP; -} +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +#include "EFI.h" + + +// Supporting function implementation +void getEFIStringPackages(vector &stringPackages, const string &buffer) { + + // Initialize variables + EFI_IFR_STRING_PACK tempStringPackage; + + // Go through buffer + for (unsigned int i = 0; i < buffer.size() - 9; i++) + + // Check if string package was found + if ((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x02' && buffer[i + 5] == '\x00' && (buffer[i + 6] != '\x00' || buffer[i + 7] != '\x00' || buffer[i + 8] != '\x00' || buffer[i + 9] != '\x00') && i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] >= 'a' && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] <= 'z' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 4] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 5] == '\x00') { + + // Set temp string package + tempStringPackage.header.offset = i; + + tempStringPackage.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24)); + + tempStringPackage.header.type = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8)); + + for (uint32_t j = i + static_cast(static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24)); buffer[j] != '\x00'; j += 2) + tempStringPackage.language.push_back(buffer[j]); + + tempStringPackage.numberOfStrings = static_cast(static_cast(buffer[i + 14]) + (static_cast(buffer[i + 15]) << 8) + (static_cast(buffer[i + 16]) << 16) + (static_cast(buffer[i + 17]) << 24)); + + tempStringPackage.attributes = static_cast(static_cast(buffer[i + 18]) + (static_cast(buffer[i + 19]) << 8) + (static_cast(buffer[i + 20]) << 16) + (static_cast(buffer[i + 21]) << 24)); + + // Add string package to list + stringPackages.push_back(tempStringPackage); + + // Clear temp string package + tempStringPackage.language.clear(); + } +} + +void displayEFIStringPackages(const vector &stringPackages) { + + // Display string packages info + cout << "String Packages Information:" << endl; + + // Go through string packages + for (unsigned int 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 << "\t\tNumber of strings: " << dec << stringPackages[i].numberOfStrings << hex << uppercase << " (0x" << stringPackages[i].numberOfStrings << ')' << endl; + cout << "\t\tAttributes: " << dec << stringPackages[i].attributes << hex << uppercase << " (0x" << stringPackages[i].attributes << ')' << endl; + } + + cout << endl; +} + +void getEFIStrings(vector &stringPackages, vector &strings, const string &buffer) { + + // Initialize variables + int index; + string temp; + + // Go through string packages + for (unsigned int i = 0; i < stringPackages.size(); i++) { + + // Check if language isn't english + if (stringPackages[i].language != "eng") + + // Continue + continue; + + // Set structure offset + stringPackages[i].structureOffset = strings.size(); + + // Set index + index = stringPackages[i].header.offset + 22; + + // Go through strings + for (uint32_t j = 0; j < stringPackages[i].numberOfStrings; j++) { + + // Fill string + for (uint32_t k = stringPackages[i].header.offset + static_cast(static_cast(buffer[index]) + (static_cast(buffer[index + 1]) << 8) + (static_cast(buffer[index + 2]) << 16) + (static_cast(buffer[index + 3]) << 24)); buffer[k] != '\x00'; k += 2) + temp.push_back(buffer[k]); + + // Add string to list + strings.push_back(temp); + + // Clear temp + temp.clear(); + + // Increment index + index += 4; + } + } + + // Go through strings + for (unsigned int i = 0; i < strings.size(); i++) { + + // Change carriage return characters to spaces + for (unsigned int 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 (unsigned int 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 displayEFIStrings(const vector &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 getEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings) { + + // Initialize variables + EFI_IFR_FORM_SET_PACK tempFormSet; + vector stringCandidates; + uint32_t chosenCandidate; + + // Go through string packages + for (unsigned int i = 0; i < stringPackages.size(); i++) { + + // Check if language isn't english + if (stringPackages[i].language != "eng") + + // Continue + continue; + + // Get string candidate + stringCandidates.push_back(i); + } + + // Go through buffer + for (uint32_t i = 0; i < buffer.size() - 5; i++) + + // Check if form set was found + if ((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x03' && buffer[i + 5] == '\x00' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) - 1] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) - 2] == '\x0D') { + + // Get chosen candidate for form set's string package + chosenCandidate = stringCandidates[0]; + for (unsigned int j = 1; j < stringCandidates.size(); j++) + if (abs(static_cast(stringPackages[j].header.offset - i)) < abs(static_cast(stringPackages[chosenCandidate].header.offset - i))) + chosenCandidate = j; + + // Set temp form set + tempFormSet.header.offset = i; + tempFormSet.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24)); + tempFormSet.header.type = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8)); + tempFormSet.titleString = static_cast(static_cast(buffer[i + 24]) + (static_cast(buffer[i + 25]) << 8)); + tempFormSet.usingStringPackage = stringCandidates[chosenCandidate]; + tempFormSet.title = strings[tempFormSet.titleString + stringPackages[tempFormSet.usingStringPackage].structureOffset]; + + // Add temp form set to list + formSets.push_back(tempFormSet); + } +} + +void displayEFIFormSets(const vector &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; +} + +void generateEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings) { + + // Initialize variables + uint8_t numberOfTabs = 0; + uint8_t numberOfIfs = 0; + unsigned char highNibble, lowNibble; + ofstream fout(outputFile.c_str()); + + // Display protocol + for (uint8_t i = 0; i < 32; i++) + fout << ' '; + fout << "EFI Protocol Detected" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << endl << endl << endl; + + // Display string packages info + for (uint8_t i = 0; i < 32; i++) + fout << ' '; + fout << "String Packages" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << endl; + fout << "Offset:\t\tLanguage:" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << 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 << static_cast(i) << ')' << endl; + } + fout << endl << endl; + + // Display form sets info + for (uint8_t i = 0; i < 35; i++) + fout << ' '; + fout << "Form Sets" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << endl; + fout << "Offset:\t\tTitle:" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << 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 internal forms representation + for (uint8_t i = 0; i < 25; i++) + fout << ' '; + fout << "Internal Forms Representation" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << endl; + fout << "Offset:\t\tInstruction:" << endl; + for (uint8_t i = 0; i < 80; i++) + fout << '-'; + fout << endl; + + // Go through form sets + for (uint32_t i = 0; i < formSets.size(); i++) + + // Go through all the form set's operations + for (uint32_t j = formSets[i].header.offset + 6; j < formSets[i].header.offset + formSets[i].header.length; j += static_cast(buffer[j + 1])) { + + // Check if opcode is EFI_IFR_FORM_OP 0x01 + if (buffer[j] == EFI_IFR_FORM_OP) { + + // Create temp + EFI_IFR_FORM temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.titleString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Form: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_SUBTITLE_OP 0x02 + else if (buffer[j] == EFI_IFR_SUBTITLE_OP) { + + // Create temp + EFI_IFR_SUBTITLE temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.subtitleString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Subtitle: " << strings[temp.subtitleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; + } + + // Otherwise check if opcode is EFI_IFR_TEXT_OP 0x03 + else if (buffer[j] == EFI_IFR_TEXT_OP) { + + // Create temp + EFI_IFR_TEXT temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.helpString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.primaryTextString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.secondaryTextString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); + temp.flags = static_cast(buffer[j + 8]); + temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Text: " << strings[temp.primaryTextString + stringPackages[formSets[i].usingStringPackage].structureOffset]; + } + + // Otherwise chec if opcode is EFI_IFR_GRAPHIC_OP 0x04 + else if (buffer[j] == EFI_IFR_GRAPHIC_OP) { + + // Display offset + fout << "0x" << hex << uppercase << j << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Graphic:"; + } + + // Otherwise check if opcode is EFI_IFR_ONE_OF_OP 0x05 + else if (buffer[j] == EFI_IFR_ONE_OF_OP) { + + // Create temp + EFI_IFR_ONE_OF temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Setting: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_CHECKBOX_OP 0x06 + else if (buffer[j] == EFI_IFR_CHECKBOX_OP) { + + // Create temp + EFI_IFR_CHECKBOX temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.flags = static_cast(buffer[j + 9]); + temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Checkbox: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_NUMERIC_OP 0x07 + else if (buffer[j] == EFI_IFR_NUMERIC_OP) { + + // Create temp + EFI_IFR_NUMERIC temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.flags = static_cast(buffer[j + 9]); + temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.maximum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.minimum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.step = static_cast(static_cast(buffer[j + 16]) + (static_cast(buffer[j + 17]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Numeric: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << " (" << dec << temp.minimum << '-' << temp.maximum << "), Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_PASSWORD_OP 0x08 + else if (buffer[j] == EFI_IFR_PASSWORD_OP) { + + // Create temp + EFI_IFR_PASSWORD temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.flags = static_cast(buffer[j + 9]); + temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.minimumSize = static_cast(buffer[j + 12]); + temp.maximumSize = static_cast(buffer[j + 13]); + temp.encoding = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Password: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_ONE_OF_OPTION_OP 0x09 + else if (buffer[j] == EFI_IFR_ONE_OF_OPTION_OP) { + + // Create temp + EFI_IFR_ONE_OF_OPTION temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.optionString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.value = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.flags = static_cast(buffer[j + 6]); + temp.key = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Option: " << strings[temp.optionString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Value: 0x" << hex << uppercase << temp.value; + } + + // Otherwise check if opcode is EFI_IFR_SUPPRESS_IF_OP 0x0A + else if (buffer[j] == EFI_IFR_SUPPRESS_IF_OP) { + + // Create temp + EFI_IFR_SUPPRESS temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.flags = static_cast(buffer[j + 2]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Suppress If:"; + + // Increment number of ifs + numberOfIfs++; + } + + // Otherwise check if opcode is EFI_IFR_END_FORM_OP 0x0B + else if (buffer[j] == EFI_IFR_END_FORM_OP) { + + // Create temp + EFI_IFR_END_FORM temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Decrement number of tabs + numberOfTabs--; + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "End Form"; + } + + // Otherwise check if opcode is EFI_IFR_HIDDEN_OP 0x0C + else if (buffer[j] == EFI_IFR_HIDDEN_OP) { + + // Create temp + EFI_IFR_HIDDEN temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.value = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.key = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Hidden:"; + } + + // Otherwise check if opcode is EFI_IFR_END_FORM_SET_OP 0x0D + else if (buffer[j] == EFI_IFR_END_FORM_SET_OP) { + + // Create temp + EFI_IFR_END_FORM_SET temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Decrement number of tabs + numberOfTabs--; + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "End Form Set"; + } + + // Otherwise check if opcode is EFI_IFR_FORM_SET_OP 0x0E + else if (buffer[j] == EFI_IFR_FORM_SET_OP) { + + // Create temp + EFI_IFR_FORM_SET temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + for (uint32_t k = j + 2; k < j + 6; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(0, 1, lowNibble); + temp.guid.insert(0, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 6; k < j + 8; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(9, 1, lowNibble); + temp.guid.insert(9, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 8; k < j + 10; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(14, 1, lowNibble); + temp.guid.insert(14, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 10; k < j + 12; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.push_back(highNibble); + temp.guid.push_back(lowNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 12; k < j + 18; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.push_back(highNibble); + temp.guid.push_back(lowNibble); + } + temp.titleString = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); + temp.callbackHandle = static_cast(static_cast(buffer[j + 22]) + (static_cast(buffer[j + 23]) << 8) + (static_cast(buffer[j + 24]) << 16) + (static_cast(buffer[j + 25]) << 24) + (static_cast(static_cast(buffer[j + 26])) << 32) + (static_cast(static_cast(buffer[j + 27])) << 40) + (static_cast(static_cast(buffer[j + 28])) << 48) + (static_cast(static_cast(buffer[j + 29])) << 56)); + temp.mainClass = static_cast(static_cast(buffer[j + 30]) + (static_cast(buffer[j + 31]) << 8)); + temp.subClass = static_cast(static_cast(buffer[j + 32]) + (static_cast(buffer[j + 33]) << 8)); + temp.nvDataSize = static_cast(static_cast(buffer[j + 34]) + (static_cast(buffer[j + 25]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Form Set: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_REF_OP 0x0F + else if (buffer[j] == EFI_IFR_REF_OP) { + + // Create temp + EFI_IFR_REF temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); + temp.flags = static_cast(static_cast(buffer[j + 8])); + temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Selectable: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; + } + + // Otherwise check if opcode is EFI_IFR_END_OP 0x10 + else if (buffer[j] == EFI_IFR_END_ONE_OF_OP) { + + // Create temp + EFI_IFR_END_ONE_OF temp; + + // Fill end one of + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Decrement number of tabs + numberOfTabs--; + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "End of Options"; + } + + // Otherwise check if opcode is EFI_IFR_INCONSISTENT_IF_OP 0x11 + else if (buffer[j] == EFI_IFR_INCONSISTENT_IF_OP) { + + // Create temp + EFI_IFR_INCONSISTENT temp; + + // Fill inconsistent + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.popup = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.flags = static_cast(buffer[j + 4]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display inconsistent + fout << "Inconsistent If:"; + + // Increment number of ifs + numberOfIfs++; + } + + // Otherwise check if opcode is EFI_IFR_EQ_ID_VAL_OP 0x12 + else if (buffer[j] == EFI_IFR_EQ_ID_VAL_OP) { + + // Create temp + EFI_IFR_EQ_ID_VAL temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.value = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']' << " equals 0x" << hex << uppercase << temp.value; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_EQ_ID_ID_OP 0x13 + else if (buffer[j] == EFI_IFR_EQ_ID_ID_OP) { + + // Create temp + EFI_IFR_EQ_ID_ID temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.primaryQuestionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.secondaryQuestionId = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable 0x" << hex << uppercase << temp.primaryQuestionId << '[' << dec << static_cast(temp.width) << ']' << " equals variable 0x" << hex << uppercase << temp.secondaryQuestionId; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_EQ_ID_LIST_OP 0x14 + else if (buffer[j] == EFI_IFR_EQ_ID_LIST_OP) { + + // Create temp + EFI_IFR_EQ_ID_LIST temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.listLength = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + + // Create list + uint32_t index = j + 7; + + for (uint8_t k = 0; k < temp.listLength; k++, index += 2) + temp.valueList.push_back(static_cast(static_cast(buffer[index]) + (static_cast(buffer[index + 1]) << 8))); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']' << " 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 << ')'; + } + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_AND_OP 0x15 + else if (buffer[j] == EFI_IFR_AND_OP) { + + // Create temp + EFI_IFR_AND temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "And"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_OR_OP 0x16 + else if (buffer[j] == EFI_IFR_OR_OP) { + + // Create temp + EFI_IFR_OR temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Or"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_NOT_OP 0x17 + else if (buffer[j] == EFI_IFR_NOT_OP) { + + // Create temp + EFI_IFR_NOT temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Not"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_END_IF_OP 0x18 + else if (buffer[j] == EFI_IFR_END_IF_OP) { + + // Create temp + EFI_IFR_END_IF temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Go through ifs + for (uint8_t k = 0; k < numberOfIfs; k++) { + + // Decrement number of tabs + numberOfTabs--; + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t l = 0; l < numberOfTabs; l++) + fout << '\t'; + + // Display temp + fout << "End If"; + } + + // Clear number of ifs + numberOfIfs = 0; + } + + // Otherwise check if opcode is EFI_IFR_GRAYOUT_IF_OP 0x19 + else if (buffer[j] == EFI_IFR_GRAYOUT_IF_OP) { + + // Create temp + EFI_IFR_GRAYOUT temp; + + // Fill grayout + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.flags = static_cast(buffer[j + 2]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Grayout If:"; + + // Increment number of ifs + numberOfIfs++; + } + + // Otherwise check if opcode is EFI_IFR_DATE_OP 0x1A + else if (buffer[j] == EFI_IFR_DATE_OP) { + + // Create temp + EFI_IFR_DATE temp; + + // Fill year + temp.year.header.offset = j; + temp.year.header.opcode = buffer[j]; + temp.year.header.length = static_cast(buffer[j + 1]); + temp.year.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.year.width = static_cast(buffer[j + 4]); + temp.year.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.year.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.year.flags = static_cast(buffer[j + 9]); + temp.year.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.year.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.year.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.year.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.year.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Increment j + j += static_cast(buffer[j + 1]); + + // Fill month + temp.month.header.offset = j; + temp.month.header.opcode = buffer[j]; + temp.month.header.length = static_cast(buffer[j + 1]); + temp.month.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.month.width = static_cast(buffer[j + 4]); + temp.month.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.month.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.month.flags = static_cast(buffer[j + 9]); + temp.month.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.month.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.month.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.month.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.month.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Increment j + j += static_cast(buffer[j + 1]); + + // Fill day + temp.day.header.offset = j; + temp.day.header.opcode = buffer[j]; + temp.day.header.length = static_cast(buffer[j + 1]); + temp.day.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.day.width = static_cast(buffer[j + 4]); + temp.day.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.day.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.day.flags = static_cast(buffer[j + 9]); + temp.day.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.day.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.day.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.day.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.day.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.year.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Date: Day (" << dec << temp.day.minimum << '-' << temp.day.maximum << "), Month (" << temp.month.minimum << '-' << temp.month.maximum << "), Year (" << temp.year.minimum << '-' << temp.year.maximum << "), Variables: 0x" << hex << uppercase << temp.day.questionId << '[' << dec << static_cast(temp.day.width) << ']' << ", 0x" << hex << uppercase << temp.month.questionId << '[' << dec << static_cast(temp.month.width) << ']' << ", 0x" << hex << uppercase << temp.year.questionId << '[' << dec << static_cast(temp.year.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_TIME_OP 0x1B + else if (buffer[j] == EFI_IFR_TIME_OP) { + + // Create temp + EFI_IFR_TIME temp; + + // Fill hour + temp.hour.header.offset = j; + temp.hour.header.opcode = buffer[j]; + temp.hour.header.length = static_cast(buffer[j + 1]); + temp.hour.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.hour.width = static_cast(buffer[j + 4]); + temp.hour.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.hour.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.hour.flags = static_cast(buffer[j + 9]); + temp.hour.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.hour.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.hour.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.hour.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.hour.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Increment j + j += static_cast(buffer[j + 1]); + + // Fill minute + temp.minute.header.offset = j; + temp.minute.header.opcode = buffer[j]; + temp.minute.header.length = static_cast(buffer[j + 1]); + temp.minute.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.minute.width = static_cast(buffer[j + 4]); + temp.minute.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.minute.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.minute.flags = static_cast(buffer[j + 9]); + temp.minute.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.minute.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.minute.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.minute.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.minute.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Increment j + j += static_cast(buffer[j + 1]); + + // Fill second + temp.second.header.offset = j; + temp.second.header.opcode = buffer[j]; + temp.second.header.length = static_cast(buffer[j + 1]); + temp.second.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.second.width = static_cast(buffer[j + 4]); + temp.second.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.second.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.second.flags = static_cast(buffer[j + 9]); + temp.second.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.second.minimum = static_cast(static_cast(buffer[j + 12]) + (static_cast(buffer[j + 13]) << 8)); + temp.second.maximum = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); + temp.second.step = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); + temp.second.defaultValue = static_cast(static_cast(buffer[j + 17]) + (static_cast(buffer[j + 18]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.hour.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Time: Hour (" << dec << temp.hour.minimum << '-' << temp.hour.maximum << "), Minute (" << temp.minute.minimum << '-' << temp.minute.maximum << "), Second (" << temp.second.minimum << '-' << temp.second.maximum << "), Variables: 0x" << hex << uppercase << temp.hour.questionId << '[' << dec << static_cast(temp.hour.width) << ']' << ", 0x" << hex << uppercase << temp.minute.questionId << '[' << dec << static_cast(temp.minute.width) << ']' << ", 0x" << hex << uppercase << temp.second.questionId << '[' << dec << static_cast(temp.second.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_STRING_OP 0x1C + else if (buffer[j] == EFI_IFR_STRING_OP) { + + // Create temp + EFI_IFR_STRING temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.width = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + temp.flags = static_cast(buffer[j + 9]); + temp.key = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); + temp.minimumSize = static_cast(buffer[j + 12]); + temp.maximumSize = static_cast(buffer[j + 13]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "String: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId << '[' << dec << static_cast(temp.width) << ']'; + } + + // Otherwise check if opcode is EFI_IFR_LABEL_OP 0x1D + else if (buffer[j] == EFI_IFR_LABEL_OP) { + + // Create temp + EFI_IFR_LABEL temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.labelId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Label: 0x" << hex << uppercase << temp.labelId; + } + + // Otherwise check if opcode is EFI_IFR_SAVE_DEFAULTS_OP 0x1E + else if (buffer[j] == EFI_IFR_SAVE_DEFAULTS_OP) { + + // Create temp + EFI_IFR_SAVE_DEFAULTS temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); + temp.flags = static_cast(buffer[j + 8]); + temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Save Defaults: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; + } + + // Otherwise check if opcode is EFI_IFR_RESTORE_DEFAULTS_OP 0x1F + else if (buffer[j] == EFI_IFR_RESTORE_DEFAULTS_OP) { + + // Create temp + EFI_IFR_RESTORE_DEFAULTS temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.promptString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); + temp.flags = static_cast(buffer[j + 8]); + temp.key = static_cast(static_cast(buffer[j + 9]) + (static_cast(buffer[j + 10]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Restore Defaults: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; + } + + // Otherwise check if opcode is EFI_IFR_BANNER_OP 0x20 + else if (buffer[j] == EFI_IFR_BANNER_OP) { + + // Create temp + EFI_IFR_BANNER temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.titleString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.lineNumber = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.alignment = static_cast(buffer[j + 6]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Banner: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; + } + + // Otherwise check if opcode is EFI_IFR_INVENTORY_OP 0x21 + else if (buffer[j] == EFI_IFR_INVENTORY_OP) { + + // Create temp + EFI_IFR_INVENTORY temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.helpString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.primaryTextString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + temp.secondaryTextString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Inventory: " << strings[temp.primaryTextString + stringPackages[formSets[i].usingStringPackage].structureOffset]; + } + + // Otherwise check if opcode is EFI_IFR_EQ_VAR_VAL_OP 0x22 + else if (buffer[j] == EFI_IFR_EQ_VAR_VAL_OP) { + + // Create temp + EFI_IFR_EQ_VAR_VAL temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.variableId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.value = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable 0x" << hex << uppercase << temp.variableId << " equals 0x" << temp.value; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_ORDERED_LIST_OP 0x23 + else if (buffer[j] == EFI_IFR_ORDERED_LIST_OP) { + + // Create temp + EFI_IFR_ORDERED_LIST temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.maximumEntries = static_cast(buffer[j + 4]); + temp.promptString = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); + temp.helpString = static_cast(static_cast(buffer[j + 7]) + (static_cast(buffer[j + 8]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Ordered List: " << strings[temp.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.questionId; + } + + // Otherwise check if opcode is EFI_IFR_VARSTORE_OP 0x24 + else if (buffer[j] == EFI_IFR_VARSTORE_OP) { + + // Create temp + EFI_IFR_VARSTORE temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + for (uint32_t k = j + 2; k < j + 6; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(0, 1, lowNibble); + temp.guid.insert(0, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 6; k < j + 8; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(9, 1, lowNibble); + temp.guid.insert(9, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 8; k < j + 10; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.insert(14, 1, lowNibble); + temp.guid.insert(14, 1, highNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 10; k < j + 12; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.push_back(highNibble); + temp.guid.push_back(lowNibble); + } + temp.guid.push_back('-'); + for (uint32_t k = j + 12; k < j + 18; k++) { + highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; + lowNibble = (buffer[k] & 0x0F) + '0'; + if (highNibble > 0x39 && highNibble < 0x41) + highNibble += 0x07; + if (lowNibble > 0x39 && lowNibble < 0x41) + lowNibble += 0x07; + temp.guid.push_back(highNibble); + temp.guid.push_back(lowNibble); + } + temp.varId = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); + temp.size = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); + strncpy((char *)temp.name, (char *)&buffer[j + 22], 233); // Name can start at 22, and will be header_length - 22 long. + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + //fout << "Variable Store: 0x" << hex << uppercase << temp.varId; + fout << "Var Store: "; + //Display additional information: GUID:Name[] + fout << "[0x" << hex << uppercase << setw(4) << setfill('0') << temp.varId << "]"; + fout << "[" << temp.guid << "]"; + fout << "[" << dec << setw(3) << temp.size << "]"; + fout << "[" << temp.name << "]"; + } + + // Otherwise check if opcode is EFI_IFR_VARSTORE_SELECT_OP 0x25 + else if (buffer[j] == EFI_IFR_VARSTORE_SELECT_OP) { + + // Create temp + EFI_IFR_VARSTORE_SELECT temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.varId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable Store Select: 0x" << hex << uppercase << temp.varId; + } + + // Otherwise check if opcode is EFI_IFR_VARSTORE_SELECT_PAIR_OP 0x26 + else if (buffer[j] == EFI_IFR_VARSTORE_SELECT_PAIR_OP) { + + // Create temp + EFI_IFR_VARSTORE_SELECT_PAIR temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + temp.primaryVarId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); + temp.secondaryVarId = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "Variable Store Select Pair: 0x" << hex << uppercase << temp.primaryVarId << "and 0x" << temp.secondaryVarId; + } + + // Otherwise check if opcode is EFI_IFR_TRUE_OP 0x27 + else if (buffer[j] == EFI_IFR_TRUE_OP) { + + // Create temp + EFI_IFR_TRUE temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "True"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_FALSE_OP 0x28 + else if (buffer[j] == EFI_IFR_FALSE_OP) { + + // Create temp + EFI_IFR_FALSE temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "False"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_GT_OP 0x29 + else if (buffer[j] == EFI_IFR_GT_OP) { + + // Create temp + EFI_IFR_GT temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "GT"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_GE_OP 0x2A + else if (buffer[j] == EFI_IFR_GE_OP) { + + // Create temp + EFI_IFR_GE temp; + + // Fill temp + temp.header.offset = j; + temp.header.opcode = buffer[j]; + temp.header.length = static_cast(buffer[j + 1]); + + // Display offset + fout << "0x" << hex << uppercase << temp.header.offset << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "GE"; + + // Check if there isn't a following conditional statement + if (endEFICondition(buffer, j)) + + // Increment number of tabs + numberOfTabs++; + } + + // Otherwise check if opcode is EFI_IFR_OEM_DEFINED_OP 0x2B + else if (buffer[j] == EFI_IFR_OEM_DEFINED_OP) { + + // Display offset + fout << "0x" << hex << uppercase << j << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "OEM Defined:"; + } + + // Otherwise check if opcode is EFI_IFR_OEM_OP 0xFE + else if (buffer[j] == EFI_IFR_OEM_OP) { + + // Display offset + fout << "0x" << hex << uppercase << j << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "OEM:"; + } + + // Otherwise check if opcode is EFI_IFR_NV_ACCESS_COMMAND 0xFF + else if (buffer[j] == EFI_IFR_NV_ACCESS_COMMAND) { + + // Display offset + fout << "0x" << hex << uppercase << j << ' '; + + // Display tabs + for (uint8_t k = 0; k < numberOfTabs; k++) + fout << '\t'; + + // Display temp + fout << "NV Access Command:"; + } + + // Display code + fout << " {"; + for (int k = 0; k < static_cast(buffer[j + 1]); k++) { + fout << hex << uppercase << setw(2) << setfill('0') << static_cast(static_cast(buffer[j + k])); + if (k != static_cast(buffer[j + 1]) - 1) + fout << ' '; + } + fout << '}' << endl; + } + + // Close file + fout.close(); +} + +bool endEFICondition(const string &buffer, uint32_t j) { + + // Return if following opcode isn't a condition + return buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_VAL_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_ID_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_ID_LIST_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_EQ_VAR_VAL_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_AND_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_OR_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_NOT_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_TRUE_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_FALSE_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_GT_OP && buffer[j + static_cast(buffer[j + 1])] != EFI_IFR_GE_OP; +} diff --git a/EFI.h b/EFI.h old mode 100755 new mode 100644 index 8857db8..8e585c0 --- a/EFI.h +++ b/EFI.h @@ -1,432 +1,433 @@ -// Header gaurd -#ifndef EFI_H -#define EFI_H - - -// Header files -#include -#include -#include - -using namespace std; - - -// Gobal definitions -#define EFI_IFR_FORM_OP '\x01' -#define EFI_IFR_SUBTITLE_OP '\x02' -#define EFI_IFR_TEXT_OP '\x03' -#define EFI_IFR_GRAPHIC_OP '\x04' -#define EFI_IFR_ONE_OF_OP '\x05' -#define EFI_IFR_CHECKBOX_OP '\x06' -#define EFI_IFR_NUMERIC_OP '\x07' -#define EFI_IFR_PASSWORD_OP '\x08' -#define EFI_IFR_ONE_OF_OPTION_OP '\x09' -#define EFI_IFR_SUPPRESS_IF_OP '\x0A' -#define EFI_IFR_END_FORM_OP '\x0B' -#define EFI_IFR_HIDDEN_OP '\x0C' -#define EFI_IFR_END_FORM_SET_OP '\x0D' -#define EFI_IFR_FORM_SET_OP '\x0E' -#define EFI_IFR_REF_OP '\x0F' -#define EFI_IFR_END_ONE_OF_OP '\x10' -#define EFI_IFR_END_OP EFI_IFR_END_ONE_OF_OP -#define EFI_IFR_INCONSISTENT_IF_OP '\x11' -#define EFI_IFR_EQ_ID_VAL_OP '\x12' -#define EFI_IFR_EQ_ID_ID_OP '\x13' -#define EFI_IFR_EQ_ID_LIST_OP '\x14' -#define EFI_IFR_AND_OP '\x15' -#define EFI_IFR_OR_OP '\x16' -#define EFI_IFR_NOT_OP '\x17' -#define EFI_IFR_END_IF_OP '\x18' -#define EFI_IFR_GRAYOUT_IF_OP '\x19' -#define EFI_IFR_DATE_OP '\x1A' -#define EFI_IFR_TIME_OP '\x1B' -#define EFI_IFR_STRING_OP '\x1C' -#define EFI_IFR_LABEL_OP '\x1D' -#define EFI_IFR_SAVE_DEFAULTS_OP '\x1E' -#define EFI_IFR_RESTORE_DEFAULTS_OP '\x1F' -#define EFI_IFR_BANNER_OP '\x20' -#define EFI_IFR_INVENTORY_OP '\x21' -#define EFI_IFR_EQ_VAR_VAL_OP '\x22' -#define EFI_IFR_ORDERED_LIST_OP '\x23' -#define EFI_IFR_VARSTORE_OP '\x24' -#define EFI_IFR_VARSTORE_SELECT_OP '\x25' -#define EFI_IFR_VARSTORE_SELECT_PAIR_OP '\x26' -#define EFI_IFR_TRUE_OP '\x27' -#define EFI_IFR_FALSE_OP '\x28' -#define EFI_IFR_GT_OP '\x29' -#define EFI_IFR_GE_OP '\x2A' -#define EFI_IFR_OEM_DEFINED_OP '\x2B' -#define EFI_IFR_LAST_OPCODE EFI_IFR_OEM_DEFINED_OP -#define EFI_IFR_OEM_OP '\xFE' -#define EFI_IFR_NV_ACCESS_COMMAND '\xFF' - - -// Classes/structs -struct EFI_HII_PACK_HEADER { - uint32_t offset; - uint32_t length; - uint16_t type; -}; - -struct EFI_IFR_STRING_PACK { - EFI_HII_PACK_HEADER header; - uint32_t numberOfStrings; - uint32_t attributes; - string language; - uint32_t structureOffset; -}; - -struct EFI_IFR_FORM_SET_PACK { - EFI_HII_PACK_HEADER header; - uint16_t titleString; - uint32_t usingStringPackage; - string title; -}; - -struct EFI_IFR_OP_HEADER { - uint32_t offset; - uint8_t opcode; - uint8_t length; -}; - -struct EFI_IFR_FORM_SET { - EFI_IFR_OP_HEADER header; - string guid; - uint16_t titleString; - uint16_t helpString; - uint64_t callbackHandle; - uint16_t mainClass; - uint16_t subClass; - uint16_t nvDataSize; -}; - -struct EFI_IFR_FORM { - EFI_IFR_OP_HEADER header; - uint16_t formId; - uint16_t titleString; -}; - -struct EFI_IFR_LABEL { - EFI_IFR_OP_HEADER header; - uint16_t labelId; -}; - -struct EFI_IFR_SUBTITLE { - EFI_IFR_OP_HEADER header; - uint16_t subtitleString; -}; - -struct EFI_IFR_TEXT { - EFI_IFR_OP_HEADER header; - uint16_t helpString; - uint16_t primaryTextString; - uint16_t secondaryTextString; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_REF { - EFI_IFR_OP_HEADER header; - uint16_t formId; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_END_FORM { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_END_FORM_SET { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_ONE_OF { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t promptString; - uint16_t helpString; -}; - -struct EFI_IFR_CHECKBOX { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_ORDERED_LIST { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t maximumEntries; - uint16_t promptString; - uint16_t helpString; -}; - -struct EFI_IFR_CHECK_BOX { - EFI_IFR_OP_HEADER header; - uint16_t option; - uint16_t value; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_ONE_OF_OPTION { - EFI_IFR_OP_HEADER header; - uint16_t optionString; - uint16_t value; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_NUMERIC { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; - uint16_t minimum; - uint16_t maximum; - uint16_t step; - uint16_t defaultValue; -}; - -struct EFI_IFR_TIME { - EFI_IFR_NUMERIC hour; - EFI_IFR_NUMERIC minute; - EFI_IFR_NUMERIC second; -}; - -struct EFI_IFR_DATE { - EFI_IFR_NUMERIC year; - EFI_IFR_NUMERIC month; - EFI_IFR_NUMERIC day; -}; - -struct EFI_IFR_PASSWORD { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; - uint8_t minimumSize; - uint8_t maximumSize; - uint16_t encoding; -}; - -struct EFI_IFR_STRING { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; - uint8_t minimumSize; - uint8_t maximumSize; -}; - -struct EFI_IFR_END_ONE_OF { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_HIDDEN { - EFI_IFR_OP_HEADER header; - uint16_t value; - uint16_t key; -}; - -struct EFI_IFR_SUPPRESS { - EFI_IFR_OP_HEADER header; - uint8_t flags; -}; - -struct EFI_IFR_GRAYOUT { - EFI_IFR_OP_HEADER header; - uint8_t flags; -}; - -struct EFI_IFR_INCONSISTENT { - EFI_IFR_OP_HEADER header; - uint16_t popup; - uint8_t flags; -}; - -struct EFI_IFR_EQ_ID_VAL { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t value; -}; - -struct EFI_IFR_EQ_ID_LIST { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t width; - uint16_t listLength; - vector valueList; -}; - -struct EFI_IFR_EQ_ID_ID { - EFI_IFR_OP_HEADER header; - uint16_t primaryQuestionId; - uint8_t width; - uint16_t secondaryQuestionId; -}; - -struct EFI_IFR_EQ_VAR_VAL { - EFI_IFR_OP_HEADER header; - uint16_t variableId; - uint16_t value; -}; - -struct EFI_IFR_AND { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_OR { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_NOT { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_END_IF { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_SAVE_DEFAULTS { - EFI_IFR_OP_HEADER header; - uint16_t formId; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_RESTORE_DEFAULTS { - EFI_IFR_OP_HEADER header; - uint16_t formId; - uint16_t promptString; - uint16_t helpString; - uint8_t flags; - uint16_t key; -}; - -struct EFI_IFR_INVENTORY { - EFI_IFR_OP_HEADER header; - uint16_t helpString; - uint16_t primaryTextString; - uint16_t secondaryTextString; -}; - -struct EFI_IFR_VARSTORE { - EFI_IFR_OP_HEADER header; - string guid; - uint16_t varId; - uint16_t size; -}; - -struct EFI_IFR_VARSTORE_SELECT { - EFI_IFR_OP_HEADER header; - uint16_t varId; -}; - -struct EFI_IFR_VARSTORE_SELECT_PAIR { - EFI_IFR_OP_HEADER header; - uint16_t primaryVarId; - uint16_t secondaryVarId; -}; - -struct EFI_IFR_TRUE { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_FALSE { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_GT { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_GE { - EFI_IFR_OP_HEADER header; -}; - -struct EFI_IFR_BANNER { - EFI_IFR_OP_HEADER header; - uint16_t titleString; - uint16_t lineNumber; - uint8_t alignment; -}; - -struct EFI_IFR_NV_DATA { - EFI_IFR_OP_HEADER header; - uint16_t questionId; - uint8_t storageWidth; - vector data; -}; - - -// Function prototypes -/* -Name: getEFIStringPackages -Purpose: Gets EFI string packages -*/ -void getEFIStringPackages(vector &stringPackages, const string &buffer); - -/* -Name: displayEFIStringPackages -Purpose: Displays EFI string packages -*/ -void displayEFIStringPackages(const vector &stringPackages); - -/* -Name: getEFIStrings -Purpose: Gets strings from string package -*/ -void getEFIStrings(vector &stringPackages, vector &strings, const string &buffer); - -/* -Name: displayEFIStrings -Purpose: Displays EFI strings -*/ -void displayEFIStrings(const vector &strings); - -/* -Name: getEFIFormSets -Purpose: Gets EFI form sets -*/ -void getEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings); - -/* -Name: displayEFIFormSets -Purpose: Displays EFI form sets -*/ -void displayEFIFormSets(const vector &formSets); - -/* -Name: generateEFIIFRDump -Purpose: Generates EFI IFR dump -*/ -void generateEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings); - -/* -Name: endEFICondition -Purpose: Returns if opcode ends a conditional statement -*/ -bool endEFICondition(const string &buffer, uint32_t j); - - -#endif +// Header guard +#ifndef EFI_H +#define EFI_H + +// Header files +#include +#include +#include +#include + +using namespace std; + +// Global definitions +#define EFI_IFR_FORM_OP '\x01' +#define EFI_IFR_SUBTITLE_OP '\x02' +#define EFI_IFR_TEXT_OP '\x03' +#define EFI_IFR_GRAPHIC_OP '\x04' +#define EFI_IFR_ONE_OF_OP '\x05' +#define EFI_IFR_CHECKBOX_OP '\x06' +#define EFI_IFR_NUMERIC_OP '\x07' +#define EFI_IFR_PASSWORD_OP '\x08' +#define EFI_IFR_ONE_OF_OPTION_OP '\x09' +#define EFI_IFR_SUPPRESS_IF_OP '\x0A' +#define EFI_IFR_END_FORM_OP '\x0B' +#define EFI_IFR_HIDDEN_OP '\x0C' +#define EFI_IFR_END_FORM_SET_OP '\x0D' +#define EFI_IFR_FORM_SET_OP '\x0E' +#define EFI_IFR_REF_OP '\x0F' +#define EFI_IFR_END_ONE_OF_OP '\x10' +#define EFI_IFR_END_OP EFI_IFR_END_ONE_OF_OP +#define EFI_IFR_INCONSISTENT_IF_OP '\x11' +#define EFI_IFR_EQ_ID_VAL_OP '\x12' +#define EFI_IFR_EQ_ID_ID_OP '\x13' +#define EFI_IFR_EQ_ID_LIST_OP '\x14' +#define EFI_IFR_AND_OP '\x15' +#define EFI_IFR_OR_OP '\x16' +#define EFI_IFR_NOT_OP '\x17' +#define EFI_IFR_END_IF_OP '\x18' +#define EFI_IFR_GRAYOUT_IF_OP '\x19' +#define EFI_IFR_DATE_OP '\x1A' +#define EFI_IFR_TIME_OP '\x1B' +#define EFI_IFR_STRING_OP '\x1C' +#define EFI_IFR_LABEL_OP '\x1D' +#define EFI_IFR_SAVE_DEFAULTS_OP '\x1E' +#define EFI_IFR_RESTORE_DEFAULTS_OP '\x1F' +#define EFI_IFR_BANNER_OP '\x20' +#define EFI_IFR_INVENTORY_OP '\x21' +#define EFI_IFR_EQ_VAR_VAL_OP '\x22' +#define EFI_IFR_ORDERED_LIST_OP '\x23' +#define EFI_IFR_VARSTORE_OP '\x24' +#define EFI_IFR_VARSTORE_SELECT_OP '\x25' +#define EFI_IFR_VARSTORE_SELECT_PAIR_OP '\x26' +#define EFI_IFR_TRUE_OP '\x27' +#define EFI_IFR_FALSE_OP '\x28' +#define EFI_IFR_GT_OP '\x29' +#define EFI_IFR_GE_OP '\x2A' +#define EFI_IFR_OEM_DEFINED_OP '\x2B' +#define EFI_IFR_LAST_OPCODE EFI_IFR_OEM_DEFINED_OP +#define EFI_IFR_OEM_OP '\xFE' +#define EFI_IFR_NV_ACCESS_COMMAND '\xFF' + + +// Classes/structs +struct EFI_HII_PACK_HEADER { + uint32_t offset; + uint32_t length; + uint16_t type; +}; + +struct EFI_IFR_STRING_PACK { + EFI_HII_PACK_HEADER header; + uint32_t numberOfStrings; + uint32_t attributes; + string language; + uint32_t structureOffset; +}; + +struct EFI_IFR_FORM_SET_PACK { + EFI_HII_PACK_HEADER header; + uint16_t titleString; + uint32_t usingStringPackage; + string title; +}; + +struct EFI_IFR_OP_HEADER { + uint32_t offset; + uint8_t opcode; + uint8_t length; +}; + +struct EFI_IFR_FORM_SET { + EFI_IFR_OP_HEADER header; + string guid; + uint16_t titleString; + uint16_t helpString; + uint64_t callbackHandle; + uint16_t mainClass; + uint16_t subClass; + uint16_t nvDataSize; +}; + +struct EFI_IFR_FORM { + EFI_IFR_OP_HEADER header; + uint16_t formId; + uint16_t titleString; +}; + +struct EFI_IFR_LABEL { + EFI_IFR_OP_HEADER header; + uint16_t labelId; +}; + +struct EFI_IFR_SUBTITLE { + EFI_IFR_OP_HEADER header; + uint16_t subtitleString; +}; + +struct EFI_IFR_TEXT { + EFI_IFR_OP_HEADER header; + uint16_t helpString; + uint16_t primaryTextString; + uint16_t secondaryTextString; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_REF { + EFI_IFR_OP_HEADER header; + uint16_t formId; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_END_FORM { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_END_FORM_SET { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_ONE_OF { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t promptString; + uint16_t helpString; +}; + +struct EFI_IFR_CHECKBOX { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_ORDERED_LIST { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t maximumEntries; + uint16_t promptString; + uint16_t helpString; +}; + +struct EFI_IFR_CHECK_BOX { + EFI_IFR_OP_HEADER header; + uint16_t option; + uint16_t value; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_ONE_OF_OPTION { + EFI_IFR_OP_HEADER header; + uint16_t optionString; + uint16_t value; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_NUMERIC { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; + uint16_t minimum; + uint16_t maximum; + uint16_t step; + uint16_t defaultValue; +}; + +struct EFI_IFR_TIME { + EFI_IFR_NUMERIC hour; + EFI_IFR_NUMERIC minute; + EFI_IFR_NUMERIC second; +}; + +struct EFI_IFR_DATE { + EFI_IFR_NUMERIC year; + EFI_IFR_NUMERIC month; + EFI_IFR_NUMERIC day; +}; + +struct EFI_IFR_PASSWORD { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; + uint8_t minimumSize; + uint8_t maximumSize; + uint16_t encoding; +}; + +struct EFI_IFR_STRING { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; + uint8_t minimumSize; + uint8_t maximumSize; +}; + +struct EFI_IFR_END_ONE_OF { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_HIDDEN { + EFI_IFR_OP_HEADER header; + uint16_t value; + uint16_t key; +}; + +struct EFI_IFR_SUPPRESS { + EFI_IFR_OP_HEADER header; + uint8_t flags; +}; + +struct EFI_IFR_GRAYOUT { + EFI_IFR_OP_HEADER header; + uint8_t flags; +}; + +struct EFI_IFR_INCONSISTENT { + EFI_IFR_OP_HEADER header; + uint16_t popup; + uint8_t flags; +}; + +struct EFI_IFR_EQ_ID_VAL { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t value; +}; + +struct EFI_IFR_EQ_ID_LIST { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t width; + uint16_t listLength; + vector valueList; +}; + +struct EFI_IFR_EQ_ID_ID { + EFI_IFR_OP_HEADER header; + uint16_t primaryQuestionId; + uint8_t width; + uint16_t secondaryQuestionId; +}; + +struct EFI_IFR_EQ_VAR_VAL { + EFI_IFR_OP_HEADER header; + uint16_t variableId; + uint16_t value; +}; + +struct EFI_IFR_AND { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_OR { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_NOT { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_END_IF { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_SAVE_DEFAULTS { + EFI_IFR_OP_HEADER header; + uint16_t formId; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_RESTORE_DEFAULTS { + EFI_IFR_OP_HEADER header; + uint16_t formId; + uint16_t promptString; + uint16_t helpString; + uint8_t flags; + uint16_t key; +}; + +struct EFI_IFR_INVENTORY { + EFI_IFR_OP_HEADER header; + uint16_t helpString; + uint16_t primaryTextString; + uint16_t secondaryTextString; +}; + +struct EFI_IFR_VARSTORE { + EFI_IFR_OP_HEADER header; + string guid; + uint16_t varId; + uint16_t size; + // 255 (max size allowed by EFI_IFR_OP_HEADER:Length - 2 - 16 - 2 - 2 = 233 bytes max name (?) + uint8_t name[233]; +}; + +struct EFI_IFR_VARSTORE_SELECT { + EFI_IFR_OP_HEADER header; + uint16_t varId; +}; + +struct EFI_IFR_VARSTORE_SELECT_PAIR { + EFI_IFR_OP_HEADER header; + uint16_t primaryVarId; + uint16_t secondaryVarId; +}; + +struct EFI_IFR_TRUE { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_FALSE { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_GT { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_GE { + EFI_IFR_OP_HEADER header; +}; + +struct EFI_IFR_BANNER { + EFI_IFR_OP_HEADER header; + uint16_t titleString; + uint16_t lineNumber; + uint8_t alignment; +}; + +struct EFI_IFR_NV_DATA { + EFI_IFR_OP_HEADER header; + uint16_t questionId; + uint8_t storageWidth; + vector data; +}; + + +// Function prototypes +/* +Name: getEFIStringPackages +Purpose: Gets EFI string packages +*/ +void getEFIStringPackages(vector &stringPackages, const string &buffer); + +/* +Name: displayEFIStringPackages +Purpose: Displays EFI string packages +*/ +void displayEFIStringPackages(const vector &stringPackages); + +/* +Name: getEFIStrings +Purpose: Gets strings from string package +*/ +void getEFIStrings(vector &stringPackages, vector &strings, const string &buffer); + +/* +Name: displayEFIStrings +Purpose: Displays EFI strings +*/ +void displayEFIStrings(const vector &strings); + +/* +Name: getEFIFormSets +Purpose: Gets EFI form sets +*/ +void getEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings); + +/* +Name: displayEFIFormSets +Purpose: Displays EFI form sets +*/ +void displayEFIFormSets(const vector &formSets); + +/* +Name: generateEFIIFRDump +Purpose: Generates EFI IFR dump +*/ +void generateEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings); + +/* +Name: endEFICondition +Purpose: Returns if opcode ends a conditional statement +*/ +bool endEFICondition(const string &buffer, uint32_t j); + + +#endif diff --git a/Icon.ico b/Icon.ico deleted file mode 100644 index ca49ee2..0000000 Binary files a/Icon.ico and /dev/null differ diff --git a/LICENSE b/LICENSE index ef7e7ef..efe40f6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,674 @@ -GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 3d0326c..bc72695 --- a/README.md +++ b/README.md @@ -1,32 +1,16 @@ -Universal IFR Extractor -======================= - -Utility that can extract the internal forms representation from both EFI and UEFI modules and convert it into a human readable format. - -You can download an executable here. - -© 2014 donovan6000 -


-Changelog: - -v0.6 6/16/2014 -* Added support for multiple string packages being used by one form. - -v0.5 3/2/2014 -* Fixed an issue that caused it to crash older versions of Windows. -* Corrected form set offsets that were off by four bytes. - -v0.4 2/10/2014 -* Fixed an issue with ASROCK FM2-A55M's Setup module. - -v0.3 2/8/2014 -* Shows entire command's hex sequence in output. - -v0.2 2/7/2014 -* I think I fixed the issue that prevented it from running on Windows XP. -* Doesn't require any additional DLLs anymore. -* The extract dialog now starts in the selected modules directory. -* Fix the issue where it crashed on a few Acer BIOS. Thanks BDMaster! - -v0.1 1/7/2014 -* Initial release. +End of Life Notification +======================= + +This fork is not supported anymore, and this repository is archived. + +Please consider using https://github.com/LongSoft/IFRExtractor-RS instead. + +IFR Extractor LS +======================= + +Utility to extract the internal forms representation from both EFI and UEFI drivers/applications into human readable text file. + +A fork of Donovan6000's project with bugfixes and additions. + +Original code by Donovan6000, rewritten UEFI.cpp by TomRus88, fixes and additions by DeathBringer, Fernando Rodriguez and Seth Stahlman. + diff --git a/UEFI.cpp b/UEFI.cpp old mode 100755 new mode 100644 index 9f2b30e..34b08c0 --- a/UEFI.cpp +++ b/UEFI.cpp @@ -1,4097 +1,1308 @@ -// Header files -#include -#include -#include -#include "UEFI.h" - - -// Supporting function implementation -void getUEFIStringPackages(vector &stringPackages, const string &buffer) { - - // Initialize variables - UEFI_IFR_STRING_PACK tempStringPackage; - - // Go through buffer - for(unsigned int i = 0; i < buffer.size() - 45; 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 + 45] == '\x00' && buffer[i + 48] == '\x2D' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x00') { - - // Set temp string package - tempStringPackage.header.offset = i; - - tempStringPackage.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16)); - - tempStringPackage.header.type = static_cast(buffer[i + 3]); - tempStringPackage.headerSize = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8) + (static_cast(buffer[i + 6]) << 16) + (static_cast(buffer[i + 7]) << 24)); - - tempStringPackage.stringOffset = i + static_cast(static_cast(buffer[i + 8]) + (static_cast(buffer[i + 9]) << 8) + (static_cast(buffer[i + 10]) << 16) + (static_cast(buffer[i + 11]) << 24)); - - for(int j = 0; j < 16; j++) - tempStringPackage.languageWindow.push_back(static_cast(static_cast(buffer[i + 12 + j * 2]) + (static_cast(buffer[i + 13 + j * 2]) << 8))); - - for(int 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 &stringPackages) { - - // Display string packages info - cout << "String Packages Information:" << endl; - - // Go through string packages - for(unsigned int 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 &stringPackages, vector &strings, const string &buffer) { - - // Initialize variables - int index; - string temp; - - // Go through string packages - for(unsigned int i = 0; i < stringPackages.size(); i++) { - - // Check if language isn't english - if(stringPackages[i].language != "en-US") - - // Continue - continue; - - // Set structure offset - stringPackages[i].structureOffset = strings.size(); - - // Add language string to list - strings.push_back(stringPackages[i].language); - - // Loop while string exists - for(index = stringPackages[i].stringOffset; buffer[index] == '\x14'; index += 2) { - - // Fill string - for(index++; buffer[index] != '\x00'; index += 2) - temp.push_back(buffer[index]); - - // Add string to list - strings.push_back(temp); - - // Clear temp - temp.clear(); - - // Skip % padding - while(buffer[index + 1] == '\x25') - index += 2; - } - } - - // Go through strings - for(unsigned int i = 0; i < strings.size(); i++) { - - // Change carriage return characters to spaces - for(unsigned int 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(unsigned int 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 &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 &formSets, const string &buffer, const vector &stringPackages, const vector &strings) { - - // Initialize variables - UEFI_IFR_FORM_SET_PACK tempFormSet; - vector stringCandidates; - uint32_t chosenCandidate; - - // Go through string packages - for(unsigned int i = 0; i < stringPackages.size(); i++) { - - // Check if language isn't english - if(stringPackages[i].language != "en-US") - - // Continue - continue; - - // Get string candidate - stringCandidates.push_back(i); - } - - // Go through buffer - for(uint32_t i = 0; 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(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x29') { - - // Get chosen candidate for form set's string package - chosenCandidate = stringCandidates[0]; - for(unsigned int j = 1; j < stringCandidates.size(); j++) - if(abs(static_cast(stringPackages[j].header.offset - i)) < abs(static_cast(stringPackages[chosenCandidate].header.offset - i))) - chosenCandidate = j; - - // Set temp form set - tempFormSet.header.offset = i; - tempFormSet.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16)); - tempFormSet.header.type = static_cast(buffer[i + 3]); - tempFormSet.titleString = static_cast(static_cast(buffer[i + 22]) + (static_cast(buffer[i + 23]) << 8)); - tempFormSet.usingStringPackage = stringCandidates[chosenCandidate]; - tempFormSet.title = strings[tempFormSet.titleString + stringPackages[tempFormSet.usingStringPackage].structureOffset]; - - // Add temp form set to list - formSets.push_back(tempFormSet); - } -} - -void displayUEFIFormSets(const vector &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; -} - -void generateUEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings) { - - // Initialize variables - uint8_t numberOfTabs = 0; - unsigned char highNibble, lowNibble; - vector conditionalStack; - ofstream fout(outputFile.c_str()); - - // Display protocol - for(uint8_t i = 0; i < 32; i++) - fout << ' '; - fout << "UEFI Protocol Detected" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl << endl << endl; - - // Display string packages info - for(uint8_t i = 0; i < 32; i++) - fout << ' '; - fout << "String Packages" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tLanguage:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << 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 << static_cast(i) << ')' << endl; - } - fout << endl << endl; - - // Display form sets info - for(uint8_t i = 0; i < 35; i++) - fout << ' '; - fout << "Form Sets" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tTitle:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << 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 - for(uint8_t i = 0; i < 25; i++) - fout << ' '; - fout << "Internal Forms Representation" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - fout << "Offset:\t\tInstruction:" << endl; - for(uint8_t i = 0; i < 80; i++) - fout << '-'; - fout << endl; - - // Go through form sets - for(uint32_t i = 0; i < formSets.size(); i++) - - // 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(buffer[j + 1]) & 0x7F) { - - // Check if opcode if UEFI_IFR_FORM_OP 0x01 - if(buffer[j] == UEFI_IFR_FORM_OP) { - - // Create temp - UEFI_IFR_FORM temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.titleString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Form: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Form ID: 0x" << hex << uppercase << temp.formId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(FORM); - } - } - - // Otherwise check if opcode if UEFI_IFR_SUBTITLE_OP 0x02 - else if(buffer[j] == UEFI_IFR_SUBTITLE_OP) { - - // Create temp - UEFI_IFR_SUBTITLE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.flags = static_cast(buffer[j + 6]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Subtitle: " << strings[temp.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TEXT_OP 0x03 - else if(buffer[j] == UEFI_IFR_TEXT_OP) { - - // Create temp - UEFI_IFR_TEXT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.secondaryTextString = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Text: " << strings[temp.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_IMAGE_OP 0x04 - else if(buffer[j] == UEFI_IFR_IMAGE_OP) { - - // Create temp - UEFI_IFR_IMAGE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.imageId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Image"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ONE_OF_OP 0x05 - else if(buffer[j] == UEFI_IFR_ONE_OF_OP) { - - // Create temp - UEFI_IFR_ONE_OF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.flags = static_cast(buffer[j + 13]); - - if(temp.flags == 0x00) { - temp.data.minimumValue = static_cast(buffer[j + 14]); - temp.data.maximumValue = static_cast(buffer[j + 15]); - temp.data.step = static_cast(buffer[j + 16]); - } - else if(temp.flags == 0x01) { - temp.data.minimumValue = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.data.maximumValue = static_cast(static_cast(buffer[j + 16]) + (static_cast(buffer[j + 17]) << 8)); - temp.data.step = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - } - else if(temp.flags == 0x02) { - temp.data.minimumValue = static_cast(static_cast(buffer[i + 14]) + (static_cast(buffer[i + 15]) << 8) + (static_cast(buffer[i + 16]) << 16) + (static_cast(buffer[i + 17]) << 24)); - temp.data.maximumValue = static_cast(static_cast(buffer[i + 18]) + (static_cast(buffer[i + 19]) << 8) + (static_cast(buffer[i + 20]) << 16) + (static_cast(buffer[i + 21]) << 24)); - temp.data.step = static_cast(static_cast(buffer[i + 22]) + (static_cast(buffer[i + 23]) << 8) + (static_cast(buffer[i + 24]) << 16) + (static_cast(buffer[i + 25]) << 24)); - } - else if(temp.flags == 0x03) { - temp.data.minimumValue = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8) + (static_cast(buffer[j + 16]) << 16) + (static_cast(buffer[j + 17]) << 24) + (static_cast(static_cast(buffer[j + 18])) << 32) + (static_cast(static_cast(buffer[j + 19])) << 40) + (static_cast(static_cast(buffer[j + 20])) << 48) + (static_cast(static_cast(buffer[j + 21])) << 56)); - temp.data.maximumValue = static_cast(static_cast(buffer[j + 22]) + (static_cast(buffer[j + 23]) << 8) + (static_cast(buffer[j + 24]) << 16) + (static_cast(buffer[j + 25]) << 24) + (static_cast(static_cast(buffer[j + 26])) << 32) + (static_cast(static_cast(buffer[j + 27])) << 40) + (static_cast(static_cast(buffer[j + 28])) << 48) + (static_cast(static_cast(buffer[j + 29])) << 56)); - temp.data.step = static_cast(static_cast(buffer[j + 30]) + (static_cast(buffer[j + 31]) << 8) + (static_cast(buffer[j + 32]) << 16) + (static_cast(buffer[j + 33]) << 24) + (static_cast(static_cast(buffer[j + 34])) << 32) + (static_cast(static_cast(buffer[j + 35])) << 40) + (static_cast(static_cast(buffer[j + 36])) << 48) + (static_cast(static_cast(buffer[j + 37])) << 56)); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Setting: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OPTION); - } - } - - // Otherwise check if opcode if UEFI_IFR_CHECKBOX_OP 0x06 - else if(buffer[j] == UEFI_IFR_CHECKBOX_OP) { - - // Create temp - UEFI_IFR_CHECKBOX temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.flags = static_cast(buffer[j + 13]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Checkbox: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_NUMERIC_OP 0x07 - else if(buffer[j] == UEFI_IFR_NUMERIC_OP) { - - // Create temp - UEFI_IFR_NUMERIC temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.flags = static_cast(buffer[j + 13]); - - if(temp.flags == 0x00) { - temp.data.minimumValue = static_cast(buffer[j + 14]); - temp.data.maximumValue = static_cast(buffer[j + 15]); - temp.data.step = static_cast(buffer[j + 16]); - } - else if(temp.flags == 0x01) { - temp.data.minimumValue = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8)); - temp.data.maximumValue = static_cast(static_cast(buffer[j + 16]) + (static_cast(buffer[j + 17]) << 8)); - temp.data.step = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - } - else if(temp.flags == 0x02) { - temp.data.minimumValue = static_cast(static_cast(buffer[i + 14]) + (static_cast(buffer[i + 15]) << 8) + (static_cast(buffer[i + 16]) << 16) + (static_cast(buffer[i + 17]) << 24)); - temp.data.maximumValue = static_cast(static_cast(buffer[i + 18]) + (static_cast(buffer[i + 19]) << 8) + (static_cast(buffer[i + 20]) << 16) + (static_cast(buffer[i + 21]) << 24)); - temp.data.step = static_cast(static_cast(buffer[i + 22]) + (static_cast(buffer[i + 23]) << 8) + (static_cast(buffer[i + 24]) << 16) + (static_cast(buffer[i + 25]) << 24)); - } - else if(temp.flags == 0x03) { - temp.data.minimumValue = static_cast(static_cast(buffer[j + 14]) + (static_cast(buffer[j + 15]) << 8) + (static_cast(buffer[j + 16]) << 16) + (static_cast(buffer[j + 17]) << 24) + (static_cast(static_cast(buffer[j + 18])) << 32) + (static_cast(static_cast(buffer[j + 19])) << 40) + (static_cast(static_cast(buffer[j + 20])) << 48) + (static_cast(static_cast(buffer[j + 21])) << 56)); - temp.data.maximumValue = static_cast(static_cast(buffer[j + 22]) + (static_cast(buffer[j + 23]) << 8) + (static_cast(buffer[j + 24]) << 16) + (static_cast(buffer[j + 25]) << 24) + (static_cast(static_cast(buffer[j + 26])) << 32) + (static_cast(static_cast(buffer[j + 27])) << 40) + (static_cast(static_cast(buffer[j + 28])) << 48) + (static_cast(static_cast(buffer[j + 29])) << 56)); - temp.data.step = static_cast(static_cast(buffer[j + 30]) + (static_cast(buffer[j + 31]) << 8) + (static_cast(buffer[j + 32]) << 16) + (static_cast(buffer[j + 33]) << 24) + (static_cast(static_cast(buffer[j + 34])) << 32) + (static_cast(static_cast(buffer[j + 35])) << 40) + (static_cast(static_cast(buffer[j + 36])) << 48) + (static_cast(static_cast(buffer[j + 37])) << 56)); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Numeric: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << dec << " (" << temp.data.minimumValue << '-' << temp.data.maximumValue << ") , Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_PASSWORD_OP 0x08 - else if(buffer[j] == UEFI_IFR_PASSWORD_OP) { - - // Create temp - UEFI_IFR_PASSWORD temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.minimumSize = static_cast(static_cast(buffer[j + 13]) + (static_cast(buffer[j + 14]) << 8)); - temp.maximumSize = static_cast(static_cast(buffer[j + 15]) + (static_cast(buffer[j + 16]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Password: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ONE_OF_OPTION_OP 0x09 - else if(buffer[j] == UEFI_IFR_ONE_OF_OPTION_OP) { - - // Create temp - UEFI_IFR_ONE_OF_OPTION temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.optionString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.flags = static_cast(buffer[j + 4]); - temp.type = static_cast(buffer[j + 5]); - - if(temp.type == 0x00) - temp.value = static_cast(buffer[j + 6]); - else if(temp.type == 0x01) - temp.value = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - else if(temp.type == 0x02) - temp.value = static_cast(static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24)); - else if(temp.type == 0x03) - temp.value = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8) + (static_cast(buffer[j + 8]) << 16) + (static_cast(buffer[j + 9]) << 24) + (static_cast(static_cast(buffer[j + 10])) << 32) + (static_cast(static_cast(buffer[j + 11])) << 40) + (static_cast(static_cast(buffer[j + 12])) << 48) + (static_cast(static_cast(buffer[j + 13])) << 56)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Option: " << strings[temp.optionString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Value: "; - - if(temp.type >= 0x00 && temp.type <= 0x03) - fout << "0x" << hex << uppercase << temp.value; - else if(temp.type == 0x04) - fout << "Bool"; - else if(temp.type == 0x05) - fout << "Time"; - else if(temp.type == 0x06) - fout << "Date"; - else if(temp.type == 0x07) - fout << "String"; - else if(temp.type == 0x08) - fout << "Other"; - else if(temp.type == 0x09) - fout << "Undefined"; - else if(temp.type == 0x0A) - fout << "Action"; - else if(temp.type == 0x0B) - fout << "Buffer"; - - if(temp.flags == 0x10) - fout << " (default)"; - else if(temp.flags == 0x20) - fout << " (default MFG)"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SUPPRESS_IF_OP 0x0A - else if(buffer[j] == UEFI_IFR_SUPPRESS_IF_OP) { - - // Create temp - UEFI_IFR_SUPPRESS_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Suppress If:"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(CONDITION); - } - } - - // Otherwise check if opcode if UEFI_IFR_LOCKED_OP 0x0B - else if(buffer[j] == UEFI_IFR_LOCKED_OP) { - - // Create temp - UEFI_IFR_LOCKED temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Locked"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ACTION_OP 0x0C - else if(buffer[j] == UEFI_IFR_ACTION_OP) { - - // Create temp - UEFI_IFR_ACTION temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.questionConfigString = static_cast(static_cast(buffer[j + 13]) + (static_cast(buffer[j + 14]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Action: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_RESET_BUTTON_OP 0x0D - else if(buffer[j] == UEFI_IFR_RESET_BUTTON_OP) { - - // Create temp - UEFI_IFR_RESET_BUTTON temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.defaultId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Reset: " << strings[temp.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_FORM_SET_OP 0x0E - else if(buffer[j] == UEFI_IFR_FORM_SET_OP) { - - // Create temp - UEFI_IFR_FORM_SET temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[i] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[i] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.titleString = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - temp.helpString = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); - temp.flags = static_cast(buffer[j + 22]); - for(uint32_t k = j + 23; k < j + 27; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.classGuid.insert(0, 1, lowNibble); - temp.classGuid.insert(0, 1, highNibble); - } - temp.classGuid.push_back('-'); - for(uint32_t k = j + 27; k < j + 29; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.classGuid.insert(9, 1, lowNibble); - temp.classGuid.insert(9, 1, highNibble); - } - temp.classGuid.push_back('-'); - for(uint32_t k = j + 29; k < j + 31; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.classGuid.insert(14, 1, lowNibble); - temp.classGuid.insert(14, 1, highNibble); - } - temp.classGuid.push_back('-'); - for(uint32_t k = j + 31; k < j + 33; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.classGuid.push_back(highNibble); - temp.classGuid.push_back(lowNibble); - } - temp.classGuid.push_back('-'); - for(uint32_t k = j + 33; k < j + 39; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.classGuid.push_back(highNibble); - temp.classGuid.push_back(lowNibble); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Form Set: " << strings[temp.titleString + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(FORM_SET); - } - } - - // Otherwise check if opcode if UEFI_IFR_REF_OP 0x0F - else if(buffer[j] == UEFI_IFR_REF_OP) { - - // Create temp - UEFI_IFR_REF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.formId = static_cast(static_cast(buffer[j + 13]) + (static_cast(buffer[j + 14]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Ref: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_NO_SUBMIT_IF_OP 0x10 - else if(buffer[j] == UEFI_IFR_NO_SUBMIT_IF_OP) { - - // Create temp - UEFI_IFR_NO_SUBMIT_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "No Submit If:"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(CONDITION); - } - } - - // Otherwise check if opcode if UEFI_IFR_INCONSISTENT_IF_OP 0x11 - else if(buffer[j] == UEFI_IFR_INCONSISTENT_IF_OP) { - - // Create temp - UEFI_IFR_INCONSISTENT_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Inconsistent If:"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(CONDITION); - } - } - - // Otherwise check if opcode if UEFI_IFR_EQ_ID_VAL_OP 0x12 - else if(buffer[j] == UEFI_IFR_EQ_ID_VAL_OP) { - - // Create temp - UEFI_IFR_EQ_ID_VAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.value = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.questionId << " equals 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_EQ_ID_ID_OP 0x13 - else if(buffer[j] == UEFI_IFR_EQ_ID_ID_OP) { - - // Create temp - UEFI_IFR_EQ_ID_ID temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.primaryQuestionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.secondaryQuestionId = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 0x" << hex << uppercase << temp.primaryQuestionId << " equals variable 0x" << hex << uppercase << temp.secondaryQuestionId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_EQ_ID_LIST_OP 0x14 - else if(buffer[j] == UEFI_IFR_EQ_ID_LIST_OP) { - - // Create temp - UEFI_IFR_EQ_ID_LIST temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.questionId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.listLength = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Create list - uint32_t index = j + 6; - - for(uint8_t k = 0; k < temp.listLength; k++, index += 2) - temp.valueList.push_back(static_cast(static_cast(buffer[index]) + (static_cast(buffer[index + 1]) << 8))); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Variable 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 << ')'; - } - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_AND_OP 0x15 - else if(buffer[j] == UEFI_IFR_AND_OP) { - - // Create temp - UEFI_IFR_AND temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "And"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_OR_OP 0x16 - else if(buffer[j] == UEFI_IFR_OR_OP) { - - // Create temp - UEFI_IFR_OR temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Or"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_NOT_OP 0x17 - else if(buffer[j] == UEFI_IFR_NOT_OP) { - - // Create temp - UEFI_IFR_NOT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Not"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_RULE_OP 0x18 - else if(buffer[j] == UEFI_IFR_RULE_OP) { - - // Create temp - UEFI_IFR_RULE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.ruleId = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Rule"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_GRAY_OUT_IF_OP 0x19 - else if(buffer[j] == UEFI_IFR_GRAY_OUT_IF_OP) { - - // Create temp - UEFI_IFR_GRAY_OUT_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Grayout If:"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(CONDITION); - } - } - - // Otherwise check if opcode if UEFI_IFR_DATE_OP 0x1A - else if(buffer[j] == UEFI_IFR_DATE_OP) { - - // Create temp - UEFI_IFR_DATE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.flags = static_cast(buffer[j + 13]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Date: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TIME_OP 0x1B - else if(buffer[j] == UEFI_IFR_TIME_OP) { - - // Create temp - UEFI_IFR_TIME temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.flags = static_cast(buffer[j + 13]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Time: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_STRING_OP 0x1C - else if(buffer[j] == UEFI_IFR_STRING_OP) { - - // Create temp - UEFI_IFR_STRING temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.minimumSize = static_cast(buffer[j + 13]); - temp.maximumSize = static_cast(buffer[j + 14]); - temp.flags = static_cast(buffer[j + 15]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "String: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_REFRESH_OP 0x1D - else if(buffer[j] == UEFI_IFR_REFRESH_OP) { - - // Create temp - UEFI_IFR_REFRESH temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.refreshInterval = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Refresh"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_DISABLE_IF_OP 0x1E - else if(buffer[j] == UEFI_IFR_DISABLE_IF_OP) { - - // Create temp - UEFI_IFR_DISABLE_IF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Disable If:"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(CONDITION); - } - } - - // Otherwise check if opcode if UEFI_IFR_ANIMATION_OP 0x1F - else if(buffer[j] == UEFI_IFR_ANIMATION_OP) { - - // Create temp - UEFI_IFR_ANIMATION temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.animationId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Animation"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TO_LOWER_OP 0x20 - else if(buffer[j] == UEFI_IFR_TO_LOWER_OP) { - - // Create temp - UEFI_IFR_TO_LOWER temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Convert to Lower"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TO_UPPER_OP 0x21 - else if(buffer[j] == UEFI_IFR_TO_UPPER_OP) { - - // Create temp - UEFI_IFR_TO_UPPER temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Convert to Upper"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_MAP_OP 0x22 - else if(buffer[j] == UEFI_IFR_MAP_OP) { - - // Create temp - UEFI_IFR_MAP temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Map"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ORDERED_LIST_OP 0x23 - else if(buffer[j] == UEFI_IFR_ORDERED_LIST_OP) { - - // Create temp - UEFI_IFR_ORDERED_LIST temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.question.statement.promptString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.question.statement.helpString = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.question.questionId = static_cast(static_cast(buffer[j + 6]) + (static_cast(buffer[j + 7]) << 8)); - temp.question.varStoreId = static_cast(static_cast(buffer[j + 8]) + (static_cast(buffer[j + 9]) << 8)); - temp.question.varOffset = static_cast(static_cast(buffer[j + 10]) + (static_cast(buffer[j + 11]) << 8)); - temp.question.flags = static_cast(buffer[j + 12]); - temp.minimumContainers = static_cast(buffer[j + 13]); - temp.flags = static_cast(buffer[j + 14]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Ordered List: " << strings[temp.question.statement.promptString + stringPackages[formSets[i].usingStringPackage].structureOffset] << ", Variable: 0x" << hex << uppercase << temp.question.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VARSTORE_OP 0x24 - else if(buffer[j] == UEFI_IFR_VARSTORE_OP) { - - // Create temp - UEFI_IFR_VARSTORE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.varStoreId = static_cast(static_cast(buffer[j + 18]) + (static_cast(buffer[j + 19]) << 8)); - temp.size = static_cast(static_cast(buffer[j + 20]) + (static_cast(buffer[j + 21]) << 8)); - for(uint32_t index = j + 22; buffer[index] != '\x00'; index++) - temp.name.push_back(buffer[index]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Var Store: 0x" << hex << uppercase << temp.varStoreId << "[" << dec << temp.size << "] (" << temp.name << ')'; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VARSTORE_NAME_VALUE_OP 0x25 - else if(buffer[j] == UEFI_IFR_VARSTORE_NAME_VALUE_OP) { - - // Create temp - UEFI_IFR_VARSTORE_NAME_VALUE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.varStoreId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - for(uint32_t k = j + 4; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 14; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 14; k < j + 20; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Var Store Name Value: 0x" << hex << uppercase << temp.varStoreId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VARSTORE_EFI_OP 0x26 - else if(buffer[j] == UEFI_IFR_VARSTORE_EFI_OP) { - - // Create temp - UEFI_IFR_VARSTORE_EFI temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.varStoreId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - for(uint32_t k = j + 4; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 14; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 14; k < j + 20; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.attributes = static_cast(static_cast(buffer[i + 20]) + (static_cast(buffer[i + 21]) << 8) + (static_cast(buffer[i + 22]) << 16) + (static_cast(buffer[i + 23]) << 24)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Var Store EFI: 0x" << hex << uppercase << temp.varStoreId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VARSTORE_DEVICE_OP 0x27 - else if(buffer[j] == UEFI_IFR_VARSTORE_DEVICE_OP) { - - // Create temp - UEFI_IFR_VARSTORE_DEVICE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.devicePathString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Var Store Device"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VERSION_OP 0x28 - else if(buffer[j] == UEFI_IFR_VERSION_OP) { - - // Create temp - UEFI_IFR_VERSION temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Version"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_END_OP 0x29 - else if(buffer[j] == UEFI_IFR_END_OP) { - - // Create temp - UEFI_IFR_END temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.condition = conditionalStack.back(); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Decrement number of tabs - numberOfTabs--; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Decrement conditional stack - conditionalStack.pop_back(); - - // Display temp - fout << "End"; - if(temp.condition == FORM_SET) - fout << " Form Set"; - else if(temp.condition == FORM) - fout << " Form"; - else if(temp.condition == CONDITION) - fout << " If"; - else if(temp.condition == OPTION) - fout << " of Options"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_MATCH_OP 0x2A - else if(buffer[j] == UEFI_IFR_MATCH_OP) { - - // Create temp - UEFI_IFR_MATCH temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Match"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_GET_OP 0x2B - else if(buffer[j] == UEFI_IFR_GET_OP) { - - // Create temp - UEFI_IFR_GET temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.varStoreId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.varOffset = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.varStoreType = static_cast(buffer[j + 6]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Get: 0x" << hex << uppercase << temp.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SET_OP 0x2C - else if(buffer[j] == UEFI_IFR_SET_OP) { - - // Create temp - UEFI_IFR_SET temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.varStoreId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.varOffset = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - temp.varStoreType = static_cast(buffer[j + 6]); - - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Set: 0x" << hex << uppercase << temp.varOffset; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_READ_OP 0x2D - else if(buffer[j] == UEFI_IFR_READ_OP) { - - // Create temp - UEFI_IFR_READ temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Read"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_WRITE_OP 0x2E - else if(buffer[j] == UEFI_IFR_WRITE_OP) { - - // Create temp - UEFI_IFR_WRITE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Write"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_EQUAL_OP 0x2F - else if(buffer[j] == UEFI_IFR_EQUAL_OP) { - - // Create temp - UEFI_IFR_EQUAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Equal"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_NOT_EQUAL_OP 0x30 - else if(buffer[j] == UEFI_IFR_NOT_EQUAL_OP) { - - // Create temp - UEFI_IFR_NOT_EQUAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Not Equal"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_GREATER_THAN_OP 0x31 - else if(buffer[j] == UEFI_IFR_GREATER_THAN_OP) { - - // Create temp - UEFI_IFR_GREATER_THAN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Greater Than"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_GREATER_EQUAL_OP 0x32 - else if(buffer[j] == UEFI_IFR_GREATER_EQUAL_OP) { - - // Create temp - UEFI_IFR_GREATER_EQUAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Greater Than or Equal"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_LESS_THAN_OP 0x33 - else if(buffer[j] == UEFI_IFR_LESS_THAN_OP) { - - // Create temp - UEFI_IFR_LESS_THAN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Less Than"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_LESS_EQUAL_OP 0x34 - else if(buffer[j] == UEFI_IFR_LESS_EQUAL_OP) { - - // Create temp - UEFI_IFR_LESS_EQUAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Less Than or Equal"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_BITWISE_AND_OP 0x35 - else if(buffer[j] == UEFI_IFR_BITWISE_AND_OP) { - - // Create temp - UEFI_IFR_BITWISE_AND temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Bitwise And"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_BITWISE_OR_OP 0x36 - else if(buffer[j] == UEFI_IFR_BITWISE_OR_OP) { - - // Create temp - UEFI_IFR_BITWISE_OR temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Bitwise Or"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_BITWISE_NOT_OP 0x37 - else if(buffer[j] == UEFI_IFR_BITWISE_NOT_OP) { - - // Create temp - UEFI_IFR_BITWISE_NOT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Bitwise Not"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SHIFT_LEFT_OP 0x38 - else if(buffer[j] == UEFI_IFR_SHIFT_LEFT_OP) { - - // Create temp - UEFI_IFR_SHIFT_LEFT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Shift Left"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SHIFT_RIGHT_OP 0x39 - else if(buffer[j] == UEFI_IFR_SHIFT_RIGHT_OP) { - - // Create temp - UEFI_IFR_SHIFT_RIGHT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Shift Right"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ADD_OP 0x3A - else if(buffer[j] == UEFI_IFR_ADD_OP) { - - // Create temp - UEFI_IFR_ADD temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Add"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SUBTRACT_OP 0x3B - else if(buffer[j] == UEFI_IFR_SUBTRACT_OP) { - - // Create temp - UEFI_IFR_SUBTRACT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Subtract"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_MULTIPLY_OP 0x3C - else if(buffer[j] == UEFI_IFR_MULTIPLY_OP) { - - // Create temp - UEFI_IFR_MULTIPLY temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Multiply"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_DIVIDE_OP 0x3D - else if(buffer[j] == UEFI_IFR_DIVIDE_OP) { - - // Create temp - UEFI_IFR_DIVIDE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Divide"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_MODULO_OP 0x3E - else if(buffer[j] == UEFI_IFR_MODULO_OP) { - - // Create temp - UEFI_IFR_MODULO temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Modulo"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_RULE_REF_OP 0x3F - else if(buffer[j] == UEFI_IFR_RULE_REF_OP) { - - // Create temp - UEFI_IFR_RULE_REF temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.ruleId = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Rule Ref"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_QUESTION_REF1_OP 0x40 - else if(buffer[j] == UEFI_IFR_QUESTION_REF1_OP) { - - // Create temp - UEFI_IFR_QUESTION_REF1 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.questionId = static_cast(static_cast(buffer[i + 2]) + (static_cast(buffer[i + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Question Ref: 0x" << hex << uppercase << temp.questionId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_QUESTION_REF2_OP 0x41 - else if(buffer[j] == UEFI_IFR_QUESTION_REF2_OP) { - - // Create temp - UEFI_IFR_QUESTION_REF2 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Question Ref"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_UINT8_OP 0x42 - else if(buffer[j] == UEFI_IFR_UINT8_OP) { - - // Create temp - UEFI_IFR_UINT8 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.value = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "8 Bit Unsigned Int: 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_UINT16_OP 0x43 - else if(buffer[j] == UEFI_IFR_UINT16_OP) { - - // Create temp - UEFI_IFR_UINT16 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.value = static_cast(static_cast(buffer[i + 2]) + (static_cast(buffer[i + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "16 Bit Unsigned Int: 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_UINT32_OP 0x44 - else if(buffer[j] == UEFI_IFR_UINT32_OP) { - - // Create temp - UEFI_IFR_UINT32 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.value = static_cast(static_cast(buffer[i + 2]) + (static_cast(buffer[i + 3]) << 8) + (static_cast(buffer[i + 4]) << 16) + (static_cast(buffer[i + 5]) << 24)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "32 Bit Unsigned Int: 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_UINT64_OP 0x45 - else if(buffer[j] == UEFI_IFR_UINT64_OP) { - - // Create temp - UEFI_IFR_UINT64 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.value = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8) + (static_cast(buffer[j + 4]) << 16) + (static_cast(buffer[j + 5]) << 24) + (static_cast(static_cast(buffer[j + 6])) << 32) + (static_cast(static_cast(buffer[j + 7])) << 40) + (static_cast(static_cast(buffer[j + 8])) << 48) + (static_cast(static_cast(buffer[j + 9])) << 56)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "64 Bit Unsigned Int: 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TRUE_OP 0x46 - else if(buffer[j] == UEFI_IFR_TRUE_OP) { - - // Create temp - UEFI_IFR_TRUE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "True"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_FALSE_OP 0x47 - else if(buffer[j] == UEFI_IFR_FALSE_OP) { - - // Create temp - UEFI_IFR_FALSE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "False"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TO_UINT_OP 0x48 - else if(buffer[j] == UEFI_IFR_TO_UINT_OP) { - - // Create temp - UEFI_IFR_TO_UINT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Convert to Unsigned Int"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TO_STRING_OP 0x49 - else if(buffer[j] == UEFI_IFR_TO_STRING_OP) { - - // Create temp - UEFI_IFR_TO_STRING temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.format = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Convert to String"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TO_BOOLEAN_OP 0x4A - else if(buffer[j] == UEFI_IFR_TO_BOOLEAN_OP) { - - // Create temp - UEFI_IFR_TO_BOOLEAN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Boolean"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_MID_OP 0x4B - else if(buffer[j] == UEFI_IFR_MID_OP) { - - // Create temp - UEFI_IFR_MID temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Mid"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_FIND_OP 0x4C - else if(buffer[j] == UEFI_IFR_FIND_OP) { - - // Create temp - UEFI_IFR_FIND temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.format = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Find"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_TOKEN_OP 0x4D - else if(buffer[j] == UEFI_IFR_TOKEN_OP) { - - // Create temp - UEFI_IFR_TOKEN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Token"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_STRING_REF1_OP 0x4E - else if(buffer[j] == UEFI_IFR_STRING_REF1_OP) { - - // Create temp - UEFI_IFR_STRING_REF1 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.stringId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "String Ref: " << strings[temp.stringId + stringPackages[formSets[i].usingStringPackage].structureOffset]; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_STRING_REF2_OP 0x4F - else if(buffer[j] == UEFI_IFR_STRING_REF2_OP) { - - // Create temp - UEFI_IFR_STRING_REF2 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "String Ref"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_CONDITIONAL_OP 0x50 - else if(buffer[j] == UEFI_IFR_CONDITIONAL_OP) { - - // Create temp - UEFI_IFR_CONDITIONAL temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Conditional"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_QUESTION_REF3_OP 0x51 - else if(buffer[j] == UEFI_IFR_QUESTION_REF3_OP) { - - // Create temp - UEFI_IFR_QUESTION_REF3 temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Question Ref"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ZERO_OP 0x52 - else if(buffer[j] == UEFI_IFR_ZERO_OP) { - - // Create temp - UEFI_IFR_ZERO temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Zero"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ONE_OP 0x53 - else if(buffer[j] == UEFI_IFR_ONE_OP) { - - // Create temp - UEFI_IFR_ONE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "One"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_ONES_OP 0x54 - else if(buffer[j] == UEFI_IFR_ONES_OP) { - - // Create temp - UEFI_IFR_ONES temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Ones"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_UNDEFINED_OP 0x55 - else if(buffer[j] == UEFI_IFR_UNDEFINED_OP) { - - // Create temp - UEFI_IFR_UNDEFINED temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Undefined"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_LENGTH_OP 0x56 - else if(buffer[j] == UEFI_IFR_LENGTH_OP) { - - // Create temp - UEFI_IFR_LENGTH temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Length"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_DUP_OP 0x57 - else if(buffer[j] == UEFI_IFR_DUP_OP) { - - // Create temp - UEFI_IFR_DUP temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Dup"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_THIS_OP 0x58 - else if(buffer[j] == UEFI_IFR_THIS_OP) { - - // Create temp - UEFI_IFR_THIS temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "This"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SPAN_OP 0x59 - else if(buffer[j] == UEFI_IFR_SPAN_OP) { - - // Create temp - UEFI_IFR_SPAN temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.flags = static_cast(buffer[j + 2]); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Span"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_VALUE_OP 0x5A - else if(buffer[j] == UEFI_IFR_VALUE_OP) { - - // Create temp - UEFI_IFR_VALUE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Value"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_DEFAULT_OP 0x5B - else if(buffer[j] == UEFI_IFR_DEFAULT_OP) { - - // Create temp - UEFI_IFR_DEFAULT temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.defaultId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.type = static_cast(buffer[j + 4]); - - if(temp.type == 0x00) - temp.value = static_cast(buffer[j + 5]); - else if(temp.type == 0x01) - temp.value = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8)); - else if(temp.type == 0x02) - temp.value = static_cast(static_cast(buffer[i + 5]) + (static_cast(buffer[i + 6]) << 8) + (static_cast(buffer[i + 7]) << 16) + (static_cast(buffer[i + 8]) << 24)); - else if(temp.type == 0x03) - temp.value = static_cast(static_cast(buffer[j + 5]) + (static_cast(buffer[j + 6]) << 8) + (static_cast(buffer[j + 7]) << 16) + (static_cast(buffer[j + 8]) << 24) + (static_cast(static_cast(buffer[j + 9])) << 32) + (static_cast(static_cast(buffer[j + 10])) << 40) + (static_cast(static_cast(buffer[j + 11])) << 48) + (static_cast(static_cast(buffer[j + 12])) << 56)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Default: "; - if(temp.type == 0x00) - fout << "8 Bit"; - else if(temp.type == 0x01) - fout << "16 Bit"; - else if(temp.type == 0x02) - fout << "32 Bit"; - else if(temp.type == 0x03) - fout << "64 Bit"; - else if(temp.type == 0x04) - fout << "Bool"; - else if(temp.type == 0x05) - fout << "Time"; - else if(temp.type == 0x06) - fout << "Date"; - else if(temp.type == 0x07) - fout << "String"; - else if(temp.type == 0x08) - fout << "Other"; - else if(temp.type == 0x09) - fout << "Undefined"; - else if(temp.type == 0x0A) - fout << "Action"; - else if(temp.type == 0x0B) - fout << "Buffer"; - - if(temp.type >= 0x00 && temp.type <= 0x03) - fout << ", Value: 0x" << hex << uppercase << temp.value; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_DEFAULTSTORE_OP 0x5C - else if(buffer[j] == UEFI_IFR_DEFAULTSTORE_OP) { - - // Create temp - UEFI_IFR_DEFAULTSTORE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.defaultNameString = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - temp.defaultId = static_cast(static_cast(buffer[j + 4]) + (static_cast(buffer[j + 5]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Default Store: " << strings[temp.defaultNameString + stringPackages[formSets[i].usingStringPackage].structureOffset] << " 0x" << hex << uppercase << temp.defaultId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_FORM_MAP_OP 0x5D - else if(buffer[j] == UEFI_IFR_FORM_MAP_OP) { - - // Create temp - UEFI_IFR_FORM_MAP temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - temp.formId = static_cast(static_cast(buffer[j + 2]) + (static_cast(buffer[j + 3]) << 8)); - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Form Map: 0x" << hex << uppercase << temp.formId; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_CATENATE_OP 0x5E - else if(buffer[j] == UEFI_IFR_CATENATE_OP) { - - // Create temp - UEFI_IFR_CATENATE temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Catenate"; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_GUID_OP 0x5F - else if(buffer[j] == UEFI_IFR_GUID_OP) { - - // Create temp - UEFI_IFR_GUID temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(0, 1, lowNibble); - temp.guid.insert(0, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(9, 1, lowNibble); - temp.guid.insert(9, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.insert(14, 1, lowNibble); - temp.guid.insert(14, 1, highNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - temp.guid.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.guid.push_back(highNibble); - temp.guid.push_back(lowNibble); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Guid: " << temp.guid; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Otherwise check if opcode if UEFI_IFR_SECURITY_OP 0x60 - else if(buffer[j] == UEFI_IFR_SECURITY_OP) { - - // Create temp - UEFI_IFR_SECURITY temp; - - // Fill temp - temp.header.offset = j; - temp.header.opcode = buffer[j]; - temp.header.length = static_cast(buffer[j + 1]) & 0x7F; - temp.header.scope = static_cast(buffer[j + 1]) & 0x80; - for(uint32_t k = j + 2; k < j + 6; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.permission.insert(0, 1, lowNibble); - temp.permission.insert(0, 1, highNibble); - } - temp.permission.push_back('-'); - for(uint32_t k = j + 6; k < j + 8; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.permission.insert(9, 1, lowNibble); - temp.permission.insert(9, 1, highNibble); - } - temp.permission.push_back('-'); - for(uint32_t k = j + 8; k < j + 10; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.permission.insert(14, 1, lowNibble); - temp.permission.insert(14, 1, highNibble); - } - temp.permission.push_back('-'); - for(uint32_t k = j + 10; k < j + 12; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.permission.push_back(highNibble); - temp.permission.push_back(lowNibble); - } - temp.permission.push_back('-'); - for(uint32_t k = j + 12; k < j + 18; k++) { - highNibble = ((buffer[k] >> 4) & 0x0F) + '0'; - lowNibble = (buffer[k] & 0x0F) + '0'; - if(highNibble > 0x39 && highNibble < 0x41) - highNibble += 0x07; - if(lowNibble > 0x39 && lowNibble < 0x41) - lowNibble += 0x07; - temp.permission.push_back(highNibble); - temp.permission.push_back(lowNibble); - } - - // Display offset - fout << "0x" << hex << uppercase << temp.header.offset << ' '; - - // Display tabs - for(uint8_t k = 0; k < numberOfTabs; k++) - fout << '\t'; - - // Display temp - fout << "Security: " << temp.permission; - - // Check if scope - if(temp.header.scope) { - - // Increment number of tabs - numberOfTabs++; - - // Add to conditional stack - conditionalStack.push_back(OTHER); - } - } - - // Display code - fout << " {"; - for(int k = 0; k < static_cast(buffer[j + 1] & 0x7F); k++) { - fout << hex << uppercase << setw(2) << setfill('0') << static_cast(static_cast(buffer[j + k])); - if(k != static_cast(buffer[j + 1] & 0x7F) - 1) - fout << ' '; - } - fout << '}' << endl; - } - - // Close file - fout.close(); -} +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +#include "UEFI.h" +#include "UEFIHeader.h" + +#if defined (__unix__) || defined (__APPLE__) +#include +#define _strcmpi strcasecmp +#endif + +// Supporting function implementation +void getUEFIStringPackages(vector &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(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) <= buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x00') { + + // Set temp string package + tempStringPackage.header.offset = i; + + tempStringPackage.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16)); + + tempStringPackage.header.type = static_cast(buffer[i + 3]); + tempStringPackage.headerSize = static_cast(static_cast(buffer[i + 4]) + (static_cast(buffer[i + 5]) << 8) + (static_cast(buffer[i + 6]) << 16) + (static_cast(buffer[i + 7]) << 24)); + + tempStringPackage.stringOffset = i + static_cast(static_cast(buffer[i + 8]) + (static_cast(buffer[i + 9]) << 8) + (static_cast(buffer[i + 10]) << 16) + (static_cast(buffer[i + 11]) << 24)); + + for (uint32_t j = 0; j < 16; j++) + tempStringPackage.languageWindow.push_back(static_cast(static_cast(buffer[i + 12 + j * 2]) + (static_cast(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 &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 &stringPackages, vector &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 &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 &formSets, const string &buffer, const vector &stringPackages, const vector &strings) { + + // Initialize variables + UEFI_IFR_FORM_SET_PACK tempFormSet; + vector 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(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) <= buffer.size() + && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x02' + && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(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(stringPackages[stringCandidates[j]].header.offset - i)) < abs(static_cast(stringPackages[chosenCandidate].header.offset - i))) + chosenCandidate = stringCandidates[j]; + + // Set temp form set + tempFormSet.header.offset = i; + tempFormSet.header.length = static_cast(static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16)); + tempFormSet.header.type = static_cast(buffer[i + 3]); + tempFormSet.titleString = static_cast(static_cast(buffer[i + 22]) + (static_cast(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 &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 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); +} + +static const char *GetString(const vector &strings, size_t index) +{ + return strings.size() > index ? strings[index].c_str() : ""; +} + +void generateUEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &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(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: " << GetString(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: " << GetString(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: " << GetString(strings, temp->Statement.Prompt + strPackageOffset); + //fout << ", Statement.Help: " << strings[temp->Statement.Help + strPackageOffset]; + fout << ", TextTwo: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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" << (unsigned)temp->MinSize; + fout << ", MaxSize 0x" << (unsigned)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: " << GetString(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): " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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: " << GetString(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" << (unsigned) temp->MinSize << ", MaxSize: 0x" << (unsigned)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: " << GetString(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: " << GetString(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 + EFI_IFR_FALSE *temp = (EFI_IFR_FALSE*)&buffer[j]; + + // Display temp + fout << "False"; + } + else if (buffer[j] == EFI_IFR_TO_UINT_OP) { + + // Create temp + EFI_IFR_TO_UINT *temp = (EFI_IFR_TO_UINT*)&buffer[j]; + + // Display temp + fout << "Convert to Unsigned Int"; + } + else if (buffer[j] == EFI_IFR_TO_STRING_OP) { + + // Create temp + EFI_IFR_TO_STRING *temp = (EFI_IFR_TO_STRING*)&buffer[j]; + + // Display temp + fout << "Convert to String: Format: 0x" << hex << uppercase << (uint16_t)temp->Format; + } + else if (buffer[j] == EFI_IFR_TO_BOOLEAN_OP) { + + // Create temp + EFI_IFR_TO_BOOLEAN *temp = (EFI_IFR_TO_BOOLEAN*)&buffer[j]; + + // Display temp + fout << "Boolean"; + } + else if (buffer[j] == EFI_IFR_MID_OP) { + + // Create temp + EFI_IFR_MID *temp = (EFI_IFR_MID*)&buffer[j]; + + // Display temp + fout << "Mid"; + } + else if (buffer[j] == EFI_IFR_FIND_OP) { + + // Create temp + EFI_IFR_FIND *temp = (EFI_IFR_FIND*)&buffer[j]; + + // Display temp + fout << "Find: Format: 0x" << hex << uppercase << (uint16_t)temp->Format; + } + else if (buffer[j] == EFI_IFR_TOKEN_OP) { + + // Create temp + EFI_IFR_TOKEN *temp = (EFI_IFR_TOKEN*)&buffer[j]; + + // Display temp + fout << "Token"; + } + else if (buffer[j] == EFI_IFR_STRING_REF1_OP) { + + // Create temp + EFI_IFR_STRING_REF1 *temp = (EFI_IFR_STRING_REF1*)&buffer[j]; + + // Display temp + fout << "String Ref: " << GetString(strings, temp->StringId + strPackageOffset) << " (0x" << hex << uppercase << temp->StringId << ")"; + } + else if (buffer[j] == EFI_IFR_STRING_REF2_OP) { + + // Create temp + EFI_IFR_STRING_REF2 *temp = (EFI_IFR_STRING_REF2*)&buffer[j]; + + // Display temp + fout << "String Ref2"; + } + else if (buffer[j] == EFI_IFR_CONDITIONAL_OP) { + + // Create temp + EFI_IFR_CONDITIONAL *temp = (EFI_IFR_CONDITIONAL*)&buffer[j]; + + // Display temp + fout << "Conditional"; + } + else if (buffer[j] == EFI_IFR_QUESTION_REF3_OP) { + + // Create temp + EFI_IFR_QUESTION_REF3 *temp = (EFI_IFR_QUESTION_REF3*)&buffer[j]; + + // Display temp + fout << "Question Ref3"; + } + else if (buffer[j] == EFI_IFR_ZERO_OP) { + + // Create temp + EFI_IFR_ZERO *temp = (EFI_IFR_ZERO*)&buffer[j]; + + // Display temp + fout << "Zero"; + } + else if (buffer[j] == EFI_IFR_ONE_OP) { + + // Create temp + EFI_IFR_ONE *temp = (EFI_IFR_ONE*)&buffer[j]; + + // Display temp + fout << "One"; + } + else if (buffer[j] == EFI_IFR_ONES_OP) { + + // Create temp + EFI_IFR_ONES *temp = (EFI_IFR_ONES*)&buffer[j]; + + // Display temp + fout << "Ones"; + } + else if (buffer[j] == EFI_IFR_UNDEFINED_OP) { + + // Create temp + EFI_IFR_UNDEFINED *temp = (EFI_IFR_UNDEFINED*)&buffer[j]; + + // Display temp + fout << "Undefined"; + } + else if (buffer[j] == EFI_IFR_LENGTH_OP) { + + // Create temp + EFI_IFR_LENGTH *temp = (EFI_IFR_LENGTH*)&buffer[j]; + + // Display temp + fout << "Length"; + } + else if (buffer[j] == EFI_IFR_DUP_OP) { + + // Create temp + EFI_IFR_DUP *temp = (EFI_IFR_DUP*)&buffer[j]; + + // Display temp + fout << "Dup"; + } + else if (buffer[j] == EFI_IFR_THIS_OP) { + + // Create temp + EFI_IFR_THIS *temp = (EFI_IFR_THIS*)&buffer[j]; + + // Display temp + fout << "This"; + } + else if (buffer[j] == EFI_IFR_SPAN_OP) { + + // Create temp + EFI_IFR_SPAN *temp = (EFI_IFR_SPAN*)&buffer[j]; + + // Display temp + fout << "Span: Flags: 0x" << hex << uppercase << (uint16_t)temp->Flags; + } + else if (buffer[j] == EFI_IFR_VALUE_OP) { + + // Create temp + EFI_IFR_VALUE *temp = (EFI_IFR_VALUE*)&buffer[j]; + + // Display temp + fout << "Value"; + } + else if (buffer[j] == EFI_IFR_DEFAULT_OP) { + + // Create temp + EFI_IFR_DEFAULT *temp = (EFI_IFR_DEFAULT*)&buffer[j]; + + // Display temp + fout << "Default: DefaultId: 0x" << hex << uppercase << temp->DefaultId << ", 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): " << GetString(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)"; + } + else if (buffer[j] == EFI_IFR_DEFAULTSTORE_OP) { + + // Create temp + EFI_IFR_DEFAULTSTORE *temp = (EFI_IFR_DEFAULTSTORE*)&buffer[j]; + + // Display temp + fout << "Default Store: " << GetString(strings, temp->DefaultName + strPackageOffset) << ", DefaultId: 0x" << hex << uppercase << temp->DefaultId; + } + else if (buffer[j] == EFI_IFR_FORM_MAP_OP) { + + // Create temp + EFI_IFR_FORM_MAP *temp = (EFI_IFR_FORM_MAP*)&buffer[j]; + + // Display temp + fout << "Form Map: FormId: 0x" << hex << uppercase << temp->FormId; + // Methods? + } + else if (buffer[j] == EFI_IFR_CATENATE_OP) { + + // Create temp + EFI_IFR_CATENATE *temp = (EFI_IFR_CATENATE*)&buffer[j]; + + // Display temp + fout << "Catenate"; + } + else if (buffer[j] == EFI_IFR_GUID_OP) { + + // Create temp + EFI_IFR_GUID *temp = (EFI_IFR_GUID*)&buffer[j]; + + // Display temp + fout << "Guid: [" << GuidToString(temp->Guid) << "]"; + // TODO: optional data? + } + else if (buffer[j] == EFI_IFR_SECURITY_OP) { + + // Create temp + EFI_IFR_SECURITY *temp = (EFI_IFR_SECURITY*)&buffer[j]; + + // Display temp + fout << "Security: Permissions: [" << GuidToString(temp->Permissions) << "]"; + } + else if (buffer[j] == EFI_IFR_MODAL_TAG_OP) { + + // Create temp + EFI_IFR_MODAL_TAG *temp = (EFI_IFR_MODAL_TAG*)&buffer[j]; + + // Display temp + fout << "Modal Tag"; + } + else if (buffer[j] == EFI_IFR_REFRESH_ID_OP) { + + // Create temp + EFI_IFR_REFRESH_ID *temp = (EFI_IFR_REFRESH_ID*)&buffer[j]; + + // Display temp + fout << "Refresh Id: [" << GuidToString(temp->RefreshEventGroupId) << "]"; + } + else if (buffer[j] == EFI_IFR_WARNING_IF_OP) { + + // Create temp + EFI_IFR_WARNING_IF *temp = (EFI_IFR_WARNING_IF*)&buffer[j]; + + // Display temp + fout << "Warning If: " << GetString(strings, temp->Warning + strPackageOffset) << ", TimeOut: 0x" << hex << uppercase << temp->TimeOut; + } + else if (buffer[j] == EFI_IFR_MATCH2_OP) { + + // Create temp + EFI_IFR_MATCH2 *temp = (EFI_IFR_MATCH2*)&buffer[j]; + + // Display temp + fout << "Match2: SyntaxType: [" << GuidToString(temp->SyntaxType) << "]"; + } + else { + + // Create temp + EFI_IFR_OP_HEADER *temp = (EFI_IFR_OP_HEADER*)&buffer[j]; + + // Display temp + fout << "Unknown EFI_IFR OpCode: 0x" << hex << uppercase << (uint16_t)temp->OpCode << ", Length: " << temp->Length << ", Scope: " << temp->Scope; + } + + EFI_IFR_OP_HEADER *opHdr = (EFI_IFR_OP_HEADER*)&buffer[j]; + if (opHdr->Scope) { + if (opHdr->OpCode == EFI_IFR_FORM_OP) + IndentText(FORM); + else if (opHdr->OpCode == EFI_IFR_ONE_OF_OP) + IndentText(OPTION); + else if (opHdr->OpCode == EFI_IFR_SUPPRESS_IF_OP || opHdr->OpCode == EFI_IFR_NO_SUBMIT_IF_OP || opHdr->OpCode == EFI_IFR_INCONSISTENT_IF_OP || opHdr->OpCode == EFI_IFR_GRAY_OUT_IF_OP || opHdr->OpCode == EFI_IFR_DISABLE_IF_OP || opHdr->OpCode == EFI_IFR_WARNING_IF_OP) + IndentText(CONDITION); + else if (opHdr->OpCode == EFI_IFR_FORM_SET_OP) + IndentText(FORM_SET); + else + IndentText(OTHER); + } + + // Display code + fout << " {"; + for (uint32_t k = 0; k < static_cast(buffer[j + 1] & 0x7F); k++) { + fout << hex << uppercase << setw(2) << setfill('0') << static_cast(static_cast(buffer[j + k])); + if (k != static_cast(buffer[j + 1] & 0x7F) - 1) + fout << ' '; + } + fout << '}' << endl; + } + } + + // Close file + fout.close(); +} diff --git a/UEFI.h b/UEFI.h old mode 100755 new mode 100644 index dfd3f05..22b11d5 --- a/UEFI.h +++ b/UEFI.h @@ -1,684 +1,83 @@ -// Header gaurd -#ifndef UEFI_H -#define UEFI_H - - -// Header files -#include -#include -#include - -using namespace std; - - -// Gobal definitions -enum { FORM_SET, FORM, CONDITION, OPTION, OTHER }; - -#define UEFI_IFR_FORM_OP '\x01' -#define UEFI_IFR_SUBTITLE_OP '\x02' -#define UEFI_IFR_TEXT_OP '\x03' -#define UEFI_IFR_IMAGE_OP '\x04' -#define UEFI_IFR_ONE_OF_OP '\x05' -#define UEFI_IFR_CHECKBOX_OP '\x06' -#define UEFI_IFR_NUMERIC_OP '\x07' -#define UEFI_IFR_PASSWORD_OP '\x08' -#define UEFI_IFR_ONE_OF_OPTION_OP '\x09' -#define UEFI_IFR_SUPPRESS_IF_OP '\x0A' -#define UEFI_IFR_LOCKED_OP '\x0B' -#define UEFI_IFR_ACTION_OP '\x0C' -#define UEFI_IFR_RESET_BUTTON_OP '\x0D' -#define UEFI_IFR_FORM_SET_OP '\x0E' -#define UEFI_IFR_REF_OP '\x0F' -#define UEFI_IFR_NO_SUBMIT_IF_OP '\x10' -#define UEFI_IFR_INCONSISTENT_IF_OP '\x11' -#define UEFI_IFR_EQ_ID_VAL_OP '\x12' -#define UEFI_IFR_EQ_ID_ID_OP '\x13' -#define UEFI_IFR_EQ_ID_LIST_OP '\x14' -#define UEFI_IFR_AND_OP '\x15' -#define UEFI_IFR_OR_OP '\x16' -#define UEFI_IFR_NOT_OP '\x17' -#define UEFI_IFR_RULE_OP '\x18' -#define UEFI_IFR_GRAY_OUT_IF_OP '\x19' -#define UEFI_IFR_DATE_OP '\x1A' -#define UEFI_IFR_TIME_OP '\x1B' -#define UEFI_IFR_STRING_OP '\x1C' -#define UEFI_IFR_REFRESH_OP '\x1D' -#define UEFI_IFR_DISABLE_IF_OP '\x1E' -#define UEFI_IFR_ANIMATION_OP '\x1F' -#define UEFI_IFR_TO_LOWER_OP '\x20' -#define UEFI_IFR_TO_UPPER_OP '\x21' -#define UEFI_IFR_MAP_OP '\x22' -#define UEFI_IFR_ORDERED_LIST_OP '\x23' -#define UEFI_IFR_VARSTORE_OP '\x24' -#define UEFI_IFR_VARSTORE_NAME_VALUE_OP '\x25' -#define UEFI_IFR_VARSTORE_EFI_OP '\x26' -#define UEFI_IFR_VARSTORE_DEVICE_OP '\x27' -#define UEFI_IFR_VERSION_OP '\x28' -#define UEFI_IFR_END_OP '\x29' -#define UEFI_IFR_MATCH_OP '\x2A' -#define UEFI_IFR_GET_OP '\x2B' -#define UEFI_IFR_SET_OP '\x2C' -#define UEFI_IFR_READ_OP '\x2D' -#define UEFI_IFR_WRITE_OP '\x2E' -#define UEFI_IFR_EQUAL_OP '\x2F' -#define UEFI_IFR_NOT_EQUAL_OP '\x30' -#define UEFI_IFR_GREATER_THAN_OP '\x31' -#define UEFI_IFR_GREATER_EQUAL_OP '\x32' -#define UEFI_IFR_LESS_THAN_OP '\x33' -#define UEFI_IFR_LESS_EQUAL_OP '\x34' -#define UEFI_IFR_BITWISE_AND_OP '\x35' -#define UEFI_IFR_BITWISE_OR_OP '\x36' -#define UEFI_IFR_BITWISE_NOT_OP '\x37' -#define UEFI_IFR_SHIFT_LEFT_OP '\x38' -#define UEFI_IFR_SHIFT_RIGHT_OP '\x39' -#define UEFI_IFR_ADD_OP '\x3A' -#define UEFI_IFR_SUBTRACT_OP '\x3B' -#define UEFI_IFR_MULTIPLY_OP '\x3C' -#define UEFI_IFR_DIVIDE_OP '\x3D' -#define UEFI_IFR_MODULO_OP '\x3E' -#define UEFI_IFR_RULE_REF_OP '\x3F' -#define UEFI_IFR_QUESTION_REF1_OP '\x40' -#define UEFI_IFR_QUESTION_REF2_OP '\x41' -#define UEFI_IFR_UINT8_OP '\x42' -#define UEFI_IFR_UINT16_OP '\x43' -#define UEFI_IFR_UINT32_OP '\x44' -#define UEFI_IFR_UINT64_OP '\x45' -#define UEFI_IFR_TRUE_OP '\x46' -#define UEFI_IFR_FALSE_OP '\x47' -#define UEFI_IFR_TO_UINT_OP '\x48' -#define UEFI_IFR_TO_STRING_OP '\x49' -#define UEFI_IFR_TO_BOOLEAN_OP '\x4A' -#define UEFI_IFR_MID_OP '\x4B' -#define UEFI_IFR_FIND_OP '\x4C' -#define UEFI_IFR_TOKEN_OP '\x4D' -#define UEFI_IFR_STRING_REF1_OP '\x4E' -#define UEFI_IFR_STRING_REF2_OP '\x4F' -#define UEFI_IFR_CONDITIONAL_OP '\x50' -#define UEFI_IFR_QUESTION_REF3_OP '\x51' -#define UEFI_IFR_ZERO_OP '\x52' -#define UEFI_IFR_ONE_OP '\x53' -#define UEFI_IFR_ONES_OP '\x54' -#define UEFI_IFR_UNDEFINED_OP '\x55' -#define UEFI_IFR_LENGTH_OP '\x56' -#define UEFI_IFR_DUP_OP '\x57' -#define UEFI_IFR_THIS_OP '\x58' -#define UEFI_IFR_SPAN_OP '\x59' -#define UEFI_IFR_VALUE_OP '\x5A' -#define UEFI_IFR_DEFAULT_OP '\x5B' -#define UEFI_IFR_DEFAULTSTORE_OP '\x5C' -#define UEFI_IFR_FORM_MAP_OP '\x5D' -#define UEFI_IFR_CATENATE_OP '\x5E' -#define UEFI_IFR_GUID_OP '\x5F' -#define UEFI_IFR_SECURITY_OP '\x60' - - -// Classes/structs -struct UEFI_HII_PACK_HEADER { - uint32_t offset; - uint32_t length; - uint8_t type; -}; - -struct UEFI_IFR_STRING_PACK { - UEFI_HII_PACK_HEADER header; - uint32_t headerSize; - uint32_t stringOffset; - vector languageWindow; - string language; - uint32_t structureOffset; -}; - -struct UEFI_IFR_FORM_SET_PACK { - UEFI_HII_PACK_HEADER header; - uint16_t titleString; - uint32_t usingStringPackage; - string title; -}; - -struct UEFI_IFR_OP_HEADER { - uint32_t offset; - uint8_t opcode; - uint8_t length; - uint8_t scope; -}; - -struct UEFI_IFR_STATEMENT_HEADER { - uint16_t promptString; - uint16_t helpString; -}; - -struct UEFI_IFR_QUESTION_HEADER { - UEFI_IFR_STATEMENT_HEADER statement; - uint16_t questionId; - uint16_t varStoreId; - uint16_t varOffset; - uint8_t flags; -}; - -union MINMAXSTEP_DATA { - uint64_t minimumValue; - uint64_t maximumValue; - uint64_t step; -}; - -struct UEFI_IFR_FORM_SET { - UEFI_IFR_OP_HEADER header; - string guid; - uint16_t titleString; - uint16_t helpString; - uint8_t flags; - string classGuid; -}; - -struct UEFI_IFR_FORM { - UEFI_IFR_OP_HEADER header; - uint16_t formId; - uint16_t titleString; -}; - -struct UEFI_IFR_VARSTORE { - UEFI_IFR_OP_HEADER header; - string guid; - uint16_t varStoreId; - uint16_t size; - string name; -}; - -struct UEFI_IFR_VARSTORE_EFI { - UEFI_IFR_OP_HEADER header; - uint16_t varStoreId; - string guid; - uint32_t attributes; -}; - -struct UEFI_IFR_VARSTORE_NAME_VALUE { - UEFI_IFR_OP_HEADER header; - uint16_t varStoreId; - string guid; -}; - -struct UEFI_IFR_END { - UEFI_IFR_OP_HEADER header; - uint8_t condition; -}; - -struct UEFI_IFR_IMAGE { - UEFI_IFR_OP_HEADER header; - uint16_t imageId; -}; - -struct UEFI_IFR_LOCKED { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_RULE { - UEFI_IFR_OP_HEADER header; - uint8_t ruleId; -}; - -struct UEFI_IFR_DEFAULT { - UEFI_IFR_OP_HEADER header; - uint16_t defaultId; - uint8_t type; - uint64_t value; -}; - -struct UEFI_IFR_DEFAULTSTORE { - UEFI_IFR_OP_HEADER header; - uint16_t defaultNameString; - uint16_t defaultId; -}; - -struct UEFI_IFR_VALUE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SUBTITLE { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_STATEMENT_HEADER statement; - uint8_t flags; -}; - -struct UEFI_IFR_CHECKBOX { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t flags; -}; - -struct UEFI_IFR_TEXT { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_STATEMENT_HEADER statement; - uint16_t secondaryTextString; -}; - -struct UEFI_IFR_REF { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint16_t formId; -}; - -struct UEFI_IFR_RESET_BUTTON { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_STATEMENT_HEADER statement; - uint16_t defaultId; -}; - -struct UEFI_IFR_ACTION { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint16_t questionConfigString; -}; - -struct UEFI_IFR_DATE { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t flags; -}; - -struct UEFI_IFR_NUMERIC { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t flags; - MINMAXSTEP_DATA data; -}; - -struct UEFI_IFR_ONE_OF { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t flags; - MINMAXSTEP_DATA data; -}; - -struct UEFI_IFR_STRING { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t minimumSize; - uint8_t maximumSize; - uint8_t flags; -}; - -struct UEFI_IFR_PASSWORD { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint16_t minimumSize; - uint16_t maximumSize; -}; - -struct UEFI_IFR_ORDERED_LIST { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t minimumContainers; - uint8_t flags; -}; - -struct UEFI_IFR_TIME { - UEFI_IFR_OP_HEADER header; - UEFI_IFR_QUESTION_HEADER question; - uint8_t flags; -}; - -struct UEFI_IFR_DISABLE_IF { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SUPPRESS_IF { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_GRAY_OUT_IF { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_INCONSISTENT_IF { - UEFI_IFR_OP_HEADER header; - uint16_t errorString; -}; - -struct UEFI_IFR_NO_SUBMIT_IF { - UEFI_IFR_OP_HEADER header; - uint16_t errorString; -}; - -struct UEFI_IFR_REFRESH { - UEFI_IFR_OP_HEADER header; - uint8_t refreshInterval; -}; - -struct UEFI_IFR_VARSTORE_DEVICE { - UEFI_IFR_OP_HEADER header; - uint16_t devicePathString; -}; - -struct UEFI_IFR_ONE_OF_OPTION { - UEFI_IFR_OP_HEADER header; - uint16_t optionString; - uint8_t flags; - uint8_t type; - uint64_t value; -}; - -struct UEFI_IFR_GUID { - UEFI_IFR_OP_HEADER header; - string guid; -}; - -struct UEFI_IFR_DUP { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_EQ_ID_ID { - UEFI_IFR_OP_HEADER header; - uint16_t primaryQuestionId; - uint16_t secondaryQuestionId; -}; - -struct UEFI_IFR_EQ_ID_VAL { - UEFI_IFR_OP_HEADER header; - uint16_t questionId; - uint16_t value; -}; - -struct UEFI_IFR_EQ_ID_LIST { - UEFI_IFR_OP_HEADER header; - uint16_t questionId; - uint16_t listLength; - vector valueList; -}; - -struct UEFI_IFR_UINT8 { - UEFI_IFR_OP_HEADER header; - uint8_t value; -}; - -struct UEFI_IFR_UINT16 { - UEFI_IFR_OP_HEADER header; - uint16_t value; -}; - -struct UEFI_IFR_UINT32 { - UEFI_IFR_OP_HEADER header; - uint32_t value; -}; - -struct UEFI_IFR_UINT64 { - UEFI_IFR_OP_HEADER header; - uint64_t value; -}; - -struct UEFI_IFR_QUESTION_REF1 { - UEFI_IFR_OP_HEADER header; - uint16_t questionId; -}; - -struct UEFI_IFR_QUESTION_REF2 { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_QUESTION_REF3 { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_RULE_REF { - UEFI_IFR_OP_HEADER header; - uint8_t ruleId; -}; - -struct UEFI_IFR_STRING_REF1 { - UEFI_IFR_OP_HEADER header; - uint16_t stringId; -}; - -struct UEFI_IFR_STRING_REF2 { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_THIS { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TRUE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_FALSE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_ONE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_ONES { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_ZERO { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_UNDEFINED { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_VERSION { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_LENGTH { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_NOT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_BITWISE_NOT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TO_BOOLEAN { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TO_STRING { - UEFI_IFR_OP_HEADER header; - uint8_t format; -}; - -struct UEFI_IFR_TO_UINT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TO_UPPER { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TO_LOWER { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_ADD { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_AND { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_BITWISE_AND { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_BITWISE_OR { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_CATENATE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_DIVIDE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_EQUAL { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_GREATER_EQUAL { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_GREATER_THAN { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_LESS_EQUAL { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_LESS_THAN { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_MATCH { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_MULTIPLY { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_MODULO { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_NOT_EQUAL { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_OR { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SHIFT_LEFT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SHIFT_RIGHT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SUBTRACT { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_CONDITIONAL { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_FIND { - UEFI_IFR_OP_HEADER header; - uint8_t format; -}; - -struct UEFI_IFR_MID { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_TOKEN { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_SPAN { - UEFI_IFR_OP_HEADER header; - uint8_t flags; -}; - -struct UEFI_IFR_SECURITY { - UEFI_IFR_OP_HEADER header; - string permission; -}; - -struct UEFI_IFR_FORM_MAP { - UEFI_IFR_OP_HEADER header; - uint16_t formId; -}; - -struct UEFI_IFR_SET { - UEFI_IFR_OP_HEADER header; - uint16_t varStoreId; - uint16_t varOffset; - uint8_t varStoreType; -}; - -struct UEFI_IFR_GET { - UEFI_IFR_OP_HEADER header; - uint16_t varStoreId; - uint16_t varOffset; - uint8_t varStoreType; -}; - -struct UEFI_IFR_READ { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_WRITE { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_MAP { - UEFI_IFR_OP_HEADER header; -}; - -struct UEFI_IFR_ANIMATION { - UEFI_IFR_OP_HEADER header; - uint16_t animationId; -}; - - -// Function prototypes -/* -Name: getUEFIStringPackages -Purpose: Gets UEFI string packages -*/ -void getUEFIStringPackages(vector &stringPackages, const string &buffer); - -/* -Name: displayUEFIStringPackages -Purpose: Displays UEFI string packages -*/ -void displayUEFIStringPackages(const vector &stringPackages); - -/* -Name: getUEFIStrings -Purpose: Gets strings from string package -*/ -void getUEFIStrings(vector &stringPackages, vector &strings, const string &buffer); - -/* -Name: displayUEFIStrings -Purpose: Displays UEFI strings -*/ -void displayUEFIStrings(const vector &strings); - -/* -Name: getUEFIFormSets -Purpose: Gets UEFI form sets -*/ -void getUEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings); - -/* -Name: displayUEFIFormSets -Purpose: Displays UEFI form sets -*/ -void displayUEFIFormSets(const vector &formSets); - -/* -Name: generateUEFIIFRDump -Purpose: Generates UEFI IFR dump -*/ -void generateUEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings); - - -#endif +// Header guard +#ifndef UEFI_H +#define UEFI_H + +// Header files +#include +#include +#include +#include + +using namespace std; + +// Global definitions +enum { FORM_SET, FORM, CONDITION, OPTION, OTHER }; + +// Classes/structs +struct UEFI_HII_PACK_HEADER { + uint32_t offset; + uint32_t length; + uint8_t type; +}; + +struct UEFI_IFR_STRING_PACK { + UEFI_HII_PACK_HEADER header; + uint32_t headerSize; + uint32_t stringOffset; + vector languageWindow; + string language; + uint32_t structureOffset; +}; + +struct UEFI_IFR_FORM_SET_PACK { + UEFI_HII_PACK_HEADER header; + uint16_t titleString; + uint32_t usingStringPackage; + string title; +}; + +// Function prototypes +/* +Name: getUEFIStringPackages +Purpose: Gets UEFI string packages +*/ +void getUEFIStringPackages(vector &stringPackages, const string &buffer); + +/* +Name: displayUEFIStringPackages +Purpose: Displays UEFI string packages +*/ +void displayUEFIStringPackages(const vector &stringPackages); + +/* +Name: getUEFIStrings +Purpose: Gets strings from string package +*/ +void getUEFIStrings(vector &stringPackages, vector &strings, const string &buffer); + +/* +Name: displayUEFIStrings +Purpose: Displays UEFI strings +*/ +void displayUEFIStrings(const vector &strings); + +/* +Name: getUEFIFormSets +Purpose: Gets UEFI form sets +*/ +void getUEFIFormSets(vector &formSets, const string &buffer, const vector &stringPackages, const vector &strings); + +/* +Name: displayUEFIFormSets +Purpose: Displays UEFI form sets +*/ +void displayUEFIFormSets(const vector &formSets); + +/* +Name: generateUEFIIFRDump +Purpose: Generates UEFI IFR dump +*/ +void generateUEFIIFRDump(const string &outputFile, const vector &stringPackages, const vector &formSets, const string &buffer, const vector &strings); + + +#endif diff --git a/UEFIHeader.h b/UEFIHeader.h new file mode 100644 index 0000000..56a38a3 --- /dev/null +++ b/UEFIHeader.h @@ -0,0 +1,1038 @@ +#ifndef UEFI_HEADER_H +#define UEFI_HEADER_H +#include + +typedef char CHAR8; +typedef char16_t CHAR16; +typedef uint8_t BOOLEAN; +typedef uint8_t UINT8; +typedef uint16_t UINT16; +typedef uint32_t UINT32; +typedef uint64_t UINT64; + +typedef UINT16 EFI_QUESTION_ID; +typedef UINT16 EFI_IMAGE_ID; +typedef UINT16 EFI_STRING_ID; +typedef UINT16 EFI_FORM_ID; +typedef UINT16 EFI_VARSTORE_ID; +typedef UINT16 EFI_ANIMATION_ID; +typedef UINT16 EFI_DEFAULT_ID; + +typedef UINT32 EFI_HII_FONT_STYLE; + +#pragma pack(push, 1) + +typedef struct { + UINT32 Data1; + UINT16 Data2; + UINT16 Data3; + UINT8 Data4[8]; +} EFI_GUID; + +/// +/// The header found at the start of each package list. +/// +typedef struct { + EFI_GUID PackageListGuid; + UINT32 PackageLength; +} EFI_HII_PACKAGE_LIST_HEADER; + +/// +/// The header found at the start of each package. +/// +typedef struct { + UINT32 Length : 24; + UINT32 Type : 8; + // UINT8 Data[...]; +} EFI_HII_PACKAGE_HEADER; + +// +// Value of HII package type +// +#define EFI_HII_PACKAGE_TYPE_ALL 0x00 +#define EFI_HII_PACKAGE_TYPE_GUID 0x01 +#define EFI_HII_PACKAGE_FORMS 0x02 +#define EFI_HII_PACKAGE_STRINGS 0x04 +#define EFI_HII_PACKAGE_FONTS 0x05 +#define EFI_HII_PACKAGE_IMAGES 0x06 +#define EFI_HII_PACKAGE_SIMPLE_FONTS 0x07 +#define EFI_HII_PACKAGE_DEVICE_PATH 0x08 +#define EFI_HII_PACKAGE_KEYBOARD_LAYOUT 0x09 +#define EFI_HII_PACKAGE_ANIMATIONS 0x0A +#define EFI_HII_PACKAGE_END 0xDF +#define EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN 0xE0 +#define EFI_HII_PACKAGE_TYPE_SYSTEM_END 0xFF + +/// +/// The fixed header consists of a standard record header and then the string identifiers +/// contained in this section and the offsets of the string and language information. +/// +typedef struct _EFI_HII_STRING_PACKAGE_HDR { + EFI_HII_PACKAGE_HEADER Header; + UINT32 HdrSize; + UINT32 StringInfoOffset; + CHAR16 LanguageWindow[16]; + EFI_STRING_ID LanguageName; + CHAR8 Language[1]; +} EFI_HII_STRING_PACKAGE_HDR; + +typedef struct { + UINT8 BlockType; +} EFI_HII_STRING_BLOCK; + +// +// Value of different string information block types +// +#define EFI_HII_SIBT_END 0x00 // The end of the string information. +#define EFI_HII_SIBT_STRING_SCSU 0x10 // Single string using default font information. +#define EFI_HII_SIBT_STRING_SCSU_FONT 0x11 // Single string with font information. +#define EFI_HII_SIBT_STRINGS_SCSU 0x12 // Multiple strings using default font information. +#define EFI_HII_SIBT_STRINGS_SCSU_FONT 0x13 // Multiple strings with font information. +#define EFI_HII_SIBT_STRING_UCS2 0x14 // Single UCS - 2 string using default font information. +#define EFI_HII_SIBT_STRING_UCS2_FONT 0x15 // Single UCS - 2 string with font information +#define EFI_HII_SIBT_STRINGS_UCS2 0x16 // Multiple UCS - 2 strings using default font information. +#define EFI_HII_SIBT_STRINGS_UCS2_FONT 0x17 // Multiple UCS - 2 strings with font information. +#define EFI_HII_SIBT_DUPLICATE 0x20 // Create a duplicate of an existing string. +#define EFI_HII_SIBT_SKIP2 0x21 // Skip a certain number of string identifiers. +#define EFI_HII_SIBT_SKIP1 0x22 // Skip a certain number of string identifiers. +#define EFI_HII_SIBT_EXT1 0x30 // For future expansion(one byte length field) +#define EFI_HII_SIBT_EXT2 0x31 // For future expansion(two byte length field) +#define EFI_HII_SIBT_EXT4 0x32 // For future expansion(four byte length field) +#define EFI_HII_SIBT_FONT 0x40 // Font information. + +// +// Definition of different string information block types +// + +typedef struct _EFI_HII_SIBT_DUPLICATE_BLOCK { + EFI_HII_STRING_BLOCK Header; + EFI_STRING_ID StringId; +} EFI_HII_SIBT_DUPLICATE_BLOCK; + +typedef struct _EFI_HII_SIBT_END_BLOCK { + EFI_HII_STRING_BLOCK Header; +} EFI_HII_SIBT_END_BLOCK; + +typedef struct _EFI_HII_SIBT_EXT1_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 BlockType2; + UINT8 Length; +} EFI_HII_SIBT_EXT1_BLOCK; + +typedef struct _EFI_HII_SIBT_EXT2_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 BlockType2; + UINT16 Length; +} EFI_HII_SIBT_EXT2_BLOCK; + +typedef struct _EFI_HII_SIBT_EXT4_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 BlockType2; + UINT32 Length; +} EFI_HII_SIBT_EXT4_BLOCK; + +typedef struct _EFI_HII_SIBT_FONT_BLOCK { + EFI_HII_SIBT_EXT2_BLOCK Header; + UINT8 FontId; + UINT16 FontSize; + EFI_HII_FONT_STYLE FontStyle; + CHAR16 FontName[1]; +} EFI_HII_SIBT_FONT_BLOCK; + +typedef struct _EFI_HII_SIBT_SKIP1_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 SkipCount; +} EFI_HII_SIBT_SKIP1_BLOCK; + +typedef struct _EFI_HII_SIBT_SKIP2_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT16 SkipCount; +} EFI_HII_SIBT_SKIP2_BLOCK; + +typedef struct _EFI_HII_SIBT_STRING_SCSU_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 StringText[1]; +} EFI_HII_SIBT_STRING_SCSU_BLOCK; + +typedef struct _EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 FontIdentifier; + UINT8 StringText[1]; +} EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK; + +typedef struct _EFI_HII_SIBT_STRINGS_SCSU_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT16 StringCount; + UINT8 StringText[1]; +} EFI_HII_SIBT_STRINGS_SCSU_BLOCK; + +typedef struct _EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 FontIdentifier; + UINT16 StringCount; + UINT8 StringText[1]; +} EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK; + +typedef struct _EFI_HII_SIBT_STRING_UCS2_BLOCK { + EFI_HII_STRING_BLOCK Header; + CHAR16 StringText[1]; +} EFI_HII_SIBT_STRING_UCS2_BLOCK; + +typedef struct _EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 FontIdentifier; + CHAR16 StringText[1]; +} EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK; + +typedef struct _EFI_HII_SIBT_STRINGS_UCS2_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT16 StringCount; + CHAR16 StringText[1]; +} EFI_HII_SIBT_STRINGS_UCS2_BLOCK; + +typedef struct _EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK { + EFI_HII_STRING_BLOCK Header; + UINT8 FontIdentifier; + UINT16 StringCount; + CHAR16 StringText[1]; +} EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK; + +/// +/// The Form package is used to carry form-based encoding data. +/// +typedef struct _EFI_HII_FORM_PACKAGE_HDR { + EFI_HII_PACKAGE_HEADER Header; + //EFI_IFR_OP_HEADER OpCodeHeader; + //More op-codes follow +} EFI_HII_FORM_PACKAGE_HDR; + +typedef struct { + UINT8 Hour; + UINT8 Minute; + UINT8 Second; +} EFI_HII_TIME; + +typedef struct { + UINT16 Year; + UINT8 Month; + UINT8 Day; +} EFI_HII_DATE; + +typedef struct { + EFI_QUESTION_ID QuestionId; + EFI_FORM_ID FormId; + EFI_GUID FormSetGuid; + EFI_STRING_ID DevicePath; +} EFI_HII_REF; + +typedef union { + UINT8 u8; // EFI_IFR_TYPE_NUM_SIZE_8 + UINT16 u16; // EFI_IFR_TYPE_NUM_SIZE_16 + UINT32 u32; // EFI_IFR_TYPE_NUM_SIZE_32 + UINT64 u64; // EFI_IFR_TYPE_NUM_SIZE_64 + BOOLEAN b; // EFI_IFR_TYPE_BOOLEAN + EFI_HII_TIME time; // EFI_IFR_TYPE_TIME + EFI_HII_DATE date; // EFI_IFR_TYPE_DATE + EFI_STRING_ID string; // EFI_IFR_TYPE_STRING, EFI_IFR_TYPE_ACTION + EFI_HII_REF ref; // EFI_IFR_TYPE_REF + // UINT8 buffer[]; // EFI_IFR_TYPE_BUFFER +} EFI_IFR_TYPE_VALUE; + +// +// Definitions of IFR Standard Headers +// Section 27.3.8.2 +// + +typedef struct _EFI_IFR_OP_HEADER { + UINT8 OpCode; + UINT8 Length : 7; + UINT8 Scope : 1; +} EFI_IFR_OP_HEADER; + +typedef struct _EFI_IFR_STATEMENT_HEADER { + EFI_STRING_ID Prompt; + EFI_STRING_ID Help; +} EFI_IFR_STATEMENT_HEADER; + +typedef struct _EFI_IFR_QUESTION_HEADER { + EFI_IFR_STATEMENT_HEADER Header; + EFI_QUESTION_ID QuestionId; + EFI_VARSTORE_ID VarStoreId; + union { + EFI_STRING_ID VarName; + UINT16 VarOffset; + } VarStoreInfo; + UINT8 Flags; +} EFI_IFR_QUESTION_HEADER; + +// +// Flag values of EFI_IFR_QUESTION_HEADER +// +#define EFI_IFR_FLAG_READ_ONLY 0x01 +#define EFI_IFR_FLAG_CALLBACK 0x04 +#define EFI_IFR_FLAG_RESET_REQUIRED 0x10 +#define EFI_IFR_FLAG_RECONNECT_REQUIRED 0x40 +#define EFI_IFR_FLAG_OPTIONS_ONLY 0x80 + +// +// Definition for Opcode Reference +// Section 27.3.8.3 +// + +typedef struct _EFI_IFR_ACTION { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + EFI_STRING_ID QuestionConfig; +} EFI_IFR_ACTION; + +typedef struct _EFI_IFR_ACTION_1 { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; +}_EFI_IFR_ACTION_1; + +typedef struct _EFI_IFR_ANIMATION { + EFI_IFR_OP_HEADER Header; + EFI_ANIMATION_ID Id; +} EFI_IFR_ANIMATION; + +typedef struct _EFI_IFR_ADD { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_ADD; + +typedef struct _EFI_IFR_AND { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_AND; + +typedef struct _EFI_IFR_BITWISE_AND { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_BITWISE_AND; + +typedef struct _EFI_IFR_BITWISE_NOT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_BITWISE_NOT; + +typedef struct _EFI_IFR_BITWISE_OR { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_BITWISE_OR; + +typedef struct _EFI_IFR_CATENATE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_CATENATE; + +typedef struct _EFI_IFR_CHECKBOX { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 Flags; +} EFI_IFR_CHECKBOX; + +#define EFI_IFR_CHECKBOX_DEFAULT 0x01 +#define EFI_IFR_CHECKBOX_DEFAULT_MFG 0x02 + +typedef struct _EFI_IFR_CONDITIONAL { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_CONDITIONAL; + +typedef struct _EFI_IFR_DATE { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 Flags; +} EFI_IFR_DATE; + +#define EFI_QF_DATE_YEAR_SUPPRESS 0x01 +#define EFI_QF_DATE_MONTH_SUPPRESS 0x02 +#define EFI_QF_DATE_DAY_SUPPRESS 0x04 +#define EFI_QF_DATE_STORAGE 0x30 + +#define QF_DATE_STORAGE_NORMAL 0x00 +#define QF_DATE_STORAGE_TIME 0x10 +#define QF_DATE_STORAGE_WAKEUP 0x20 + +typedef struct _EFI_IFR_DEFAULT { + EFI_IFR_OP_HEADER Header; + UINT16 DefaultId; + UINT8 Type; + EFI_IFR_TYPE_VALUE Value; +} EFI_IFR_DEFAULT; + +typedef struct _EFI_IFR_DEFAULT_2 { + EFI_IFR_OP_HEADER Header; + UINT16 DefaultId; + UINT8 Type; +} EFI_IFR_DEFAULT_2; + +typedef struct _EFI_IFR_DEFAULTSTORE { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID DefaultName; + UINT16 DefaultId; +} EFI_IFR_DEFAULTSTORE; + +typedef struct _EFI_IFR_DISABLE_IF { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_DISABLE_IF; + +typedef struct _EFI_IFR_DIVIDE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_DIVIDE; + +typedef struct _EFI_IFR_DUP { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_DUP; + +typedef struct _EFI_IFR_END { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_END; + +typedef struct _EFI_IFR_EQUAL { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_EQUAL; + +typedef struct _EFI_IFR_EQ_ID_ID { + EFI_IFR_OP_HEADER Header; + EFI_QUESTION_ID QuestionId1; + EFI_QUESTION_ID QuestionId2; +} EFI_IFR_EQ_ID_ID; + +typedef struct _EFI_IFR_EQ_ID_VAL_LIST { + EFI_IFR_OP_HEADER Header; + EFI_QUESTION_ID QuestionId; + UINT16 ListLength; + UINT16 ValueList[1]; +} EFI_IFR_EQ_ID_VAL_LIST; + +typedef struct _EFI_IFR_EQ_ID_VAL { + EFI_IFR_OP_HEADER Header; + EFI_QUESTION_ID QuestionId; + UINT16 Value; +} EFI_IFR_EQ_ID_VAL; + +typedef struct _EFI_IFR_FALSE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_FALSE; + +typedef struct _EFI_IFR_FIND { + EFI_IFR_OP_HEADER Header; + UINT8 Format; +} EFI_IFR_FIND; + +#define EFI_IFR_FF_CASE_SENSITIVE 0x00 +#define EFI_IFR_FF_CASE_INSENSITIVE 0x01 + +typedef struct _EFI_IFR_FORM { + EFI_IFR_OP_HEADER Header; + EFI_FORM_ID FormId; + EFI_STRING_ID FormTitle; +} EFI_IFR_FORM; + +typedef struct _EFI_IFR_FORM_MAP_METHOD { + EFI_STRING_ID MethodTitle; + EFI_GUID MethodIdentifier; +} EFI_IFR_FORM_MAP_METHOD; + +typedef struct _EFI_IFR_FORM_MAP { + EFI_IFR_OP_HEADER Header; + EFI_FORM_ID FormId; + //EFI_IFR_FORM_MAP_METHOD Methods[]; +} EFI_IFR_FORM_MAP; + +typedef struct _EFI_IFR_FORM_SET { + EFI_IFR_OP_HEADER Header; + EFI_GUID Guid; + EFI_STRING_ID FormSetTitle; + EFI_STRING_ID Help; + UINT8 Flags; + EFI_GUID ClassGuid[1]; +} EFI_IFR_FORM_SET; + +typedef struct _EFI_IFR_GET { + EFI_IFR_OP_HEADER Header; + EFI_VARSTORE_ID VarStoreId; + union { + EFI_STRING_ID VarName; + UINT16 VarOffset; + } VarStoreInfo; + UINT8 VarStoreType; +} EFI_IFR_GET; + +typedef struct _EFI_IFR_GRAY_OUT_IF { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_GRAY_OUT_IF; + +typedef struct _EFI_IFR_GREATER_EQUAL { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_GREATER_EQUAL; + +typedef struct _EFI_IFR_GREATER_THAN { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_GREATER_THAN; + +typedef struct _EFI_IFR_GUID { + EFI_IFR_OP_HEADER Header; + EFI_GUID Guid; + //Optional Data Follows +} EFI_IFR_GUID; + +typedef struct _EFI_IFR_IMAGE { + EFI_IFR_OP_HEADER Header; // why was it missing in docs? + EFI_IMAGE_ID Id; +} EFI_IFR_IMAGE; + +typedef struct _EFI_IFR_INCONSISTENT_IF { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID Error; +} EFI_IFR_INCONSISTENT_IF; + +typedef struct _EFI_IFR_LENGTH { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_LENGTH; + +typedef struct _EFI_IFR_LESS_EQUAL { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_LESS_EQUAL; + +typedef struct _EFI_IFR_LESS_THAN { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_LESS_THAN; + +typedef struct _EFI_IFR_LOCKED { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_LOCKED; + +typedef struct _EFI_IFR_MAP { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MAP; + +typedef struct _EFI_IFR_MATCH { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MATCH; + +typedef struct _EFI_IFR_MID { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MID; + +typedef struct _EFI_IFR_MODAL_TAG { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MODAL_TAG; + +typedef struct _EFI_IFR_MODULO { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MODULO; + +typedef struct _EFI_IFR_MULTIPLY { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_MULTIPLY; + +typedef struct _EFI_IFR_NOT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_NOT; + +typedef struct _EFI_IFR_NOT_EQUAL { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_NOT_EQUAL; + +typedef struct _EFI_IFR_NO_SUBMIT_IF { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID Error; +} EFI_IFR_NO_SUBMIT_IF; + +typedef struct _EFI_IFR_NUMERIC { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 Flags; + + union { + struct { + UINT8 MinValue; + UINT8 MaxValue; + UINT8 Step; + } u8; + struct { + UINT16 MinValue; + UINT16 MaxValue; + UINT16 Step; + } u16; + struct { + UINT32 MinValue; + UINT32 MaxValue; + UINT32 Step; + } u32; + struct { + UINT64 MinValue; + UINT64 MaxValue; + UINT64 Step; + } u64; + } data; +} EFI_IFR_NUMERIC; + +#define EFI_IFR_NUMERIC_SIZE 0x03 +#define EFI_IFR_NUMERIC_SIZE_1 0x00 +#define EFI_IFR_NUMERIC_SIZE_2 0x01 +#define EFI_IFR_NUMERIC_SIZE_4 0x02 +#define EFI_IFR_NUMERIC_SIZE_8 0x03 +#define EFI_IFR_DISPLAY 0x30 +#define EFI_IFR_DISPLAY_INT_DEC 0x00 +#define EFI_IFR_DISPLAY_UINT_DEC 0x10 +#define EFI_IFR_DISPLAY_UINT_HEX 0x20 + +typedef struct _EFI_IFR_ONE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_ONE; + +typedef struct _EFI_IFR_ONES { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_ONES; + +typedef struct _EFI_IFR_ONE_OF { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 Flags; + union { + struct { + UINT8 MinValue; + UINT8 MaxValue; + UINT8 Step; + } u8; + struct { + UINT16 MinValue; + UINT16 MaxValue; + UINT16 Step; + } u16; + struct { + UINT32 MinValue; + UINT32 MaxValue; + UINT32 Step; + } u32; + struct { + UINT64 MinValue; + UINT64 MaxValue; + UINT64 Step; + } u64; + } data; +} EFI_IFR_ONE_OF; + +typedef struct _EFI_IFR_ONE_OF_OPTION { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID Option; + UINT8 Flags; + UINT8 Type; + EFI_IFR_TYPE_VALUE Value; +} EFI_IFR_ONE_OF_OPTION; + +#define EFI_IFR_TYPE_NUM_SIZE_8 0x00 +#define EFI_IFR_TYPE_NUM_SIZE_16 0x01 +#define EFI_IFR_TYPE_NUM_SIZE_32 0x02 +#define EFI_IFR_TYPE_NUM_SIZE_64 0x03 +#define EFI_IFR_TYPE_BOOLEAN 0x04 +#define EFI_IFR_TYPE_TIME 0x05 +#define EFI_IFR_TYPE_DATE 0x06 +#define EFI_IFR_TYPE_STRING 0x07 +#define EFI_IFR_TYPE_OTHER 0x08 +#define EFI_IFR_TYPE_UNDEFINED 0x09 +#define EFI_IFR_TYPE_ACTION 0x0A +#define EFI_IFR_TYPE_BUFFER 0x0B +#define EFI_IFR_TYPE_REF 0x0C + +#define EFI_IFR_OPTION_DEFAULT 0x10 +#define EFI_IFR_OPTION_DEFAULT_MFG 0x20 + +typedef struct _EFI_IFR_OR { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_OR; + +typedef struct _EFI_IFR_ORDERED_LIST { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 MaxContainers; + UINT8 Flags; +} EFI_IFR_ORDERED_LIST; + +#define EFI_IFR_UNIQUE_SET 0x01 +#define EFI_IFR_NO_EMPTY_SET 0x02 + +typedef struct _EFI_IFR_PASSWORD { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT16 MinSize; + UINT16 MaxSize; +} EFI_IFR_PASSWORD; + +typedef struct _EFI_IFR_QUESTION_REF1 { + EFI_IFR_OP_HEADER Header; + EFI_QUESTION_ID QuestionId; +} EFI_IFR_QUESTION_REF1; + +typedef struct _EFI_IFR_QUESTION_REF2 { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_QUESTION_REF2; + +typedef struct _EFI_IFR_QUESTION_REF3 { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_QUESTION_REF3; + +typedef struct _EFI_IFR_QUESTION_REF3_2 { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID DevicePath; +} EFI_IFR_QUESTION_REF3_2; + +typedef struct _EFI_IFR_QUESTION_REF3_3 { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID DevicePath; + EFI_GUID Guid; +} EFI_IFR_QUESTION_REF3_3; + +typedef struct _EFI_IFR_READ { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_READ; + +typedef struct _EFI_IFR_REF { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + EFI_FORM_ID FormId; +} EFI_IFR_REF; + +typedef struct _EFI_IFR_REF2 { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + EFI_FORM_ID FormId; + EFI_QUESTION_ID QuestionId; +} EFI_IFR_REF2; + +typedef struct _EFI_IFR_REF3 { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + EFI_FORM_ID FormId; + EFI_QUESTION_ID QuestionId; + EFI_GUID FormSetId; +} EFI_IFR_REF3; + +typedef struct _EFI_IFR_REF4 { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + EFI_FORM_ID FormId; + EFI_QUESTION_ID QuestionId; + EFI_GUID FormSetId; + EFI_STRING_ID DevicePath; +} EFI_IFR_REF4; + +typedef struct _EFI_IFR_REF5 { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; +} EFI_IFR_REF5; + +typedef struct _EFI_IFR_REFRESH { + EFI_IFR_OP_HEADER Header; + UINT8 RefreshInterval; +} EFI_IFR_REFRESH; + +typedef struct _EFI_IFR_REFRESH_ID { + EFI_IFR_OP_HEADER Header; + EFI_GUID RefreshEventGroupId; +} EFI_IFR_REFRESH_ID; + +typedef struct _EFI_IFR_RESET_BUTTON { + EFI_IFR_OP_HEADER Header; + EFI_IFR_STATEMENT_HEADER Statement; + EFI_DEFAULT_ID DefaultId; +} EFI_IFR_RESET_BUTTON; + +typedef struct _EFI_IFR_RULE { + EFI_IFR_OP_HEADER Header; + UINT8 RuleId; +} EFI_IFR_RULE; + +typedef struct _EFI_IFR_RULE_REF { + EFI_IFR_OP_HEADER Header; + UINT8 RuleId; +} EFI_IFR_RULE_REF; + +typedef struct _EFI_IFR_SECURITY { + EFI_IFR_OP_HEADER Header; + EFI_GUID Permissions; +} EFI_IFR_SECURITY; + +typedef struct _EFI_IFR_SET { + EFI_IFR_OP_HEADER Header; + EFI_VARSTORE_ID VarStoreId; + union { + EFI_STRING_ID VarName; + UINT16 VarOffset; + } VarStoreInfo; + UINT8 VarStoreType; +} EFI_IFR_SET; + +typedef struct _EFI_IFR_SHIFT_LEFT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_SHIFT_LEFT; + +typedef struct _EFI_IFR_SHIFT_RIGHT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_SHIFT_RIGHT; + +typedef struct _EFI_IFR_SPAN { + EFI_IFR_OP_HEADER Header; + UINT8 Flags; +} EFI_IFR_SPAN; + +#define EFI_IFR_FLAGS_FIRST_MATCHING 0x00 +#define EFI_IFR_FLAGS_FIRST_NON_MATCHING 0x01 + +typedef struct _EFI_IFR_STRING { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 MinSize; + UINT8 MaxSize; + UINT8 Flags; +} EFI_IFR_STRING; + +typedef struct _EFI_IFR_STRING_REF1 { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID StringId; +} EFI_IFR_STRING_REF1; + +typedef struct _EFI_IFR_STRING_REF2 { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_STRING_REF2; + +typedef struct _EFI_IFR_SUBTITLE { + EFI_IFR_OP_HEADER Header; + EFI_IFR_STATEMENT_HEADER Statement; + UINT8 Flags; +} EFI_IFR_SUBTITLE; + +#define EFI_IFR_FLAGS_HORIZONTAL 0x01 + +typedef struct _EFI_IFR_SUBTRACT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_SUBTRACT; + +typedef struct _EFI_IFR_SUPPRESS_IF { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_SUPPRESS_IF; + +typedef struct _EFI_IFR_TEXT { + EFI_IFR_OP_HEADER Header; + EFI_IFR_STATEMENT_HEADER Statement; + EFI_STRING_ID TextTwo; +} EFI_IFR_TEXT; + +typedef struct _EFI_IFR_THIS { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_THIS; + +typedef struct _EFI_IFR_TIME { + EFI_IFR_OP_HEADER Header; + EFI_IFR_QUESTION_HEADER Question; + UINT8 Flags; +} EFI_IFR_TIME; + +typedef struct _EFI_IFR_TOKEN { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TOKEN; + +typedef struct _EFI_IFR_TO_BOOLEAN { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TO_BOOLEAN; + +typedef struct _EFI_IFR_TO_LOWER { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TO_LOWER; + +typedef struct _EFI_IFR_TO_STRING { + EFI_IFR_OP_HEADER Header; + UINT8 Format; +} EFI_IFR_TO_STRING; + +typedef struct _EFI_IFR_TO_UINT { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TO_UINT; + +typedef struct _EFI_IFR_TO_UPPER { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TO_UPPER; + +typedef struct _EFI_IFR_TRUE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_TRUE; + +typedef struct _EFI_IFR_UINT8 { + EFI_IFR_OP_HEADER Header; + UINT8 Value; +} EFI_IFR_UINT8; + +typedef struct _EFI_IFR_UINT16 { + EFI_IFR_OP_HEADER Header; + UINT16 Value; +} EFI_IFR_UINT16; + +typedef struct _EFI_IFR_UINT32 { + EFI_IFR_OP_HEADER Header; + UINT32 Value; +} EFI_IFR_UINT32; + +typedef struct _EFI_IFR_UINT64 { + EFI_IFR_OP_HEADER Header; + UINT64 Value; +} EFI_IFR_UINT64; + +typedef struct _EFI_IFR_UNDEFINED { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_UNDEFINED; + +typedef struct _EFI_IFR_VALUE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_VALUE; + +typedef struct { + EFI_IFR_OP_HEADER Header; + EFI_GUID Guid; + EFI_VARSTORE_ID VarStoreId; + UINT16 Size; + UINT8 Name[1]; +} EFI_IFR_VARSTORE; + +typedef struct _EFI_IFR_VARSTORE_NAME_VALUE { + EFI_IFR_OP_HEADER Header; + EFI_VARSTORE_ID VarStoreId; + EFI_GUID Guid; +} EFI_IFR_VARSTORE_NAME_VALUE; + +typedef struct _EFI_IFR_VARSTORE_EFI { + EFI_IFR_OP_HEADER Header; + EFI_VARSTORE_ID VarStoreId; + EFI_GUID Guid; + UINT32 Attributes; + UINT16 Size; + UINT8 Name[1]; +} EFI_IFR_VARSTORE_EFI; + +typedef struct _EFI_IFR_VARSTORE_DEVICE { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID DevicePath; +} EFI_IFR_VARSTORE_DEVICE; + +typedef struct _EFI_IFR_VERSION { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_VERSION; + +typedef struct _EFI_IFR_WRITE { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_WRITE; + +typedef struct _EFI_IFR_ZERO { + EFI_IFR_OP_HEADER Header; +} EFI_IFR_ZERO; + +typedef struct _EFI_IFR_WARNING_IF { + EFI_IFR_OP_HEADER Header; + EFI_STRING_ID Warning; + UINT8 TimeOut; +} EFI_IFR_WARNING_IF; + +typedef struct _EFI_IFR_MATCH2 { + EFI_IFR_OP_HEADER Header; + EFI_GUID SyntaxType; +} EFI_IFR_MATCH2; + +#pragma pack(pop) + +#define EFI_IFR_FORM_OP 0x01 // Form +#define EFI_IFR_SUBTITLE_OP 0x02 // Subtitle statement +#define EFI_IFR_TEXT_OP 0x03 // Static text / image statement +#define EFI_IFR_IMAGE_OP 0x04 // Static image. +#define EFI_IFR_ONE_OF_OP 0x05 // One - of question +#define EFI_IFR_CHECKBOX_OP 0x06 // Boolean question +#define EFI_IFR_NUMERIC_OP 0x07 // Numeric question +#define EFI_IFR_PASSWORD_OP 0x08 // Password string question +#define EFI_IFR_ONE_OF_OPTION_OP 0x09 // Option +#define EFI_IFR_SUPPRESS_IF_OP 0x0A // Suppress if conditional +#define EFI_IFR_LOCKED_OP 0x0B // Marks statement / question as locked +#define EFI_IFR_ACTION_OP 0x0C // Button question +#define EFI_IFR_RESET_BUTTON_OP 0x0D // Reset button statement +#define EFI_IFR_FORM_SET_OP 0x0E // Form set +#define EFI_IFR_REF_OP 0x0F // Cross - reference statement +#define EFI_IFR_NO_SUBMIT_IF_OP 0x10 // Error checking conditional +#define EFI_IFR_INCONSISTENT_IF_OP 0x11 // Error checking conditional +#define EFI_IFR_EQ_ID_VAL_OP 0x12 // Return true if question value equals UINT16 +#define EFI_IFR_EQ_ID_ID_OP 0x13 // Return true if question value equals another question value +#define EFI_IFR_EQ_ID_VAL_LIST_OP 0x14 // Return true if question value is found in list of UINT16s +#define EFI_IFR_AND_OP 0x15 // Push true if both sub - expressions returns true. +#define EFI_IFR_OR_OP 0x16 // Push true if either sub - expressions returns true. +#define EFI_IFR_NOT_OP 0x17 // Push false if sub - expression returns true, otherwise return true. +#define EFI_IFR_RULE_OP 0x18 // Create rule in current form. +#define EFI_IFR_GRAY_OUT_IF_OP 0x19 // Nested statements, questions or options will not be selectable if expression returns true. +#define EFI_IFR_DATE_OP 0x1A // Date question. +#define EFI_IFR_TIME_OP 0x1B // Time question. +#define EFI_IFR_STRING_OP 0x1C // String question +#define EFI_IFR_REFRESH_OP 0x1D // Interval for refreshing a question +#define EFI_IFR_DISABLE_IF_OP 0x1E // Nested statements, questions or options will not be processed if expression returns true. +#define EFI_IFR_ANIMATION_OP 0x1F // Animation associated with question statement, form or form set. +#define EFI_IFR_TO_LOWER_OP 0x20 // Convert a string on the expression stack to lower case. +#define EFI_IFR_TO_UPPER_OP 0x21 // Convert a string on the expression stack to upper case. +#define EFI_IFR_MAP_OP 0x22 // Convert one value to another by selecting a match from a list. +#define EFI_IFR_ORDERED_LIST_OP 0x23 // Set question +#define EFI_IFR_VARSTORE_OP 0x24 // Define a buffer - style variable storage. +#define EFI_IFR_VARSTORE_NAME_VALUE_OP 0x25 // Define a name / value style variable storage. +#define EFI_IFR_VARSTORE_EFI_OP 0x26 // Define a UEFI variable style variable storage. +#define EFI_IFR_VARSTORE_DEVICE_OP 0x27 // Specify the device path to use for variable storage. +#define EFI_IFR_VERSION_OP 0x28 // Push the revision level of the UEFI Specification to which this Forms Processor is compliant. +#define EFI_IFR_END_OP 0x29 // Marks end of scope. +#define EFI_IFR_MATCH_OP 0x2A // Push TRUE if string matches a pattern. +#define EFI_IFR_GET_OP 0x2B // Return a stored value. +#define EFI_IFR_SET_OP 0x2C // Change a stored value. +#define EFI_IFR_READ_OP 0x2D // Provides a value for the current question or default. +#define EFI_IFR_WRITE_OP 0x2E // Change a value for the current question. +#define EFI_IFR_EQUAL_OP 0x2F // Push TRUE if two expressions are equal. +#define EFI_IFR_NOT_EQUAL_OP 0x30 // Push TRUE if two expressions are not equal. +#define EFI_IFR_GREATER_THAN_OP 0x31 // Push TRUE if one expression is greater than another expression. +#define EFI_IFR_GREATER_EQUAL_OP 0x32 // Push TRUE if one expression is greater than or equal to another expression. +#define EFI_IFR_LESS_THAN_OP 0x33 // Push TRUE if one expression is less than another expression. +#define EFI_IFR_LESS_EQUAL_OP 0x34 // Push TRUE if one expression is less than or equal to another expression. +#define EFI_IFR_BITWISE_AND_OP 0x35 // Bitwise - AND two unsigned integers and push the result. +#define EFI_IFR_BITWISE_OR_OP 0x36 // Bitwise - OR two unsigned integers and push the result. +#define EFI_IFR_BITWISE_NOT_OP 0x37 // Bitwise - NOT an unsigned integer and push the result. +#define EFI_IFR_SHIFT_LEFT_OP 0x38 // Shift an unsigned integer left by a number of bits and push the result. +#define EFI_IFR_SHIFT_RIGHT_OP 0x39 // Shift an unsigned integer right by a number of bits and push the result. +#define EFI_IFR_ADD_OP 0x3A // Add two unsigned integers and push the result. +#define EFI_IFR_SUBTRACT_OP 0x3B // Subtract two unsigned integers and push the result. +#define EFI_IFR_MULTIPLY_OP 0x3C // Multiply two unsigned integers and push the result. +#define EFI_IFR_DIVIDE_OP 0x3D // Divide one unsigned integer by another and push the result. +#define EFI_IFR_MODULO_OP 0x3E // Divide one unsigned integer by another and push the remainder. +#define EFI_IFR_RULE_REF_OP 0x3F // Evaluate a rule +#define EFI_IFR_QUESTION_REF1_OP 0x40 // Push a question’s value +#define EFI_IFR_QUESTION_REF2_OP 0x41 // Push a question’s value +#define EFI_IFR_UINT8_OP 0x42 // Push an 8 - bit unsigned integer +#define EFI_IFR_UINT16_OP 0x43 // Push a 16 - bit unsigned integer. +#define EFI_IFR_UINT32_OP 0x44 // Push a 32 - bit unsigned integer +#define EFI_IFR_UINT64_OP 0x45 // Push a 64 - bit unsigned integer. +#define EFI_IFR_TRUE_OP 0x46 // Push a boolean TRUE. +#define EFI_IFR_FALSE_OP 0x47 // Push a boolean FALSE +#define EFI_IFR_TO_UINT_OP 0x48 // Convert expression to an unsigned integer +#define EFI_IFR_TO_STRING_OP 0x49 // Convert expression to a string +#define EFI_IFR_TO_BOOLEAN_OP 0x4A // Convert expression to a boolean. +#define EFI_IFR_MID_OP 0x4B // Extract portion of string or buffer +#define EFI_IFR_FIND_OP 0x4C // Find a string in a string. +#define EFI_IFR_TOKEN_OP 0x4D // Extract a delimited byte or character string from buffer or string. +#define EFI_IFR_STRING_REF1_OP 0x4E // Push a string +#define EFI_IFR_STRING_REF2_OP 0x4F // Push a string +#define EFI_IFR_CONDITIONAL_OP 0x50 // Duplicate one of two expressions depending on result of the first expression. +#define EFI_IFR_QUESTION_REF3_OP 0x51 // Push a question’s value from a different form. +#define EFI_IFR_ZERO_OP 0x52 // Push a zero +#define EFI_IFR_ONE_OP 0x53 // Push a one +#define EFI_IFR_ONES_OP 0x54 // Push a 0xFFFFFFFFFFFFFFFF. +#define EFI_IFR_UNDEFINED_OP 0x55 // Push Undefined +#define EFI_IFR_LENGTH_OP 0x56 // Push length of buffer or string. +#define EFI_IFR_DUP_OP 0x57 // Duplicate top of expression stack +#define EFI_IFR_THIS_OP 0x58 // Push the current question’s value +#define EFI_IFR_SPAN_OP 0x59 // Return first matching / non - matching character in a string +#define EFI_IFR_VALUE_OP 0x5A // Provide a value for a question +#define EFI_IFR_DEFAULT_OP 0x5B // Provide a default value for a question. +#define EFI_IFR_DEFAULTSTORE_OP 0x5C // Define a Default Type Declaration +#define EFI_IFR_FORM_MAP_OP 0x5D // Create a standards - map form. +#define EFI_IFR_CATENATE_OP 0x5E // Push concatenated buffers or strings. +#define EFI_IFR_GUID_OP 0x5F // An extensible GUIDed op - code +#define EFI_IFR_SECURITY_OP 0x60 // Returns whether current user profile contains specified setup access privileges. +#define EFI_IFR_MODAL_TAG_OP 0x61 // Specify current form is modal +#define EFI_IFR_REFRESH_ID_OP 0x62 // Establish an event group for refreshing a forms - based element. +#define EFI_IFR_WARNING_IF_OP 0x63 // Warning conditional +#define EFI_IFR_MATCH2_OP 0x64 // Push TRUE if string matches a Regular Expression pattern. + +#endif diff --git a/Universal IFR Extractor.rc b/Universal IFR Extractor.rc deleted file mode 100644 index 0a49ee8..0000000 Binary files a/Universal IFR Extractor.rc and /dev/null differ diff --git a/Universal IFR Extractor.sln b/Universal IFR Extractor.sln deleted file mode 100644 index 0edb2ed..0000000 --- a/Universal IFR Extractor.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Universal IFR Extractor", "Universal IFR Extractor.vcxproj", "{090E4D91-4577-4FA3-A0B0-1B42BED09F43}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {090E4D91-4577-4FA3-A0B0-1B42BED09F43}.Debug|Win32.ActiveCfg = Debug|Win32 - {090E4D91-4577-4FA3-A0B0-1B42BED09F43}.Debug|Win32.Build.0 = Debug|Win32 - {090E4D91-4577-4FA3-A0B0-1B42BED09F43}.Release|Win32.ActiveCfg = Release|Win32 - {090E4D91-4577-4FA3-A0B0-1B42BED09F43}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Universal IFR Extractor.v12.suo b/Universal IFR Extractor.v12.suo deleted file mode 100644 index 55ea036..0000000 Binary files a/Universal IFR Extractor.v12.suo and /dev/null differ diff --git a/Universal IFR Extractor.vcxproj b/Universal IFR Extractor.vcxproj deleted file mode 100644 index d0afa45..0000000 --- a/Universal IFR Extractor.vcxproj +++ /dev/null @@ -1,89 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {090E4D91-4577-4FA3-A0B0-1B42BED09F43} - UniversalIFRExtractor - - - - Application - true - v120_xp - MultiByte - - - Application - false - v120_xp - true - MultiByte - - - - - - - - - - - - - - - Level3 - Disabled - true - MultiThreaded - - - true - - - - - Level3 - MaxSpeed - true - true - true - - - MultiThreaded - - - true - true - true - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ifrextractor.ico b/ifrextractor.ico new file mode 100644 index 0000000..ba13be7 Binary files /dev/null and b/ifrextractor.ico differ diff --git a/ifrextractor.rc b/ifrextractor.rc new file mode 100644 index 0000000..bbb62b2 --- /dev/null +++ b/ifrextractor.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "ifrextractor.ico" diff --git a/main-cli.cpp b/main-cli.cpp new file mode 100644 index 0000000..1d6e31c --- /dev/null +++ b/main-cli.cpp @@ -0,0 +1,178 @@ +// Header files +#include +#include +#include +#include "EFI.h" +#include "UEFI.h" +#include +#include + +using namespace std; + + +// Error codes +enum {IFR_EXTRACTED, FILE_NOT_FOUND, UNKNOWN_PROTOCOL}; + +// Global definitions +enum type {EFI, UEFI, UNKNOWN}; + + +// Global variables +string fileLocation, outputFile; +int errorCode; +string buffer; +type protocol; +vector strings; + +std::ostream& operator<<(std::ostream& out, const type value) +{ + map strs; + + strs[EFI] = "EFI"; + strs[UEFI] = "UEFI"; + strs[UNKNOWN] = "UNKNOWN"; + + return out << strs[value]; +} + +bool fileExists(const string &file) { + + // Open file + ifstream fin(file.c_str()); + + // Return if first character doesn't equal EOF + return fin.peek() != EOF; +} + +void readFile(const string &file, string &buffer) { + + // Initialize variables + ifstream fin(file.c_str(), ios::binary); + + // Clear buffer + buffer.clear(); + + // Read in file + while(fin.peek() != EOF) + buffer.push_back(fin.get()); + + // Close file + fin.close(); +} + +type getType(const string &buffer) { + + type currtype = UNKNOWN; + + // Go through buffer + for(unsigned int i = 0; i < buffer.size() - 9; i++) { + + // Check if an EFI string package was found + if((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x02' && buffer[i + 5] == '\x00' && (buffer[i + 6] != '\x00' || buffer[i + 7] != '\x00' || buffer[i + 8] != '\x00' || buffer[i + 9] != '\x00') && i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] >= 'a' && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] <= 'z' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 4] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 5] == '\x00') { + // Notice legacy EFI + currtype = EFI; + // Otherwise check if a UEFI string package was found + } else 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 + 45] == '\x00' && buffer[i + 48] == '\x2D' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x00') { + // Prefer UEFI over EFI + return UEFI; + } + } + + return currtype; +} + +int main(int argc, char **argv) +{ + if (argc != 3) + { + cout << "EFI/UEFI IFR Extractor LS v0.3.7" << endl; + cout << "Usage: ifrextract input_file output_file" << endl; + return 1; + } + + + // Reset error code + errorCode = IFR_EXTRACTED; + fileLocation = argv[1]; + outputFile = argv[2]; + + // Check if file exists + if(fileExists(fileLocation)) { + + readFile(fileLocation, buffer); + protocol = getType(buffer); + + cout << "Input: " << fileLocation << endl; + cout << "Output: " << outputFile << endl; + cout << "Protocol: " << protocol << endl; + + + // Check if protocol is unknown + if(protocol == UNKNOWN) { + + // Set error code + errorCode = UNKNOWN_PROTOCOL; + + // Display message + cout << "error: Unknown protocol" << endl; + + // Break + return errorCode; + } + + // Clear strings + strings.clear(); + + // Check if protocol is EFI + if(protocol == EFI) { + + // Initialize EFI variables + vector stringPackages; + vector formSets; + + // Get EFI string packages + getEFIStringPackages(stringPackages, buffer); + + // Get EFI strings + getEFIStrings(stringPackages, strings, buffer); + + // Get EFI form sets + getEFIFormSets(formSets, buffer, stringPackages, strings); + + // Generate EFI IFR dump + generateEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); + } + + // Otherwise check if protocol is UEFI + else if(protocol == UEFI) { + + // Initialize UEFI variables + vector stringPackages; + vector formSets; + + // Get UEFI string packages + getUEFIStringPackages(stringPackages, buffer); + + // Get UEFI strings + getUEFIStrings(stringPackages, strings, buffer); + + // Get UEFI form sets + getUEFIFormSets(formSets, buffer, stringPackages, strings); + + // Generate UEFI IFR dump + generateUEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); + } + } + + // Otherwise + else + { + // Set error code + errorCode = FILE_NOT_FOUND; + cout << "File not found!" << endl; + } + + // Return + return errorCode; +} + diff --git a/main.cpp b/main.cpp old mode 100755 new mode 100644 index bb4ee53..95e7789 --- a/main.cpp +++ b/main.cpp @@ -19,13 +19,13 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") // Global constants // Handel actions -enum {NO_ACTION, EXTRACT_BUTTON_ACTION, BROWSE_BUTTON_ACTION, FILE_LOCATION_EDIT_ACTION}; +enum { NO_ACTION, EXTRACT_BUTTON_ACTION, BROWSE_BUTTON_ACTION, FILE_LOCATION_EDIT_ACTION }; // Error codes -enum {IFR_EXTRACTED, FILE_NOT_FOUND, UNKNOWN_PROTOCOL}; +enum { IFR_EXTRACTED, FILE_NOT_FOUND, UNKNOWN_PROTOCOL }; // Global definitions -enum type {EFI, UEFI, UNKNOWN}; +enum type { EFI, UEFI, UNKNOWN }; // Global variables @@ -83,379 +83,364 @@ type getType(const string &buffer); // Main function -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { - - // Initialize variables - static TCHAR appName[] = TEXT("Universal IFR Extractor"); - HWND hwnd; - MSG msg; - WNDCLASSEX wndclass; - - // Initialize window class - wndclass.cbSize = sizeof(WNDCLASSEX); - wndclass.style = 0; - wndclass.lpfnWndProc = WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = hInstance; - wndclass.hIcon = HICON(LoadImage(GetModuleHandle(NULL), "MY_ICON", IMAGE_ICON, 256, 256, 0)); - wndclass.hIconSm = NULL; - wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); - wndclass.hbrBackground = HBRUSH((COLOR_WINDOW + 1)); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = appName; - - // Register windows class - RegisterClassEx(&wndclass); - - // Create window - hwnd = CreateWindow(appName, - TEXT("Universal IFR Extractor v0.6"), - WS_SYSMENU | WS_MINIMIZEBOX, - 0, 0, - 354, 135, - NULL, - NULL, - hInstance, - NULL); - - // Show window - ShowWindow(hwnd, iCmdShow); - UpdateWindow(hwnd); - - // Message loop - while(GetMessage(&msg, NULL, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - // Return - return msg.wParam; +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) +{ + // Initialize variables + static TCHAR appName[] = TEXT("IFRExtractor LS"); + HWND hwnd; + MSG msg; + WNDCLASSEX wndclass; + + // Initialize window class + wndclass.cbSize = sizeof(WNDCLASSEX); + wndclass.style = 0; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = HICON(LoadImage(GetModuleHandle(NULL), TEXT("IDI_ICON1"), IMAGE_ICON, 16, 16, 0)); + wndclass.hIconSm = NULL; + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = HBRUSH((COLOR_WINDOW + 1)); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = appName; + + // Register windows class + RegisterClassEx(&wndclass); + + // Create window + hwnd = CreateWindow(appName, + TEXT("IFRExtractor LS v0.3.7"), + WS_SYSMENU | WS_MINIMIZEBOX, + 0, 0, + 350, 120, + NULL, + NULL, + hInstance, + NULL); + + // Show window + ShowWindow(hwnd, iCmdShow); + UpdateWindow(hwnd); + + // Message loop + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + // Return + return msg.wParam; } // Supporting function implementation LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - // Check message - switch (message) { - - // Create - case WM_CREATE: - - // Center window - RECT rectangle; - GetWindowRect(hwnd, &rectangle); - int xPos; - xPos = (GetSystemMetrics(SM_CXSCREEN) - rectangle.right) / 2; - int yPos; - yPos = (GetSystemMetrics(SM_CYSCREEN) - rectangle.bottom) / 2; - SetWindowPos(hwnd, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - - // Create module location text - HWND moduleLocationText; - moduleLocationText = CreateWindowEx(WS_EX_TRANSPARENT, - TEXT("static"), - TEXT("Module Location"), - WS_CHILD | WS_VISIBLE, - 10, 16, - 100, 25, - hwnd, - HMENU(NO_ACTION), - NULL, - NULL); - SendMessage(moduleLocationText, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); - - // Create protocol text - HWND protocolText; - protocolText = CreateWindowEx(WS_EX_TRANSPARENT, - TEXT("static"), - TEXT("Protocol:"), - WS_CHILD | WS_VISIBLE, - 10, 52, - 100, 25, - hwnd, - HMENU(NO_ACTION), - NULL, - NULL); - SendMessage(protocolText, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); - - // Create type text - typeText = CreateWindowEx(WS_EX_TRANSPARENT, - TEXT("static"), - TEXT(""), - WS_CHILD | WS_VISIBLE, - 55, 50, - 100, 25, - hwnd, - HMENU(NO_ACTION), - NULL, - NULL); - - // Create copyright text - HWND copyrightText; - copyrightText = CreateWindowEx(WS_EX_TRANSPARENT, - TEXT("static"), - TEXT("© 2014 donovan6000"), - WS_CHILD | WS_VISIBLE, - 198, 81, - 200, 25, - hwnd, - HMENU(NO_ACTION), - NULL, - NULL); - - // Create file location edit - fileLocationEdit = CreateWindow(TEXT("edit"), - NULL, - WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | WS_EX_CLIENTEDGE, - 93, 13, - 200, 17, - hwnd, - HMENU(FILE_LOCATION_EDIT_ACTION), - NULL, - NULL); - SendMessage(fileLocationEdit, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); - TCHAR fileLocationEditValue[MAX_PATH]; - if(__argc < 2) { - GetEnvironmentVariable(("userprofile"), fileLocationEditValue, MAX_PATH); - strcat_s(fileLocationEditValue, TEXT("\\module.rom")); - } - else - strcpy_s(fileLocationEditValue, TEXT(__argv[1])); - SetWindowText(fileLocationEdit, TEXT(fileLocationEditValue)); - - // Create browse button - HWND browseButton; - browseButton = CreateWindow(TEXT("button"), - TEXT(".."), - WS_VISIBLE | WS_CHILD, - 298, 12, - 30, 19, - hwnd, - HMENU(BROWSE_BUTTON_ACTION), - NULL, - NULL); - SendMessage(browseButton, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); - - // Create extract button - HWND extractButton; - extractButton = CreateWindow(TEXT("button"), - TEXT("Extract"), - WS_VISIBLE | WS_CHILD, - 248, 45, - 80, 25, - hwnd, - HMENU(EXTRACT_BUTTON_ACTION), - NULL, - NULL); - SendMessage(extractButton, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); - - // Break - break; - - // Command - case WM_COMMAND: - - // Check if extract button action - if(LOWORD(wParam) == EXTRACT_BUTTON_ACTION) { - - // Reset error code - errorCode = IFR_EXTRACTED; - - // Refresh file location settings - SetWindowText(fileLocationEdit, TEXT(fileLocation.c_str())); - - // Check if file exists - if(fileExists(fileLocation)) { - - // Check if protocol is unknown - if(protocol == UNKNOWN) { - - // Set error code - errorCode = UNKNOWN_PROTOCOL; - - // Display message - showDialog(hwnd); - - // Break - break; - } - - // Clear strings - strings.clear(); - - // Check if output file was canceled - if(!saveFile(hwnd)) - - // Break - break; - - // Check if protocol is EFI - if(protocol == EFI) { - - // Initialize EFI variables - vector stringPackages; - vector formSets; - - // Get EFI string packages - getEFIStringPackages(stringPackages, buffer); - - // Get EFI strings - getEFIStrings(stringPackages, strings, buffer); - - // Get EFI form sets - getEFIFormSets(formSets, buffer, stringPackages, strings); - - // Generate EFI IFR dump - generateEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); - } - - // Otherwise check if protocol is UEFI - else if(protocol == UEFI) { - - // Initialize UEFI variables - vector stringPackages; - vector formSets; - - // Get UEFI string packages - getUEFIStringPackages(stringPackages, buffer); - - // Get UEFI strings - getUEFIStrings(stringPackages, strings, buffer); - - // Get UEFI form sets - getUEFIFormSets(formSets, buffer, stringPackages, strings); - - // Generate UEFI IFR dump - generateUEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); - } - } - - // Otherwise - else - - // Set error code - errorCode = FILE_NOT_FOUND; - - // Display message - showDialog(hwnd); - } - - // Otherwise check if browse button action - else if(LOWORD(wParam) == BROWSE_BUTTON_ACTION) - - // Browse folders - fileBrowser(hwnd); - - // Otherwise check if file location edit action - else if(LOWORD(wParam) == FILE_LOCATION_EDIT_ACTION) - - // Check if file location edit was changed - if(HIWORD(wParam) == EN_CHANGE) { - - // Set file location - TCHAR tempBuffer[MAX_PATH]; - GetWindowText(fileLocationEdit, tempBuffer, MAX_PATH); - fileLocation = tempBuffer; - - // Check if file exists - if(fileExists(fileLocation)) { - - // Read in file - readFile(fileLocation, buffer); - - // Get protocol - protocol = getType(buffer); - } - - // Otherwise - else - - // Set protocol - protocol = UNKNOWN; - - // Clear type text - RECT rectangle; - GetClientRect(typeText, &rectangle); - InvalidateRect(typeText, &rectangle, TRUE); - MapWindowPoints(typeText, hwnd, (POINT *)&rectangle, 2); - RedrawWindow(hwnd, &rectangle, NULL, RDW_ERASE | RDW_INVALIDATE); - - // Update type text - SendMessage(typeText, WM_SETTEXT, NULL, NULL); - } - - break; - - // Static color - case WM_CTLCOLORSTATIC: - - // Make static control transparent - HDC hdcStatic; - hdcStatic = (HDC)wParam; - - // Check if caller is type text - if((HWND)lParam == typeText) { - - // Check if protocol is unknown - if(protocol == UNKNOWN) { - - // Set text - SetWindowText(typeText, TEXT("Unknown")); - - // Set colot - SetTextColor(hdcStatic, RGB(255, 0, 0)); - } - - // Otherwise - else { - - // Check if protocol is EFI - if(protocol == EFI) - - // Set text - SetWindowText(typeText, TEXT("EFI")); - - // Otherwise check if protocol is UEFI - else if(protocol == UEFI) - - // Set text - SetWindowText(typeText, TEXT("UEFI")); - - // Set color - SetTextColor(hdcStatic, RGB(0, 255, 0)); - } - } - - // Otherwise - else - - // Set colot - SetTextColor(hdcStatic, RGB(0, 0, 0)); - - // Make background transparent - SetBkMode(hdcStatic, TRANSPARENT); - - // Return result - return (LRESULT)GetStockObject(NULL_BRUSH); - - // Close - case WM_DESTROY: - - // Quit - PostQuitMessage(0); - - // Break - break; - } + // Check message + switch (message) { + + // Create + case WM_CREATE: + // Center window + RECT rectangle; + GetWindowRect(hwnd, &rectangle); + int xPos; + xPos = (GetSystemMetrics(SM_CXSCREEN) - rectangle.right) / 2; + int yPos; + yPos = (GetSystemMetrics(SM_CYSCREEN) - rectangle.bottom) / 2; + SetWindowPos(hwnd, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + + // Create module location text + HWND moduleLocationText; + moduleLocationText = CreateWindowEx(WS_EX_TRANSPARENT, + TEXT("static"), + TEXT("Module Location"), + WS_CHILD | WS_VISIBLE, + 10, 16, + 100, 25, + hwnd, + HMENU(NO_ACTION), + NULL, + NULL); + SendMessage(moduleLocationText, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); + + // Create protocol text + HWND protocolText; + protocolText = CreateWindowEx(WS_EX_TRANSPARENT, + TEXT("static"), + TEXT("Protocol:"), + WS_CHILD | WS_VISIBLE, + 10, 52, + 100, 25, + hwnd, + HMENU(NO_ACTION), + NULL, + NULL); + SendMessage(protocolText, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); + + // Create type text + typeText = CreateWindowEx(WS_EX_TRANSPARENT, + TEXT("static"), + TEXT(""), + WS_CHILD | WS_VISIBLE, + 55, 50, + 100, 25, + hwnd, + HMENU(NO_ACTION), + NULL, + NULL); + + // Create file location edit + fileLocationEdit = CreateWindow(TEXT("edit"), + NULL, + WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | WS_EX_CLIENTEDGE, + 93, 13, + 200, 17, + hwnd, + HMENU(FILE_LOCATION_EDIT_ACTION), + NULL, + NULL); + SendMessage(fileLocationEdit, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); + TCHAR fileLocationEditValue[MAX_PATH]; + if (__argc < 2) { + GetEnvironmentVariable(("userprofile"), fileLocationEditValue, MAX_PATH); + strcat_s(fileLocationEditValue, TEXT("\\module.rom")); + } + else + strcpy_s(fileLocationEditValue, TEXT(__argv[1])); + SetWindowText(fileLocationEdit, TEXT(fileLocationEditValue)); + + // Create browse button + HWND browseButton; + browseButton = CreateWindow(TEXT("button"), + TEXT(".."), + WS_VISIBLE | WS_CHILD, + 298, 12, + 30, 19, + hwnd, + HMENU(BROWSE_BUTTON_ACTION), + NULL, + NULL); + SendMessage(browseButton, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); + + // Create extract button + HWND extractButton; + extractButton = CreateWindow(TEXT("button"), + TEXT("Extract"), + WS_VISIBLE | WS_CHILD, + 248, 45, + 80, 25, + hwnd, + HMENU(EXTRACT_BUTTON_ACTION), + NULL, + NULL); + SendMessage(extractButton, WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), MAKELPARAM(FALSE, 0)); + + // Break + break; + + // Command + case WM_COMMAND: + + // Check if extract button action + if (LOWORD(wParam) == EXTRACT_BUTTON_ACTION) { + + // Reset error code + errorCode = IFR_EXTRACTED; + + // Refresh file location settings + SetWindowText(fileLocationEdit, TEXT(fileLocation.c_str())); + + // Check if file exists + if (fileExists(fileLocation)) { + + // Check if protocol is unknown + if (protocol == UNKNOWN) { + + // Set error code + errorCode = UNKNOWN_PROTOCOL; + + // Display message + showDialog(hwnd); + + // Break + break; + } + + // Clear strings + strings.clear(); + + // Check if output file was canceled + if (!saveFile(hwnd)) + // Break + break; + + // Check if protocol is EFI + if (protocol == EFI) { + + // Initialize EFI variables + vector stringPackages; + vector formSets; + + // Get EFI string packages + getEFIStringPackages(stringPackages, buffer); + + // Get EFI strings + getEFIStrings(stringPackages, strings, buffer); + + // Get EFI form sets + getEFIFormSets(formSets, buffer, stringPackages, strings); + + // Generate EFI IFR dump + generateEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); + } - // Return - return DefWindowProc(hwnd, message, wParam, lParam); -} + // Otherwise check if protocol is UEFI + else if (protocol == UEFI) { + + // Initialize UEFI variables + vector stringPackages; + vector formSets; + + // Get UEFI string packages + getUEFIStringPackages(stringPackages, buffer); + + // Get UEFI strings + getUEFIStrings(stringPackages, strings, buffer); + + // Get UEFI form sets + getUEFIFormSets(formSets, buffer, stringPackages, strings); + + // Generate UEFI IFR dump + generateUEFIIFRDump(outputFile, stringPackages, formSets, buffer, strings); + } + } + + // Otherwise + else + + // Set error code + errorCode = FILE_NOT_FOUND; + + // Display message + showDialog(hwnd); + } + + // Otherwise check if browse button action + else if (LOWORD(wParam) == BROWSE_BUTTON_ACTION) + + // Browse folders + fileBrowser(hwnd); + + // Otherwise check if file location edit action + else if (LOWORD(wParam) == FILE_LOCATION_EDIT_ACTION) + + // Check if file location edit was changed + if (HIWORD(wParam) == EN_CHANGE) { + + // Set file location + TCHAR tempBuffer[MAX_PATH]; + GetWindowText(fileLocationEdit, tempBuffer, MAX_PATH); + fileLocation = tempBuffer; + + // Check if file exists + if (fileExists(fileLocation)) { + + // Read in file + readFile(fileLocation, buffer); + + // Get protocol + protocol = getType(buffer); + } + + // Otherwise + else + + // Set protocol + protocol = UNKNOWN; + + // Clear type text + RECT rectangle; + GetClientRect(typeText, &rectangle); + InvalidateRect(typeText, &rectangle, TRUE); + MapWindowPoints(typeText, hwnd, (POINT *)&rectangle, 2); + RedrawWindow(hwnd, &rectangle, NULL, RDW_ERASE | RDW_INVALIDATE); + + // Update type text + SendMessage(typeText, WM_SETTEXT, NULL, NULL); + } + + break; + + // Static color + case WM_CTLCOLORSTATIC: + + // Make static control transparent + HDC hdcStatic; + hdcStatic = (HDC)wParam; + + // Check if caller is type text + if ((HWND)lParam == typeText) { + + // Check if protocol is unknown + if (protocol == UNKNOWN) { + + // Set text + SetWindowText(typeText, TEXT("Unknown")); + + // Set colot + SetTextColor(hdcStatic, RGB(255, 0, 0)); + } + + // Otherwise + else { + + // Check if protocol is EFI + if (protocol == EFI) + + // Set text + SetWindowText(typeText, TEXT("EFI")); -void fileBrowser(HWND hwnd) { + // Otherwise check if protocol is UEFI + else if (protocol == UEFI) + // Set text + SetWindowText(typeText, TEXT("UEFI")); + + // Set color + SetTextColor(hdcStatic, RGB(0, 255, 0)); + } + } + + // Otherwise + else + + // Set colot + SetTextColor(hdcStatic, RGB(0, 0, 0)); + + // Make background transparent + SetBkMode(hdcStatic, TRANSPARENT); + + // Return result + return (LRESULT)GetStockObject(NULL_BRUSH); + + // Close + case WM_DESTROY: + + // Quit + PostQuitMessage(0); + + // Break + break; + } + + // Return + return DefWindowProc(hwnd, message, wParam, lParam); +} + +void fileBrowser(HWND hwnd) +{ // Initialize variables OPENFILENAME browserInfo; CHAR szFile[MAX_PATH]; @@ -474,125 +459,135 @@ void fileBrowser(HWND hwnd) { browserInfo.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // Check if file was selected - if(GetOpenFileName(&browserInfo)) - + if (GetOpenFileName(&browserInfo)) { // Update file location edit SetWindowText(fileLocationEdit, TEXT(browserInfo.lpstrFile)); -} - -bool saveFile(HWND hwnd) { - - // Initialize variables - OPENFILENAME browserInfo; - string fileName = fileLocation.substr(0, fileLocation.find_last_of('.')) + " IFR"; - - // Set dialog options - ZeroMemory(&browserInfo, sizeof(browserInfo)); - browserInfo.lStructSize = sizeof(browserInfo); - browserInfo.hwndOwner = hwnd; - browserInfo.lpstrFilter = (LPCSTR)"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; - browserInfo.lpstrFile = (LPSTR)fileName.c_str(); - browserInfo.nMaxFile = MAX_PATH; - browserInfo.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; - browserInfo.lpstrDefExt = (LPCSTR)"txt"; - - // Check if file was selected - if(GetSaveFileName(&browserInfo)) { - - // Set output file - outputFile = browserInfo.lpstrFile; - - // Return true - return true; } - - // Return false - return false; } -void showDialog(HWND hwnd) { +bool saveFile(HWND hwnd) +{ + // Initialize variables + OPENFILENAME browserInfo; + string fileName = fileLocation.substr(0, fileLocation.find_last_of('.')) + " IFR"; + fileName.reserve(MAX_PATH); + + // Set dialog options + ZeroMemory(&browserInfo, sizeof(browserInfo)); + browserInfo.lStructSize = sizeof(browserInfo); + browserInfo.hwndOwner = hwnd; + browserInfo.lpstrFilter = (LPCSTR)"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; + browserInfo.lpstrFile = (LPSTR)fileName.c_str(); + browserInfo.nMaxFile = MAX_PATH; + browserInfo.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; + browserInfo.lpstrDefExt = (LPCSTR)"txt"; + + // Check if file was selected + if (GetSaveFileName(&browserInfo)) { + + // Set output file + outputFile = browserInfo.lpstrFile; + + // Return true + return true; + } + + // Return false + return false; +} - // Initialize variables - string header, message; +void showDialog(HWND hwnd) +{ + // Initialize variables + string header, message; - // Check if error code is IFR extracted - if(errorCode == IFR_EXTRACTED) { + // Check if error code is IFR extracted + if (errorCode == IFR_EXTRACTED) { - // Set header - header = "Message"; + // Set header + header = "Message"; - // Set message - message = "IFR extracted successfully"; + // Set message + message = "IFR extracted successfully"; - // Display message - MessageBox(hwnd, TEXT(message.c_str()), TEXT(header.c_str()), MB_OK | MB_ICONINFORMATION); - } + // Display message + MessageBox(hwnd, TEXT(message.c_str()), TEXT(header.c_str()), MB_OK | MB_ICONINFORMATION); + } - // Otherwise - else { + // Otherwise + else { - // Set header - header = "Error"; + // Set header + header = "Error"; - // Check if error code equals file not found - if(errorCode == FILE_NOT_FOUND) + // Check if error code equals file not found + if (errorCode == FILE_NOT_FOUND) - // Set message - message = "File not found"; + // Set message + message = "File not found"; - // Otherwise check if error code equals unknown protocol - else if(errorCode == UNKNOWN_PROTOCOL) + // Otherwise check if error code equals unknown protocol + else if (errorCode == UNKNOWN_PROTOCOL) - // Set message - message = "Unknown protocol detected"; + // Set message + message = "Unknown protocol detected"; - // Display message - MessageBox(hwnd, TEXT(message.c_str()), TEXT(header.c_str()), MB_OK | MB_ICONWARNING); - } + // Display message + MessageBox(hwnd, TEXT(message.c_str()), TEXT(header.c_str()), MB_OK | MB_ICONWARNING); + } } -bool fileExists(const string &file) { - - // Open file - ifstream fin(file); - - // Return if first characetr doesn't equal EOF - return fin.peek() != EOF; +bool fileExists(const string &file) +{ + // Open file +#if (_MSC_VER < 1600) + ifstream fin(file.c_str()); +#else + ifstream fin(file); +#endif + + // Return if first character doesn't equal EOF + return fin.peek() != EOF; } -void readFile(const string &file, string &buffer) { - - // Initialize variables - ifstream fin(file, ios::binary); +void readFile(const string &file, string &buffer) +{ + // Initialize variables +#if (_MSC_VER < 1600) + ifstream fin(file.c_str(), ios::binary); +#else + ifstream fin(file, ios::binary); +#endif - // Clear buffer - buffer.clear(); + // Clear buffer + buffer.clear(); - // Read in file - while(fin.peek() != EOF) - buffer.push_back(fin.get()); + // Read in file + while (fin.peek() != EOF) + buffer.push_back(fin.get()); - // Close file - fin.close(); + // Close file + fin.close(); } -type getType(const string &buffer) { - - // Go through buffer - for(unsigned int i = 0; i < buffer.size() - 9; i++) - - // Check if an EFI string pakage was found - if((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x02' && buffer[i + 5] == '\x00' && (buffer[i + 6] != '\x00' || buffer[i + 7] != '\x00' || buffer[i + 8] != '\x00' || buffer[i + 9] != '\x00') && i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] >= 'a' && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] <= 'z' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 4] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 5] == '\x00') - - // Return EFI - return EFI; - - // Otherwise check if a UEFI string pakage was found - else 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 + 45] == '\x00' && buffer[i + 48] == '\x2D' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x00') - - // Return UEFI - return UEFI; - - // Return unknown - return UNKNOWN; +type getType(const string &buffer) +{ + + type currtype = UNKNOWN; + + // Go through buffer + for(unsigned int i = 0; i < buffer.size() - 9; i++) { + + // Check if an EFI string package was found + if((buffer[i] != '\x00' || buffer[i + 1] != '\x00' || buffer[i + 2] != '\x00' || buffer[i + 3] != '\x00') && buffer[i + 4] == '\x02' && buffer[i + 5] == '\x00' && (buffer[i + 6] != '\x00' || buffer[i + 7] != '\x00' || buffer[i + 8] != '\x00' || buffer[i + 9] != '\x00') && i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] >= 'a' && buffer[i + static_cast(buffer[i + 6]) + (static_cast(buffer[i + 7]) << 8) + (static_cast(buffer[i + 8]) << 16) + (static_cast(buffer[i + 9]) << 24) + 4] <= 'z' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 4] == '\x02' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) + (static_cast(buffer[i + 3]) << 24) + 5] == '\x00') { + // Notice legacy EFI + currtype = EFI; + // Otherwise check if a UEFI string package was found + } else 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 + 45] == '\x00' && buffer[i + 48] == '\x2D' && i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) < buffer.size() && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 1] == '\x00' && buffer[i + static_cast(buffer[i]) + (static_cast(buffer[i + 1]) << 8) + (static_cast(buffer[i + 2]) << 16) - 2] == '\x00') { + // Prefer UEFI over EFI + return UEFI; + } + } + + return currtype; } diff --git a/resource.h b/resource.h deleted file mode 100644 index 88c0c7d..0000000 Binary files a/resource.h and /dev/null differ