├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── UEFIExtract ├── CMakeLists.txt ├── ffsdumper.cpp ├── ffsdumper.h ├── meson.build ├── uefidump.cpp ├── uefidump.h ├── uefiextract.manifest └── uefiextract_main.cpp ├── UEFIFind ├── CMakeLists.txt ├── meson.build ├── uefifind.cpp ├── uefifind.h ├── uefifind.manifest └── uefifind_main.cpp ├── UEFITool ├── CMakeLists.txt ├── Info.plist ├── QHexView │ ├── CMakeLists.txt │ ├── LICENSE │ ├── include │ │ └── QHexView │ │ │ ├── dialogs │ │ │ └── hexfinddialog.h │ │ │ ├── model │ │ │ ├── buffer │ │ │ │ ├── qdevicebuffer.h │ │ │ │ ├── qhexbuffer.h │ │ │ │ ├── qmappedfilebuffer.h │ │ │ │ ├── qmemorybuffer.h │ │ │ │ └── qmemoryrefbuffer.h │ │ │ ├── commands │ │ │ │ ├── hexcommand.h │ │ │ │ ├── insertcommand.h │ │ │ │ ├── removecommand.h │ │ │ │ └── replacecommand.h │ │ │ ├── qhexcursor.h │ │ │ ├── qhexdelegate.h │ │ │ ├── qhexdocument.h │ │ │ ├── qhexmetadata.h │ │ │ ├── qhexoptions.h │ │ │ └── qhexutils.h │ │ │ └── qhexview.h │ └── src │ │ ├── dialogs │ │ └── hexfinddialog.cpp │ │ ├── model │ │ ├── buffer │ │ │ ├── qdevicebuffer.cpp │ │ │ ├── qhexbuffer.cpp │ │ │ ├── qmappedfilebuffer.cpp │ │ │ ├── qmemorybuffer.cpp │ │ │ └── qmemoryrefbuffer.cpp │ │ ├── commands │ │ │ ├── hexcommand.cpp │ │ │ ├── insertcommand.cpp │ │ │ ├── removecommand.cpp │ │ │ └── replacecommand.cpp │ │ ├── qhexcursor.cpp │ │ ├── qhexdelegate.cpp │ │ ├── qhexdocument.cpp │ │ ├── qhexmetadata.cpp │ │ └── qhexutils.cpp │ │ └── qhexview.cpp ├── ffsfinder.cpp ├── ffsfinder.h ├── gotoaddressdialog.h ├── gotoaddressdialog.ui ├── gotobasedialog.h ├── gotobasedialog.ui ├── hexlineedit.cpp ├── hexlineedit.h ├── hexspinbox.cpp ├── hexspinbox.h ├── hexviewdialog.cpp ├── hexviewdialog.h ├── hexviewdialog.ui ├── icons │ ├── uefitool.icns │ ├── uefitool.ico │ ├── uefitool_128x128.png │ ├── uefitool_16x16.png │ ├── uefitool_256x256.png │ ├── uefitool_32x32.png │ ├── uefitool_48x48.png │ ├── uefitool_512x512.png │ └── uefitool_64x64.png ├── searchdialog.cpp ├── searchdialog.h ├── searchdialog.ui ├── uefitool.cpp ├── uefitool.desktop ├── uefitool.entitlements ├── uefitool.h ├── uefitool.pro ├── uefitool.qrc ├── uefitool.rc ├── uefitool.ui └── uefitool_main.cpp ├── appstream ├── UEFITool.png └── appdata.xml ├── common ├── LZMA │ ├── LzmaCompress.c │ ├── LzmaCompress.h │ ├── LzmaDecompress.c │ ├── LzmaDecompress.h │ └── SDK │ │ └── C │ │ ├── 7zTypes.h │ │ ├── 7zVersion.h │ │ ├── 7zWindows.h │ │ ├── Bra.c │ │ ├── Bra.h │ │ ├── Bra86.c │ │ ├── Compiler.h │ │ ├── CpuArch.c │ │ ├── CpuArch.h │ │ ├── LzFind.c │ │ ├── LzFind.h │ │ ├── LzHash.h │ │ ├── LzmaDec.c │ │ ├── LzmaDec.h │ │ ├── LzmaEnc.c │ │ ├── LzmaEnc.h │ │ ├── Precomp.h │ │ └── RotateDefs.h ├── Tiano │ ├── EfiTianoCompress.c │ ├── EfiTianoCompress.h │ ├── EfiTianoCompressLegacy.c │ ├── EfiTianoDecompress.c │ └── EfiTianoDecompress.h ├── basetypes.h ├── bstrlib │ ├── LICENSE │ ├── bstrlib.c │ ├── bstrlib.h │ ├── bstrwrap.cpp │ └── bstrwrap.h ├── descriptor.cpp ├── descriptor.h ├── digest │ ├── sha1.c │ ├── sha1.h │ ├── sha2.h │ ├── sha256.c │ ├── sha512.c │ ├── sm3.c │ └── sm3.h ├── ffs.cpp ├── ffs.h ├── ffsbuilder.cpp ├── ffsbuilder.h ├── ffsops.cpp ├── ffsops.h ├── ffsparser.cpp ├── ffsparser.h ├── ffsreport.cpp ├── ffsreport.h ├── filesystem.cpp ├── filesystem.h ├── fitparser.cpp ├── fitparser.h ├── gbe.h ├── generated │ ├── ami_nvar.cpp │ ├── ami_nvar.h │ ├── apple_sysf.cpp │ ├── apple_sysf.h │ ├── dell_dvar.cpp │ ├── dell_dvar.h │ ├── edk2_ftw.cpp │ ├── edk2_ftw.h │ ├── edk2_vss.cpp │ ├── edk2_vss.h │ ├── edk2_vss2.cpp │ ├── edk2_vss2.h │ ├── insyde_fdc.cpp │ ├── insyde_fdc.h │ ├── insyde_fdm.cpp │ ├── insyde_fdm.h │ ├── intel_acbp_v1.cpp │ ├── intel_acbp_v1.h │ ├── intel_acbp_v2.cpp │ ├── intel_acbp_v2.h │ ├── intel_acm.cpp │ ├── intel_acm.h │ ├── intel_keym_v1.cpp │ ├── intel_keym_v1.h │ ├── intel_keym_v2.cpp │ ├── intel_keym_v2.h │ ├── ms_slic_marker.cpp │ ├── ms_slic_marker.h │ ├── ms_slic_pubkey.cpp │ ├── ms_slic_pubkey.h │ ├── phoenix_evsa.cpp │ ├── phoenix_evsa.h │ ├── phoenix_flm.cpp │ └── phoenix_flm.h ├── guiddatabase.cpp ├── guiddatabase.h ├── guids.csv ├── intel_fit.h ├── intel_microcode.h ├── kaitai │ ├── custom_decoder.h │ ├── exceptions.h │ ├── kaitaistream.cpp │ ├── kaitaistream.h │ └── kaitaistruct.h ├── ksy │ ├── ami_nvar.ksy │ ├── apple_sysf.ksy │ ├── dell_dvar.ksy │ ├── edk2_ftw.ksy │ ├── edk2_vss.ksy │ ├── edk2_vss2.ksy │ ├── insyde_fdc.ksy │ ├── insyde_fdm.ksy │ ├── intel_acbp_v1.ksy │ ├── intel_acbp_v2.ksy │ ├── intel_acm.ksy │ ├── intel_keym_v1.ksy │ ├── intel_keym_v2.ksy │ ├── ms_slic_marker.ksy │ ├── ms_slic_pubkey.ksy │ ├── phoenix_evsa.ksy │ └── phoenix_flm.ksy ├── me.h ├── meparser.cpp ├── meparser.h ├── meson.build ├── nvram.cpp ├── nvram.h ├── nvramparser.cpp ├── nvramparser.h ├── parsingdata.h ├── peimage.cpp ├── peimage.h ├── treeitem.cpp ├── treeitem.h ├── treemodel.cpp ├── treemodel.h ├── types.cpp ├── types.h ├── ubytearray.h ├── umemstream.h ├── ustring.cpp ├── ustring.h ├── utility.cpp ├── utility.h └── zlib │ ├── ChangeLog │ ├── LICENSE │ ├── README │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── fuzzing ├── CMakeLists.txt ├── afl_driver.cpp └── ffsparser_fuzzer.cpp ├── kaitai_regenerate.sh ├── meson.build ├── sonar-project.properties └── version.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.22) 2 | 3 | PROJECT(UEFITool_everything) 4 | 5 | ADD_SUBDIRECTORY(UEFIExtract) 6 | ADD_SUBDIRECTORY(UEFIFind) 7 | ADD_SUBDIRECTORY(UEFITool) 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Nikolaj Schlej 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /UEFIExtract/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.22) 2 | 3 | PROJECT(UEFIExtract) 4 | 5 | SET(CMAKE_CXX_STANDARD 11) 6 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | SET(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | SET(PROJECT_SOURCES 10 | uefiextract_main.cpp 11 | ffsdumper.cpp 12 | uefidump.cpp 13 | ../common/guiddatabase.cpp 14 | ../common/types.cpp 15 | ../common/filesystem.cpp 16 | ../common/descriptor.cpp 17 | ../common/ffs.cpp 18 | ../common/nvram.cpp 19 | ../common/nvramparser.cpp 20 | ../common/meparser.cpp 21 | ../common/ffsparser.cpp 22 | ../common/fitparser.cpp 23 | ../common/ffsreport.cpp 24 | ../common/peimage.cpp 25 | ../common/treeitem.cpp 26 | ../common/treemodel.cpp 27 | ../common/utility.cpp 28 | ../common/LZMA/LzmaDecompress.c 29 | ../common/LZMA/SDK/C/Bra.c 30 | ../common/LZMA/SDK/C/Bra86.c 31 | ../common/LZMA/SDK/C/CpuArch.c 32 | ../common/LZMA/SDK/C/LzmaDec.c 33 | ../common/Tiano/EfiTianoDecompress.c 34 | ../common/ustring.cpp 35 | ../common/bstrlib/bstrlib.c 36 | ../common/bstrlib/bstrwrap.cpp 37 | ../common/generated/ami_nvar.cpp 38 | ../common/generated/apple_sysf.cpp 39 | ../common/generated/dell_dvar.cpp 40 | ../common/generated/edk2_vss.cpp 41 | ../common/generated/edk2_vss2.cpp 42 | ../common/generated/edk2_ftw.cpp 43 | ../common/generated/insyde_fdc.cpp 44 | ../common/generated/insyde_fdm.cpp 45 | ../common/generated/ms_slic_marker.cpp 46 | ../common/generated/ms_slic_pubkey.cpp 47 | ../common/generated/phoenix_flm.cpp 48 | ../common/generated/phoenix_evsa.cpp 49 | ../common/generated/intel_acbp_v1.cpp 50 | ../common/generated/intel_acbp_v2.cpp 51 | ../common/generated/intel_keym_v1.cpp 52 | ../common/generated/intel_keym_v2.cpp 53 | ../common/generated/intel_acm.cpp 54 | ../common/kaitai/kaitaistream.cpp 55 | ../common/digest/sha1.c 56 | ../common/digest/sha256.c 57 | ../common/digest/sha512.c 58 | ../common/digest/sm3.c 59 | ../common/zlib/adler32.c 60 | ../common/zlib/compress.c 61 | ../common/zlib/crc32.c 62 | ../common/zlib/deflate.c 63 | ../common/zlib/gzclose.c 64 | ../common/zlib/gzlib.c 65 | ../common/zlib/gzread.c 66 | ../common/zlib/gzwrite.c 67 | ../common/zlib/inflate.c 68 | ../common/zlib/infback.c 69 | ../common/zlib/inftrees.c 70 | ../common/zlib/inffast.c 71 | ../common/zlib/trees.c 72 | ../common/zlib/uncompr.c 73 | ../common/zlib/zutil.c 74 | ) 75 | 76 | ADD_DEFINITIONS( 77 | -DU_ENABLE_NVRAM_PARSING_SUPPORT 78 | -DU_ENABLE_ME_PARSING_SUPPORT 79 | -DU_ENABLE_FIT_PARSING_SUPPORT 80 | -DU_ENABLE_GUID_DATABASE_SUPPORT 81 | ) 82 | 83 | ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} uefiextract.manifest) 84 | 85 | IF(UNIX) 86 | SET_TARGET_PROPERTIES(UEFIExtract PROPERTIES OUTPUT_NAME uefiextract) 87 | ENDIF() 88 | 89 | INSTALL( 90 | TARGETS UEFIExtract 91 | RUNTIME DESTINATION bin 92 | ) 93 | -------------------------------------------------------------------------------- /UEFIExtract/ffsdumper.h: -------------------------------------------------------------------------------- 1 | /* ffsdumper.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FFSDUMPER_H 15 | #define FFSDUMPER_H 16 | 17 | #include 18 | 19 | #include "../common/basetypes.h" 20 | #include "../common/ustring.h" 21 | #include "../common/treemodel.h" 22 | #include "../common/ffs.h" 23 | #include "../common/filesystem.h" 24 | #include "../common/utility.h" 25 | 26 | class FfsDumper 27 | { 28 | public: 29 | enum DumpMode { 30 | DUMP_CURRENT, 31 | DUMP_ALL, 32 | DUMP_BODY, 33 | DUMP_UNC_DATA, 34 | DUMP_HEADER, 35 | DUMP_INFO, 36 | DUMP_FILE 37 | }; 38 | 39 | static const UINT8 IgnoreSectionType = 0xFF; 40 | 41 | explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false), 42 | counterHeader(0), counterBody(0), counterUncData(0), counterRaw(0), counterInfo(0) {} 43 | ~FfsDumper() {}; 44 | 45 | USTATUS dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const UString & guid = UString()); 46 | 47 | private: 48 | USTATUS recursiveDump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid); 49 | TreeModel* model; 50 | UString currentPath; 51 | bool dumped; 52 | int counterHeader, counterBody, counterUncData, counterRaw, counterInfo; 53 | std::set fileList; 54 | }; 55 | #endif // FFSDUMPER_H 56 | -------------------------------------------------------------------------------- /UEFIExtract/meson.build: -------------------------------------------------------------------------------- 1 | executable( 2 | 'UEFIExtract', 3 | sources: [ 4 | 'uefiextract_main.cpp', 5 | 'ffsdumper.cpp', 6 | 'uefidump.cpp', 7 | ], 8 | link_with: [ 9 | lzma, 10 | bstrlib, 11 | uefitoolcommon, 12 | ], 13 | dependencies: [ 14 | zlib, 15 | ], 16 | install: true, 17 | ) 18 | -------------------------------------------------------------------------------- /UEFIExtract/uefidump.h: -------------------------------------------------------------------------------- 1 | /* uefidump.h 2 | 3 | Copyright (c) 2018, LongSoft. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef UEFIDUMP_H 15 | #define UEFIDUMP_H 16 | 17 | #include "../common/basetypes.h" 18 | #include "../common/ustring.h" 19 | #include "../common/treemodel.h" 20 | #include "../common/ffsparser.h" 21 | #include "../common/ffsreport.h" 22 | 23 | class UEFIDumper 24 | { 25 | public: 26 | explicit UEFIDumper() : model(), ffsParser(&model), ffsReport(&model), currentBuffer(), initialized(false), dumped(false) {} 27 | ~UEFIDumper() {} 28 | 29 | USTATUS dump(const UByteArray & buffer, const UString & path, const UString & guid = UString()); 30 | 31 | private: 32 | USTATUS recursiveDump(const UModelIndex & root); 33 | 34 | TreeModel model; 35 | FfsParser ffsParser; 36 | FfsReport ffsReport; 37 | 38 | UByteArray currentBuffer; 39 | bool initialized; 40 | bool dumped; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /UEFIExtract/uefiextract.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | -------------------------------------------------------------------------------- /UEFIFind/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.22) 2 | 3 | PROJECT(UEFIFind) 4 | 5 | SET(CMAKE_CXX_STANDARD 11) 6 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | SET(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | SET(PROJECT_SOURCES 10 | uefifind_main.cpp 11 | uefifind.cpp 12 | ../common/guiddatabase.cpp 13 | ../common/types.cpp 14 | ../common/filesystem.cpp 15 | ../common/descriptor.cpp 16 | ../common/ffs.cpp 17 | ../common/nvram.cpp 18 | ../common/nvramparser.cpp 19 | ../common/ffsparser.cpp 20 | ../common/fitparser.cpp 21 | ../common/peimage.cpp 22 | ../common/treeitem.cpp 23 | ../common/treemodel.cpp 24 | ../common/utility.cpp 25 | ../common/LZMA/LzmaDecompress.c 26 | ../common/LZMA/SDK/C/Bra.c 27 | ../common/LZMA/SDK/C/Bra86.c 28 | ../common/LZMA/SDK/C/CpuArch.c 29 | ../common/LZMA/SDK/C/LzmaDec.c 30 | ../common/Tiano/EfiTianoDecompress.c 31 | ../common/ustring.cpp 32 | ../common/bstrlib/bstrlib.c 33 | ../common/bstrlib/bstrwrap.cpp 34 | ../common/generated/ami_nvar.cpp 35 | ../common/generated/apple_sysf.cpp 36 | ../common/generated/dell_dvar.cpp 37 | ../common/generated/edk2_vss.cpp 38 | ../common/generated/edk2_vss2.cpp 39 | ../common/generated/edk2_ftw.cpp 40 | ../common/generated/insyde_fdc.cpp 41 | ../common/generated/insyde_fdm.cpp 42 | ../common/generated/ms_slic_marker.cpp 43 | ../common/generated/ms_slic_pubkey.cpp 44 | ../common/generated/phoenix_flm.cpp 45 | ../common/generated/phoenix_evsa.cpp 46 | ../common/generated/intel_acbp_v1.cpp 47 | ../common/generated/intel_acbp_v2.cpp 48 | ../common/generated/intel_keym_v1.cpp 49 | ../common/generated/intel_keym_v2.cpp 50 | ../common/generated/intel_acm.cpp 51 | ../common/kaitai/kaitaistream.cpp 52 | ../common/digest/sha1.c 53 | ../common/digest/sha256.c 54 | ../common/digest/sha512.c 55 | ../common/digest/sm3.c 56 | ../common/zlib/adler32.c 57 | ../common/zlib/compress.c 58 | ../common/zlib/crc32.c 59 | ../common/zlib/deflate.c 60 | ../common/zlib/gzclose.c 61 | ../common/zlib/gzlib.c 62 | ../common/zlib/gzread.c 63 | ../common/zlib/gzwrite.c 64 | ../common/zlib/inflate.c 65 | ../common/zlib/infback.c 66 | ../common/zlib/inftrees.c 67 | ../common/zlib/inffast.c 68 | ../common/zlib/trees.c 69 | ../common/zlib/uncompr.c 70 | ../common/zlib/zutil.c 71 | ) 72 | 73 | ADD_EXECUTABLE(UEFIFind ${PROJECT_SOURCES} uefifind.manifest) 74 | 75 | IF(UNIX) 76 | SET_TARGET_PROPERTIES(UEFIFind PROPERTIES OUTPUT_NAME uefifind) 77 | ENDIF() 78 | 79 | INSTALL( 80 | TARGETS UEFIFind 81 | RUNTIME DESTINATION bin 82 | ) 83 | -------------------------------------------------------------------------------- /UEFIFind/meson.build: -------------------------------------------------------------------------------- 1 | executable( 2 | 'UEFIFind', 3 | sources: [ 4 | 'uefifind_main.cpp', 5 | 'uefifind.cpp', 6 | ], 7 | link_with: [ 8 | lzma, 9 | bstrlib, 10 | uefitoolcommon, 11 | ], 12 | dependencies: [ 13 | zlib, 14 | ], 15 | install: true, 16 | ) 17 | -------------------------------------------------------------------------------- /UEFIFind/uefifind.h: -------------------------------------------------------------------------------- 1 | /* uefifind.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef UEFIFIND_H 15 | #define UEFIFIND_H 16 | 17 | #include 18 | #include 19 | 20 | #include "../common/basetypes.h" 21 | #include "../common/ustring.h" 22 | #include "../common/filesystem.h" 23 | #include "../common/ffsparser.h" 24 | #include "../common/ffs.h" 25 | #include "../common/utility.h" 26 | 27 | class UEFIFind 28 | { 29 | public: 30 | explicit UEFIFind(); 31 | ~UEFIFind(); 32 | 33 | USTATUS init(const UString & path); 34 | USTATUS find(const UINT8 mode, const bool count, const UString & hexPattern, UString & result); 35 | 36 | private: 37 | USTATUS findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set > & files); 38 | 39 | FfsParser* ffsParser; 40 | TreeModel* model; 41 | bool initDone; 42 | }; 43 | 44 | #endif // UEFIFIND_H 45 | -------------------------------------------------------------------------------- /UEFIFind/uefifind.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | -------------------------------------------------------------------------------- /UEFITool/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDocumentTypes 6 | 7 | 8 | CFBundleTypeExtensions 9 | 10 | * 11 | 12 | CFBundleTypeRole 13 | Viewer 14 | LSHandlerRank 15 | None 16 | 17 | 18 | CFBundleExecutable 19 | UEFITool 20 | CFBundleGetInfoString 21 | UEFITool NE 22 | CFBundleIconFile 23 | uefitool 24 | CFBundleIdentifier 25 | me.coderush.UEFITool 26 | CFBundlePackageType 27 | APPL 28 | CFBundleSignature 29 | ???? 30 | NSPrincipalClass 31 | NSApplication 32 | 33 | 34 | -------------------------------------------------------------------------------- /UEFITool/QHexView/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(QHexView) 4 | 5 | option(QHEXVIEW_BUILD_EXAMPLE "Build Example Application" OFF) 6 | option(QHEXVIEW_USE_QT5 "Enable Qt5 build" OFF) 7 | option(QHEXVIEW_ENABLE_DIALOGS "BuiltIn dialogs" OFF) 8 | 9 | if(QHEXVIEW_USE_QT5) 10 | find_package(Qt5 REQUIRED COMPONENTS Widgets) 11 | else() 12 | find_package(Qt6 COMPONENTS Widgets) 13 | 14 | if(NOT Qt6_FOUND) 15 | find_package(Qt5 REQUIRED COMPONENTS Widgets) 16 | endif() 17 | endif() 18 | 19 | add_library(${PROJECT_NAME} STATIC) 20 | 21 | set_target_properties(${PROJECT_NAME} 22 | PROPERTIES 23 | CXX_STANDARD_REQUIRED YES 24 | CXX_STANDARD 11 25 | AUTOMOC ON 26 | ) 27 | 28 | target_link_libraries(${PROJECT_NAME} 29 | PUBLIC 30 | Qt::Widgets 31 | ) 32 | 33 | target_include_directories(${PROJECT_NAME} 34 | PUBLIC 35 | "${PROJECT_SOURCE_DIR}/include" 36 | ) 37 | 38 | target_sources(${PROJECT_NAME} 39 | PRIVATE 40 | include/QHexView/model/buffer/qdevicebuffer.h 41 | include/QHexView/model/buffer/qhexbuffer.h 42 | include/QHexView/model/buffer/qmappedfilebuffer.h 43 | include/QHexView/model/buffer/qmemorybuffer.h 44 | include/QHexView/model/buffer/qmemoryrefbuffer.h 45 | include/QHexView/model/commands/hexcommand.h 46 | include/QHexView/model/commands/insertcommand.h 47 | include/QHexView/model/commands/removecommand.h 48 | include/QHexView/model/commands/replacecommand.h 49 | include/QHexView/model/commands/replacecommand.h 50 | include/QHexView/model/qhexcursor.h 51 | include/QHexView/model/qhexdelegate.h 52 | include/QHexView/model/qhexdocument.h 53 | include/QHexView/model/qhexmetadata.h 54 | include/QHexView/model/qhexoptions.h 55 | include/QHexView/model/qhexutils.h 56 | include/QHexView/qhexview.h 57 | 58 | PRIVATE 59 | src/model/commands/hexcommand.cpp 60 | src/model/commands/insertcommand.cpp 61 | src/model/commands/removecommand.cpp 62 | src/model/commands/replacecommand.cpp 63 | src/model/buffer/qdevicebuffer.cpp 64 | src/model/buffer/qhexbuffer.cpp 65 | src/model/buffer/qmemorybuffer.cpp 66 | src/model/buffer/qmemoryrefbuffer.cpp 67 | src/model/buffer/qmappedfilebuffer.cpp 68 | src/model/qhexdelegate.cpp 69 | src/model/qhexutils.cpp 70 | src/model/qhexcursor.cpp 71 | src/model/qhexmetadata.cpp 72 | src/model/qhexdocument.cpp 73 | src/qhexview.cpp 74 | ) 75 | 76 | if(QHEXVIEW_ENABLE_DIALOGS) 77 | target_sources(${PROJECT_NAME} 78 | PRIVATE 79 | include/QHexView/dialogs/hexfinddialog.h 80 | src/dialogs/hexfinddialog.cpp 81 | ) 82 | 83 | target_compile_definitions(${PROJECT_NAME} 84 | PUBLIC 85 | QHEXVIEW_ENABLE_DIALOGS 86 | ) 87 | endif() 88 | 89 | if(QHEXVIEW_BUILD_EXAMPLE) 90 | add_subdirectory(example) 91 | endif() 92 | -------------------------------------------------------------------------------- /UEFITool/QHexView/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Dax89 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/dialogs/hexfinddialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class QRegularExpressionValidator; 7 | class QDoubleValidator; 8 | class QIntValidator; 9 | class QHexView; 10 | 11 | class HexFindDialog: public QDialog { 12 | Q_OBJECT 13 | 14 | public: 15 | enum class Type { Find, Replace }; 16 | 17 | public: 18 | explicit HexFindDialog(HexFindDialog::Type type = Type::Find, 19 | QHexView* parent = nullptr); 20 | QHexView* hexView() const; 21 | 22 | private Q_SLOTS: 23 | void updateFindOptions(int); 24 | void validateActions(); 25 | void replace(); 26 | void find(); 27 | 28 | private: 29 | bool prepareOptions(QString& q, QHexFindMode& mode, QHexFindDirection& fd); 30 | bool validateIntRange(uint v) const; 31 | void checkResult(const QString& q, qint64 offset, QHexFindDirection fd); 32 | void prepareTextMode(QLayout* l); 33 | void prepareHexMode(QLayout* l); 34 | void prepareIntMode(QLayout* l); 35 | void prepareFloatMode(QLayout* l); 36 | 37 | private: 38 | QRegularExpressionValidator *m_hexvalidator, *m_hexpvalidator; 39 | QDoubleValidator* m_dblvalidator; 40 | QIntValidator* m_intvalidator; 41 | int m_oldidxbits{-1}, m_oldidxendian{-1}; 42 | unsigned int m_findoptions{0}; 43 | qint64 m_startoffset{-1}; 44 | Type m_type; 45 | 46 | private: 47 | static const QString BUTTONBOX; 48 | static const QString CBFINDMODE; 49 | static const QString LEFIND; 50 | static const QString LEREPLACE; 51 | static const QString HLAYOUT; 52 | static const QString GBOPTIONS; 53 | static const QString RBALL; 54 | static const QString RBFORWARD; 55 | static const QString RBBACKWARD; 56 | }; 57 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/buffer/qdevicebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class QDeviceBuffer: public QHexBuffer { 6 | Q_OBJECT 7 | 8 | public: 9 | explicit QDeviceBuffer(QObject* parent = nullptr); 10 | virtual ~QDeviceBuffer(); 11 | uchar at(qint64 idx) override; 12 | qint64 length() const override; 13 | void insert(qint64 offset, const QByteArray& data) override; 14 | void replace(qint64 offset, const QByteArray& data) override; 15 | void remove(qint64 offset, int length) override; 16 | QByteArray read(qint64 offset, int length) override; 17 | bool read(QIODevice* device) override; 18 | void write(QIODevice* device) override; 19 | qint64 indexOf(const QByteArray& ba, qint64 from) override; 20 | qint64 lastIndexOf(const QByteArray& ba, qint64 from) override; 21 | 22 | protected: 23 | QIODevice* m_device{nullptr}; 24 | }; 25 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/buffer/qhexbuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class QHexBuffer: public QObject { 7 | Q_OBJECT 8 | 9 | public: 10 | explicit QHexBuffer(QObject* parent = nullptr); 11 | bool isEmpty() const; 12 | 13 | public: 14 | virtual uchar at(qint64 idx); 15 | virtual bool accept(qint64 idx) const; 16 | virtual void replace(qint64 offset, const QByteArray& data); 17 | virtual void read(char* data, int size); 18 | virtual void read(const QByteArray& ba); 19 | 20 | public: 21 | virtual qint64 length() const = 0; 22 | virtual void insert(qint64 offset, const QByteArray& data) = 0; 23 | virtual void remove(qint64 offset, int length) = 0; 24 | virtual QByteArray read(qint64 offset, int length) = 0; 25 | virtual bool read(QIODevice* iodevice) = 0; 26 | virtual void write(QIODevice* iodevice) = 0; 27 | virtual qint64 indexOf(const QByteArray& ba, qint64 from) = 0; 28 | virtual qint64 lastIndexOf(const QByteArray& ba, qint64 from) = 0; 29 | }; 30 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/buffer/qmappedfilebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class QMappedFileBuffer: public QDeviceBuffer { 6 | public: 7 | explicit QMappedFileBuffer(QObject* parent = nullptr); 8 | virtual ~QMappedFileBuffer(); 9 | 10 | public: 11 | QByteArray read(qint64 offset, int length) override; 12 | bool read(QIODevice* iodevice) override; 13 | void write(QIODevice* iodevice) override; 14 | 15 | private: 16 | void remap(); 17 | 18 | private: 19 | uchar* m_mappeddata{nullptr}; 20 | }; 21 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/buffer/qmemorybuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class QMemoryBuffer: public QHexBuffer { 6 | Q_OBJECT 7 | 8 | public: 9 | explicit QMemoryBuffer(QObject* parent = nullptr); 10 | uchar at(qint64 idx) override; 11 | qint64 length() const override; 12 | void insert(qint64 offset, const QByteArray& data) override; 13 | void remove(qint64 offset, int length) override; 14 | QByteArray read(qint64 offset, int length) override; 15 | bool read(QIODevice* device) override; 16 | void write(QIODevice* device) override; 17 | qint64 indexOf(const QByteArray& ba, qint64 from) override; 18 | qint64 lastIndexOf(const QByteArray& ba, qint64 from) override; 19 | 20 | private: 21 | QByteArray m_buffer; 22 | }; 23 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/buffer/qmemoryrefbuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class QMemoryRefBuffer: public QDeviceBuffer { 6 | Q_OBJECT 7 | 8 | public: 9 | explicit QMemoryRefBuffer(QObject* parent = nullptr); 10 | bool read(QIODevice* device) override; 11 | void write(QIODevice* device) override; 12 | }; 13 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/commands/hexcommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class QHexDocument; 7 | 8 | class HexCommand: public QUndoCommand { 9 | public: 10 | HexCommand(QHexBuffer* buffer, QHexDocument* document, 11 | QUndoCommand* parent = nullptr); 12 | 13 | protected: 14 | QHexDocument* m_hexdocument; 15 | QHexBuffer* m_buffer; 16 | qint64 m_offset; 17 | int m_length; 18 | QByteArray m_data; 19 | }; 20 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/commands/insertcommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class InsertCommand: public HexCommand { 6 | public: 7 | InsertCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset, 8 | const QByteArray& data, QUndoCommand* parent = nullptr); 9 | void undo() override; 10 | void redo() override; 11 | }; 12 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/commands/removecommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class RemoveCommand: public HexCommand { 6 | public: 7 | RemoveCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset, 8 | int length, QUndoCommand* parent = nullptr); 9 | void undo() override; 10 | void redo() override; 11 | }; 12 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/commands/replacecommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class ReplaceCommand: public HexCommand { 6 | public: 7 | ReplaceCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset, 8 | const QByteArray& data, QUndoCommand* parent = nullptr); 9 | void undo() override; 10 | void redo() override; 11 | 12 | private: 13 | QByteArray m_olddata; 14 | }; 15 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/qhexcursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class QHexView; 8 | 9 | class QHexCursor: public QObject { 10 | Q_OBJECT 11 | 12 | public: 13 | enum class Mode { Overwrite, Insert }; 14 | 15 | private: 16 | explicit QHexCursor(const QHexOptions* options, QHexView* parent = nullptr); 17 | 18 | public: 19 | QHexView* hexView() const; 20 | Mode mode() const; 21 | qint64 line() const; 22 | qint64 column() const; 23 | qint64 offset() const; 24 | qint64 address() const; 25 | quint64 lineAddress() const; 26 | qint64 selectionStartOffset() const; 27 | qint64 selectionEndOffset() const; 28 | qint64 selectionLength() const; 29 | QHexPosition position() const; 30 | QHexPosition selectionStart() const; 31 | QHexPosition selectionEnd() const; 32 | QByteArray selectedBytes() const; 33 | bool hasSelection() const; 34 | bool isSelected(qint64 line, qint64 column) const; 35 | void setMode(Mode m); 36 | void move(qint64 offset); 37 | void move(qint64 line, qint64 column); 38 | void move(QHexPosition pos); 39 | void select(qint64 offset); 40 | void select(qint64 line, qint64 column); 41 | void select(QHexPosition pos); 42 | void selectSize(qint64 length); 43 | qint64 replace(const QVariant& oldvalue, const QVariant& newvalue, 44 | qint64 offset, QHexFindMode mode = QHexFindMode::Text, 45 | unsigned int options = QHexFindOptions::None, 46 | QHexFindDirection fd = QHexFindDirection::Forward) const; 47 | qint64 find(const QVariant& value, qint64 offset, 48 | QHexFindMode mode = QHexFindMode::Text, 49 | unsigned int options = QHexFindOptions::None, 50 | QHexFindDirection fd = QHexFindDirection::Forward) const; 51 | qint64 positionToOffset(QHexPosition pos) const; 52 | QHexPosition offsetToPosition(qint64 offset) const; 53 | 54 | public Q_SLOTS: 55 | void cut(bool hex = false); 56 | void copy(bool hex = false) const; 57 | void paste(bool hex = false); 58 | void selectAll(); 59 | void removeSelection(); 60 | void clearSelection(); 61 | void switchMode(); 62 | 63 | Q_SIGNALS: 64 | void positionChanged(); 65 | void modeChanged(); 66 | 67 | private: 68 | const QHexOptions* m_options; 69 | Mode m_mode{Mode::Overwrite}; 70 | QHexPosition m_position{}, m_selection{}; 71 | 72 | friend class QHexView; 73 | }; 74 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/qhexdelegate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class QHexView; 8 | 9 | class QHexDelegate: public QObject { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QHexDelegate(QObject* parent = nullptr); 14 | virtual ~QHexDelegate() = default; 15 | virtual QString addressHeader(const QHexView* hexview) const; 16 | virtual QString hexHeader(const QHexView* hexview) const; 17 | virtual QString asciiHeader(const QHexView* hexview) const; 18 | virtual void renderAddress(quint64 address, QTextCharFormat& cf, 19 | const QHexView* hexview) const; 20 | virtual void renderHeader(QTextBlockFormat& bf, 21 | const QHexView* hexview) const; 22 | virtual void renderHeaderPart(const QString& s, QHexArea area, 23 | QTextCharFormat& cf, 24 | const QHexView* hexview) const; 25 | virtual bool render(quint64 offset, quint8 b, QTextCharFormat& outcf, 26 | const QHexView* hexview) const; 27 | virtual bool paintSeparator(QPainter* painter, QLineF line, 28 | const QHexView* hexview) const; 29 | virtual void paint(QPainter* painter, const QHexView* hexview) const; 30 | }; 31 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/qhexmetadata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct QHexMetadataItem { 11 | qint64 begin, end; 12 | QColor foreground, background; 13 | QString comment; 14 | }; 15 | 16 | using QHexMetadataLine = QList; 17 | 18 | class QHexMetadata: public QObject { 19 | Q_OBJECT 20 | 21 | private: 22 | using ClearMetadataCallback = std::function; 23 | 24 | private: 25 | explicit QHexMetadata(const QHexOptions* options, 26 | QObject* parent = nullptr); 27 | 28 | public: 29 | const QHexMetadataLine* find(qint64 line) const; 30 | QString getComment(qint64 line, qint64 column) const; 31 | void removeMetadata(qint64 line); 32 | void removeBackground(qint64 line); 33 | void removeForeground(qint64 line); 34 | void removeComments(qint64 line); 35 | void unhighlight(qint64 line); 36 | void clear(); 37 | 38 | public: 39 | inline void setMetadata(qint64 begin, qint64 end, const QColor& fgcolor, 40 | const QColor& bgcolor, const QString& comment) { 41 | this->setMetadata({begin, end, fgcolor, bgcolor, comment}); 42 | } 43 | 44 | inline void setForeground(qint64 begin, qint64 end, const QColor& fgcolor) { 45 | this->setMetadata(begin, end, fgcolor, QColor(), QString()); 46 | } 47 | 48 | inline void setBackground(qint64 begin, qint64 end, const QColor& bgcolor) { 49 | this->setMetadata(begin, end, QColor(), bgcolor, QString()); 50 | } 51 | 52 | inline void setComment(qint64 begin, qint64 end, const QString& comment) { 53 | this->setMetadata(begin, end, QColor(), QColor(), comment); 54 | }; 55 | 56 | inline void setMetadataSize(qint64 begin, qint64 length, 57 | const QColor& fgcolor, const QColor& bgcolor, 58 | const QString& comment) { 59 | this->setMetadata({begin, begin + length, fgcolor, bgcolor, comment}); 60 | } 61 | 62 | inline void setForegroundSize(qint64 begin, qint64 length, 63 | const QColor& fgcolor) { 64 | this->setForeground(begin, begin + length, fgcolor); 65 | } 66 | 67 | inline void setBackgroundSize(qint64 begin, qint64 length, 68 | const QColor& bgcolor) { 69 | this->setBackground(begin, begin + length, bgcolor); 70 | } 71 | 72 | inline void setCommentSize(qint64 begin, qint64 length, 73 | const QString& comment) { 74 | this->setComment(begin, begin + length, comment); 75 | }; 76 | 77 | private: 78 | void copy(const QHexMetadata* metadata); 79 | void clearMetadata(qint64 line, ClearMetadataCallback&& cb); 80 | void setMetadata(const QHexMetadataItem& mi); 81 | void invalidate(); 82 | 83 | Q_SIGNALS: 84 | void changed(); 85 | void cleared(); 86 | 87 | private: 88 | QHash m_metadata; 89 | const QHexOptions* m_options; 90 | 91 | friend class QHexView; 92 | }; 93 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/qhexoptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace QHexFlags { 8 | 9 | enum : unsigned int { 10 | None = (1 << 0), 11 | HSeparator = (1 << 1), 12 | VSeparator = (1 << 2), 13 | StyledHeader = (1 << 3), 14 | StyledAddress = (1 << 4), 15 | NoHeader = (1 << 5), 16 | HighlightAddress = (1 << 6), 17 | HighlightColumn = (1 << 7), 18 | 19 | Separators = HSeparator | VSeparator, 20 | Styled = StyledHeader | StyledAddress, 21 | }; 22 | 23 | } 24 | 25 | struct QHexColor { 26 | QColor foreground; 27 | QColor background; 28 | }; 29 | 30 | struct QHexOptions { 31 | // Appearance 32 | QChar unprintablechar{'.'}; 33 | QChar invalidchar{'?'}; 34 | QString addresslabel{""}; 35 | QString hexlabel; 36 | QString asciilabel; 37 | quint64 baseaddress{0}; 38 | unsigned int flags{QHexFlags::None}; 39 | unsigned int linelength{0x10}; 40 | unsigned int addresswidth{0}; 41 | unsigned int grouplength{1}; 42 | int scrollsteps{1}; 43 | 44 | // Colors & Styles 45 | QHash bytecolors; 46 | QColor linealternatebackground; 47 | QColor linebackground; 48 | QColor headercolor; 49 | QColor commentcolor; 50 | QColor separatorcolor; 51 | 52 | // Misc 53 | bool copybreak{true}; 54 | 55 | inline bool hasFlag(unsigned int flag) const { return flags & flag; } 56 | }; 57 | -------------------------------------------------------------------------------- /UEFITool/QHexView/include/QHexView/model/qhexutils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct QHexOptions; 9 | class QHexView; 10 | 11 | namespace QHexFindOptions { 12 | 13 | enum : unsigned int { 14 | None = (1 << 0), 15 | CaseSensitive = (1 << 1), 16 | Int8 = (1 << 2), 17 | Int16 = (1 << 3), 18 | Int32 = (1 << 4), 19 | Int64 = (1 << 5), 20 | Float = (1 << 6), 21 | Double = (1 << 7), 22 | 23 | BigEndian = (1 << 11), 24 | }; 25 | 26 | } 27 | 28 | enum class QHexFindMode { Text, Hex, Int, Float }; 29 | enum class QHexFindDirection { All, Forward, Backward }; 30 | enum class QHexArea { Header, Address, Hex, Ascii, Extra }; 31 | 32 | struct QHexPosition { 33 | qint64 line; 34 | qint64 column; 35 | static inline QHexPosition invalid() { return {-1, -1}; } 36 | inline bool isValid() const { return line >= 0 && column >= 0; } 37 | inline bool operator==(const QHexPosition& rhs) const { 38 | return (line == rhs.line) && (column == rhs.column); 39 | } 40 | inline bool operator!=(const QHexPosition& rhs) const { 41 | return (line != rhs.line) || (column != rhs.column); 42 | } 43 | }; 44 | 45 | namespace QHexUtils { 46 | 47 | bool isHex(char ch); 48 | QByteArray toHex(const QByteArray& ba, char sep); 49 | QByteArray toHex(const QByteArray& ba); 50 | qint64 positionToOffset(const QHexOptions* options, QHexPosition pos); 51 | QHexPosition offsetToPosition(const QHexOptions* options, qint64 offset); 52 | bool checkPattern(QString pattern); 53 | 54 | QPair find(const QHexView* hexview, QVariant value, 55 | qint64 startoffset = 0, 56 | QHexFindMode mode = QHexFindMode::Text, 57 | unsigned int options = QHexFindOptions::None, 58 | QHexFindDirection fd = QHexFindDirection::Forward); 59 | 60 | QPair 61 | replace(const QHexView* hexview, QVariant oldvalue, QVariant newvalue, 62 | qint64 startoffset = 0, QHexFindMode mode = QHexFindMode::Text, 63 | unsigned int options = QHexFindOptions::None, 64 | QHexFindDirection fd = QHexFindDirection::Forward); 65 | 66 | } // namespace QHexUtils 67 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/buffer/qdevicebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | QDeviceBuffer::QDeviceBuffer(QObject* parent): QHexBuffer{parent} {} 6 | 7 | QDeviceBuffer::~QDeviceBuffer() { 8 | if(!m_device) 9 | return; 10 | 11 | if(m_device->parent() == this) { 12 | if(m_device->isOpen()) 13 | m_device->close(); 14 | m_device->deleteLater(); 15 | } 16 | 17 | m_device = nullptr; 18 | } 19 | 20 | uchar QDeviceBuffer::at(qint64 idx) { 21 | m_device->seek(idx); 22 | 23 | char c = '\0'; 24 | m_device->getChar(&c); 25 | return static_cast(c); 26 | } 27 | 28 | qint64 QDeviceBuffer::length() const { return m_device->size(); } 29 | 30 | void QDeviceBuffer::insert(qint64 offset, const QByteArray& data) { 31 | Q_UNUSED(offset) 32 | Q_UNUSED(data) 33 | // Not implemented 34 | } 35 | 36 | void QDeviceBuffer::replace(qint64 offset, const QByteArray& data) { 37 | m_device->seek(offset); 38 | m_device->write(data); 39 | } 40 | 41 | void QDeviceBuffer::remove(qint64 offset, int length) { 42 | Q_UNUSED(offset) 43 | Q_UNUSED(length) 44 | // Not implemented 45 | } 46 | 47 | QByteArray QDeviceBuffer::read(qint64 offset, int length) { 48 | m_device->seek(offset); 49 | return m_device->read(length); 50 | } 51 | 52 | bool QDeviceBuffer::read(QIODevice* device) { 53 | m_device = device; 54 | if(!m_device) 55 | return false; 56 | if(!m_device->isOpen()) 57 | m_device->open(QIODevice::ReadWrite); 58 | return m_device->isOpen(); 59 | } 60 | 61 | void QDeviceBuffer::write(QIODevice* device) { 62 | Q_UNUSED(device) 63 | // Not implemented 64 | } 65 | 66 | qint64 QDeviceBuffer::indexOf(const QByteArray& ba, qint64 from) { 67 | const auto MAX = std::numeric_limits::max(); 68 | qint64 idx = -1; 69 | 70 | if(from < m_device->size()) { 71 | idx = from; 72 | m_device->seek(from); 73 | 74 | while(idx < m_device->size()) { 75 | QByteArray data = m_device->read(MAX); 76 | int sidx = data.indexOf(ba); 77 | 78 | if(sidx >= 0) { 79 | idx += sidx; 80 | break; 81 | } 82 | 83 | if(idx + data.size() >= m_device->size()) 84 | return -1; 85 | m_device->seek(m_device->pos() + data.size() - ba.size()); 86 | } 87 | } 88 | 89 | return idx; 90 | } 91 | 92 | qint64 QDeviceBuffer::lastIndexOf(const QByteArray& ba, qint64 from) { 93 | const auto MAX = std::numeric_limits::max(); 94 | qint64 idx = -1; 95 | 96 | if(from >= 0 && ba.size() < MAX) { 97 | qint64 currpos = from; 98 | 99 | while(currpos >= 0) { 100 | qint64 readpos = (currpos < MAX) ? 0 : currpos - MAX; 101 | m_device->seek(readpos); 102 | 103 | QByteArray data = m_device->read(currpos - readpos); 104 | int lidx = data.lastIndexOf(ba, from); 105 | 106 | if(lidx >= 0) { 107 | idx = readpos + lidx; 108 | break; 109 | } 110 | 111 | if(readpos <= 0) 112 | break; 113 | currpos = readpos + ba.size(); 114 | } 115 | } 116 | 117 | return idx; 118 | } 119 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/buffer/qhexbuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | QHexBuffer::QHexBuffer(QObject* parent): QObject{parent} {} 5 | uchar QHexBuffer::at(qint64 idx) { return this->read(idx, 1).at(0); } 6 | bool QHexBuffer::isEmpty() const { return this->length() <= 0; } 7 | 8 | void QHexBuffer::replace(qint64 offset, const QByteArray& data) { 9 | this->remove(offset, data.length()); 10 | this->insert(offset, data); 11 | } 12 | 13 | bool QHexBuffer::accept(qint64 idx) const { 14 | Q_UNUSED(idx); 15 | return true; 16 | } 17 | 18 | void QHexBuffer::read(char* data, int size) { 19 | QBuffer* buffer = new QBuffer(this); 20 | buffer->setData(data, size); 21 | 22 | if(!buffer->isOpen()) 23 | buffer->open(QBuffer::ReadWrite); 24 | 25 | this->read(buffer); 26 | } 27 | 28 | void QHexBuffer::read(const QByteArray& ba) { 29 | QBuffer* buffer = new QBuffer(this); 30 | 31 | buffer->setData(ba); 32 | if(!buffer->isOpen()) 33 | buffer->open(QBuffer::ReadWrite); 34 | 35 | this->read(buffer); 36 | } 37 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/buffer/qmappedfilebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | QMappedFileBuffer::QMappedFileBuffer(QObject* parent): QDeviceBuffer{parent} {} 5 | 6 | QMappedFileBuffer::~QMappedFileBuffer() { 7 | if((m_device && (m_device->parent() == this)) && m_mappeddata) { 8 | QFile* f = qobject_cast(m_device); 9 | f->unmap(m_mappeddata); 10 | } 11 | 12 | m_mappeddata = nullptr; 13 | } 14 | 15 | QByteArray QMappedFileBuffer::read(qint64 offset, int length) { 16 | if(offset >= this->length()) 17 | return {}; 18 | 19 | if(offset + length >= this->length()) 20 | length = this->length() - offset; 21 | 22 | return QByteArray::fromRawData( 23 | reinterpret_cast(m_mappeddata + offset), length); 24 | } 25 | 26 | bool QMappedFileBuffer::read(QIODevice* iodevice) { 27 | m_device = qobject_cast(iodevice); 28 | if(!m_device || !QDeviceBuffer::read(iodevice)) 29 | return false; 30 | 31 | this->remap(); 32 | return m_mappeddata; 33 | } 34 | 35 | void QMappedFileBuffer::write(QIODevice* iodevice) { 36 | if(iodevice == m_device) 37 | this->remap(); 38 | else 39 | iodevice->write(reinterpret_cast(m_mappeddata), 40 | m_device->size()); 41 | } 42 | 43 | void QMappedFileBuffer::remap() { 44 | QFile* f = qobject_cast(m_device); 45 | if(!f) 46 | return; 47 | 48 | if(m_mappeddata) 49 | f->unmap(m_mappeddata); 50 | m_mappeddata = f->map(0, f->size()); 51 | } 52 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/buffer/qmemorybuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | QMemoryBuffer::QMemoryBuffer(QObject* parent): QHexBuffer{parent} {} 5 | 6 | uchar QMemoryBuffer::at(qint64 idx) { 7 | return static_cast(m_buffer.at(idx)); 8 | } 9 | 10 | qint64 QMemoryBuffer::length() const { 11 | return static_cast(m_buffer.length()); 12 | } 13 | 14 | void QMemoryBuffer::insert(qint64 offset, const QByteArray& data) { 15 | m_buffer.insert(static_cast(offset), data); 16 | } 17 | 18 | void QMemoryBuffer::remove(qint64 offset, int length) { 19 | m_buffer.remove(static_cast(offset), length); 20 | } 21 | 22 | QByteArray QMemoryBuffer::read(qint64 offset, int length) { 23 | return m_buffer.mid(static_cast(offset), length); 24 | } 25 | 26 | bool QMemoryBuffer::read(QIODevice* device) { 27 | m_buffer = device->readAll(); 28 | return true; 29 | } 30 | 31 | void QMemoryBuffer::write(QIODevice* device) { device->write(m_buffer); } 32 | 33 | qint64 QMemoryBuffer::indexOf(const QByteArray& ba, qint64 from) { 34 | return m_buffer.indexOf(ba, static_cast(from)); 35 | } 36 | 37 | qint64 QMemoryBuffer::lastIndexOf(const QByteArray& ba, qint64 from) { 38 | return m_buffer.lastIndexOf(ba, static_cast(from)); 39 | } 40 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/buffer/qmemoryrefbuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | QMemoryRefBuffer::QMemoryRefBuffer(QObject* parent): QDeviceBuffer{parent} {} 5 | 6 | bool QMemoryRefBuffer::read(QIODevice* device) { 7 | m_device = qobject_cast(device); 8 | 9 | if(m_device) { 10 | m_device->setParent(this); 11 | return QDeviceBuffer::read(device); 12 | } 13 | 14 | return false; 15 | } 16 | 17 | void QMemoryRefBuffer::write(QIODevice* device) { 18 | if(!m_device || m_device == device) 19 | return; 20 | 21 | static const int CHUNK_SIZE = 4096; 22 | m_device->seek(0); 23 | 24 | while(!m_device->atEnd()) 25 | device->write(m_device->read(CHUNK_SIZE)); 26 | } 27 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/commands/hexcommand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | HexCommand::HexCommand(QHexBuffer* buffer, QHexDocument* document, 4 | QUndoCommand* parent) 5 | : QUndoCommand(parent), m_hexdocument(document), m_buffer(buffer), 6 | m_offset(0), m_length(0) {} 7 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/commands/insertcommand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | InsertCommand::InsertCommand(QHexBuffer* buffer, QHexDocument* document, 5 | qint64 offset, const QByteArray& data, 6 | QUndoCommand* parent) 7 | : HexCommand(buffer, document, parent) { 8 | m_offset = offset; 9 | m_data = data; 10 | } 11 | 12 | void InsertCommand::undo() { 13 | m_buffer->remove(m_offset, m_data.length()); 14 | Q_EMIT m_hexdocument->dataChanged(m_data, m_offset, 15 | QHexDocument::ChangeReason::Remove); 16 | } 17 | 18 | void InsertCommand::redo() { m_buffer->insert(m_offset, m_data); } 19 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/commands/removecommand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | RemoveCommand::RemoveCommand(QHexBuffer* buffer, QHexDocument* document, 5 | qint64 offset, int length, QUndoCommand* parent) 6 | : HexCommand(buffer, document, parent) { 7 | m_offset = offset; 8 | m_length = length; 9 | } 10 | 11 | void RemoveCommand::undo() { 12 | m_buffer->insert(m_offset, m_data); 13 | Q_EMIT m_hexdocument->dataChanged(m_data, m_offset, 14 | QHexDocument::ChangeReason::Insert); 15 | } 16 | 17 | void RemoveCommand::redo() { 18 | m_data = m_buffer->read(m_offset, m_length); // Backup data 19 | m_buffer->remove(m_offset, m_length); 20 | } 21 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/commands/replacecommand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ReplaceCommand::ReplaceCommand(QHexBuffer* buffer, QHexDocument* document, 5 | qint64 offset, const QByteArray& data, 6 | QUndoCommand* parent) 7 | : HexCommand(buffer, document, parent) { 8 | m_offset = offset; 9 | m_data = data; 10 | } 11 | 12 | void ReplaceCommand::undo() { 13 | m_buffer->replace(m_offset, m_olddata); 14 | Q_EMIT m_hexdocument->dataChanged(m_olddata, m_offset, 15 | QHexDocument::ChangeReason::Replace); 16 | } 17 | 18 | void ReplaceCommand::redo() { 19 | m_olddata = m_buffer->read(m_offset, m_data.length()); 20 | m_buffer->replace(m_offset, m_data); 21 | } 22 | -------------------------------------------------------------------------------- /UEFITool/QHexView/src/model/qhexdelegate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | QHexDelegate::QHexDelegate(QObject* parent): QObject{parent} {} 5 | 6 | QString QHexDelegate::addressHeader(const QHexView* hexview) const { 7 | Q_UNUSED(hexview); 8 | return QString(); 9 | } 10 | 11 | QString QHexDelegate::hexHeader(const QHexView* hexview) const { 12 | Q_UNUSED(hexview); 13 | return QString(); 14 | } 15 | 16 | QString QHexDelegate::asciiHeader(const QHexView* hexview) const { 17 | Q_UNUSED(hexview); 18 | return QString(); 19 | } 20 | 21 | void QHexDelegate::renderAddress(quint64 address, QTextCharFormat& cf, 22 | const QHexView* hexview) const { 23 | Q_UNUSED(address); 24 | Q_UNUSED(hexview); 25 | Q_UNUSED(cf); 26 | Q_UNUSED(hexview); 27 | } 28 | 29 | void QHexDelegate::renderHeader(QTextBlockFormat& bf, 30 | const QHexView* hexview) const { 31 | Q_UNUSED(bf); 32 | Q_UNUSED(hexview); 33 | } 34 | 35 | void QHexDelegate::renderHeaderPart(const QString& s, QHexArea area, 36 | QTextCharFormat& cf, 37 | const QHexView* hexview) const { 38 | Q_UNUSED(s); 39 | Q_UNUSED(area); 40 | Q_UNUSED(cf); 41 | Q_UNUSED(hexview); 42 | } 43 | 44 | bool QHexDelegate::render(quint64 offset, quint8 b, QTextCharFormat& outcf, 45 | const QHexView* hexview) const { 46 | Q_UNUSED(offset); 47 | Q_UNUSED(b); 48 | Q_UNUSED(outcf); 49 | Q_UNUSED(hexview); 50 | 51 | return false; 52 | } 53 | 54 | bool QHexDelegate::paintSeparator(QPainter* painter, QLineF line, 55 | const QHexView* hexview) const { 56 | Q_UNUSED(painter); 57 | Q_UNUSED(line); 58 | Q_UNUSED(hexview); 59 | return false; 60 | } 61 | 62 | void QHexDelegate::paint(QPainter* painter, const QHexView* hexview) const { 63 | Q_UNUSED(hexview); 64 | hexview->paint(painter); 65 | } 66 | -------------------------------------------------------------------------------- /UEFITool/ffsfinder.h: -------------------------------------------------------------------------------- 1 | /* fssfinder.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FFSFINDER_H 15 | #define FFSFINDER_H 16 | 17 | #include 18 | 19 | #include "../common/ubytearray.h" 20 | #include "../common/ustring.h" 21 | #include "../common/basetypes.h" 22 | #include "../common/treemodel.h" 23 | 24 | class FfsFinder 25 | { 26 | public: 27 | FfsFinder(const TreeModel * treeModel) : model(treeModel) {} 28 | ~FfsFinder() {} 29 | 30 | std::vector > getMessages() const { return messagesVector; } 31 | void clearMessages() { messagesVector.clear(); } 32 | 33 | USTATUS findHexPattern(const UByteArray & hexPattern, const UINT8 mode); 34 | USTATUS findGuidPattern(const UByteArray & guidPattern, const UINT8 mode); 35 | USTATUS findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive); 36 | 37 | private: 38 | const TreeModel* model; 39 | std::vector > messagesVector; 40 | 41 | void msg(const UString & message, const UModelIndex &index = UModelIndex()) { 42 | messagesVector.push_back(std::pair(message, index)); 43 | } 44 | 45 | USTATUS findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode); 46 | USTATUS findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode); 47 | USTATUS findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive); 48 | }; 49 | 50 | #endif // FFSFINDER_H 51 | -------------------------------------------------------------------------------- /UEFITool/gotoaddressdialog.h: -------------------------------------------------------------------------------- 1 | /* gotoaddressdialog.h 2 | 3 | Copyright (c) 2018, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef GOTOADDRESSDIALOG_H 15 | #define GOTOADDRESSDIALOG_H 16 | 17 | #include 18 | #include 19 | #include "ui_gotoaddressdialog.h" 20 | class GoToAddressDialog : public QDialog 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | GoToAddressDialog(QWidget* parent = NULL) : 26 | QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), 27 | ui(new Ui::GoToAddressDialog) { 28 | ui->setupUi(this); 29 | } 30 | 31 | ~GoToAddressDialog() { delete ui; } 32 | 33 | Ui::GoToAddressDialog* ui; 34 | }; 35 | 36 | #endif // GOTOADDRESSDIALOG_H 37 | -------------------------------------------------------------------------------- /UEFITool/gotoaddressdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | GoToAddressDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 270 10 | 86 11 | 12 | 13 | 14 | Select item at address 15 | 16 | 17 | false 18 | 19 | 20 | 21 | 5 22 | 23 | 24 | 5 25 | 26 | 27 | 5 28 | 29 | 30 | 5 31 | 32 | 33 | 5 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 5 43 | 44 | 45 | 5 46 | 47 | 48 | 5 49 | 50 | 51 | 5 52 | 53 | 54 | 5 55 | 56 | 57 | 58 | 59 | Select item at address: 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Qt::Horizontal 80 | 81 | 82 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | HexSpinBox 91 | QSpinBox 92 |
hexspinbox.h
93 |
94 |
95 | 96 | buttonBox 97 | 98 | 99 | 100 | 101 | buttonBox 102 | accepted() 103 | GoToAddressDialog 104 | accept() 105 | 106 | 107 | 182 108 | 185 109 | 110 | 111 | 157 112 | 194 113 | 114 | 115 | 116 | 117 | buttonBox 118 | rejected() 119 | GoToAddressDialog 120 | reject() 121 | 122 | 123 | 182 124 | 185 125 | 126 | 127 | 286 128 | 194 129 | 130 | 131 | 132 | 133 |
134 | -------------------------------------------------------------------------------- /UEFITool/gotobasedialog.h: -------------------------------------------------------------------------------- 1 | /* gotobasedialog.h 2 | 3 | Copyright (c) 2018, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef GOTOBASEDIALOG_H 15 | #define GOTOBASEDIALOG_H 16 | 17 | #include 18 | #include 19 | #include "ui_gotobasedialog.h" 20 | class GoToBaseDialog : public QDialog 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | GoToBaseDialog(QWidget* parent = NULL): 26 | QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), 27 | ui(new Ui::GoToBaseDialog) { 28 | ui->setupUi(this); 29 | } 30 | 31 | ~GoToBaseDialog() {delete ui;} 32 | 33 | Ui::GoToBaseDialog* ui; 34 | }; 35 | 36 | #endif // GOTOBASEDIALOG_H 37 | -------------------------------------------------------------------------------- /UEFITool/gotobasedialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | GoToBaseDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 270 10 | 86 11 | 12 | 13 | 14 | Select item at base 15 | 16 | 17 | false 18 | 19 | 20 | 21 | 5 22 | 23 | 24 | 5 25 | 26 | 27 | 5 28 | 29 | 30 | 5 31 | 32 | 33 | 5 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 5 43 | 44 | 45 | 5 46 | 47 | 48 | 5 49 | 50 | 51 | 5 52 | 53 | 54 | 5 55 | 56 | 57 | 58 | 59 | Select item at base: 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Qt::Horizontal 80 | 81 | 82 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | HexSpinBox 91 | QSpinBox 92 |
hexspinbox.h
93 |
94 |
95 | 96 | buttonBox 97 | 98 | 99 | 100 | 101 | buttonBox 102 | accepted() 103 | GoToBaseDialog 104 | accept() 105 | 106 | 107 | 182 108 | 185 109 | 110 | 111 | 157 112 | 194 113 | 114 | 115 | 116 | 117 | buttonBox 118 | rejected() 119 | GoToBaseDialog 120 | reject() 121 | 122 | 123 | 182 124 | 185 125 | 126 | 127 | 286 128 | 194 129 | 130 | 131 | 132 | 133 |
134 | -------------------------------------------------------------------------------- /UEFITool/hexlineedit.cpp: -------------------------------------------------------------------------------- 1 | /* hexlineedit.cpp 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "hexlineedit.h" 15 | 16 | #if QT_VERSION_MAJOR >= 6 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | HexLineEdit::HexLineEdit(QWidget * parent) 23 | :QLineEdit(parent) 24 | { 25 | m_editAsGuid = false; 26 | } 27 | 28 | HexLineEdit::HexLineEdit(const QString & contents, QWidget * parent) 29 | :QLineEdit(contents, parent) 30 | { 31 | m_editAsGuid = false; 32 | } 33 | 34 | HexLineEdit::~HexLineEdit() 35 | { 36 | } 37 | 38 | void HexLineEdit::keyPressEvent(QKeyEvent * event) 39 | { 40 | QClipboard *clipboard; 41 | QString originalText; 42 | 43 | if (m_editAsGuid && (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace)) 44 | { 45 | int pos = cursorPosition(); 46 | if (event->key() == Qt::Key_Backspace && pos > 0) { 47 | cursorBackward(false); 48 | pos = cursorPosition(); 49 | } 50 | 51 | QString txt = text(); 52 | QString selected = selectedText(); 53 | 54 | if (!selected.isEmpty()) { 55 | pos = QLineEdit::selectionStart(); 56 | for (int i = pos; i < pos + selected.length(); i++) 57 | if (txt[i] != QChar('-')) 58 | txt[i] = QChar('.'); 59 | } 60 | else { 61 | txt[pos] = QChar('.'); 62 | } 63 | 64 | setCursorPosition(0); 65 | insert(txt); 66 | setCursorPosition(pos); 67 | 68 | return; 69 | } 70 | 71 | if (event == QKeySequence::Paste) 72 | { 73 | clipboard = QApplication::clipboard(); 74 | originalText = clipboard->text(); 75 | QString cleanedHex = QString(originalText).replace(QString("0x"), QString(""), Qt::CaseInsensitive); 76 | #if QT_VERSION_MAJOR >= 6 77 | cleanedHex.remove(QRegularExpression("[^a-fA-F\\d]+")); 78 | #else 79 | cleanedHex.remove(QRegExp("[^a-fA-F\\d]+")); 80 | #endif 81 | clipboard->setText(cleanedHex); 82 | } 83 | 84 | // Call original event handler 85 | QLineEdit::keyPressEvent(event); 86 | } 87 | -------------------------------------------------------------------------------- /UEFITool/hexlineedit.h: -------------------------------------------------------------------------------- 1 | /* hexlineedit.h 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef HEXLINEEDIT_H 15 | #define HEXLINEEDIT_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/basetypes.h" 25 | 26 | class HexLineEdit : public QLineEdit 27 | { 28 | Q_OBJECT 29 | Q_PROPERTY(bool editAsGuid READ editAsGuid WRITE setEditAsGuid) 30 | 31 | public: 32 | HexLineEdit(QWidget * parent = 0); 33 | HexLineEdit(const QString & contents, QWidget * parent = 0); 34 | ~HexLineEdit(); 35 | 36 | void setEditAsGuid(bool editAsGuid) 37 | { 38 | m_editAsGuid = editAsGuid; 39 | } 40 | bool editAsGuid() const 41 | { return m_editAsGuid; } 42 | 43 | private: 44 | bool m_editAsGuid; 45 | 46 | protected: 47 | void keyPressEvent(QKeyEvent * event); 48 | 49 | }; 50 | 51 | #endif // HEXLINEEDIT_H 52 | -------------------------------------------------------------------------------- /UEFITool/hexspinbox.cpp: -------------------------------------------------------------------------------- 1 | /* hexspinbox.cpp 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "hexspinbox.h" 15 | #include 16 | 17 | HexSpinBox::HexSpinBox(QWidget *parent) : 18 | #if QT_VERSION_MAJOR >= 6 19 | QSpinBox(parent), validator(QRegularExpression("0x([0-9a-fA-F]){1,8}")) 20 | #else 21 | QSpinBox(parent), validator(QRegExp("0x([0-9a-fA-F]){1,8}")) 22 | #endif 23 | { 24 | this->setRange(INT_MIN, INT_MAX); 25 | this->setPrefix("0x"); 26 | } 27 | 28 | QValidator::State HexSpinBox::validate(QString &text, int &pos) const 29 | { 30 | return validator.validate(text, pos); 31 | } 32 | 33 | QString HexSpinBox::textFromValue(int val) const 34 | { 35 | return QString::number((uint)val, 16).toUpper(); 36 | } 37 | 38 | int HexSpinBox::valueFromText(const QString &text) const 39 | { 40 | return (int)text.toUInt(NULL, 16); 41 | } 42 | -------------------------------------------------------------------------------- /UEFITool/hexspinbox.h: -------------------------------------------------------------------------------- 1 | /* hexspinbox.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef HEXSPINBOX_H 15 | #define HEXSPINBOX_H 16 | 17 | #include 18 | 19 | #if QT_VERSION_MAJOR >= 6 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | class HexSpinBox : public QSpinBox 26 | { 27 | Q_OBJECT 28 | 29 | public: 30 | HexSpinBox(QWidget *parent = 0); 31 | 32 | protected: 33 | QValidator::State validate(QString &text, int &pos) const; 34 | int valueFromText(const QString &text) const; 35 | QString textFromValue(int value) const; 36 | 37 | private: 38 | #if QT_VERSION_MAJOR >= 6 39 | QRegularExpressionValidator validator; 40 | #else 41 | QRegExpValidator validator; 42 | #endif 43 | }; 44 | 45 | #endif // HEXSPINBOX_H 46 | -------------------------------------------------------------------------------- /UEFITool/hexviewdialog.cpp: -------------------------------------------------------------------------------- 1 | /* hexviewdialog.cpp 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "hexviewdialog.h" 15 | 16 | HexViewDialog::HexViewDialog(QWidget *parent) : 17 | QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), 18 | ui(new Ui::HexViewDialog), 19 | hexView(NULL) 20 | { 21 | // Create UI 22 | ui->setupUi(this); 23 | hexView = new QHexView(this); 24 | hexView->setReadOnly(true); 25 | ui->layout->addWidget(hexView); 26 | } 27 | 28 | HexViewDialog::~HexViewDialog() 29 | { 30 | delete hexView; 31 | delete ui; 32 | } 33 | 34 | void HexViewDialog::setFont(const QFont &font) 35 | { 36 | hexView->setFont(font); 37 | } 38 | 39 | void HexViewDialog::setItem(const UModelIndex & index, HexViewType type) 40 | { 41 | const TreeModel * model = (const TreeModel*)index.model(); 42 | UString itemName = model->name(index); 43 | UString itemText = model->text(index); 44 | 45 | // Set hex data and dialog title 46 | QByteArray hexdata; 47 | UString dialogTitle; 48 | 49 | switch (type) { 50 | case fullHexView: 51 | dialogTitle = UString("Hex view: "); 52 | hexdata = model->header(index) + model->body(index) + model->tail(index); 53 | break; 54 | case bodyHexView: 55 | dialogTitle = UString("Body hex view: "); 56 | hexdata = model->body(index); 57 | break; 58 | case uncompressedHexView: 59 | dialogTitle = UString("Uncompressed hex view: "); 60 | hexdata = model->uncompressedData(index); 61 | break; 62 | } 63 | 64 | dialogTitle += itemText.isEmpty() ? itemName : itemName + " | " + itemText; 65 | setWindowTitle(dialogTitle); 66 | hexView->setData(hexdata); 67 | hexView->setFont(QApplication::font()); 68 | } 69 | -------------------------------------------------------------------------------- /UEFITool/hexviewdialog.h: -------------------------------------------------------------------------------- 1 | /* hexviewdialog.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef HEXVIEWDIALOG_H 15 | #define HEXVIEWDIALOG_H 16 | 17 | #include 18 | #include 19 | #include "../common/treemodel.h" 20 | #include "ui_hexviewdialog.h" 21 | 22 | class HexViewDialog : public QDialog 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | enum HexViewType { 28 | fullHexView, 29 | bodyHexView, 30 | uncompressedHexView 31 | }; 32 | 33 | HexViewDialog(QWidget *parent = 0); 34 | ~HexViewDialog(); 35 | Ui::HexViewDialog* ui; 36 | 37 | void setItem(const UModelIndex & index, HexViewType dataType); 38 | void setFont(const QFont &font); 39 | 40 | private: 41 | QHexView * hexView; 42 | }; 43 | 44 | #endif // HEXVIEWDIALOG_H 45 | -------------------------------------------------------------------------------- /UEFITool/hexviewdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | HexViewDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 5 22 | 23 | 24 | 5 25 | 26 | 27 | 5 28 | 29 | 30 | 5 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /UEFITool/icons/uefitool.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool.icns -------------------------------------------------------------------------------- /UEFITool/icons/uefitool.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool.ico -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_128x128.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_16x16.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_256x256.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_32x32.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_48x48.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_512x512.png -------------------------------------------------------------------------------- /UEFITool/icons/uefitool_64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/UEFITool/icons/uefitool_64x64.png -------------------------------------------------------------------------------- /UEFITool/searchdialog.cpp: -------------------------------------------------------------------------------- 1 | /* searchdialog.cpp 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "searchdialog.h" 15 | 16 | SearchDialog::SearchDialog(QWidget *parent) : 17 | QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), 18 | ui(new Ui::SearchDialog), 19 | #if QT_VERSION_MAJOR >= 6 20 | hexValidator(QRegularExpression("([0-9a-fA-F\\. ])*")), 21 | guidValidator(QRegularExpression("[0-9a-fA-F\\.]{8}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{12}")) 22 | #else 23 | hexValidator(QRegExp("([0-9a-fA-F\\. ])*")), 24 | guidValidator(QRegExp("[0-9a-fA-F\\.]{8}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{12}")) 25 | #endif 26 | { 27 | // Create UI 28 | ui->setupUi(this); 29 | ui->hexEdit->setValidator(&hexValidator); 30 | ui->guidEdit->setValidator(&guidValidator); 31 | 32 | // Connect 33 | connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(setEditFocus(int))); 34 | 35 | // Set initial focus 36 | setEditFocus(ui->tabWidget->currentIndex()); 37 | } 38 | 39 | SearchDialog::~SearchDialog() 40 | { 41 | delete ui; 42 | } 43 | 44 | void SearchDialog::setEditFocus(int index) 45 | { 46 | if (index == 0) // Hex pattern 47 | ui->hexEdit->setFocus(); 48 | else if (index == 1) { // GUID 49 | ui->guidEdit->setFocus(); 50 | ui->guidEdit->setCursorPosition(0); 51 | } 52 | else if (index == 2) // Text 53 | ui->textEdit->setFocus(); 54 | } 55 | -------------------------------------------------------------------------------- /UEFITool/searchdialog.h: -------------------------------------------------------------------------------- 1 | /* searchdialog.h 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef SEARCHDIALOG_H 15 | #define SEARCHDIALOG_H 16 | 17 | #include 18 | 19 | #if QT_VERSION_MAJOR >= 6 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | #include "ui_searchdialog.h" 26 | 27 | class SearchDialog : public QDialog 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | SearchDialog(QWidget *parent = 0); 33 | ~SearchDialog(); 34 | Ui::SearchDialog* ui; 35 | 36 | private slots: 37 | void setEditFocus(int index); 38 | 39 | private: 40 | #if QT_VERSION_MAJOR >= 6 41 | QRegularExpressionValidator hexValidator; 42 | QRegularExpressionValidator guidValidator; 43 | #else 44 | QRegExpValidator hexValidator; 45 | QRegExpValidator guidValidator; 46 | #endif 47 | }; 48 | 49 | #endif // SEARCHDIALOG_H 50 | -------------------------------------------------------------------------------- /UEFITool/uefitool.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Version=1.0 4 | Name=UEFITool 5 | Comment=UEFI firmware image viewer and editor 6 | Exec=uefitool 7 | Icon=uefitool 8 | Terminal=false 9 | Categories=Development;System;Utility;HardwareSettings;Electronics;Engineering; 10 | Keywords=BIOS;UEFI; 11 | -------------------------------------------------------------------------------- /UEFITool/uefitool.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.assets.movies.read-write 8 | 9 | com.apple.security.assets.music.read-write 10 | 11 | com.apple.security.assets.pictures.read-write 12 | 13 | com.apple.security.files.downloads.read-write 14 | 15 | com.apple.security.files.user-selected.read-write 16 | 17 | com.apple.security.print 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /UEFITool/uefitool.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ../common/guids.csv 4 | 5 | -------------------------------------------------------------------------------- /UEFITool/uefitool.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "icons/uefitool.ico" 2 | -------------------------------------------------------------------------------- /UEFITool/uefitool_main.cpp: -------------------------------------------------------------------------------- 1 | /* uefitool_main.cpp 2 | 3 | Copyright (c) 2022, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include 15 | #include 16 | #include "uefitool.h" 17 | 18 | class UEFIToolApplication : public QApplication 19 | { 20 | UEFITool* tool; 21 | 22 | public: 23 | UEFIToolApplication(int &argc, char **argv) 24 | : QApplication(argc, argv) 25 | { 26 | setOrganizationName("CodeRush"); 27 | setOrganizationDomain("coderush.me"); 28 | setApplicationName("UEFITool"); 29 | #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) 30 | setDesktopFileName("uefitool"); 31 | #endif 32 | tool = new UEFITool(); 33 | } 34 | 35 | virtual ~UEFIToolApplication() { 36 | delete tool; 37 | } 38 | 39 | virtual bool event(QEvent *event) 40 | { 41 | if (event->type() == QEvent::FileOpen) { 42 | QFileOpenEvent *openEvent = static_cast(event); 43 | tool->openImageFile(openEvent->file()); 44 | } 45 | 46 | return QApplication::event(event); 47 | } 48 | 49 | int startup() 50 | { 51 | tool->setProgramPath(arguments().at(0)); 52 | if (arguments().length() > 1) 53 | tool->openImageFile(arguments().at(1)); 54 | tool->show(); 55 | 56 | return exec(); 57 | } 58 | }; 59 | 60 | int main(int argc, char *argv[]) 61 | { 62 | UEFIToolApplication a(argc, argv); 63 | return a.startup(); 64 | } 65 | -------------------------------------------------------------------------------- /appstream/UEFITool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongSoft/UEFITool/fa7360d9c247ef5f07c26acfd7c3a4db21503148/appstream/UEFITool.png -------------------------------------------------------------------------------- /appstream/appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.github.LongSoft.UEFITool 4 | com.github.LongSoft.UEFITool.desktop 5 | UEFITool 6 | UEFI firmware image viewer and editor 7 | 8 |

UEFITool is a cross-platform open source application, that parses UEFI PI-compatible firmware image into a tree structure, verifies image integrity and provides a GUI to manipulate image elements.

9 |
10 | 11 | 12 | https://github.com/LongSoft/UEFITool/raw/new_engine/appstream/UEFITool.png 13 | 14 | 15 | 16 | 17 | 18 | https://github.com/LongSoft/UEFITool 19 | LongSoft 20 | CC0-1.0 21 | BSD-2-Clause 22 | 23 |
24 | -------------------------------------------------------------------------------- /common/LZMA/LzmaCompress.c: -------------------------------------------------------------------------------- 1 | /* LZMA Compress Implementation 2 | 3 | Copyright (c) 2012, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "LzmaCompress.h" 15 | #include "SDK/C/7zVersion.h" 16 | #include "SDK/C/LzmaEnc.h" 17 | 18 | #include 19 | 20 | #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) 21 | 22 | static void * AllocForLzma(ISzAllocPtr p, size_t size) { (void)p; return malloc(size); } 23 | static void FreeForLzma(ISzAllocPtr p, void *address) { (void)p; free(address); } 24 | static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma }; 25 | 26 | SRes OnProgress(const ICompressProgress *p, UInt64 inSize, UInt64 outSize) 27 | { 28 | (void)p; (void)inSize; (void)outSize; 29 | return SZ_OK; 30 | } 31 | 32 | static ICompressProgress g_ProgressCallback = { &OnProgress }; 33 | 34 | STATIC 35 | UINT64 36 | EFIAPI 37 | RShiftU64 ( 38 | UINT64 Operand, 39 | UINT32 Count 40 | ) 41 | { 42 | return Operand >> Count; 43 | } 44 | 45 | VOID 46 | SetEncodedSizeOfBuf( 47 | UINT64 EncodedSize, 48 | UINT8* EncodedData 49 | ) 50 | { 51 | INT32 Index; 52 | 53 | EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF; 54 | for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++) 55 | { 56 | EncodedSize = RShiftU64(EncodedSize, 8); 57 | EncodedData[Index] = EncodedSize & 0xFF; 58 | } 59 | } 60 | 61 | USTATUS 62 | EFIAPI 63 | LzmaCompress ( 64 | CONST UINT8 *Source, 65 | UINT32 SourceSize, 66 | UINT8 *Destination, 67 | UINT32 *DestinationSize, 68 | UINT32 DictionarySize 69 | ) 70 | { 71 | SRes LzmaResult; 72 | CLzmaEncProps props; 73 | SizeT propsSize = LZMA_PROPS_SIZE; 74 | SizeT destLen = SourceSize + SourceSize / 3 + 128; 75 | 76 | if (*DestinationSize < (UINT32)destLen) 77 | { 78 | *DestinationSize = (UINT32)destLen; 79 | return EFI_BUFFER_TOO_SMALL; 80 | } 81 | 82 | LzmaEncProps_Init(&props); 83 | props.dictSize = DictionarySize; 84 | props.level = 9; 85 | props.fb = 273; 86 | 87 | LzmaResult = LzmaEncode( 88 | (Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE), 89 | &destLen, 90 | Source, 91 | (SizeT)SourceSize, 92 | &props, 93 | (UINT8*)Destination, 94 | &propsSize, 95 | props.writeEndMark, 96 | &g_ProgressCallback, 97 | &SzAllocForLzma, 98 | &SzAllocForLzma); 99 | 100 | *DestinationSize = (UINT32)(destLen + LZMA_HEADER_SIZE); 101 | 102 | SetEncodedSizeOfBuf(SourceSize, Destination); 103 | 104 | if (LzmaResult == SZ_OK) { 105 | return EFI_SUCCESS; 106 | } 107 | else { 108 | return EFI_INVALID_PARAMETER; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /common/LZMA/LzmaCompress.h: -------------------------------------------------------------------------------- 1 | /* LZMA Compress Header 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef LZMACOMPRESS_H 15 | #define LZMACOMPRESS_H 16 | 17 | #include "SDK/C/7zTypes.h" 18 | #include "../basetypes.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define DEFAULT_LZMA_DICTIONARY_SIZE 0x800000 25 | #define _LZMA_SIZE_OPT 26 | 27 | USTATUS 28 | EFIAPI 29 | LzmaCompress ( 30 | const UINT8 *Source, 31 | UINT32 SourceSize, 32 | UINT8 *Destination, 33 | UINT32 *DestinationSize, 34 | UINT32 DictionarySize 35 | ); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif // LZMACOMPRESS_H 42 | -------------------------------------------------------------------------------- /common/LZMA/LzmaDecompress.h: -------------------------------------------------------------------------------- 1 | /* LZMA Decompress Header 2 | 3 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef LZMADECOMPRESS_H 15 | #define LZMADECOMPRESS_H 16 | 17 | #include "../basetypes.h" 18 | #include "SDK/C/LzmaDec.h" 19 | #include "SDK/C/Bra.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) 26 | 27 | /* 28 | Given a Lzma compressed source buffer, this function retrieves the size of 29 | the uncompressed buffer and the size of the scratch buffer required 30 | to decompress the compressed source buffer. 31 | 32 | Retrieves the size of the uncompressed buffer and the temporary scratch buffer 33 | required to decompress the buffer specified by Source and SourceSize. 34 | The size of the uncompressed buffer is returned DestinationSize, 35 | the size of the scratch buffer is returned ScratchSize, and RETURN_SUCCESS is returned. 36 | This function does not have scratch buffer available to perform a thorough 37 | checking of the validity of the source data. It just retrieves the "Original Size" 38 | field from the LZMA_HEADER_SIZE beginning bytes of the source data and output it as DestinationSize. 39 | And ScratchSize is specific to the decompression implementation. 40 | 41 | If SourceSize is less than LZMA_HEADER_SIZE, then ASSERT(). 42 | 43 | @param Source The source buffer containing the compressed data. 44 | @param SourceSize The size, bytes, of the source buffer. 45 | @param DestinationSize A pointer to the size, bytes, of the uncompressed buffer 46 | that will be generated when the compressed buffer specified 47 | by Source and SourceSize is decompressed. 48 | 49 | @retval EFI_SUCCESS The size of the uncompressed data was returned 50 | DestinationSize and the size of the scratch 51 | buffer was returned ScratchSize. 52 | 53 | */ 54 | USTATUS 55 | EFIAPI 56 | LzmaGetInfo ( 57 | CONST VOID *Source, 58 | UINT32 SourceSize, 59 | UINT32 *DestinationSize 60 | ); 61 | 62 | /* 63 | Decompresses a Lzma compressed source buffer. 64 | 65 | Extracts decompressed data to its original form. 66 | If the compressed source data specified by Source is successfully decompressed 67 | into Destination, then RETURN_SUCCESS is returned. If the compressed source data 68 | specified by Source is not a valid compressed data format, 69 | then RETURN_INVALID_PARAMETER is returned. 70 | 71 | @param Source The source buffer containing the compressed data. 72 | @param SourceSize The size of source buffer. 73 | @param Destination The destination buffer to store the decompressed data 74 | 75 | @retval EFI_SUCCESS Decompression completed successfully, and 76 | the uncompressed buffer is returned Destination. 77 | @retval EFI_INVALID_PARAMETER 78 | The source buffer specified by Source is corrupted 79 | (not a valid compressed format). 80 | */ 81 | USTATUS 82 | EFIAPI 83 | LzmaDecompress ( 84 | CONST VOID *Source, 85 | UINT32 SourceSize, 86 | VOID *Destination 87 | ); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif // LZMADECOMPRESS_H 94 | -------------------------------------------------------------------------------- /common/LZMA/SDK/C/7zVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 24 2 | #define MY_VER_MINOR 9 3 | #define MY_VER_BUILD 0 4 | #define MY_VERSION_NUMBERS "24.09" 5 | #define MY_VERSION MY_VERSION_NUMBERS 6 | 7 | #ifdef MY_CPU_NAME 8 | #define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")" 9 | #else 10 | #define MY_VERSION_CPU MY_VERSION 11 | #endif 12 | 13 | #define MY_DATE "2024-11-29" 14 | #undef MY_COPYRIGHT 15 | #undef MY_VERSION_COPYRIGHT_DATE 16 | #define MY_AUTHOR_NAME "Igor Pavlov" 17 | #define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" 18 | #define MY_COPYRIGHT_CR "Copyright (c) 1999-2024 Igor Pavlov" 19 | 20 | #ifdef USE_COPYRIGHT_CR 21 | #define MY_COPYRIGHT MY_COPYRIGHT_CR 22 | #else 23 | #define MY_COPYRIGHT MY_COPYRIGHT_PD 24 | #endif 25 | 26 | #define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE 27 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE 28 | -------------------------------------------------------------------------------- /common/LZMA/SDK/C/7zWindows.h: -------------------------------------------------------------------------------- 1 | /* 7zWindows.h -- StdAfx 2 | 2023-04-02 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef ZIP7_INC_7Z_WINDOWS_H 5 | #define ZIP7_INC_7Z_WINDOWS_H 6 | 7 | #ifdef _WIN32 8 | 9 | #if defined(__clang__) 10 | # pragma clang diagnostic push 11 | #endif 12 | 13 | #if defined(_MSC_VER) 14 | 15 | #pragma warning(push) 16 | #pragma warning(disable : 4668) // '_WIN32_WINNT' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' 17 | 18 | #if _MSC_VER == 1900 19 | // for old kit10 versions 20 | // #pragma warning(disable : 4255) // winuser.h(13979): warning C4255: 'GetThreadDpiAwarenessContext': 21 | #endif 22 | // win10 Windows Kit: 23 | #endif // _MSC_VER 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64) 26 | // for msvc6 without sdk2003 27 | #define RPC_NO_WINDOWS_H 28 | #endif 29 | 30 | #if defined(__MINGW32__) || defined(__MINGW64__) 31 | // #if defined(__GNUC__) && !defined(__clang__) 32 | #include 33 | #else 34 | #include 35 | #endif 36 | // #include 37 | // #include 38 | 39 | // but if precompiled with clang-cl then we need 40 | // #include 41 | #if defined(_MSC_VER) 42 | #pragma warning(pop) 43 | #endif 44 | 45 | #if defined(__clang__) 46 | # pragma clang diagnostic pop 47 | #endif 48 | 49 | #if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64) 50 | #ifndef _W64 51 | 52 | typedef long LONG_PTR, *PLONG_PTR; 53 | typedef unsigned long ULONG_PTR, *PULONG_PTR; 54 | typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; 55 | 56 | #define Z7_OLD_WIN_SDK 57 | #endif // _W64 58 | #endif // _MSC_VER == 1200 59 | 60 | #ifdef Z7_OLD_WIN_SDK 61 | 62 | #ifndef INVALID_FILE_ATTRIBUTES 63 | #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 64 | #endif 65 | #ifndef INVALID_SET_FILE_POINTER 66 | #define INVALID_SET_FILE_POINTER ((DWORD)-1) 67 | #endif 68 | #ifndef FILE_SPECIAL_ACCESS 69 | #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS) 70 | #endif 71 | 72 | // ShlObj.h: 73 | // #define BIF_NEWDIALOGSTYLE 0x0040 74 | 75 | #pragma warning(disable : 4201) 76 | // #pragma warning(disable : 4115) 77 | 78 | #undef VARIANT_TRUE 79 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) 80 | #endif 81 | 82 | #endif // Z7_OLD_WIN_SDK 83 | 84 | #ifdef UNDER_CE 85 | #undef VARIANT_TRUE 86 | #define VARIANT_TRUE ((VARIANT_BOOL)-1) 87 | #endif 88 | 89 | 90 | #if defined(_MSC_VER) 91 | #if _MSC_VER >= 1400 && _MSC_VER <= 1600 92 | // BaseTsd.h(148) : 'HandleToULong' : unreferenced inline function has been removed 93 | // string.h 94 | // #pragma warning(disable : 4514) 95 | #endif 96 | #endif 97 | 98 | 99 | /* #include "7zTypes.h" */ 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /common/LZMA/SDK/C/LzHash.h: -------------------------------------------------------------------------------- 1 | /* LzHash.h -- HASH constants for LZ algorithms 2 | 2023-03-05 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef ZIP7_INC_LZ_HASH_H 5 | #define ZIP7_INC_LZ_HASH_H 6 | 7 | /* 8 | (kHash2Size >= (1 << 8)) : Required 9 | (kHash3Size >= (1 << 16)) : Required 10 | */ 11 | 12 | #define kHash2Size (1 << 10) 13 | #define kHash3Size (1 << 16) 14 | // #define kHash4Size (1 << 20) 15 | 16 | #define kFix3HashSize (kHash2Size) 17 | #define kFix4HashSize (kHash2Size + kHash3Size) 18 | // #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 19 | 20 | /* 21 | We use up to 3 crc values for hash: 22 | crc0 23 | crc1 << Shift_1 24 | crc2 << Shift_2 25 | (Shift_1 = 5) and (Shift_2 = 10) is good tradeoff. 26 | Small values for Shift are not good for collision rate. 27 | Big value for Shift_2 increases the minimum size 28 | of hash table, that will be slow for small files. 29 | */ 30 | 31 | #define kLzHash_CrcShift_1 5 32 | #define kLzHash_CrcShift_2 10 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /common/LZMA/SDK/C/LzmaEnc.h: -------------------------------------------------------------------------------- 1 | /* LzmaEnc.h -- LZMA Encoder 2 | 2023-04-13 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef ZIP7_INC_LZMA_ENC_H 5 | #define ZIP7_INC_LZMA_ENC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA_PROPS_SIZE 5 12 | 13 | typedef struct 14 | { 15 | int level; /* 0 <= level <= 9 */ 16 | UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version 17 | (1 << 12) <= dictSize <= (3 << 29) for 64-bit version 18 | default = (1 << 24) */ 19 | int lc; /* 0 <= lc <= 8, default = 3 */ 20 | int lp; /* 0 <= lp <= 4, default = 0 */ 21 | int pb; /* 0 <= pb <= 4, default = 2 */ 22 | int algo; /* 0 - fast, 1 - normal, default = 1 */ 23 | int fb; /* 5 <= fb <= 273, default = 32 */ 24 | int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ 25 | int numHashBytes; /* 2, 3 or 4, default = 4 */ 26 | unsigned numHashOutBits; /* default = ? */ 27 | UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ 28 | unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ 29 | int numThreads; /* 1 or 2, default = 2 */ 30 | 31 | // int _pad; 32 | 33 | UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1. 34 | Encoder uses this value to reduce dictionary size */ 35 | 36 | UInt64 affinity; 37 | } CLzmaEncProps; 38 | 39 | void LzmaEncProps_Init(CLzmaEncProps *p); 40 | void LzmaEncProps_Normalize(CLzmaEncProps *p); 41 | UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); 42 | 43 | 44 | /* ---------- CLzmaEncHandle Interface ---------- */ 45 | 46 | /* LzmaEnc* functions can return the following exit codes: 47 | SRes: 48 | SZ_OK - OK 49 | SZ_ERROR_MEM - Memory allocation error 50 | SZ_ERROR_PARAM - Incorrect paramater in props 51 | SZ_ERROR_WRITE - ISeqOutStream write callback error 52 | SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output 53 | SZ_ERROR_PROGRESS - some break from progress callback 54 | SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) 55 | */ 56 | 57 | typedef struct CLzmaEnc CLzmaEnc; 58 | typedef CLzmaEnc * CLzmaEncHandle; 59 | // Z7_DECLARE_HANDLE(CLzmaEncHandle) 60 | 61 | CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc); 62 | void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig); 63 | 64 | SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); 65 | void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize); 66 | SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); 67 | unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p); 68 | 69 | SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, 70 | ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 71 | SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 72 | int writeEndMark, ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 73 | 74 | 75 | /* ---------- One Call Interface ---------- */ 76 | 77 | SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 78 | const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 79 | ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 80 | 81 | EXTERN_C_END 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /common/LZMA/SDK/C/RotateDefs.h: -------------------------------------------------------------------------------- 1 | /* RotateDefs.h -- Rotate functions 2 | 2023-06-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef ZIP7_INC_ROTATE_DEFS_H 5 | #define ZIP7_INC_ROTATE_DEFS_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #include 10 | 11 | /* don't use _rotl with old MINGW. It can insert slow call to function. */ 12 | 13 | /* #if (_MSC_VER >= 1200) */ 14 | #pragma intrinsic(_rotl) 15 | #pragma intrinsic(_rotr) 16 | /* #endif */ 17 | 18 | #define rotlFixed(x, n) _rotl((x), (n)) 19 | #define rotrFixed(x, n) _rotr((x), (n)) 20 | 21 | #if (_MSC_VER >= 1300) 22 | #define Z7_ROTL64(x, n) _rotl64((x), (n)) 23 | #define Z7_ROTR64(x, n) _rotr64((x), (n)) 24 | #else 25 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) 26 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n)))) 27 | #endif 28 | 29 | #else 30 | 31 | /* new compilers can translate these macros to fast commands. */ 32 | 33 | #if defined(__clang__) && (__clang_major__ >= 4) \ 34 | || defined(__GNUC__) && (__GNUC__ >= 5) 35 | /* GCC 4.9.0 and clang 3.5 can recognize more correct version: */ 36 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (-(n) & 31))) 37 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (-(n) & 31))) 38 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (-(n) & 63))) 39 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (-(n) & 63))) 40 | #else 41 | /* for old GCC / clang: */ 42 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 43 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 44 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) 45 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n)))) 46 | #endif 47 | 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /common/Tiano/EfiTianoCompress.h: -------------------------------------------------------------------------------- 1 | /* EfiTianoCompress.h 2 | 3 | Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
4 | Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | Module Name: 14 | 15 | TianoCompress.h 16 | 17 | Abstract: 18 | 19 | Header file for compression routine. 20 | 21 | */ 22 | 23 | #ifndef EFITIANOCOMPRESS_H 24 | #define EFITIANOCOMPRESS_H 25 | 26 | #include 27 | #include 28 | 29 | #include "../basetypes.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /*++ 36 | 37 | Routine Description: 38 | 39 | Tiano compression routine. 40 | 41 | Arguments: 42 | 43 | SrcBuffer - The buffer storing the source data 44 | SrcSize - The size of source data 45 | DstBuffer - The buffer to store the compressed data 46 | DstSize - On input, the size of DstBuffer; On output, 47 | the size of the actual compressed data. 48 | 49 | Returns: 50 | 51 | EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case, 52 | DstSize contains the size needed. 53 | EFI_SUCCESS - Compression is successful. 54 | EFI_OUT_OF_RESOURCES - No resource to complete function. 55 | EFI_INVALID_PARAMETER - Parameter supplied is wrong. 56 | 57 | --*/ 58 | EFI_STATUS 59 | TianoCompress ( 60 | IN CONST VOID *SrcBuffer, 61 | IN UINT32 SrcSize, 62 | IN VOID *DstBuffer, 63 | IN OUT UINT32 *DstSize 64 | ); 65 | 66 | EFI_STATUS 67 | TianoCompressLegacy( 68 | CONST VOID *SrcBuffer, 69 | UINT32 SrcSize, 70 | VOID *DstBuffer, 71 | UINT32 *DstSize 72 | ); 73 | /*++ 74 | 75 | Routine Description: 76 | 77 | EFI 1.1 compression routine. 78 | 79 | Arguments: 80 | 81 | SrcBuffer - The buffer storing the source data 82 | SrcSize - The size of source data 83 | DstBuffer - The buffer to store the compressed data 84 | DstSize - On input, the size of DstBuffer; On output, 85 | the size of the actual compressed data. 86 | 87 | Returns: 88 | 89 | EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case, 90 | DstSize contains the size needed. 91 | EFI_SUCCESS - Compression is successful. 92 | EFI_OUT_OF_RESOURCES - No resource to complete function. 93 | EFI_INVALID_PARAMETER - Parameter supplied is wrong. 94 | 95 | --*/ 96 | EFI_STATUS 97 | EfiCompress ( 98 | IN CONST VOID *SrcBuffer, 99 | IN UINT32 SrcSize, 100 | IN VOID *DstBuffer, 101 | IN OUT UINT32 *DstSize 102 | ); 103 | 104 | EFI_STATUS 105 | EfiCompressLegacy( 106 | CONST VOID *SrcBuffer, 107 | UINT32 SrcSize, 108 | VOID *DstBuffer, 109 | UINT32 *DstSize 110 | ); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | #endif // EFITIANOCOMPRESS_H 116 | -------------------------------------------------------------------------------- /common/bstrlib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Paul Hsieh 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of bstrlib nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /common/digest/sha1.h: -------------------------------------------------------------------------------- 1 | /* sha1.h 2 | 3 | Copyright (c) 2022, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef SHA1_H 15 | #define SHA1_H 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | void sha1(const void *in, unsigned long inlen, void* out); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | #endif // SHA2_H 26 | -------------------------------------------------------------------------------- /common/digest/sha2.h: -------------------------------------------------------------------------------- 1 | /* sha2.h 2 | 3 | Copyright (c) 2017, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef SHA2_H 15 | #define SHA2_H 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | void sha256(const void *in, unsigned long inlen, void* out); 21 | void sha384(const void *in, unsigned long inlen, void* out); 22 | void sha512(const void *in, unsigned long inlen, void* out); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif // SHA2_H 28 | -------------------------------------------------------------------------------- /common/digest/sm3.h: -------------------------------------------------------------------------------- 1 | /* sm3.h 2 | 3 | Copyright (c) 2022, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | /* SPDX-License-Identifier: BSD-2-Clause */ 15 | /* 16 | * Copyright (c) 2019 Huawei Technologies Co., Ltd 17 | */ 18 | #ifndef SM3_H 19 | #define SM3_H 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | void sm3(const void *in, unsigned long inlen, void* out); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif /* SM3_H */ 33 | -------------------------------------------------------------------------------- /common/ffsbuilder.h: -------------------------------------------------------------------------------- 1 | /* fssbuilder.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FFSBUILDER_H 15 | #define FFSBUILDER_H 16 | 17 | #include 18 | 19 | #include "basetypes.h" 20 | #include "ubytearray.h" 21 | #include "ustring.h" 22 | #include "treemodel.h" 23 | 24 | class FfsBuilder 25 | { 26 | public: 27 | FfsBuilder(const TreeModel * treeModel) : model(treeModel) {} 28 | ~FfsBuilder() {} 29 | 30 | std::vector > getMessages() const { return messagesVector; } 31 | void clearMessages() { messagesVector.clear(); } 32 | 33 | USTATUS build(const UModelIndex & root, UByteArray & image); 34 | 35 | private: 36 | const TreeModel* model; 37 | std::vector > messagesVector; 38 | void msg(const UString & message, const UModelIndex &index = UModelIndex()) { 39 | messagesVector.push_back(std::pair(message, index)); 40 | } 41 | 42 | USTATUS buildCapsule(const UModelIndex & index, UByteArray & capsule); 43 | USTATUS buildIntelImage(const UModelIndex & index, UByteArray & intelImage); 44 | USTATUS buildRawArea(const UModelIndex & index, UByteArray & rawArea); 45 | USTATUS buildPadding(const UModelIndex & index, UByteArray & padding); 46 | USTATUS buildVolume(const UModelIndex & index, UByteArray & volume); 47 | USTATUS buildNonUefiData(const UModelIndex & index, UByteArray & data); 48 | USTATUS buildFreeSpace(const UModelIndex & index, UByteArray & freeSpace); 49 | USTATUS buildPadFile(const UModelIndex & index, UByteArray & padFile); 50 | USTATUS buildFile(const UModelIndex & index, UByteArray & file); 51 | USTATUS buildSection(const UModelIndex & index, UByteArray & section); 52 | 53 | // Utility functions 54 | USTATUS erase(const UModelIndex & index, UByteArray & erased); 55 | }; 56 | 57 | #endif // FFSBUILDER_H 58 | -------------------------------------------------------------------------------- /common/ffsops.cpp: -------------------------------------------------------------------------------- 1 | /* fssops.cpp 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "ffsops.h" 15 | #include "ffs.h" 16 | #include "utility.h" 17 | 18 | USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteArray & extracted, const UINT8 mode) 19 | { 20 | // Sanity check 21 | if (!index.isValid()) 22 | return U_INVALID_PARAMETER; 23 | 24 | // Default name 25 | name = uniqueItemName(index); 26 | 27 | // Get extracted data 28 | if (mode == EXTRACT_MODE_AS_IS) { 29 | // Extract as is, with header body and tail 30 | extracted.clear(); 31 | extracted += model->header(index); 32 | extracted += model->body(index); 33 | extracted += model->tail(index); 34 | } 35 | else if (mode == EXTRACT_MODE_BODY) { 36 | name += UString("_body"); 37 | // Extract without header and tail 38 | extracted.clear(); 39 | extracted += model->body(index); 40 | } 41 | else if (mode == EXTRACT_MODE_BODY_UNCOMPRESSED) { 42 | name += UString("_body_uncompressed"); 43 | extracted.clear(); 44 | extracted += model->uncompressedData(index); 45 | } 46 | else 47 | return U_UNKNOWN_EXTRACT_MODE; 48 | 49 | return U_SUCCESS; 50 | } 51 | 52 | USTATUS FfsOperations::replace(const UModelIndex & index, UByteArray & data, const UINT8 mode) 53 | { 54 | U_UNUSED_PARAMETER(data); 55 | 56 | // Sanity check 57 | if (!index.isValid()) 58 | return U_INVALID_PARAMETER; 59 | 60 | if (mode == REPLACE_MODE_AS_IS) { 61 | return U_NOT_IMPLEMENTED; 62 | } 63 | else if (mode == REPLACE_MODE_BODY) { 64 | return U_NOT_IMPLEMENTED; 65 | } 66 | 67 | return U_UNKNOWN_REPLACE_MODE; 68 | } 69 | 70 | USTATUS FfsOperations::remove(const UModelIndex & index) 71 | { 72 | // Sanity check 73 | if (!index.isValid()) 74 | return U_INVALID_PARAMETER; 75 | 76 | // Set remove action 77 | model->setAction(index, Actions::Remove); 78 | 79 | return U_SUCCESS; 80 | } 81 | 82 | USTATUS FfsOperations::rebuild(const UModelIndex & index) 83 | { 84 | // Sanity check 85 | if (!index.isValid()) 86 | return U_INVALID_PARAMETER; 87 | 88 | // On insert action, set insert action for children 89 | //if (action == Actions::Insert) 90 | // for (int i = 0; i < item->childCount(); i++) 91 | // setAction(index.child(i, 0), Actions::Insert); 92 | 93 | // Set rebuild action 94 | model->setAction(index, Actions::Rebuild); 95 | 96 | // Rebuild parent, if it has no action now 97 | UModelIndex parent = index.parent(); 98 | if (parent.isValid() && model->type(parent) != Types::Root 99 | && model->action(parent) == Actions::NoAction) 100 | rebuild(parent); 101 | 102 | return U_SUCCESS; 103 | } 104 | -------------------------------------------------------------------------------- /common/ffsops.h: -------------------------------------------------------------------------------- 1 | /* fssops.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FFSOPS_H 15 | #define FFSOPS_H 16 | 17 | #include 18 | 19 | #include "basetypes.h" 20 | #include "ubytearray.h" 21 | #include "ustring.h" 22 | #include "treemodel.h" 23 | #include "ffsparser.h" 24 | 25 | class FfsOperations 26 | { 27 | public: 28 | 29 | FfsOperations(TreeModel * treeModel) : model(treeModel) {} 30 | ~FfsOperations() {}; 31 | 32 | std::vector > getMessages() const { return messagesVector; } 33 | void clearMessages() { messagesVector.clear(); } 34 | 35 | USTATUS extract(const UModelIndex & index, UString & name, UByteArray & extracted, const UINT8 mode); 36 | USTATUS replace(const UModelIndex & index, UByteArray & data, const UINT8 mode); 37 | 38 | USTATUS remove(const UModelIndex & index); 39 | USTATUS rebuild(const UModelIndex & index); 40 | 41 | private: 42 | TreeModel * model; 43 | 44 | std::vector > messagesVector; 45 | 46 | void msg(const UString & message, const UModelIndex &index = UModelIndex()) { 47 | messagesVector.push_back(std::pair(message, index)); 48 | } 49 | }; 50 | 51 | #endif // FFSOPS_H 52 | -------------------------------------------------------------------------------- /common/ffsreport.cpp: -------------------------------------------------------------------------------- 1 | /* fssreport.cpp 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "ffsreport.h" 15 | #include "ffs.h" 16 | #include "utility.h" 17 | 18 | std::vector FfsReport::generate() 19 | { 20 | std::vector report; 21 | 22 | // Check model pointer 23 | if (!model) { 24 | report.push_back(usprintf("%s: invalid model pointer provided", __FUNCTION__)); 25 | return report; 26 | } 27 | 28 | // Check root index to be valid 29 | UModelIndex root = model->index(0,0); 30 | if (!root.isValid()) { 31 | report.push_back(usprintf("%s: model root index is invalid", __FUNCTION__)); 32 | return report; 33 | } 34 | 35 | // Generate report recursive 36 | report.push_back(UString(" Type | Subtype | Base | Size | CRC32 | Name ")); 37 | USTATUS result = generateRecursive(report, root); 38 | if (result) { 39 | report.push_back(usprintf("%s: generateRecursive returned ", __FUNCTION__) + errorCodeToUString(result)); 40 | } 41 | 42 | return report; 43 | } 44 | 45 | USTATUS FfsReport::generateRecursive(std::vector & report, const UModelIndex & index, const UINT32 level) 46 | { 47 | if (!index.isValid()) 48 | return U_SUCCESS; // Nothing to report for invalid index 49 | 50 | // Calculate item CRC32 51 | UByteArray data = model->header(index) + model->body(index) + model->tail(index); 52 | UINT32 crc = (UINT32)crc32(0, (const UINT8*)data.constData(), (uInt)data.size()); 53 | 54 | // Information on current item 55 | UString text = model->text(index); 56 | UString offset = "| N/A "; 57 | if ((!model->compressed(index)) || (index.parent().isValid() && !model->compressed(index.parent()))) { 58 | offset = usprintf("| %08X ", model->base(index)); 59 | } 60 | 61 | report.push_back( 62 | UString(" ") + itemTypeToUString(model->type(index)).leftJustified(20) 63 | + UString("| ") + itemSubtypeToUString(model->type(index), model->subtype(index)).leftJustified(22) 64 | + offset 65 | + usprintf("| %08X | %08X | ", (UINT32)data.size(), crc) 66 | + urepeated('-', level) + UString(" ") + model->name(index) + (text.isEmpty() ? UString() : UString(" | ") + text) 67 | ); 68 | 69 | // Information on child items 70 | for (int i = 0; i < model->rowCount(index); i++) { 71 | generateRecursive(report, index.model()->index(i,0,index), level + 1); 72 | } 73 | 74 | return U_SUCCESS; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /common/ffsreport.h: -------------------------------------------------------------------------------- 1 | /* fssreport.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FFSREPORT_H 15 | #define FFSREPORT_H 16 | 17 | #include 18 | 19 | #include "basetypes.h" 20 | #include "ubytearray.h" 21 | #include "ustring.h" 22 | #include "treemodel.h" 23 | 24 | 25 | class FfsReport 26 | { 27 | public: 28 | 29 | FfsReport(TreeModel * treeModel) : model(treeModel) {} 30 | ~FfsReport() {}; 31 | 32 | std::vector generate(); 33 | 34 | private: 35 | TreeModel* model; 36 | 37 | USTATUS generateRecursive(std::vector & report, const UModelIndex & index, const UINT32 level = 0); 38 | }; 39 | 40 | #endif // FFSREPORT_H 41 | 42 | -------------------------------------------------------------------------------- /common/filesystem.cpp: -------------------------------------------------------------------------------- 1 | /* filesystem.c 2 | 3 | Copyright (c) 2023, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "filesystem.h" 15 | #include 16 | #include 17 | 18 | bool readFileIntoBuffer(const UString& inPath, UByteArray& buf) 19 | { 20 | if (!isExistOnFs(inPath)) 21 | return false; 22 | 23 | std::ifstream inputFile(inPath.toLocal8Bit(), std::ios::in | std::ios::binary); 24 | if (!inputFile) 25 | return false; 26 | std::vector buffer(std::istreambuf_iterator(inputFile), 27 | (std::istreambuf_iterator())); 28 | inputFile.close(); 29 | 30 | buf = buffer; 31 | 32 | return true; 33 | } 34 | 35 | #if defined(_WIN32) || defined(__MINGW32__) 36 | #include 37 | #include 38 | bool isExistOnFs(const UString & path) 39 | { 40 | struct _stat buf; 41 | return (_stat(path.toLocal8Bit(), &buf) == 0); 42 | } 43 | 44 | bool makeDirectory(const UString & dir) 45 | { 46 | return (_mkdir(dir.toLocal8Bit()) == 0); 47 | } 48 | 49 | bool changeDirectory(const UString & dir) 50 | { 51 | return (_chdir(dir.toLocal8Bit()) == 0); 52 | } 53 | 54 | bool removeDirectory(const UString & dir) 55 | { 56 | int r = _rmdir(dir.toLocal8Bit()); 57 | // Hack: unlike *nix, Windows does not permit deleting current directories 58 | if (r < 0 && errno == EACCES && changeDirectory(dir + UString("/../"))) { 59 | return (_rmdir(dir.toLocal8Bit()) == 0); 60 | } 61 | return (r == 0); 62 | } 63 | 64 | UString getAbsPath(const UString & path) 65 | { 66 | char * abs = (char*)calloc(0x8000, 1); 67 | UString new_path; 68 | if (_fullpath(abs, path.toLocal8Bit(), 0x8000)) 69 | new_path = UString(abs); 70 | else 71 | new_path = path; 72 | free(abs); 73 | return new_path; 74 | } 75 | #else 76 | #include 77 | #include 78 | #if !defined(ACCESSPERMS) 79 | #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) 80 | #endif 81 | bool isExistOnFs(const UString & path) 82 | { 83 | struct stat buf; 84 | return (stat(path.toLocal8Bit(), &buf) == 0); 85 | } 86 | 87 | bool makeDirectory(const UString & dir) 88 | { 89 | return (mkdir(dir.toLocal8Bit(), ACCESSPERMS) == 0); 90 | } 91 | 92 | bool removeDirectory(const UString & dir) 93 | { 94 | return (rmdir(dir.toLocal8Bit()) == 0); 95 | } 96 | 97 | bool changeDirectory(const UString & dir) 98 | { 99 | return (chdir(dir.toLocal8Bit()) == 0); 100 | } 101 | 102 | UString getAbsPath(const UString & path) { 103 | char * abs = realpath(path.toLocal8Bit(), nullptr); 104 | // Last is a non-standard extension for non-existent files 105 | UString new_path; 106 | if (abs) 107 | new_path = UString(abs); 108 | else 109 | new_path = path; 110 | free(abs); 111 | return new_path; 112 | } 113 | #endif 114 | -------------------------------------------------------------------------------- /common/filesystem.h: -------------------------------------------------------------------------------- 1 | /* filesystem.h 2 | 3 | Copyright (c) 2023, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef FILESYSTEM_H 15 | #define FILESYSTEM_H 16 | 17 | #include "ustring.h" 18 | #include "ubytearray.h" 19 | 20 | bool isExistOnFs(const UString& path); 21 | bool makeDirectory(const UString& dir); 22 | bool changeDirectory(const UString& dir); 23 | bool removeDirectory(const UString& dir); 24 | bool readFileIntoBuffer(const UString& inPath, UByteArray& buf); 25 | UString getAbsPath(const UString& path); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /common/gbe.h: -------------------------------------------------------------------------------- 1 | /* gbe.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | */ 12 | 13 | #ifndef GBE_H 14 | #define GBE_H 15 | 16 | #include "basetypes.h" 17 | 18 | // Make sure we use right packing rules 19 | #pragma pack(push, 1) 20 | 21 | typedef struct GBE_MAC_ADDRESS_ { 22 | UINT8 vendor[3]; 23 | UINT8 device[3]; 24 | } GBE_MAC_ADDRESS; 25 | 26 | #define GBE_VERSION_OFFSET 10 27 | 28 | typedef struct GBE_VERSION_ { 29 | UINT8 id : 4; 30 | UINT8 minor : 4; 31 | UINT8 major; 32 | } GBE_VERSION; 33 | 34 | // Restore previous packing rules 35 | #pragma pack(pop) 36 | 37 | #endif // GBE_H 38 | -------------------------------------------------------------------------------- /common/generated/edk2_ftw.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "edk2_ftw.h" 4 | 5 | edk2_ftw_t::edk2_ftw_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, edk2_ftw_t* p__root) : kaitai::kstruct(p__io) { 6 | m__parent = p__parent; 7 | m__root = this; (void)p__root; 8 | f_len_ftw_store_header_32 = false; 9 | f_len_ftw_store_header_64 = false; 10 | _read(); 11 | } 12 | 13 | void edk2_ftw_t::_read() { 14 | m_signature = m__io->read_bytes(16); 15 | m_crc = m__io->read_u4le(); 16 | m_state = m__io->read_u1(); 17 | m_reserved = m__io->read_bytes(3); 18 | m_len_write_queue_32 = m__io->read_u4le(); 19 | n_len_write_queue_64 = true; 20 | if (kaitai::kstream::mod(len_write_queue_32(), 16) == 0) { 21 | n_len_write_queue_64 = false; 22 | m_len_write_queue_64 = m__io->read_u4le(); 23 | } 24 | n_write_queue_32 = true; 25 | if (kaitai::kstream::mod(len_write_queue_32(), 16) == 4) { 26 | n_write_queue_32 = false; 27 | m_write_queue_32 = m__io->read_bytes(len_write_queue_32()); 28 | } 29 | n_write_queue_64 = true; 30 | if (kaitai::kstream::mod(len_write_queue_32(), 16) == 0) { 31 | n_write_queue_64 = false; 32 | m_write_queue_64 = m__io->read_bytes(((static_cast(len_write_queue_64()) << 32) + len_write_queue_32())); 33 | } 34 | } 35 | 36 | edk2_ftw_t::~edk2_ftw_t() { 37 | _clean_up(); 38 | } 39 | 40 | void edk2_ftw_t::_clean_up() { 41 | if (!n_len_write_queue_64) { 42 | } 43 | if (!n_write_queue_32) { 44 | } 45 | if (!n_write_queue_64) { 46 | } 47 | } 48 | 49 | int8_t edk2_ftw_t::len_ftw_store_header_32() { 50 | if (f_len_ftw_store_header_32) 51 | return m_len_ftw_store_header_32; 52 | m_len_ftw_store_header_32 = 28; 53 | f_len_ftw_store_header_32 = true; 54 | return m_len_ftw_store_header_32; 55 | } 56 | 57 | int8_t edk2_ftw_t::len_ftw_store_header_64() { 58 | if (f_len_ftw_store_header_64) 59 | return m_len_ftw_store_header_64; 60 | m_len_ftw_store_header_64 = 32; 61 | f_len_ftw_store_header_64 = true; 62 | return m_len_ftw_store_header_64; 63 | } 64 | -------------------------------------------------------------------------------- /common/generated/edk2_ftw.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 4 | 5 | #include "../kaitai/kaitaistruct.h" 6 | #include 7 | #include 8 | 9 | #if KAITAI_STRUCT_VERSION < 9000L 10 | #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" 11 | #endif 12 | 13 | class edk2_ftw_t : public kaitai::kstruct { 14 | 15 | public: 16 | 17 | edk2_ftw_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, edk2_ftw_t* p__root = nullptr); 18 | 19 | private: 20 | void _read(); 21 | void _clean_up(); 22 | 23 | public: 24 | ~edk2_ftw_t(); 25 | 26 | private: 27 | bool f_len_ftw_store_header_32; 28 | int8_t m_len_ftw_store_header_32; 29 | 30 | public: 31 | int8_t len_ftw_store_header_32(); 32 | 33 | private: 34 | bool f_len_ftw_store_header_64; 35 | int8_t m_len_ftw_store_header_64; 36 | 37 | public: 38 | int8_t len_ftw_store_header_64(); 39 | 40 | private: 41 | std::string m_signature; 42 | uint32_t m_crc; 43 | uint8_t m_state; 44 | std::string m_reserved; 45 | uint32_t m_len_write_queue_32; 46 | uint32_t m_len_write_queue_64; 47 | bool n_len_write_queue_64; 48 | 49 | public: 50 | bool _is_null_len_write_queue_64() { len_write_queue_64(); return n_len_write_queue_64; }; 51 | 52 | private: 53 | std::string m_write_queue_32; 54 | bool n_write_queue_32; 55 | 56 | public: 57 | bool _is_null_write_queue_32() { write_queue_32(); return n_write_queue_32; }; 58 | 59 | private: 60 | std::string m_write_queue_64; 61 | bool n_write_queue_64; 62 | 63 | public: 64 | bool _is_null_write_queue_64() { write_queue_64(); return n_write_queue_64; }; 65 | 66 | private: 67 | edk2_ftw_t* m__root; 68 | kaitai::kstruct* m__parent; 69 | 70 | public: 71 | std::string signature() const { return m_signature; } 72 | uint32_t crc() const { return m_crc; } 73 | uint8_t state() const { return m_state; } 74 | std::string reserved() const { return m_reserved; } 75 | uint32_t len_write_queue_32() const { return m_len_write_queue_32; } 76 | uint32_t len_write_queue_64() const { return m_len_write_queue_64; } 77 | std::string write_queue_32() const { return m_write_queue_32; } 78 | std::string write_queue_64() const { return m_write_queue_64; } 79 | edk2_ftw_t* _root() const { return m__root; } 80 | kaitai::kstruct* _parent() const { return m__parent; } 81 | }; 82 | -------------------------------------------------------------------------------- /common/generated/insyde_fdc.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "insyde_fdc.h" 4 | #include "../kaitai/exceptions.h" 5 | 6 | insyde_fdc_t::insyde_fdc_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, insyde_fdc_t* p__root) : kaitai::kstruct(p__io) { 7 | m__parent = p__parent; 8 | m__root = this; (void)p__root; 9 | f_len_fdc_store_header = false; 10 | _read(); 11 | } 12 | 13 | void insyde_fdc_t::_read() { 14 | m_signature = m__io->read_u4le(); 15 | m_fdc_size = m__io->read_u4le(); 16 | { 17 | uint32_t _ = fdc_size(); 18 | if (!( ((_ > static_cast(len_fdc_store_header())) && (_ < 4294967295UL)) )) { 19 | throw kaitai::validation_expr_error(fdc_size(), _io(), std::string("/seq/1")); 20 | } 21 | } 22 | m_body = m__io->read_bytes((fdc_size() - len_fdc_store_header())); 23 | } 24 | 25 | insyde_fdc_t::~insyde_fdc_t() { 26 | _clean_up(); 27 | } 28 | 29 | void insyde_fdc_t::_clean_up() { 30 | } 31 | 32 | int8_t insyde_fdc_t::len_fdc_store_header() { 33 | if (f_len_fdc_store_header) 34 | return m_len_fdc_store_header; 35 | m_len_fdc_store_header = 80; 36 | f_len_fdc_store_header = true; 37 | return m_len_fdc_store_header; 38 | } 39 | -------------------------------------------------------------------------------- /common/generated/insyde_fdc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 4 | 5 | #include "../kaitai/kaitaistruct.h" 6 | #include 7 | #include 8 | 9 | #if KAITAI_STRUCT_VERSION < 9000L 10 | #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" 11 | #endif 12 | 13 | class insyde_fdc_t : public kaitai::kstruct { 14 | 15 | public: 16 | 17 | insyde_fdc_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, insyde_fdc_t* p__root = nullptr); 18 | 19 | private: 20 | void _read(); 21 | void _clean_up(); 22 | 23 | public: 24 | ~insyde_fdc_t(); 25 | 26 | private: 27 | bool f_len_fdc_store_header; 28 | int8_t m_len_fdc_store_header; 29 | 30 | public: 31 | int8_t len_fdc_store_header(); 32 | 33 | private: 34 | uint32_t m_signature; 35 | uint32_t m_fdc_size; 36 | std::string m_body; 37 | insyde_fdc_t* m__root; 38 | kaitai::kstruct* m__parent; 39 | 40 | public: 41 | uint32_t signature() const { return m_signature; } 42 | uint32_t fdc_size() const { return m_fdc_size; } 43 | std::string body() const { return m_body; } 44 | insyde_fdc_t* _root() const { return m__root; } 45 | kaitai::kstruct* _parent() const { return m__parent; } 46 | }; 47 | -------------------------------------------------------------------------------- /common/generated/intel_acm.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "intel_acm.h" 4 | #include "../kaitai/exceptions.h" 5 | 6 | intel_acm_t::intel_acm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acm_t* p__root) : kaitai::kstruct(p__io) { 7 | m__parent = p__parent; 8 | m__root = this; (void)p__root; 9 | m_header = nullptr; 10 | _read(); 11 | } 12 | 13 | void intel_acm_t::_read() { 14 | m_header = std::unique_ptr(new header_t(m__io, this, m__root)); 15 | m_body = m__io->read_bytes((4 * ((header()->module_size() - header()->header_size()) - header()->scratch_space_size()))); 16 | } 17 | 18 | intel_acm_t::~intel_acm_t() { 19 | _clean_up(); 20 | } 21 | 22 | void intel_acm_t::_clean_up() { 23 | } 24 | 25 | intel_acm_t::header_t::header_t(kaitai::kstream* p__io, intel_acm_t* p__parent, intel_acm_t* p__root) : kaitai::kstruct(p__io) { 26 | m__parent = p__parent; 27 | m__root = p__root; 28 | _read(); 29 | } 30 | 31 | void intel_acm_t::header_t::_read() { 32 | m_module_type = m__io->read_u2le(); 33 | if (!(module_type() == 2)) { 34 | throw kaitai::validation_not_equal_error(2, module_type(), _io(), std::string("/types/header/seq/0")); 35 | } 36 | m_module_subtype = static_cast(m__io->read_u2le()); 37 | m_header_size = m__io->read_u4le(); 38 | m_header_version = m__io->read_u4le(); 39 | m_chipset_id = m__io->read_u2le(); 40 | m_flags = m__io->read_u2le(); 41 | m_module_vendor = m__io->read_u4le(); 42 | if (!(module_vendor() == 32902)) { 43 | throw kaitai::validation_not_equal_error(32902, module_vendor(), _io(), std::string("/types/header/seq/6")); 44 | } 45 | m_date_day = m__io->read_u1(); 46 | m_date_month = m__io->read_u1(); 47 | m_date_year = m__io->read_u2le(); 48 | m_module_size = m__io->read_u4le(); 49 | m_acm_svn = m__io->read_u2le(); 50 | m_se_svn = m__io->read_u2le(); 51 | m_code_control_flags = m__io->read_u4le(); 52 | m_error_entry_point = m__io->read_u4le(); 53 | m_gdt_max = m__io->read_u4le(); 54 | m_gdt_base = m__io->read_u4le(); 55 | m_segment_sel = m__io->read_u4le(); 56 | m_entry_point = m__io->read_u4le(); 57 | m_reserved = m__io->read_bytes(64); 58 | m_key_size = m__io->read_u4le(); 59 | m_scratch_space_size = m__io->read_u4le(); 60 | m_rsa_public_key = m__io->read_bytes((4 * key_size())); 61 | n_rsa_exponent = true; 62 | if (header_version() == 0) { 63 | n_rsa_exponent = false; 64 | m_rsa_exponent = m__io->read_u4le(); 65 | } 66 | m_rsa_signature = m__io->read_bytes((4 * key_size())); 67 | m_scratch_space = m__io->read_bytes((4 * scratch_space_size())); 68 | } 69 | 70 | intel_acm_t::header_t::~header_t() { 71 | _clean_up(); 72 | } 73 | 74 | void intel_acm_t::header_t::_clean_up() { 75 | if (!n_rsa_exponent) { 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /common/generated/ms_slic_marker.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "ms_slic_marker.h" 4 | 5 | ms_slic_marker_t::ms_slic_marker_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, ms_slic_marker_t* p__root) : kaitai::kstruct(p__io) { 6 | m__parent = p__parent; 7 | m__root = this; (void)p__root; 8 | _read(); 9 | } 10 | 11 | void ms_slic_marker_t::_read() { 12 | m_type = m__io->read_u4le(); 13 | m_len_marker = m__io->read_u4le(); 14 | m_version = m__io->read_u4le(); 15 | m_oem_id = m__io->read_bytes(6); 16 | m_oem_table_id = m__io->read_bytes(8); 17 | m_windows_flag = m__io->read_u8le(); 18 | m_slic_version = m__io->read_u4le(); 19 | m_reserved = m__io->read_bytes(16); 20 | m_signature = m__io->read_bytes(128); 21 | } 22 | 23 | ms_slic_marker_t::~ms_slic_marker_t() { 24 | _clean_up(); 25 | } 26 | 27 | void ms_slic_marker_t::_clean_up() { 28 | } 29 | -------------------------------------------------------------------------------- /common/generated/ms_slic_marker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 4 | 5 | #include "../kaitai/kaitaistruct.h" 6 | #include 7 | #include 8 | 9 | #if KAITAI_STRUCT_VERSION < 9000L 10 | #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" 11 | #endif 12 | 13 | class ms_slic_marker_t : public kaitai::kstruct { 14 | 15 | public: 16 | 17 | ms_slic_marker_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, ms_slic_marker_t* p__root = nullptr); 18 | 19 | private: 20 | void _read(); 21 | void _clean_up(); 22 | 23 | public: 24 | ~ms_slic_marker_t(); 25 | 26 | private: 27 | uint32_t m_type; 28 | uint32_t m_len_marker; 29 | uint32_t m_version; 30 | std::string m_oem_id; 31 | std::string m_oem_table_id; 32 | uint64_t m_windows_flag; 33 | uint32_t m_slic_version; 34 | std::string m_reserved; 35 | std::string m_signature; 36 | ms_slic_marker_t* m__root; 37 | kaitai::kstruct* m__parent; 38 | 39 | public: 40 | uint32_t type() const { return m_type; } 41 | uint32_t len_marker() const { return m_len_marker; } 42 | uint32_t version() const { return m_version; } 43 | std::string oem_id() const { return m_oem_id; } 44 | std::string oem_table_id() const { return m_oem_table_id; } 45 | uint64_t windows_flag() const { return m_windows_flag; } 46 | uint32_t slic_version() const { return m_slic_version; } 47 | std::string reserved() const { return m_reserved; } 48 | std::string signature() const { return m_signature; } 49 | ms_slic_marker_t* _root() const { return m__root; } 50 | kaitai::kstruct* _parent() const { return m__parent; } 51 | }; 52 | -------------------------------------------------------------------------------- /common/generated/ms_slic_pubkey.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "ms_slic_pubkey.h" 4 | 5 | ms_slic_pubkey_t::ms_slic_pubkey_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, ms_slic_pubkey_t* p__root) : kaitai::kstruct(p__io) { 6 | m__parent = p__parent; 7 | m__root = this; (void)p__root; 8 | _read(); 9 | } 10 | 11 | void ms_slic_pubkey_t::_read() { 12 | m_type = m__io->read_u4le(); 13 | m_len_pubkey = m__io->read_u4le(); 14 | m_key_type = m__io->read_u1(); 15 | m_version = m__io->read_u1(); 16 | m_reserved = m__io->read_u2le(); 17 | m_algorithm = m__io->read_u4le(); 18 | m_magic = m__io->read_u4le(); 19 | m_bit_length = m__io->read_u4le(); 20 | m_exponent = m__io->read_u4le(); 21 | m_modulus = m__io->read_bytes(128); 22 | } 23 | 24 | ms_slic_pubkey_t::~ms_slic_pubkey_t() { 25 | _clean_up(); 26 | } 27 | 28 | void ms_slic_pubkey_t::_clean_up() { 29 | } 30 | -------------------------------------------------------------------------------- /common/generated/ms_slic_pubkey.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 4 | 5 | #include "../kaitai/kaitaistruct.h" 6 | #include 7 | #include 8 | 9 | #if KAITAI_STRUCT_VERSION < 9000L 10 | #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" 11 | #endif 12 | 13 | class ms_slic_pubkey_t : public kaitai::kstruct { 14 | 15 | public: 16 | 17 | ms_slic_pubkey_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, ms_slic_pubkey_t* p__root = nullptr); 18 | 19 | private: 20 | void _read(); 21 | void _clean_up(); 22 | 23 | public: 24 | ~ms_slic_pubkey_t(); 25 | 26 | private: 27 | uint32_t m_type; 28 | uint32_t m_len_pubkey; 29 | uint8_t m_key_type; 30 | uint8_t m_version; 31 | uint16_t m_reserved; 32 | uint32_t m_algorithm; 33 | uint32_t m_magic; 34 | uint32_t m_bit_length; 35 | uint32_t m_exponent; 36 | std::string m_modulus; 37 | ms_slic_pubkey_t* m__root; 38 | kaitai::kstruct* m__parent; 39 | 40 | public: 41 | uint32_t type() const { return m_type; } 42 | uint32_t len_pubkey() const { return m_len_pubkey; } 43 | uint8_t key_type() const { return m_key_type; } 44 | uint8_t version() const { return m_version; } 45 | uint16_t reserved() const { return m_reserved; } 46 | uint32_t algorithm() const { return m_algorithm; } 47 | uint32_t magic() const { return m_magic; } 48 | uint32_t bit_length() const { return m_bit_length; } 49 | uint32_t exponent() const { return m_exponent; } 50 | std::string modulus() const { return m_modulus; } 51 | ms_slic_pubkey_t* _root() const { return m__root; } 52 | kaitai::kstruct* _parent() const { return m__parent; } 53 | }; 54 | -------------------------------------------------------------------------------- /common/generated/phoenix_flm.cpp: -------------------------------------------------------------------------------- 1 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 2 | 3 | #include "phoenix_flm.h" 4 | 5 | phoenix_flm_t::phoenix_flm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, phoenix_flm_t* p__root) : kaitai::kstruct(p__io) { 6 | m__parent = p__parent; 7 | m__root = this; (void)p__root; 8 | m_entries = nullptr; 9 | f_len_flm_store_header = false; 10 | f_len_flm_entry = false; 11 | _read(); 12 | } 13 | 14 | void phoenix_flm_t::_read() { 15 | m_signature = m__io->read_bytes(10); 16 | m_num_entries = m__io->read_u2le(); 17 | m_reserved = m__io->read_u4le(); 18 | m_entries = std::unique_ptr>>(new std::vector>()); 19 | const int l_entries = num_entries(); 20 | for (int i = 0; i < l_entries; i++) { 21 | m_entries->push_back(std::move(std::unique_ptr(new flm_entry_t(m__io, this, m__root)))); 22 | } 23 | } 24 | 25 | phoenix_flm_t::~phoenix_flm_t() { 26 | _clean_up(); 27 | } 28 | 29 | void phoenix_flm_t::_clean_up() { 30 | } 31 | 32 | phoenix_flm_t::flm_entry_t::flm_entry_t(kaitai::kstream* p__io, phoenix_flm_t* p__parent, phoenix_flm_t* p__root) : kaitai::kstruct(p__io) { 33 | m__parent = p__parent; 34 | m__root = p__root; 35 | _read(); 36 | } 37 | 38 | void phoenix_flm_t::flm_entry_t::_read() { 39 | m_guid = m__io->read_bytes(16); 40 | m_data_type = m__io->read_u2le(); 41 | m_entry_type = m__io->read_u2le(); 42 | m_physical_address = m__io->read_u8le(); 43 | m_size = m__io->read_u4le(); 44 | m_offset = m__io->read_u4le(); 45 | } 46 | 47 | phoenix_flm_t::flm_entry_t::~flm_entry_t() { 48 | _clean_up(); 49 | } 50 | 51 | void phoenix_flm_t::flm_entry_t::_clean_up() { 52 | } 53 | 54 | int8_t phoenix_flm_t::len_flm_store_header() { 55 | if (f_len_flm_store_header) 56 | return m_len_flm_store_header; 57 | m_len_flm_store_header = 16; 58 | f_len_flm_store_header = true; 59 | return m_len_flm_store_header; 60 | } 61 | 62 | int8_t phoenix_flm_t::len_flm_entry() { 63 | if (f_len_flm_entry) 64 | return m_len_flm_entry; 65 | m_len_flm_entry = 36; 66 | f_len_flm_entry = true; 67 | return m_len_flm_entry; 68 | } 69 | -------------------------------------------------------------------------------- /common/generated/phoenix_flm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild 4 | 5 | #include "../kaitai/kaitaistruct.h" 6 | #include 7 | #include 8 | #include 9 | 10 | #if KAITAI_STRUCT_VERSION < 9000L 11 | #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" 12 | #endif 13 | 14 | class phoenix_flm_t : public kaitai::kstruct { 15 | 16 | public: 17 | class flm_entry_t; 18 | 19 | phoenix_flm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, phoenix_flm_t* p__root = nullptr); 20 | 21 | private: 22 | void _read(); 23 | void _clean_up(); 24 | 25 | public: 26 | ~phoenix_flm_t(); 27 | 28 | class flm_entry_t : public kaitai::kstruct { 29 | 30 | public: 31 | 32 | flm_entry_t(kaitai::kstream* p__io, phoenix_flm_t* p__parent = nullptr, phoenix_flm_t* p__root = nullptr); 33 | 34 | private: 35 | void _read(); 36 | void _clean_up(); 37 | 38 | public: 39 | ~flm_entry_t(); 40 | 41 | private: 42 | std::string m_guid; 43 | uint16_t m_data_type; 44 | uint16_t m_entry_type; 45 | uint64_t m_physical_address; 46 | uint32_t m_size; 47 | uint32_t m_offset; 48 | phoenix_flm_t* m__root; 49 | phoenix_flm_t* m__parent; 50 | 51 | public: 52 | std::string guid() const { return m_guid; } 53 | uint16_t data_type() const { return m_data_type; } 54 | uint16_t entry_type() const { return m_entry_type; } 55 | uint64_t physical_address() const { return m_physical_address; } 56 | uint32_t size() const { return m_size; } 57 | uint32_t offset() const { return m_offset; } 58 | phoenix_flm_t* _root() const { return m__root; } 59 | phoenix_flm_t* _parent() const { return m__parent; } 60 | }; 61 | 62 | private: 63 | bool f_len_flm_store_header; 64 | int8_t m_len_flm_store_header; 65 | 66 | public: 67 | int8_t len_flm_store_header(); 68 | 69 | private: 70 | bool f_len_flm_entry; 71 | int8_t m_len_flm_entry; 72 | 73 | public: 74 | int8_t len_flm_entry(); 75 | 76 | private: 77 | std::string m_signature; 78 | uint16_t m_num_entries; 79 | uint32_t m_reserved; 80 | std::unique_ptr>> m_entries; 81 | phoenix_flm_t* m__root; 82 | kaitai::kstruct* m__parent; 83 | 84 | public: 85 | std::string signature() const { return m_signature; } 86 | uint16_t num_entries() const { return m_num_entries; } 87 | uint32_t reserved() const { return m_reserved; } 88 | std::vector>* entries() const { return m_entries.get(); } 89 | phoenix_flm_t* _root() const { return m__root; } 90 | kaitai::kstruct* _parent() const { return m__parent; } 91 | }; 92 | -------------------------------------------------------------------------------- /common/guiddatabase.h: -------------------------------------------------------------------------------- 1 | /* guiddatabase.h 2 | 3 | Copyright (c) 2017, LongSoft. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | */ 12 | 13 | #ifndef GUID_DATABASE_H 14 | #define GUID_DATABASE_H 15 | 16 | #include 17 | #include 18 | 19 | #include "basetypes.h" 20 | #include "ustring.h" 21 | #include "ffsparser.h" 22 | #include "ffs.h" 23 | #include "utility.h" 24 | 25 | struct OperatorLessForGuids 26 | { 27 | bool operator()(const EFI_GUID& lhs, const EFI_GUID& rhs) const 28 | { 29 | return (memcmp(&lhs, &rhs, sizeof(EFI_GUID)) < 0); 30 | } 31 | }; 32 | 33 | typedef std::map GuidDatabase; 34 | 35 | UString guidDatabaseLookup(const EFI_GUID & guid); 36 | void initGuidDatabase(const UString & path = "", UINT32* numEntries = NULL); 37 | GuidDatabase guidDatabaseFromTreeRecursive(TreeModel * model, const UModelIndex index); 38 | USTATUS guidDatabaseExportToFile(const UString & outPath, GuidDatabase & db); 39 | 40 | #endif // GUID_DATABASE_H 41 | -------------------------------------------------------------------------------- /common/kaitai/custom_decoder.h: -------------------------------------------------------------------------------- 1 | #ifndef KAITAI_CUSTOM_DECODER_H 2 | #define KAITAI_CUSTOM_DECODER_H 3 | 4 | #include 5 | 6 | namespace kaitai { 7 | 8 | class custom_decoder { 9 | public: 10 | virtual ~custom_decoder() {}; 11 | virtual std::string decode(std::string src) = 0; 12 | }; 13 | 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /common/kaitai/kaitaistruct.h: -------------------------------------------------------------------------------- 1 | #ifndef KAITAI_STRUCT_H 2 | #define KAITAI_STRUCT_H 3 | 4 | #include "kaitaistream.h" 5 | 6 | namespace kaitai { 7 | 8 | class kstruct { 9 | public: 10 | kstruct(kstream *_io) { m__io = _io; } 11 | virtual ~kstruct() {} 12 | protected: 13 | kstream *m__io; 14 | public: 15 | kstream *_io() { return m__io; } 16 | }; 17 | 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /common/ksy/apple_sysf.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: apple_sysf 3 | title: Apple System Flags store 4 | application: Apple MacEFI-based UEFI firmware 5 | file-extension: sysf 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | type: u4 15 | - id: unknown 16 | type: u1 17 | - id: unknown1 18 | type: u4 19 | - id: sysf_size 20 | type: u2 21 | - id: body 22 | type: sysf_store_body 23 | size: sysf_size - len_sysf_store_header - sizeof 24 | - id: crc 25 | type: u4 26 | 27 | instances: 28 | len_sysf_store_header: 29 | value: 11 30 | 31 | types: 32 | sysf_store_body: 33 | seq: 34 | - id: variables 35 | type: sysf_variable 36 | repeat: until 37 | repeat-until: (_.len_name == 3 and _.name == "EOF") or _io.eof 38 | - id: zeroes 39 | type: u1 40 | repeat: eos 41 | 42 | sysf_variable: 43 | seq: 44 | - id: len_name 45 | type: b7le 46 | - id: invalid_flag 47 | type: b1le 48 | - id: name 49 | type: strz 50 | encoding: ascii 51 | size: len_name 52 | - id: len_data 53 | type: u2 54 | if: name != "EOF" 55 | - id: data 56 | size: len_data 57 | if: name != "EOF" 58 | 59 | -------------------------------------------------------------------------------- /common/ksy/dell_dvar.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: dell_dvar 3 | title: Dell DVAR Storage 4 | application: Dell UEFI firmware 5 | file-extension: dvar 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | size: 4 15 | - id: len_store_c 16 | type: u4 17 | - id: flags_c 18 | type: u1 19 | - id: entries 20 | type: dvar_entry 21 | repeat: until 22 | repeat-until: _.state_c == 0xFF 23 | 24 | instances: 25 | len_store: 26 | value: 0xFFFFFFFF - len_store_c 27 | flags: 28 | value: 0xFF - flags_c 29 | data_offset: 30 | value: 9 31 | 32 | #TODO: find samples with different flags and types to make them flags insead of immediates 33 | 34 | types: 35 | dvar_entry: 36 | seq: 37 | - id: state_c 38 | type: u1 39 | - id: flags_c 40 | type: u1 41 | if: state_c != 0xFF 42 | - id: type_c 43 | type: u1 44 | if: state_c != 0xFF 45 | - id: attributes_c 46 | type: u1 47 | if: state_c != 0xFF 48 | - id: namespace_id_c 49 | type: u1 50 | if: state_c != 0xFF and (flags == 2 or flags == 6) 51 | - id: namespace_guid 52 | size: 16 53 | if: state_c != 0xFF and flags == 6 54 | - id: name_id_8_c 55 | type: u1 56 | if: state_c != 0xFF and type == 0 57 | - id: name_id_16_c 58 | type: u2 59 | if: state_c != 0xFF and (type == 4 or type == 5) 60 | - id: len_data_8_c 61 | type: u1 62 | if: state_c != 0xFF and (type == 0 or type == 4) 63 | - id: len_data_16_c 64 | type: u2 65 | if: state_c != 0xFF and type == 5 66 | - id: data_8 67 | size: len_data_8 68 | if: state_c != 0xFF and (type == 0 or type == 4) 69 | - id: data_16 70 | size: len_data_16 71 | if: state_c != 0xFF and type == 5 72 | 73 | instances: 74 | state: 75 | value: 0xFF - state_c 76 | flags: 77 | value: 0xFF - flags_c 78 | type: 79 | value: 0xFF - type_c 80 | attributes: 81 | value: 0xFF - attributes_c 82 | namespace_id: 83 | value: 0xFF - namespace_id_c 84 | name_id_8: 85 | value: 0xFF - name_id_8_c 86 | name_id_16: 87 | value: 0xFFFF - name_id_16_c 88 | len_data_8: 89 | value: 0xFF - len_data_8_c 90 | len_data_16: 91 | value: 0xFFFF - len_data_16_c 92 | -------------------------------------------------------------------------------- /common/ksy/edk2_ftw.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: edk2_ftw 3 | title: EDK2 Fault Tolerant Write NVRAM store 4 | application: EDK2-based UEFI firmware 5 | file-extension: ftw 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | size: 16 15 | - id: crc 16 | type: u4 17 | - id: state 18 | type: u1 19 | - id: reserved 20 | size: 3 21 | - id: len_write_queue_32 22 | type: u4 23 | - id: len_write_queue_64 24 | type: u4 25 | if: len_write_queue_32 % 0x10 == 0 26 | - id: write_queue_32 27 | size: len_write_queue_32 28 | if: len_write_queue_32 % 0x10 == 0x04 29 | - id: write_queue_64 30 | size: ((len_write_queue_64.as) << 32) + len_write_queue_32 31 | if: len_write_queue_32 % 0x10 == 0 32 | 33 | instances: 34 | len_ftw_store_header_32: 35 | value: 28 36 | len_ftw_store_header_64: 37 | value: 32 38 | -------------------------------------------------------------------------------- /common/ksy/insyde_fdc.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: insyde_fdc 3 | title: Insyde Factory Data Copy NVRAM store 4 | application: Insyde-based UEFI firmware 5 | file-extension: fdc 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | type: u4 15 | - id: fdc_size 16 | type: u4 17 | valid: 18 | expr: _ > len_fdc_store_header.as and _ < 0xFFFFFFFF 19 | - id: body 20 | size: fdc_size - len_fdc_store_header 21 | instances: 22 | len_fdc_store_header: 23 | value: 0x50 24 | -------------------------------------------------------------------------------- /common/ksy/insyde_fdm.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: insyde_fdm 3 | title: Insyde Flash Device Map 4 | application: Insyde-based UEFI firmware 5 | file-extension: fdm 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | type: u4 15 | - id: store_size 16 | type: u4 17 | - id: data_offset 18 | type: u4 19 | - id: entry_size 20 | type: u4 21 | - id: entry_format 22 | type: u1 23 | - id: revision 24 | type: u1 25 | - id: num_extensions 26 | type: u1 27 | - id: checksum 28 | type: u1 29 | - id: fd_base_address 30 | type: u8 31 | - id: extensions 32 | type: fdm_extensions 33 | size: num_extensions * sizeof 34 | if: revision > 2 35 | - id: board_ids 36 | type: fdm_board_ids 37 | if: revision > 2 and extensions.extensions[1].count > 0 38 | #TODO: need to find a sample with revision == 4 and extensions.extensions[2].count > 0 39 | - id: entries 40 | type: fdm_entries 41 | size: store_size - data_offset 42 | 43 | types: 44 | fdm_extensions: 45 | seq: 46 | - id: extensions 47 | type: fdm_extension 48 | repeat: eos 49 | 50 | fdm_extension: 51 | seq: 52 | - id: offset 53 | type: u2 54 | - id: count 55 | type: u2 56 | 57 | fdm_board_ids: 58 | seq: 59 | - id: region_index 60 | type: u4 61 | - id: num_board_ids 62 | type: u4 63 | - id: board_ids 64 | type: u8 65 | repeat: expr 66 | repeat-expr: num_board_ids 67 | 68 | fdm_entries: 69 | seq: 70 | - id: entries 71 | type: fdm_entry 72 | repeat: eos 73 | 74 | fdm_entry: 75 | seq: 76 | - id: guid 77 | size: 16 78 | - id: region_id 79 | size: 16 80 | - id: region_offset 81 | type: u8 82 | - id: region_size 83 | type: u8 84 | - id: attributes 85 | type: u4 86 | - id: hash 87 | size: _parent._parent.entry_size - 16 - 16 - 8 - 8 - 4 88 | instances: 89 | region_base: 90 | value: _root.fd_base_address.as + region_offset.as 91 | 92 | -------------------------------------------------------------------------------- /common/ksy/intel_acm.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: intel_acm 3 | title: Intel Authenticated Code Module 4 | application: Intel x86 firmware 5 | file-extension: acm 6 | tags: 7 | - executable 8 | - firmware 9 | license: CC0-1.0 10 | ks-version: 0.9 11 | endian: le 12 | 13 | enums: 14 | module_subtype: 15 | 0: txt 16 | 1: startup 17 | 3: boot_guard 18 | 19 | known_header_version: 20 | 0x00000000: v0_0 21 | 0x00030000: v3_0 22 | 23 | seq: 24 | - id: header 25 | type: header 26 | - id: body 27 | size: 4 * (header.module_size - header.header_size - header.scratch_space_size) 28 | 29 | types: 30 | header: 31 | seq: 32 | - id: module_type 33 | type: u2 34 | valid: 0x0002 35 | - id: module_subtype 36 | type: u2 37 | enum: module_subtype 38 | - id: header_size 39 | type: u4 40 | doc: counted in 4 byte increments 41 | - id: header_version 42 | type: u4 43 | - id: chipset_id 44 | type: u2 45 | - id: flags 46 | type: u2 47 | - id: module_vendor 48 | type: u4 49 | valid: 0x8086 50 | - id: date_day 51 | type: u1 52 | doc: BCD 53 | - id: date_month 54 | type: u1 55 | doc: BCD 56 | - id: date_year 57 | type: u2 58 | doc: BCD 59 | - id: module_size 60 | type: u4 61 | doc: counted in 4 byte increments 62 | - id: acm_svn 63 | type: u2 64 | - id: se_svn 65 | type: u2 66 | - id: code_control_flags 67 | type: u4 68 | - id: error_entry_point 69 | type: u4 70 | - id: gdt_max 71 | type: u4 72 | - id: gdt_base 73 | type: u4 74 | - id: segment_sel 75 | type: u4 76 | - id: entry_point 77 | type: u4 78 | - id: reserved 79 | size: 64 80 | - id: key_size 81 | type: u4 82 | doc: counted in 4 byte increments 83 | - id: scratch_space_size 84 | type: u4 85 | doc: counted in 4 byte increments 86 | - id: rsa_public_key 87 | size: (4 * key_size) 88 | - id: rsa_exponent 89 | type: u4 90 | if: header_version == 0 91 | - id: rsa_signature 92 | size: (4 * key_size) 93 | - id: scratch_space 94 | size: (4 * scratch_space_size) 95 | -------------------------------------------------------------------------------- /common/ksy/intel_keym_v1.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: intel_keym_v1 3 | title: Intel BootGuard Key Manifest v1 4 | application: Intel x86 firmware 5 | file-extension: keym_v1 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | enums: 13 | structure_ids: 14 | 0x5f5f4d59454b5f5f: keym 15 | 16 | seq: 17 | - id: structure_id 18 | type: u8 19 | enum: structure_ids 20 | valid: structure_ids::keym 21 | - id: version 22 | type: u1 23 | valid: 24 | expr: _ < 0x20 25 | - id: km_version 26 | type: u1 27 | - id: km_svn 28 | type: u1 29 | - id: km_id 30 | type: u1 31 | - id: km_hash 32 | type: km_hash 33 | - id: key_signature 34 | type: key_signature 35 | 36 | types: 37 | km_hash: 38 | seq: 39 | - id: hash_algorithm_id 40 | type: u2 41 | - id: len_hash 42 | type: u2 43 | - id: hash 44 | size: len_hash 45 | 46 | public_key: 47 | seq: 48 | - id: version 49 | type: u1 50 | - id: size_bits 51 | type: u2 52 | - id: exponent 53 | type: u4 54 | - id: modulus 55 | size: size_bits / 8 56 | 57 | signature: 58 | seq: 59 | - id: version 60 | type: u1 61 | - id: size_bits 62 | type: u2 63 | - id: hash_algorithm_id 64 | type: u2 65 | - id: signature 66 | size: size_bits / 8 67 | 68 | key_signature: 69 | seq: 70 | - id: version 71 | type: u1 72 | - id: key_id 73 | type: u2 74 | - id: public_key 75 | type: public_key 76 | - id: sig_scheme 77 | type: u2 78 | - id: signature 79 | type: signature -------------------------------------------------------------------------------- /common/ksy/intel_keym_v2.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: intel_keym_v2 3 | title: Intel BootGuard Key Manifest v2 4 | application: Intel x86 firmware 5 | file-extension: keym_v2 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | enums: 13 | structure_ids: 14 | 0x5f5f4d59454b5f5f: keym 15 | 16 | km_usage_flags: 17 | 1: boot_policy_manifest 18 | 2: fit_patch_manifest 19 | 4: acm_manifest 20 | 8: sdev 21 | 22 | seq: 23 | - id: header 24 | type: header 25 | - id: key_signature_offset 26 | type: u2 27 | - id: reserved 28 | type: u1 29 | repeat: expr 30 | repeat-expr: 3 31 | - id: km_version 32 | type: u1 33 | - id: km_svn 34 | type: u1 35 | - id: km_id 36 | type: u1 37 | - id: fpf_hash_algorithm_id 38 | type: u2 39 | - id: num_km_hashes 40 | type: u2 41 | - id: km_hashes 42 | type: km_hash 43 | repeat: expr 44 | repeat-expr: num_km_hashes 45 | - id: key_signature 46 | type: key_signature 47 | 48 | types: 49 | header: 50 | seq: 51 | - id: structure_id 52 | type: u8 53 | enum: structure_ids 54 | valid: structure_ids::keym 55 | - id: version 56 | type: u1 57 | valid: 58 | expr: _ >= 0x20 59 | - id: header_specific 60 | type: u1 61 | - id: total_size 62 | type: u2 63 | valid: 0x0 64 | 65 | km_hash: 66 | seq: 67 | - id: usage_flags 68 | type: u8 69 | - id: hash_algorithm_id 70 | type: u2 71 | - id: len_hash 72 | type: u2 73 | - id: hash 74 | size: len_hash 75 | 76 | public_key: 77 | seq: 78 | - id: version 79 | type: u1 80 | - id: size_bits 81 | type: u2 82 | - id: exponent 83 | type: u4 84 | - id: modulus 85 | size: size_bits / 8 86 | 87 | signature: 88 | seq: 89 | - id: version 90 | type: u1 91 | - id: size_bits 92 | type: u2 93 | - id: hash_algorithm_id 94 | type: u2 95 | - id: signature 96 | size: size_bits / 8 97 | 98 | key_signature: 99 | seq: 100 | - id: version 101 | type: u1 102 | - id: key_id 103 | type: u2 104 | - id: public_key 105 | type: public_key 106 | - id: sig_scheme 107 | type: u2 108 | - id: signature 109 | type: signature -------------------------------------------------------------------------------- /common/ksy/ms_slic_marker.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: ms_slic_marker 3 | title: Microsoft SLIC Marker 4 | application: Phoenix-based UEFI firmware 5 | file-extension: slmr 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: type 14 | type: u4 15 | - id: len_marker 16 | type: u4 17 | - id: version 18 | type: u4 19 | - id: oem_id 20 | size: 6 21 | - id: oem_table_id 22 | size: 8 23 | - id: windows_flag 24 | type: u8 25 | - id: slic_version 26 | type: u4 27 | - id: reserved 28 | size: 16 29 | - id: signature 30 | size: 128 31 | -------------------------------------------------------------------------------- /common/ksy/ms_slic_pubkey.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: ms_slic_pubkey 3 | title: Microsoft SLIC Public Key 4 | application: Phoenix-based UEFI firmware 5 | file-extension: slpk 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: type 14 | type: u4 15 | - id: len_pubkey 16 | type: u4 17 | - id: key_type 18 | type: u1 19 | - id: version 20 | type: u1 21 | - id: reserved 22 | type: u2 23 | - id: algorithm 24 | type: u4 25 | - id: magic 26 | type: u4 27 | - id: bit_length 28 | type: u4 29 | - id: exponent 30 | type: u4 31 | - id: modulus 32 | size: 128 33 | -------------------------------------------------------------------------------- /common/ksy/phoenix_evsa.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: phoenix_evsa 3 | title: Phoenix EVSA NVRAM store 4 | application: Phoenix-based UEFI firmware 5 | file-extension: evsa 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: type 14 | type: u1 15 | - id: checksum 16 | type: u1 17 | - id: len_evsa_store_header 18 | type: u2 19 | - id: signature 20 | type: u4 21 | - id: attributes 22 | type: u4 23 | - id: len_evsa_store 24 | type: u4 25 | - id: reserved 26 | type: u4 27 | - id: body 28 | type: evsa_body 29 | size: len_evsa_store - len_evsa_store_header 30 | 31 | types: 32 | evsa_guid: 33 | seq: 34 | - id: guid_id 35 | type: u2 36 | - id: guid 37 | size: 16 38 | valid: 39 | expr: _parent.len_evsa_entry == 22 40 | 41 | evsa_name: 42 | seq: 43 | - id: var_id 44 | type: u2 45 | - id: name 46 | size: _parent.len_evsa_entry - 6 47 | 48 | evsa_variable_attributes: 49 | seq: 50 | - id: non_volatile 51 | type: b1le 52 | - id: boot_service 53 | type: b1le 54 | - id: runtime 55 | type: b1le 56 | - id: hw_error_record 57 | type: b1le 58 | - id: auth_write 59 | type: b1le 60 | - id: time_based_auth 61 | type: b1le 62 | - id: append_write 63 | type: b1le 64 | - id: reserved 65 | type: b21le 66 | - id: extended_header 67 | type: b1le 68 | - id: reserved1 69 | type: b3le 70 | 71 | evsa_data: 72 | seq: 73 | - id: guid_id 74 | type: u2 75 | - id: var_id 76 | type: u2 77 | - id: attributes 78 | type: evsa_variable_attributes 79 | - id: len_data_ext 80 | type: u4 81 | if: attributes.extended_header 82 | - id: data 83 | size: _parent.len_evsa_entry - 12 84 | if: not attributes.extended_header 85 | - id: data_ext 86 | size: len_data_ext 87 | if: attributes.extended_header 88 | 89 | evsa_unknown: 90 | seq: 91 | - id: unknown 92 | size: 0 93 | 94 | evsa_entry: 95 | seq: 96 | - id: entry_type 97 | type: u1 98 | - id: checksum 99 | type: u1 100 | if: entry_type == 0xE1 101 | or entry_type == 0xE2 102 | or entry_type == 0xE3 103 | or entry_type == 0xED 104 | or entry_type == 0xEE 105 | or entry_type == 0xEF 106 | or entry_type == 0x83 107 | - id: len_evsa_entry 108 | type: u2 109 | if: entry_type == 0xE1 110 | or entry_type == 0xE2 111 | or entry_type == 0xE3 112 | or entry_type == 0xED 113 | or entry_type == 0xEE 114 | or entry_type == 0xEF 115 | or entry_type == 0x83 116 | - id: body 117 | type: 118 | switch-on: entry_type 119 | cases: 120 | 0xED: evsa_guid 121 | 0xE1: evsa_guid 122 | 0xEE: evsa_name 123 | 0xE2: evsa_name 124 | 0xEF: evsa_data 125 | 0xE3: evsa_data 126 | 0x83: evsa_data 127 | _: evsa_unknown 128 | 129 | evsa_body: 130 | seq: 131 | - id: entries 132 | type: evsa_entry 133 | repeat: until 134 | repeat-until: (_.entry_type != 0xED 135 | and _.entry_type != 0xEE 136 | and _.entry_type != 0xEF 137 | and _.entry_type != 0xE1 138 | and _.entry_type != 0xE2 139 | and _.entry_type != 0xE3 140 | and _.entry_type != 0x83) 141 | or _io.eof 142 | - id: free_space 143 | type: u1 144 | repeat: eos 145 | -------------------------------------------------------------------------------- /common/ksy/phoenix_flm.ksy: -------------------------------------------------------------------------------- 1 | meta: 2 | id: phoenix_flm 3 | title: Phoenix Flash Map 4 | application: Phoenix-based UEFI firmware 5 | file-extension: flm 6 | tags: 7 | - firmware 8 | license: CC0-1.0 9 | ks-version: 0.9 10 | endian: le 11 | 12 | seq: 13 | - id: signature 14 | size: 10 15 | - id: num_entries 16 | type: u2 17 | - id: reserved 18 | type: u4 19 | - id: entries 20 | type: flm_entry 21 | repeat: expr 22 | repeat-expr: num_entries 23 | 24 | instances: 25 | len_flm_store_header: 26 | value: 16 27 | len_flm_entry: 28 | value: 36 29 | 30 | types: 31 | flm_entry: 32 | seq: 33 | - id: guid 34 | size: 16 35 | - id: data_type 36 | type: u2 37 | - id: entry_type 38 | type: u2 39 | - id: physical_address 40 | type: u8 41 | - id: size 42 | type: u4 43 | - id: offset 44 | type: u4 45 | 46 | -------------------------------------------------------------------------------- /common/me.h: -------------------------------------------------------------------------------- 1 | /* me.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | */ 12 | 13 | #ifndef ME_H 14 | #define ME_H 15 | 16 | #include "basetypes.h" 17 | 18 | // Make sure we use right packing rules 19 | #pragma pack(push, 1) 20 | 21 | typedef struct ME_VERSION_ { 22 | UINT32 Signature; 23 | UINT32 Reserved; 24 | UINT16 Major; 25 | UINT16 Minor; 26 | UINT16 Bugfix; 27 | UINT16 Build; 28 | } ME_VERSION; 29 | 30 | #define ME_VERSION_SIGNATURE 0x4E414D24 //$MAN 31 | #define ME_VERSION_SIGNATURE2 0x324E4D24 //$MN2 32 | 33 | // FPT 34 | #define ME_ROM_BYPASS_VECTOR_SIZE 0x10 35 | #define FPT_HEADER_SIGNATURE 0x54504624 //$FPT 36 | 37 | // Header version 1.0 or 2.0, default 38 | typedef struct FPT_HEADER_ { 39 | UINT32 Signature; 40 | UINT32 NumEntries; 41 | UINT8 HeaderVersion; // 0x10 or 0x20 42 | UINT8 EntryVersion; 43 | UINT8 HeaderLength; 44 | UINT8 HeaderChecksum; // One bit for Redundant 45 | UINT16 FlashCycleLife; // Maybe also TicksToAdd 46 | UINT16 FlashCycleLimit;// Maybe also TokensToAdd 47 | UINT32 UmaSize; // Maybe also Flags 48 | UINT32 Flags; // Maybe also FlashLayout 49 | UINT16 FitcMajor; 50 | UINT16 FitcMinor; 51 | UINT16 FitcHotfix; 52 | UINT16 FitcBuild; 53 | } FPT_HEADER; 54 | 55 | // Header version 2.1, special case 56 | #define FPT_HEADER_VERSION_21 0x21 57 | typedef struct FPT_HEADER_21_ { 58 | UINT32 Signature; 59 | UINT32 NumEntries; 60 | UINT8 HeaderVersion; // 0x21 61 | UINT8 EntryVersion; 62 | UINT8 HeaderLength; 63 | UINT8 Flags; // One bit for Redundant 64 | UINT16 TicksToAdd; 65 | UINT16 TokensToAdd; 66 | UINT32 SPSFlags; 67 | UINT32 HeaderCrc32; // Header + Entries sums to 0 68 | UINT16 FitcMajor; 69 | UINT16 FitcMinor; 70 | UINT16 FitcHotfix; 71 | UINT16 FitcBuild; 72 | } FPT_HEADER_21; 73 | 74 | typedef struct FPT_HEADER_ENTRY_{ 75 | CHAR8 Name[4]; 76 | CHAR8 Owner[4]; 77 | UINT32 Offset; 78 | UINT32 Size; 79 | UINT32 Reserved[3]; 80 | UINT8 Type : 7; 81 | UINT8 CopyToDramCache : 1; 82 | UINT8 Reserved1 : 7; 83 | UINT8 BuiltWithLength1 : 1; 84 | UINT8 BuiltWithLength2 : 1; 85 | UINT8 Reserved2 : 7; 86 | UINT8 EntryValid; 87 | } FPT_HEADER_ENTRY; 88 | 89 | // IFWI 90 | typedef struct IFWI_HEADER_ENTRY_ { 91 | UINT32 Offset; 92 | UINT32 Size; 93 | } IFWI_HEADER_ENTRY; 94 | 95 | // IFWI 1.6 (ME), 2.0 (BIOS) 96 | typedef struct IFWI_16_LAYOUT_HEADER_ { 97 | UINT8 RomBypassVector[16]; 98 | IFWI_HEADER_ENTRY DataPartition; 99 | IFWI_HEADER_ENTRY BootPartition[5]; 100 | UINT64 Checksum; 101 | } IFWI_16_LAYOUT_HEADER; 102 | 103 | // IFWI 1.7 (ME) 104 | typedef struct IFWI_17_LAYOUT_HEADER_ { 105 | UINT8 RomBypassVector[16]; 106 | UINT16 HeaderSize; 107 | UINT8 Flags; 108 | UINT8 Reserved; 109 | UINT32 Checksum; 110 | IFWI_HEADER_ENTRY DataPartition; 111 | IFWI_HEADER_ENTRY BootPartition[5]; 112 | IFWI_HEADER_ENTRY TempPage; 113 | } IFWI_17_LAYOUT_HEADER; 114 | 115 | #define ME_MANIFEST_HEADER_ID 0x324E4D24 //$MN2 116 | 117 | // Restore previous packing rules 118 | #pragma pack(pop) 119 | 120 | #endif // ME_H 121 | -------------------------------------------------------------------------------- /common/meparser.h: -------------------------------------------------------------------------------- 1 | /* meparser.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | 5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | */ 14 | 15 | #ifndef MEPARSER_H 16 | #define MEPARSER_H 17 | 18 | #include 19 | 20 | #include "basetypes.h" 21 | #include "ustring.h" 22 | #include "ubytearray.h" 23 | #include "treemodel.h" 24 | #include "ffsparser.h" 25 | 26 | #include "digest/sha2.h" 27 | 28 | #ifdef U_ENABLE_ME_PARSING_SUPPORT 29 | class MeParser 30 | { 31 | public: 32 | // Default constructor and destructor 33 | MeParser(TreeModel* treeModel, FfsParser* parser) : model(treeModel), ffsParser(parser) {} 34 | ~MeParser() {} 35 | 36 | // Returns messages 37 | std::vector > getMessages() const { return messagesVector; } 38 | // Clears messages 39 | void clearMessages() { messagesVector.clear(); } 40 | 41 | // ME parsing 42 | USTATUS parseMeRegionBody(const UModelIndex & index); 43 | private: 44 | TreeModel *model; 45 | FfsParser *ffsParser; 46 | std::vector > messagesVector; 47 | 48 | void msg(const UString message, const UModelIndex index = UModelIndex()) { 49 | messagesVector.push_back(std::pair(message, index)); 50 | } 51 | 52 | USTATUS parseFptRegion(const UByteArray & region, const UModelIndex & parent, UModelIndex & index); 53 | USTATUS parseIfwi16Region(const UByteArray & region, const UModelIndex & parent, UModelIndex & index); 54 | USTATUS parseIfwi17Region(const UByteArray & region, const UModelIndex & parent, UModelIndex & index); 55 | }; 56 | #else 57 | class MeParser 58 | { 59 | public: 60 | // Default constructor and destructor 61 | MeParser(TreeModel* treeModel, FfsParser* parser) { U_UNUSED_PARAMETER(treeModel); U_UNUSED_PARAMETER(parser); } 62 | ~MeParser() {} 63 | 64 | // Returns messages 65 | std::vector > getMessages() const { return std::vector >(); } 66 | // Clears messages 67 | void clearMessages() {} 68 | 69 | // ME parsing 70 | USTATUS parseMeRegionBody(const UModelIndex & index) { U_UNUSED_PARAMETER(index); return U_SUCCESS; } 71 | }; 72 | #endif // U_ENABLE_ME_PARSING_SUPPORT 73 | #endif // MEPARSER_H 74 | -------------------------------------------------------------------------------- /common/meson.build: -------------------------------------------------------------------------------- 1 | lzma = static_library('lzma', 2 | sources: [ 3 | 'LZMA/LzmaDecompress.c', 4 | 'LZMA/SDK/C/Bra86.c', 5 | 'LZMA/SDK/C/LzmaDec.c', 6 | 'Tiano/EfiTianoDecompress.c', 7 | ], 8 | ) 9 | 10 | bstrlib = static_library('bstrlib', 11 | sources: [ 12 | 'bstrlib/bstrlib.c', 13 | 'bstrlib/bstrwrap.cpp', 14 | ], 15 | ) 16 | 17 | uefitoolcommon = static_library('uefitoolcommon', 18 | sources: [ 19 | 'guiddatabase.cpp', 20 | 'types.cpp', 21 | 'descriptor.cpp', 22 | 'filesystem.cpp', 23 | 'ffs.cpp', 24 | 'nvram.cpp', 25 | 'nvramparser.cpp', 26 | 'meparser.cpp', 27 | 'fitparser.cpp', 28 | 'ffsparser.cpp', 29 | 'ffsreport.cpp', 30 | 'peimage.cpp', 31 | 'treeitem.cpp', 32 | 'treemodel.cpp', 33 | 'utility.cpp', 34 | 'ustring.cpp', 35 | 'generated/ami_nvar.cpp', 36 | 'generated/apple_sysf.cpp', 37 | 'generated/dell_dvar.cpp', 38 | 'generated/edk2_vss.cpp', 39 | 'generated/edk2_vss2.cpp', 40 | 'generated/edk2_ftw.cpp', 41 | 'generated/insyde_fdc.cpp', 42 | 'generated/insyde_fdm.cpp', 43 | 'generated/ms_slic_marker.cpp', 44 | 'generated/ms_slic_pubkey.cpp', 45 | 'generated/phoenix_flm.cpp', 46 | 'generated/phoenix_evsa.cpp', 47 | 'generated/intel_acbp_v1.cpp', 48 | 'generated/intel_acbp_v2.cpp', 49 | 'generated/intel_keym_v1.cpp', 50 | 'generated/intel_keym_v2.cpp', 51 | 'generated/intel_acm.cpp', 52 | 'kaitai/kaitaistream.cpp', 53 | 'digest/sha1.c', 54 | 'digest/sha256.c', 55 | 'digest/sha512.c', 56 | 'digest/sm3.c', 57 | ], 58 | cpp_args: [ 59 | '-DU_ENABLE_NVRAM_PARSING_SUPPORT', 60 | '-DU_ENABLE_ME_PARSING_SUPPORT', 61 | '-DU_ENABLE_FIT_PARSING_SUPPORT', 62 | '-DU_ENABLE_GUID_DATABASE_SUPPORT', 63 | ], 64 | ) 65 | -------------------------------------------------------------------------------- /common/nvramparser.h: -------------------------------------------------------------------------------- 1 | /* nvramparser.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | 5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | */ 14 | 15 | #ifndef NVRAMPARSER_H 16 | #define NVRAMPARSER_H 17 | 18 | #include 19 | 20 | #include "basetypes.h" 21 | #include "ustring.h" 22 | #include "ubytearray.h" 23 | #include "treemodel.h" 24 | #include "ffsparser.h" 25 | 26 | #ifdef U_ENABLE_NVRAM_PARSING_SUPPORT 27 | class NvramParser 28 | { 29 | public: 30 | // Default constructor and destructor 31 | NvramParser(TreeModel* treeModel, FfsParser* parser) : model(treeModel), ffsParser(parser) {} 32 | ~NvramParser() {} 33 | 34 | // Returns messages 35 | std::vector > getMessages() const { return messagesVector; } 36 | // Clears messages 37 | void clearMessages() { messagesVector.clear(); } 38 | 39 | // NVRAM parsing 40 | USTATUS parseNvramVolumeBody(const UModelIndex & index, const UINT32 fdcStoreSizeOverride = 0); 41 | USTATUS parseNvarStore(const UModelIndex & index); 42 | 43 | private: 44 | TreeModel *model; 45 | FfsParser *ffsParser; 46 | std::vector > messagesVector; 47 | void msg(const UString & message, const UModelIndex & index = UModelIndex()) { 48 | messagesVector.push_back(std::pair(message, index)); 49 | }; 50 | }; 51 | #else 52 | class NvramParser 53 | { 54 | public: 55 | // Default constructor and destructor 56 | NvramParser(TreeModel* treeModel, FfsParser* parser) { U_UNUSED_PARAMETER(treeModel); U_UNUSED_PARAMETER(parser); } 57 | ~NvramParser() {} 58 | 59 | // Returns messages 60 | std::vector > getMessages() const { return std::vector >(); } 61 | // Clears messages 62 | void clearMessages() {} 63 | 64 | // NVRAM parsing 65 | USTATUS parseNvramVolumeBody(const UModelIndex &) { return U_SUCCESS; } 66 | USTATUS parseNvarStore(const UModelIndex &) { return U_SUCCESS; } 67 | }; 68 | #endif // U_ENABLE_NVRAM_PARSING_SUPPORT 69 | #endif // NVRAMPARSER_H 70 | -------------------------------------------------------------------------------- /common/parsingdata.h: -------------------------------------------------------------------------------- 1 | /* parsingdata.h 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | Parsing data is an information needed for each level of image reconstruction 13 | routines without the need of backward traversal 14 | 15 | */ 16 | 17 | #ifndef PARSINGDATA_H 18 | #define PARSINGDATA_H 19 | 20 | #include "basetypes.h" 21 | 22 | typedef struct VOLUME_PARSING_DATA_ { 23 | EFI_GUID extendedHeaderGuid; 24 | UINT32 alignment; 25 | UINT32 usedSpace; 26 | BOOLEAN hasValidUsedSpace; 27 | UINT8 ffsVersion; 28 | UINT8 emptyByte; 29 | UINT8 revision; 30 | BOOLEAN hasExtendedHeader; 31 | BOOLEAN hasAppleCrc32; 32 | BOOLEAN isWeakAligned; 33 | BOOLEAN requiresSectionAlignmentQuirk; 34 | } VOLUME_PARSING_DATA; 35 | 36 | typedef struct FILE_PARSING_DATA_ { 37 | UINT8 emptyByte; 38 | EFI_GUID guid; 39 | } FILE_PARSING_DATA; 40 | 41 | typedef struct GUIDED_SECTION_PARSING_DATA_ { 42 | EFI_GUID guid; 43 | UINT32 dictionarySize; 44 | } GUIDED_SECTION_PARSING_DATA; 45 | 46 | typedef struct FREEFORM_GUIDED_SECTION_PARSING_DATA_ { 47 | EFI_GUID guid; 48 | } FREEFORM_GUIDED_SECTION_PARSING_DATA; 49 | 50 | typedef struct COMPRESSED_SECTION_PARSING_DATA_ { 51 | UINT32 uncompressedSize; 52 | UINT8 compressionType; 53 | UINT8 algorithm; 54 | UINT32 dictionarySize; 55 | } COMPRESSED_SECTION_PARSING_DATA; 56 | 57 | typedef struct TE_IMAGE_SECTION_PARSING_DATA_ { 58 | UINT32 originalImageBase; 59 | UINT32 adjustedImageBase; 60 | UINT8 imageBaseType; 61 | } TE_IMAGE_SECTION_PARSING_DATA; 62 | 63 | typedef struct NVAR_ENTRY_PARSING_DATA_ { 64 | UINT8 emptyByte; 65 | BOOLEAN isValid; 66 | UINT32 next; 67 | } NVAR_ENTRY_PARSING_DATA; 68 | 69 | #endif // PARSINGDATA_H 70 | -------------------------------------------------------------------------------- /common/peimage.cpp: -------------------------------------------------------------------------------- 1 | /* peimage.cpp 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php. 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "peimage.h" 15 | 16 | UString machineTypeToUString(UINT16 machineType) 17 | { 18 | switch (machineType) { 19 | case EFI_IMAGE_FILE_MACHINE_AMD64: return UString("x86-64"); 20 | case EFI_IMAGE_FILE_MACHINE_ARM: return UString("ARM"); 21 | case EFI_IMAGE_FILE_MACHINE_ARMNT: return UString("ARMv7"); 22 | case EFI_IMAGE_FILE_MACHINE_APPLE_ARM: return UString("Apple ARM"); 23 | case EFI_IMAGE_FILE_MACHINE_AARCH64: return UString("AArch64"); 24 | case EFI_IMAGE_FILE_MACHINE_EBC: return UString("EBC"); 25 | case EFI_IMAGE_FILE_MACHINE_I386: return UString("x86"); 26 | case EFI_IMAGE_FILE_MACHINE_IA64: return UString("IA64"); 27 | case EFI_IMAGE_FILE_MACHINE_POWERPC: return UString("PowerPC"); 28 | case EFI_IMAGE_FILE_MACHINE_POWERPCFP: return UString("PowerPC FP"); 29 | case EFI_IMAGE_FILE_MACHINE_THUMB: return UString("ARM Thumb"); 30 | case EFI_IMAGE_FILE_MACHINE_RISCV32: return UString("RISC-V 32-bit"); 31 | case EFI_IMAGE_FILE_MACHINE_RISCV64: return UString("RISC-V 64-bit"); 32 | case EFI_IMAGE_FILE_MACHINE_RISCV128: return UString("RISC-V 128-bit"); 33 | } 34 | return usprintf("Unknown %04Xh", machineType); 35 | } 36 | -------------------------------------------------------------------------------- /common/treeitem.cpp: -------------------------------------------------------------------------------- 1 | /* treeitem.cpp 2 | 3 | Copyright (c) 2015, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "treeitem.h" 15 | #include "types.h" 16 | 17 | TreeItem::TreeItem(const UINT32 offset, const UINT8 type, const UINT8 subtype, 18 | const UString & name, const UString & text, const UString & info, 19 | const UByteArray & header, const UByteArray & body, const UByteArray & tail, 20 | const bool fixed, const bool compressed, 21 | TreeItem *parent) : 22 | itemOffset(offset), 23 | itemAction(Actions::NoAction), 24 | itemType(type), 25 | itemSubtype(subtype), 26 | itemMarking(0), 27 | itemName(name), 28 | itemText(text), 29 | itemInfo(info), 30 | itemHeader(header), 31 | itemBody(body), 32 | itemTail(tail), 33 | itemFixed(fixed), 34 | itemCompressed(compressed), 35 | parentItem(parent) 36 | { 37 | } 38 | 39 | TreeItem::~TreeItem() { 40 | std::list::iterator begin = childItems.begin(); 41 | while (begin != childItems.end()) { 42 | delete *begin; 43 | ++begin; 44 | } 45 | } 46 | 47 | UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem) 48 | { 49 | std::list::iterator found = std::find(childItems.begin(), childItems.end(), item); 50 | if (found == childItems.end()) 51 | return U_ITEM_NOT_FOUND; 52 | childItems.insert(found, newItem); 53 | return U_SUCCESS; 54 | } 55 | 56 | UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem) 57 | { 58 | std::list::iterator found = std::find(childItems.begin(), childItems.end(), item); 59 | if (found == childItems.end()) 60 | return U_ITEM_NOT_FOUND; 61 | childItems.insert(++found, newItem); 62 | return U_SUCCESS; 63 | } 64 | 65 | UString TreeItem::data(int column) const 66 | { 67 | switch (column) 68 | { 69 | case 0: // Name 70 | return itemName; 71 | case 1: // Action 72 | return actionTypeToUString(itemAction); 73 | case 2: // Type 74 | return itemTypeToUString(itemType); 75 | case 3: // Subtype 76 | return itemSubtypeToUString(itemType, itemSubtype); 77 | case 4: // Text 78 | return itemText; 79 | default: 80 | return UString(); 81 | } 82 | } 83 | 84 | int TreeItem::row() const 85 | { 86 | if (parentItem) { 87 | std::list::const_iterator iter = parentItem->childItems.begin(); 88 | for (int i = 0; i < (int)parentItem->childItems.size(); ++i, ++iter) { 89 | if (const_cast(this) == *iter) 90 | return i; 91 | } 92 | } 93 | return 0; 94 | } 95 | 96 | TreeItem* TreeItem::child(int row) 97 | { 98 | std::list::iterator child = childItems.begin(); 99 | std::advance(child, row); 100 | return *child; 101 | } 102 | -------------------------------------------------------------------------------- /common/umemstream.h: -------------------------------------------------------------------------------- 1 | /* umemstream.h 2 | 3 | Copyright (c) 2023, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef UMEMSTREAM_H 15 | #define UMEMSTREAM_H 16 | 17 | #include 18 | 19 | // NOTE: this implementation is certainly not a valid replacement to std::stringstream 20 | // NOTE: because it only supports getting through the buffer once 21 | // NOTE: however, we already do it this way, so it's enough for practical purposes 22 | 23 | class umembuf : public std::streambuf { 24 | public: 25 | umembuf(const char *p, size_t l) { 26 | setg((char*)p, (char*)p, (char*)p + l); 27 | } 28 | 29 | pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in) override 30 | { 31 | (void)which; 32 | if (dir == std::ios_base::cur) 33 | gbump((int)off); 34 | else if (dir == std::ios_base::end) 35 | setg(eback(), egptr() + off, egptr()); 36 | else if (dir == std::ios_base::beg) 37 | setg(eback(), eback() + off, egptr()); 38 | return gptr() - eback(); 39 | } 40 | 41 | pos_type seekpos(pos_type sp, std::ios_base::openmode which) override 42 | { 43 | return seekoff(sp - pos_type(off_type(0)), std::ios_base::beg, which); 44 | } 45 | }; 46 | 47 | class umemstream : public std::istream { 48 | public: 49 | umemstream(const char *p, size_t l) : std::istream(&buffer_), 50 | buffer_(p, l) { 51 | rdbuf(&buffer_); 52 | } 53 | 54 | private: 55 | umembuf buffer_; 56 | }; 57 | 58 | #endif // UMEMSTREAM_H 59 | -------------------------------------------------------------------------------- /common/ustring.cpp: -------------------------------------------------------------------------------- 1 | /* ustring.cpp 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | */ 12 | 13 | #include "ustring.h" 14 | #include 15 | #include 16 | #include 17 | 18 | #if defined(QT_CORE_LIB) 19 | UString usprintf(const char* fmt, ...) 20 | { 21 | UString msg; 22 | va_list vl; 23 | va_start(vl, fmt); 24 | 25 | msg = msg.vasprintf(fmt, vl); 26 | 27 | va_end(vl); 28 | return msg; 29 | }; 30 | 31 | UString urepeated(char c, int len) 32 | { 33 | return UString(len, c); 34 | } 35 | #else 36 | /* Give WATCOM C/C++, MSVC some latitude for their non-support of vsnprintf */ 37 | #if defined(__WATCOMC__) || defined(_MSC_VER) 38 | #define exvsnprintf(r,b,n,f,a) {r = _vsnprintf (b,n,f,a);} 39 | #else 40 | #ifdef BSTRLIB_NOVSNP 41 | /* This is just a hack. If you are using a system without a vsnprintf, it is 42 | not recommended that bformat be used at all. */ 43 | #define exvsnprintf(r,b,n,f,a) {vsprintf (b,f,a); r = -1;} 44 | #define START_VSNBUFF (256) 45 | #else 46 | 47 | #if defined (__GNUC__) && !defined (__PPC__) && !defined(__WIN32__) 48 | /* Something is making gcc complain about this prototype not being here, so 49 | I've just gone ahead and put it in. */ 50 | extern "C" { 51 | extern int vsnprintf(char *buf, size_t count, const char *format, va_list arg); 52 | } 53 | #endif 54 | 55 | #define exvsnprintf(r,b,n,f,a) {r = vsnprintf (b,n,f,a);} 56 | #endif 57 | #endif 58 | 59 | #ifndef START_VSNBUFF 60 | #define START_VSNBUFF (16) 61 | #endif 62 | 63 | UString usprintf(const char* fmt, ...) 64 | { 65 | UString msg; 66 | bstring b; 67 | va_list arglist; 68 | int r, n; 69 | 70 | if (fmt == NULL) { 71 | msg = ""; 72 | } 73 | else { 74 | 75 | if ((b = bfromcstr("")) == NULL) { 76 | msg = ""; 77 | } 78 | else { 79 | if ((n = (int)(2 * (strlen)(fmt))) < START_VSNBUFF) n = START_VSNBUFF; 80 | for (;;) { 81 | if (BSTR_OK != balloc(b, n + 2)) { 82 | b = bformat(""); 83 | break; 84 | } 85 | 86 | va_start(arglist, fmt); 87 | exvsnprintf(r, (char *)b->data, n + 1, fmt, arglist); 88 | va_end(arglist); 89 | 90 | b->data[n] = '\0'; 91 | b->slen = (int)(strlen)((char *)b->data); 92 | 93 | if (b->slen < n) break; 94 | if (r > n) n = r; else n += n; 95 | } 96 | msg = *b; 97 | bdestroy(b); 98 | } 99 | } 100 | 101 | return msg; 102 | } 103 | 104 | UString urepeated(char c, int len) 105 | { 106 | return UString(c, len); 107 | } 108 | #endif 109 | 110 | UString uFromUcs2(const char* str, size_t max_len) 111 | { 112 | // Naive implementation assuming that only ASCII LE part of UCS2 is used, str may not be aligned. 113 | UString msg; 114 | const char *str8 = str; 115 | size_t rest = (max_len == 0) ? SIZE_MAX : max_len; 116 | while (str8[0] && rest) { 117 | msg += str8[0]; 118 | str8 += 2; 119 | rest--; 120 | } 121 | return msg; 122 | } 123 | -------------------------------------------------------------------------------- /common/ustring.h: -------------------------------------------------------------------------------- 1 | /* ustring.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | */ 12 | 13 | #ifndef USTRING_H 14 | #define USTRING_H 15 | 16 | #if defined (QT_CORE_LIB) 17 | // Use Qt class, if Qt is available 18 | #include 19 | #define UString QString 20 | #define findreplace replace 21 | #else 22 | // Use Bstrlib 23 | #define BSTRLIB_DOESNT_THROW_EXCEPTIONS 24 | #include "bstrlib/bstrwrap.h" 25 | #define UString CBString 26 | #endif // QT_CORE_LIB 27 | 28 | #if defined(__clang__) || defined(__GNUC__) 29 | #define ATTRIBUTE_FORMAT_(t,f,a) __attribute__((format(t, f, a))) 30 | #else 31 | #define ATTRIBUTE_FORMAT_(t,f,a) 32 | #endif 33 | 34 | UString usprintf(const char* fmt, ...) ATTRIBUTE_FORMAT_(printf, 1, 2); 35 | UString urepeated(char c, int len); 36 | UString uFromUcs2(const char* str, size_t max_len = 0); 37 | 38 | #endif // USTRING_H 39 | -------------------------------------------------------------------------------- /common/utility.h: -------------------------------------------------------------------------------- 1 | /* utility.h 2 | 3 | Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef UTILITY_H 15 | #define UTILITY_H 16 | 17 | #include 18 | 19 | #include "../common/zlib/zlib.h" 20 | 21 | #include "basetypes.h" 22 | #include "ustring.h" 23 | #include "treemodel.h" 24 | #include "parsingdata.h" 25 | 26 | // Returns text representation of 4CC value 27 | UString fourCC(const UINT32 value); 28 | 29 | // Returns bytes as string when all bytes are ascii visible, hex representation otherwise 30 | UString visibleAsciiOrHex(UINT8* bytes, UINT32 length); 31 | 32 | // Returns unique name for tree item 33 | UString uniqueItemName(const UModelIndex & index); 34 | 35 | // Makes the name usable as a file name 36 | void fixFileName(UString &name, bool replaceSpaces); 37 | 38 | // Converts error code to UString 39 | UString errorCodeToUString(USTATUS errorCode); 40 | 41 | // EFI/Tiano/LZMA decompression routine 42 | USTATUS decompress(const UByteArray & compressed, const UINT8 compressionType, UINT8 & algorithm, UINT32 & dictionarySize, UByteArray & decompressed, UByteArray & efiDecompressed); 43 | 44 | // GZIP decompression routine 45 | USTATUS gzipDecompress(const UByteArray & compressed, UByteArray & decompressed); 46 | 47 | // ZLIB decompression routine 48 | USTATUS zlibDecompress(const UByteArray& compressed, UByteArray& decompressed); 49 | 50 | // 8bit sum calculation routine 51 | UINT8 calculateSum8(const UINT8* buffer, UINT32 bufferSize); 52 | 53 | // 8bit checksum calculation routine 54 | UINT8 calculateChecksum8(const UINT8* buffer, UINT32 bufferSize); 55 | 56 | // 16bit checksum calculation routine 57 | UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize); 58 | 59 | // 32bit checksum calculation routine 60 | UINT32 calculateChecksum32(const UINT32* buffer, UINT32 bufferSize); 61 | 62 | // Return padding type from it's contents 63 | UINT8 getPaddingType(const UByteArray & padding); 64 | 65 | // Make pattern from a hexstring with an assumption of . being any char 66 | bool makePattern(const CHAR8 *textPattern, std::vector &pattern, std::vector &patternMask); 67 | 68 | // Find pattern in a binary blob 69 | INTN findPattern(const UINT8 *pattern, const UINT8 *patternMask, UINTN patternSize, 70 | const UINT8 *data, UINTN dataSize, UINTN dataOff); 71 | 72 | // Safely dereferences misaligned pointers 73 | template 74 | inline T readUnaligned(const T *v) { 75 | T tmp = {}; 76 | memcpy(reinterpret_cast(&tmp), reinterpret_cast(v), sizeof(T)); 77 | return tmp; 78 | } 79 | 80 | #endif // UTILITY_H 81 | -------------------------------------------------------------------------------- /common/zlib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright notice: 2 | 3 | (C) 1995-2022 Jean-loup Gailly and Mark Adler 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | Jean-loup Gailly Mark Adler 22 | jloup@gzip.org madler@alumni.caltech.edu 23 | -------------------------------------------------------------------------------- /common/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, 23 | uLong sourceLen, int level) { 24 | z_stream stream; 25 | int err; 26 | const uInt max = (uInt)-1; 27 | uLong left; 28 | 29 | left = *destLen; 30 | *destLen = 0; 31 | 32 | stream.zalloc = (alloc_func)0; 33 | stream.zfree = (free_func)0; 34 | stream.opaque = (voidpf)0; 35 | 36 | err = deflateInit(&stream, level); 37 | if (err != Z_OK) return err; 38 | 39 | stream.next_out = dest; 40 | stream.avail_out = 0; 41 | stream.next_in = (z_const Bytef *)source; 42 | stream.avail_in = 0; 43 | 44 | do { 45 | if (stream.avail_out == 0) { 46 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 47 | left -= stream.avail_out; 48 | } 49 | if (stream.avail_in == 0) { 50 | stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen; 51 | sourceLen -= stream.avail_in; 52 | } 53 | err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); 54 | } while (err == Z_OK); 55 | 56 | *destLen = stream.total_out; 57 | deflateEnd(&stream); 58 | return err == Z_STREAM_END ? Z_OK : err; 59 | } 60 | 61 | /* =========================================================================== 62 | */ 63 | int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, 64 | uLong sourceLen) { 65 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 66 | } 67 | 68 | /* =========================================================================== 69 | If the default memLevel or windowBits for deflateInit() is changed, then 70 | this function needs to be updated. 71 | */ 72 | uLong ZEXPORT compressBound(uLong sourceLen) { 73 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 74 | (sourceLen >> 25) + 13; 75 | } 76 | -------------------------------------------------------------------------------- /common/zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(gzFile file) { 12 | #ifndef NO_GZCOMPRESS 13 | gz_statep state; 14 | 15 | if (file == NULL) 16 | return Z_STREAM_ERROR; 17 | state = (gz_statep)file; 18 | 19 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 20 | #else 21 | return gzclose_r(file); 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /common/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); 12 | -------------------------------------------------------------------------------- /common/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns 852, and "enough 30 6 15" for distance codes returns 592. The 45 | initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work); 63 | -------------------------------------------------------------------------------- /common/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. *sourceLen is 13 | the byte length of the source buffer. Upon entry, *destLen is the total size 14 | of the destination buffer, which must be large enough to hold the entire 15 | uncompressed data. (The size of the uncompressed data must have been saved 16 | previously by the compressor and transmitted to the decompressor by some 17 | mechanism outside the scope of this compression library.) Upon exit, 18 | *destLen is the size of the decompressed data and *sourceLen is the number 19 | of source bytes consumed. Upon return, source + *sourceLen points to the 20 | first unused input byte. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough 23 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, or 24 | Z_DATA_ERROR if the input data was corrupted, including if the input data is 25 | an incomplete zlib stream. 26 | */ 27 | int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, 28 | uLong *sourceLen) { 29 | z_stream stream; 30 | int err; 31 | const uInt max = (uInt)-1; 32 | uLong len, left; 33 | Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ 34 | 35 | len = *sourceLen; 36 | if (*destLen) { 37 | left = *destLen; 38 | *destLen = 0; 39 | } 40 | else { 41 | left = 1; 42 | dest = buf; 43 | } 44 | 45 | stream.next_in = (z_const Bytef *)source; 46 | stream.avail_in = 0; 47 | stream.zalloc = (alloc_func)0; 48 | stream.zfree = (free_func)0; 49 | stream.opaque = (voidpf)0; 50 | 51 | err = inflateInit(&stream); 52 | if (err != Z_OK) return err; 53 | 54 | stream.next_out = dest; 55 | stream.avail_out = 0; 56 | 57 | do { 58 | if (stream.avail_out == 0) { 59 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 60 | left -= stream.avail_out; 61 | } 62 | if (stream.avail_in == 0) { 63 | stream.avail_in = len > (uLong)max ? max : (uInt)len; 64 | len -= stream.avail_in; 65 | } 66 | err = inflate(&stream, Z_NO_FLUSH); 67 | } while (err == Z_OK); 68 | 69 | *sourceLen -= len + stream.avail_in; 70 | if (dest != buf) 71 | *destLen = stream.total_out; 72 | else if (stream.total_out && err == Z_BUF_ERROR) 73 | left = 1; 74 | 75 | inflateEnd(&stream); 76 | return err == Z_STREAM_END ? Z_OK : 77 | err == Z_NEED_DICT ? Z_DATA_ERROR : 78 | err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : 79 | err; 80 | } 81 | 82 | int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, 83 | uLong sourceLen) { 84 | return uncompress2(dest, destLen, source, &sourceLen); 85 | } 86 | -------------------------------------------------------------------------------- /fuzzing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.22) 2 | 3 | PROJECT(ffsparser_fuzzer LANGUAGES C CXX) 4 | 5 | OPTION(USE_QT "Link against Qt" OFF) 6 | OPTION(USE_AFL "Build in AFL-compatible mode" OFF) 7 | 8 | SET(CMAKE_CXX_STANDARD 11) 9 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 10 | SET(CMAKE_CXX_EXTENSIONS OFF) 11 | 12 | SET(PROJECT_SOURCES 13 | ffsparser_fuzzer.cpp 14 | ../common/types.cpp 15 | ../common/descriptor.cpp 16 | ../common/guiddatabase.cpp 17 | ../common/ffs.cpp 18 | ../common/nvram.cpp 19 | ../common/nvramparser.cpp 20 | ../common/meparser.cpp 21 | ../common/ffsparser.cpp 22 | ../common/fitparser.cpp 23 | ../common/peimage.cpp 24 | ../common/treeitem.cpp 25 | ../common/treemodel.cpp 26 | ../common/utility.cpp 27 | ../common/LZMA/LzmaDecompress.c 28 | ../common/LZMA/SDK/C/Bra.c 29 | ../common/LZMA/SDK/C/Bra86.c 30 | ../common/LZMA/SDK/C/CpuArch.c 31 | ../common/LZMA/SDK/C/LzmaDec.c 32 | ../common/Tiano/EfiTianoDecompress.c 33 | ../common/ustring.cpp 34 | ../common/generated/ami_nvar.cpp 35 | ../common/generated/apple_sysf.cpp 36 | ../common/generated/dell_dvar.cpp 37 | ../common/generated/edk2_vss.cpp 38 | ../common/generated/edk2_vss2.cpp 39 | ../common/generated/edk2_ftw.cpp 40 | ../common/generated/insyde_fdc.cpp 41 | ../common/generated/insyde_fdm.cpp 42 | ../common/generated/ms_slic_marker.cpp 43 | ../common/generated/ms_slic_pubkey.cpp 44 | ../common/generated/phoenix_flm.cpp 45 | ../common/generated/phoenix_evsa.cpp 46 | ../common/generated/intel_acbp_v1.cpp 47 | ../common/generated/intel_acbp_v2.cpp 48 | ../common/generated/intel_keym_v1.cpp 49 | ../common/generated/intel_keym_v2.cpp 50 | ../common/generated/intel_acm.cpp 51 | ../common/kaitai/kaitaistream.cpp 52 | ../common/digest/sha1.c 53 | ../common/digest/sha256.c 54 | ../common/digest/sha512.c 55 | ../common/digest/sm3.c 56 | ../common/zlib/adler32.c 57 | ../common/zlib/compress.c 58 | ../common/zlib/crc32.c 59 | ../common/zlib/deflate.c 60 | ../common/zlib/gzclose.c 61 | ../common/zlib/gzlib.c 62 | ../common/zlib/gzread.c 63 | ../common/zlib/gzwrite.c 64 | ../common/zlib/inflate.c 65 | ../common/zlib/infback.c 66 | ../common/zlib/inftrees.c 67 | ../common/zlib/inffast.c 68 | ../common/zlib/trees.c 69 | ../common/zlib/uncompr.c 70 | ../common/zlib/zutil.c 71 | ) 72 | 73 | IF(USE_AFL) 74 | SET(PROJECT_SOURCES ${PROJECT_SOURCES} afl_driver.cpp) 75 | MESSAGE("-- Building in AFL-compatible mode") 76 | ELSE() 77 | MESSAGE("-- Building in libFuzzer mode") 78 | ENDIF() 79 | 80 | IF(NOT USE_QT) 81 | SET(PROJECT_SOURCES ${PROJECT_SOURCES} 82 | ../common/bstrlib/bstrlib.c 83 | ../common/bstrlib/bstrwrap.cpp 84 | ) 85 | MESSAGE("-- Using non-Qt implementations") 86 | ELSE() 87 | FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Core) 88 | MESSAGE("-- Using Qt version: ${Qt6_VERSION}") 89 | ENDIF() 90 | 91 | ADD_DEFINITIONS( 92 | -DU_ENABLE_NVRAM_PARSING_SUPPORT 93 | -DU_ENABLE_ME_PARSING_SUPPORT 94 | -DU_ENABLE_FIT_PARSING_SUPPORT 95 | -DU_ENABLE_GUID_DATABASE_SUPPORT 96 | ) 97 | 98 | ADD_EXECUTABLE(ffsparser_fuzzer ${PROJECT_SOURCES}) 99 | 100 | 101 | IF(NOT USE_AFL_DRIVER) 102 | TARGET_COMPILE_OPTIONS(ffsparser_fuzzer PRIVATE -O1 -fno-omit-frame-pointer -g -ggdb3 -fsanitize=fuzzer,address,undefined -fsanitize-address-use-after-scope -fno-sanitize-recover=undefined) 103 | TARGET_LINK_LIBRARIES(ffsparser_fuzzer PRIVATE -fsanitize=fuzzer,address,undefined) 104 | ELSE() 105 | TARGET_COMPILE_OPTIONS(ffsparser_fuzzer PRIVATE -O1 -fno-omit-frame-pointer -g -ggdb3 -fsanitize=address,undefined -fsanitize-coverage=trace-pc-guard -fsanitize-address-use-after-scope -fno-sanitize-recover=undefined) 106 | TARGET_LINK_LIBRARIES(ffsparser_fuzzer PRIVATE -fsanitize=address,undefined) 107 | ENDIF() 108 | 109 | IF(USE_QT) 110 | TARGET_LINK_LIBRARIES(ffsparser_fuzzer PRIVATE Qt6::Core) 111 | ENDIF() 112 | -------------------------------------------------------------------------------- /fuzzing/ffsparser_fuzzer.cpp: -------------------------------------------------------------------------------- 1 | /* ffsparser_fuzzer.cpp 2 | 3 | Copyright (c) 2023, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #include "../common/ffsparser.h" 15 | 16 | #define FUZZING_MIN_INPUT_SIZE 16 17 | #define FUZZING_MAX_INPUT_SIZE (128 * 1024 * 1024) 18 | 19 | extern "C" int LLVMFuzzerTestOneInput(const char *Data, long long Size) { 20 | // Do not overblow the inout file size, won't change much in practical sense 21 | if (Size > FUZZING_MAX_INPUT_SIZE || Size < FUZZING_MIN_INPUT_SIZE) return 0; 22 | 23 | // Create the FFS parser 24 | TreeModel* model = new TreeModel(); 25 | FfsParser* ffsParser = new FfsParser(model); 26 | 27 | // Parse the image 28 | (void)ffsParser->parse(UByteArray(Data, (uint32_t)Size)); 29 | 30 | delete model; 31 | delete ffsParser; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /kaitai_regenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | UTARGET=$(uname) 4 | 5 | # Determine platform 6 | if [ "$UTARGET" = "Darwin" ]; then 7 | export UPLATFORM="mac" 8 | export UFIND="find -E" 9 | export UFINDOPT="" 10 | elif [ "$UTARGET" = "Linux" ]; then 11 | export UPLATFORM="linux_$(uname -m)" 12 | export UFIND="find" 13 | export UFINDOPT="-regextype posix-extended" 14 | else 15 | export UPLATFORM="$UTARGET" 16 | echo "Please run this script on Linux or macOS" 17 | fi 18 | 19 | # Generate 20 | echo "Attempting to to generate parsers from Kaitai KSY files on ${UPLATFORM}..." 21 | kaitai-struct-compiler --target cpp_stl --cpp-standard 11 --outdir common/generated common/ksy/* || exit 1 22 | 23 | # Show generated files 24 | ${UFIND} common/generated ${UFINDOPT} \ 25 | -regex '.*\.(cpp|h)' \ 26 | -print || exit 1 27 | 28 | # Replace global includes for kaitai with local ones (<> -> "") 29 | ${UFIND} common/generated ${UFINDOPT} \ 30 | -regex '.*\.(cpp|h)' \ 31 | -exec sed -i.bak '/^#include ]/\"/g' {} + || exit 1 32 | 33 | # Add .. to the include path for kaitai includes 34 | ${UFIND} common/generated ${UFINDOPT} \ 35 | -regex '.*\.(cpp|h)' \ 36 | -exec sed -i.bak '/^#include \"kaitai\//s/kaitai\//..\/kaitai\//g' {} + || exit 1 37 | 38 | # Suppress "p__root - unused parameter" warning 39 | ${UFIND} common/generated ${UFINDOPT} \ 40 | -regex '.*\.(cpp)' \ 41 | -exec sed -i.bak '/^ m__root = this;/s/;/; (void)p__root;/g' {} + || exit 1 42 | 43 | # Add uint64_t to enum structure_ids_t 44 | ${UFIND} common/generated ${UFINDOPT} \ 45 | -regex '.*\.(h)' \ 46 | -exec sed -i.bak '/^ enum structure_ids_t {/s/{/: uint64_t {/g' {} + || exit 1 47 | 48 | # Suppress type downcast warning in ami_nvar.cpp 49 | ${UFIND} common/generated ${UFINDOPT} \ 50 | -name 'ami_nvar.cpp' \ 51 | -exec sed -i.bak 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1 52 | 53 | # Suppress type downcast warning in edk2_vss2.cpp 54 | ${UFIND} common/generated ${UFINDOPT} \ 55 | -name 'edk2_vss2.cpp' \ 56 | -exec sed -i.bak 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1 57 | ${UFIND} common/generated ${UFINDOPT} \ 58 | -name 'edk2_vss2.cpp' \ 59 | -exec sed -i.bak 's/_offset_auth = _io()->pos();/_offset_auth = (int32_t)_io()->pos();/g' {} + || exit 1 60 | 61 | # Remove backup files 62 | ${UFIND} common/generated ${UFINDOPT} \ 63 | -regex '.*\.(bak)' \ 64 | -exec rm {} + || exit 1 65 | 66 | exit 0 67 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('UEFITool', ['c', 'cpp'], 2 | version: 'A72', 3 | license: 'BSD-2-Clause', 4 | meson_version: '>=0.45.0', 5 | default_options : ['c_std=c11', 'cpp_std=c++11'], 6 | ) 7 | 8 | zlib = dependency('zlib') 9 | 10 | subdir('common') 11 | subdir('UEFIExtract') 12 | subdir('UEFIFind') 13 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=LongSoft_UEFITool 2 | sonar.organization=longsoft -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | /* version.h 2 | 3 | Copyright (c) 2019, Nikolaj Schlej. All rights reserved. 4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | */ 13 | 14 | #ifndef VERSION_H 15 | #define VERSION_H 16 | 17 | #define PROGRAM_VERSION "NE alpha 72" " (" __DATE__ ")" 18 | 19 | #endif // VERSION_H 20 | --------------------------------------------------------------------------------