Compare commits

...

425 commits

Author SHA1 Message Date
Nikolaj Schlej
a072527138 Convert other uses of 0xABCD back to ABCDh 2025-04-26 19:13:36 +07:00
Nikolaj Schlej
a19aeadb54 Revert "Update hexadecimal numbers output format from ABCDh to 0xABCD" due to breaking downstream tools
This reverts commit 9cc9518f8b.
2025-04-26 19:09:49 +07:00
Nikolaj Schlej
775227942a Improve region access settings info for Intel v2 descriptor 2025-04-26 17:30:54 +07:00
Nikolaj Schlej
6f6debb212 Add volume header info on NumBlocks and Length used to calcualte alternative size of it 2025-04-26 17:08:36 +07:00
Nikolaj Schlej
f64ba09a9c Minor fix for embedded QHexView on Windows 2025-04-26 16:28:44 +07:00
Nikolaj Schlej
2b23bbd82c Implement Apple developer signing for macOS builds 2025-04-26 16:21:58 +07:00
Nikolaj Schlej
9cc9518f8b Update hexadecimal numbers output format from ABCDh to 0xABCD 2025-04-26 16:16:02 +07:00
Nikolaj Schlej
73d07cddc3 Add Kaitai-based parser for Dell DVAR store 2025-04-26 01:14:13 +07:00
Nikolaj Schlej
c8b7151b9e Fix minor bug while presenting the EOF elemement of AppleSysF store 2025-04-24 16:11:16 +07:00
Nikolaj Schlej
892111a8b1 Add new fields into Intel Microcode header 2025-04-14 19:19:45 +07:00
Nikolaj Schlej
7cea8ee512 Remove outdated definition of FLASH_PARAMETERS 2025-04-14 18:08:12 +07:00
Nikolaj Schlej
c38ed925b0 Add missing header comments to goto*dialog.h 2025-04-14 17:58:23 +07:00
yangfl
22bb757726 Remove PATH_MAX from realpath
POSIX.1-2008 ensures realpath() give a dynamically allocated buffer if
NULL is passed, which avoids using PATH_MAX, which may be too large to
fit in stack, or even undefined on some systems.
2025-03-19 15:25:03 +07:00
Nikolaj Schlej
d61d759db2 Make sure to wrap all uses of kaitai::kstream into try-catch blocks 2025-03-16 23:37:10 +07:00
Nikolaj Schlej
7ef371957a Add initial support for Insyde H2O FlashDeviceMap rev4 2025-03-16 23:12:56 +07:00
Nikolaj Schlej
97a85f9ddc Add Microsoft LZMA section GUID 2025-03-14 07:13:06 +07:00
Nikolaj Schlej
a077743de8 Bump version numbers 2025-03-13 19:50:36 +07:00
Nikolaj Schlej
07742a5069 Update GUID database 2025-03-13 19:30:12 +07:00
Nikolaj Schlej
a12be6bfc7 Address review comments 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
9719b0cf03 Update copyright and authors in About UEFITool window 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
fbf6afdfc8 Expand Type column of the report to fit new FlashDeviceMap store and entry types 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
3cb5dc0165 Add SLIC pubkey and marker parsers 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
fd0faea9ea Add Phoenix CMDB parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
01e2e0877b Add FFS volume parser for non-AMI NVRAM areas 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
4e2a8f6bd7 Add Intel uCode parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
58366f48fe Add Insyde Flash Device Map parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
b98edf6944 Add Phoenix EVSA parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
f989fdfea1 Add Phoenix FlashMap parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
4e600eb986 Add Apple SysF/Diag parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
2d6eaa917f Add EDK2 FTW parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
ca7d4caa7a Add Insyde FDC parser 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
34904bdc5d Add KaitaiStruct parsing of Phoenix VSS2 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
489b85fd98 Rewrite VSS and VSS2 NVRAM variable parsers in KaitaiStruct 2025-03-13 19:27:55 +07:00
Nikolaj Schlej
2661b8fe4b Remove manual NVRAM parsing, add EDK2 VSS parser written in KaitaiStruct 2025-03-13 19:27:55 +07:00
Vitaly Cheptsov
d91115ff78
Also sign UEFIFind and UEFIExtract for macOS 2025-02-24 10:10:14 +03:00
Vitaly Cheptsov
0fae05c2cb
Add adhoc signature to UEFITool on macOS
Modern macOS version require applications to be signed to run
2025-02-23 20:05:16 +03:00
Vitaly Cheptsov
5e6a1c7119
Fix CFBundleIdentifier in UEFITool Info.plist
CMake does not expand Xcode-like variable sequences.
The value now matches .cpp file.
2025-02-23 19:50:39 +03:00
Nikolaj Schlej
8d7e01c027 Make sure to initialize counterUncData 2025-02-21 12:15:01 +07:00
Nikolaj Schlej
b1ad055eef Bump version numbers 2025-02-21 11:46:53 +07:00
Nikolaj Schlej
7dd9014a38 Update GUID database 2025-02-21 11:21:21 +07:00
Nikolaj Schlej
4e3fa5899c Update QHexView, build it as a library for Qt6 builds 2025-02-21 11:09:10 +07:00
Nikolaj Schlej
369f10188c Enable building ffsparser_fuzzer during CI/CD, improve readUnaligned to silence Clang UBSAN 2025-02-14 12:00:37 +01:00
Nikolaj Schlej
ff42cecb07 UEFIExtract: add support for extracting uncompressedData for tree items that have it 2025-02-14 07:19:09 +01:00
Nikolaj Schlej
c94f78a530 Add missing common/LZMA/SDK/C/7zWindows.h 2025-02-14 06:53:27 +01:00
Nikolaj Schlej
b5756f9ccb Revert old patch from common/LZMA/SDK/C/CpuArch.c 2025-02-14 06:51:07 +01:00
Nikolaj Schlej
65fb4a86b6 Update LZMA SDK to 24.09 2025-02-14 06:45:33 +01:00
Nikolaj Schlej
e66bc7d8dc Apply a small patch to common/zlib/gzguts.h to fix a build issue in macOS 2025-02-14 05:22:05 +01:00
Nikolaj Schlej
dcf21fa50a Update built-in zlib to 1.3.1 2025-02-14 05:07:30 +01:00
Nikolaj Schlej
0af36bdcd9 Fix an issue with kaitai_regenerate.sh creating backup files on modern macOS 2025-02-14 04:58:59 +01:00
Nikolaj Schlej
fd76e896cc
Update README.md 2025-02-14 03:33:37 +01:00
Nikolaj Schlej
427d8ecdcb
Update README.md 2025-02-13 01:28:06 +01:00
Nikolaj Schlej
a824260064 Add MX77L12850F 2025-02-13 01:09:48 +01:00
Nikolaj Schlej
a777f1fa5f
Update main.yml 2025-02-12 10:12:41 +01:00
Nikolaj Schlej
5f2337741a
Update main.yml 2025-02-12 10:10:31 +01:00
Nikolaj Schlej
932120cb36
Use x64 macos-13 runner for FreeBSD in main.yml 2025-02-12 09:56:49 +01:00
Nikolaj Schlej
a8c008cf74
Update macos-12 to macos-latest in main.yml 2025-02-12 09:41:49 +01:00
Nikolaj Schlej
6b853f8caf
Fix SonarCube Scan action version 2025-02-12 09:33:28 +01:00
Nikolaj Schlej
66565a557a
Try using new SonarCube scan action 2025-02-12 09:31:22 +01:00
Nikolaj Schlej
371448d0ec Enable long file paths for UEFIFind 2025-02-12 09:16:42 +01:00
Nikolaj Schlej
b0cd7fe38f
Update upload-artifacts action to v4 2025-02-12 09:11:18 +01:00
Nikolaj Schlej
4b868bb208
Remove CodeQL and PVS-Studio from main.yml 2025-02-12 09:07:02 +01:00
Nikolaj Schlej
214b356f84 Add AMIC A25LQ64 to internal JEDEC ID database 2025-02-12 08:50:50 +01:00
Vitaly Cheptsov
0030ea9481
Fix findPattern logic when pattern is at the end of the data
references #404
2024-10-09 23:36:23 +03:00
Integral
3441255566 fix: add qt version limit to setDesktopFileName 2024-07-04 20:59:19 +02:00
Integral
941ee6cfd1 Set desktop file name to fix the missing icon when running under Wayland 2024-07-04 20:59:19 +02:00
Jeremy Brown
c5508535c1 Defined ACCESSPERMS for musl 2024-02-20 12:19:07 -08:00
Nikolaj Schlej
bf93a5eacc Bump version numbers 2023-11-03 22:29:09 -07:00
Nikolaj Schlej
d03a8f254a Fixing FreeBSD action
Update main.yml
2023-11-02 13:30:11 -07:00
Nikolaj Schlej
0a88da1410 Update guids.csv 2023-11-02 12:48:44 -07:00
Nikolaj Schlej
6f9a4c0d46 Fix off-by-one error in parsing IFWI partition table
Fixes #376
2023-11-02 12:44:09 -07:00
Nikolaj Schlej
e0b1e0205f
Update main.yml
Update SonarCloud action version to 2
2023-10-26 08:51:41 -07:00
Nikolaj Schlej
161c697104
Update main.yml
Actually install JDK 17 for SonarCloud
2023-10-26 08:39:55 -07:00
Nikolaj Schlej
573452ec09
Update main.yml
Update SonarCloud action to stop using deprecated Java 11
2023-10-26 08:28:56 -07:00
William Leara
166c797a20 add Micron XM25RH128C
Add support for the Micron XM25RH128C SPI flash part.  This is a 128Mb part with DevID0 = 0x43, and DevID1 = 0x18.
2023-10-24 22:15:42 -07:00
William Leara
0e11189644 fix a few misspellings 2023-10-13 21:46:53 -07:00
Nikolaj Schlej
daf585151c
Update README.md 2023-10-06 13:36:14 -07:00
Nikolaj Schlej
1cba371cc2 Update guids.csv 2023-10-06 13:30:20 -07:00
Kamay Xutax
4992474e83 Fix CPD Extension offset (reverts 29915ca)
The CPD Extensions should have the header size added as an
offset instead.
2023-08-19 15:15:51 -07:00
xutaxkamay
29915ca620 Fix CPD Manifest's partition offset
The header size needs to be probably added here, maybe it was forgotten ?

This is needed in order to get the proper base address of a CPD_EXT_IFWI_PARTITION_MANIFEST structure in the image for example in that specific case.

If I don't do this, it points to a meaningless address.

Let me know if there can be any issues with this.
2023-08-18 09:11:13 -07:00
chunqing286
4a41c33596 Regenerate cpp source files with 2023-08-04 13:07:11 -07:00
chunqing286
b2a8952c71 Fix for AMI NVAR parser based on kaitai struct by modifing 1 line (line 128) for ami_nvar.ksy. 2023-08-04 13:07:11 -07:00
yeggor
036be8d3bc add additional check for BPDT store size 2023-07-18 15:59:14 -07:00
Julian Prein
a5675bda90 Display message when search fails
Display a message 'could not be found' when the UEFITool search fails.
2023-07-08 09:07:17 -07:00
Nikolaj Schlej
a7cf9cc3e3 Add definitions for yet another AMD-specific Zlib-compressed file and section 2023-06-25 11:58:37 -07:00
Nikolaj Schlej
2b8b00d5b0 Temporary regression fix
Reverting a check added in A66, fixing #368
2023-06-23 21:12:14 -07:00
Daniel Maslowski
8e710e637a README: point UBU link to new Win-Raid Forum home at Level1 Tech 2023-06-19 22:27:54 -07:00
Nikolaj Schlej
53f5c5cd71 Post-release version bump 2023-06-19 18:59:44 -07:00
Nikolaj Schlej
eaef5c819e Clarify MAX_PATH limitation in Windows builds of UEFIExtract 2023-06-19 18:49:59 -07:00
Nikolaj Schlej
b6cdc9f484 Add support for long paths in Windows 10+ 2023-06-19 18:49:53 -07:00
Nikolaj Schlej
031bd4f734 Provide separate filesystem.cpp 2023-06-19 12:59:23 -07:00
Nikolaj Schlej
91fb7cdc83 Update GUID database
https://fwupd.org/lvfs/shards/export/csv
2023-06-07 05:52:19 -07:00
Nikolaj Schlej
a040c72217 Post-release version bump 2023-04-23 20:34:49 -07:00
Nikolaj Schlej
1a1a20895b Refactor UEFIExtract a bit 2023-04-23 16:46:59 -07:00
Nikolaj Schlej
ddf40c9260 Add guids command to UEFIExtract 2023-04-23 16:03:35 -07:00
Nikolaj Schlej
d7c834042f
Update main.yml 2023-04-23 15:27:43 -07:00
Nikolaj Schlej
1958ed7fa9 Use static Qt 6.5.0 for universal macOS builds 2023-04-23 14:59:43 -07:00
Nikolaj Schlej
40fed25637
Update main.yml
Switch to static universal Qt 6.5.0 for macOS
2023-04-23 14:17:00 -07:00
Nikolaj Schlej
dce666c262
Update main.yml
Switch back to ubuntu-latest runner for static analyzers
2023-04-23 10:26:47 -07:00
Nikolaj Schlej
29b339436c
Update main.yml
Try using 16-core runners for static analysis
2023-04-23 10:23:50 -07:00
Nikolaj Schlej
d8bdac174d Fix static analysis issues found by PVS-Studio and Coverity 2023-04-23 10:07:45 -07:00
Nikolaj Schlej
fb5a81ebda
Update main.yml
Try reverting to ubuntu-20.04 for static analysis runners that randomly fail on ubuntu-latest
2023-04-23 02:37:12 -07:00
Nikolaj Schlej
4e17fb4f58
Update main.yml
Update Qt to 6.5.0 in CI/CD
2023-04-23 02:13:18 -07:00
Nikolaj Schlej
cba31d826a Replace QHexEdit2 with QHexView5
New widget adds better look-and-feel and comes with free proper dark mode support.
2023-04-23 00:55:05 -07:00
Nikolaj Schlej
cbf26d125d Add support for dynamic color scheme update 2023-04-22 23:48:25 -07:00
Nikolaj Schlej
84ea44829a
Change Win64 builds to Qt 6.5.0 2023-04-22 22:22:16 -07:00
Nikolaj Schlej
ce92b98527 Restore sorted state of guids.csv 2023-04-20 20:26:21 -07:00
Tody
88fa2d2a47 Update guids.csv
update TpmNvmeSupport GUID
2023-04-19 09:34:18 -07:00
Nikolaj Schlej
f1b0cae1a5
Update README.md 2023-03-26 18:56:20 -07:00
Nikolaj Schlej
12b52902e4
Update README.md 2023-03-26 18:53:52 -07:00
yeggor
d9e1fe5859 Check that volumeHeader->ExtHeaderOffset is aligned to 4 bytes 2023-03-16 16:47:51 -07:00
yeggor
2b876e2cc3 Add check for volumeHeader->ExtHeaderOffset in FfsParser::parseVolumeHeader to prevent OOB access 2023-03-16 16:47:51 -07:00
yeggor
7a25a52427 Fix OOB access with volume.mid(headerSize) 2023-03-16 16:47:51 -07:00
yeggor
37372cdab4 Release memory in fuzzer 2023-03-16 16:47:51 -07:00
yeggor
ea38ab3696 Fix nullptr deref, OOB access to volumeHeader and tempHeader by checking volumeHeader->HeaderLength 2023-03-16 16:47:51 -07:00
yeggor
9c6786a27b Fix 2 OOB access crashes in FfsParser::findNextRawAreaItem 2023-03-16 16:47:51 -07:00
yeggor
6875968d97 Check partitions size before erasing to avoid memory corruption 2023-03-16 16:47:51 -07:00
Nikolaj Schlej
aa3e790fb1 Revert "Fix FfsParser issues found by fuzzing"
This reverts commit b8567d32cc.
2023-03-12 08:49:19 -07:00
May
6aeb713488 Update README.md
Fix MDL URLs
2023-03-07 18:43:57 -08:00
Nikolaj Schlej
b8567d32cc Fix FfsParser issues found by fuzzing
Resolve alignment issue with guidToUstring
2023-02-26 16:27:27 -08:00
Nikolaj Schlej
75bf036137 Switch to C++11 for Kaitai-generated parsers 2023-02-26 13:23:25 -08:00
Nikolaj Schlej
255742f371 Post-release version bump 2023-02-25 08:59:59 -08:00
Nikolaj Schlej
62d96a16df Fix extract body action 2023-02-21 16:55:53 -08:00
Nikolaj Schlej
6c695c12a7 Fix meson builds 2023-02-19 12:38:35 -08:00
Nikolaj Schlej
7eb565d788 Switch AMI NVAR parser to Kaitai 2023-02-19 12:24:20 -08:00
Nikolaj Schlej
2d1ebcc11b Fallback to RawArea parsing in case IntelDescriptor or Capsule parsing was unsuccesful 2023-02-18 08:28:15 -08:00
Nikolaj Schlej
6f9dc0ab88 Fix Unicode search 2023-02-16 22:11:39 -08:00
Nikolaj Schlej
cb6ef45d0c Add -h/--help and -v/--version support to commandline tools 2023-02-15 16:54:32 -08:00
Nikolaj Schlej
c4ed9c310d Fix the issue with CMake install for UEFIExtract and UEFIFind
Trying to fix the issue with CMake install #2
2023-02-15 16:35:01 -08:00
Nikolaj Schlej
633561adbf
Fix macOS app packaging issue 2023-02-14 08:15:25 -08:00
Nikolaj Schlej
3cf8d86c34 Add AFL-compatible fuzzing mode, disable use of Qt6 by default 2023-02-13 19:55:31 -08:00
Nikolaj Schlej
38854e945a Fuzzing: build with Qt6 support by default, enable all parsers 2023-02-13 18:13:23 -08:00
Nikolaj Schlej
209fbb6282 Add minimal libFuzzer-compatible harness for FfsParser 2023-02-13 16:56:53 -08:00
Nikolaj Schlej
69edce7d77 Post-release version bump 2023-02-12 18:54:21 -08:00
Nikolaj Schlej
24d61c4375 Enable UI dark mode detection for Linux and FreeBSD, switch to Qt6 for them too 2023-02-12 18:20:11 -08:00
Nikolaj Schlej
1c73007e4a Remove unixbuild.sh
As we are moving away from Qt 5 and into gathering all custom build settings in one place (CI/CD configuration file), we do not need this file anymore.
2023-02-12 13:57:56 -08:00
Nikolaj Schlej
a5a0f55149 Add icons and desktop files to UEFITool install target for Linux and FreeBSD 2023-02-12 13:23:28 -08:00
Nikolaj Schlej
4053a8fe72 Add install targets to CMake files 2023-02-12 13:08:35 -08:00
Nikolaj Schlej
11e00f7113 Switch macOS builds to Qt 6.4.2 to support UI dark mode
Try #2

Try #3

Try #4

Try #5

Try #6

Try #7
2023-02-12 11:35:28 -08:00
Nikolaj Schlej
6232836fb6 Detect macOS dark aqua mode 2023-02-11 21:29:35 -08:00
Nikolaj Schlej
745f4b69f2 Fix an issue spotted by SonarCloud 2023-02-11 21:12:01 -08:00
Nikolaj Schlej
944133caa7 Automatically select dark colors for BootGuard markings in dark mode 2023-02-11 21:05:18 -08:00
Nikolaj Schlej
ef7ceefa41 Temporary change UI style for Qt6-based Windows build of UEFITool to support dark mode 2023-02-11 20:19:32 -08:00
Nikolaj Schlej
d48955d45a Add UEFITool win64 build with static Qt 6.4.2 2023-02-11 15:53:37 -08:00
Nikolaj Schlej
0c92f935e4 Add missing break 2023-02-08 00:38:47 -08:00
Nikolaj Schlej
a7aa3fa440 Update README.md 2023-02-08 00:21:36 -08:00
Nikolaj Schlej
180f061bcc Remove excessive file types for extracted data 2023-02-08 00:20:35 -08:00
Nikolaj Schlej
33c25e8255 Add AMI v3 protected ranges hash file support 2023-02-05 20:30:20 -08:00
Nikolaj Schlej
7a161f577a Fix truncation issue with 64-bit contants on Windows, update Kaitai patch script 2023-02-03 23:53:10 -08:00
Nikolaj Schlej
f02f828571 Add program version to About dialog box 2023-02-03 21:59:00 -08:00
Nikolaj Schlej
c9939e23ec Fix possible unaligned access to UCS2 strings 2023-01-31 20:15:12 -08:00
Nikolaj Schlej
20d0155130
Try updating the apt database to fix CI issues 2023-01-31 18:11:26 -08:00
Nikolaj Schlej
43997ab169
Build UEFITool with Clang sanitizers in CI/CD 2023-01-31 18:06:45 -08:00
Nikolaj Schlej
b649b98cb5 Add support for Clang sanitizers for UEFITool
Only applied to CMake Debug builds, useful for debugging undefined behavior.
2023-01-31 17:48:20 -08:00
Nikolaj Schlej
2467b48802 Attempt to fix an issue spotted by SonarCloud 2023-01-29 16:52:08 -08:00
Nikolaj Schlej
03d71d6f9f Update Intel FIT definitions accodring to FIT specification v1.4 2023-01-29 15:58:43 -08:00
Nikolaj Schlej
66e9f95dc3 Replace unneeded BOOLEAN with bool 2023-01-29 15:13:37 -08:00
Nikolaj Schlej
e6b567532d Post-release version bump 2023-01-29 14:42:54 -08:00
Nikolaj Schlej
3e55a655da
Update main.yml
Update action versions to suppress deprecation warnings
2023-01-28 22:02:15 -08:00
Nikolaj Schlej
507f884635 Fix compressed flag not being applied to the items inside GZip and Zlib GUIDed sections 2023-01-28 21:56:01 -08:00
Nikolaj Schlej
fa5d744aac Fix an issue with search result text 2023-01-28 21:48:16 -08:00
Nikolaj Schlej
5437efc2c5
Update README.md
Added Qt6, fixed the link to FIT table description, added more information about the fact that image editing is not yet supported by new_engine
2023-01-14 16:46:28 -08:00
Nikolaj Schlej
1adff58591 Update guids.csv
Add GUIDs for Intel BG BootPolicy and KeyManifest
2023-01-12 21:51:42 -08:00
Mike Beaton
eab62138aa guids.csv - fix additional [g|G][A-Z] errors 2023-01-06 19:14:51 +03:00
Nikolaj Schlej
19ab6076c4
Update ffsparser.cpp
Fix an issue with parsing CRC32 sections introduced in the previous commit
2023-01-03 01:17:41 -08:00
Mike Beaton
1b143c89e6
Fix minor issues in guids.csv (#328)
- Fix DebuSupport error from 0fb88ab760
- Add GUIDs
2023-01-02 18:08:01 +03:00
Nikolaj Schlej
7337f15ec9 Implement parsing for AMD-specific Zlib-compressed GUIDed section
Fix incorrect overflow check in parsing volume block map
2022-12-23 22:49:37 -08:00
Nikolaj Schlej
15026849d2
Update main.yml
Fix meson builds in CI
2022-12-07 12:55:07 -08:00
Nikolaj Schlej
862cdb1931 Set the font globally to fix an issue with HiDPI displays, update copyrights and organization name and domain 2022-12-07 12:25:57 -08:00
Klemens Nanni
6e7b46d791 Fix OpenBSD build, use swap16(3) from <endian.h>
bswap*() do not exist on OpenBSD.
2022-11-27 10:22:38 -08:00
yeggor
47c8938c7e Add additional check for entryHeader->Size in NvramParser::parseEvsaStoreBody to avoid uint32 underflow 2022-11-15 18:08:25 -08:00
Nikolaj Schlej
5f134f783a Fix initialization issue spotted by PVS-Studio and Coverity 2022-11-12 06:14:57 -08:00
Mike Beaton
1d560bd0be Apply hex cleaning to search dialog paste operations
- Permits pasting to 'GUID' search directly from cpp representation
 - Provides hex cleaning (e.g. auto-remove 0x) in 'Hex pattern' search as well
2022-11-12 05:52:40 -08:00
Nikolaj Schlej
71a7336730
Fix warnings spotted by GCC 2022-11-05 11:03:50 +01:00
Nikolaj Schlej
497fb2a86f Replace append with += 2022-10-23 13:49:53 +02:00
Nikolaj Schlej
c9e16cb180 Add modulus+exponent KM hashes 2022-10-23 13:37:19 +02:00
Nikolaj Schlej
50396d7291 Improve truncated image checks to preven UEFIExtract crashes 2022-10-15 09:20:55 +03:00
Richard Hughes
0429225c56 trivial: Fix the position of the colon when dumping the KM pubkey
This kinda matters when parsing the output using Python...
2022-10-11 17:15:59 +02:00
Richard Hughes
cd22c3db2b Split up the signature exponent and modulus on stdout
This makes it easier to parse from Python.
2022-10-11 09:40:34 +02:00
Nikolaj Schlej
c3cedba150 Fix another crash in checkProtectedRanges 2022-10-11 09:39:19 +02:00
Nikolaj Schlej
89a302e5d9 Calculate key manifest public key hashes that could be written into FPFs 2022-10-09 11:24:27 +02:00
Nikolaj Schlej
7e5e02b4b4 Improve detection of BPDT partition tables in raw areas, update the list of known BPDT entry types 2022-10-09 07:18:28 +02:00
Nikolaj Schlej
acc913769b Add workaround for Lenovo large files inside FFSv2 volumes 2022-10-07 14:40:20 +02:00
vulpes2
ad8a841f43 Update appstream metadata to fix screenshot URL 2022-10-05 19:00:34 +02:00
Nikolaj Schlej
d0129d4c63 Post-release version bump 2022-10-03 22:36:28 +02:00
Nikolaj Schlej
662e0bf9b1 Comment out unused (but still generating warnings) floating point parsing functions 2022-10-03 20:29:27 +02:00
Nikolaj Schlej
ee6b536009 Add FreeBSD x86-64 builds to CI/CD pipeline
Check if FreeBSD action works

Reduce qt5 package list, try building the things using default build script

Add the required qt5-buildtools package

Enable upload steps
2022-10-03 19:43:15 +02:00
pkubaj
799f186852 Fix build on *BSD/arm (32-bit)
Similar fix as for aarch64. I only tested FreeBSD, but since aarch64 version works everywhere, this one should also.
2022-09-29 23:15:57 +03:00
Nikolaj Schlej
7d4e535c34 Make UEFITool buildable with Qt 6.2 and older 2022-09-28 05:58:53 +00:00
Nikolaj Schlej
6247fa5bbc Fix building with MinGW 11.2.0 on Windows, add it into CI/CD 2022-09-27 19:22:32 +02:00
Nikolaj Schlej
9bb0549ad2 Add other BSD variants once again 2022-09-25 08:22:24 +02:00
Nikolaj Schlej
e38e246bf5 Update appdata.xml 2022-09-25 08:19:29 +02:00
vulpes2
6ca7d99f66 Add appstream manifest and screenshot 2022-09-25 08:15:40 +02:00
pkubaj
739de0fec8 Fix build on FreeBSD/arm64 2022-09-21 18:03:45 +03:00
ValdikSS
152fcc44a5 Fix compilation documentation 2022-09-17 06:33:59 -07:00
ValdikSS
d1032d59fd Compile in parallel, with all available cores 2022-09-17 06:33:59 -07:00
ValdikSS
26a2f46197 Fix compilation on Fedora: qmake is qmake-qt5 2022-09-17 06:33:59 -07:00
Nikolaj Schlej
a9d1016a52 Add other BSD variants to the same area that fixed FreeBSD builds 2022-09-15 06:46:02 +02:00
pkubaj
4358f31242 Fix build on FreeBSD 2022-09-14 21:26:55 -07:00
Nikolaj Schlej
574754fce6 Add a missing break to types.cpp 2022-09-14 19:04:44 +02:00
Nikolaj Schlej
6e5cc3bccc Add support for AMI ROM hole files 2022-09-14 19:04:44 +02:00
Nikolaj Schlej
011647aa30 Fix a possible crash of MeParser in case there are no valid FPT partition table entries 2022-09-14 19:04:44 +02:00
Nikolaj Schlej
a4a455d0ff Add support for x86 recovery startup AP data entries in special padding files 2022-09-14 19:04:44 +02:00
Nikolaj Schlej
06653d024b Provide basic non-owning memstream implementation for Kaitai parsers to use 2022-09-14 19:04:44 +02:00
Nikolaj Schlej
f514c60cba
Update README.md
Add SonarCloud QualityGate badge
2022-09-14 08:41:04 +02:00
Nikolaj Schlej
109d30b5e6
Update README.md
Added "Bug repellents" section to comply with PVS-Studio OSS licensing rules
2022-09-14 08:37:17 +02:00
yeggor
ce2291a23c Fix CMAKE_CXX_STANDARD 17 build on Windows 2022-09-14 04:05:13 +02:00
Nikolaj Schlej
b457ed99cd Post-release version bump to A62 2022-09-10 16:47:56 +02:00
Nikolaj Schlej
c4ca232b3a Fix a version issue in ACBPv2 definition file 2022-09-10 16:08:06 +02:00
Nikolaj Schlej
a9c6f347a2 Fix another issue spotted by PVS-Studio 2022-09-10 14:47:55 +02:00
Nikolaj Schlej
22d1db8c7f Fix issues spotted by PVS-Studio and SonarCloud 2022-09-10 14:20:49 +02:00
Nikolaj Schlej
75a1374c0c Fix a type issue found by CoreQL 2022-09-10 13:59:23 +02:00
Nikolaj Schlej
934ce1f3f8 Kaitai-based Intel ACM and BootGuard parsers
As the first step towards automated parsing, this change set replaces outdated BootGuard-related parsers with shiny new KaitaiStruct-based ones.
It also does the following:
- improves Intel FIT definitions by using the relevant specification
- adds sha1, sha384, sha512 and sm3 digest implementations
- updates LZMA SDK to v22.01
- moves GUIDs out of include files to prevent multiple instantiations
- enforces C++11
- adds Kaitai-based parsers for Intel FIT, BootGuard v1 and BootGuard v2 structures
- makes many small refactorings here, there and everywhere
2022-09-10 13:14:29 +02:00
Richard Hughes
8600bc3ab3 meson: Use cpp_args when compiling C++ sources 2022-09-09 16:14:40 +03:00
Glenn Washburn
55d4b4fc66 Add GUIDs from Lenovo UEFI BIOS 2022-09-08 13:43:50 +03:00
Nikolaj Schlej
2be53035b6 Add SonarCloud to CI/CD 2022-09-02 23:47:55 +02:00
Nikolaj Schlej
d6bf25df67 Add CodeQL, build everything for PVS-Studio 2022-09-02 23:11:39 +02:00
Nikolaj Schlej
787e02181a Run PVS-Studio static analyzer as part of CI/CD 2022-09-02 22:27:32 +02:00
Nikolaj Schlej
3977fcaed9 Add Qt6-only CMake file for UEFITool to use for CI/CD 2022-09-02 21:40:32 +02:00
Richard Hughes
9cd97e78e6 Post release version bump in meson 2022-09-02 13:02:51 +02:00
Richard Hughes
1675498d4d Add UEFIFind as a meson target 2022-09-02 13:02:51 +02:00
Richard Hughes
d93f1ae749 Remove an extraneous meson parameter 2022-09-02 13:02:51 +02:00
Richard Hughes
e9261a9900 Lower the meson requirement to what ships in Ubuntu 18.04 2022-09-02 13:02:51 +02:00
Nikolaj Schlej
f58a97a657
Update main.yml
Change Qt6 version from 6.4.0 (that is now "not found" for some reason) to 6.2.4.
2022-09-01 20:58:14 +02:00
Richard Hughes
eef00f73a4 Add Meson buildsystem
This allows UEFIExtract to build on a greater variety of targets and more
importantly allows us to build with the system-defined hardening protections
present in enterprise distributions.
2022-09-01 20:44:13 +02:00
Nikolaj Schlej
7695927eec Fixed inconsistent use of %ll and %l format modifiers 2022-08-29 07:10:13 +02:00
Nikolaj Schlej
e5b594c347 Run Coverity in Linux with Qt6, improve unixbuild.sh 2022-08-28 18:38:23 +02:00
Nikolaj Schlej
67c568daf8
Merge pull request #279 from LongSoft/PR/make_format_strings_sane_again
Make format strings sane again
2022-08-28 13:21:09 +02:00
Nikolaj Schlej
4006954bc1 Downcast all qtsizetype to UINT32 manually, apply consistent identation 2022-08-28 12:47:01 +02:00
Nikolaj Schlej
10e2e60183 Off with that PRI*Q bullshit 2022-08-28 12:01:43 +02:00
Nikolaj Schlej
eb3185224b More minor structure init fixes 2022-08-28 08:00:05 +02:00
vit9696
83548d4c8a Add new macOS style icon wrapper 2022-08-28 07:01:47 +03:00
vit9696
2246026434 Also force macOS 12 for Coverity 2022-08-27 19:44:18 +03:00
vit9696
ff864f9b8f Force macOS 12 to support LTO in new format
Currently macos-latest is macOS 11 on GitHub
2022-08-27 19:25:26 +03:00
vit9696
f626316b1e Build UEFITool with universal Qt 5.6.3 to produce FAT binaries on macOS
references #228
2022-08-27 19:20:04 +03:00
vit9696
7951bc1bcf Build tools as FAT binaries (arm64/x86_64) on macOS
references #228
2022-08-27 19:20:04 +03:00
Nikolaj Schlej
19ec41b7e2
Update README.md
Update CI badge to show the status of GitHub Actions, instead of the now-unused Travis-CI
2022-08-25 10:14:11 +02:00
Nikolaj Schlej
3aafbdd269 Fix another coverity warning about unitialized structure fields usage 2022-08-25 09:43:18 +02:00
Nikolaj Schlej
4c74232688
Merge pull request #274 from LongSoft/PR/fpt_header_21
Add support for Intel ME FPT header version 2.1
2022-08-25 09:27:32 +02:00
Nikolaj Schlej
74910c4658 Add support for Intel ME FPT header version 2.1 2022-08-25 08:54:34 +02:00
Nikolaj Schlej
eabd6a8604
Merge pull request #271 from LongSoft/PR/uncompressed_and_refactorings
Refactoring round 1
2022-08-25 07:13:54 +02:00
Nikolaj Schlej
820e3ea65d
Merge pull request #272 from LongSoft/PR/fix_new_coverity_warnings
Fix new warnings from Coverity Scan
2022-08-25 07:09:58 +02:00
Nikolaj Schlej
d7f360e337
Merge pull request #273 from LongSoft/PR/modernize_cicd_runners
Fix CI/CD
2022-08-25 07:08:12 +02:00
Nikolaj Schlej
e36cc77c06 Fix CI/CD
- update Linux and macOS runners to ubuntu-latest and macos-latest
- update Windows runner to use windows-2019 and VS 2019 (still with XP targeting)
2022-08-25 06:56:49 +02:00
Nikolaj Schlej
e85fb741ee Fix new warnings from Coverity Scan 2022-08-25 06:49:10 +02:00
Nikolaj Schlej
12f40cf289 - introduce Extract Uncompressed and Uncompressed Hex View actions for compressed items
- remove unused code to support Qt 5.5 and earlier Qt versions
- remove unused section parsing code
- add a check and description for section alignment quirk (compiled out for now)
2022-08-24 22:17:51 +02:00
Nikolaj Schlej
cc274319bf
Merge pull request #266 from yeggor/new_engine
Add support for EFI_GUIDED_SECTION_LZMA_HP GUID
2022-08-24 10:42:32 +02:00
yeggor
d46489fabb
Add EFI_GUIDED_SECTION_LZMA_HP GUID 2022-08-24 06:01:00 +03:00
Vitaly Cheptsov
7c534cca2a
Bump alpha version to A60 2021-10-14 04:26:59 +03:00
vit9696
d9af12b567 Use constant offsets instead of 1-byte arrays 2021-10-14 04:25:26 +03:00
Nikolaj Schlej
fae9d6681d Update utility.cpp
- address review comment
2021-10-14 04:25:26 +03:00
Nikolaj Schlej
1f488862c6 Fix #246
- fixed CPLD extension area parser hang
- added some definitions for CSME types obtained from MEParser
2021-10-14 04:25:26 +03:00
vit9696
963671a73e Merge zlib warning fixes by rurban
https://github.com/madler/zlib/compare/develop...rurban:FALLTHROUGH?d=1.patch
2021-10-07 19:10:36 +03:00
vit9696
2a083d8739 Fix cast warnings 2021-10-07 19:02:11 +03:00
vit9696
44bb6e8261 Drop meaningless const inst scalar casts 2021-10-07 18:56:25 +03:00
joevt
f9c35f77a6 Improve firmware parser and tool robustness
closes #241
2021-10-07 18:51:39 +03:00
Vitaly Cheptsov
e14547c497
Upgrade Linux CI to Ubuntu 20.04 2021-10-06 19:01:39 +03:00
vit9696
44c5b4bc49 Fix autorename in TCG and others 2021-09-11 05:33:01 +03:00
vit9696
0fb88ab760 Fix file names in guids.csv 2021-09-11 05:30:00 +03:00
assafcarlsbad
a754fb5153
Add some more GUID definitions to guids.csv. (#242) 2021-09-09 18:55:50 +03:00
Vampire Cat
34c8ad8dcc
Updated code to support newer Qt versions (#237) 2021-04-04 12:09:23 +03:00
Nikolai Kostrigin
d1e47539fc
common/descriptor.cpp: add JEDEC ID C86015 definition as GD25LQ16V (#236)
"parseIntelImage: SPI flash with unknown JEDEC ID C86015 found in VSCC table"
message was displayed on a device equipped with GigaDevice GD25LQ16V SPI flash

Co-authored-by: Nikolai Kostrigin <nickel@altlinux.org>
2021-02-17 19:51:34 +03:00
vit9696
2335e69dce Do not run Coverity in forks 2020-12-11 11:54:38 +03:00
vit9696
5066a44132 Disable coverity for pull requests 2020-11-29 16:57:32 +03:00
vit9696
6bb862d626 Build UEFITool exclusively for coverity 2020-11-27 17:49:10 +03:00
vit9696
e6f3f4380f Try configuring and building for Coverity at once 2020-11-27 15:06:19 +03:00
vit9696
05f770c8a4 Fix typo in the previous commit 2020-11-27 14:55:52 +03:00
vit9696
fd1e8c4856 Add workaround for Coverity 2020-11-27 14:48:58 +03:00
vit9696
8f862d4fdb Add coverity analysis 2020-11-27 12:17:33 +03:00
Nikolaj Schlej
3945c9b89f Correctly calculate FPT header checksum if ROM bypass vector is present and non-zero, fixes #215 for real 2020-11-22 21:19:26 -08:00
Nikolaj Schlej
5645599c58 Fix incorrect padding construction spotted by Xcode Analyzer 2020-11-22 20:56:51 -08:00
Nikolaj Schlej
115d338a70 Display non-ASCII-named FPT partition table entry names as hex (fixing #215) 2020-11-22 18:01:44 -08:00
vit9696
5967865028 Switch CI to GitHub Actions 2020-11-22 12:20:27 +03:00
Nikolaj Schlej
78714f6755
Merge pull request #226 from krsh/new_engine
Added security info to UEFIExtract
2020-11-10 02:08:11 -08:00
glgspg
10295bd0dd Added security info to UEFIExtract 2020-11-09 14:33:43 +01:00
Nikolaj Schlej
24cf452024 UE/UF: remove cmake 3.15+ property, need a different solution 2020-11-08 11:05:42 -08:00
Nikolaj Schlej
55b7a759ff UE/UF: user static CRT by default for Windows builds, take 2 2020-11-07 18:11:16 -08:00
Nikolaj Schlej
92d0a8f754 Revert "UE/UF: user static CRT by default for Windows builds"
This reverts commit d69aca6554.
2020-11-07 18:05:12 -08:00
Nikolaj Schlej
d69aca6554 UE/UF: user static CRT by default for Windows builds 2020-11-07 17:57:13 -08:00
vit9696
7bce6fac92 Bump version 2020-11-07 20:11:05 +03:00
vit9696
812af96d82 Drop windows CI builds 2020-11-07 20:10:33 +03:00
vit9696
0edd935d28 Try C++11 since it requests C++11 symbols 2020-11-04 19:37:23 +03:00
vit9696
446dba9d64 Try forcing C++03 2020-11-04 18:52:19 +03:00
vit9696
0504af6fdc Fix MINGW32 definition 2020-11-04 17:52:09 +03:00
vit9696
bfbf18404d Run msys2 upgrade externally 2020-11-04 17:06:32 +03:00
Vitaly Cheptsov
750b589575
Try importing new keys via signature verification 2020-11-04 17:02:29 +03:00
Vitaly Cheptsov
9351f697ff
Import new msys2 keys from keyring 2020-11-04 16:56:10 +03:00
Vitaly Cheptsov
ae133acc59
Try to workaround win32 CI issues 2020-11-04 16:48:20 +03:00
vit9696
753b8ee893 Fix misparsing volumes in some Lenovo firmwares 2020-11-03 11:32:54 +03:00
vit9696
b96772190a Workaround crash with AMI addressDiff calculation
references #219
2020-09-25 18:16:10 +03:00
Nikolai SAOUKH
a2d7169a82 cmake files: add EOL to last line(s) 2020-07-20 13:15:08 +03:00
Nikolai SAOUKH
57e4d6dfa0 Update AMIC Technology spi flash info
Info taken from http://www.amictechnology.com/english/flash_spi_flash.html
2020-07-16 10:03:42 +03:00
vit9696
cd110eafa6 Provide workaround for #196 2020-04-22 19:25:36 +03:00
vit9696
fc2d8f07b1
Version bump 2020-03-24 07:53:38 +03:00
vit9696
30d05a9fed Revert "Update CI configuration to dpl v2"
This reverts commit 65670a704c.
2020-03-23 15:46:46 +03:00
vit9696
65670a704c Update CI configuration to dpl v2 2020-03-22 20:25:41 +03:00
p-state
8e189f88df
Print found item as "parent/child" path (#203) 2020-03-14 07:17:49 +03:00
p-state
0f31b1401e
Print parent's name in search results (#201) 2020-03-12 20:38:48 +03:00
p-state
07dbfa3f96
Allow to use enter/return key within list widgets to navigate (#200) 2020-03-12 20:38:22 +03:00
p-state
ac1f24ec77
Fix window is not in full screen mode after closing the app (#202) 2020-03-12 20:38:08 +03:00
assafcarlsbad
a3425115b8
Add some more GUIDs to the database. (#199) 2020-03-11 21:45:56 +03:00
vit9696
0f2ede398d Implement LZMAF86 support
references #197
2020-03-06 23:54:20 +03:00
vit9696
6fdc69415b Fix microcode detection
closes #194
2020-02-08 22:05:33 +03:00
vit9696
1dccf3f15a Fix CPD signature verification 2020-01-25 10:54:06 +03:00
vit9696
4d948475d8 Fix using temporary after scope in FfsParser::parseVendorHashFile 2020-01-25 01:15:18 +03:00
vit9696
bf3adbe4c6 Fix infinite loop due to 0-sized volume files
closes #191
2020-01-24 22:36:39 +03:00
serg-pushkarev
516949a6e6 Fix FIT entry engine checksum (#189) 2020-01-20 03:18:15 +03:00
vit9696
2ef8d770e4 Fix memory leak introduced in the previous commit 2019-11-27 20:02:20 +03:00
vit9696
1b2ea8c276 Import legacy bugfixes found over time
- Fix mishandling empty microcode entries
- Fix mishandling TE image base
- Fix Intel legacy LZMA support
2019-11-27 19:46:16 +03:00
vit9696
f2e343d8bf Update field names in microcode struct as in EDK II 2019-09-06 23:16:26 +03:00
vit9696
967375243c Fix LoaderVersion and UpdateVersion handling in MCU 2019-09-05 23:38:53 +03:00
Nikolaj Schlej
8bddbe7d1f Fix TotalSize check 2019-09-05 12:58:51 -07:00
Nikolaj Schlej
3507698136 Remove broken revision check 2019-09-05 12:42:26 -07:00
Nikolaj Schlej
64e1aa18b8 Further improve micorcode header detection 2019-09-05 12:25:47 -07:00
Nikolaj Schlej
95c838181f Improve microcode header detection, parse DevExp1 region as ME region 2019-09-04 17:07:18 -07:00
Nikolaj Schlej
90ff19692d Add support for IFWI 1.7 and 2.0 layouts, improve ME parser, fix small issues spotted by static analysis 2019-08-19 11:36:02 -07:00
vit9696
d95e533441 Fix Dock drag and drop 2019-08-18 05:02:30 +03:00
vit9696
fa954394cc Remove mac image parsing as it breaks GUI navigation
Use MacEfiUnpack utility to expand the images prior to using UEFITool:
https://github.com/acidanthera/OcSupportPkg/tree/master/Utilities/MacEfiUnpack
2019-08-18 03:41:06 +03:00
vit9696
1e1d5c6e17 Add hack for broken NVRAM store sizes in Apple images 2019-08-17 14:58:08 +03:00
vit9696
47637ef152 Add dual mac image parsing support 2019-08-17 14:03:23 +03:00
vit9696
a01d2c6003 Implement Mac Image parsing support 2019-08-17 13:31:53 +03:00
Nikolaj Schlej
2e7aa8133a Initial ME parser, improved ucode parser, reset vector info 2019-07-24 10:30:59 -07:00
vit9696
f386eda430 Add support for parsing NVRAM_NVAR_BB_DEFAULTS_FILE_GUID, closes #71 2019-04-11 19:30:30 +03:00
vit9696
be65f8ae06 Fix one more resource leak 2019-03-26 14:59:13 +03:00
vit9696
5edd5c10ee Fix potential bugs found with static analysis 2019-03-26 14:22:51 +03:00
vit9696
2cbd78fb9e Fix directory creation error in UEFIExtract default mode 2019-03-08 03:07:58 +03:00
vit9696
e7455409ff Bump version to A55 2019-02-10 18:39:53 +03:00
vit9696
f34894b9fd Add support for NVRAM_NVAR_PEI_EXTERNAL_DEFAULTS_FILE_GUID, fixes #163 2019-02-10 18:38:37 +03:00
vit9696
5c98152c58 Fix analyzer warnings 2019-02-01 19:45:39 +03:00
Savva
f863caac9d Update GUID database (#161) 2019-01-29 21:15:05 +03:00
vit9696
1ac6e6a4f0 Multiple improvements and bugfixes
1. Fixes #158, UEFITool and UEFIFind failed to lookup pattern crossing header/body boundary
2. Fixes #159, filter out more symbols in fileanems, which are prohibited by different filesystems
3. Add more known file GUIDs
4. Add basic support for FMP images
5. Fix unaligned read in uint24ToUint32
6. Fix compilation with latest cmake requiring directory path
2019-01-20 13:23:28 +03:00
vit9696
40b77a713f Fix typos 2019-01-07 23:01:04 +03:00
vit9696
d16c438069 Implement dumping GUIDs from firmware and add more to builtin database 2019-01-07 19:26:31 +03:00
vit9696
afce02430a Implement local offsets 2019-01-07 16:05:57 +03:00
vit9696
be2cdc7dfe Implement custom LZMA dictionary size for NE 2019-01-03 22:53:31 +03:00
vit9696
f074dfc5ca More SPI chips (thx 4.8.4) 2018-12-11 14:51:26 +03:00
vit9696
d9325c22fe Fix #152, caused by multiple body match 2018-11-24 22:48:41 +03:00
vit9696
e1c0b08fc0 Fix analyser issues 2018-11-14 19:17:06 +03:00
vit9696
7ab6dd4285 Fix header&body extraction 2018-11-14 19:09:48 +03:00
vit9696
2201a9b10c Workaround dir removal on current dir on windows 2018-11-12 14:49:35 +03:00
vit9696
76ff756598 Rework argument passing in analysis plugin 2018-11-12 12:05:44 +03:00
vit9696
3e1afd1e00 Attempt to integrate static analysis 2018-11-12 11:06:44 +03:00
vit9696
8932aebc02 Backport decompressor untrusted data fixes from EDK2 2018-11-12 09:25:04 +03:00
vit9696
5b26775463 Rename readMisaligned to readUnaligned 2018-11-12 09:24:55 +03:00
vit9696
f2cdf7dc3b Bump version and add timestamp 2018-11-11 19:53:40 +03:00
vit9696
4dcd6b26a3 Implement gzip unpacking, fixes #149 2018-11-11 16:33:13 +03:00
vit9696
aa0ab13411 Fix duplicates in UEFIExtract 2018-11-11 14:15:11 +03:00
vit9696
6e481fbb4d Fix broken README formatting 2018-10-15 08:19:42 +03:00
vit9696
14e72cb03a More #147 fixes 2018-10-11 11:39:09 +03:00
vit9696
bc3193420c Fix #144 2018-10-10 23:41:53 +03:00
vit9696
021da9df4c Fix file extraction in UEFIExtract 2018-10-10 23:32:58 +03:00
vit9696
126b36a672 Fix windows compilation 2018-10-10 17:25:31 +03:00
vit9696
49e8e02b77 Remove debug code added by mistake 2018-10-10 17:23:45 +03:00
vit9696
7e1e1ab61e Bugfixes for #147 2018-10-10 17:20:00 +03:00
vit9696
337da5e632 Provide scanf with unsigned for strict compliance 2018-10-08 23:42:41 +03:00
vit9696
0a634ebcbd Merge recent updates but without broken builder and with minor refactoring and bugfixes 2018-10-08 12:58:12 +03:00
vit9696
b064495db8 Refresh readme 2018-08-08 09:32:56 +03:00
vit9696
8f6c8ef5cc Untie guid database from Qt 2018-08-02 05:37:09 +03:00
vit9696
6982aace9b Remove UEFIDump 2018-08-02 04:12:03 +03:00
vit9696
f666fe63db Fix compilation on Linux 2018-08-02 03:54:45 +03:00
vit9696
ee6ce579e3 Fix compilation 2018-08-02 03:51:52 +03:00
vit9696
4d50d581fa Remove Qt deps from UEFIFind and fix issues 2018-08-02 03:41:11 +03:00
vit9696
7d16c1d48d Buildfix 2018-07-13 00:31:46 +03:00
vit9696
c9db871c12 Rough attempt to deglue UEFIExtract from Qt 2018-07-13 00:17:08 +03:00
vit9696
0a2f115056 Fix some warnings 2018-07-12 22:56:51 +03:00
vit9696
616464ba29 Version bump 2018-06-13 21:58:52 +03:00
vit9696
aee2831b25 Fix info extension 2018-06-13 21:58:26 +03:00
vit9696
c70d448056 Add file extraction mode to UEFIExtract 2018-06-13 19:53:18 +03:00
vit9696
d23c1a682a Do not overwrite extracted files in UEFIExtract 2018-06-12 17:14:32 +03:00
vit9696
dccc335886 Fix subguid search in uefiextract 2018-06-08 09:32:12 +03:00
vit9696
b60a49bef3 Fix not working comparison 2018-06-03 03:42:35 +03:00
vit9696
53a0887112 Allow specialised output in UEFIExtract 2018-06-02 21:59:57 +03:00
vit9696
a5b2f00f9b Make imagefile first arg of UEFIFind 2018-06-02 20:56:17 +03:00
vit9696
4f6efe5195 Add more chip IDs, thank you Google 2018-06-02 19:27:24 +03:00
vit9696
4f9f31ef71 Unify version scheme and fix minor issues 2018-05-22 00:59:23 +03:00
vit9696
daea6d8b16 Make appveyor like artifacts 2018-05-08 21:36:20 +03:00
vit9696
6f104ec94c Fix appveyour deploy 2018-05-08 19:51:12 +03:00
vit9696
fc2cd74755 Increment version 2018-05-08 19:35:14 +03:00
vit9696
4ab4393632 Watch out for invalid variables 2018-05-08 19:33:00 +03:00
vit9696
f352fa0cab Sync tianocompress with upstream and more warning fixes 2018-05-08 19:02:25 +03:00
vit9696
9ee937a429 Include offset in FfsReport 2018-05-08 18:44:49 +03:00
vit9696
cf01543f06 Silence analyzer warnings and fix potential issues 2018-05-08 18:42:16 +03:00
vit9696
bbdfe28449 Fix and reindent LZMA 2018-05-08 18:16:28 +03:00
vit9696
d87cbe3210 Slightly more portable PRIX64 workaround 2018-05-08 10:48:04 +03:00
vit9696
afc5a44446 Fix Linux compilation 2018-05-08 03:02:07 +03:00
vit9696
e0b3049bff Initial Windows build support for NE 2018-05-08 02:48:34 +03:00
vit9696
217df48c45 Watch out for qmake failures on Linux 2018-05-07 21:43:12 +03:00
vit9696
a03b87785f Add Linux x86-64 CI support 2018-05-07 21:28:45 +03:00
vit9696
b35193b3df Fix a compiler warning 2018-05-07 20:55:25 +03:00
vit9696
ec38091599 Improve descriptor version handling 2018-05-07 00:38:06 +03:00
vit9696
3eae2e4fdc 1.0 descriptors should go via FLASH_DESCRIPTOR_MASTER_SECTION_V2 2018-05-06 15:34:34 +03:00
vit9696
8bbf56d2f4 Fix Intel descriptor version parsing 2018-05-06 15:22:25 +03:00
vit9696
23c4006979 Version bump 2018-05-04 21:52:25 +03:00
vit9696
268ccb00a8 Backport TianoDecompress fix for Xcode (https://bugzilla.tianocore.org/show_bug.cgi?id=635) 2018-05-04 20:48:02 +03:00
vit9696
17bbe50320 Merge pull request #131 from vit9696/new_engine
Travis Mac NE
2018-05-04 06:51:51 +03:00
vit9696
471c5801f1 Add deloy key 2018-05-04 06:41:01 +03:00
vit9696
ddecccec86 Implement mac builds with deploy and fix Linux builds 2018-05-03 22:26:28 +03:00
Alex Matrosov
17267ed4b1 Update ffsparser.cpp 2018-04-29 22:41:13 -07:00
Alex Matrosov
1f120b821d Update uefitool.cpp 2018-04-29 22:35:51 -07:00
Alex Matrosov
e3ace324ee bugfix 2018-04-29 22:33:19 -07:00
Alex Matrosov
1cbd3393c8 bugfix 2018-02-25 15:33:54 -08:00
Cr4sh
a4e38090b0 NE Alpha 46 2018-02-15 06:02:53 +03:00
Alex Matrosov
82a89b2c03 multiple fixes 2018-01-23 00:00:03 -08:00
Alex Matrosov
8fb214c322 Update ffsparser.cpp 2017-12-10 21:39:47 -08:00
Alex Matrosov
63088afd87 A45
+ FFSv3 support with large files and large sections
+ proper names for Flash Descriptor v2 regions (#89)
+ better alignment calculations (#96)
+ improved NVRAM parser
+ post IBB hash support for Boot Guard
+  bugfixes
+ companion tool updated
2017-12-10 17:56:00 -08:00
Alex Matrosov
02369442a2 NE Alpha 44
+ support of MS Surface implementation of Intel Boot Guard
+ optional disabling Intel Boot Guard marking
2017-11-05 23:10:06 -08:00
Alex Matrosov
68df5a64a3 NE Alpha 43
add visual validation of Intel Boot Guard coverage
2017-10-11 22:59:23 -07:00
Cr4sh
fc579533e8 NE Alpha 42 2017-07-31 09:06:11 +03:00
Cr4sh
9b85fac61b UEFIFind and nvramparser.cpp bugfixes 2017-07-22 21:43:20 +03:00
Cr4sh
227be5480e NE Alpha 41 2017-07-08 22:31:57 +03:00
Alex Matrosov
c0f1a8eadf Merge pull request #77 from Velocet/patch-1
Update guids.csv
2017-05-06 17:18:14 -07:00
Velocet
7773e31c47 Update guids.csv
- Consolidated with https://gist.github.com/skochinsky/3b8f948bfef6f8b32c0577ac018bdaf9 from @skochinsky
- Some duplicates removed
2017-04-27 00:45:17 +02:00
Dmytro Oleksiuk
abf7778395 Merge pull request #71 from probonopd/patch-1
Compile on Travis CI
2017-03-09 16:24:44 +03:00
probonopd
cec9d67165 Update .travis.yml 2017-02-26 01:04:10 +01:00
probonopd
a535e8a577 Update .travis.yml 2017-02-26 01:00:38 +01:00
probonopd
a1b6dc0598 Create .travis.yml 2017-02-26 00:54:01 +01:00
Cr4sh
0f0bc32a42 NE Alpha 40 2017-02-14 09:39:16 +03:00
Cr4sh
7b18f346dd NE Alpha 39 2017-02-12 10:28:33 +03:00
Cr4sh
f5f7f3664c messagelistitem.cpp/h removed 2017-01-16 21:28:30 +03:00
Cr4sh
7cf24f5370 remove old unused source files 2017-01-16 06:06:18 +03:00
Cr4sh
0e09dfe1b2 NE Alpha 38 2017-01-14 03:24:56 +03:00
Cr4sh
f410b0f969 NE Alpha 37 2016-12-23 01:34:24 +03:00
Cr4sh
0e60013311 NE Alpha 36 2016-12-04 01:36:01 +03:00
Cr4sh
4160a6a580 NE Alpha 35 2016-11-03 02:40:38 +07:00
Cr4sh
52c7a56f68 NE Alpha 34 2016-10-27 23:31:15 +07:00
Alex Matrosov
cb430456bf NE Alpha 33
- human readable JEDEC ID
- NVRAM parser separated from FFS parser
- added support for LZMAF86 sections
- solved a bug with parsing of VSS variables with invalid sizes
2016-10-09 23:05:04 -07:00
292 changed files with 77019 additions and 25818 deletions

418
.github/workflows/main.yml vendored Normal file
View file

@ -0,0 +1,418 @@
name: CI/CD
on:
push:
pull_request:
workflow_dispatch:
release:
types: [published]
jobs:
# Release builds
build_release_macos:
name: Release build (macOS universal, static Qt 6.5.0)
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Get Qt
uses: actions/checkout@v3
with:
repository: LongSoft/qt-6-static-universal-macos
path: qt
lfs: true
- name: Unpack Qt
shell: bash
working-directory: qt
run: sudo 7z x qt-6.5.0-static-universal-macos.7z -o/opt
- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure everything
working-directory: ${{runner.workspace}}/build
run: cmake -DCMAKE_PREFIX_PATH="/opt/qt-6.5.0-static-universal-macos" -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_OSX_DEPLOYMENT_TARGET="11.0" ../UEFITool
- name: Build everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config Release
- name: Create dist directory
run: cmake -E make_directory ${{runner.workspace}}/UEFITool/dist
- name: Signed archive everything
if: github.repository_owner == 'LongSoft'
working-directory: ${{runner.workspace}}/build
env:
MAC_CERTIFICATE_PASSWORD: ${{ secrets.MAC_CERTIFICATE_PASSWORD }}
MAC_ACCOUNT_NAME: ${{ secrets.MAC_ACCOUNT_NAME }}
MAC_ACCOUNT_PASSWORD: ${{ secrets.MAC_ACCOUNT_PASSWORD }}
shell: bash
run: |
UEFITOOL_VER=$(cat ../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
codesign -fs - UEFIExtract/UEFIExtract
codesign -fs - UEFIFind/UEFIFind
zip -qryj ../UEFITool/dist/UEFIExtract_NE_${UEFITOOL_VER}_universal_mac.zip ./UEFIExtract/UEFIExtract
zip -qryj ../UEFITool/dist/UEFIFind_NE_${UEFITOOL_VER}_universal_mac.zip ./UEFIFind/UEFIFind
brew install create-dmg || exit 1
curl -OL "https://github.com/acidanthera/ocbuild/raw/master/codesign/appsign.sh" || exit 1
chmod a+x appsign.sh || exit 1
"$(pwd)/appsign.sh" ./UEFITool/UEFITool.app ../UEFITool/dist/UEFITool_NE_${UEFITOOL_VER}_universal_mac.dmg
- name: Archive everything
if: github.repository_owner != 'LongSoft'
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
UEFITOOL_VER=$(cat ../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
codesign -fs - UEFIExtract/UEFIExtract
codesign -fs - UEFIFind/UEFIFind
zip -qryj ../UEFITool/dist/UEFIExtract_NE_${UEFITOOL_VER}_universal_mac.zip ./UEFIExtract/UEFIExtract
zip -qryj ../UEFITool/dist/UEFIFind_NE_${UEFITOOL_VER}_universal_mac.zip ./UEFIFind/UEFIFind
cd UEFITool
codesign -fs - --deep UEFITool.app
zip -qry ../../UEFITool/dist/UEFITool_NE_${UEFITOOL_VER}_universal_mac.zip ./UEFITool.app
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: macOS builds
path: dist/*
- name: Upload to releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*
tag: ${{ github.ref }}
file_glob: true
build_release_linux:
name: Release build (Linux x64, shared Qt 6)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Get Qt
run: |
sudo apt update
sudo apt-get install -qq zip cmake libgl1-mesa-dev qt6-base-dev
- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure everything
working-directory: ${{runner.workspace}}/build
run: cmake ../UEFITool
- name: Build everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config Release
- name: Create dist directory
run: cmake -E make_directory ${{runner.workspace}}/UEFITool/dist
- name: Archive everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
UEFITOOL_VER=$(cat ../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
zip -qryj ../UEFITool/dist/UEFIExtract_NE_${UEFITOOL_VER}_x64_linux.zip ./UEFIExtract/uefiextract
zip -qryj ../UEFITool/dist/UEFIFind_NE_${UEFITOOL_VER}_x64_linux.zip ./UEFIFind/uefifind
zip -qryj ../UEFITool/dist/UEFITool_NE_${UEFITOOL_VER}_x64_linux.zip ./UEFITool/uefitool
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: Linux builds
path: dist/*.zip
- name: Upload to releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*.zip
tag: ${{ github.ref }}
file_glob: true
build_release_freebsd:
name: Release build (FreeBSD x64, shared Qt 6)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build on FreeBSD inside Ubuntu VM
id: test
uses: cross-platform-actions/action@v0.27.0
with:
operating_system: freebsd
version: '13.3'
shell: sh
run: |
sudo pkg install -y zip cmake qt6-base
mkdir dist
mkdir build
cd build
cmake ..
cmake --build . --config Release
UEFITOOL_VER=$(cat ../version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
zip -qryj ../dist/UEFIExtract_NE_${UEFITOOL_VER}_x64_freebsd.zip ./UEFIExtract/uefiextract
zip -qryj ../dist/UEFIFind_NE_${UEFITOOL_VER}_x64_freebsd.zip ./UEFIFind/uefifind
zip -qryj ../dist/UEFITool_NE_${UEFITOOL_VER}_x64_freebsd.zip ./UEFITool/uefitool
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: FreeBSD builds
path: dist/*.zip
- name: Upload to releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*.zip
tag: ${{ github.ref }}
file_glob: true
build_release_windows_32:
name: Release build (Win32, static Qt 5.6.3)
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Get Qt 5.6.3
uses: actions/checkout@v3
with:
repository: LongSoft/qt-5.6.3-static-x86-msvc2017
path: qt5
lfs: true
- name: Unpack Qt 5.6.3
shell: bash
working-directory: qt5
run: 7z x qt-5.6.3-static-x86-msvc2017.7z -o../..
- name: Create dist directory
shell: bash
run: mkdir dist
- name: Create UEFIExtract build directory
run: cmake -E make_directory ${{runner.workspace}}/build/UEFIExtract
- name: Configure UEFIExtract
shell: bash
working-directory: ${{runner.workspace}}/build/UEFIExtract
run: cmake -G "Visual Studio 16 2019" -A Win32 -T "v141_xp" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ../../UEFITool/UEFIExtract/
- name: Build UEFIExtract
working-directory: ${{runner.workspace}}/build/UEFIExtract
shell: bash
run: cmake --build . --config Release
- name: Archive UEFIExtract
working-directory: ${{runner.workspace}}/build/UEFIExtract/Release
shell: bash
run: |
UEFITOOL_VER=$(cat ../../../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
7z a ../../../UEFITool/dist/UEFIExtract_NE_${UEFITOOL_VER}_win32.zip UEFIExtract.exe
- name: Create UEFIFind build directory
run: cmake -E make_directory ${{runner.workspace}}/build/UEFIFind
- name: Configure UEFIFind
working-directory: ${{runner.workspace}}/build/UEFIFind
shell: bash
run: cmake -G "Visual Studio 16 2019" -A Win32 -T "v141_xp" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ../../UEFITool/UEFIFind/
- name: Build UEFIFind
working-directory: ${{runner.workspace}}/build/UEFIFind
shell: bash
run: cmake --build . --config Release
- name: Archive UEFIFind
working-directory: ${{runner.workspace}}/build/UEFIFind/Release
shell: bash
run: |
UEFITOOL_VER=$(cat ../../../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
7z a ../../../UEFITool/dist/UEFIFind_NE_${UEFITOOL_VER}_win32.zip UEFIFind.exe
- name: Create UEFITool build directory
run: cmake -E make_directory ${{runner.workspace}}/build/UEFITool
- name: Configure UEFITool
shell: bash
working-directory: ${{runner.workspace}}/build/UEFITool
run: ../../qt-5.6.3-static-x86-msvc2017/bin/qmake.exe -tp vc ../../UEFITool/UEFITool/
- name: Build UEFITool
working-directory: ${{runner.workspace}}/build/UEFITool
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
msbuild -t:Rebuild -p:PlatformToolset=v141_xp;Configuration=Release
- name: Archive UEFITool
working-directory: ${{runner.workspace}}/build/UEFITool/release
shell: bash
run: |
UEFITOOL_VER=$(cat ../../../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
7z a ../../../UEFITool/dist/UEFITool_NE_${UEFITOOL_VER}_win32.zip UEFITool.exe
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: Windows 32-bit builds
path: dist/*.zip
- name: Upload to releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*.zip
tag: ${{ github.ref }}
file_glob: true
build_release_windows_64:
name: Release build (Win64, static Qt 6.5.0)
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- name: Get Qt 6.5.0
uses: actions/checkout@v3
with:
repository: LongSoft/qt-6-static-x64-msvc2022
path: qt6
lfs: true
- name: Unpack Qt 6.5.0
shell: bash
working-directory: qt6
run: 7z x qt-6.5.0-static-x64-msvc2022.7z -o../..
- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure everything
working-directory: ${{runner.workspace}}/build
shell: cmd
run: cmake -DCMAKE_PREFIX_PATH="D:\a\UEFITool\qt-6.5.0-static-x64-msvc2022" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -A x64 ../UEFITool
- name: Build everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config Release
- name: Create dist directory
run: cmake -E make_directory ${{runner.workspace}}/UEFITool/dist
- name: Archive everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
UEFITOOL_VER=$(cat ../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
7z a ../UEFITool/dist/UEFIExtract_NE_${UEFITOOL_VER}_win64.zip ./UEFIExtract/Release/UEFIExtract.exe
7z a ../UEFITool/dist/UEFIFind_NE_${UEFITOOL_VER}_win64.zip ./UEFIFind/Release/UEFIFind.exe
7z a ../UEFITool/dist/UEFITool_NE_${UEFITOOL_VER}_win64.zip ./UEFITool/Release/UEFITool.exe
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: Windows 64-bit builds
path: dist/*.zip
- name: Upload to releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*.zip
tag: ${{ github.ref }}
file_glob: true
# Build Tests
build_test_linux_meson:
name: Meson build system test (shared Qt 5)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Get Deps
run: |
sudo apt update
sudo apt-get install -qq cmake meson zlib1g-dev qtbase5-dev
- name: Configure build
run: mkdir build-meson && meson ./build-meson
- name: Build everything
run: ninja -C build-meson
build_test_windows_mingw:
name: MinGW compiler test (shared Qt 6.5.0)
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '6.5.0'
host: 'windows'
target: 'desktop'
arch: 'win64_mingw'
- name: Build everything
run: |
cmake -G "MinGW Makefiles" -B build .
cmake --build build --parallel
build_test_linux_fuzzer:
name: Fuzzer build test (Clang, Linux x64)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure everything
working-directory: ${{runner.workspace}}/build
run: CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake ../UEFITool/fuzzing
- name: Build everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build .
- name: Create dist directory
run: cmake -E make_directory ${{runner.workspace}}/dist
- name: Archive everything
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
UEFITOOL_VER=$(cat ../UEFITool/version.h | grep PROGRAM_VERSION | cut -d'"' -f2 | sed 's/NE alpha /A/') ; \
zip -qryj ../dist/ffsparser_fuzzer_NE_${UEFITOOL_VER}_x64_linux.zip ./ffsparser_fuzzer
- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: Fuzzer
path: ${{runner.workspace}}/dist/*.zip
# Static Analysis
build_analyze_linux_coverity:
env:
PROJECT_TYPE: TOOL
JOB_TYPE: COVERITY
if: github.repository_owner == 'LongSoft' && github.event_name != 'pull_request'
name: Coverity Static Analysis (shared Qt 6.5.0)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '6.5.0'
host: 'linux'
target: 'desktop'
- name: Create build directory
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure everything
working-directory: ${{runner.workspace}}/build
run: cmake ../UEFITool
- name: Run Coverity
working-directory: ${{runner.workspace}}/build
run: |
src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/coverity/covstrap-linux.sh) && eval "$src" || exit 1
env:
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
COVERITY_SCAN_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
COVERITY_BUILD_COMMAND: cmake --build .
build_analyze_linux_sonarcloud:
if: github.repository_owner == 'LongSoft' && github.event_name != 'pull_request'
name: SonarCloud Static Analysis (shared Qt 6.5.0)
runs-on: ubuntu-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '6.5.0'
host: 'linux'
target: 'desktop'
- name: Install JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Install build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Run build-wrapper
run: |
cmake -B build .
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v4.2.1
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_ROOT_CERT: ${{ secrets.SONAR_ROOT_CERT }}
with:
# Consult https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/ for more information and options
args: >
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"

21
.gitignore vendored
View file

@ -3,6 +3,7 @@
################# #################
moc_*.* moc_*.*
ui_*.* ui_*.*
qrc_*.*
################# #################
## Qt Creator ## Qt Creator
@ -231,3 +232,23 @@ pip-log.txt
############# #############
*.o *.o
Makefile Makefile
uefitool_plugin_import.cpp
UEFITool.app/
UEFITool/XCBuildData
UEFIDump/UEFIDump
UEFIExtract/UEFIExtract
UEFIExtract/guids.csv
UEFIFind/UEFIFind
.qmake.stash
CMakeCache.txt
CMakeFiles
cmake_install.cmake
DerivedData
*.xcodeproj
compile_commands.json
CMakeScripts
UEFITool/qrc_uefitool.cpp
XcodeQT5
XcodeQT6
*.dSYM

7
CMakeLists.txt Normal file
View file

@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(UEFITool_everything)
ADD_SUBDIRECTORY(UEFIExtract)
ADD_SUBDIRECTORY(UEFIFind)
ADD_SUBDIRECTORY(UEFITool)

View file

@ -3,7 +3,7 @@
UEFITool is a viewer and editor of firmware images conforming to UEFI Platform Interface (PI) Specifications. UEFITool is a viewer and editor of firmware images conforming to UEFI Platform Interface (PI) Specifications.
![UEFITool icon](https://raw.githubusercontent.com/LongSoft/UEFITool/new_engine/UEFITool/icons/uefitool_64x64.png "UEFITool icon") ![UEFITool icon](https://raw.githubusercontent.com/LongSoft/UEFITool/new_engine/UEFITool/icons/uefitool_64x64.png "UEFITool icon")
![Coverity badge](https://scan.coverity.com/projects/1812/badge.svg?flat=1 "Coverity badge") ![CI Status](https://github.com/LongSoft/UEFITool/actions/workflows/main.yml/badge.svg?branch=new_engine) [![Scan Status](https://scan.coverity.com/projects/17209/badge.svg?flat=1)](https://scan.coverity.com/projects/17209) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=LongSoft_UEFITool&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=LongSoft_UEFITool)
## Very Brief Introduction to UEFI ## Very Brief Introduction to UEFI
@ -29,28 +29,37 @@ The missing parts are in development and the version with a new engine will be m
There are some other projects that use UEFITool's engine: There are some other projects that use UEFITool's engine:
* UEFIExtract, which uses ffsParser to parse supplied firmware image into a tree structure and dumps the parsed structure recursively on the FS. Jethro Beekman's [tree](https://github.com/jethrogb/uefireverse) utility can be used to work with the extracted tree. * UEFIExtract, which uses ffsParser to parse supplied firmware image into a tree structure and dumps the parsed structure recursively on the FS. Jethro Beekman's [tree](https://github.com/jethrogb/uefireverse) utility can be used to work with the extracted tree.
* UEFIDump, a variation of UEFIExtract that dumps all leaf items into one .dump folder without any hierarchy. This tool is a PoC for non-Qt engine usage. * UEFIFind, which uses ffsParser to find image elements containing a specified pattern. It was developed for [UBU](https://winraid.level1techs.com/t/tool-guide-news-uefi-bios-updater-ubu/30357) project.
* UEFIFind, which uses ffsParser to find image elements containing a specified pattern. It was developed for [UBU](http://www.win-raid.com/t154f16-Tool-Guide-News-quot-UEFI-BIOS-Updater-quot-UBU.html) project.
* [OZMTool](https://github.com/tuxuser/UEFITool/tree/OZM/OZMTool), which uses UEFITool's engine to perform various "hackintosh"-related firmware modifications.
## Alternatives ## Alternatives
Right now there are some alternatives to UEFITool that you could find useful too: Right now there are some alternatives to UEFITool that you could find useful too:
* **[PhoenixTool](http://forums.mydigitallife.info/threads/13194-Tool-to-Insert-Replace-SLIC-in-Phoenix-Insyde-Dell-EFI-BIOSes)** by [AndyP](http://forums.mydigitallife.info/members/39295-andyp). Windows-only freeware GUI application written in C#. Used mostly for SLIC-related modifications, but it not limited to this task. Requires Microsoft .NET 3.5 to work properly. Supports unpacking firmware images from various vendor-specific formats like encrypted HP update files and Dell installers. * **[FMMT](https://github.com/tianocore/edk2/tree/master/BaseTools/Source/Python/FMMT)** by TianoCore. Python-based open source toolset for modifying EDK2-based UEFI firmware images. Does not support any IBV customizations, but is _official_, and lives in EDK2 repository.
* **[Fiano](https://github.com/linuxboot/fiano)** by Google and Facebook. Go-based cross-platform open source toolset for modifying UEFI firmware images.
* **[PhoenixTool](https://forums.mydigitallife.net/threads/tool-to-insert-replace-slic-in-phoenix-insyde-dell-efi-bioses.13194)** by [AndyP](https://forums.mydigitallife.net/members/andyp.39295). Windows-only freeware GUI application written in C#. Used mostly for SLIC-related modifications, but it not limited to this task. Requires Microsoft .NET 3.5 to work properly. Supports unpacking firmware images from various vendor-specific formats like encrypted HP update files and Dell installers.
* **[uefi-firmware-parser](https://github.com/theopolis/uefi-firmware-parser)** by [Teddy Reed](https://github.com/theopolis). Cross-platform open source console application written in Python. Very tinker-friendly due to use of Python. Can be used in scripts to automate firmware patching. * **[uefi-firmware-parser](https://github.com/theopolis/uefi-firmware-parser)** by [Teddy Reed](https://github.com/theopolis). Cross-platform open source console application written in Python. Very tinker-friendly due to use of Python. Can be used in scripts to automate firmware patching.
* **[Chipsec](https://github.com/chipsec/chipsec)** by Intel. Cross-platform partially open source console application written in Python and C. Can be used to test Intel-based platforms for various security-related misconfigurations, but also has NVRAM parser and other components aimed to firmware modification. * **[Chipsec](https://github.com/chipsec/chipsec)** by Intel. Cross-platform partially open source console application written in Python and C. Can be used to test Intel-based platforms for various security-related misconfigurations, but also has NVRAM parser and other components aimed to firmware modification.
* **MMTool** by AMI. Windows-only proprietary application available to AMI clients. Works only with Aptio4- and AptioV-based firmware images, but has some interesting features including OptionROM replacement and microcode update. Must be licensed from AMI.
* **H2OEZE** by Insyde. Windows-only proprietary application available to Insyde clients. Works only with InsydeH2O-based firmware images. Must be licensed from Insyde.
* **SCT BIOS Editor** by Phoenix. Windows-only proprietary application available to Phoenix clients. Works only with Phoenix SCT-based firmware images. Must be licensed from Phoenix.
## Installation ## Installation
You can either use [pre-built binaries for Windows and OSX](https://github.com/LongSoft/UEFITool/releases) or build a binary yourself. You can either use [pre-built binaries](https://github.com/LongSoft/UEFITool/releases) or build a binary yourself.
* To build a binary that uses Qt library (UEFITool, UEFIExtract, UEFIFind) you need a C++ compiler and an instance of Qt4/Qt5 library. Install both of them, get the sources, generate makefiles using qmake (`qmake UEFITool.pro`) and use your system's make command on that generated files (i.e. `nmake release`, `make release` and so on). * To build a binary that uses Qt library (UEFITool) you need a C++ compiler and an instance of [Qt5 or Qt6](https://www.qt.io) library. Install both of them, get the sources, generate makefiles using qmake (`qmake ./UEFITool/uefitool.pro`) and use your system's make command on that generated files (i.e. `nmake release`, `make release` and so on). Qt6-based builds can also use CMAKE as an altearnative build system.
* To build a binary that doesn't use Qt (UEFIDump), you need a C++ compiler and CMAKE utility to generate a makefile for your OS and build environment. Install both of them, get the sources, generate makefiles using cmake (`cmake UEFIDump`) and use your system's make command on that generated files (i.e. `nmake release`, `make release` and so on). * To build a binary that doesn't use Qt (UEFIExtract, UEFIFind), you need a C++ compiler and [CMAKE](https://cmake.org) utility to generate a makefile for your OS and build environment. Install both of them, get the sources, generate makefiles using cmake (`cmake UEFIExtract`) and use your system's make command on that generated files (i.e. `nmake release`, `make release` and so on). Non-Qt builds can also use Meson as an alternative build system.
## Known issues ## Known issues
* Image editing is currently only possible using an outdated and unsupported UEFITool 0.28 (`old_engine` branch) and the tools based on it (`UEFIReplace`, `UEFIPatch`). This is the top priority [issue #67](https://github.com/LongSoft/UEFITool/issues/67), which is being worked on, albeit slowly (due to the amount of coding and testing required to implement it correctly).
* Some vendor-specific firmware update files can be opened incorrectly or can't be opened at all. This includes encrypted HP update files, Dell HDR and EXE files, some InsydeFlash FD files and so on. Enabling support for such files will require massive amount of reverse-engineering which is almost pointless because the updated image can be obtained from BIOS chip where it's already decrypted and unpacked. * Some vendor-specific firmware update files can be opened incorrectly or can't be opened at all. This includes encrypted HP update files, Dell HDR and EXE files, some InsydeFlash FD files and so on. Enabling support for such files will require massive amount of reverse-engineering which is almost pointless because the updated image can be obtained from BIOS chip where it's already decrypted and unpacked.
* Intel Firmware Interface Table (FIT) editing is not supported right now. FIT contains pointers to various image components that must be loaded before executing the first CPU instruction from the BIOS chip. Those components include CPU microcode updates, binaries and settings used by BIOS Guard and Boot Guard technologies and some other stuff. More information on FIT can be obtained [here](http://downloadmirror.intel.com/18931/eng/Intel%20TXT%20LAB%20Handout.pdf). * Intel Firmware Interface Table (FIT) editing is not supported right now. FIT contains pointers to various image components that must be loaded before executing the first CPU instruction from the BIOS chip. Those components include CPU microcode updates, binaries and settings used by BIOS Guard and Boot Guard technologies and some other stuff. More information on FIT can be obtained [here](https://edc.intel.com/content/www/us/en/design/products-and-solutions/software-and-services/firmware-and-bios/firmware-interface-table/firmware-interface-table/).
* Builder code is still not ready, but I'm working hard on it. * Windows builds of `UEFIExtract` and `UEFIFind` might encouter an issue with folder paths being longer than 260 bytes (`MAX_PATH`) on some input files (see [issue #363](https://github.com/LongSoft/UEFITool/issues/363)). This is a [known Windows limitation](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry), that can be fixed by enabling long paths support via Windows Registry and adding a manifest to the executable file that requires such support. `UEFIExtract` has the required manifest additions since version `A67`, and the required registry file is provided by Microsoft on the page linked above, but this workaround is only awailable starting with Windows 10 build 1067.
## Bug repellents
* [Coverity Scan](https://scan.coverity.com/projects/17209) - static analyzer for C, C++, C#, JavaScript, Ruby, or Python code.
* [SonarCloud](https://sonarcloud.io/project/overview?id=LongSoft_UEFITool) - cloud-based source code analysis service.
## GUID Database
Every new release includes an update to the database of known UEFI-related GUIDs build with help of [Linux Vendor Firmware Service](https://fwupd.org).
You can download the up-to-date version of that database using [this link](https://fwupd.org/lvfs/shards/export/csv).

View file

@ -1,48 +0,0 @@
PROJECT(UEFIDump)
SET(PROJECT_SOURCES
uefidump_main.cpp
uefidump.cpp
../common/types.cpp
../common/descriptor.cpp
../common/ffs.cpp
../common/nvram.cpp
../common/ffsparser.cpp
../common/ffsreport.cpp
../common/peimage.cpp
../common/treeitem.cpp
../common/treemodel.cpp
../common/utility.cpp
../common/LZMA/LzmaDecompress.c
../common/LZMA/SDK/C/LzmaDec.c
../common/Tiano/EfiTianoDecompress.c
../common/ustring.cpp
../bstrlib/bstrlib.c
../bstrlib/bstrwrap.cpp
)
SET(PROJECT_HEADERS
uefidump.h
../common/basetypes.h
../common/descriptor.h
../common/gbe.h
../common/me.h
../common/ffs.h
../common/fit.h
../common/nvram.h
../common/ffsparser.h
../common/ffsreport.h
../common/peimage.h
../common/types.h
../common/treeitem.h
../common/treemodel.h
../common/utility.h
../common/LZMA/LzmaDecompress.h
../common/Tiano/EfiTianoDecompress.h
../common/ubytearray.h
../common/ustring.h
../bstrlib/bstrlib.h
../bstrlib/bstrwrap.h
)
ADD_EXECUTABLE(UEFIDump ${PROJECT_SOURCES} ${PROJECT_HEADERS})

View file

@ -1,204 +0,0 @@
/* ffsdumper.cpp
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "uefidump.h"
#include "../common/ffs.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <sys/stat.h>
#ifdef WIN32
#include <direct.h>
bool isExistOnFs(const UString & path) {
struct _stat buf;
return (_stat((const char*)path.toLocal8Bit(), &buf) == 0);
}
bool makeDirectory(const UString & dir) {
return (_mkdir((const char*)dir.toLocal8Bit()) == 0);
}
bool changeDirectory(const UString & dir) {
return (_chdir((const char*)dir.toLocal8Bit()) == 0);
}
#else
#include <unistd.h>
bool isExistOnFs(const UString & path) {
struct stat buf;
return (stat((const char*)path.toLocal8Bit(), &buf) == 0);
}
bool makeDirectory(const UString & dir) {
return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0);
}
bool changeDirectory(const UString & dir) {
return (chdir((const char*)dir.toLocal8Bit()) == 0);
}
#endif
USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, const UString & guid)
{
UString path = UString(inPath) + UString(".dump");
UString reportPath = UString(inPath) + UString(".report.txt");
if (initialized) {
// Check if called with a different buffer as before
if (buffer != currentBuffer) {
// Reinitalize if so
initialized = false;
}
}
if (!initialized) {
// Fill currentBuffer
currentBuffer = buffer;
// Parse FFS structure
USTATUS result = ffsParser.parse(buffer);
if (result)
return result;
// Show ffsParser messages
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages();
for (size_t i = 0; i < messages.size(); i++) {
std::cout << messages[i].first << std::endl;
}
// Show FIT table
std::vector<std::vector<UString> > fitTable = ffsParser.getFitTable();
if (fitTable.size()) {
std::cout << "-------------------------------------------------------------------" << std::endl;
std::cout << " Address | Size | Ver | CS | Type " << std::endl;
std::cout << "-------------------------------------------------------------------" << std::endl;
for (size_t i = 0; i < fitTable.size(); i++) {
std::cout << (const char*)fitTable[i][0].toLocal8Bit() << " | "
<< (const char*)fitTable[i][1].toLocal8Bit() << " | "
<< (const char*)fitTable[i][2].toLocal8Bit() << " | "
<< (const char*)fitTable[i][3].toLocal8Bit() << " | "
<< (const char*)fitTable[i][4].toLocal8Bit() << std::endl;
}
}
// Create ffsReport
FfsReport ffsReport(&model);
std::vector<UString> report = ffsReport.generate();
if (report.size()) {
std::ofstream ofs;
ofs.open((const char*)reportPath, std::ofstream::out);
for (size_t i = 0; i < report.size(); i++) {
ofs << (const char*)report[i].toLocal8Bit() << std::endl;
}
ofs.close();
}
initialized = true;
}
// Check for dump directory existence
if (isExistOnFs(path))
return U_DIR_ALREADY_EXIST;
// Create dump directory and cd to it
if (!makeDirectory(path))
return U_DIR_CREATE;
if (!changeDirectory(path))
return U_DIR_CHANGE;
dumped = false;
UINT8 result = recursiveDump(model.index(0,0));
if (result)
return result;
else if (!dumped)
return U_ITEM_NOT_FOUND;
return U_SUCCESS;
}
USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
{
if (!index.isValid())
return U_INVALID_PARAMETER;
//UByteArray itemHeader = model.header(index);
//UByteArray fileHeader = model.header(model.findParentOfType(index, Types::File));
//if (guid.length() == 0 ||
// (itemHeader.size() >= sizeof (EFI_GUID) && guidToUString(*(const EFI_GUID*)itemHeader.constData()) == guid) ||
// (fileHeader.size() >= sizeof(EFI_GUID) && guidToUString(*(const EFI_GUID*)fileHeader.constData()) == guid)) {
// Construct file name
UString orgName = uniqueItemName(index);
UString name = orgName;
bool nameFound = false;
for (int i = 1; i < 1000; ++i) {
if (!isExistOnFs(name + UString("_info.txt"))) {
nameFound = true;
break;
}
name = orgName + UString("_") + usprintf("%03d", i);
}
if (!nameFound)
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
// Add header and body only for leaf sections
if (model.rowCount(index) == 0) {
// Header
UByteArray data = model.header(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_header.bin");
file.open((const char*)str, std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}
// Body
data = model.body(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_body.bin");
file.open((const char*)str, std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}
}
// Info
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
if (model.text(index).length() > 0)
info += "Text: " + model.text(index) + "\n";
info += model.info(index) + "\n";
std::ofstream file;
UString str = name + UString("_info.txt");
file.open((const char*)str, std::ios::out);
file.write((const char*)info, info.length());
file.close();
dumped = true;
//}
// Process child items
UINT8 result;
for (int i = 0; i < model.rowCount(index); i++) {
result = recursiveDump(index.child(i, 0));
if (result)
return result;
}
return U_SUCCESS;
}

View file

@ -1,35 +0,0 @@
/* uefidump_main.cpp
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include <iostream>
#include <fstream>
#include "uefidump.h"
int main(int argc, char *argv[])
{
if (argc > 1) {
std::ifstream inputFile;
inputFile.open(argv[1], std::ios::in | std::ios::binary);
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
(std::istreambuf_iterator<char>()));
inputFile.close();
UEFIDumper uefidumper;
return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS);
}
std::cout << "UEFIDump 0.1.1" << std::endl << std::endl
<< "Usage: UEFIDump imagefile" << std::endl;
return 0;
}

View file

@ -0,0 +1,92 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(UEFIExtract)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(PROJECT_SOURCES
uefiextract_main.cpp
ffsdumper.cpp
uefidump.cpp
../common/guiddatabase.cpp
../common/types.cpp
../common/filesystem.cpp
../common/descriptor.cpp
../common/ffs.cpp
../common/nvram.cpp
../common/nvramparser.cpp
../common/meparser.cpp
../common/ffsparser.cpp
../common/fitparser.cpp
../common/ffsreport.cpp
../common/peimage.cpp
../common/treeitem.cpp
../common/treemodel.cpp
../common/utility.cpp
../common/LZMA/LzmaDecompress.c
../common/LZMA/SDK/C/Bra.c
../common/LZMA/SDK/C/Bra86.c
../common/LZMA/SDK/C/CpuArch.c
../common/LZMA/SDK/C/LzmaDec.c
../common/Tiano/EfiTianoDecompress.c
../common/ustring.cpp
../common/bstrlib/bstrlib.c
../common/bstrlib/bstrwrap.cpp
../common/generated/ami_nvar.cpp
../common/generated/apple_sysf.cpp
../common/generated/dell_dvar.cpp
../common/generated/edk2_vss.cpp
../common/generated/edk2_vss2.cpp
../common/generated/edk2_ftw.cpp
../common/generated/insyde_fdc.cpp
../common/generated/insyde_fdm.cpp
../common/generated/ms_slic_marker.cpp
../common/generated/ms_slic_pubkey.cpp
../common/generated/phoenix_flm.cpp
../common/generated/phoenix_evsa.cpp
../common/generated/intel_acbp_v1.cpp
../common/generated/intel_acbp_v2.cpp
../common/generated/intel_keym_v1.cpp
../common/generated/intel_keym_v2.cpp
../common/generated/intel_acm.cpp
../common/kaitai/kaitaistream.cpp
../common/digest/sha1.c
../common/digest/sha256.c
../common/digest/sha512.c
../common/digest/sm3.c
../common/zlib/adler32.c
../common/zlib/compress.c
../common/zlib/crc32.c
../common/zlib/deflate.c
../common/zlib/gzclose.c
../common/zlib/gzlib.c
../common/zlib/gzread.c
../common/zlib/gzwrite.c
../common/zlib/inflate.c
../common/zlib/infback.c
../common/zlib/inftrees.c
../common/zlib/inffast.c
../common/zlib/trees.c
../common/zlib/uncompr.c
../common/zlib/zutil.c
)
ADD_DEFINITIONS(
-DU_ENABLE_NVRAM_PARSING_SUPPORT
-DU_ENABLE_ME_PARSING_SUPPORT
-DU_ENABLE_FIT_PARSING_SUPPORT
-DU_ENABLE_GUID_DATABASE_SUPPORT
)
ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} uefiextract.manifest)
IF(UNIX)
SET_TARGET_PROPERTIES(UEFIExtract PROPERTIES OUTPUT_NAME uefiextract)
ENDIF()
INSTALL(
TARGETS UEFIExtract
RUNTIME DESTINATION bin
)

View file

@ -13,81 +13,219 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsdumper.h" #include "ffsdumper.h"
USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid) #include <fstream>
USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
{ {
dumped = false; dumped = false;
UINT8 result = recursiveDump(root, path, dumpAll, guid); counterHeader = counterBody = counterRaw = counterInfo = 0;
if (result) fileList.clear();
if (changeDirectory(path)) {
printf("Directory \"%s\" already exists.\n", (const char*)path.toLocal8Bit());
return U_DIR_ALREADY_EXIST;
}
currentPath = path;
USTATUS result = recursiveDump(root, path, dumpMode, sectionType, guid);
if (result) {
printf("Error %zu returned from recursiveDump (directory \"%s\").\n", result, (const char*)path.toLocal8Bit());
return result; return result;
else if (!dumped) } else if (!dumped) {
if (removeDirectory(path)) {
printf("Removed directory \"%s\" since nothing was dumped.\n", (const char*)path.toLocal8Bit());
}
return U_ITEM_NOT_FOUND; return U_ITEM_NOT_FOUND;
}
return U_SUCCESS; return U_SUCCESS;
} }
USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const bool dumpAll, const QString & guid) USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
{ {
if (!index.isValid()) if (!index.isValid())
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
QDir dir;
if (guid.isEmpty() || if (guid.isEmpty() ||
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid || (model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID &&
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) { guidToUString(readUnaligned((const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER)))) == guid) ||
guidToUString(readUnaligned((const EFI_GUID*)model->header(index).constData())) == guid ||
guidToUString(readUnaligned((const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData())) == guid) {
if (dir.cd(path)) if (!changeDirectory(path) && !makeDirectory(path)) {
return U_DIR_ALREADY_EXIST; printf("Cannot use directory \"%s\" (recursiveDump part 1).\n", (const char*)path.toLocal8Bit());
if (!dir.mkpath(path))
return U_DIR_CREATE; return U_DIR_CREATE;
QFile file;
if (dumpAll || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
if (!model->header(index).isEmpty()) {
file.setFileName(QObject::tr("%1/header.bin").arg(path));
if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN;
file.write(model->header(index));
file.close();
} }
if (!model->body(index).isEmpty()) { if (currentPath != path) {
file.setFileName(QObject::tr("%1/body.bin").arg(path)); counterHeader = counterBody = counterUncData = counterRaw = counterInfo = 0;
if (!file.open(QFile::WriteOnly)) currentPath = path;
return U_FILE_OPEN;
file.write(model->body(index));
file.close();
}
} }
// Always dump info if (fileList.count(index) == 0
QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n") && (dumpMode == DUMP_ALL || model->rowCount(index) == 0)
.arg(itemTypeToUString(model->type(index))) && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
.arg(itemSubtypeToUString(model->type(index), model->subtype(index)))
.arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index))) if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER)
.arg(model->info(index)); && !model->hasEmptyHeader(index)) {
file.setFileName(QObject::tr("%1/info.txt").arg(path)); fileList.insert(index);
if (!file.open(QFile::Text | QFile::WriteOnly))
return U_FILE_OPEN; UString filename;
if (counterHeader == 0)
filename = usprintf("%s/header.bin", path.toLocal8Bit());
else
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
counterHeader++;
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
if (!file) {
printf("Cannot open header \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
const UByteArray &data = model->header(index);
file.write(data.constData(), data.size());
file.write(info.toLatin1());
file.close();
dumped = true; dumped = true;
} }
UINT8 result; if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY)
&& !model->hasEmptyBody(index)) {
fileList.insert(index);
UString filename;
if (counterBody == 0)
filename = usprintf("%s/body.bin", path.toLocal8Bit());
else
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
counterBody++;
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
if (!file) {
printf("Cannot open body \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
const UByteArray &data = model->body(index);
file.write(data.constData(), data.size());
dumped = true;
}
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_UNC_DATA)
&& !model->hasEmptyUncompressedData(index)) {
fileList.insert(index);
UString filename;
if (counterUncData == 0)
filename = usprintf("%s/unc_data.bin", path.toLocal8Bit());
else
filename = usprintf("%s/unc_data_%d.bin", path.toLocal8Bit(), counterUncData);
counterUncData++;
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
if (!file) {
printf("Cannot open uncompressed data \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
const UByteArray &data = model->uncompressedData(index);
file.write(data.constData(), data.size());
dumped = true;
}
if (dumpMode == DUMP_FILE) {
UModelIndex fileIndex = index;
if (model->type(fileIndex) != Types::File) {
fileIndex = model->findParentOfType(index, Types::File);
if (!fileIndex.isValid())
fileIndex = index;
}
// We may select parent file during ffs extraction.
if (fileList.count(fileIndex) == 0) {
fileList.insert(fileIndex);
UString filename;
if (counterRaw == 0)
filename = usprintf("%s/file.ffs", path.toLocal8Bit());
else
filename = usprintf("%s/file_%d.ffs", path.toLocal8Bit(), counterRaw);
counterRaw++;
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
if (!file) {
printf("Cannot open file \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
const UByteArray &headerData = model->header(fileIndex);
const UByteArray &bodyData = model->body(fileIndex);
const UByteArray &tailData = model->tail(fileIndex);
file.write(headerData.constData(), headerData.size());
file.write(bodyData.constData(), bodyData.size());
file.write(tailData.constData(), tailData.size());
dumped = true;
}
}
}
// Always dump info unless explicitly prohibited
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
itemTypeToUString(model->type(index)).toLocal8Bit(),
itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
(model->text(index).isEmpty() ? UString("") :
usprintf("Text: %s\n", model->text(index).toLocal8Bit())).toLocal8Bit(),
model->info(index).toLocal8Bit());
UString filename;
if (counterInfo == 0)
filename = usprintf("%s/info.txt", path.toLocal8Bit());
else
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
counterInfo++;
std::ofstream file(filename.toLocal8Bit());
if (!file) {
printf("Cannot open info \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
file << info.toLocal8Bit();
dumped = true;
}
}
USTATUS result;
for (int i = 0; i < model->rowCount(index); i++) { for (int i = 0; i < model->rowCount(index); i++) {
QModelIndex childIndex = index.child(i, 0); UModelIndex childIndex = index.child(i, 0);
bool useText = FALSE; bool useText = FALSE;
if (model->type(childIndex) != Types::Volume) if (model->type(childIndex) != Types::Volume)
useText = !model->text(childIndex).isEmpty(); useText = !model->text(childIndex).isEmpty();
QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex)); UString childPath = path;
result = recursiveDump(childIndex, childPath, dumpAll, guid); if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT) {
if (result) if (!changeDirectory(path) && !makeDirectory(path)) {
printf("Cannot use directory \"%s\" (recursiveDump part 2).\n", (const char*)path.toLocal8Bit());
return U_DIR_CREATE;
}
UString name = usprintf("%d %s", i, (useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit());
fixFileName (name, false);
childPath = usprintf("%s/%s", path.toLocal8Bit(), name.toLocal8Bit());
}
result = recursiveDump(childIndex, childPath, dumpMode, sectionType, guid);
if (result) {
printf("Error %zu returned from recursiveDump (child directory \"%s\").\n", result, (const char*)childPath.toLocal8Bit());
return result; return result;
} }
}
return U_SUCCESS; return U_SUCCESS;
} }

View file

@ -14,27 +14,42 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef FFSDUMPER_H #ifndef FFSDUMPER_H
#define FFSDUMPER_H #define FFSDUMPER_H
#include <QObject> #include <set>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QModelIndex>
#include "../common/basetypes.h" #include "../common/basetypes.h"
#include "../common/ustring.h"
#include "../common/treemodel.h" #include "../common/treemodel.h"
#include "../common/ffs.h" #include "../common/ffs.h"
#include "../common/filesystem.h"
#include "../common/utility.h"
class FfsDumper class FfsDumper
{ {
public: public:
explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false) {} enum DumpMode {
DUMP_CURRENT,
DUMP_ALL,
DUMP_BODY,
DUMP_UNC_DATA,
DUMP_HEADER,
DUMP_INFO,
DUMP_FILE
};
static const UINT8 IgnoreSectionType = 0xFF;
explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false),
counterHeader(0), counterBody(0), counterUncData(0), counterRaw(0), counterInfo(0) {}
~FfsDumper() {}; ~FfsDumper() {};
USTATUS dump(const QModelIndex & root, const QString & path, const bool dumpAll = false, const QString & guid = QString()); USTATUS dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const UString & guid = UString());
private: private:
USTATUS recursiveDump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid); USTATUS recursiveDump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid);
TreeModel* model; TreeModel* model;
UString currentPath;
bool dumped; bool dumped;
int counterHeader, counterBody, counterUncData, counterRaw, counterInfo;
std::set<UModelIndex> fileList;
}; };
#endif // FFSDUMPER_H #endif // FFSDUMPER_H

17
UEFIExtract/meson.build Normal file
View file

@ -0,0 +1,17 @@
executable(
'UEFIExtract',
sources: [
'uefiextract_main.cpp',
'ffsdumper.cpp',
'uefidump.cpp',
],
link_with: [
lzma,
bstrlib,
uefitoolcommon,
],
dependencies: [
zlib,
],
install: true,
)

151
UEFIExtract/uefidump.cpp Normal file
View file

@ -0,0 +1,151 @@
/* ffsdumper.cpp
Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "uefidump.h"
#include "../common/ffs.h"
#include "../common/utility.h"
#include "../common/filesystem.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, const UString & guid)
{
UString path = UString(inPath) + UString(".dump");
UString reportPath = UString(inPath) + UString(".report.txt");
if (initialized) {
// Check if called with a different buffer as before
if (buffer != currentBuffer) {
// Reinitalize if so
initialized = false;
}
}
if (!initialized) {
// Fill currentBuffer
currentBuffer = buffer;
// Parse FFS structure
USTATUS result = ffsParser.parse(buffer);
if (result)
return result;
ffsParser.outputInfo();
// Create ffsReport
FfsReport ffsReport(&model);
std::vector<UString> report = ffsReport.generate();
if (report.size()) {
std::ofstream ofs;
ofs.open(reportPath, std::ofstream::out);
for (size_t i = 0; i < report.size(); i++) {
ofs << report[i].toLocal8Bit() << std::endl;
}
ofs.close();
}
initialized = true;
}
// Check for dump directory existence
if (isExistOnFs(path))
return U_DIR_ALREADY_EXIST;
// Create dump directory and cd to it
if (!makeDirectory(path))
return U_DIR_CREATE;
if (!changeDirectory(path))
return U_DIR_CHANGE;
dumped = false;
USTATUS result = recursiveDump(model.index(0,0));
if (result)
return result;
else if (!dumped)
return U_ITEM_NOT_FOUND;
return U_SUCCESS;
}
USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
{
if (!index.isValid())
return U_INVALID_PARAMETER;
// Construct file name
UString orgName = uniqueItemName(index);
UString name = orgName;
bool nameFound = false;
for (int i = 1; i < 1000; ++i) {
if (!isExistOnFs(name + UString("_info.txt"))) {
nameFound = true;
break;
}
name = orgName + UString("_") + usprintf("%03d", i);
}
if (!nameFound) {
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
}
// Add header and body only for leaf sections
if (model.rowCount(index) == 0) {
// Header
UByteArray data = model.header(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_header.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}
// Body
data = model.body(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_body.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}
}
// Info
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
if (model.text(index).length() > 0)
info += "Text: " + model.text(index) + "\n";
info += model.info(index) + "\n";
std::ofstream file;
UString str = name + UString("_info.txt");
file.open(str.toLocal8Bit(), std::ios::out);
file.write(info.toLocal8Bit(), info.length());
file.close();
dumped = true;
// Process child items
USTATUS result;
for (int i = 0; i < model.rowCount(index); i++) {
result = recursiveDump(index.child(i, 0));
if (result)
return result;
}
return U_SUCCESS;
}

View file

@ -1,6 +1,6 @@
/* uefidump.h /* uefidump.h
Copyright (c) 2016, Nikolaj Schlej. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at

View file

@ -0,0 +1,8 @@
<assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv1:assemblyIdentity type='win32' name='me.coderush.UEFIExtract' version='1.0.0.0' />
<asmv3:application>
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View file

@ -1,46 +0,0 @@
QT += core
QT -= gui
TARGET = UEFIExtract
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += \
uefiextract_main.cpp \
ffsdumper.cpp \
../common/types.cpp \
../common/descriptor.cpp \
../common/ffs.cpp \
../common/nvram.cpp \
../common/ffsparser.cpp \
../common/ffsreport.cpp \
../common/peimage.cpp \
../common/treeitem.cpp \
../common/treemodel.cpp \
../common/utility.cpp \
../common/LZMA/LzmaDecompress.c \
../common/LZMA/SDK/C/LzmaDec.c \
../common/Tiano/EfiTianoDecompress.c \
../common/ustring.cpp
HEADERS += \
ffsdumper.h \
../common/basetypes.h \
../common/descriptor.h \
../common/gbe.h \
../common/me.h \
../common/ffs.h \
../common/nvram.h \
../common/ffsparser.h \
../common/ffsreport.h \
../common/peimage.h \
../common/types.h \
../common/treeitem.h \
../common/treemodel.h \
../common/utility.h \
../common/LZMA/LzmaDecompress.h \
../common/Tiano/EfiTianoDecompress.h \
../common/ubytearray.h \
../common/ustring.h

View file

@ -1,5 +1,5 @@
/* uefiextract_main.cpp /* uefiextract_main.cpp
Copyright (c) 2016, Nikolaj Schlej. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -7,125 +7,213 @@ http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include <QCoreApplication>
#include <QString>
#include <QFileInfo>
#include <iostream> #include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include "../version.h"
#include "../common/basetypes.h"
#include "../common/ustring.h"
#include "../common/filesystem.h"
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffsreport.h" #include "../common/ffsreport.h"
#include "../common/guiddatabase.h"
#include "ffsdumper.h" #include "ffsdumper.h"
#include "uefidump.h"
enum ReadType {
READ_INPUT,
READ_OUTPUT,
READ_MODE,
READ_SECTION
};
void print_usage()
{
std::cout << "UEFIExtract " PROGRAM_VERSION << std::endl
<< "Usage: UEFIExtract {-h | --help | -v | --version} - show help and/or version information." << std::endl
<< " UEFIExtract imagefile - generate report and GUID database, then dump only leaf tree items into .dump folder." << std::endl
<< " UEFIExtract imagefile all - generate report and GUID database, then dump all tree items into .dump folder." << std::endl
<< " UEFIExtract imagefile unpack - generate report, then dump all tree items into a single .dump folder (legacy UEFIDump compatibility mode)." << std::endl
<< " UEFIExtract imagefile dump - only generate dump, no report or GUID database needed." << std::endl
<< " UEFIExtract imagefile report - only generate report, no dump or GUID database needed." << std::endl
<< " UEFIExtract imagefile guids - only generate GUID database, no dump or report needed." << std::endl
<< " UEFIExtract imagefile GUID_1 ... [ -o FILE_1 ... ] [ -m MODE_1 ... ] [ -t TYPE_1 ... ] -" << std::endl
<< " Dump only FFS file(s) with specific GUID(s), without report or GUID database." << std::endl
<< " Type is section type or FF to ignore. Mode is one of: all, body, unc_data, header, info, file." << std::endl
<< " Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise." << std::endl;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); initGuidDatabase("guids.csv");
a.setOrganizationName("CodeRush");
a.setOrganizationDomain("coderush.me");
a.setApplicationName("UEFIExtract");
if (a.arguments().length() > 32) { if (argc <= 1) {
std::cout << "Too many arguments" << std::endl; print_usage();
return 1; return 1;
} }
if (a.arguments().length() > 1) { // Help and version
if (argc == 2) {
UString arg = UString(argv[1]);
if (arg == UString("-h") || arg == UString("--help")) {
print_usage();
return 0;
}
else if (arg == UString("-v") || arg == UString("--version")) {
std::cout << PROGRAM_VERSION << std::endl;
return 0;
}
}
// Check that input file exists // Check that input file exists
QString path = a.arguments().at(1); USTATUS result;
QFileInfo fileInfo(path); UByteArray buffer;
if (!fileInfo.exists()) UString path = getAbsPath(argv[1]);
if (false == readFileIntoBuffer(path, buffer))
return U_FILE_OPEN; return U_FILE_OPEN;
// Open the input file // Hack to support legacy UEFIDump mode
QFile inputFile; if (argc == 3 && !std::strcmp(argv[2], "unpack")) {
inputFile.setFileName(path); UEFIDumper uefidumper;
if (!inputFile.open(QFile::ReadOnly)) return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS);
return U_FILE_OPEN; }
// Read and close the file
QByteArray buffer = inputFile.readAll();
inputFile.close();
// Create model and ffsParser // Create model and ffsParser
TreeModel model; TreeModel model;
FfsParser ffsParser(&model); FfsParser ffsParser(&model);
// Parse input buffer // Parse input buffer
USTATUS result = ffsParser.parse(buffer); result = ffsParser.parse(buffer);
if (result) if (result)
return result; return (int)result;
// Show ffsParser's messages
std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
for (size_t i = 0; i < messages.size(); i++) {
std::cout << messages[i].first.toLatin1().constData() << std::endl;
}
// Get last VTF
std::vector<std::vector<QString> > fitTable = ffsParser.getFitTable();
if (fitTable.size()) {
std::cout << "-------------------------------------------------------------------" << std::endl;
std::cout << " Address | Size | Ver | CS | Type " << std::endl;
std::cout << "-------------------------------------------------------------------" << std::endl;
for (size_t i = 0; i < fitTable.size(); i++) {
std::cout << fitTable[i][0].toLatin1().constData() << " | "
<< fitTable[i][1].toLatin1().constData() << " | "
<< fitTable[i][2].toLatin1().constData() << " | "
<< fitTable[i][3].toLatin1().constData() << " | "
<< fitTable[i][4].toLatin1().constData() << std::endl;
}
}
ffsParser.outputInfo();
// Create ffsDumper // Create ffsDumper
FfsDumper ffsDumper(&model); FfsDumper ffsDumper(&model);
// Dump only leaf elements, no report // Dump only leaf elements, no report or GUID database
if (a.arguments().length() == 3 && a.arguments().at(2) == QString("dump")) { if (argc == 3 && !std::strcmp(argv[2], "dump")) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS); return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
} }
else if (a.arguments().length() > 3 || // Dump named GUIDs found in the image, no dump or report
(a.arguments().length() == 3 && a.arguments().at(2) != QString("all") && a.arguments().at(2) != QString("report"))) { // Dump specific files, without report else if (argc == 3 && !std::strcmp(argv[2], "guids")) {
UINT32 returned = 0; GuidDatabase db = guidDatabaseFromTreeRecursive(&model, model.index(0, 0));
for (int i = 2; i < a.arguments().length(); i++) { if (!db.empty()) {
result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true, a.arguments().at(i)); return (int)guidDatabaseExportToFile(path + UString(".guids.csv"), db);
if (result)
returned |= (1 << (i - 1));
} }
return returned;
} }
// Generate report, no dump or GUID database
// Create ffsReport else if (argc == 3 && !std::strcmp(argv[2], "report")) {
FfsReport ffsReport(&model); FfsReport ffsReport(&model);
std::vector<QString> report = ffsReport.generate(); std::vector<UString> report = ffsReport.generate();
if (report.size()) { if (report.size()) {
QFile file; std::ofstream file;
file.setFileName(fileInfo.fileName().append(".report.txt")); file.open((path + UString(".report.txt")).toLocal8Bit());
if (file.open(QFile::Text | QFile::WriteOnly)) { for (size_t i = 0; i < report.size(); i++)
for (size_t i = 0; i < report.size(); i++) { file << report[i].toLocal8Bit() << '\n';
file.write(report[i].toLatin1().append('\n'));
}
file.close();
}
}
// Dump all non-leaf elements, with report, default
if (a.arguments().length() == 2) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
}
else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("all")) { // Dump every elementm with report
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true) != U_SUCCESS);
}
else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("report")) { // Skip dumping
return 0; return 0;
} }
return 1;
} }
// Either default or all mode
else if (argc == 2 || (argc == 3 && !std::strcmp(argv[2], "all"))) {
// Generate report
FfsReport ffsReport(&model);
std::vector<UString> report = ffsReport.generate();
if (report.size()) {
std::ofstream file;
file.open((path + UString(".report.txt")).toLocal8Bit());
for (size_t i = 0; i < report.size(); i++)
file << report[i].toLocal8Bit() << '\n';
}
// Create GUID database
GuidDatabase db = guidDatabaseFromTreeRecursive(&model, model.index(0, 0));
if (!db.empty()) {
guidDatabaseExportToFile(path + UString(".guids.csv"), db);
}
// Dump all non-leaf elements, with report and GUID database, default
if (argc == 2) {
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
}
else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every element with report and GUID database
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
}
}
// Dump specific files, without report or GUID database
else {
std::vector<UString> inputs, outputs;
std::vector<FfsDumper::DumpMode> modes;
std::vector<UINT8> sectionTypes;
ReadType readType = READ_INPUT;
for (int i = 2; i < argc; i++) {
const char *arg = argv[i];
if (!std::strcmp(arg, "-i")) {
readType = READ_INPUT;
continue;
} else if (!std::strcmp(arg, "-o")) {
readType = READ_OUTPUT;
continue;
} else if (!std::strcmp(arg, "-m")) {
readType = READ_MODE;
continue;
} else if (!std::strcmp(arg, "-t")) {
readType = READ_SECTION;
continue;
}
if (readType == READ_INPUT) {
inputs.push_back(arg);
} else if (readType == READ_OUTPUT) {
outputs.push_back(getAbsPath(arg));
} else if (readType == READ_MODE) {
if (!std::strcmp(arg, "all"))
modes.push_back(FfsDumper::DUMP_ALL);
else if (!std::strcmp(arg, "body"))
modes.push_back(FfsDumper::DUMP_BODY);
else if (!std::strcmp(arg, "unc_data"))
modes.push_back(FfsDumper::DUMP_UNC_DATA);
else if (!std::strcmp(arg, "header"))
modes.push_back(FfsDumper::DUMP_HEADER);
else if (!std::strcmp(arg, "info"))
modes.push_back(FfsDumper::DUMP_INFO);
else if (!std::strcmp(arg, "file"))
modes.push_back(FfsDumper::DUMP_FILE);
else
return U_INVALID_PARAMETER;
} else if (readType == READ_SECTION) {
char *converted = const_cast<char *>(arg);
UINT8 sectionType = (UINT8)std::strtol(arg, &converted, 16);
if (converted == arg)
return U_INVALID_PARAMETER;
sectionTypes.push_back(sectionType);
}
}
if (inputs.empty() || (!outputs.empty() && inputs.size() != outputs.size()) ||
(!modes.empty() && inputs.size() != modes.size()) ||
(!sectionTypes.empty() && inputs.size() != sectionTypes.size()))
return U_INVALID_PARAMETER;
USTATUS lastError = U_SUCCESS;
for (size_t i = 0; i < inputs.size(); i++) {
UString outPath = outputs.empty() ? path + UString(".dump") : outputs[i];
FfsDumper::DumpMode mode = modes.empty() ? FfsDumper::DUMP_ALL : modes[i];
UINT8 type = sectionTypes.empty() ? FfsDumper::IgnoreSectionType : sectionTypes[i];
result = ffsDumper.dump(model.index(0, 0), outPath, mode, type, inputs[i]);
if (result) {
std::cout << "Guid " << inputs[i].toLocal8Bit() << " failed with " << result << " code!" << std::endl;
lastError = result;
}
}
return (int)lastError;
}
// If parameters are different, show version and usage information // If parameters are different, show version and usage information
std::cout << "UEFIExtract 0.13.0" << std::endl << std::endl print_usage();
<< "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder." << std::endl
<< " UEFIExtract imagefile all - generate report and dump all tree items." << std::endl
<< " UEFIExtract imagefile dump - only generate dump, no report needed." << std::endl
<< " UEFIExtract imagefile report - only generate report, no dump needed." << std::endl
<< " UEFIExtract imagefile GUID_1 GUID_2 ... GUID_31 - dump only FFS file(s) with specific GUID(s), without report." << std::endl
<< "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise." << std::endl;
return 1; return 1;
} }

82
UEFIFind/CMakeLists.txt Normal file
View file

@ -0,0 +1,82 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(UEFIFind)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(PROJECT_SOURCES
uefifind_main.cpp
uefifind.cpp
../common/guiddatabase.cpp
../common/types.cpp
../common/filesystem.cpp
../common/descriptor.cpp
../common/ffs.cpp
../common/nvram.cpp
../common/nvramparser.cpp
../common/ffsparser.cpp
../common/fitparser.cpp
../common/peimage.cpp
../common/treeitem.cpp
../common/treemodel.cpp
../common/utility.cpp
../common/LZMA/LzmaDecompress.c
../common/LZMA/SDK/C/Bra.c
../common/LZMA/SDK/C/Bra86.c
../common/LZMA/SDK/C/CpuArch.c
../common/LZMA/SDK/C/LzmaDec.c
../common/Tiano/EfiTianoDecompress.c
../common/ustring.cpp
../common/bstrlib/bstrlib.c
../common/bstrlib/bstrwrap.cpp
../common/generated/ami_nvar.cpp
../common/generated/apple_sysf.cpp
../common/generated/dell_dvar.cpp
../common/generated/edk2_vss.cpp
../common/generated/edk2_vss2.cpp
../common/generated/edk2_ftw.cpp
../common/generated/insyde_fdc.cpp
../common/generated/insyde_fdm.cpp
../common/generated/ms_slic_marker.cpp
../common/generated/ms_slic_pubkey.cpp
../common/generated/phoenix_flm.cpp
../common/generated/phoenix_evsa.cpp
../common/generated/intel_acbp_v1.cpp
../common/generated/intel_acbp_v2.cpp
../common/generated/intel_keym_v1.cpp
../common/generated/intel_keym_v2.cpp
../common/generated/intel_acm.cpp
../common/kaitai/kaitaistream.cpp
../common/digest/sha1.c
../common/digest/sha256.c
../common/digest/sha512.c
../common/digest/sm3.c
../common/zlib/adler32.c
../common/zlib/compress.c
../common/zlib/crc32.c
../common/zlib/deflate.c
../common/zlib/gzclose.c
../common/zlib/gzlib.c
../common/zlib/gzread.c
../common/zlib/gzwrite.c
../common/zlib/inflate.c
../common/zlib/infback.c
../common/zlib/inftrees.c
../common/zlib/inffast.c
../common/zlib/trees.c
../common/zlib/uncompr.c
../common/zlib/zutil.c
)
ADD_EXECUTABLE(UEFIFind ${PROJECT_SOURCES} uefifind.manifest)
IF(UNIX)
SET_TARGET_PROPERTIES(UEFIFind PROPERTIES OUTPUT_NAME uefifind)
ENDIF()
INSTALL(
TARGETS UEFIFind
RUNTIME DESTINATION bin
)

16
UEFIFind/meson.build Normal file
View file

@ -0,0 +1,16 @@
executable(
'UEFIFind',
sources: [
'uefifind_main.cpp',
'uefifind.cpp',
],
link_with: [
lzma,
bstrlib,
uefitoolcommon,
],
dependencies: [
zlib,
],
install: true,
)

View file

@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include "uefifind.h" #include "uefifind.h"
#include <fstream>
#include <set>
UEFIFind::UEFIFind() UEFIFind::UEFIFind()
{ {
@ -27,25 +30,13 @@ UEFIFind::~UEFIFind()
model = NULL; model = NULL;
} }
USTATUS UEFIFind::init(const QString & path) USTATUS UEFIFind::init(const UString & path)
{ {
USTATUS result; UByteArray buffer;
if (false == readFileIntoBuffer(path, buffer))
fileInfo = QFileInfo(path);
if (!fileInfo.exists())
return U_FILE_OPEN; return U_FILE_OPEN;
QFile inputFile; USTATUS result = ffsParser->parse(buffer);
inputFile.setFileName(path);
if (!inputFile.open(QFile::ReadOnly))
return U_FILE_OPEN;
QByteArray buffer = inputFile.readAll();
inputFile.close();
result = ffsParser->parse(buffer);
if (result) if (result)
return result; return result;
@ -53,10 +44,78 @@ USTATUS UEFIFind::init(const QString & path)
return U_SUCCESS; return U_SUCCESS;
} }
USTATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result) USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files)
{ {
QModelIndex root = model->index(0, 0); if (!index.isValid())
std::set<std::pair<QModelIndex, QModelIndex> > files; return U_SUCCESS;
if (hexPattern.isEmpty())
return U_INVALID_PARAMETER;
const char *hexPatternRaw = hexPattern.toLocal8Bit();
std::vector<UINT8> pattern, patternMask;
if (!makePattern(hexPatternRaw, pattern, patternMask))
return U_INVALID_PARAMETER;
// Check for "all substrings" pattern
size_t count = 0;
for (size_t i = 0; i < patternMask.size(); i++)
if (patternMask[i] == 0)
count++;
if (count == patternMask.size())
return U_SUCCESS;
bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
findFileRecursive(index.model()->index(i, index.column(), index), hexPattern, mode, files);
}
// TODO: handle a case where an item has both compressed and uncompressed bodies
UByteArray data;
if (hasChildren) {
if (mode == SEARCH_MODE_HEADER)
data = model->header(index);
else if (mode == SEARCH_MODE_ALL)
data = model->header(index) + model->body(index);
}
else {
if (mode == SEARCH_MODE_HEADER)
data = model->header(index);
else if (mode == SEARCH_MODE_BODY)
data = model->body(index);
else
data = model->header(index) + model->body(index);
}
const UINT8 *rawData = reinterpret_cast<const UINT8 *>(data.constData());
INTN offset = findPattern(pattern.data(), patternMask.data(), pattern.size(), rawData, data.size(), 0);
// For patterns that cross header|body boundary, skip patterns entirely located in body, since
// children search above has already found them.
if (hasChildren && mode == SEARCH_MODE_ALL && offset >= model->header(index).size()) {
offset = -1;
}
if (offset >= 0) {
if (model->type(index) != Types::File) {
UModelIndex parentFile = model->findParentOfType(index, Types::File);
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID)
files.insert(std::pair<UModelIndex, UModelIndex>(parentFile, index));
else
files.insert(std::pair<UModelIndex, UModelIndex>(parentFile, UModelIndex()));
}
else {
files.insert(std::pair<UModelIndex, UModelIndex>(index, UModelIndex()));
}
}
return U_SUCCESS;
}
USTATUS UEFIFind::find(const UINT8 mode, const bool count, const UString & hexPattern, UString & result)
{
UModelIndex root = model->index(0, 0);
std::set<std::pair<UModelIndex, UModelIndex> > files;
result.clear(); result.clear();
@ -66,78 +125,24 @@ USTATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPa
if (count) { if (count) {
if (!files.empty()) if (!files.empty())
result.append(QString("%1\n").arg(files.size())); result += usprintf("%lu\n", files.size());
return U_SUCCESS; return U_SUCCESS;
} }
for (std::set<std::pair<QModelIndex, QModelIndex> >::const_iterator citer = files.cbegin(); citer != files.cend(); ++citer) { for (std::set<std::pair<UModelIndex, UModelIndex> >::const_iterator citer = files.begin(); citer != files.end(); ++citer) {
QByteArray data(16, '\x00'); UByteArray data(16, '\x00');
std::pair<QModelIndex, QModelIndex> indexes = *citer; std::pair<UModelIndex, UModelIndex> indexes = *citer;
if (!model->hasEmptyHeader(indexes.first)) if (!model->hasEmptyHeader(indexes.first))
data = model->header(indexes.first).left(16); data = model->header(indexes.first).left(16);
result.append(guidToUString(*(const EFI_GUID*)data.constData())); result += guidToUString(readUnaligned((const EFI_GUID*)data.constData()));
// Special case of freeform subtype GUID files // Special case of freeform subtype GUID files
if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) { if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
data = model->header(indexes.second).left(sizeof(EFI_FREEFORM_SUBTYPE_GUID_SECTION)); data = model->header(indexes.second);
result.append(" ").append(guidToUString(*(const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))); result += UString(" ") + (guidToUString(readUnaligned((const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))));
} }
result.append("\n"); result += UString("\n");
} }
return U_SUCCESS; return U_SUCCESS;
} }
USTATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<QModelIndex, QModelIndex> > & files)
{
if (!index.isValid())
return U_SUCCESS;
if (hexPattern.isEmpty())
return U_INVALID_PARAMETER;
// Check for "all substrings" pattern
if (hexPattern.count('.') == hexPattern.length())
return U_SUCCESS;
bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) {
findFileRecursive(index.child(i, index.column()), hexPattern, mode, files);
}
QByteArray data;
if (hasChildren) {
if (mode == SEARCH_MODE_HEADER || mode == SEARCH_MODE_ALL)
data.append(model->header(index));
}
else {
if (mode == SEARCH_MODE_HEADER)
data.append(model->header(index));
else if (mode == SEARCH_MODE_BODY)
data.append(model->body(index));
else
data.append(model->header(index)).append(model->body(index));
}
QString hexBody = QString(data.toHex());
QRegExp regexp = QRegExp(QString(hexPattern), Qt::CaseInsensitive);
INT32 offset = regexp.indexIn(hexBody);
while (offset >= 0) {
if (offset % 2 == 0) {
if (model->type(index) != Types::File) {
QModelIndex ffs = model->findParentOfType(index, Types::File);
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID)
files.insert(std::pair<QModelIndex, QModelIndex>(ffs, index));
else
files.insert(std::pair<QModelIndex, QModelIndex>(ffs, QModelIndex()));
}
else
files.insert(std::pair<QModelIndex, QModelIndex>(index, QModelIndex()));
break;
}
offset = regexp.indexIn(hexBody, offset + 1);
}
return U_SUCCESS;
}

View file

@ -14,19 +14,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef UEFIFIND_H #ifndef UEFIFIND_H
#define UEFIFIND_H #define UEFIFIND_H
#include <iterator>
#include <set> #include <set>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QDir>
#include <QFileInfo>
#include <QString>
#include <QUuid>
#include "../common/basetypes.h" #include "../common/basetypes.h"
#include "../common/ustring.h"
#include "../common/filesystem.h"
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffs.h" #include "../common/ffs.h"
#include "../common/utility.h"
class UEFIFind class UEFIFind
{ {
@ -34,16 +30,14 @@ public:
explicit UEFIFind(); explicit UEFIFind();
~UEFIFind(); ~UEFIFind();
USTATUS init(const QString & path); USTATUS init(const UString & path);
USTATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result); USTATUS find(const UINT8 mode, const bool count, const UString & hexPattern, UString & result);
private: private:
USTATUS findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<QModelIndex, QModelIndex> > & files); USTATUS findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files);
QString guidToQString(const UINT8* guid);
FfsParser* ffsParser; FfsParser* ffsParser;
TreeModel* model; TreeModel* model;
QFileInfo fileInfo;
bool initDone; bool initDone;
}; };

View file

@ -0,0 +1,8 @@
<assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv1:assemblyIdentity type='win32' name='me.coderush.UEFIFind' version='1.0.0.0' />
<asmv3:application>
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View file

@ -1,42 +0,0 @@
QT += core
QT -= gui
TARGET = UEFIFind
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += uefifind_main.cpp \
uefifind.cpp \
../common/types.cpp \
../common/descriptor.cpp \
../common/ffs.cpp \
../common/nvram.cpp \
../common/ffsparser.cpp \
../common/peimage.cpp \
../common/treeitem.cpp \
../common/treemodel.cpp \
../common/utility.cpp \
../common/LZMA/LzmaDecompress.c \
../common/LZMA/SDK/C/LzmaDec.c \
../common/Tiano/EfiTianoDecompress.c \
../common/ustring.cpp
HEADERS += uefifind.h \
../common/basetypes.h \
../common/descriptor.h \
../common/gbe.h \
../common/me.h \
../common/ffs.h \
../common/nvram.h \
../common/ffsparser.h \
../common/peimage.h \
../common/types.h \
../common/treeitem.h \
../common/treemodel.h \
../common/utility.h \
../common/LZMA/LzmaDecompress.h \
../common/Tiano/EfiTianoDecompress.h \
../common/ustring.h \
../common/ubytearray.h

View file

@ -1,6 +1,6 @@
/* uefifind_main.cpp /* uefifind_main.cpp
Copyright (c) 2016, Nikolaj Schlej. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -10,49 +10,77 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include <QCoreApplication>
#include <iostream> #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "../version.h"
#include "../common/guiddatabase.h"
#include "uefifind.h" #include "uefifind.h"
void print_usage()
{
std::cout << "UEFIFind " PROGRAM_VERSION << std::endl <<
"Usage: UEFIFind {-h | --help | -v | -version}" << std::endl <<
" UEFIFind imagefile {header | body | all} {list | count} pattern" << std::endl <<
" UEFIFind imagefile file patternsfile" << std::endl;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv);
a.setOrganizationName("CodeRush");
a.setOrganizationDomain("coderush.me");
a.setApplicationName("UEFIFind");
UEFIFind w; UEFIFind w;
UINT8 result; USTATUS result;
if (argc == 1) {
print_usage();
return U_SUCCESS;
}
else if (argc == 2) {
UString arg = argv[1];
if (arg == UString("-h") || arg == UString("--help")) {
print_usage();
return U_SUCCESS;
}
else if (arg == UString("-v") || arg == UString("--version")) {
std::cout << PROGRAM_VERSION << std::endl;
return U_SUCCESS;
}
}
else if (argc == 5) {
UString inputArg = argv[1];
UString modeArg = argv[2];
UString subModeArg = argv[3];
UString patternArg = argv[4];
if (a.arguments().length() == 5) {
// Get search mode // Get search mode
UINT8 mode; UINT8 mode;
if (a.arguments().at(1) == QString("header")) if (modeArg == UString("header"))
mode = SEARCH_MODE_HEADER; mode = SEARCH_MODE_HEADER;
else if (a.arguments().at(1) == QString("body")) else if (modeArg == UString("body"))
mode = SEARCH_MODE_BODY; mode = SEARCH_MODE_BODY;
else if (a.arguments().at(1) == QString("all")) else if (modeArg == UString("all"))
mode = SEARCH_MODE_ALL; mode = SEARCH_MODE_ALL;
else else
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
// Get result type // Get result type
bool count; bool count;
if (a.arguments().at(2) == QString("list")) if (subModeArg == UString("list"))
count = false; count = false;
else if (a.arguments().at(2) == QString("count")) else if (subModeArg == UString("count"))
count = true; count = true;
else else
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
// Parse input file // Parse input file
result = w.init(a.arguments().at(4)); result = w.init(inputArg);
if (result) if (result)
return result; return result;
// Go find the supplied pattern // Go find the supplied pattern
QString found; UString found;
result = w.find(mode, count, a.arguments().at(3), found); result = w.find(mode, count, patternArg, found);
if (result) if (result)
return result; return result;
@ -61,82 +89,93 @@ int main(int argc, char *argv[])
return U_ITEM_NOT_FOUND; return U_ITEM_NOT_FOUND;
// Print result // Print result
std::cout << found.toStdString(); std::cout << found.toLocal8Bit();
return U_SUCCESS; return U_SUCCESS;
} }
else if (a.arguments().length() == 4) { else if (argc == 4) {
UString inputArg = argv[1];
UString modeArg = argv[2];
UString patternArg = argv[3];
// Get search mode // Get search mode
if (a.arguments().at(1) != QString("file")) if (modeArg != UString("file"))
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
// Open patterns file // Open patterns file
QFileInfo fileInfo(a.arguments().at(2)); if (!isExistOnFs(patternArg))
if (!fileInfo.exists())
return U_FILE_OPEN; return U_FILE_OPEN;
QFile patternsFile; std::ifstream patternsFile(patternArg.toLocal8Bit());
patternsFile.setFileName(a.arguments().at(2)); if (!patternsFile)
if (!patternsFile.open(QFile::ReadOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
// Parse input file // Parse input file
result = w.init(a.arguments().at(3)); result = w.init(inputArg);
if (result) if (result)
return result; return result;
// Perform searches // Perform searches
bool somethingFound = false; bool somethingFound = false;
while (!patternsFile.atEnd()) { while (!patternsFile.eof()) {
QByteArray line = patternsFile.readLine(); std::string line;
std::getline(patternsFile, line);
// Use sharp symbol as commentary // Use sharp symbol as commentary
if (line.count() == 0 || line[0] == '#') if (line.size() == 0 || line[0] == '#')
continue; continue;
// Split the read line // Split the read line
QList<QByteArray> list = line.split(' '); std::vector<UString> list;
if (list.count() < 3) { std::string::size_type prev = 0, curr = 0;
std::cout << line.constData() << "skipped, too few arguments" << std::endl << std::endl; while ((curr = line.find(' ', curr)) != std::string::npos) {
std::string substring( line.substr(prev, curr-prev) );
list.push_back(UString(substring.c_str()));
prev = ++curr;
}
list.push_back(UString(line.substr(prev, curr-prev).c_str()));
if (list.size() < 3) {
std::cout << line << std::endl << "skipped, too few arguments" << std::endl << std::endl;
continue; continue;
} }
// Get search mode // Get search mode
UINT8 mode; UINT8 mode;
if (list.at(0) == QString("header")) if (list.at(0) == UString("header"))
mode = SEARCH_MODE_HEADER; mode = SEARCH_MODE_HEADER;
else if (list.at(0) == QString("body")) else if (list.at(0) == UString("body"))
mode = SEARCH_MODE_BODY; mode = SEARCH_MODE_BODY;
else if (list.at(0) == QString("all")) else if (list.at(0) == UString("all"))
mode = SEARCH_MODE_ALL; mode = SEARCH_MODE_ALL;
else { else {
std::cout << line.constData() << "skipped, invalid search mode" << std::endl << std::endl; std::cout << line << std::endl << "skipped, invalid search mode" << std::endl << std::endl;
continue; continue;
} }
// Get result type // Get result type
bool count; bool count;
if (list.at(1) == QString("list")) if (list.at(1) == UString("list"))
count = false; count = false;
else if (list.at(1) == QString("count")) else if (list.at(1) == UString("count"))
count = true; count = true;
else { else {
std::cout << line.constData() << "skipped, invalid result type" << std::endl << std::endl; std::cout << line << std::endl << "skipped, invalid result type" << std::endl << std::endl;
continue; continue;
} }
// Go find the supplied pattern // Go find the supplied pattern
QString found; UString found;
result = w.find(mode, count, list.at(2), found); result = w.find(mode, count, list.at(2), found);
if (result) { if (result) {
std::cout << line.constData() << "skipped, find failed with error " << (UINT32)result << std::endl << std::endl; std::cout << line << std::endl << "skipped, find failed with error " << (UINT32)result << std::endl << std::endl;
continue; continue;
} }
if (found.isEmpty()) { if (found.isEmpty()) {
// Nothing is found // Nothing is found
std::cout << line.constData() << "nothing found" << std::endl << std::endl; std::cout << line << std::endl << "nothing found" << std::endl << std::endl;
} }
else { else {
// Print result // Print result
std::cout << line.constData() << found.toStdString() << std::endl; std::cout << line << std::endl << found.toLocal8Bit() << std::endl;
somethingFound = true; somethingFound = true;
} }
} }
@ -147,11 +186,7 @@ int main(int argc, char *argv[])
return U_SUCCESS; return U_SUCCESS;
} }
else {
std::cout << "UEFIFind 0.10.6" << std::endl << std::endl <<
"Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl <<
" or UEFIFind file patternsfile imagefile" << std::endl;
return U_INVALID_PARAMETER;
}
}
print_usage();
return U_INVALID_PARAMETER;
}

146
UEFITool/CMakeLists.txt Normal file
View file

@ -0,0 +1,146 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(UEFITool LANGUAGES C CXX)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Widgets)
SET(PROJECT_FORMS
uefitool.ui
searchdialog.ui
hexviewdialog.ui
gotobasedialog.ui
gotoaddressdialog.ui
)
SET(PROJECT_HEADERS
uefitool.h
hexspinbox.h
searchdialog.h
hexviewdialog.h
gotobasedialog.h
gotoaddressdialog.h
)
SET(PROJECT_SOURCES
icons/uefitool.icns
uefitool.rc
uefitool_main.cpp
uefitool.cpp
searchdialog.cpp
hexviewdialog.cpp
hexlineedit.cpp
ffsfinder.cpp
hexspinbox.cpp
../common/fitparser.cpp
../common/guiddatabase.cpp
../common/nvram.cpp
../common/nvramparser.cpp
../common/meparser.cpp
../common/ffsops.cpp
../common/types.cpp
../common/descriptor.cpp
../common/ffs.cpp
../common/peimage.cpp
../common/utility.cpp
../common/ffsbuilder.cpp
../common/ffsparser.cpp
../common/ffsreport.cpp
../common/treeitem.cpp
../common/treemodel.cpp
../common/LZMA/LzmaCompress.c
../common/LZMA/LzmaDecompress.c
../common/LZMA/SDK/C/CpuArch.c
../common/LZMA/SDK/C/Bra.c
../common/LZMA/SDK/C/Bra86.c
../common/LZMA/SDK/C/LzFind.c
../common/LZMA/SDK/C/LzmaDec.c
../common/LZMA/SDK/C/LzmaEnc.c
../common/Tiano/EfiTianoDecompress.c
../common/Tiano/EfiTianoCompress.c
../common/Tiano/EfiTianoCompressLegacy.c
../common/ustring.cpp
../common/digest/sha1.c
../common/digest/sha256.c
../common/digest/sha512.c
../common/digest/sm3.c
../common/generated/ami_nvar.cpp
../common/generated/apple_sysf.cpp
../common/generated/dell_dvar.cpp
../common/generated/edk2_vss.cpp
../common/generated/edk2_vss2.cpp
../common/generated/edk2_ftw.cpp
../common/generated/insyde_fdc.cpp
../common/generated/insyde_fdm.cpp
../common/generated/ms_slic_marker.cpp
../common/generated/ms_slic_pubkey.cpp
../common/generated/phoenix_evsa.cpp
../common/generated/phoenix_flm.cpp
../common/generated/intel_acbp_v1.cpp
../common/generated/intel_acbp_v2.cpp
../common/generated/intel_keym_v1.cpp
../common/generated/intel_keym_v2.cpp
../common/generated/intel_acm.cpp
../common/kaitai/kaitaistream.cpp
../common/zlib/adler32.c
../common/zlib/compress.c
../common/zlib/crc32.c
../common/zlib/deflate.c
../common/zlib/gzclose.c
../common/zlib/gzlib.c
../common/zlib/gzread.c
../common/zlib/gzwrite.c
../common/zlib/inflate.c
../common/zlib/infback.c
../common/zlib/inftrees.c
../common/zlib/inffast.c
../common/zlib/trees.c
../common/zlib/uncompr.c
../common/zlib/zutil.c
)
QT_ADD_RESOURCES(PROJECT_SOURCES
uefitool.qrc
)
ADD_DEFINITIONS(
-DU_ENABLE_NVRAM_PARSING_SUPPORT
-DU_ENABLE_ME_PARSING_SUPPORT
-DU_ENABLE_FIT_PARSING_SUPPORT
-DU_ENABLE_GUID_DATABASE_SUPPORT
)
SET_SOURCE_FILES_PROPERTIES(icons/uefitool.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
ADD_EXECUTABLE(UEFITool ${PROJECT_HEADERS} ${PROJECT_FORMS} ${PROJECT_SOURCES})
TARGET_INCLUDE_DIRECTORIES(UEFITool PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
TARGET_LINK_LIBRARIES(UEFITool PRIVATE Qt6::Widgets)
ADD_SUBDIRECTORY(QHexView)
TARGET_LINK_LIBRARIES(UEFITool PRIVATE QHexView)
SET_TARGET_PROPERTIES(UEFITool PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
AUTOMOC ON
AUTOUIC ON
)
IF(UNIX AND (NOT APPLE) AND (NOT CYGWIN))
SET_TARGET_PROPERTIES(UEFITool PROPERTIES OUTPUT_NAME uefitool)
INSTALL(FILES icons/uefitool_16x16.png DESTINATION share/icons/hicolor/16x16/apps RENAME uefitool.png)
INSTALL(FILES icons/uefitool_32x32.png DESTINATION share/icons/hicolor/32x32/apps RENAME uefitool.png)
INSTALL(FILES icons/uefitool_64x64.png DESTINATION share/icons/hicolor/64x64/apps RENAME uefitool.png)
INSTALL(FILES icons/uefitool_128x128.png DESTINATION share/icons/hicolor/128x128/apps RENAME uefitool.png)
INSTALL(FILES icons/uefitool_256x256.png DESTINATION share/icons/hicolor/256x256/apps RENAME uefitool.png)
INSTALL(FILES icons/uefitool_512x512.png DESTINATION share/icons/hicolor/512x512/apps RENAME uefitool.png)
INSTALL(FILES uefitool.desktop DESTINATION share/applications)
ENDIF()
INSTALL(TARGETS UEFITool BUNDLE DESTINATION "/Applications" )

33
UEFITool/Info.plist Normal file
View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>None</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>UEFITool</string>
<key>CFBundleGetInfoString</key>
<string>UEFITool NE</string>
<key>CFBundleIconFile</key>
<string>uefitool</string>
<key>CFBundleIdentifier</key>
<string>me.coderush.UEFITool</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View file

@ -0,0 +1,91 @@
cmake_minimum_required(VERSION 3.13)
project(QHexView)
option(QHEXVIEW_BUILD_EXAMPLE "Build Example Application" OFF)
option(QHEXVIEW_USE_QT5 "Enable Qt5 build" OFF)
option(QHEXVIEW_ENABLE_DIALOGS "BuiltIn dialogs" OFF)
if(QHEXVIEW_USE_QT5)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
else()
find_package(Qt6 COMPONENTS Widgets)
if(NOT Qt6_FOUND)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
endif()
endif()
add_library(${PROJECT_NAME} STATIC)
set_target_properties(${PROJECT_NAME}
PROPERTIES
CXX_STANDARD_REQUIRED YES
CXX_STANDARD 11
AUTOMOC ON
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt::Widgets
)
target_include_directories(${PROJECT_NAME}
PUBLIC
"${PROJECT_SOURCE_DIR}/include"
)
target_sources(${PROJECT_NAME}
PRIVATE
include/QHexView/model/buffer/qdevicebuffer.h
include/QHexView/model/buffer/qhexbuffer.h
include/QHexView/model/buffer/qmappedfilebuffer.h
include/QHexView/model/buffer/qmemorybuffer.h
include/QHexView/model/buffer/qmemoryrefbuffer.h
include/QHexView/model/commands/hexcommand.h
include/QHexView/model/commands/insertcommand.h
include/QHexView/model/commands/removecommand.h
include/QHexView/model/commands/replacecommand.h
include/QHexView/model/commands/replacecommand.h
include/QHexView/model/qhexcursor.h
include/QHexView/model/qhexdelegate.h
include/QHexView/model/qhexdocument.h
include/QHexView/model/qhexmetadata.h
include/QHexView/model/qhexoptions.h
include/QHexView/model/qhexutils.h
include/QHexView/qhexview.h
PRIVATE
src/model/commands/hexcommand.cpp
src/model/commands/insertcommand.cpp
src/model/commands/removecommand.cpp
src/model/commands/replacecommand.cpp
src/model/buffer/qdevicebuffer.cpp
src/model/buffer/qhexbuffer.cpp
src/model/buffer/qmemorybuffer.cpp
src/model/buffer/qmemoryrefbuffer.cpp
src/model/buffer/qmappedfilebuffer.cpp
src/model/qhexdelegate.cpp
src/model/qhexutils.cpp
src/model/qhexcursor.cpp
src/model/qhexmetadata.cpp
src/model/qhexdocument.cpp
src/qhexview.cpp
)
if(QHEXVIEW_ENABLE_DIALOGS)
target_sources(${PROJECT_NAME}
PRIVATE
include/QHexView/dialogs/hexfinddialog.h
src/dialogs/hexfinddialog.cpp
)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
QHEXVIEW_ENABLE_DIALOGS
)
endif()
if(QHEXVIEW_BUILD_EXAMPLE)
add_subdirectory(example)
endif()

20
UEFITool/QHexView/LICENSE Normal file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 Dax89
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,56 @@
#pragma once
#include <QDialog>
#include <QHexView/model/qhexutils.h>
class QRegularExpressionValidator;
class QDoubleValidator;
class QIntValidator;
class QHexView;
class HexFindDialog: public QDialog {
Q_OBJECT
public:
enum class Type { Find, Replace };
public:
explicit HexFindDialog(HexFindDialog::Type type = Type::Find,
QHexView* parent = nullptr);
QHexView* hexView() const;
private Q_SLOTS:
void updateFindOptions(int);
void validateActions();
void replace();
void find();
private:
bool prepareOptions(QString& q, QHexFindMode& mode, QHexFindDirection& fd);
bool validateIntRange(uint v) const;
void checkResult(const QString& q, qint64 offset, QHexFindDirection fd);
void prepareTextMode(QLayout* l);
void prepareHexMode(QLayout* l);
void prepareIntMode(QLayout* l);
void prepareFloatMode(QLayout* l);
private:
QRegularExpressionValidator *m_hexvalidator, *m_hexpvalidator;
QDoubleValidator* m_dblvalidator;
QIntValidator* m_intvalidator;
int m_oldidxbits{-1}, m_oldidxendian{-1};
unsigned int m_findoptions{0};
qint64 m_startoffset{-1};
Type m_type;
private:
static const QString BUTTONBOX;
static const QString CBFINDMODE;
static const QString LEFIND;
static const QString LEREPLACE;
static const QString HLAYOUT;
static const QString GBOPTIONS;
static const QString RBALL;
static const QString RBFORWARD;
static const QString RBBACKWARD;
};

View file

@ -0,0 +1,24 @@
#pragma once
#include <QHexView/model/buffer/qhexbuffer.h>
class QDeviceBuffer: public QHexBuffer {
Q_OBJECT
public:
explicit QDeviceBuffer(QObject* parent = nullptr);
virtual ~QDeviceBuffer();
uchar at(qint64 idx) override;
qint64 length() const override;
void insert(qint64 offset, const QByteArray& data) override;
void replace(qint64 offset, const QByteArray& data) override;
void remove(qint64 offset, int length) override;
QByteArray read(qint64 offset, int length) override;
bool read(QIODevice* device) override;
void write(QIODevice* device) override;
qint64 indexOf(const QByteArray& ba, qint64 from) override;
qint64 lastIndexOf(const QByteArray& ba, qint64 from) override;
protected:
QIODevice* m_device{nullptr};
};

View file

@ -0,0 +1,29 @@
#pragma once
#include <QIODevice>
#include <QObject>
class QHexBuffer: public QObject {
Q_OBJECT
public:
explicit QHexBuffer(QObject* parent = nullptr);
bool isEmpty() const;
public:
virtual uchar at(qint64 idx);
virtual bool accept(qint64 idx) const;
virtual void replace(qint64 offset, const QByteArray& data);
virtual void read(char* data, int size);
virtual void read(const QByteArray& ba);
public:
virtual qint64 length() const = 0;
virtual void insert(qint64 offset, const QByteArray& data) = 0;
virtual void remove(qint64 offset, int length) = 0;
virtual QByteArray read(qint64 offset, int length) = 0;
virtual bool read(QIODevice* iodevice) = 0;
virtual void write(QIODevice* iodevice) = 0;
virtual qint64 indexOf(const QByteArray& ba, qint64 from) = 0;
virtual qint64 lastIndexOf(const QByteArray& ba, qint64 from) = 0;
};

View file

@ -0,0 +1,20 @@
#pragma once
#include <QHexView/model/buffer/qdevicebuffer.h>
class QMappedFileBuffer: public QDeviceBuffer {
public:
explicit QMappedFileBuffer(QObject* parent = nullptr);
virtual ~QMappedFileBuffer();
public:
QByteArray read(qint64 offset, int length) override;
bool read(QIODevice* iodevice) override;
void write(QIODevice* iodevice) override;
private:
void remap();
private:
uchar* m_mappeddata{nullptr};
};

View file

@ -0,0 +1,22 @@
#pragma once
#include <QHexView/model/buffer/qhexbuffer.h>
class QMemoryBuffer: public QHexBuffer {
Q_OBJECT
public:
explicit QMemoryBuffer(QObject* parent = nullptr);
uchar at(qint64 idx) override;
qint64 length() const override;
void insert(qint64 offset, const QByteArray& data) override;
void remove(qint64 offset, int length) override;
QByteArray read(qint64 offset, int length) override;
bool read(QIODevice* device) override;
void write(QIODevice* device) override;
qint64 indexOf(const QByteArray& ba, qint64 from) override;
qint64 lastIndexOf(const QByteArray& ba, qint64 from) override;
private:
QByteArray m_buffer;
};

View file

@ -0,0 +1,12 @@
#pragma once
#include <QHexView/model/buffer/qdevicebuffer.h>
class QMemoryRefBuffer: public QDeviceBuffer {
Q_OBJECT
public:
explicit QMemoryRefBuffer(QObject* parent = nullptr);
bool read(QIODevice* device) override;
void write(QIODevice* device) override;
};

View file

@ -0,0 +1,19 @@
#pragma once
#include <QHexView/model/buffer/qhexbuffer.h>
#include <QUndoCommand>
class QHexDocument;
class HexCommand: public QUndoCommand {
public:
HexCommand(QHexBuffer* buffer, QHexDocument* document,
QUndoCommand* parent = nullptr);
protected:
QHexDocument* m_hexdocument;
QHexBuffer* m_buffer;
qint64 m_offset;
int m_length;
QByteArray m_data;
};

View file

@ -0,0 +1,11 @@
#pragma once
#include <QHexView/model/commands/hexcommand.h>
class InsertCommand: public HexCommand {
public:
InsertCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset,
const QByteArray& data, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
};

View file

@ -0,0 +1,11 @@
#pragma once
#include <QHexView/model/commands/hexcommand.h>
class RemoveCommand: public HexCommand {
public:
RemoveCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset,
int length, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
};

View file

@ -0,0 +1,14 @@
#pragma once
#include <QHexView/model/commands/hexcommand.h>
class ReplaceCommand: public HexCommand {
public:
ReplaceCommand(QHexBuffer* buffer, QHexDocument* document, qint64 offset,
const QByteArray& data, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
private:
QByteArray m_olddata;
};

View file

@ -0,0 +1,73 @@
#pragma once
#include <QHexView/model/qhexoptions.h>
#include <QHexView/model/qhexutils.h>
#include <QObject>
class QHexView;
class QHexCursor: public QObject {
Q_OBJECT
public:
enum class Mode { Overwrite, Insert };
private:
explicit QHexCursor(const QHexOptions* options, QHexView* parent = nullptr);
public:
QHexView* hexView() const;
Mode mode() const;
qint64 line() const;
qint64 column() const;
qint64 offset() const;
qint64 address() const;
quint64 lineAddress() const;
qint64 selectionStartOffset() const;
qint64 selectionEndOffset() const;
qint64 selectionLength() const;
QHexPosition position() const;
QHexPosition selectionStart() const;
QHexPosition selectionEnd() const;
QByteArray selectedBytes() const;
bool hasSelection() const;
bool isSelected(qint64 line, qint64 column) const;
void setMode(Mode m);
void move(qint64 offset);
void move(qint64 line, qint64 column);
void move(QHexPosition pos);
void select(qint64 offset);
void select(qint64 line, qint64 column);
void select(QHexPosition pos);
void selectSize(qint64 length);
qint64 replace(const QVariant& oldvalue, const QVariant& newvalue,
qint64 offset, QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward) const;
qint64 find(const QVariant& value, qint64 offset,
QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward) const;
qint64 positionToOffset(QHexPosition pos) const;
QHexPosition offsetToPosition(qint64 offset) const;
public Q_SLOTS:
void cut(bool hex = false);
void copy(bool hex = false) const;
void paste(bool hex = false);
void selectAll();
void removeSelection();
void clearSelection();
void switchMode();
Q_SIGNALS:
void positionChanged();
void modeChanged();
private:
const QHexOptions* m_options;
Mode m_mode{Mode::Overwrite};
QHexPosition m_position{}, m_selection{};
friend class QHexView;
};

View file

@ -0,0 +1,30 @@
#pragma once
#include <QHexView/model/qhexutils.h>
#include <QObject>
#include <QTextCharFormat>
class QHexView;
class QHexDelegate: public QObject {
Q_OBJECT
public:
explicit QHexDelegate(QObject* parent = nullptr);
virtual ~QHexDelegate() = default;
virtual QString addressHeader(const QHexView* hexview) const;
virtual QString hexHeader(const QHexView* hexview) const;
virtual QString asciiHeader(const QHexView* hexview) const;
virtual void renderAddress(quint64 address, QTextCharFormat& cf,
const QHexView* hexview) const;
virtual void renderHeader(QTextBlockFormat& bf,
const QHexView* hexview) const;
virtual void renderHeaderPart(const QString& s, QHexArea area,
QTextCharFormat& cf,
const QHexView* hexview) const;
virtual bool render(quint64 offset, quint8 b, QTextCharFormat& outcf,
const QHexView* hexview) const;
virtual bool paintSeparator(QPainter* painter, QLineF line,
const QHexView* hexview) const;
virtual void paint(QPainter* painter, const QHexView* hexview) const;
};

View file

@ -0,0 +1,102 @@
#pragma once
#include <QHexView/model/buffer/qhexbuffer.h>
#include <QHexView/model/qhexmetadata.h>
#include <QUndoStack>
class QHexCursor;
class QHexDocument: public QObject {
Q_OBJECT
public:
enum class ChangeReason { Insert, Remove, Replace };
enum class FindDirection { Forward, Backward };
Q_ENUM(ChangeReason);
Q_ENUM(FindDirection);
private:
explicit QHexDocument(QHexBuffer* buffer, QObject* parent = nullptr);
bool accept(qint64 idx) const;
public:
bool isEmpty() const;
bool isModified() const;
bool canUndo() const;
bool canRedo() const;
void setData(const QByteArray& ba);
void setData(QHexBuffer* buffer);
qint64 length() const;
qint64 indexOf(const QByteArray& ba, qint64 from = 0);
qint64 lastIndexOf(const QByteArray& ba, qint64 from = 0);
QByteArray read(qint64 offset, int len = 0) const;
uchar at(int offset) const;
public Q_SLOTS:
void clearModified();
void undo();
void redo();
void insert(qint64 offset, uchar b);
void replace(qint64 offset, uchar b);
void insert(qint64 offset, const QByteArray& data);
void replace(qint64 offset, const QByteArray& data);
void remove(qint64 offset, int len);
bool saveTo(QIODevice* device);
public:
template<typename T, bool Owned = true>
static QHexDocument* fromDevice(QIODevice* iodevice,
QObject* parent = nullptr);
template<typename T>
static QHexDocument* fromMemory(char* data, int size,
QObject* parent = nullptr);
template<typename T>
static QHexDocument* fromMemory(const QByteArray& ba,
QObject* parent = nullptr);
static QHexDocument* fromBuffer(QHexBuffer* buffer,
QObject* parent = nullptr);
static QHexDocument* fromLargeFile(QString filename,
QObject* parent = nullptr);
static QHexDocument* fromMappedFile(QString filename,
QObject* parent = nullptr);
static QHexDocument* fromFile(QString filename, QObject* parent = nullptr);
static QHexDocument* create(QObject* parent = nullptr);
Q_SIGNALS:
void modifiedChanged(bool modified);
void canUndoChanged(bool canundo);
void canRedoChanged(bool canredo);
void dataChanged(const QByteArray& data, quint64 offset,
QHexDocument::ChangeReason reason);
void changed();
void reset();
private:
QHexBuffer* m_buffer;
QUndoStack m_undostack;
friend class QHexView;
};
template<typename T, bool Owned>
QHexDocument* QHexDocument::fromDevice(QIODevice* iodevice, QObject* parent) {
QHexBuffer* hexbuffer = new T(parent);
if(Owned)
iodevice->setParent(hexbuffer);
return hexbuffer->read(iodevice) ? new QHexDocument(hexbuffer, parent)
: nullptr;
}
template<typename T>
QHexDocument* QHexDocument::fromMemory(char* data, int size, QObject* parent) {
QHexBuffer* hexbuffer = new T();
hexbuffer->read(data, size);
return new QHexDocument(hexbuffer, parent);
}
template<typename T>
QHexDocument* QHexDocument::fromMemory(const QByteArray& ba, QObject* parent) {
QHexBuffer* hexbuffer = new T();
hexbuffer->read(ba);
return new QHexDocument(hexbuffer, parent);
}

View file

@ -0,0 +1,92 @@
#pragma once
#include <QColor>
#include <QHash>
#include <QHexView/model/qhexoptions.h>
#include <QList>
#include <QObject>
#include <functional>
struct QHexMetadataItem {
qint64 begin, end;
QColor foreground, background;
QString comment;
};
using QHexMetadataLine = QList<QHexMetadataItem>;
class QHexMetadata: public QObject {
Q_OBJECT
private:
using ClearMetadataCallback = std::function<bool(QHexMetadataItem&)>;
private:
explicit QHexMetadata(const QHexOptions* options,
QObject* parent = nullptr);
public:
const QHexMetadataLine* find(qint64 line) const;
QString getComment(qint64 line, qint64 column) const;
void removeMetadata(qint64 line);
void removeBackground(qint64 line);
void removeForeground(qint64 line);
void removeComments(qint64 line);
void unhighlight(qint64 line);
void clear();
public:
inline void setMetadata(qint64 begin, qint64 end, const QColor& fgcolor,
const QColor& bgcolor, const QString& comment) {
this->setMetadata({begin, end, fgcolor, bgcolor, comment});
}
inline void setForeground(qint64 begin, qint64 end, const QColor& fgcolor) {
this->setMetadata(begin, end, fgcolor, QColor(), QString());
}
inline void setBackground(qint64 begin, qint64 end, const QColor& bgcolor) {
this->setMetadata(begin, end, QColor(), bgcolor, QString());
}
inline void setComment(qint64 begin, qint64 end, const QString& comment) {
this->setMetadata(begin, end, QColor(), QColor(), comment);
};
inline void setMetadataSize(qint64 begin, qint64 length,
const QColor& fgcolor, const QColor& bgcolor,
const QString& comment) {
this->setMetadata({begin, begin + length, fgcolor, bgcolor, comment});
}
inline void setForegroundSize(qint64 begin, qint64 length,
const QColor& fgcolor) {
this->setForeground(begin, begin + length, fgcolor);
}
inline void setBackgroundSize(qint64 begin, qint64 length,
const QColor& bgcolor) {
this->setBackground(begin, begin + length, bgcolor);
}
inline void setCommentSize(qint64 begin, qint64 length,
const QString& comment) {
this->setComment(begin, begin + length, comment);
};
private:
void copy(const QHexMetadata* metadata);
void clearMetadata(qint64 line, ClearMetadataCallback&& cb);
void setMetadata(const QHexMetadataItem& mi);
void invalidate();
Q_SIGNALS:
void changed();
void cleared();
private:
QHash<qint64, QHexMetadataLine> m_metadata;
const QHexOptions* m_options;
friend class QHexView;
};

View file

@ -0,0 +1,56 @@
#pragma once
#include <QChar>
#include <QColor>
#include <QHash>
namespace QHexFlags {
enum : unsigned int {
None = (1 << 0),
HSeparator = (1 << 1),
VSeparator = (1 << 2),
StyledHeader = (1 << 3),
StyledAddress = (1 << 4),
NoHeader = (1 << 5),
HighlightAddress = (1 << 6),
HighlightColumn = (1 << 7),
Separators = HSeparator | VSeparator,
Styled = StyledHeader | StyledAddress,
};
}
struct QHexColor {
QColor foreground;
QColor background;
};
struct QHexOptions {
// Appearance
QChar unprintablechar{'.'};
QChar invalidchar{'?'};
QString addresslabel{""};
QString hexlabel;
QString asciilabel;
quint64 baseaddress{0};
unsigned int flags{QHexFlags::None};
unsigned int linelength{0x10};
unsigned int addresswidth{0};
unsigned int grouplength{1};
int scrollsteps{1};
// Colors & Styles
QHash<quint8, QHexColor> bytecolors;
QColor linealternatebackground;
QColor linebackground;
QColor headercolor;
QColor commentcolor;
QColor separatorcolor;
// Misc
bool copybreak{true};
inline bool hasFlag(unsigned int flag) const { return flags & flag; }
};

View file

@ -0,0 +1,66 @@
#pragma once
#include <QByteArray>
#include <QPair>
#include <QString>
#include <QVariant>
struct QHexOptions;
class QHexView;
namespace QHexFindOptions {
enum : unsigned int {
None = (1 << 0),
CaseSensitive = (1 << 1),
Int8 = (1 << 2),
Int16 = (1 << 3),
Int32 = (1 << 4),
Int64 = (1 << 5),
Float = (1 << 6),
Double = (1 << 7),
BigEndian = (1 << 11),
};
}
enum class QHexFindMode { Text, Hex, Int, Float };
enum class QHexFindDirection { All, Forward, Backward };
enum class QHexArea { Header, Address, Hex, Ascii, Extra };
struct QHexPosition {
qint64 line;
qint64 column;
static inline QHexPosition invalid() { return {-1, -1}; }
inline bool isValid() const { return line >= 0 && column >= 0; }
inline bool operator==(const QHexPosition& rhs) const {
return (line == rhs.line) && (column == rhs.column);
}
inline bool operator!=(const QHexPosition& rhs) const {
return (line != rhs.line) || (column != rhs.column);
}
};
namespace QHexUtils {
bool isHex(char ch);
QByteArray toHex(const QByteArray& ba, char sep);
QByteArray toHex(const QByteArray& ba);
qint64 positionToOffset(const QHexOptions* options, QHexPosition pos);
QHexPosition offsetToPosition(const QHexOptions* options, qint64 offset);
bool checkPattern(QString pattern);
QPair<qint64, qint64> find(const QHexView* hexview, QVariant value,
qint64 startoffset = 0,
QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward);
QPair<qint64, qint64>
replace(const QHexView* hexview, QVariant oldvalue, QVariant newvalue,
qint64 startoffset = 0, QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward);
} // namespace QHexUtils

View file

@ -0,0 +1,184 @@
#pragma once
#define QHEXVIEW_VERSION 5.0
#include <QAbstractScrollArea>
#include <QFontMetricsF>
#include <QHexView/model/qhexcursor.h>
#include <QHexView/model/qhexdelegate.h>
#include <QHexView/model/qhexdocument.h>
#include <QList>
#include <QRectF>
#include <QTextCharFormat>
#if defined(QHEXVIEW_ENABLE_DIALOGS)
class HexFindDialog;
#endif
class QHexView: public QAbstractScrollArea {
Q_OBJECT
public:
enum class CopyMode { Visual, HexArraySquare, HexArrayCurly, HexArrayChar };
Q_ENUM(CopyMode);
public:
explicit QHexView(QWidget* parent = nullptr);
QRectF headerRect() const;
QRectF addressRect() const;
QRectF hexRect() const;
QRectF asciiRect() const;
QHexDocument* hexDocument() const;
QHexCursor* hexCursor() const;
const QHexMetadata* hexMetadata() const;
QHexOptions options() const;
QColor getReadableColor(QColor c) const;
QByteArray selectedBytes() const;
QByteArray getLine(qint64 line) const;
unsigned int addressWidth() const;
unsigned int lineLength() const;
bool isModified() const;
bool canUndo() const;
bool canRedo() const;
quint64 offset() const;
quint64 address() const;
QHexPosition positionFromOffset(quint64 offset) const;
QHexPosition positionFromAddress(quint64 address) const;
QHexPosition position() const;
QHexPosition selectionStart() const;
QHexPosition selectionEnd() const;
quint64 selectionStartOffset() const;
quint64 selectionEndOffset() const;
quint64 baseAddress() const;
quint64 lines() const;
qint64 replace(const QVariant& oldvalue, const QVariant& newvalue,
qint64 offset, QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward) const;
qint64 find(const QVariant& value, qint64 offset,
QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward) const;
void setOptions(const QHexOptions& options);
void setBaseAddress(quint64 baseaddress);
void setDelegate(QHexDelegate* rd);
void setDocument(QHexDocument* doc);
void setData(const QByteArray& ba);
void setData(QHexBuffer* buffer);
void setCursorMode(QHexCursor::Mode mode);
void setByteColor(quint8 b, QHexColor c);
void setByteForeground(quint8 b, QColor c);
void setByteBackground(quint8 b, QColor c);
void setMetadata(qint64 begin, qint64 end, const QColor& fgcolor,
const QColor& bgcolor, const QString& comment);
void setForeground(qint64 begin, qint64 end, const QColor& fgcolor);
void setBackground(qint64 begin, qint64 end, const QColor& bgcolor);
void setComment(qint64 begin, qint64 end, const QString& comment);
void setMetadataSize(qint64 begin, qint64 length, const QColor& fgcolor,
const QColor& bgcolor, const QString& comment);
void setForegroundSize(qint64 begin, qint64 length, const QColor& fgcolor);
void setBackgroundSize(qint64 begin, qint64 length, const QColor& bgcolor);
void setCommentSize(qint64 begin, qint64 length, const QString& comment);
void removeMetadata(qint64 line);
void removeBackground(qint64 line);
void removeForeground(qint64 line);
void removeComments(qint64 line);
void unhighlight(qint64 line);
void clearMetadata();
public Q_SLOTS:
#if defined(QHEXVIEW_ENABLE_DIALOGS)
void showFind();
void showReplace();
#endif
void undo();
void redo();
void cut(bool hex = false);
void copyAs(CopyMode mode = CopyMode::Visual) const;
void copy(bool hex = false) const;
void paste(bool hex = false);
void clearModified();
void selectAll();
void removeSelection();
void switchMode();
void setAddressWidth(unsigned int w);
void setLineLength(unsigned int l);
void setGroupLength(unsigned int l);
void setScrollSteps(int scrollsteps);
void setReadOnly(bool r);
void setAutoWidth(bool r);
private:
void paint(QPainter* painter) const;
void checkOptions();
void checkState();
void checkAndUpdate(bool calccolumns = false);
void calcColumns();
void ensureVisible();
void drawSeparators(QPainter* p) const;
void drawHeader(QTextCursor& c) const;
void drawDocument(QTextCursor& c) const;
QTextCharFormat drawFormat(QTextCursor& c, quint8 b, const QString& s,
QHexArea area, qint64 line, qint64 column,
bool applyformat) const;
unsigned int calcAddressWidth() const;
int visibleLines(bool absolute = false) const;
qint64 getLastColumn(qint64 line) const;
qint64 lastLine() const;
qreal getNCellsWidth(int n) const;
qreal hexColumnWidth() const;
qreal hexColumnX() const;
qreal asciiColumnX() const;
qreal endColumnX() const;
qreal cellWidth() const;
qreal lineHeight() const;
qint64 positionFromLineCol(qint64 line, qint64 col) const;
QHexPosition positionFromPoint(QPoint pt) const;
QPoint absolutePoint(QPoint pt) const;
QHexArea areaFromPoint(QPoint pt) const;
void moveNext(bool select = false);
void movePrevious(bool select = false);
bool keyPressMove(QKeyEvent* e);
bool keyPressTextInput(QKeyEvent* e);
bool keyPressAction(QKeyEvent* e);
protected:
bool event(QEvent* e) override;
void showEvent(QShowEvent* e) override;
void paintEvent(QPaintEvent*) override;
void resizeEvent(QResizeEvent* e) override;
void focusInEvent(QFocusEvent* e) override;
void focusOutEvent(QFocusEvent* e) override;
void mousePressEvent(QMouseEvent* e) override;
void mouseMoveEvent(QMouseEvent* e) override;
void wheelEvent(QWheelEvent* e) override;
void keyPressEvent(QKeyEvent* e) override;
private:
static QString reduced(const QString& s, int maxlen);
static bool isColorLight(QColor c);
Q_SIGNALS:
void dataChanged(const QByteArray& data, quint64 offset,
QHexDocument::ChangeReason reason);
void modifiedChanged(bool modified);
void positionChanged();
void modeChanged();
private:
bool m_readonly{false}, m_writing{false}, m_autowidth{false};
QHexArea m_currentarea{QHexArea::Ascii};
QList<QRectF> m_hexcolumns;
QFontMetricsF m_fontmetrics;
QHexOptions m_options;
QHexCursor* m_hexcursor{nullptr};
QHexDocument* m_hexdocument{nullptr};
QHexMetadata* m_hexmetadata{nullptr};
QHexDelegate* m_hexdelegate{nullptr};
#if defined(QHEXVIEW_ENABLE_DIALOGS)
HexFindDialog *m_hexdlgfind{nullptr}, *m_hexdlgreplace{nullptr};
#endif
friend class QHexDelegate;
friend class QHexCursor;
};

View file

@ -0,0 +1,418 @@
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHexView/dialogs/hexfinddialog.h>
#include <QHexView/qhexview.h>
#include <QLabel>
#include <QLineEdit>
#include <QList>
#include <QMessageBox>
#include <QPair>
#include <QPushButton>
#include <QRadioButton>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QSpacerItem>
#include <QStackedLayout>
#include <QVBoxLayout>
#include <limits>
const QString HexFindDialog::BUTTONBOX = "qhexview_buttonbox";
const QString HexFindDialog::CBFINDMODE = "qhexview_cbfindmode";
const QString HexFindDialog::LEFIND = "qhexview_lefind";
const QString HexFindDialog::LEREPLACE = "qhexview_lereplace";
const QString HexFindDialog::HLAYOUT = "qhexview_hlayout";
const QString HexFindDialog::GBOPTIONS = "qhexview_gboptions";
const QString HexFindDialog::RBALL = "qhexview_rball";
const QString HexFindDialog::RBFORWARD = "qhexview_rbforward";
const QString HexFindDialog::RBBACKWARD = "qhexview_rbbackward";
HexFindDialog::HexFindDialog(Type type, QHexView* parent)
: QDialog{parent}, m_type{type} {
m_hexvalidator = new QRegularExpressionValidator(
QRegularExpression{"[0-9A-Fa-f ]+"}, this);
m_hexpvalidator = new QRegularExpressionValidator(
QRegularExpression{"[0-9A-Fa-f \\?]+"}, this);
m_dblvalidator = new QDoubleValidator(this);
m_intvalidator = new QIntValidator(this);
this->setWindowTitle(type == Type::Replace ? tr("Replace...")
: tr("Find..."));
auto* vlayout = new QVBoxLayout(this);
auto* gridlayout = new QGridLayout();
auto* cbfindmode = new QComboBox(this);
cbfindmode->setObjectName(HexFindDialog::CBFINDMODE);
cbfindmode->addItem("Text", static_cast<int>(QHexFindMode::Text));
cbfindmode->addItem("Hex", static_cast<int>(QHexFindMode::Hex));
cbfindmode->addItem("Int", static_cast<int>(QHexFindMode::Int));
cbfindmode->addItem("Float", static_cast<int>(QHexFindMode::Float));
QLineEdit *lereplace = nullptr, *lefind = new QLineEdit(this);
lefind->setObjectName(HexFindDialog::LEFIND);
gridlayout->addWidget(new QLabel(tr("Mode:"), this), 0, 0, Qt::AlignRight);
gridlayout->addWidget(cbfindmode, 0, 1);
gridlayout->addWidget(new QLabel(tr("Find:"), this), 1, 0, Qt::AlignRight);
gridlayout->addWidget(lefind, 1, 1);
if(type == Type::Replace) {
lereplace = new QLineEdit(this);
lereplace->setObjectName(HexFindDialog::LEREPLACE);
gridlayout->addWidget(new QLabel(tr("Replace:"), this), 2, 0,
Qt::AlignRight);
gridlayout->addWidget(lereplace, 2, 1);
}
vlayout->addLayout(gridlayout);
auto* gboptions = new QGroupBox(this);
gboptions->setObjectName(HexFindDialog::GBOPTIONS);
gboptions->setTitle(tr("Options"));
gboptions->setLayout(new QStackedLayout());
QGroupBox* gbdirection = new QGroupBox(this);
gbdirection->setTitle(tr("Find direction"));
auto* gbvlayout = new QVBoxLayout(gbdirection);
auto* rball = new QRadioButton("All", gbdirection);
rball->setObjectName(HexFindDialog::RBALL);
auto* rbforward = new QRadioButton("Forward", gbdirection);
rbforward->setObjectName(HexFindDialog::RBFORWARD);
rbforward->setChecked(true);
auto* rbbackward = new QRadioButton("Backward", gbdirection);
rbbackward->setObjectName(HexFindDialog::RBBACKWARD);
gbvlayout->addWidget(rball);
gbvlayout->addWidget(rbforward);
gbvlayout->addWidget(rbbackward);
gbvlayout->addSpacerItem(
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
auto* hlayout = new QHBoxLayout();
hlayout->setObjectName(HexFindDialog::HLAYOUT);
hlayout->addWidget(gboptions, 1);
hlayout->addWidget(gbdirection);
vlayout->addLayout(hlayout, 1);
auto* buttonbox = new QDialogButtonBox(this);
buttonbox->setOrientation(Qt::Horizontal);
if(type == Type::Replace)
buttonbox->setStandardButtons(QDialogButtonBox::Ok |
QDialogButtonBox::Apply |
QDialogButtonBox::Cancel);
else
buttonbox->setStandardButtons(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel);
buttonbox->setObjectName(HexFindDialog::BUTTONBOX);
buttonbox->button(QDialogButtonBox::Ok)->setEnabled(false);
buttonbox->button(QDialogButtonBox::Ok)->setText(tr("Find"));
if(type == Type::Replace) {
buttonbox->button(QDialogButtonBox::Apply)->setEnabled(false);
buttonbox->button(QDialogButtonBox::Apply)->setText(tr("Replace"));
}
vlayout->addWidget(buttonbox);
connect(lefind, &QLineEdit::textChanged, this,
&HexFindDialog::validateActions);
connect(cbfindmode, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &HexFindDialog::updateFindOptions);
connect(buttonbox, &QDialogButtonBox::accepted, this, &HexFindDialog::find);
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(parent, &QHexView::positionChanged, this,
[this]() { m_startoffset = -1; });
if(lereplace) {
connect(buttonbox->button(QDialogButtonBox::Apply),
&QPushButton::clicked, this, &HexFindDialog::replace);
connect(lereplace, &QLineEdit::textChanged, this,
&HexFindDialog::validateActions);
}
this->prepareTextMode(gboptions->layout());
this->prepareHexMode(gboptions->layout());
this->prepareIntMode(gboptions->layout());
this->prepareFloatMode(gboptions->layout());
this->updateFindOptions(-1);
}
QHexView* HexFindDialog::hexView() const {
return qobject_cast<QHexView*>(this->parentWidget());
}
void HexFindDialog::updateFindOptions(int) {
QGroupBox* gboptions =
this->findChild<QGroupBox*>(HexFindDialog::GBOPTIONS);
QLineEdit* lefind = this->findChild<QLineEdit*>(HexFindDialog::LEFIND);
QLineEdit* lereplace =
this->findChild<QLineEdit*>(HexFindDialog::LEREPLACE);
lefind->clear();
if(lereplace)
lereplace->clear();
bool ok = false;
QHexFindMode mode = static_cast<QHexFindMode>(
this->findChild<QComboBox*>(HexFindDialog::CBFINDMODE)
->currentData()
.toInt(&ok));
if(!ok)
return;
m_findoptions = QHexFindOptions::None;
m_oldidxbits = m_oldidxendian = -1;
auto* stack = qobject_cast<QStackedLayout*>(gboptions->layout());
switch(mode) {
case QHexFindMode::Text: {
lefind->setValidator(nullptr);
if(lereplace)
lereplace->setValidator(nullptr);
stack->setCurrentIndex(0);
gboptions->setVisible(true);
break;
}
case QHexFindMode::Hex: {
lefind->setValidator(m_hexpvalidator);
if(lereplace)
lereplace->setValidator(m_hexvalidator);
stack->setCurrentIndex(1);
gboptions->setVisible(false);
break;
}
case QHexFindMode::Int: {
lefind->setValidator(m_intvalidator);
if(lereplace)
lereplace->setValidator(m_intvalidator);
stack->setCurrentIndex(2);
gboptions->setVisible(true);
break;
}
case QHexFindMode::Float: {
lefind->setValidator(m_dblvalidator);
if(lereplace)
lereplace->setValidator(m_dblvalidator);
stack->setCurrentIndex(3);
gboptions->setVisible(true);
break;
}
}
}
bool HexFindDialog::validateIntRange(uint v) const {
if(m_findoptions & QHexFindOptions::Int8)
return !(v > std::numeric_limits<quint8>::max());
if(m_findoptions & QHexFindOptions::Int16)
return !(v > std::numeric_limits<quint16>::max());
if(m_findoptions & QHexFindOptions::Int32)
return !(v > std::numeric_limits<quint32>::max());
return true;
}
void HexFindDialog::checkResult(const QString& q, qint64 offset,
QHexFindDirection fd) {
if(offset == -1) {
QMessageBox::information(this, tr("Not found"),
tr("Cannot find '%1'").arg(q));
return;
}
if(fd == QHexFindDirection::Backward)
m_startoffset = this->hexView()->selectionStartOffset() - 1;
else
m_startoffset = this->hexView()->selectionEndOffset() + 1;
}
void HexFindDialog::validateActions() {
auto mode = static_cast<QHexFindMode>(
this->findChild<QComboBox*>(HexFindDialog::CBFINDMODE)
->currentData()
.toUInt());
auto* lefind = this->findChild<QLineEdit*>(HexFindDialog::LEFIND);
auto* lereplace = this->findChild<QLineEdit*>(HexFindDialog::LEREPLACE);
auto* buttonbox =
this->findChild<QDialogButtonBox*>(HexFindDialog::BUTTONBOX);
bool findenable = false, replaceenable = false;
switch(mode) {
case QHexFindMode::Hex:
findenable = QHexUtils::checkPattern(lefind->text());
replaceenable = findenable;
break;
case QHexFindMode::Float: {
lefind->text().toFloat(&findenable);
if(lereplace && findenable)
lereplace->text().toFloat(&replaceenable);
break;
}
case QHexFindMode::Int: {
auto v = lefind->text().toUInt(&findenable);
if(findenable && !this->validateIntRange(v))
findenable = false;
if(lereplace && findenable)
lereplace->text().toUInt(&replaceenable);
break;
}
default:
findenable = !lefind->text().isEmpty();
replaceenable = findenable;
break;
}
if(lereplace)
buttonbox->button(QDialogButtonBox::Apply)->setEnabled(replaceenable);
buttonbox->button(QDialogButtonBox::Ok)->setEnabled(findenable);
}
void HexFindDialog::replace() {
QString q1;
QHexFindMode mode;
QHexFindDirection fd;
if(!this->prepareOptions(q1, mode, fd))
return;
QString q2 = this->findChild<QLineEdit*>(HexFindDialog::LEREPLACE)->text();
auto offset = this->hexView()->hexCursor()->replace(
q1, q2, m_startoffset > -1 ? m_startoffset : this->hexView()->offset(),
mode, m_findoptions, fd);
this->checkResult(q1, offset, fd);
}
void HexFindDialog::find() {
QString q;
QHexFindMode mode;
QHexFindDirection fd;
if(!this->prepareOptions(q, mode, fd))
return;
auto offset = this->hexView()->hexCursor()->find(
q, m_startoffset > -1 ? m_startoffset : this->hexView()->offset(), mode,
m_findoptions, fd);
this->checkResult(q, offset, fd);
}
bool HexFindDialog::prepareOptions(QString& q, QHexFindMode& mode,
QHexFindDirection& fd) {
q = this->findChild<QLineEdit*>(HexFindDialog::LEFIND)->text();
mode = static_cast<QHexFindMode>(
this->findChild<QComboBox*>(HexFindDialog::CBFINDMODE)
->currentData()
.toUInt());
if(mode == QHexFindMode::Hex && !QHexUtils::checkPattern(q)) {
QMessageBox::warning(this, tr("Pattern Error"),
tr("Hex pattern '%1' is not valid").arg(q));
return false;
}
if(this->findChild<QRadioButton*>(HexFindDialog::RBBACKWARD)->isChecked())
fd = QHexFindDirection::Backward;
else if(this->findChild<QRadioButton*>(HexFindDialog::RBFORWARD)
->isChecked())
fd = QHexFindDirection::Forward;
else
fd = QHexFindDirection::All;
return true;
}
void HexFindDialog::prepareTextMode(QLayout* l) {
auto* cbcasesensitive = new QCheckBox("Case sensitive");
connect(cbcasesensitive, &QCheckBox::stateChanged, this, [this](int state) {
if(state == Qt::Checked)
m_findoptions |= QHexFindOptions::CaseSensitive;
else
m_findoptions &= ~QHexFindOptions::CaseSensitive;
});
auto* vlayout = new QVBoxLayout(new QWidget());
vlayout->addWidget(cbcasesensitive);
l->addWidget(vlayout->parentWidget());
}
void HexFindDialog::prepareHexMode(QLayout* l) { l->addWidget(new QWidget()); }
void HexFindDialog::prepareIntMode(QLayout* l) {
static const QList<QPair<QString, unsigned int>> INT_TYPES = {
qMakePair<QString, unsigned int>("(any)", 0),
qMakePair<QString, unsigned int>("8", QHexFindOptions::Int8),
qMakePair<QString, unsigned int>("16", QHexFindOptions::Int16),
qMakePair<QString, unsigned int>("32", QHexFindOptions::Int32),
qMakePair<QString, unsigned int>("64", QHexFindOptions::Int64)};
auto* cbbits = new QComboBox();
for(const auto& it : INT_TYPES)
cbbits->addItem(it.first, it.second);
connect(cbbits, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this, cbbits](int index) {
if(m_oldidxbits > -1)
m_findoptions &= ~cbbits->itemData(m_oldidxbits).toUInt();
m_findoptions |= cbbits->itemData(index).toUInt();
m_oldidxbits = index;
});
auto* cbendian = new QComboBox();
cbendian->addItem("Little Endian", 0);
cbendian->addItem("Big Endian", QHexFindOptions::BigEndian);
connect(cbendian, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this, cbendian](int index) {
if(m_oldidxendian > -1)
m_findoptions &=
~cbendian->itemData(m_oldidxendian).toUInt();
m_findoptions |= cbendian->itemData(index).toUInt();
m_oldidxendian = index;
});
auto* vlayout = new QVBoxLayout(new QWidget());
QGridLayout* gl = new QGridLayout();
gl->addWidget(new QLabel("Type:"), 0, 0, Qt::AlignRight);
gl->addWidget(cbbits, 0, 1);
gl->addWidget(new QLabel("Endian:"), 1, 0, Qt::AlignRight);
gl->addWidget(cbendian, 1, 1);
vlayout->addLayout(gl);
l->addWidget(vlayout->parentWidget());
}
void HexFindDialog::prepareFloatMode(QLayout* l) {
static const QList<QPair<QString, unsigned int>> FLOAT_TYPES = {
qMakePair<QString, unsigned int>("float", QHexFindOptions::Float),
qMakePair<QString, unsigned int>("double", QHexFindOptions::Double)};
bool first = true;
auto* vlayout = new QVBoxLayout(new QWidget());
for(const auto& ft : FLOAT_TYPES) {
auto* rb = new QRadioButton(ft.first);
rb->setChecked(first);
vlayout->addWidget(rb);
first = false;
}
l->addWidget(vlayout->parentWidget());
}

View file

@ -0,0 +1,118 @@
#include <QHexView/model/buffer/qdevicebuffer.h>
#include <QIODevice>
#include <limits>
QDeviceBuffer::QDeviceBuffer(QObject* parent): QHexBuffer{parent} {}
QDeviceBuffer::~QDeviceBuffer() {
if(!m_device)
return;
if(m_device->parent() == this) {
if(m_device->isOpen())
m_device->close();
m_device->deleteLater();
}
m_device = nullptr;
}
uchar QDeviceBuffer::at(qint64 idx) {
m_device->seek(idx);
char c = '\0';
m_device->getChar(&c);
return static_cast<uchar>(c);
}
qint64 QDeviceBuffer::length() const { return m_device->size(); }
void QDeviceBuffer::insert(qint64 offset, const QByteArray& data) {
Q_UNUSED(offset)
Q_UNUSED(data)
// Not implemented
}
void QDeviceBuffer::replace(qint64 offset, const QByteArray& data) {
m_device->seek(offset);
m_device->write(data);
}
void QDeviceBuffer::remove(qint64 offset, int length) {
Q_UNUSED(offset)
Q_UNUSED(length)
// Not implemented
}
QByteArray QDeviceBuffer::read(qint64 offset, int length) {
m_device->seek(offset);
return m_device->read(length);
}
bool QDeviceBuffer::read(QIODevice* device) {
m_device = device;
if(!m_device)
return false;
if(!m_device->isOpen())
m_device->open(QIODevice::ReadWrite);
return m_device->isOpen();
}
void QDeviceBuffer::write(QIODevice* device) {
Q_UNUSED(device)
// Not implemented
}
qint64 QDeviceBuffer::indexOf(const QByteArray& ba, qint64 from) {
const auto MAX = std::numeric_limits<int>::max();
qint64 idx = -1;
if(from < m_device->size()) {
idx = from;
m_device->seek(from);
while(idx < m_device->size()) {
QByteArray data = m_device->read(MAX);
int sidx = data.indexOf(ba);
if(sidx >= 0) {
idx += sidx;
break;
}
if(idx + data.size() >= m_device->size())
return -1;
m_device->seek(m_device->pos() + data.size() - ba.size());
}
}
return idx;
}
qint64 QDeviceBuffer::lastIndexOf(const QByteArray& ba, qint64 from) {
const auto MAX = std::numeric_limits<int>::max();
qint64 idx = -1;
if(from >= 0 && ba.size() < MAX) {
qint64 currpos = from;
while(currpos >= 0) {
qint64 readpos = (currpos < MAX) ? 0 : currpos - MAX;
m_device->seek(readpos);
QByteArray data = m_device->read(currpos - readpos);
int lidx = data.lastIndexOf(ba, from);
if(lidx >= 0) {
idx = readpos + lidx;
break;
}
if(readpos <= 0)
break;
currpos = readpos + ba.size();
}
}
return idx;
}

View file

@ -0,0 +1,36 @@
#include <QBuffer>
#include <QHexView/model/buffer/qhexbuffer.h>
QHexBuffer::QHexBuffer(QObject* parent): QObject{parent} {}
uchar QHexBuffer::at(qint64 idx) { return this->read(idx, 1).at(0); }
bool QHexBuffer::isEmpty() const { return this->length() <= 0; }
void QHexBuffer::replace(qint64 offset, const QByteArray& data) {
this->remove(offset, data.length());
this->insert(offset, data);
}
bool QHexBuffer::accept(qint64 idx) const {
Q_UNUSED(idx);
return true;
}
void QHexBuffer::read(char* data, int size) {
QBuffer* buffer = new QBuffer(this);
buffer->setData(data, size);
if(!buffer->isOpen())
buffer->open(QBuffer::ReadWrite);
this->read(buffer);
}
void QHexBuffer::read(const QByteArray& ba) {
QBuffer* buffer = new QBuffer(this);
buffer->setData(ba);
if(!buffer->isOpen())
buffer->open(QBuffer::ReadWrite);
this->read(buffer);
}

View file

@ -0,0 +1,51 @@
#include <QFile>
#include <QHexView/model/buffer/qmappedfilebuffer.h>
QMappedFileBuffer::QMappedFileBuffer(QObject* parent): QDeviceBuffer{parent} {}
QMappedFileBuffer::~QMappedFileBuffer() {
if((m_device && (m_device->parent() == this)) && m_mappeddata) {
QFile* f = qobject_cast<QFile*>(m_device);
f->unmap(m_mappeddata);
}
m_mappeddata = nullptr;
}
QByteArray QMappedFileBuffer::read(qint64 offset, int length) {
if(offset >= this->length())
return {};
if(offset + length >= this->length())
length = this->length() - offset;
return QByteArray::fromRawData(
reinterpret_cast<const char*>(m_mappeddata + offset), length);
}
bool QMappedFileBuffer::read(QIODevice* iodevice) {
m_device = qobject_cast<QFile*>(iodevice);
if(!m_device || !QDeviceBuffer::read(iodevice))
return false;
this->remap();
return m_mappeddata;
}
void QMappedFileBuffer::write(QIODevice* iodevice) {
if(iodevice == m_device)
this->remap();
else
iodevice->write(reinterpret_cast<const char*>(m_mappeddata),
m_device->size());
}
void QMappedFileBuffer::remap() {
QFile* f = qobject_cast<QFile*>(m_device);
if(!f)
return;
if(m_mappeddata)
f->unmap(m_mappeddata);
m_mappeddata = f->map(0, f->size());
}

View file

@ -0,0 +1,39 @@
#include <QHexView/model/buffer/qmemorybuffer.h>
#include <QIODevice>
QMemoryBuffer::QMemoryBuffer(QObject* parent): QHexBuffer{parent} {}
uchar QMemoryBuffer::at(qint64 idx) {
return static_cast<uchar>(m_buffer.at(idx));
}
qint64 QMemoryBuffer::length() const {
return static_cast<qint64>(m_buffer.length());
}
void QMemoryBuffer::insert(qint64 offset, const QByteArray& data) {
m_buffer.insert(static_cast<int>(offset), data);
}
void QMemoryBuffer::remove(qint64 offset, int length) {
m_buffer.remove(static_cast<int>(offset), length);
}
QByteArray QMemoryBuffer::read(qint64 offset, int length) {
return m_buffer.mid(static_cast<int>(offset), length);
}
bool QMemoryBuffer::read(QIODevice* device) {
m_buffer = device->readAll();
return true;
}
void QMemoryBuffer::write(QIODevice* device) { device->write(m_buffer); }
qint64 QMemoryBuffer::indexOf(const QByteArray& ba, qint64 from) {
return m_buffer.indexOf(ba, static_cast<int>(from));
}
qint64 QMemoryBuffer::lastIndexOf(const QByteArray& ba, qint64 from) {
return m_buffer.lastIndexOf(ba, static_cast<int>(from));
}

View file

@ -0,0 +1,26 @@
#include <QBuffer>
#include <QHexView/model/buffer/qmemoryrefbuffer.h>
QMemoryRefBuffer::QMemoryRefBuffer(QObject* parent): QDeviceBuffer{parent} {}
bool QMemoryRefBuffer::read(QIODevice* device) {
m_device = qobject_cast<QBuffer*>(device);
if(m_device) {
m_device->setParent(this);
return QDeviceBuffer::read(device);
}
return false;
}
void QMemoryRefBuffer::write(QIODevice* device) {
if(!m_device || m_device == device)
return;
static const int CHUNK_SIZE = 4096;
m_device->seek(0);
while(!m_device->atEnd())
device->write(m_device->read(CHUNK_SIZE));
}

View file

@ -0,0 +1,6 @@
#include <QHexView/model/commands/hexcommand.h>
HexCommand::HexCommand(QHexBuffer* buffer, QHexDocument* document,
QUndoCommand* parent)
: QUndoCommand(parent), m_hexdocument(document), m_buffer(buffer),
m_offset(0), m_length(0) {}

View file

@ -0,0 +1,18 @@
#include <QHexView/model/commands/insertcommand.h>
#include <QHexView/model/qhexdocument.h>
InsertCommand::InsertCommand(QHexBuffer* buffer, QHexDocument* document,
qint64 offset, const QByteArray& data,
QUndoCommand* parent)
: HexCommand(buffer, document, parent) {
m_offset = offset;
m_data = data;
}
void InsertCommand::undo() {
m_buffer->remove(m_offset, m_data.length());
Q_EMIT m_hexdocument->dataChanged(m_data, m_offset,
QHexDocument::ChangeReason::Remove);
}
void InsertCommand::redo() { m_buffer->insert(m_offset, m_data); }

View file

@ -0,0 +1,20 @@
#include <QHexView/model/commands/removecommand.h>
#include <QHexView/model/qhexdocument.h>
RemoveCommand::RemoveCommand(QHexBuffer* buffer, QHexDocument* document,
qint64 offset, int length, QUndoCommand* parent)
: HexCommand(buffer, document, parent) {
m_offset = offset;
m_length = length;
}
void RemoveCommand::undo() {
m_buffer->insert(m_offset, m_data);
Q_EMIT m_hexdocument->dataChanged(m_data, m_offset,
QHexDocument::ChangeReason::Insert);
}
void RemoveCommand::redo() {
m_data = m_buffer->read(m_offset, m_length); // Backup data
m_buffer->remove(m_offset, m_length);
}

View file

@ -0,0 +1,21 @@
#include <QHexView/model/commands/replacecommand.h>
#include <QHexView/model/qhexdocument.h>
ReplaceCommand::ReplaceCommand(QHexBuffer* buffer, QHexDocument* document,
qint64 offset, const QByteArray& data,
QUndoCommand* parent)
: HexCommand(buffer, document, parent) {
m_offset = offset;
m_data = data;
}
void ReplaceCommand::undo() {
m_buffer->replace(m_offset, m_olddata);
Q_EMIT m_hexdocument->dataChanged(m_olddata, m_offset,
QHexDocument::ChangeReason::Replace);
}
void ReplaceCommand::redo() {
m_olddata = m_buffer->read(m_offset, m_data.length());
m_buffer->replace(m_offset, m_data);
}

View file

@ -0,0 +1,182 @@
#include <QHexView/model/qhexcursor.h>
#include <QHexView/model/qhexdocument.h>
#include <QHexView/qhexview.h>
/*
* https://stackoverflow.com/questions/10803043/inverse-column-row-major-order-transformation
*
* If the index is calculated as:
* offset = row + column*NUMROWS
* then the inverse would be:
* row = offset % NUMROWS
* column = offset / NUMROWS
* where % is modulus, and / is integer division.
*/
QHexCursor::QHexCursor(const QHexOptions* options, QHexView* parent)
: QObject(parent), m_options(options) {}
QHexView* QHexCursor::hexView() const {
return qobject_cast<QHexView*>(this->parent());
}
QHexCursor::Mode QHexCursor::mode() const { return m_mode; }
qint64 QHexCursor::offset() const { return this->positionToOffset(m_position); }
qint64 QHexCursor::address() const {
return m_options->baseaddress + this->offset();
}
quint64 QHexCursor::lineAddress() const {
return m_options->baseaddress + (m_position.line * m_options->linelength);
}
qint64 QHexCursor::selectionStartOffset() const {
return this->positionToOffset(this->selectionStart());
}
qint64 QHexCursor::selectionEndOffset() const {
return this->positionToOffset(this->selectionEnd());
}
qint64 QHexCursor::line() const { return m_position.line; }
qint64 QHexCursor::column() const { return m_position.column; }
QHexPosition QHexCursor::selectionStart() const {
if(m_position.line < m_selection.line)
return m_position;
if(m_position.line == m_selection.line) {
if(m_position.column < m_selection.column)
return m_position;
}
return m_selection;
}
QHexPosition QHexCursor::selectionEnd() const {
if(m_position.line > m_selection.line)
return m_position;
if(m_position.line == m_selection.line) {
if(m_position.column > m_selection.column)
return m_position;
}
return m_selection;
}
qint64 QHexCursor::selectionLength() const {
auto selstart = this->selectionStartOffset(),
selend = this->selectionEndOffset();
return selstart == selend ? 0 : selend - selstart + 1;
}
QHexPosition QHexCursor::position() const { return m_position; }
QByteArray QHexCursor::selectedBytes() const {
return this->hexView()->selectedBytes();
}
bool QHexCursor::hasSelection() const { return m_position != m_selection; }
bool QHexCursor::isSelected(qint64 line, qint64 column) const {
if(!this->hasSelection())
return false;
auto selstart = this->selectionStart(), selend = this->selectionEnd();
if(line > selstart.line && line < selend.line)
return true;
if(line == selstart.line && line == selend.line)
return column >= selstart.column && column <= selend.column;
if(line == selstart.line)
return column >= selstart.column;
if(line == selend.line)
return column <= selend.column;
return false;
}
void QHexCursor::setMode(Mode m) {
if(m_mode == m)
return;
m_mode = m;
Q_EMIT modeChanged();
}
void QHexCursor::switchMode() {
switch(m_mode) {
case Mode::Insert: this->setMode(Mode::Overwrite); break;
case Mode::Overwrite: this->setMode(Mode::Insert); break;
}
}
void QHexCursor::move(qint64 offset) {
this->move(this->offsetToPosition(offset));
}
void QHexCursor::move(qint64 line, qint64 column) {
return this->move({line, column});
}
void QHexCursor::move(QHexPosition pos) {
if(pos.line >= 0)
m_selection.line = pos.line;
if(pos.column >= 0)
m_selection.column = pos.column;
this->select(pos);
}
void QHexCursor::select(qint64 offset) {
this->select(this->offsetToPosition(offset));
}
void QHexCursor::select(qint64 line, qint64 column) {
this->select({line, column});
}
void QHexCursor::select(QHexPosition pos) {
if(pos.line >= 0)
m_position.line = pos.line;
if(pos.column >= 0)
m_position.column = pos.column;
Q_EMIT positionChanged();
}
void QHexCursor::selectSize(qint64 length) {
if(length > 0)
length--;
else if(length < 0)
length++;
if(length)
this->select(this->offset() + length);
}
qint64 QHexCursor::replace(const QVariant& oldvalue, const QVariant& newvalue,
qint64 offset, QHexFindMode mode,
unsigned int options, QHexFindDirection fd) const {
return this->hexView()->replace(oldvalue, newvalue, offset, mode, options,
fd);
}
qint64 QHexCursor::find(const QVariant& value, qint64 offset, QHexFindMode mode,
unsigned int options, QHexFindDirection fd) const {
return this->hexView()->find(value, offset, mode, options, fd);
}
void QHexCursor::cut(bool hex) { this->hexView()->cut(hex); }
void QHexCursor::copy(bool hex) const { this->hexView()->copy(hex); }
void QHexCursor::paste(bool hex) { this->hexView()->paste(hex); }
void QHexCursor::selectAll() { this->hexView()->selectAll(); }
void QHexCursor::removeSelection() { this->hexView()->removeSelection(); }
void QHexCursor::clearSelection() {
m_position = m_selection;
Q_EMIT positionChanged();
}
qint64 QHexCursor::positionToOffset(QHexPosition pos) const {
return QHexUtils::positionToOffset(m_options, pos);
}
QHexPosition QHexCursor::offsetToPosition(qint64 offset) const {
return QHexUtils::offsetToPosition(m_options, offset);
}

View file

@ -0,0 +1,65 @@
#include <QHexView/model/qhexdelegate.h>
#include <QHexView/qhexview.h>
QHexDelegate::QHexDelegate(QObject* parent): QObject{parent} {}
QString QHexDelegate::addressHeader(const QHexView* hexview) const {
Q_UNUSED(hexview);
return QString();
}
QString QHexDelegate::hexHeader(const QHexView* hexview) const {
Q_UNUSED(hexview);
return QString();
}
QString QHexDelegate::asciiHeader(const QHexView* hexview) const {
Q_UNUSED(hexview);
return QString();
}
void QHexDelegate::renderAddress(quint64 address, QTextCharFormat& cf,
const QHexView* hexview) const {
Q_UNUSED(address);
Q_UNUSED(hexview);
Q_UNUSED(cf);
Q_UNUSED(hexview);
}
void QHexDelegate::renderHeader(QTextBlockFormat& bf,
const QHexView* hexview) const {
Q_UNUSED(bf);
Q_UNUSED(hexview);
}
void QHexDelegate::renderHeaderPart(const QString& s, QHexArea area,
QTextCharFormat& cf,
const QHexView* hexview) const {
Q_UNUSED(s);
Q_UNUSED(area);
Q_UNUSED(cf);
Q_UNUSED(hexview);
}
bool QHexDelegate::render(quint64 offset, quint8 b, QTextCharFormat& outcf,
const QHexView* hexview) const {
Q_UNUSED(offset);
Q_UNUSED(b);
Q_UNUSED(outcf);
Q_UNUSED(hexview);
return false;
}
bool QHexDelegate::paintSeparator(QPainter* painter, QLineF line,
const QHexView* hexview) const {
Q_UNUSED(painter);
Q_UNUSED(line);
Q_UNUSED(hexview);
return false;
}
void QHexDelegate::paint(QPainter* painter, const QHexView* hexview) const {
Q_UNUSED(hexview);
hexview->paint(painter);
}

View file

@ -0,0 +1,142 @@
#include <QBuffer>
#include <QFile>
#include <QHexView/model/buffer/qdevicebuffer.h>
#include <QHexView/model/buffer/qmappedfilebuffer.h>
#include <QHexView/model/buffer/qmemorybuffer.h>
#include <QHexView/model/commands/insertcommand.h>
#include <QHexView/model/commands/removecommand.h>
#include <QHexView/model/commands/replacecommand.h>
#include <QHexView/model/qhexdocument.h>
#include <cmath>
QHexDocument::QHexDocument(QHexBuffer* buffer, QObject* parent)
: QObject(parent) {
m_buffer = buffer;
m_buffer->setParent(this); // Take Ownership
connect(&m_undostack, &QUndoStack::canUndoChanged, this,
&QHexDocument::canUndoChanged);
connect(&m_undostack, &QUndoStack::canRedoChanged, this,
&QHexDocument::canRedoChanged);
connect(&m_undostack, &QUndoStack::cleanChanged, this,
[&](bool clean) { Q_EMIT modifiedChanged(!clean); });
}
qint64 QHexDocument::indexOf(const QByteArray& ba, qint64 from) {
return m_buffer->indexOf(ba, from);
}
qint64 QHexDocument::lastIndexOf(const QByteArray& ba, qint64 from) {
return m_buffer->lastIndexOf(ba, from);
}
bool QHexDocument::accept(qint64 idx) const { return m_buffer->accept(idx); }
bool QHexDocument::isEmpty() const { return m_buffer->isEmpty(); }
bool QHexDocument::isModified() const { return !m_undostack.isClean(); }
bool QHexDocument::canUndo() const { return m_undostack.canUndo(); }
bool QHexDocument::canRedo() const { return m_undostack.canRedo(); }
void QHexDocument::setData(const QByteArray& ba) {
QHexBuffer* mb = new QMemoryBuffer();
mb->read(ba);
this->setData(mb);
}
void QHexDocument::setData(QHexBuffer* buffer) {
if(!buffer)
return;
m_undostack.clear();
buffer->setParent(this);
auto* oldbuffer = m_buffer;
m_buffer = buffer;
if(oldbuffer)
oldbuffer->deleteLater();
Q_EMIT canUndoChanged(false);
Q_EMIT canRedoChanged(false);
Q_EMIT changed();
Q_EMIT reset();
}
void QHexDocument::clearModified() { m_undostack.setClean(); }
qint64 QHexDocument::length() const {
return m_buffer ? m_buffer->length() : 0;
}
uchar QHexDocument::at(int offset) const { return m_buffer->at(offset); }
QHexDocument* QHexDocument::fromFile(QString filename, QObject* parent) {
QFile f(filename);
f.open(QFile::ReadOnly);
return QHexDocument::fromMemory<QMemoryBuffer>(f.readAll(), parent);
}
void QHexDocument::undo() {
m_undostack.undo();
Q_EMIT changed();
}
void QHexDocument::redo() {
m_undostack.redo();
Q_EMIT changed();
}
void QHexDocument::insert(qint64 offset, uchar b) {
this->insert(offset, QByteArray(1, b));
}
void QHexDocument::replace(qint64 offset, uchar b) {
this->replace(offset, QByteArray(1, b));
}
void QHexDocument::insert(qint64 offset, const QByteArray& data) {
m_undostack.push(new InsertCommand(m_buffer, this, offset, data));
Q_EMIT changed();
Q_EMIT dataChanged(data, offset, ChangeReason::Insert);
}
void QHexDocument::replace(qint64 offset, const QByteArray& data) {
m_undostack.push(new ReplaceCommand(m_buffer, this, offset, data));
Q_EMIT changed();
Q_EMIT dataChanged(data, offset, ChangeReason::Replace);
}
void QHexDocument::remove(qint64 offset, int len) {
QByteArray data = m_buffer->read(offset, len);
m_undostack.push(new RemoveCommand(m_buffer, this, offset, len));
Q_EMIT changed();
Q_EMIT dataChanged(data, offset, ChangeReason::Remove);
}
QByteArray QHexDocument::read(qint64 offset, int len) const {
return m_buffer->read(offset, len);
}
bool QHexDocument::saveTo(QIODevice* device) {
if(!device->isWritable())
return false;
m_buffer->write(device);
return true;
}
QHexDocument* QHexDocument::fromBuffer(QHexBuffer* buffer, QObject* parent) {
return new QHexDocument(buffer, parent);
}
QHexDocument* QHexDocument::fromLargeFile(QString filename, QObject* parent) {
return QHexDocument::fromDevice<QDeviceBuffer>(new QFile(filename), parent);
}
QHexDocument* QHexDocument::fromMappedFile(QString filename, QObject* parent) {
return QHexDocument::fromDevice<QMappedFileBuffer>(new QFile(filename),
parent);
}
QHexDocument* QHexDocument::create(QObject* parent) {
return QHexDocument::fromMemory<QMemoryBuffer>({}, parent);
}

View file

@ -0,0 +1,158 @@
#include <QHexView/model/qhexcursor.h>
#include <QHexView/model/qhexmetadata.h>
QHexMetadata::QHexMetadata(const QHexOptions* options, QObject* parent)
: QObject(parent), m_options(options) {}
const QHexMetadataLine* QHexMetadata::find(qint64 line) const {
auto it = m_metadata.find(line);
return it != m_metadata.end() ? std::addressof(it.value()) : nullptr;
}
QString QHexMetadata::getComment(qint64 line, qint64 column) const {
auto* metadataline = this->find(line);
if(!metadataline)
return QString();
auto offset = QHexUtils::positionToOffset(m_options, {line, column});
QStringList comments;
for(auto& mi : *metadataline) {
if((offset < mi.begin || offset > mi.end) || mi.comment.isEmpty())
continue;
comments.push_back(mi.comment);
}
return comments.join("\n");
}
void QHexMetadata::removeMetadata(qint64 line) {
auto it = m_metadata.find(line);
if(it == m_metadata.end())
return;
m_metadata.erase(it);
Q_EMIT changed();
}
void QHexMetadata::removeBackground(qint64 line) {
this->clearMetadata(line, [](QHexMetadataItem& mi) -> bool {
if(!mi.background.isValid())
return false;
if(mi.foreground.isValid() || !mi.comment.isEmpty()) {
mi.background = QColor();
return false;
}
return true;
});
}
void QHexMetadata::removeForeground(qint64 line) {
this->clearMetadata(line, [](QHexMetadataItem& mi) -> bool {
if(!mi.foreground.isValid())
return false;
if(mi.background.isValid() || !mi.comment.isEmpty()) {
mi.foreground = QColor();
return false;
}
return true;
});
}
void QHexMetadata::removeComments(qint64 line) {
this->clearMetadata(line, [](QHexMetadataItem& mi) -> bool {
if(mi.comment.isEmpty())
return false;
if(mi.foreground.isValid() || mi.background.isValid()) {
mi.comment.clear();
return false;
}
return true;
});
}
void QHexMetadata::unhighlight(qint64 line) {
this->clearMetadata(line, [](QHexMetadataItem& mi) -> bool {
if(!mi.foreground.isValid() && !mi.background.isValid())
return false;
if(!mi.comment.isEmpty()) {
mi.foreground = QColor();
mi.background = QColor();
return false;
}
return true;
});
}
void QHexMetadata::clear() {
m_metadata.clear();
Q_EMIT changed();
}
void QHexMetadata::copy(const QHexMetadata* metadata) {
m_metadata = metadata->m_metadata;
}
void QHexMetadata::clearMetadata(qint64 line, ClearMetadataCallback&& cb) {
auto iit = m_metadata.find(line);
if(iit == m_metadata.end())
return;
auto oldsize = iit->size();
for(auto it = iit->begin(); it != iit->end();) {
if(cb(*it))
it = iit->erase(it);
else
it++;
}
if(iit->empty()) {
this->removeMetadata(line);
return;
}
if(oldsize != iit->size())
Q_EMIT changed();
}
void QHexMetadata::setMetadata(const QHexMetadataItem& mi) {
if(!m_options->linelength)
return;
const qint64 firstline = mi.begin / m_options->linelength;
const qint64 lastline = mi.end / m_options->linelength;
bool notify = false;
for(auto line = firstline; line <= lastline; line++) {
auto start = line == firstline ? mi.begin % m_options->linelength : 0;
auto length = line == lastline
? (mi.end % m_options->linelength) - start
: m_options->linelength;
if(length <= 0)
continue;
notify = true;
m_metadata[line].push_back(mi);
}
if(notify)
Q_EMIT changed();
}
void QHexMetadata::invalidate() {
auto oldmetadata = m_metadata;
m_metadata.clear();
for(const QHexMetadataLine& line : oldmetadata)
for(const QHexMetadataItem& mi : line)
this->setMetadata(mi);
}

View file

@ -0,0 +1,384 @@
#include <QDataStream>
#include <QGlobalStatic>
#include <QHash>
#include <QHexView/model/qhexoptions.h>
#include <QHexView/model/qhexutils.h>
#include <QHexView/qhexview.h>
#include <QList>
#include <QtEndian>
#include <limits>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#define QHEXVIEW_VARIANT_EQ(x, t) ((x).metaType().id() == QMetaType::Q##t)
#else
#define QHEXVIEW_VARIANT_EQ(x, t) ((x).type() == QVariant::t)
#endif
#if defined(_WIN32) && _MSC_VER <= 1916 // v141_xp
#include <ctype.h>
namespace std {
using ::tolower;
}
#else
#include <cctype>
#endif
namespace QHexUtils {
Q_GLOBAL_STATIC_WITH_ARGS(QList<char>, HEXMAP,
({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'}));
bool isHex(char ch) {
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f');
}
namespace PatternUtils {
Q_GLOBAL_STATIC_WITH_ARGS(QString, WILDCARD_BYTE, ("??"))
bool check(QString& p, qint64& len) {
static QHash<QString, QPair<QString, size_t>>
processed; // Cache processed patterns
auto it = processed.find(p);
if(it != processed.end()) {
p = it.value().first;
len = it.value().second;
return true;
}
QString op = p; // Store unprocessed pattern
p = p.simplified().replace(" ", "");
if(p.isEmpty() || (p.size() % 2))
return false;
int wccount = 0;
for(auto i = 0; i < p.size() - 2; i += 2) {
const auto& hexb = p.mid(i, 2);
if(hexb == *WILDCARD_BYTE) {
wccount++;
continue;
}
if(!QHexUtils::isHex(hexb.at(0).toLatin1()) ||
!QHexUtils::isHex(hexb.at(1).toLatin1()))
return false;
}
if(wccount >= p.size())
return false;
len = p.size() / 2;
processed[op] = qMakePair(p, len); // Cache processed pattern
return true;
}
bool match(const QByteArray& data, const QString& pattern) {
for(qint64 i = 0, idx = 0; (i <= (pattern.size() - 2)); i += 2, idx++) {
if(idx >= data.size())
return false;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringView hexb = QStringView{pattern}.mid(i, 2);
#else
const QStringRef& hexb = pattern.midRef(i, 2);
#endif
if(hexb == *WILDCARD_BYTE)
continue;
bool ok = false;
auto b = static_cast<char>(hexb.toUInt(&ok, 16));
if(!ok || (b != data.at(idx)))
return false;
}
return true;
}
} // namespace PatternUtils
namespace {
unsigned int countBits(uint val) {
if(val <= std::numeric_limits<quint8>::max())
return QHexFindOptions::Int8;
if(val <= std::numeric_limits<quint16>::max())
return QHexFindOptions::Int16;
if(val <= std::numeric_limits<quint32>::max())
return QHexFindOptions::Int32;
return QHexFindOptions::Int64;
}
template<typename Function>
qint64 findIter(qint64 startoffset, QHexFindDirection fd,
const QHexView* hexview, Function&& f) {
QHexDocument* hexdocument = hexview->hexDocument();
qint64 offset = -1;
QHexFindDirection cfd = fd;
if(cfd == QHexFindDirection::All)
cfd = QHexFindDirection::Forward;
qint64 i = startoffset;
bool restartLoopOnce = true;
while(offset == -1 &&
(cfd == QHexFindDirection::Backward ? (i >= 0)
: (i < hexdocument->length()))) {
if(!f(i, offset))
break;
if(cfd == QHexFindDirection::Backward)
i--;
else
i++;
if(fd == QHexFindDirection::All && i >= hexdocument->length() &&
restartLoopOnce) {
i = 0;
restartLoopOnce = false;
}
}
return offset;
}
qint64 findDefault(const QByteArray& value, qint64 startoffset,
const QHexView* hexview, unsigned int options,
QHexFindDirection fd) {
QHexDocument* hexdocument = hexview->hexDocument();
if(value.size() > hexdocument->length())
return -1;
return findIter(
startoffset, fd, hexview,
[options, value, hexdocument](qint64 idx, qint64& offset) -> bool {
for(auto i = 0; i < value.size(); i++) {
qint64 curroffset = idx + i;
if(curroffset >= hexdocument->length()) {
offset = -1;
return false;
}
uchar ch1 = hexdocument->at(curroffset);
uchar ch2 = value.at(i);
if(!(options & QHexFindOptions::CaseSensitive)) {
ch1 = std::tolower(ch1);
ch2 = std::tolower(ch2);
}
if(ch1 != ch2)
break;
if(i == value.size() - 1)
offset = idx;
}
return true;
});
}
qint64 findWildcard(QString pattern, qint64 startoffset,
const QHexView* hexview, QHexFindDirection fd,
qint64& patternlen) {
QHexDocument* hexdocument = hexview->hexDocument();
if(!PatternUtils::check(pattern, patternlen) ||
(patternlen >= hexdocument->length()))
return -1;
return findIter(
startoffset, fd, hexview,
[hexdocument, pattern, patternlen](qint64 idx, qint64& offset) -> bool {
if(PatternUtils::match(hexdocument->read(idx, patternlen), pattern))
offset = idx;
return true;
});
}
QByteArray variantToByteArray(QVariant value, QHexFindMode mode,
unsigned int options) {
QByteArray v;
switch(mode) {
case QHexFindMode::Text:
if(QHEXVIEW_VARIANT_EQ(value, String))
v = value.toString().toUtf8();
else if(QHEXVIEW_VARIANT_EQ(value, ByteArray))
v = value.toByteArray();
break;
case QHexFindMode::Hex: {
if(QHEXVIEW_VARIANT_EQ(value, String)) {
qint64 len = 0;
auto s = value.toString();
if(!PatternUtils::check(s, len))
return {};
bool ok = true;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
for(auto i = 0; ok && i < s.size(); i += 2)
v.push_back(static_cast<char>(
QStringView{s}.mid(i, 2).toUInt(&ok, 16)));
#else
for(auto i = 0; ok && i < s.size(); i += 2)
v.push_back(
static_cast<char>(s.midRef(i, 2).toUInt(&ok, 16)));
#endif
if(!ok)
return {};
}
else if(QHEXVIEW_VARIANT_EQ(value, ByteArray))
v = value.toByteArray();
break;
}
case QHexFindMode::Int: {
bool ok = false;
uint val = value.toUInt(&ok);
if(!ok)
return QByteArray{};
QDataStream ds(&v, QIODevice::WriteOnly);
if(options & QHexFindOptions::BigEndian) {
if(options & QHexFindOptions::Int8)
ds << qToBigEndian<quint8>(val);
else if(options & QHexFindOptions::Int16)
ds << qToBigEndian<quint16>(val);
else if(options & QHexFindOptions::Int32)
ds << qToBigEndian<quint32>(val);
else if(options & QHexFindOptions::Int64)
ds << qToBigEndian<quint64>(val);
else
return variantToByteArray(value, mode,
options | countBits(val));
}
else {
if(options & QHexFindOptions::Int8)
ds << static_cast<quint8>(val);
else if(options & QHexFindOptions::Int16)
ds << static_cast<quint16>(val);
else if(options & QHexFindOptions::Int32)
ds << static_cast<quint32>(val);
else if(options & QHexFindOptions::Int64)
ds << static_cast<quint64>(val);
else
return variantToByteArray(value, mode,
options | countBits(val));
}
break;
}
case QHexFindMode::Float: {
bool ok = false;
QDataStream ds(&v, QIODevice::WriteOnly);
if(options & QHexFindOptions::Float)
ds << value.toFloat(&ok);
else if(options & QHexFindOptions::Double)
ds << value.toDouble(&ok);
if(!ok)
return {};
}
default: break;
}
return v;
}
} // namespace
QByteArray toHex(const QByteArray& ba, char sep) {
if(ba.isEmpty()) {
return QByteArray();
}
QByteArray hex(sep ? (ba.size() * 3 - 1) : (ba.size() * 2),
Qt::Uninitialized);
for(auto i = 0, o = 0; i < ba.size(); i++) {
if(sep && i)
hex[o++] = static_cast<uchar>(sep);
hex[o++] = HEXMAP->at((ba.at(i) & 0xf0) >> 4);
hex[o++] = HEXMAP->at(ba.at(i) & 0x0f);
}
return hex;
}
QByteArray toHex(const QByteArray& ba) { return QHexUtils::toHex(ba, '\0'); }
qint64 positionToOffset(const QHexOptions* options, QHexPosition pos) {
return options->linelength * pos.line + pos.column;
}
QHexPosition offsetToPosition(const QHexOptions* options, qint64 offset) {
return {offset / options->linelength, offset % options->linelength};
}
QPair<qint64, qint64> find(const QHexView* hexview, QVariant value,
qint64 startoffset, QHexFindMode mode,
unsigned int options, QHexFindDirection fd) {
qint64 offset = -1, size = 0;
if(startoffset == -1)
startoffset = static_cast<qint64>(hexview->offset());
if(mode == QHexFindMode::Hex && QHEXVIEW_VARIANT_EQ(value, String)) {
offset = QHexUtils::findWildcard(value.toString(), startoffset, hexview,
fd, size);
}
else {
auto ba = variantToByteArray(value, mode, options);
if(!ba.isEmpty()) {
offset =
QHexUtils::findDefault(ba, startoffset, hexview, options, fd);
size = ba.size();
}
else
offset = -1;
}
return {offset, offset > -1 ? size : 0};
}
bool checkPattern(QString pattern) {
qint64 len = 0;
return PatternUtils::check(pattern, len);
}
QPair<qint64, qint64> replace(const QHexView* hexview, QVariant oldvalue,
QVariant newvalue, qint64 startoffset,
QHexFindMode mode, unsigned int options,
QHexFindDirection fd) {
auto res =
QHexUtils::find(hexview, oldvalue, startoffset, mode, options, fd);
if(res.first != -1 && res.second > 0) {
QHexDocument* hexdocument = hexview->hexDocument();
auto ba = variantToByteArray(newvalue, mode, options);
if(!ba.isEmpty()) {
hexdocument->remove(res.first, res.second);
hexdocument->insert(res.first, ba);
res.second = ba.size();
}
else {
res.first = -1;
res.second = 0;
}
}
return res;
}
} // namespace QHexUtils

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,32 @@
/* fssfinder.cpp /* ffsfinder.cpp
Copyright (c) 2015, Nikolaj Schlej. All rights reserved. Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include "ffsfinder.h" #include "ffsfinder.h"
#if QT_VERSION_MAJOR >= 6
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
USTATUS FfsFinder::findHexPattern(const UByteArray & hexPattern, const UINT8 mode) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findHexPattern(rootIndex, hexPattern, mode);
if (ret != U_SUCCESS)
msg(UString("Hex pattern \"") + UString(hexPattern) + UString("\" could not be found"), rootIndex);
return ret;
}
USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode) USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode)
{ {
if (!index.isValid()) if (!index.isValid())
@ -25,40 +39,80 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
if (hexPattern.count('.') == hexPattern.length()) if (hexPattern.count('.') == hexPattern.length())
return U_SUCCESS; return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0); bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) { for (int i = 0; i < model->rowCount(index); i++) {
findHexPattern(index.child(i, index.column()), hexPattern, mode); if (U_SUCCESS == findHexPattern(index.model()->index(i, index.column(), index), hexPattern, mode))
ret = U_SUCCESS;
} }
UByteArray data; UByteArray data;
if (hasChildren) { if (hasChildren) {
if (mode != SEARCH_MODE_BODY) if (mode == SEARCH_MODE_HEADER)
data = model->header(index); data = model->header(index);
else if (mode == SEARCH_MODE_ALL)
data = model->header(index) + model->body(index);
} }
else { else {
if (mode == SEARCH_MODE_HEADER) if (mode == SEARCH_MODE_HEADER)
data.append(model->header(index)); data = model->header(index);
else if (mode == SEARCH_MODE_BODY) else if (mode == SEARCH_MODE_BODY)
data.append(model->body(index)); data = model->body(index);
else else
data.append(model->header(index)).append(model->body(index)); data = model->header(index) + model->body(index);
} }
UString hexBody = UString(data.toHex()); UString hexBody = UString(data.toHex());
#if QT_VERSION_MAJOR >= 6
QRegularExpression regexp = QRegularExpression(UString(hexPattern));
regexp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch regexpmatch;
INT32 offset = (INT32)hexBody.indexOf(regexp, 0, &regexpmatch);
#else
QRegExp regexp = QRegExp(UString(hexPattern), Qt::CaseInsensitive); QRegExp regexp = QRegExp(UString(hexPattern), Qt::CaseInsensitive);
INT32 offset = regexp.indexIn(hexBody); INT32 offset = regexp.indexIn(hexBody);
#endif
while (offset >= 0) { while (offset >= 0) {
if (offset % 2 == 0) { if (offset % 2 == 0) {
msg(UString("Hex pattern \"") + UString(hexPattern) // For patterns that cross header|body boundary, skip patterns entirely located in body, since
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper() // children search above has already found them.
+ UString("\" in ") + model->name(index) if (!(hasChildren && mode == SEARCH_MODE_ALL && offset/2 >= model->header(index).size())) {
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2), UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
index); UString name = model->name(index);
if (model->parent(index) == parentFileIndex) {
name = model->name(parentFileIndex) + UString("/") + name;
} }
offset = regexp.indexIn(hexBody, offset + 1); else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
} }
return U_SUCCESS; msg(UString("Hex pattern \"") + UString(hexPattern)
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
+ UString("\" in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index);
ret = U_SUCCESS;
}
}
#if QT_VERSION_MAJOR >= 6
offset = (INT32)hexBody.indexOf(regexp, (qsizetype)offset + 1, &regexpmatch);
#else
offset = regexp.indexIn(hexBody, offset + 1);
#endif
}
return ret;
}
USTATUS FfsFinder::findGuidPattern(const UByteArray & guidPattern, const UINT8 mode) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findGuidPattern(rootIndex, guidPattern, mode);
if (ret != U_SUCCESS)
msg(UString("GUID pattern \"") + UString(guidPattern) + UString("\" could not be found"), rootIndex);
return ret;
} }
USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode) USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode)
@ -69,9 +123,11 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
if (!index.isValid()) if (!index.isValid())
return U_SUCCESS; return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0); bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) { for (int i = 0; i < model->rowCount(index); i++) {
findGuidPattern(index.child(i, index.column()), guidPattern, mode); if (U_SUCCESS == findGuidPattern(index.model()->index(i, index.column(), index), guidPattern, mode))
ret = U_SUCCESS;
} }
UByteArray data; UByteArray data;
@ -112,20 +168,53 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
if (hexPattern.count('.') == hexPattern.length()) if (hexPattern.count('.') == hexPattern.length())
return U_SUCCESS; return U_SUCCESS;
#if QT_VERSION_MAJOR >= 6
QRegularExpression regexp((QString)UString(hexPattern));
regexp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch regexpmatch;
INT32 offset = (INT32)hexBody.indexOf(regexp, 0, &regexpmatch);
#else
QRegExp regexp(UString(hexPattern), Qt::CaseInsensitive); QRegExp regexp(UString(hexPattern), Qt::CaseInsensitive);
INT32 offset = regexp.indexIn(hexBody); INT32 offset = regexp.indexIn(hexBody);
#endif
while (offset >= 0) { while (offset >= 0) {
if (offset % 2 == 0) { if (offset % 2 == 0) {
msg(UString("GUID pattern \"") + UString(guidPattern) UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper() UString name = model->name(index);
+ UString("\" in ") + model->name(index) if (model->parent(index) == parentFileIndex) {
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2), name = model->name(parentFileIndex) + UString("/") + name;
index);
} }
offset = regexp.indexIn(hexBody, offset + 1); else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
} }
return U_SUCCESS; msg(UString("GUID pattern \"") + UString(guidPattern)
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
+ UString("\" in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
index);
ret = U_SUCCESS;
}
#if QT_VERSION_MAJOR >= 6
offset = (INT32)hexBody.indexOf(regexp, (qsizetype)offset + 1, &regexpmatch);
#else
offset = regexp.indexIn(hexBody, offset + 1);
#endif
}
return ret;
}
USTATUS FfsFinder::findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive) {
const UModelIndex rootIndex = model->index(0, 0);
USTATUS ret = findTextPattern(rootIndex, pattern, mode, unicode, caseSensitive);
if (ret != U_SUCCESS)
msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"")
+ UString(pattern) + UString("\" could not be found"), rootIndex);
return ret;
} }
USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive) USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive)
@ -136,9 +225,11 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
if (!index.isValid()) if (!index.isValid())
return U_SUCCESS; return U_SUCCESS;
USTATUS ret = U_ITEM_NOT_FOUND;
bool hasChildren = (model->rowCount(index) > 0); bool hasChildren = (model->rowCount(index) > 0);
for (int i = 0; i < model->rowCount(index); i++) { for (int i = 0; i < model->rowCount(index); i++) {
findTextPattern(index.child(i, index.column()), pattern, mode, unicode, caseSensitive); if (U_SUCCESS == findTextPattern(index.model()->index(i, index.column(), index), pattern, mode, unicode, caseSensitive))
ret = U_SUCCESS;
} }
UByteArray body; UByteArray body;
@ -155,20 +246,31 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
body.append(model->header(index)).append(model->body(index)); body.append(model->header(index)).append(model->body(index));
} }
UString data; UString data = UString::fromLatin1((const char*)body.constData(), body.length());
UString searchPattern;
if (unicode) if (unicode)
data = UString::fromUtf16((const ushort*)body.constData(), body.length() / 2); searchPattern = UString::fromLatin1((const char*)pattern.utf16(), pattern.length() * 2);
else else
data = UString::fromLatin1((const char*)body.constData(), body.length()); searchPattern = pattern;
int offset = -1; int offset = -1;
while ((offset = data.indexOf(pattern, offset + 1, caseSensitive)) >= 0) { while ((offset = (int)data.indexOf(searchPattern, (int)(offset + 1), caseSensitive)) >= 0) {
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"") + UString(pattern) UString name = model->name(index);
+ UString("\" found in ") + model->name(index) if (model->parent(index) == parentFileIndex) {
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", (unicode ? offset * 2 : offset)), name = model->name(parentFileIndex) + UString("/") + name;
index); }
else if (parentFileIndex.isValid()) {
name = model->name(parentFileIndex) + UString("/.../") + name;
} }
return U_SUCCESS; msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"") + UString(pattern)
+ UString("\" found in ") + name
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset),
index);
ret = U_SUCCESS;
}
return ret;
} }

View file

@ -15,7 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define FFSFINDER_H #define FFSFINDER_H
#include <vector> #include <vector>
#include <QRegExp>
#include "../common/ubytearray.h" #include "../common/ubytearray.h"
#include "../common/ustring.h" #include "../common/ustring.h"
@ -31,9 +30,9 @@ public:
std::vector<std::pair<UString, UModelIndex> > getMessages() const { return messagesVector; } std::vector<std::pair<UString, UModelIndex> > getMessages() const { return messagesVector; }
void clearMessages() { messagesVector.clear(); } void clearMessages() { messagesVector.clear(); }
USTATUS findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode); USTATUS findHexPattern(const UByteArray & hexPattern, const UINT8 mode);
USTATUS findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode); USTATUS findGuidPattern(const UByteArray & guidPattern, const UINT8 mode);
USTATUS findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive); USTATUS findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
private: private:
const TreeModel* model; const TreeModel* model;
@ -42,6 +41,10 @@ private:
void msg(const UString & message, const UModelIndex &index = UModelIndex()) { void msg(const UString & message, const UModelIndex &index = UModelIndex()) {
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index)); messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
} }
USTATUS findHexPattern(const UModelIndex & index, const UByteArray & hexPattern, const UINT8 mode);
USTATUS findGuidPattern(const UModelIndex & index, const UByteArray & guidPattern, const UINT8 mode);
USTATUS findTextPattern(const UModelIndex & index, const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
}; };
#endif // FFSFINDER_H #endif // FFSFINDER_H

View file

@ -0,0 +1,36 @@
/* gotoaddressdialog.h
Copyright (c) 2018, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#ifndef GOTOADDRESSDIALOG_H
#define GOTOADDRESSDIALOG_H
#include <QObject>
#include <QDialog>
#include "ui_gotoaddressdialog.h"
class GoToAddressDialog : public QDialog
{
Q_OBJECT
public:
GoToAddressDialog(QWidget* parent = NULL) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
ui(new Ui::GoToAddressDialog) {
ui->setupUi(this);
}
~GoToAddressDialog() { delete ui; }
Ui::GoToAddressDialog* ui;
};
#endif // GOTOADDRESSDIALOG_H

View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GoToAddressDialog</class>
<widget class="QDialog" name="GoToAddressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>86</height>
</rect>
</property>
<property name="windowTitle">
<string>Select item at address</string>
</property>
<property name="modal">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select item at address:</string>
</property>
</widget>
</item>
<item>
<widget class="HexSpinBox" name="hexSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HexSpinBox</class>
<extends>QSpinBox</extends>
<header>hexspinbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GoToAddressDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>194</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GoToAddressDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>194</y>
</hint>
</hints>
</connection>
</connections>
</ui>

36
UEFITool/gotobasedialog.h Normal file
View file

@ -0,0 +1,36 @@
/* gotobasedialog.h
Copyright (c) 2018, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#ifndef GOTOBASEDIALOG_H
#define GOTOBASEDIALOG_H
#include <QObject>
#include <QDialog>
#include "ui_gotobasedialog.h"
class GoToBaseDialog : public QDialog
{
Q_OBJECT
public:
GoToBaseDialog(QWidget* parent = NULL):
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
ui(new Ui::GoToBaseDialog) {
ui->setupUi(this);
}
~GoToBaseDialog() {delete ui;}
Ui::GoToBaseDialog* ui;
};
#endif // GOTOBASEDIALOG_H

133
UEFITool/gotobasedialog.ui Normal file
View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GoToBaseDialog</class>
<widget class="QDialog" name="GoToBaseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>86</height>
</rect>
</property>
<property name="windowTitle">
<string>Select item at base</string>
</property>
<property name="modal">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select item at base:</string>
</property>
</widget>
</item>
<item>
<widget class="HexSpinBox" name="hexSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HexSpinBox</class>
<extends>QSpinBox</extends>
<header>hexspinbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GoToBaseDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>194</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GoToBaseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>194</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -1,61 +0,0 @@
/* guidlineedit.cpp
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "guidlineedit.h"
GuidLineEdit::GuidLineEdit(QWidget * parent)
:QLineEdit(parent)
{
}
GuidLineEdit::GuidLineEdit(const QString & contents, QWidget * parent)
:QLineEdit(contents, parent)
{
}
GuidLineEdit::~GuidLineEdit()
{
}
void GuidLineEdit::keyPressEvent(QKeyEvent * event)
{
if (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace)
{
int pos = cursorPosition();
if (event->key() == Qt::Key_Backspace && pos > 0) {
cursorBackward(false);
pos = cursorPosition();
}
QString txt = text();
QString selected = selectedText();
if (!selected.isEmpty()) {
pos = QLineEdit::selectionStart();
for (int i = pos; i < pos + selected.count(); i++)
if (txt[i] != QChar('-'))
txt[i] = QChar('.');
}
else
txt[pos] = QChar('.');
setCursorPosition(0);
insert(txt);
setCursorPosition(pos);
return;
}
// Call original event handler
QLineEdit::keyPressEvent(event);
}

86
UEFITool/hexlineedit.cpp Normal file
View file

@ -0,0 +1,86 @@
/* hexlineedit.cpp
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "hexlineedit.h"
#if QT_VERSION_MAJOR >= 6
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
HexLineEdit::HexLineEdit(QWidget * parent)
:QLineEdit(parent)
{
m_editAsGuid = false;
}
HexLineEdit::HexLineEdit(const QString & contents, QWidget * parent)
:QLineEdit(contents, parent)
{
m_editAsGuid = false;
}
HexLineEdit::~HexLineEdit()
{
}
void HexLineEdit::keyPressEvent(QKeyEvent * event)
{
QClipboard *clipboard;
QString originalText;
if (m_editAsGuid && (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace))
{
int pos = cursorPosition();
if (event->key() == Qt::Key_Backspace && pos > 0) {
cursorBackward(false);
pos = cursorPosition();
}
QString txt = text();
QString selected = selectedText();
if (!selected.isEmpty()) {
pos = QLineEdit::selectionStart();
for (int i = pos; i < pos + selected.length(); i++)
if (txt[i] != QChar('-'))
txt[i] = QChar('.');
}
else {
txt[pos] = QChar('.');
}
setCursorPosition(0);
insert(txt);
setCursorPosition(pos);
return;
}
if (event == QKeySequence::Paste)
{
clipboard = QApplication::clipboard();
originalText = clipboard->text();
QString cleanedHex = QString(originalText).replace(QString("0x"), QString(""), Qt::CaseInsensitive);
#if QT_VERSION_MAJOR >= 6
cleanedHex.remove(QRegularExpression("[^a-fA-F\\d]+"));
#else
cleanedHex.remove(QRegExp("[^a-fA-F\\d]+"));
#endif
clipboard->setText(cleanedHex);
}
// Call original event handler
QLineEdit::keyPressEvent(event);
}

View file

@ -1,4 +1,4 @@
/* guidlineedit.h /* hexlineedit.h
Copyright (c) 2014, Nikolaj Schlej. All rights reserved. Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
@ -11,9 +11,11 @@
*/ */
#ifndef GUIDLINEEDIT_H #ifndef HEXLINEEDIT_H
#define GUIDLINEEDIT_H #define HEXLINEEDIT_H
#include <QApplication>
#include <QClipboard>
#include <QLineEdit> #include <QLineEdit>
#include <QKeyEvent> #include <QKeyEvent>
#include <QKeySequence> #include <QKeySequence>
@ -21,16 +23,29 @@
#include "../common/basetypes.h" #include "../common/basetypes.h"
class GuidLineEdit : public QLineEdit class HexLineEdit : public QLineEdit
{ {
Q_OBJECT
Q_PROPERTY(bool editAsGuid READ editAsGuid WRITE setEditAsGuid)
public: public:
GuidLineEdit(QWidget * parent = 0); HexLineEdit(QWidget * parent = 0);
GuidLineEdit(const QString & contents, QWidget * parent = 0); HexLineEdit(const QString & contents, QWidget * parent = 0);
~GuidLineEdit(); ~HexLineEdit();
void setEditAsGuid(bool editAsGuid)
{
m_editAsGuid = editAsGuid;
}
bool editAsGuid() const
{ return m_editAsGuid; }
private:
bool m_editAsGuid;
protected: protected:
void keyPressEvent(QKeyEvent * event); void keyPressEvent(QKeyEvent * event);
}; };
#endif // GUIDLINEEDIT_H #endif // HEXLINEEDIT_H

41
UEFITool/hexspinbox.cpp Normal file
View file

@ -0,0 +1,41 @@
/* hexspinbox.cpp
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "hexspinbox.h"
#include <QDebug>
HexSpinBox::HexSpinBox(QWidget *parent) :
#if QT_VERSION_MAJOR >= 6
QSpinBox(parent), validator(QRegularExpression("0x([0-9a-fA-F]){1,8}"))
#else
QSpinBox(parent), validator(QRegExp("0x([0-9a-fA-F]){1,8}"))
#endif
{
this->setRange(INT_MIN, INT_MAX);
this->setPrefix("0x");
}
QValidator::State HexSpinBox::validate(QString &text, int &pos) const
{
return validator.validate(text, pos);
}
QString HexSpinBox::textFromValue(int val) const
{
return QString::number((uint)val, 16).toUpper();
}
int HexSpinBox::valueFromText(const QString &text) const
{
return (int)text.toUInt(NULL, 16);
}

45
UEFITool/hexspinbox.h Normal file
View file

@ -0,0 +1,45 @@
/* hexspinbox.h
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#ifndef HEXSPINBOX_H
#define HEXSPINBOX_H
#include <QSpinBox>
#if QT_VERSION_MAJOR >= 6
#include <QRegularExpressionValidator>
#else
#include <QRegExpValidator>
#endif
class HexSpinBox : public QSpinBox
{
Q_OBJECT
public:
HexSpinBox(QWidget *parent = 0);
protected:
QValidator::State validate(QString &text, int &pos) const;
int valueFromText(const QString &text) const;
QString textFromValue(int value) const;
private:
#if QT_VERSION_MAJOR >= 6
QRegularExpressionValidator validator;
#else
QRegExpValidator validator;
#endif
};
#endif // HEXSPINBOX_H

View file

@ -20,9 +20,8 @@ hexView(NULL)
{ {
// Create UI // Create UI
ui->setupUi(this); ui->setupUi(this);
hexView = new QHexEdit(this); hexView = new QHexView(this);
hexView->setReadOnly(true); hexView->setReadOnly(true);
hexView->setUpperCase(true);
ui->layout->addWidget(hexView); ui->layout->addWidget(hexView);
} }
@ -37,16 +36,33 @@ void HexViewDialog::setFont(const QFont &font)
hexView->setFont(font); hexView->setFont(font);
} }
void HexViewDialog::setItem(const UModelIndex & index) void HexViewDialog::setItem(const UModelIndex & index, HexViewType type)
{ {
const TreeModel * model = (const TreeModel*)index.model(); const TreeModel * model = (const TreeModel*)index.model();
// Set dialog title
UString itemName = model->name(index); UString itemName = model->name(index);
UString itemText = model->text(index); UString itemText = model->text(index);
setWindowTitle(UString("Hex view: ") + (itemText.isEmpty() ? itemName : itemName + " | " + itemText));
// Set hex data // Set hex data and dialog title
QByteArray data = model->header(index) + model->body(index) + model->tail(index); QByteArray hexdata;
hexView->setData(data); UString dialogTitle;
switch (type) {
case fullHexView:
dialogTitle = UString("Hex view: ");
hexdata = model->header(index) + model->body(index) + model->tail(index);
break;
case bodyHexView:
dialogTitle = UString("Body hex view: ");
hexdata = model->body(index);
break;
case uncompressedHexView:
dialogTitle = UString("Uncompressed hex view: ");
hexdata = model->uncompressedData(index);
break;
}
dialogTitle += itemText.isEmpty() ? itemName : itemName + " | " + itemText;
setWindowTitle(dialogTitle);
hexView->setData(hexdata);
hexView->setFont(QApplication::font());
} }

View file

@ -15,8 +15,8 @@
#define HEXVIEWDIALOG_H #define HEXVIEWDIALOG_H
#include <QDialog> #include <QDialog>
#include <QHexView/qhexview.h>
#include "../common/treemodel.h" #include "../common/treemodel.h"
#include "../qhexedit2/qhexedit.h"
#include "ui_hexviewdialog.h" #include "ui_hexviewdialog.h"
class HexViewDialog : public QDialog class HexViewDialog : public QDialog
@ -24,15 +24,21 @@ class HexViewDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
enum HexViewType {
fullHexView,
bodyHexView,
uncompressedHexView
};
HexViewDialog(QWidget *parent = 0); HexViewDialog(QWidget *parent = 0);
~HexViewDialog(); ~HexViewDialog();
Ui::HexViewDialog* ui; Ui::HexViewDialog* ui;
void setItem(const UModelIndex & index); void setItem(const UModelIndex & index, HexViewType dataType);
void setFont(const QFont &font); void setFont(const QFont &font);
private: private:
QHexEdit * hexView; QHexView * hexView;
}; };
#endif // HEXVIEWDIALOG_H #endif // HEXVIEWDIALOG_H

Binary file not shown.

View file

@ -1,44 +0,0 @@
/* messagelistitem.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include "messagelistitem.h"
MessageListItem::MessageListItem(QListWidget * parent, int type, const QModelIndex & index)
: QListWidgetItem(parent, type)
{
itemIndex = index;
}
MessageListItem::MessageListItem(const QString & text, QListWidget * parent, int type, const QModelIndex & index)
: QListWidgetItem(text, parent, type), itemIndex(index)
{
}
MessageListItem::MessageListItem(const QIcon & icon, const QString & text, QListWidget * parent, int type, const QModelIndex & index)
: QListWidgetItem(icon, text, parent, type), itemIndex(index)
{
}
MessageListItem::~MessageListItem()
{
}
QModelIndex MessageListItem::index() const
{
return itemIndex;
}
void MessageListItem::setIndex(QModelIndex & index)
{
itemIndex = index;
}

View file

@ -1,37 +0,0 @@
/* messagelistitem.h
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#ifndef MESSAGELISTITEM_H
#define MESSAGELISTITEM_H
#include <QModelIndex>
#include <QListWidgetItem>
#include "../common/basetypes.h"
class MessageListItem : public QListWidgetItem
{
public:
MessageListItem(QListWidget * parent = 0, int type = Type, const QModelIndex & index = QModelIndex());
MessageListItem(const QString & text, QListWidget * parent = 0, int type = Type, const QModelIndex & index = QModelIndex());
MessageListItem(const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type, const QModelIndex & index = QModelIndex());
~MessageListItem();
QModelIndex index() const;
void setIndex(QModelIndex & index);
private:
QModelIndex itemIndex;
};
#endif // MESSAGELISTITEM_H

View file

@ -14,10 +14,15 @@
#include "searchdialog.h" #include "searchdialog.h"
SearchDialog::SearchDialog(QWidget *parent) : SearchDialog::SearchDialog(QWidget *parent) :
QDialog(parent), QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
ui(new Ui::SearchDialog), ui(new Ui::SearchDialog),
#if QT_VERSION_MAJOR >= 6
hexValidator(QRegularExpression("([0-9a-fA-F\\. ])*")),
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}"))
#else
hexValidator(QRegExp("([0-9a-fA-F\\. ])*")), hexValidator(QRegExp("([0-9a-fA-F\\. ])*")),
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}")) 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}"))
#endif
{ {
// Create UI // Create UI
ui->setupUi(this); ui->setupUi(this);

View file

@ -15,7 +15,13 @@
#define SEARCHDIALOG_H #define SEARCHDIALOG_H
#include <QDialog> #include <QDialog>
#if QT_VERSION_MAJOR >= 6
#include <QRegularExpressionValidator>
#else
#include <QRegExpValidator> #include <QRegExpValidator>
#endif
#include "ui_searchdialog.h" #include "ui_searchdialog.h"
class SearchDialog : public QDialog class SearchDialog : public QDialog
@ -31,8 +37,13 @@ private slots:
void setEditFocus(int index); void setEditFocus(int index);
private: private:
#if QT_VERSION_MAJOR >= 6
QRegularExpressionValidator hexValidator;
QRegularExpressionValidator guidValidator;
#else
QRegExpValidator hexValidator; QRegExpValidator hexValidator;
QRegExpValidator guidValidator; QRegExpValidator guidValidator;
#endif
}; };
#endif // SEARCHDIALOG_H #endif // SEARCHDIALOG_H

View file

@ -35,7 +35,10 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="hexEdit"> <widget class="HexLineEdit" name="hexEdit">
<property name="editAsGuid">
<bool>false</bool>
</property>
<property name="inputMask"> <property name="inputMask">
<string/> <string/>
</property> </property>
@ -89,7 +92,10 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="GuidLineEdit" name="guidEdit"> <widget class="HexLineEdit" name="guidEdit">
<property name="editAsGuid">
<bool>true</bool>
</property>
<property name="inputMask"> <property name="inputMask">
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string> <string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
</property> </property>
@ -241,9 +247,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>GuidLineEdit</class> <class>HexLineEdit</class>
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>guidlineedit.h</header> <header>hexlineedit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>

File diff suppressed because it is too large Load diff

3
UEFITool/uefitool.desktop Executable file → Normal file
View file

@ -3,9 +3,8 @@ Type=Application
Version=1.0 Version=1.0
Name=UEFITool Name=UEFITool
Comment=UEFI firmware image viewer and editor Comment=UEFI firmware image viewer and editor
Path=/usr/bin
Exec=uefitool Exec=uefitool
Icon=uefitool Icon=uefitool
Terminal=false Terminal=false
Categories=Development;System;Utility;HardwareSettings;Electronics;Engineering; Categories=Development;System;Utility;HardwareSettings;Electronics;Engineering;
Keywords=BIOS; Keywords=BIOS;UEFI;

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.assets.movies.read-write</key>
<true/>
<key>com.apple.security.assets.music.read-write</key>
<true/>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.print</key>
<true/>
</dict>
</plist>

View file

@ -22,15 +22,19 @@
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QFont>
#include <QListWidget> #include <QListWidget>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QPalette>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QSplitter> #include <QSplitter>
#include <QStyleFactory>
#include <QString> #include <QString>
#include <QTableWidget>
#include <QTreeView> #include <QTreeView>
#include <QUrl> #include <QUrl>
@ -40,10 +44,13 @@
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffsops.h" #include "../common/ffsops.h"
#include "../common/ffsbuilder.h" #include "../common/ffsbuilder.h"
#include "../common/ffsreport.h"
#include "../common/guiddatabase.h"
#include "searchdialog.h" #include "searchdialog.h"
#include "gotobasedialog.h"
#include "gotoaddressdialog.h"
#include "hexviewdialog.h" #include "hexviewdialog.h"
#include "messagelistitem.h"
#include "ffsfinder.h" #include "ffsfinder.h"
namespace Ui { namespace Ui {
@ -63,16 +70,22 @@ public:
private slots: private slots:
void init(); void init();
void populateUi(const QItemSelection &selected);
void populateUi(const QModelIndex &current); void populateUi(const QModelIndex &current);
void scrollTreeView(QListWidgetItem* item); void scrollTreeView(QListWidgetItem* item); // For messages
void scrollTreeView(QTableWidgetItem* item); // For FIT table entries
void openImageFile(); void openImageFile();
void openImageFileInNewWindow(); void openImageFileInNewWindow();
void saveImageFile(); void saveImageFile();
void search(); void search();
void goToBase();
void goToAddress();
void hexView(); void hexView();
void bodyHexView();
void uncompressedHexView();
void goToData(); void goToData();
void extract(const UINT8 mode); void extract(const UINT8 mode);
@ -98,28 +111,47 @@ private slots:
void enableMessagesCopyActions(QListWidgetItem* item); void enableMessagesCopyActions(QListWidgetItem* item);
void clearMessages(); void clearMessages();
void toggleBootGuardMarking(bool enabled);
void about(); void about();
void aboutQt(); void aboutQt();
void exit(); void exit();
void writeSettings(); void writeSettings();
void loadGuidDatabase();
void unloadGuidDatabase();
void loadDefaultGuidDatabase();
void exportDiscoveredGuids();
void generateReport();
void currentTabChanged(int index);
#if QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 5
void updateUiForNewColorScheme(Qt::ColorScheme scheme);
#endif
private: private:
Ui::UEFITool* ui; Ui::UEFITool* ui;
TreeModel* model; TreeModel* model;
FfsParser* ffsParser; FfsParser* ffsParser;
FfsFinder* ffsFinder; FfsFinder* ffsFinder;
FfsReport* ffsReport;
FfsOperations* ffsOps; FfsOperations* ffsOps;
FfsBuilder* ffsBuilder; FfsBuilder* ffsBuilder;
SearchDialog* searchDialog; SearchDialog* searchDialog;
HexViewDialog* hexViewDialog; HexViewDialog* hexViewDialog;
GoToBaseDialog* goToBaseDialog;
GoToAddressDialog* goToAddressDialog;
QClipboard* clipboard; QClipboard* clipboard;
QString currentDir; QString currentDir;
QString currentPath;
QString currentProgramPath; QString currentProgramPath;
QFont currentFont;
const QString version; const QString version;
bool markingEnabled;
bool enableExtractBodyUncompressed(const QModelIndex &current); bool eventFilter(QObject* obj, QEvent* event);
void dragEnterEvent(QDragEnterEvent* event); void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event); void dropEvent(QDropEvent* event);
void contextMenuEvent(QContextMenuEvent* event); void contextMenuEvent(QContextMenuEvent* event);
@ -127,7 +159,16 @@ private:
void showParserMessages(); void showParserMessages();
void showFinderMessages(); void showFinderMessages();
void showFitTable(); void showFitTable();
void showSecurityInfo();
void showBuilderMessages(); void showBuilderMessages();
enum {
TAB_PARSER,
TAB_FIT,
TAB_SECURITY,
TAB_SEARCH,
TAB_BUILDER
};
}; };
#endif // UEFITOOL_H #endif // UEFITOOL_H

View file

@ -1,30 +1,44 @@
QT += core gui QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = UEFITool TARGET = UEFITool
TEMPLATE = app TEMPLATE = app
CONFIG += c++11
DEFINES += "U_ENABLE_FIT_PARSING_SUPPORT"
DEFINES += "U_ENABLE_NVRAM_PARSING_SUPPORT"
DEFINES += "U_ENABLE_ME_PARSING_SUPPORT"
DEFINES += "U_ENABLE_GUID_DATABASE_SUPPORT"
HEADERS += uefitool.h \ HEADERS += uefitool.h \
searchdialog.h \ searchdialog.h \
hexviewdialog.h \ hexviewdialog.h \
messagelistitem.h \ gotobasedialog.h \
guidlineedit.h \ gotoaddressdialog.h \
hexlineedit.h \
ffsfinder.h \ ffsfinder.h \
hexspinbox.h \
../common/fitparser.h \
../common/guiddatabase.h \
../common/nvram.h \ ../common/nvram.h \
../common/nvramparser.h \
../common/meparser.h \
../common/ffsops.h \ ../common/ffsops.h \
../common/basetypes.h \ ../common/basetypes.h \
../common/descriptor.h \ ../common/descriptor.h \
../common/gbe.h \ ../common/gbe.h \
../common/me.h \ ../common/me.h \
../common/ffs.h \ ../common/ffs.h \
../common/fit.h \
../common/peimage.h \ ../common/peimage.h \
../common/types.h \ ../common/types.h \
../common/utility.h \ ../common/utility.h \
../common/parsingdata.h \ ../common/parsingdata.h \
../common/ffsbuilder.h \ ../common/ffsbuilder.h \
../common/ffsparser.h \ ../common/ffsparser.h \
../common/ffsreport.h \
../common/treeitem.h \ ../common/treeitem.h \
../common/intel_fit.h \
../common/intel_microcode.h \
../common/treemodel.h \ ../common/treemodel.h \
../common/LZMA/LzmaCompress.h \ ../common/LZMA/LzmaCompress.h \
../common/LZMA/LzmaDecompress.h \ ../common/LZMA/LzmaDecompress.h \
@ -32,18 +46,61 @@ HEADERS += uefitool.h \
../common/Tiano/EfiTianoCompress.h \ ../common/Tiano/EfiTianoCompress.h \
../common/ustring.h \ ../common/ustring.h \
../common/ubytearray.h \ ../common/ubytearray.h \
../qhexedit2/qhexedit.h \ ../common/umemstream.h \
../qhexedit2/chunks.h \ ../common/digest/sha1.h \
../qhexedit2/commands.h ../common/digest/sha2.h \
../common/digest/sm3.h \
../common/generated/ami_nvar.h \
../common/generated/apple_sysf.h \
../common/generated/dell_dvar.h \
../common/generated/edk2_vss.h \
../common/generated/edk2_vss2.h \
../common/generated/edk2_ftw.h \
../common/generated/insyde_fdc.h \
../common/generated/insyde_fdm.h \
../common/generated/ms_slic_marker.h \
../common/generated/ms_slic_pubkey.h \
../common/generated/phoenix_flm.h \
../common/generated/phoenix_evsa.h \
../common/generated/intel_acbp_v1.h \
../common/generated/intel_acbp_v2.h \
../common/generated/intel_keym_v1.h \
../common/generated/intel_keym_v2.h \
../common/generated/intel_acm.h \
../common/kaitai/kaitaistream.h \
../common/kaitai/kaitaistruct.h \
../common/kaitai/exceptions.h \
../common/zlib/zlib.h \
../common/zlib/crc32.h \
../version.h \
QHexView/include/QHexView/model/buffer/qhexbuffer.h \
QHexView/include/QHexView/model/buffer/qdevicebuffer.h \
QHexView/include/QHexView/model/buffer/qmemorybuffer.h \
QHexView/include/QHexView/model/buffer/qmappedfilebuffer.h \
QHexView/include/QHexView/model/commands/hexcommand.h \
QHexView/include/QHexView/model/commands/insertcommand.h \
QHexView/include/QHexView/model/commands/removecommand.h \
QHexView/include/QHexView/model/commands/replacecommand.h \
QHexView/include/QHexView/model/qhexcursor.h \
QHexView/include/QHexView/model/qhexdelegate.h \
QHexView/include/QHexView/model/qhexdocument.h \
QHexView/include/QHexView/model/qhexmetadata.h \
QHexView/include/QHexView/model/qhexoptions.h \
QHexView/include/QHexView/model/qhexutils.h \
QHexView/include/QHexView/qhexview.h
SOURCES += uefitool_main.cpp \ SOURCES += uefitool_main.cpp \
uefitool.cpp \ uefitool.cpp \
searchdialog.cpp \ searchdialog.cpp \
hexviewdialog.cpp \ hexviewdialog.cpp \
messagelistitem.cpp \ hexlineedit.cpp \
guidlineedit.cpp \
ffsfinder.cpp \ ffsfinder.cpp \
hexspinbox.cpp \
../common/fitparser.cpp \
../common/guiddatabase.cpp \
../common/nvram.cpp \ ../common/nvram.cpp \
../common/nvramparser.cpp \
../common/meparser.cpp \
../common/ffsops.cpp \ ../common/ffsops.cpp \
../common/types.cpp \ ../common/types.cpp \
../common/descriptor.cpp \ ../common/descriptor.cpp \
@ -52,10 +109,14 @@ SOURCES += uefitool_main.cpp \
../common/utility.cpp \ ../common/utility.cpp \
../common/ffsbuilder.cpp \ ../common/ffsbuilder.cpp \
../common/ffsparser.cpp \ ../common/ffsparser.cpp \
../common/ffsreport.cpp \
../common/treeitem.cpp \ ../common/treeitem.cpp \
../common/treemodel.cpp \ ../common/treemodel.cpp \
../common/LZMA/LzmaCompress.c \ ../common/LZMA/LzmaCompress.c \
../common/LZMA/LzmaDecompress.c \ ../common/LZMA/LzmaDecompress.c \
../common/LZMA/SDK/C/CpuArch.c \
../common/LZMA/SDK/C/Bra.c \
../common/LZMA/SDK/C/Bra86.c \
../common/LZMA/SDK/C/LzFind.c \ ../common/LZMA/SDK/C/LzFind.c \
../common/LZMA/SDK/C/LzmaDec.c \ ../common/LZMA/SDK/C/LzmaDec.c \
../common/LZMA/SDK/C/LzmaEnc.c \ ../common/LZMA/SDK/C/LzmaEnc.c \
@ -63,15 +124,68 @@ SOURCES += uefitool_main.cpp \
../common/Tiano/EfiTianoCompress.c \ ../common/Tiano/EfiTianoCompress.c \
../common/Tiano/EfiTianoCompressLegacy.c \ ../common/Tiano/EfiTianoCompressLegacy.c \
../common/ustring.cpp \ ../common/ustring.cpp \
../qhexedit2/qhexedit.cpp \ ../common/digest/sha1.c \
../qhexedit2/chunks.cpp \ ../common/digest/sha256.c \
../qhexedit2/commands.cpp ../common/digest/sha512.c \
../common/digest/sm3.c \
../common/generated/ami_nvar.cpp \
../common/generated/apple_sysf.cpp \
../common/generated/dell_dvar.cpp \
../common/generated/edk2_vss.cpp \
../common/generated/edk2_vss2.cpp \
../common/generated/edk2_ftw.cpp \
../common/generated/insyde_fdc.cpp \
../common/generated/insyde_fdm.cpp \
../common/generated/ms_slic_marker.cpp \
../common/generated/ms_slic_pubkey.cpp \
../common/generated/phoenix_flm.cpp \
../common/generated/phoenix_evsa.cpp \
../common/generated/intel_acbp_v1.cpp \
../common/generated/intel_acbp_v2.cpp \
../common/generated/intel_keym_v1.cpp \
../common/generated/intel_keym_v2.cpp \
../common/generated/intel_acm.cpp \
../common/kaitai/kaitaistream.cpp \
../common/zlib/adler32.c \
../common/zlib/compress.c \
../common/zlib/crc32.c \
../common/zlib/deflate.c \
../common/zlib/gzclose.c \
../common/zlib/gzlib.c \
../common/zlib/gzread.c \
../common/zlib/gzwrite.c \
../common/zlib/inflate.c \
../common/zlib/infback.c \
../common/zlib/inftrees.c \
../common/zlib/inffast.c \
../common/zlib/trees.c \
../common/zlib/uncompr.c \
../common/zlib/zutil.c \
QHexView/src/model/buffer/qhexbuffer.cpp \
QHexView/src/model/buffer/qdevicebuffer.cpp \
QHexView/src/model/buffer/qmemorybuffer.cpp \
QHexView/src/model/buffer/qmappedfilebuffer.cpp \
QHexView/src/model/commands/hexcommand.cpp \
QHexView/src/model/commands/insertcommand.cpp \
QHexView/src/model/commands/removecommand.cpp \
QHexView/src/model/commands/replacecommand.cpp \
QHexView/src/model/qhexcursor.cpp \
QHexView/src/model/qhexdelegate.cpp \
QHexView/src/model/qhexdocument.cpp \
QHexView/src/model/qhexmetadata.cpp \
QHexView/src/model/qhexutils.cpp \
QHexView/src/qhexview.cpp
INCLUDEPATH += QHexView/include/
FORMS += uefitool.ui \ FORMS += uefitool.ui \
searchdialog.ui \ searchdialog.ui \
hexviewdialog.ui hexviewdialog.ui \
gotobasedialog.ui \
gotoaddressdialog.ui
RESOURCES += uefitool.qrc
RC_FILE = uefitool.rc RC_FILE = uefitool.rc
ICON = icons/uefitool.icns ICON = icons/uefitool.icns
QMAKE_BUNDLE_DATA += ICONFILE
QMAKE_INFO_PLIST = Info.plist

5
UEFITool/uefitool.qrc Normal file
View file

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="guids.csv">../common/guids.csv</file>
</qresource>
</RCC>

View file

@ -132,15 +132,15 @@
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QTabWidget" name="messagesTabWidget"> <widget class="QTabWidget" name="messagesTabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
@ -203,6 +203,44 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="securityTab">
<property name="enabled">
<bool>true</bool>
</property>
<attribute name="title">
<string>Security</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPlainTextEdit" name="securityEdit">
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="finderTab"> <widget class="QWidget" name="finderTab">
<attribute name="title"> <attribute name="title">
<string>Search</string> <string>Search</string>
@ -273,7 +311,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>851</width> <width>851</width>
<height>21</height> <height>31</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -284,7 +322,12 @@
<addaction name="actionOpenImageFileInNewWindow"/> <addaction name="actionOpenImageFileInNewWindow"/>
<addaction name="actionSaveImageFile"/> <addaction name="actionSaveImageFile"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSearch"/> <addaction name="actionGenerateReport"/>
<addaction name="separator"/>
<addaction name="actionLoadGuidDatabase"/>
<addaction name="actionLoadDefaultGuidDatabase"/>
<addaction name="actionUnloadGuidDatabase"/>
<addaction name="actionExportDiscoveredGuids"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
@ -300,15 +343,23 @@
<string>&amp;Action</string> <string>&amp;Action</string>
</property> </property>
<widget class="QMenu" name="menuCapsuleActions"> <widget class="QMenu" name="menuCapsuleActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Capsule</string> <string>&amp;Capsule</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
<addaction name="actionExtractBody"/> <addaction name="actionExtractBody"/>
</widget> </widget>
<widget class="QMenu" name="menuImageActions"> <widget class="QMenu" name="menuImageActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Image</string> <string>&amp;Image</string>
</property> </property>
@ -317,6 +368,9 @@
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
</widget> </widget>
<widget class="QMenu" name="menuRegionActions"> <widget class="QMenu" name="menuRegionActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Region</string> <string>&amp;Region</string>
</property> </property>
@ -329,6 +383,9 @@
<addaction name="actionReplace"/> <addaction name="actionReplace"/>
</widget> </widget>
<widget class="QMenu" name="menuPaddingActions"> <widget class="QMenu" name="menuPaddingActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Padding</string> <string>&amp;Padding</string>
</property> </property>
@ -337,10 +394,15 @@
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
</widget> </widget>
<widget class="QMenu" name="menuVolumeActions"> <widget class="QMenu" name="menuVolumeActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Volume</string> <string>&amp;Volume</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
<addaction name="actionExtractBody"/> <addaction name="actionExtractBody"/>
@ -353,10 +415,15 @@
<addaction name="actionReplaceBody"/> <addaction name="actionReplaceBody"/>
</widget> </widget>
<widget class="QMenu" name="menuFileActions"> <widget class="QMenu" name="menuFileActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;File</string> <string>&amp;File</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
<addaction name="actionExtractBody"/> <addaction name="actionExtractBody"/>
@ -373,10 +440,15 @@
<addaction name="actionRemove"/> <addaction name="actionRemove"/>
</widget> </widget>
<widget class="QMenu" name="menuSectionActions"> <widget class="QMenu" name="menuSectionActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Section</string> <string>&amp;Section</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
<addaction name="actionExtractBody"/> <addaction name="actionExtractBody"/>
@ -393,7 +465,10 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionRemove"/> <addaction name="actionRemove"/>
</widget> </widget>
<widget class="QMenu" name="menuMessages"> <widget class="QMenu" name="menuMessageActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>&amp;Messages</string> <string>&amp;Messages</string>
</property> </property>
@ -402,11 +477,16 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionMessagesClear"/> <addaction name="actionMessagesClear"/>
</widget> </widget>
<widget class="QMenu" name="menuVariableActions"> <widget class="QMenu" name="menuEntryActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>Variable</string> <string>&amp;Entry</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionGoToData"/> <addaction name="actionGoToData"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -424,10 +504,15 @@
<addaction name="actionRemove"/> <addaction name="actionRemove"/>
</widget> </widget>
<widget class="QMenu" name="menuStoreActions"> <widget class="QMenu" name="menuStoreActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title"> <property name="title">
<string>S&amp;tore</string> <string>S&amp;tore</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/>
<addaction name="actionUncompressedHexView"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExtract"/> <addaction name="actionExtract"/>
<addaction name="actionExtractBody"/> <addaction name="actionExtractBody"/>
@ -441,6 +526,10 @@
<addaction name="actionReplace"/> <addaction name="actionReplace"/>
<addaction name="actionReplaceBody"/> <addaction name="actionReplaceBody"/>
</widget> </widget>
<addaction name="actionGoToBase"/>
<addaction name="actionGoToAddress"/>
<addaction name="actionSearch"/>
<addaction name="separator"/>
<addaction name="menuCapsuleActions"/> <addaction name="menuCapsuleActions"/>
<addaction name="menuImageActions"/> <addaction name="menuImageActions"/>
<addaction name="menuRegionActions"/> <addaction name="menuRegionActions"/>
@ -448,13 +537,21 @@
<addaction name="menuVolumeActions"/> <addaction name="menuVolumeActions"/>
<addaction name="menuFileActions"/> <addaction name="menuFileActions"/>
<addaction name="menuSectionActions"/> <addaction name="menuSectionActions"/>
<addaction name="menuStoreActions"/>
<addaction name="menuVariableActions"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menuMessages"/> <addaction name="menuStoreActions"/>
<addaction name="menuEntryActions"/>
<addaction name="separator"/>
<addaction name="menuMessageActions"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>&amp;View</string>
</property>
<addaction name="actionToggleBootGuardMarking"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuAction"/> <addaction name="menuAction"/>
<addaction name="menuView"/>
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>
<action name="actionInsertAfter"> <action name="actionInsertAfter">
@ -609,6 +706,9 @@
<property name="text"> <property name="text">
<string>About &amp;Qt</string> <string>About &amp;Qt</string>
</property> </property>
<property name="shortcut">
<string>Shift+F1</string>
</property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::AboutQtRole</enum> <enum>QAction::AboutQtRole</enum>
</property> </property>
@ -617,6 +717,9 @@
<property name="text"> <property name="text">
<string>&amp;Quit</string> <string>&amp;Quit</string>
</property> </property>
<property name="shortcut">
<string>Alt+X</string>
</property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::QuitRole</enum> <enum>QAction::QuitRole</enum>
</property> </property>
@ -626,13 +729,16 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Sear&amp;ch...</string> <string>Searc&amp;h...</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+F</string> <string>Ctrl+F</string>
</property> </property>
</action> </action>
<action name="actionMessagesClear"> <action name="actionMessagesClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Clea&amp;r</string> <string>Clea&amp;r</string>
</property> </property>
@ -658,6 +764,9 @@
</property> </property>
</action> </action>
<action name="actionMessagesCopy"> <action name="actionMessagesCopy">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>&amp;Copy</string> <string>&amp;Copy</string>
</property> </property>
@ -666,6 +775,9 @@
</property> </property>
</action> </action>
<action name="actionMessagesCopyAll"> <action name="actionMessagesCopyAll">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Copy &amp;all</string> <string>Copy &amp;all</string>
</property> </property>
@ -700,7 +812,10 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Go to &amp;data</string> <string>Go &amp;to data</string>
</property>
<property name="shortcut">
<string>Ctrl+T</string>
</property> </property>
</action> </action>
<action name="actionHexView"> <action name="actionHexView">
@ -714,6 +829,113 @@
<string>Ctrl+D</string> <string>Ctrl+D</string>
</property> </property>
</action> </action>
<action name="actionGoToBase">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Select item at base...</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
<action name="actionBodyHexView">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Body hex vie&amp;w...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+D</string>
</property>
</action>
<action name="actionUncompressedHexView">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Un&amp;compressed hex view...</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+D</string>
</property>
</action>
<action name="actionLoadGuidDatabase">
<property name="text">
<string>Load &amp;GUID database...</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+G</string>
</property>
</action>
<action name="actionGoToAddress">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Select item at &amp;address...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+G</string>
</property>
</action>
<action name="actionToggleBootGuardMarking">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>BootGuard &amp;markings</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+B</string>
</property>
</action>
<action name="actionGenerateReport">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Generate &amp;report...</string>
</property>
<property name="toolTip">
<string>Generate report</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+R</string>
</property>
</action>
<action name="actionUnloadGuidDatabase">
<property name="text">
<string>&amp;Unload GUID database</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+U</string>
</property>
</action>
<action name="actionLoadDefaultGuidDatabase">
<property name="text">
<string>Load &amp;default GUID database</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+D</string>
</property>
</action>
<action name="actionExportDiscoveredGuids">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Export discovered GUIDs...</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+E</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>

View file

@ -1,6 +1,6 @@
/* uefitool_main.cpp /* uefitool_main.cpp
Copyright (c) 2014, Nikolaj Schlej. All rights reserved. Copyright (c) 2022, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -15,18 +15,50 @@
#include <QString> #include <QString>
#include "uefitool.h" #include "uefitool.h"
class UEFIToolApplication : public QApplication
{
UEFITool* tool;
public:
UEFIToolApplication(int &argc, char **argv)
: QApplication(argc, argv)
{
setOrganizationName("CodeRush");
setOrganizationDomain("coderush.me");
setApplicationName("UEFITool");
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
setDesktopFileName("uefitool");
#endif
tool = new UEFITool();
}
virtual ~UEFIToolApplication() {
delete tool;
}
virtual bool event(QEvent *event)
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
tool->openImageFile(openEvent->file());
}
return QApplication::event(event);
}
int startup()
{
tool->setProgramPath(arguments().at(0));
if (arguments().length() > 1)
tool->openImageFile(arguments().at(1));
tool->show();
return exec();
}
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); UEFIToolApplication a(argc, argv);
a.setOrganizationName("CodeRush"); return a.startup();
a.setOrganizationDomain("coderush.me");
a.setApplicationName("UEFITool");
UEFITool w;
w.setProgramPath(a.arguments().at(0));
if (a.arguments().length() > 1)
w.openImageFile(a.arguments().at(1));
w.show();
return a.exec();
} }

BIN
appstream/UEFITool.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

23
appstream/appdata.xml Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>com.github.LongSoft.UEFITool</id>
<launchable type="desktop-id">com.github.LongSoft.UEFITool.desktop</launchable>
<name>UEFITool</name>
<summary>UEFI firmware image viewer and editor</summary>
<description>
<p>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.</p>
</description>
<screenshots>
<screenshot type="default">
<image type="source">https://github.com/LongSoft/UEFITool/raw/new_engine/appstream/UEFITool.png</image>
</screenshot>
</screenshots>
<releases>
<release version="A70" date="2025-03-13" />
</releases>
<url type="homepage">https://github.com/LongSoft/UEFITool</url>
<developer_name>LongSoft</developer_name>
<metadata_license>CC0-1.0</metadata_license>
<project_license>BSD-2-Clause</project_license>
<content_rating type="oars-1.1" />
</component>

View file

@ -1,34 +0,0 @@
The Better String Library
The Better String Library is an abstraction of a string data type which is
superior to the C library char buffer string type, or C++'s std::string.
Among the features achieved are:
- Substantial mitigation of buffer overflow/overrun problems and other
failures that result from erroneous usage of the common C string
library functions
- Significantly simplified string manipulation
- High performance interoperability with other source/libraries which
expect '\0' terminated char buffers
- Improved overall performance of common string operations
- Functional equivalency with other more modern languages
The library is totally stand alone, portable (known to work with gcc/g++,
MSVC++, Intel C++, WATCOM C/C++, Turbo C, Borland C++, IBM's native CC
compiler on Windows, Linux and Mac OS X), high performance, easy to use and
is not part of some other collection of data structures. Even the file I/O
functions are totally abstracted (so that other stream-like mechanisms, like
sockets, can be used.) Nevertheless, it is adequate as a complete
replacement of the C string library for string manipulation in any C program.
The library includes a robust C++ wrapper that uses overloaded operators,
rich constructors, exceptions, stream I/O and STL to make the CBString
struct a natural and powerful string abstraction with more functionality and
higher performance than std::string.
Bstrlib is stable, well tested and suitable for any software production
environment.

View file

@ -1,82 +0,0 @@
/*
* This source file is part of the bstring string library. This code was
* written by Paul Hsieh in 2002-2015, and is covered by the BSD open source
* license. Refer to the accompanying documentation for details on usage and
* license.
*/
/*
* bsafe.c
*
* This is an optional module that can be used to help enforce a safety
* standard based on pervasive usage of bstrlib. This file is not necessarily
* portable, however, it has been tested to work correctly with Intel's C/C++
* compiler, WATCOM C/C++ v11.x and Microsoft Visual C++.
*/
#include <stdio.h>
#include <stdlib.h>
#include "bsafe.h"
static int bsafeShouldExit = 1;
char * strcpy (char *dst, const char *src);
char * strcat (char *dst, const char *src);
char * strcpy (char *dst, const char *src) {
(void) dst;
(void) src;
fprintf (stderr, "bsafe error: strcpy() is not safe, use bstrcpy instead.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
char * strcat (char *dst, const char *src) {
(void) dst;
(void) src;
fprintf (stderr, "bsafe error: strcat() is not safe, use bstrcat instead.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
#if !defined (__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
char * (gets) (char * buf) {
(void) buf;
fprintf (stderr, "bsafe error: gets() is not safe, use bgets.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
#endif
char * (strncpy) (char *dst, const char *src, size_t n) {
(void) dst;
(void) src;
(void) n;
fprintf (stderr, "bsafe error: strncpy() is not safe, use bmidstr instead.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
char * (strncat) (char *dst, const char *src, size_t n) {
(void) dst;
(void) src;
(void) n;
fprintf (stderr, "bsafe error: strncat() is not safe, use bstrcat then btrunc\n\tor cstr2tbstr, btrunc then bstrcat instead.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
char * (strtok) (char *s1, const char *s2) {
(void) s1;
(void) s2;
fprintf (stderr, "bsafe error: strtok() is not safe, use bsplit or bsplits instead.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}
char * (strdup) (const char *s) {
(void) s;
fprintf (stderr, "bsafe error: strdup() is not safe, use bstrcpy.\n");
if (bsafeShouldExit) exit (-1);
return NULL;
}

View file

@ -1,43 +0,0 @@
/*
* This source file is part of the bstring string library. This code was
* written by Paul Hsieh in 2002-2004, and is covered by the BSD open source
* license. Refer to the accompanying documentation for details on usage and
* license.
*/
/*
* bsafe.h
*
* This is an optional module that can be used to help enforce a safety
* standard based on pervasive usage of bstrlib. This file is not necessarily
* portable, however, it has been tested to work correctly with Intel's C/C++
* compiler, WATCOM C/C++ v11.x and Microsoft Visual C++.
*/
#ifndef BSTRLIB_BSAFE_INCLUDE
#define BSTRLIB_BSAFE_INCLUDE
#ifdef __cplusplus
extern "C" {
#endif
#if !defined (__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
/* This is caught in the linker, so its not necessary for gcc. */
extern char * (gets) (char * buf);
#endif
extern char * (strncpy) (char *dst, const char *src, size_t n);
extern char * (strncat) (char *dst, const char *src, size_t n);
extern char * (strtok) (char *s1, const char *s2);
extern char * (strdup) (const char *s);
#undef strcpy
#undef strcat
#define strcpy(a,b) bsafe_strcpy(a,b)
#define strcat(a,b) bsafe_strcat(a,b)
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,115 +0,0 @@
/*
* This source file is part of the bstring string library. This code was
* written by Paul Hsieh in 2002-2015, and is covered by the BSD open source
* license and the GPL. Refer to the accompanying documentation for details
* on usage and license.
*/
/*
* bstraux.h
*
* This file is not a necessary part of the core bstring library itself, but
* is just an auxilliary module which includes miscellaneous or trivial
* functions.
*/
#ifndef BSTRAUX_INCLUDE
#define BSTRAUX_INCLUDE
#include <time.h>
#include "bstrlib.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Safety mechanisms */
#define bstrDeclare(b) bstring (b) = NULL;
#define bstrFree(b) {if ((b) != NULL && (b)->slen >= 0 && (b)->mlen >= (b)->slen) { bdestroy (b); (b) = NULL; }}
/* Backward compatibilty with previous versions of Bstrlib */
#if !defined(BSTRLIB_REDUCE_NAMESPACE_POLLUTION)
#define bAssign(a,b) ((bassign)((a), (b)))
#define bSubs(b,pos,len,a,c) ((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
#define bStrchr(b,c) ((bstrchr)((b), (c)))
#define bStrchrFast(b,c) ((bstrchr)((b), (c)))
#define bCatCstr(b,s) ((bcatcstr)((b), (s)))
#define bCatBlk(b,s,len) ((bcatblk)((b),(s),(len)))
#define bCatStatic(b,s) bcatStatic(b,s)
#define bTrunc(b,n) ((btrunc)((b), (n)))
#define bReplaceAll(b,find,repl,pos) ((bfindreplace)((b),(find),(repl),(pos)))
#define bUppercase(b) ((btoupper)(b))
#define bLowercase(b) ((btolower)(b))
#define bCaselessCmp(a,b) ((bstricmp)((a), (b)))
#define bCaselessNCmp(a,b,n) ((bstrnicmp)((a), (b), (n)))
#define bBase64Decode(b) (bBase64DecodeEx ((b), NULL))
#define bUuDecode(b) (bUuDecodeEx ((b), NULL))
#endif
/* Unusual functions */
extern struct bStream * bsFromBstr (const_bstring b);
extern bstring bTail (bstring b, int n);
extern bstring bHead (bstring b, int n);
extern int bSetCstrChar (bstring a, int pos, char c);
extern int bSetChar (bstring b, int pos, char c);
extern int bFill (bstring a, char c, int len);
extern int bReplicate (bstring b, int n);
extern int bReverse (bstring b);
extern int bInsertChrs (bstring b, int pos, int len, unsigned char c, unsigned char fill);
extern bstring bStrfTime (const char * fmt, const struct tm * timeptr);
#define bAscTime(t) (bStrfTime ("%c\n", (t)))
#define bCTime(t) ((t) ? bAscTime (localtime (t)) : NULL)
/* Spacing formatting */
extern int bJustifyLeft (bstring b, int space);
extern int bJustifyRight (bstring b, int width, int space);
extern int bJustifyMargin (bstring b, int width, int space);
extern int bJustifyCenter (bstring b, int width, int space);
/* Esoteric standards specific functions */
extern char * bStr2NetStr (const_bstring b);
extern bstring bNetStr2Bstr (const char * buf);
extern bstring bBase64Encode (const_bstring b);
extern bstring bBase64DecodeEx (const_bstring b, int * boolTruncError);
extern struct bStream * bsUuDecode (struct bStream * sInp, int * badlines);
extern bstring bUuDecodeEx (const_bstring src, int * badlines);
extern bstring bUuEncode (const_bstring src);
extern bstring bYEncode (const_bstring src);
extern bstring bYDecode (const_bstring src);
extern int bSGMLEncode (bstring b);
/* Writable stream */
typedef int (* bNwrite) (const void * buf, size_t elsize, size_t nelem, void * parm);
struct bwriteStream * bwsOpen (bNwrite writeFn, void * parm);
int bwsWriteBstr (struct bwriteStream * stream, const_bstring b);
int bwsWriteBlk (struct bwriteStream * stream, void * blk, int len);
int bwsWriteFlush (struct bwriteStream * stream);
int bwsIsEOF (const struct bwriteStream * stream);
int bwsBuffLength (struct bwriteStream * stream, int sz);
void * bwsClose (struct bwriteStream * stream);
/* Security functions */
#define bSecureDestroy(b) { \
bstring bstr__tmp = (b); \
if (bstr__tmp && bstr__tmp->mlen > 0 && bstr__tmp->data) { \
(void) memset (bstr__tmp->data, 0, (size_t) bstr__tmp->mlen); \
bdestroy (bstr__tmp); \
} \
}
#define bSecureWriteProtect(t) { \
if ((t).mlen >= 0) { \
if ((t).mlen > (t).slen)) { \
(void) memset ((t).data + (t).slen, 0, (size_t) (t).mlen - (t).slen); \
} \
(t).mlen = -1; \
} \
}
extern bstring bSecureInput (int maxlen, int termchar,
bNgetc vgetchar, void * vgcCtx);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,274 +0,0 @@
/*
* This source file is part of the bstring string library. This code was
* written by Paul Hsieh in 2002-2015, and is covered by the BSD open source
* license and the GPL. Refer to the accompanying documentation for details
* on usage and license.
*/
/*
* buniutil.c
*
* This file is not necessarily part of the core bstring library itself, but
* is just an implementation of basic utf8 processing for bstrlib. Note that
* this module is dependent upon bstrlib.c and utf8util.c
*/
#include "bstrlib.h"
#include "buniutil.h"
#define UNICODE__CODE_POINT__REPLACEMENT_CHARACTER (0xFFFDL)
/* int buIsUTF8Content (const_bstring bu)
*
* Scan string and return 1 if its entire contents is entirely UTF8 code
* points. Otherwise return 0.
*/
int buIsUTF8Content (const_bstring bu) {
struct utf8Iterator iter;
if (NULL == bdata (bu)) return 0;
for (utf8IteratorInit (&iter, bu->data, bu->slen);
iter.next < iter.slen;) {
if (0 >= utf8IteratorGetNextCodePoint (&iter, -1)) return 0;
}
return 1;
}
/* int buGetBlkUTF16 (cpUcs2* ucs2, int len, cpUcs4 errCh, const_bstring bu,
* int pos)
*
* Convert a string of UTF8 codepoints (bu) skipping the first pos, into a
* sequence of UTF16 encoded code points. Returns the number of UCS2 16-bit
* words written to the output. No more than len words are written to the
* target array ucs2. If any code point in bu is unparsable, it will be
* translated to errCh.
*/
int buGetBlkUTF16 (/* @out */ cpUcs2* ucs2, int len, cpUcs4 errCh, const_bstring bu, int pos) {
struct tagbstring t;
struct utf8Iterator iter;
cpUcs4 ucs4;
int i, j;
if (!isLegalUnicodeCodePoint (errCh)) errCh = UNICODE__CODE_POINT__REPLACEMENT_CHARACTER;
if (NULL == ucs2 || 0 >= len || NULL == bdata (bu) || 0 > pos) return BSTR_ERR;
for (j=0, i=0; j < bu->slen; j++) {
if (0x80 != (0xC0 & bu->data[j])) {
if (i >= pos) break;
i++;
}
}
t.mlen = -1;
t.data = bu->data + j;
t.slen = bu->slen - j;
utf8IteratorInit (&iter, t.data, t.slen);
ucs4 = BSTR_ERR;
for (i=0; 0 < len && iter.next < iter.slen &&
0 <= (ucs4 = utf8IteratorGetNextCodePoint (&iter, errCh)); i++) {
if (ucs4 < 0x10000) {
*ucs2++ = (cpUcs2) ucs4;
len--;
} else {
if (len < 2) {
*ucs2++ = UNICODE__CODE_POINT__REPLACEMENT_CHARACTER;
len--;
} else {
long y = ucs4 - 0x10000;
ucs2[0] = (cpUcs2) (0xD800 | (y >> 10));
ucs2[1] = (cpUcs2) (0xDC00 | (y & 0x03FF));
len -= 2;
ucs2 += 2;
i++;
}
}
}
while (0 < len) {
*ucs2++ = 0;
len--;
}
utf8IteratorUninit (&iter);
if (0 > ucs4) return BSTR_ERR;
return i;
}
/*
Unicode UTF-8
------- -----
U-00000000 - U-0000007F: 0xxxxxxx
U-00000080 - U-000007FF: 110xxxxx 10xxxxxx
U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
UTF-32: U-000000 - U-10FFFF
*/
/* int buAppendBlkUcs4 (bstring b, const cpUcs4* bu, int len, cpUcs4 errCh)
*
* Convert an array of UCS4 code points (bu) to UTF8 codepoints b. Any
* invalid code point is replaced by errCh. If errCh is itself not a
* valid code point, then this translation will halt upon the first error
* and return BSTR_ERR. Otherwise BSTR_OK is returned.
*/
int buAppendBlkUcs4 (bstring b, const cpUcs4* bu, int len, cpUcs4 errCh) {
int i, oldSlen;
if (NULL == bu || NULL == b || 0 > len || 0 > (oldSlen = blengthe (b, -1))) return BSTR_ERR;
if (!isLegalUnicodeCodePoint (errCh)) errCh = ~0;
for (i=0; i < len; i++) {
unsigned char c[6];
cpUcs4 v = bu[i];
if (!isLegalUnicodeCodePoint (v)) {
if (~0 == errCh) {
b->slen = oldSlen;
return BSTR_ERR;
}
v = errCh;
}
if (v < 0x80) {
if (BSTR_OK != bconchar (b, (char) v)) {
b->slen = oldSlen;
return BSTR_ERR;
}
} else if (v < 0x800) {
c[0] = (unsigned char) ( (v >> 6) + 0xc0);
c[1] = (unsigned char) (( v & 0x3f) + 0x80);
if (BSTR_OK != bcatblk (b, c, 2)) {
b->slen = oldSlen;
return BSTR_ERR;
}
} else if (v < 0x10000) {
c[0] = (unsigned char) ( (v >> 12) + 0xe0);
c[1] = (unsigned char) (((v >> 6) & 0x3f) + 0x80);
c[2] = (unsigned char) (( v & 0x3f) + 0x80);
if (BSTR_OK != bcatblk (b, c, 3)) {
b->slen = oldSlen;
return BSTR_ERR;
}
} else
#if 0
if (v < 0x200000)
#endif
{
c[0] = (unsigned char) ( (v >> 18) + 0xf0);
c[1] = (unsigned char) (((v >> 12) & 0x3f) + 0x80);
c[2] = (unsigned char) (((v >> 6) & 0x3f) + 0x80);
c[3] = (unsigned char) (( v & 0x3f) + 0x80);
if (BSTR_OK != bcatblk (b, c, 4)) {
b->slen = oldSlen;
return BSTR_ERR;
}
}
#if 0
else if (v < 0x4000000) {
c[0] = (unsigned char) ( (v >> 24) + 0xf8);
c[1] = (unsigned char) (((v >> 18) & 0x3f) + 0x80);
c[2] = (unsigned char) (((v >> 12) & 0x3f) + 0x80);
c[3] = (unsigned char) (((v >> 6) & 0x3f) + 0x80);
c[4] = (unsigned char) (( v & 0x3f) + 0x80);
if (BSTR_OK != bcatblk (b, c, 5)) {
b->slen = oldSlen;
return BSTR_ERR;
}
} else {
c[0] = (unsigned char) ( (v >> 30) + 0xfc);
c[1] = (unsigned char) (((v >> 24) & 0x3f) + 0x80);
c[2] = (unsigned char) (((v >> 18) & 0x3f) + 0x80);
c[3] = (unsigned char) (((v >> 12) & 0x3f) + 0x80);
c[4] = (unsigned char) (((v >> 6) & 0x3f) + 0x80);
c[5] = (unsigned char) (( v & 0x3f) + 0x80);
if (BSTR_OK != bcatblk (b, c, 6)) {
b->slen = oldSlen;
return BSTR_ERR;
}
}
#endif
}
return BSTR_OK;
}
#define endSwap(cs,mode) ((mode) ? ((((cs) & 0xFF) << 8) | (((cs) >> 8) & 0xFF)) : (cs))
#define TEMP_UCS4_BUFFER_SIZE (64)
/* int buAppendBlkUTF16 (bstring bu, const cpUcs2* utf16, int len,
* cpUcs2* bom, cpUcs4 errCh)
*
* Append an array of UCS2 code points (utf16) to UTF8 codepoints (bu). Any
* invalid code point is replaced by errCh. If errCh is itself not a
* valid code point, then this translation will halt upon the first error
* and return BSTR_ERR. Otherwise BSTR_OK is returned. If a byte order mark
* has been previously read, it may be passed in as bom, otherwise if *bom is
* set to 0, it will be filled in with the BOM as read from the first
* character if it is a BOM.
*/
int buAppendBlkUTF16 (bstring bu, const cpUcs2* utf16, int len, cpUcs2* bom, cpUcs4 errCh) {
cpUcs4 buff[TEMP_UCS4_BUFFER_SIZE];
int cc, i, sm, oldSlen;
if (NULL == bdata(bu) || NULL == utf16 || len < 0) return BSTR_ERR;
if (!isLegalUnicodeCodePoint (errCh)) errCh = ~0;
if (len == 0) return BSTR_OK;
oldSlen = bu->slen;
i = 0;
/* Check for BOM character and select endianess. Also remove the
BOM from the stream, since there is no need for it in a UTF-8 encoding. */
if (bom && (cpUcs2) 0xFFFE == *bom) {
sm = 8;
} else if (bom && (cpUcs2) 0xFEFF == *bom) {
sm = 0;
} else if (utf16[i] == (cpUcs2) 0xFFFE) {
if (bom) *bom = utf16[i];
sm = 8;
i++;
} else if (utf16[i] == (cpUcs2) 0xFEFF) {
if (bom) *bom = utf16[i];
sm = 0;
i++;
} else {
sm = 0; /* Assume local endianness. */
}
cc = 0;
for (;i < len; i++) {
cpUcs4 c, v;
v = endSwap (utf16[i], sm);
if ((v | 0x7FF) == 0xDFFF) { /* Deal with surrogate pairs */
if (v >= 0xDC00 || i >= len) {
ErrMode:;
if (~0 == errCh) {
ErrReturn:;
bu->slen = oldSlen;
return BSTR_ERR;
}
v = errCh;
} else {
i++;
if ((c = endSwap (utf16[i], sm) - 0xDC00) > 0x3FF) goto ErrMode;
v = ((v - 0xD800) << 10) + c + 0x10000;
}
}
buff[cc] = v;
cc++;
if (cc >= TEMP_UCS4_BUFFER_SIZE) {
if (0 > buAppendBlkUcs4 (bu, buff, cc, errCh)) goto ErrReturn;
cc = 0;
}
}
if (cc > 0 && 0 > buAppendBlkUcs4 (bu, buff, cc, errCh)) goto ErrReturn;
return BSTR_OK;
}

View file

@ -1,37 +0,0 @@
/*
* This source file is part of the bstring string library. This code was
* written by Paul Hsieh in 2002-2015, and is covered by the BSD open source
* license and the GPL. Refer to the accompanying documentation for details
* on usage and license.
*/
/*
* buniutil.h
*
* This file is the interface for the buniutil basic "Unicode for bstrings"
* functions. Note that there are dependencies on bstrlib.h and utf8util.h .
*/
#ifndef BSTRLIB_UNICODE_UTILITIES
#define BSTRLIB_UNICODE_UTILITIES
#include "utf8util.h"
#include "bstrlib.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int buIsUTF8Content (const_bstring bu);
extern int buAppendBlkUcs4 (bstring b, const cpUcs4* bu, int len, cpUcs4 errCh);
/* For those unfortunate enough to be stuck supporting UTF16. */
extern int buGetBlkUTF16 (/* @out */ cpUcs2* ucs2, int len, cpUcs4 errCh, const_bstring bu, int pos);
extern int buAppendBlkUTF16 (bstring bu, const cpUcs2* utf16, int len, cpUcs2* bom, cpUcs4 errCh);
#ifdef __cplusplus
}
#endif
#endif /* BSTRLIB_UNICODE_UTILITIES */

View file

@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View file

@ -1,172 +0,0 @@
Better String library Porting Guide
-----------------------------------
by Paul Hsieh
The bstring library is an attempt to provide improved string processing
functionality to the C and C++ language. At the heart of the bstring library
is the management of "bstring"s which are a significant improvement over '\0'
terminated char buffers. See the accompanying documenation file bstrlib.txt
for more information.
===============================================================================
Identifying the Compiler
------------------------
Bstrlib has been tested on the following compilers:
Microsoft Visual C++
Watcom C/C++ (32 bit flat)
Intel's C/C++ compiler (on Windows)
The GNU C/C++ compiler (on Windows/Linux on x86 and PPC64)
Borland C++
Turbo C
There are slight differences in these compilers which requires slight
differences in the implementation of Bstrlib. These are accomodated in the
same sources using #ifdef/#if defined() on compiler specific macros. To
port Bstrlib to a new compiler not listed above, it is recommended that the
same strategy be followed. If you are unaware of the compiler specific
identifying preprocessor macro for your compiler you might find it here:
http://predef.sourceforge.net/precomp.html
Note that Intel C/C++ on Windows sets the Microsoft identifier: _MSC_VER.
16-bit vs. 32-bit vs. 64-bit Systems
------------------------------------
Bstrlib has been architected to deal with strings of length between 0 and
INT_MAX (inclusive). Since the values of int are never higher than size_t
there will be no issue here. Note that on most 64-bit systems int is 32-bit.
Dependency on The C-Library
---------------------------
Bstrlib uses the functions memcpy, memmove, malloc, realloc, free and
vsnprintf. Many free standing C compiler implementations that have a mode in
which the C library is not available will typically not include these
functions which will make porting Bstrlib to it onerous. Bstrlib is not
designed for such bare bones compiler environments. This usually includes
compilers that target ROM environments.
Porting Issues
--------------
Bstrlib has been written completely in ANSI/ISO C and ISO C++, however, there
are still a few porting issues. These are described below.
1. The vsnprintf () function.
Unfortunately, the earlier ANSI/ISO C standards did not include this function.
If the compiler of interest does not support this function then the
BSTRLIB_NOVSNP should be defined via something like:
#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
# if defined (__TURBOC__) || defined (__COMPILERVENDORSPECIFICMACRO__)
# define BSTRLIB_NOVSNP
# endif
#endif
which appears at the top of bstrlib.h. Note that the bformat(a) functions
will not be declared or implemented if the BSTRLIB_NOVSNP macro is set. If
the compiler has renamed vsnprintf() to some other named function, then
search for the definition of the exvsnprintf macro in bstrlib.c file and be
sure its defined appropriately:
#if defined (__COMPILERVENDORSPECIFICMACRO__)
# define exvsnprintf(r,b,n,f,a) {r=__compiler_specific_vsnprintf(b,n,f,a);}
#else
# define exvsnprintf(r,b,n,f,a) {r=vsnprintf(b,n,f,a);}
#endif
Take notice of the return value being captured in the variable r. It is
assumed that r exceeds n if and only if the underlying vsnprintf function has
determined what the true maximal output length would be for output if the
buffer were large enough to hold it. Non-modern implementations must output a
lesser number (the macro can and should be modified to ensure this).
2. Weak C++ compiler.
C++ is a much more complicated language to implement than C. This has lead
to varying quality of compiler implementations. The weaknesses isolated in
the initial ports are inclusion of the Standard Template Library,
std::iostream and exception handling. By default it is assumed that the C++
compiler supports all of these things correctly. If your compiler does not
support one or more of these define the corresponding macro:
BSTRLIB_CANNOT_USE_STL
BSTRLIB_CANNOT_USE_IOSTREAM
BSTRLIB_DOESNT_THROW_EXCEPTIONS
The compiler specific detected macro should be defined at the top of
bstrwrap.h in the Configuration defines section. Note that these disabling
macros can be overrided with the associated enabling macro if a subsequent
version of the compiler gains support. (For example, its possible to rig
up STLport to provide STL support for WATCOM C/C++, so -DBSTRLIB_CAN_USE_STL
can be passed in as a compiler option.)
3. The bsafe module, and reserved words.
The bsafe module is in gross violation of the ANSI/ISO C standard in the
sense that it redefines what could be implemented as reserved words on a
given compiler. The typical problem is that a compiler may inline some of the
functions and thus not be properly overridden by the definitions in the bsafe
module. It is also possible that a compiler may prohibit the redefinitions in
the bsafe module. Compiler specific action will be required to deal with
these situations.
Platform Specific Files
-----------------------
The makefiles for the examples are basically setup of for particular
environments for each platform. In general these makefiles are not portable
and should be constructed as necessary from scratch for each platform.
Testing a port
--------------
To test that a port compiles correctly do the following:
1. Build a sample project that includes the bstrlib, bstraux, bstrwrap, and
bsafe modules.
2. Compile bstest against the bstrlib module.
3. Run bstest and ensure that 0 errors are reported.
4. Compile test against the bstrlib and bstrwrap modules.
5. Run test and ensure that 0 errors are reported.
6. Compile each of the examples (except for the "re" example, which may be
complicated and is not a real test of bstrlib and except for the mfcbench
example which is Windows specific.)
7. Run each of the examples.
The builds must have 0 errors, and should have the absolute minimum number of
warnings (in most cases can be reduced to 0.) The result of execution should
be essentially identical on each platform.
Performance
-----------
Different CPU and compilers have different capabilities in terms of
performance. It is possible for Bstrlib to assume performance
characteristics that a platform doesn't have (since it was primarily
developed on just one platform). The goal of Bstrlib is to provide very good
performance on all platforms regardless of this but without resorting to
extreme measures (such as using assembly language, or non-portable intrinsics
or library extensions.)
There are two performance benchmarks that can be found in the example/
directory. They are: cbench.c and cppbench.cpp. These are variations and
expansions of a benchmark for another string library. They don't cover all
string functionality, but do include the most basic functions which will be
common in most string manipulation kernels.
...............................................................................
Feedback
--------
In all cases, you may email issues found to the primary author of Bstrlib at
the email address: websnarf@users.sourceforge.net
===============================================================================

Some files were not shown because too many files have changed in this diff Show more