mirror of
https://codeberg.org/libreboot/UEFITool.git
synced 2025-07-04 00:07:00 +00:00
Compare commits
336 commits
A53
...
new_engine
Author | SHA1 | Date | |
---|---|---|---|
|
a072527138 | ||
|
a19aeadb54 | ||
|
775227942a | ||
|
6f6debb212 | ||
|
f64ba09a9c | ||
|
2b23bbd82c | ||
|
9cc9518f8b | ||
|
73d07cddc3 | ||
|
c8b7151b9e | ||
|
892111a8b1 | ||
|
7cea8ee512 | ||
|
c38ed925b0 | ||
|
22bb757726 | ||
|
d61d759db2 | ||
|
7ef371957a | ||
|
97a85f9ddc | ||
|
a077743de8 | ||
|
07742a5069 | ||
|
a12be6bfc7 | ||
|
9719b0cf03 | ||
|
fbf6afdfc8 | ||
|
3cb5dc0165 | ||
|
fd0faea9ea | ||
|
01e2e0877b | ||
|
4e2a8f6bd7 | ||
|
58366f48fe | ||
|
b98edf6944 | ||
|
f989fdfea1 | ||
|
4e600eb986 | ||
|
2d6eaa917f | ||
|
ca7d4caa7a | ||
|
34904bdc5d | ||
|
489b85fd98 | ||
|
2661b8fe4b | ||
|
d91115ff78 | ||
|
0fae05c2cb | ||
|
5e6a1c7119 | ||
|
8d7e01c027 | ||
|
b1ad055eef | ||
|
7dd9014a38 | ||
|
4e3fa5899c | ||
|
369f10188c | ||
|
ff42cecb07 | ||
|
c94f78a530 | ||
|
b5756f9ccb | ||
|
65fb4a86b6 | ||
|
e66bc7d8dc | ||
|
dcf21fa50a | ||
|
0af36bdcd9 | ||
|
fd76e896cc | ||
|
427d8ecdcb | ||
|
a824260064 | ||
|
a777f1fa5f | ||
|
5f2337741a | ||
|
932120cb36 | ||
|
a8c008cf74 | ||
|
6b853f8caf | ||
|
66565a557a | ||
|
371448d0ec | ||
|
b0cd7fe38f | ||
|
4b868bb208 | ||
|
214b356f84 | ||
|
0030ea9481 | ||
|
3441255566 | ||
|
941ee6cfd1 | ||
|
c5508535c1 | ||
|
bf93a5eacc | ||
|
d03a8f254a | ||
|
0a88da1410 | ||
|
6f9a4c0d46 | ||
|
e0b1e0205f | ||
|
161c697104 | ||
|
573452ec09 | ||
|
166c797a20 | ||
|
0e11189644 | ||
|
daf585151c | ||
|
1cba371cc2 | ||
|
4992474e83 | ||
|
29915ca620 | ||
|
4a41c33596 | ||
|
b2a8952c71 | ||
|
036be8d3bc | ||
|
a5675bda90 | ||
|
a7cf9cc3e3 | ||
|
2b8b00d5b0 | ||
|
8e710e637a | ||
|
53f5c5cd71 | ||
|
eaef5c819e | ||
|
b6cdc9f484 | ||
|
031bd4f734 | ||
|
91fb7cdc83 | ||
|
a040c72217 | ||
|
1a1a20895b | ||
|
ddf40c9260 | ||
|
d7c834042f | ||
|
1958ed7fa9 | ||
|
40fed25637 | ||
|
dce666c262 | ||
|
29b339436c | ||
|
d8bdac174d | ||
|
fb5a81ebda | ||
|
4e17fb4f58 | ||
|
cba31d826a | ||
|
cbf26d125d | ||
|
84ea44829a | ||
|
ce92b98527 | ||
|
88fa2d2a47 | ||
|
f1b0cae1a5 | ||
|
12b52902e4 | ||
|
d9e1fe5859 | ||
|
2b876e2cc3 | ||
|
7a25a52427 | ||
|
37372cdab4 | ||
|
ea38ab3696 | ||
|
9c6786a27b | ||
|
6875968d97 | ||
|
aa3e790fb1 | ||
|
6aeb713488 | ||
|
b8567d32cc | ||
|
75bf036137 | ||
|
255742f371 | ||
|
62d96a16df | ||
|
6c695c12a7 | ||
|
7eb565d788 | ||
|
2d1ebcc11b | ||
|
6f9dc0ab88 | ||
|
cb6ef45d0c | ||
|
c4ed9c310d | ||
|
633561adbf | ||
|
3cf8d86c34 | ||
|
38854e945a | ||
|
209fbb6282 | ||
|
69edce7d77 | ||
|
24d61c4375 | ||
|
1c73007e4a | ||
|
a5a0f55149 | ||
|
4053a8fe72 | ||
|
11e00f7113 | ||
|
6232836fb6 | ||
|
745f4b69f2 | ||
|
944133caa7 | ||
|
ef7ceefa41 | ||
|
d48955d45a | ||
|
0c92f935e4 | ||
|
a7aa3fa440 | ||
|
180f061bcc | ||
|
33c25e8255 | ||
|
7a161f577a | ||
|
f02f828571 | ||
|
c9939e23ec | ||
|
20d0155130 | ||
|
43997ab169 | ||
|
b649b98cb5 | ||
|
2467b48802 | ||
|
03d71d6f9f | ||
|
66e9f95dc3 | ||
|
e6b567532d | ||
|
3e55a655da | ||
|
507f884635 | ||
|
fa5d744aac | ||
|
5437efc2c5 | ||
|
1adff58591 | ||
|
eab62138aa | ||
|
19ab6076c4 | ||
|
1b143c89e6 | ||
|
7337f15ec9 | ||
|
15026849d2 | ||
|
862cdb1931 | ||
|
6e7b46d791 | ||
|
47c8938c7e | ||
|
5f134f783a | ||
|
1d560bd0be | ||
|
71a7336730 | ||
|
497fb2a86f | ||
|
c9e16cb180 | ||
|
50396d7291 | ||
|
0429225c56 | ||
|
cd22c3db2b | ||
|
c3cedba150 | ||
|
89a302e5d9 | ||
|
7e5e02b4b4 | ||
|
acc913769b | ||
|
ad8a841f43 | ||
|
d0129d4c63 | ||
|
662e0bf9b1 | ||
|
ee6b536009 | ||
|
799f186852 | ||
|
7d4e535c34 | ||
|
6247fa5bbc | ||
|
9bb0549ad2 | ||
|
e38e246bf5 | ||
|
6ca7d99f66 | ||
|
739de0fec8 | ||
|
152fcc44a5 | ||
|
d1032d59fd | ||
|
26a2f46197 | ||
|
a9d1016a52 | ||
|
4358f31242 | ||
|
574754fce6 | ||
|
6e5cc3bccc | ||
|
011647aa30 | ||
|
a4a455d0ff | ||
|
06653d024b | ||
|
f514c60cba | ||
|
109d30b5e6 | ||
|
ce2291a23c | ||
|
b457ed99cd | ||
|
c4ca232b3a | ||
|
a9c6f347a2 | ||
|
22d1db8c7f | ||
|
75a1374c0c | ||
|
934ce1f3f8 | ||
|
8600bc3ab3 | ||
|
55d4b4fc66 | ||
|
2be53035b6 | ||
|
d6bf25df67 | ||
|
787e02181a | ||
|
3977fcaed9 | ||
|
9cd97e78e6 | ||
|
1675498d4d | ||
|
d93f1ae749 | ||
|
e9261a9900 | ||
|
f58a97a657 | ||
|
eef00f73a4 | ||
|
7695927eec | ||
|
e5b594c347 | ||
|
67c568daf8 | ||
|
4006954bc1 | ||
|
10e2e60183 | ||
|
eb3185224b | ||
|
83548d4c8a | ||
|
2246026434 | ||
|
ff864f9b8f | ||
|
f626316b1e | ||
|
7951bc1bcf | ||
|
19ec41b7e2 | ||
|
3aafbdd269 | ||
|
4c74232688 | ||
|
74910c4658 | ||
|
eabd6a8604 | ||
|
820e3ea65d | ||
|
d7f360e337 | ||
|
e36cc77c06 | ||
|
e85fb741ee | ||
|
12f40cf289 | ||
|
cc274319bf | ||
|
d46489fabb | ||
|
7c534cca2a | ||
|
d9af12b567 | ||
|
fae9d6681d | ||
|
1f488862c6 | ||
|
963671a73e | ||
|
2a083d8739 | ||
|
44bb6e8261 | ||
|
f9c35f77a6 | ||
|
e14547c497 | ||
|
44c5b4bc49 | ||
|
0fb88ab760 | ||
|
a754fb5153 | ||
|
34c8ad8dcc | ||
|
d1e47539fc | ||
|
2335e69dce | ||
|
5066a44132 | ||
|
6bb862d626 | ||
|
e6f3f4380f | ||
|
05f770c8a4 | ||
|
fd1e8c4856 | ||
|
8f862d4fdb | ||
|
3945c9b89f | ||
|
5645599c58 | ||
|
115d338a70 | ||
|
5967865028 | ||
|
78714f6755 | ||
|
10295bd0dd | ||
|
24cf452024 | ||
|
55b7a759ff | ||
|
92d0a8f754 | ||
|
d69aca6554 | ||
|
7bce6fac92 | ||
|
812af96d82 | ||
|
0edd935d28 | ||
|
446dba9d64 | ||
|
0504af6fdc | ||
|
bfbf18404d | ||
|
750b589575 | ||
|
9351f697ff | ||
|
ae133acc59 | ||
|
753b8ee893 | ||
|
b96772190a | ||
|
a2d7169a82 | ||
|
57e4d6dfa0 | ||
|
cd110eafa6 | ||
|
fc2d8f07b1 | ||
|
30d05a9fed | ||
|
65670a704c | ||
|
8e189f88df | ||
|
0f31b1401e | ||
|
07dbfa3f96 | ||
|
ac1f24ec77 | ||
|
a3425115b8 | ||
|
0f2ede398d | ||
|
6fdc69415b | ||
|
1dccf3f15a | ||
|
4d948475d8 | ||
|
bf3adbe4c6 | ||
|
516949a6e6 | ||
|
2ef8d770e4 | ||
|
1b2ea8c276 | ||
|
f2e343d8bf | ||
|
967375243c | ||
|
8bddbe7d1f | ||
|
3507698136 | ||
|
64e1aa18b8 | ||
|
95c838181f | ||
|
90ff19692d | ||
|
d95e533441 | ||
|
fa954394cc | ||
|
1e1d5c6e17 | ||
|
47637ef152 | ||
|
a01d2c6003 | ||
|
2e7aa8133a | ||
|
f386eda430 | ||
|
be65f8ae06 | ||
|
5edd5c10ee | ||
|
2cbd78fb9e | ||
|
e7455409ff | ||
|
f34894b9fd | ||
|
5c98152c58 | ||
|
f863caac9d | ||
|
1ac6e6a4f0 | ||
|
40b77a713f | ||
|
d16c438069 | ||
|
afce02430a | ||
|
be2cdc7dfe | ||
|
f074dfc5ca | ||
|
d9325c22fe |
265 changed files with 60308 additions and 16279 deletions
|
@ -1,27 +0,0 @@
|
|||
image: Visual Studio 2015
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- MSYS2_ARCH: i686
|
||||
MSYSTEM: MINGW32
|
||||
|
||||
clone_depth: 10
|
||||
|
||||
build_script:
|
||||
- cd %APPVEYOR_BUILD_FOLDER%
|
||||
- set PATH=C:\msys64\mingw32\bin;C:\msys64\usr\bin;%PATH%
|
||||
- bash ./unixbuild.sh
|
||||
|
||||
deploy:
|
||||
provider: GitHub
|
||||
force_update: true
|
||||
auth_token:
|
||||
secure: zSJnpSnrKY1NO5RPVBaD/uq7UPyc+GW7ecjPFqEMsLjtnd6H+iNfROdoeuxJgt5T
|
||||
artifact: Binaries
|
||||
prerelease: true
|
||||
on:
|
||||
appveyor_repo_tag: true
|
||||
|
||||
artifacts:
|
||||
- path: dist\**\*.zip
|
||||
name: Binaries
|
418
.github/workflows/main.yml
vendored
Normal file
418
.github/workflows/main.yml
vendored
Normal 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"
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -235,10 +235,10 @@ Makefile
|
|||
|
||||
uefitool_plugin_import.cpp
|
||||
UEFITool.app/
|
||||
UEFITool/Info.plist
|
||||
UEFITool/XCBuildData
|
||||
UEFIDump/UEFIDump
|
||||
UEFIExtract/UEFIExtract
|
||||
UEFIExtract/guids.csv
|
||||
UEFIFind/UEFIFind
|
||||
.qmake.stash
|
||||
CMakeCache.txt
|
||||
|
@ -249,3 +249,6 @@ DerivedData
|
|||
compile_commands.json
|
||||
CMakeScripts
|
||||
UEFITool/qrc_uefitool.cpp
|
||||
XcodeQT5
|
||||
XcodeQT6
|
||||
*.dSYM
|
||||
|
|
78
.travis.yml
78
.travis.yml
|
@ -1,78 +0,0 @@
|
|||
language: cpp
|
||||
|
||||
env:
|
||||
global:
|
||||
secure: "cWSx7cf7dOyGzqY12imfKIF0G0ImcjChHLpWuDU4dfSl+BvPh8WURhQqwpPihFzA4j+Ob9IdgJdEINW4ZKs5Fqt9NqpqTbsGlv7xMeGSNMymlwzwrY63CU8td6z/ju8Tgvi9I7aHtrYCbi4RCw2vPRzBihgwXTzQg6LWFoVT+XQ="
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
osx_image: xcode9.2
|
||||
|
||||
compiler: clang
|
||||
|
||||
script:
|
||||
- ./unixbuild.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
skip_cleanup: true
|
||||
file: "dist/*.zip"
|
||||
file_glob: true
|
||||
api_key:
|
||||
secure: "WjYd93lVLKHULBpUXS/WtGrkdXyAwxHOUnLJotyDmQipAQP5Ox7Kj12JwkSJGEmVOEdcbIQJyi0QxPjn1UYbYsAt6Op8zrjnYLS4G4fMdBtcxprWzid85uTW7oAAIFs7ygMVhpzxRKpu70yNb683vbThqNmaOu6RyG9aJOLtPAg="
|
||||
on:
|
||||
tags: true
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq qt5-default qt5-qmake qtbase5-dev-tools cmake
|
||||
|
||||
script:
|
||||
- ./unixbuild.sh
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq qt5-default qt5-qmake qtbase5-dev-tools cmake
|
||||
|
||||
script:
|
||||
- ./unixbuild.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
skip_cleanup: true
|
||||
file: "dist/*.zip"
|
||||
file_glob: true
|
||||
api_key:
|
||||
secure: "WjYd93lVLKHULBpUXS/WtGrkdXyAwxHOUnLJotyDmQipAQP5Ox7Kj12JwkSJGEmVOEdcbIQJyi0QxPjn1UYbYsAt6Op8zrjnYLS4G4fMdBtcxprWzid85uTW7oAAIFs7ygMVhpzxRKpu70yNb683vbThqNmaOu6RyG9aJOLtPAg="
|
||||
on:
|
||||
tags: true
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq qt5-default qt5-qmake qtbase5-dev-tools cmake
|
||||
|
||||
script:
|
||||
- echo "This script runs coverity..."
|
||||
|
||||
addons:
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "LongSoft/UEFITool"
|
||||
description: "UEFITool"
|
||||
notification_email: $NOTIFICATION_EMAIL
|
||||
build_command_prepend: "./unixbuild.sh --configure"
|
||||
build_command: "./unixbuild.sh --build"
|
||||
branch_pattern: new_engine
|
7
CMakeLists.txt
Normal file
7
CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
|
||||
|
||||
PROJECT(UEFITool_everything)
|
||||
|
||||
ADD_SUBDIRECTORY(UEFIExtract)
|
||||
ADD_SUBDIRECTORY(UEFIFind)
|
||||
ADD_SUBDIRECTORY(UEFITool)
|
33
README.md
33
README.md
|
@ -3,7 +3,7 @@
|
|||
UEFITool is a viewer and editor of firmware images conforming to UEFI Platform Interface (PI) Specifications.
|
||||
|
||||

|
||||
[](https://travis-ci.org/LongSoft/UEFITool) [](https://scan.coverity.com/projects/17209)
|
||||
 [](https://scan.coverity.com/projects/17209) [](https://sonarcloud.io/summary/new_code?id=LongSoft_UEFITool)
|
||||
|
||||
|
||||
## 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:
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
## Alternatives
|
||||
|
||||
Right now there are some alternatives to UEFITool that you could find useful too:
|
||||
* **[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](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.
|
||||
* **[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.
|
||||
* **[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
|
||||
|
||||
You can either use [pre-built binaries for Windows and macOS](https://github.com/LongSoft/UEFITool/releases) or build a binary yourself.
|
||||
* To build a binary that uses Qt library (UEFITool) you need a C++ compiler and an instance of [Qt5](https://www.qt.io) 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 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).
|
||||
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) 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 (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
|
||||
|
||||
* 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.
|
||||
* 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).
|
||||
* Builder code is still not ready.
|
||||
* 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/).
|
||||
* 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).
|
||||
|
|
|
@ -1,30 +1,61 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
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/sha256.c
|
||||
../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
|
||||
|
@ -42,47 +73,20 @@ SET(PROJECT_SOURCES
|
|||
../common/zlib/zutil.c
|
||||
)
|
||||
|
||||
SET(PROJECT_HEADERS
|
||||
ffsdumper.h
|
||||
uefidump.h
|
||||
../common/guiddatabase.h
|
||||
../common/basetypes.h
|
||||
../common/descriptor.h
|
||||
../common/gbe.h
|
||||
../common/me.h
|
||||
../common/ffs.h
|
||||
../common/nvram.h
|
||||
../common/nvramparser.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
|
||||
../common/bootguard.h
|
||||
../common/sha256.h
|
||||
../common/filesystem.h
|
||||
../common/bstrlib/bstrlib.h
|
||||
../common/bstrlib/bstrwrap.h
|
||||
../common/zlib/zconf.h
|
||||
../common/zlib/zlib.h
|
||||
../common/zlib/crc32.h
|
||||
../common/zlib/deflate.h
|
||||
../common/zlib/gzguts.h
|
||||
../common/zlib/inffast.h
|
||||
../common/zlib/inffixed.h
|
||||
../common/zlib/inflate.h
|
||||
../common/zlib/inftrees.h
|
||||
../common/zlib/trees.h
|
||||
../common/zlib/zutil.h
|
||||
../version.h
|
||||
ADD_DEFINITIONS(
|
||||
-DU_ENABLE_NVRAM_PARSING_SUPPORT
|
||||
-DU_ENABLE_ME_PARSING_SUPPORT
|
||||
-DU_ENABLE_FIT_PARSING_SUPPORT
|
||||
-DU_ENABLE_GUID_DATABASE_SUPPORT
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DU_ENABLE_NVRAM_PARSING_SUPPORT -DU_ENABLE_FIT_PARSING_SUPPORT -DU_ENABLE_GUID_DATABASE_SUPPORT)
|
||||
ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} uefiextract.manifest)
|
||||
|
||||
ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} ${PROJECT_HEADERS})
|
||||
IF(UNIX)
|
||||
SET_TARGET_PROPERTIES(UEFIExtract PROPERTIES OUTPUT_NAME uefiextract)
|
||||
ENDIF()
|
||||
|
||||
INSTALL(
|
||||
TARGETS UEFIExtract
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
|
|
@ -21,16 +21,21 @@ USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const Du
|
|||
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||
fileList.clear();
|
||||
|
||||
if (changeDirectory(path))
|
||||
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;
|
||||
} else if (!dumped) {
|
||||
removeDirectory(path);
|
||||
if (removeDirectory(path)) {
|
||||
printf("Removed directory \"%s\" since nothing was dumped.\n", (const char*)path.toLocal8Bit());
|
||||
}
|
||||
return U_ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
@ -48,11 +53,13 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
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 (!changeDirectory(path) && !makeDirectory(path))
|
||||
if (!changeDirectory(path) && !makeDirectory(path)) {
|
||||
printf("Cannot use directory \"%s\" (recursiveDump part 1).\n", (const char*)path.toLocal8Bit());
|
||||
return U_DIR_CREATE;
|
||||
}
|
||||
|
||||
if (currentPath != path) {
|
||||
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||
counterHeader = counterBody = counterUncData = counterRaw = counterInfo = 0;
|
||||
currentPath = path;
|
||||
}
|
||||
|
||||
|
@ -61,7 +68,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||
|
||||
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER)
|
||||
&& !model->header(index).isEmpty()) {
|
||||
&& !model->hasEmptyHeader(index)) {
|
||||
fileList.insert(index);
|
||||
|
||||
UString filename;
|
||||
|
@ -72,8 +79,10 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
counterHeader++;
|
||||
|
||||
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||
if (!file)
|
||||
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());
|
||||
|
@ -82,7 +91,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
}
|
||||
|
||||
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY)
|
||||
&& !model->body(index).isEmpty()) {
|
||||
&& !model->hasEmptyBody(index)) {
|
||||
fileList.insert(index);
|
||||
UString filename;
|
||||
if (counterBody == 0)
|
||||
|
@ -92,8 +101,10 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
counterBody++;
|
||||
|
||||
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||
if (!file)
|
||||
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());
|
||||
|
@ -101,6 +112,28 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
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) {
|
||||
|
@ -109,28 +142,33 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
fileIndex = index;
|
||||
}
|
||||
|
||||
fileList.insert(fileIndex);
|
||||
// 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++;
|
||||
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)
|
||||
return U_FILE_OPEN;
|
||||
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);
|
||||
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());
|
||||
file.write(headerData.constData(), headerData.size());
|
||||
file.write(bodyData.constData(), bodyData.size());
|
||||
file.write(tailData.constData(), tailData.size());
|
||||
|
||||
dumped = true;
|
||||
dumped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +190,10 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
counterInfo++;
|
||||
|
||||
std::ofstream file(filename.toLocal8Bit());
|
||||
if (!file)
|
||||
if (!file) {
|
||||
printf("Cannot open info \"%s\".\n", (const char*)filename.toLocal8Bit());
|
||||
return U_FILE_OPEN;
|
||||
}
|
||||
|
||||
file << info.toLocal8Bit();
|
||||
|
||||
|
@ -162,6 +202,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
}
|
||||
|
||||
USTATUS result;
|
||||
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
UModelIndex childIndex = index.child(i, 0);
|
||||
bool useText = FALSE;
|
||||
|
@ -169,12 +210,21 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||
useText = !model->text(childIndex).isEmpty();
|
||||
|
||||
UString childPath = path;
|
||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
||||
childPath = usprintf("%s/%d %s", path.toLocal8Bit(), i,
|
||||
(useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit());
|
||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT) {
|
||||
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)
|
||||
if (result) {
|
||||
printf("Error %zu returned from recursiveDump (child directory \"%s\").\n", result, (const char*)childPath.toLocal8Bit());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return U_SUCCESS;
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
DUMP_CURRENT,
|
||||
DUMP_ALL,
|
||||
DUMP_BODY,
|
||||
DUMP_UNC_DATA,
|
||||
DUMP_HEADER,
|
||||
DUMP_INFO,
|
||||
DUMP_FILE
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
static const UINT8 IgnoreSectionType = 0xFF;
|
||||
|
||||
explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false),
|
||||
counterHeader(0), counterBody(0), counterRaw(0), counterInfo(0) {}
|
||||
counterHeader(0), counterBody(0), counterUncData(0), counterRaw(0), counterInfo(0) {}
|
||||
~FfsDumper() {};
|
||||
|
||||
USTATUS dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const UString & guid = UString());
|
||||
|
@ -48,7 +49,7 @@ private:
|
|||
TreeModel* model;
|
||||
UString currentPath;
|
||||
bool dumped;
|
||||
int counterHeader, counterBody, counterRaw, counterInfo;
|
||||
int counterHeader, counterBody, counterUncData, counterRaw, counterInfo;
|
||||
std::set<UModelIndex> fileList;
|
||||
};
|
||||
#endif // FFSDUMPER_H
|
||||
|
|
17
UEFIExtract/meson.build
Normal file
17
UEFIExtract/meson.build
Normal file
|
@ -0,0 +1,17 @@
|
|||
executable(
|
||||
'UEFIExtract',
|
||||
sources: [
|
||||
'uefiextract_main.cpp',
|
||||
'ffsdumper.cpp',
|
||||
'uefidump.cpp',
|
||||
],
|
||||
link_with: [
|
||||
lzma,
|
||||
bstrlib,
|
||||
uefitoolcommon,
|
||||
],
|
||||
dependencies: [
|
||||
zlib,
|
||||
],
|
||||
install: true,
|
||||
)
|
|
@ -41,27 +41,8 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons
|
|||
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::pair<std::vector<UString>, UModelIndex > > fitTable = ffsParser.getFitTable();
|
||||
if (fitTable.size()) {
|
||||
std::cout << "-------------------------------------------------------------------------" << std::endl;
|
||||
std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl;
|
||||
std::cout << "-------------------------------------------------------------------------" << std::endl;
|
||||
for (size_t i = 0; i < fitTable.size(); i++) {
|
||||
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[1].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[2].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[3].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[4].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[5].toLocal8Bit() << std::endl;
|
||||
}
|
||||
}
|
||||
ffsParser.outputInfo();
|
||||
|
||||
// Create ffsReport
|
||||
FfsReport ffsReport(&model);
|
||||
|
@ -104,65 +85,59 @@ 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));
|
||||
// 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 (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)) {
|
||||
if (!nameFound) {
|
||||
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
|
||||
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
|
||||
}
|
||||
|
||||
// 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);
|
||||
// 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();
|
||||
}
|
||||
|
||||
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(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();
|
||||
}
|
||||
// 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";
|
||||
}
|
||||
// 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();
|
||||
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;
|
||||
//}
|
||||
dumped = true;
|
||||
|
||||
// Process child items
|
||||
USTATUS result;
|
||||
|
|
8
UEFIExtract/uefiextract.manifest
Normal file
8
UEFIExtract/uefiextract.manifest
Normal 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>
|
|
@ -30,131 +30,97 @@ enum ReadType {
|
|||
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[])
|
||||
{
|
||||
initGuidDatabase("guids.csv");
|
||||
|
||||
if (argc > 1) {
|
||||
// Check that input file exists
|
||||
USTATUS result;
|
||||
UByteArray buffer;
|
||||
UString path = getAbsPath(argv[1]);
|
||||
result = readFileIntoBuffer(path, buffer);
|
||||
if (result)
|
||||
return result;
|
||||
if (argc <= 1) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Hack to support legacy UEFIDump mode.
|
||||
if (argc == 3 && !std::strcmp(argv[2], "unpack")) {
|
||||
UEFIDumper uefidumper;
|
||||
return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS);
|
||||
// Help and version
|
||||
if (argc == 2) {
|
||||
UString arg = UString(argv[1]);
|
||||
if (arg == UString("-h") || arg == UString("--help")) {
|
||||
print_usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create model and ffsParser
|
||||
TreeModel model;
|
||||
FfsParser ffsParser(&model);
|
||||
// Parse input buffer
|
||||
result = ffsParser.parse(buffer);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
// Show ffsParser's messages
|
||||
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages();
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
std::cout << messages[i].first.toLocal8Bit() << std::endl;
|
||||
else if (arg == UString("-v") || arg == UString("--version")) {
|
||||
std::cout << PROGRAM_VERSION << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Get last VTF
|
||||
std::vector<std::pair<std::vector<UString>, UModelIndex > > fitTable = ffsParser.getFitTable();
|
||||
if (fitTable.size()) {
|
||||
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
||||
std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl;
|
||||
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
||||
for (size_t i = 0; i < fitTable.size(); i++) {
|
||||
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[1].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[2].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[3].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[4].toLocal8Bit() << " | "
|
||||
<< fitTable[i].first[5].toLocal8Bit() << std::endl;
|
||||
}
|
||||
// Check that input file exists
|
||||
USTATUS result;
|
||||
UByteArray buffer;
|
||||
UString path = getAbsPath(argv[1]);
|
||||
if (false == readFileIntoBuffer(path, buffer))
|
||||
return U_FILE_OPEN;
|
||||
|
||||
// Hack to support legacy UEFIDump mode
|
||||
if (argc == 3 && !std::strcmp(argv[2], "unpack")) {
|
||||
UEFIDumper uefidumper;
|
||||
return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS);
|
||||
}
|
||||
|
||||
// Create model and ffsParser
|
||||
TreeModel model;
|
||||
FfsParser ffsParser(&model);
|
||||
// Parse input buffer
|
||||
result = ffsParser.parse(buffer);
|
||||
if (result)
|
||||
return (int)result;
|
||||
|
||||
ffsParser.outputInfo();
|
||||
|
||||
// Create ffsDumper
|
||||
FfsDumper ffsDumper(&model);
|
||||
|
||||
// Dump only leaf elements, no report or GUID database
|
||||
if (argc == 3 && !std::strcmp(argv[2], "dump")) {
|
||||
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
||||
}
|
||||
// Dump named GUIDs found in the image, no dump or report
|
||||
else if (argc == 3 && !std::strcmp(argv[2], "guids")) {
|
||||
GuidDatabase db = guidDatabaseFromTreeRecursive(&model, model.index(0, 0));
|
||||
if (!db.empty()) {
|
||||
return (int)guidDatabaseExportToFile(path + UString(".guids.csv"), db);
|
||||
}
|
||||
|
||||
|
||||
// Create ffsDumper
|
||||
FfsDumper ffsDumper(&model);
|
||||
|
||||
// Dump only leaf elements, no report
|
||||
if (argc == 3 && !std::strcmp(argv[2], "dump")) {
|
||||
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
||||
}
|
||||
// Generate report, no dump or GUID database
|
||||
else if (argc == 3 && !std::strcmp(argv[2], "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';
|
||||
return 0;
|
||||
}
|
||||
else if (argc > 3 ||
|
||||
(argc == 3 && std::strcmp(argv[2], "all") != 0 && std::strcmp(argv[2], "report") != 0)) { // Dump specific files, without report
|
||||
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, "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 lastError;
|
||||
}
|
||||
|
||||
// Create ffsReport
|
||||
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()) {
|
||||
|
@ -164,27 +130,90 @@ int main(int argc, char *argv[])
|
|||
file << report[i].toLocal8Bit() << '\n';
|
||||
}
|
||||
|
||||
// Dump all non-leaf elements, with report, default
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
else if (argc == 3 && !std::strcmp(argv[2], "report")) { // Skip dumping
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// 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
|
||||
std::cout << "UEFIExtract " PROGRAM_VERSION << std::endl << std::endl
|
||||
<< "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 unpack - generate report and dump all tree items in one dir." << 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 ... [ -o FILE_1 ... ] [ -m MODE_1 ... ] [ -t TYPE_1 ... ] -" << std::endl
|
||||
<< " Dump only FFS file(s) with specific GUID(s), without report." << std::endl
|
||||
<< " Type is section type or FF to ignore. Mode is one of: all, body, 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;
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,29 +1,58 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
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/ffsreport.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/sha256.c
|
||||
../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
|
||||
|
@ -41,46 +70,13 @@ SET(PROJECT_SOURCES
|
|||
../common/zlib/zutil.c
|
||||
)
|
||||
|
||||
SET(PROJECT_HEADERS
|
||||
uefifind.h
|
||||
../common/guiddatabase.h
|
||||
../common/basetypes.h
|
||||
../common/descriptor.h
|
||||
../common/gbe.h
|
||||
../common/me.h
|
||||
../common/ffs.h
|
||||
../common/nvram.h
|
||||
../common/nvramparser.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
|
||||
../common/bootguard.h
|
||||
../common/sha256.h
|
||||
../common/filesystem.h
|
||||
../common/bstrlib/bstrlib.h
|
||||
../common/bstrlib/bstrwrap.h
|
||||
../common/zlib/zconf.h
|
||||
../common/zlib/zlib.h
|
||||
../common/zlib/crc32.h
|
||||
../common/zlib/deflate.h
|
||||
../common/zlib/gzguts.h
|
||||
../common/zlib/inffast.h
|
||||
../common/zlib/inffixed.h
|
||||
../common/zlib/inflate.h
|
||||
../common/zlib/inftrees.h
|
||||
../common/zlib/trees.h
|
||||
../common/zlib/zutil.h
|
||||
../version.h
|
||||
ADD_EXECUTABLE(UEFIFind ${PROJECT_SOURCES} uefifind.manifest)
|
||||
|
||||
IF(UNIX)
|
||||
SET_TARGET_PROPERTIES(UEFIFind PROPERTIES OUTPUT_NAME uefifind)
|
||||
ENDIF()
|
||||
|
||||
INSTALL(
|
||||
TARGETS UEFIFind
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DU_ENABLE_NVRAM_PARSING_SUPPORT -DU_ENABLE_FIT_PARSING_SUPPORT -DU_ENABLE_GUID_DATABASE_SUPPORT)
|
||||
|
||||
ADD_EXECUTABLE(UEFIFind ${PROJECT_SOURCES} ${PROJECT_HEADERS})
|
16
UEFIFind/meson.build
Normal file
16
UEFIFind/meson.build
Normal file
|
@ -0,0 +1,16 @@
|
|||
executable(
|
||||
'UEFIFind',
|
||||
sources: [
|
||||
'uefifind_main.cpp',
|
||||
'uefifind.cpp',
|
||||
],
|
||||
link_with: [
|
||||
lzma,
|
||||
bstrlib,
|
||||
uefitoolcommon,
|
||||
],
|
||||
dependencies: [
|
||||
zlib,
|
||||
],
|
||||
install: true,
|
||||
)
|
|
@ -12,8 +12,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
*/
|
||||
|
||||
#include "uefifind.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
|
||||
UEFIFind::UEFIFind()
|
||||
{
|
||||
|
@ -31,13 +32,11 @@ UEFIFind::~UEFIFind()
|
|||
|
||||
USTATUS UEFIFind::init(const UString & path)
|
||||
{
|
||||
USTATUS result;
|
||||
UByteArray buffer;
|
||||
result = readFileIntoBuffer(path, buffer);
|
||||
if (result)
|
||||
return result;
|
||||
if (false == readFileIntoBuffer(path, buffer))
|
||||
return U_FILE_OPEN;
|
||||
|
||||
result = ffsParser->parse(buffer);
|
||||
USTATUS result = ffsParser->parse(buffer);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
|
@ -45,41 +44,6 @@ USTATUS UEFIFind::init(const UString & path)
|
|||
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();
|
||||
|
||||
USTATUS returned = findFileRecursive(root, hexPattern, mode, files);
|
||||
if (returned)
|
||||
return returned;
|
||||
|
||||
if (count) {
|
||||
if (!files.empty())
|
||||
result += usprintf("%d\n", files.size());
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
for (std::set<std::pair<UModelIndex, UModelIndex> >::const_iterator citer = files.begin(); citer != files.end(); ++citer) {
|
||||
UByteArray data(16, '\x00');
|
||||
std::pair<UModelIndex, UModelIndex> indexes = *citer;
|
||||
if (!model->hasEmptyHeader(indexes.first))
|
||||
data = model->header(indexes.first).left(16);
|
||||
result += guidToUString(readUnaligned((const EFI_GUID*)data.constData()));
|
||||
|
||||
// Special case of freeform subtype GUID files
|
||||
if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
|
||||
data = model->header(indexes.second);
|
||||
result += UString(" ") + (guidToUString(readUnaligned((const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))));
|
||||
}
|
||||
|
||||
result += UString("\n");
|
||||
}
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files)
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
@ -101,41 +65,84 @@ USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hex
|
|||
if (count == patternMask.size())
|
||||
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);
|
||||
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 || mode == SEARCH_MODE_ALL)
|
||||
data += model->header(index);
|
||||
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);
|
||||
data = model->header(index);
|
||||
else if (mode == SEARCH_MODE_BODY)
|
||||
data += model->body(index);
|
||||
data = model->body(index);
|
||||
else
|
||||
data += model->header(index) + model->body(index);
|
||||
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 ffs = model->findParentOfType(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>(ffs, index));
|
||||
files.insert(std::pair<UModelIndex, UModelIndex>(parentFile, index));
|
||||
else
|
||||
files.insert(std::pair<UModelIndex, UModelIndex>(ffs, UModelIndex()));
|
||||
files.insert(std::pair<UModelIndex, UModelIndex>(parentFile, UModelIndex()));
|
||||
}
|
||||
else
|
||||
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();
|
||||
|
||||
USTATUS returned = findFileRecursive(root, hexPattern, mode, files);
|
||||
if (returned)
|
||||
return returned;
|
||||
|
||||
if (count) {
|
||||
if (!files.empty())
|
||||
result += usprintf("%lu\n", files.size());
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
for (std::set<std::pair<UModelIndex, UModelIndex> >::const_iterator citer = files.begin(); citer != files.end(); ++citer) {
|
||||
UByteArray data(16, '\x00');
|
||||
std::pair<UModelIndex, UModelIndex> indexes = *citer;
|
||||
if (!model->hasEmptyHeader(indexes.first))
|
||||
data = model->header(indexes.first).left(16);
|
||||
result += guidToUString(readUnaligned((const EFI_GUID*)data.constData()));
|
||||
|
||||
// Special case of freeform subtype GUID files
|
||||
if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
|
||||
data = model->header(indexes.second);
|
||||
result += UString(" ") + (guidToUString(readUnaligned((const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))));
|
||||
}
|
||||
|
||||
result += UString("\n");
|
||||
}
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ public:
|
|||
|
||||
private:
|
||||
USTATUS findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files);
|
||||
UString guidToQString(const UINT8* guid);
|
||||
|
||||
FfsParser* ffsParser;
|
||||
TreeModel* model;
|
||||
|
|
8
UEFIFind/uefifind.manifest
Normal file
8
UEFIFind/uefifind.manifest
Normal 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>
|
|
@ -19,14 +19,35 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#include "../common/guiddatabase.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[])
|
||||
{
|
||||
UEFIFind w;
|
||||
USTATUS result;
|
||||
|
||||
initGuidDatabase("guids.csv");
|
||||
|
||||
if (argc == 5) {
|
||||
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];
|
||||
|
@ -165,10 +186,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
return U_SUCCESS;
|
||||
}
|
||||
else {
|
||||
std::cout << "UEFIFind " PROGRAM_VERSION << std::endl << std::endl <<
|
||||
"Usage: UEFIFind imagefile {header | body | all} {list | count} pattern" << std::endl <<
|
||||
" or UEFIFind imagefile file patternsfile" << std::endl;
|
||||
return U_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
print_usage();
|
||||
return U_INVALID_PARAMETER;
|
||||
}
|
||||
|
|
146
UEFITool/CMakeLists.txt
Normal file
146
UEFITool/CMakeLists.txt
Normal 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
33
UEFITool/Info.plist
Normal 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>
|
91
UEFITool/QHexView/CMakeLists.txt
Normal file
91
UEFITool/QHexView/CMakeLists.txt
Normal 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
20
UEFITool/QHexView/LICENSE
Normal 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.
|
56
UEFITool/QHexView/include/QHexView/dialogs/hexfinddialog.h
Normal file
56
UEFITool/QHexView/include/QHexView/dialogs/hexfinddialog.h
Normal 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;
|
||||
};
|
|
@ -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};
|
||||
};
|
29
UEFITool/QHexView/include/QHexView/model/buffer/qhexbuffer.h
Normal file
29
UEFITool/QHexView/include/QHexView/model/buffer/qhexbuffer.h
Normal 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;
|
||||
};
|
|
@ -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};
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
73
UEFITool/QHexView/include/QHexView/model/qhexcursor.h
Normal file
73
UEFITool/QHexView/include/QHexView/model/qhexcursor.h
Normal 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;
|
||||
};
|
30
UEFITool/QHexView/include/QHexView/model/qhexdelegate.h
Normal file
30
UEFITool/QHexView/include/QHexView/model/qhexdelegate.h
Normal 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;
|
||||
};
|
102
UEFITool/QHexView/include/QHexView/model/qhexdocument.h
Normal file
102
UEFITool/QHexView/include/QHexView/model/qhexdocument.h
Normal 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);
|
||||
}
|
92
UEFITool/QHexView/include/QHexView/model/qhexmetadata.h
Normal file
92
UEFITool/QHexView/include/QHexView/model/qhexmetadata.h
Normal 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;
|
||||
};
|
56
UEFITool/QHexView/include/QHexView/model/qhexoptions.h
Normal file
56
UEFITool/QHexView/include/QHexView/model/qhexoptions.h
Normal 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; }
|
||||
};
|
66
UEFITool/QHexView/include/QHexView/model/qhexutils.h
Normal file
66
UEFITool/QHexView/include/QHexView/model/qhexutils.h
Normal 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
|
184
UEFITool/QHexView/include/QHexView/qhexview.h
Normal file
184
UEFITool/QHexView/include/QHexView/qhexview.h
Normal 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;
|
||||
};
|
418
UEFITool/QHexView/src/dialogs/hexfinddialog.cpp
Normal file
418
UEFITool/QHexView/src/dialogs/hexfinddialog.cpp
Normal 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());
|
||||
}
|
118
UEFITool/QHexView/src/model/buffer/qdevicebuffer.cpp
Normal file
118
UEFITool/QHexView/src/model/buffer/qdevicebuffer.cpp
Normal 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;
|
||||
}
|
36
UEFITool/QHexView/src/model/buffer/qhexbuffer.cpp
Normal file
36
UEFITool/QHexView/src/model/buffer/qhexbuffer.cpp
Normal 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);
|
||||
}
|
51
UEFITool/QHexView/src/model/buffer/qmappedfilebuffer.cpp
Normal file
51
UEFITool/QHexView/src/model/buffer/qmappedfilebuffer.cpp
Normal 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());
|
||||
}
|
39
UEFITool/QHexView/src/model/buffer/qmemorybuffer.cpp
Normal file
39
UEFITool/QHexView/src/model/buffer/qmemorybuffer.cpp
Normal 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));
|
||||
}
|
26
UEFITool/QHexView/src/model/buffer/qmemoryrefbuffer.cpp
Normal file
26
UEFITool/QHexView/src/model/buffer/qmemoryrefbuffer.cpp
Normal 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));
|
||||
}
|
6
UEFITool/QHexView/src/model/commands/hexcommand.cpp
Normal file
6
UEFITool/QHexView/src/model/commands/hexcommand.cpp
Normal 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) {}
|
18
UEFITool/QHexView/src/model/commands/insertcommand.cpp
Normal file
18
UEFITool/QHexView/src/model/commands/insertcommand.cpp
Normal 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); }
|
20
UEFITool/QHexView/src/model/commands/removecommand.cpp
Normal file
20
UEFITool/QHexView/src/model/commands/removecommand.cpp
Normal 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);
|
||||
}
|
21
UEFITool/QHexView/src/model/commands/replacecommand.cpp
Normal file
21
UEFITool/QHexView/src/model/commands/replacecommand.cpp
Normal 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);
|
||||
}
|
182
UEFITool/QHexView/src/model/qhexcursor.cpp
Normal file
182
UEFITool/QHexView/src/model/qhexcursor.cpp
Normal 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);
|
||||
}
|
65
UEFITool/QHexView/src/model/qhexdelegate.cpp
Normal file
65
UEFITool/QHexView/src/model/qhexdelegate.cpp
Normal 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);
|
||||
}
|
142
UEFITool/QHexView/src/model/qhexdocument.cpp
Normal file
142
UEFITool/QHexView/src/model/qhexdocument.cpp
Normal 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);
|
||||
}
|
158
UEFITool/QHexView/src/model/qhexmetadata.cpp
Normal file
158
UEFITool/QHexView/src/model/qhexmetadata.cpp
Normal 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);
|
||||
}
|
384
UEFITool/QHexView/src/model/qhexutils.cpp
Normal file
384
UEFITool/QHexView/src/model/qhexutils.cpp
Normal 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
|
1583
UEFITool/QHexView/src/qhexview.cpp
Normal file
1583
UEFITool/QHexView/src/qhexview.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,18 +1,32 @@
|
|||
/* fssfinder.cpp
|
||||
/* ffsfinder.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
|
||||
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.
|
||||
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 "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)
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
@ -25,40 +39,80 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
|
|||
if (hexPattern.count('.') == hexPattern.length())
|
||||
return U_SUCCESS;
|
||||
|
||||
USTATUS ret = U_ITEM_NOT_FOUND;
|
||||
bool hasChildren = (model->rowCount(index) > 0);
|
||||
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;
|
||||
if (hasChildren) {
|
||||
if (mode != SEARCH_MODE_BODY)
|
||||
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.append(model->header(index));
|
||||
data = model->header(index);
|
||||
else if (mode == SEARCH_MODE_BODY)
|
||||
data.append(model->body(index));
|
||||
data = model->body(index);
|
||||
else
|
||||
data.append(model->header(index)).append(model->body(index));
|
||||
data = model->header(index) + model->body(index);
|
||||
}
|
||||
|
||||
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, ®expmatch);
|
||||
#else
|
||||
QRegExp regexp = QRegExp(UString(hexPattern), Qt::CaseInsensitive);
|
||||
|
||||
INT32 offset = regexp.indexIn(hexBody);
|
||||
#endif
|
||||
while (offset >= 0) {
|
||||
if (offset % 2 == 0) {
|
||||
msg(UString("Hex pattern \"") + UString(hexPattern)
|
||||
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
|
||||
+ UString("\" in ") + model->name(index)
|
||||
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset / 2),
|
||||
index);
|
||||
// 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/2 >= model->header(index).size())) {
|
||||
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
|
||||
UString name = model->name(index);
|
||||
if (model->parent(index) == parentFileIndex) {
|
||||
name = model->name(parentFileIndex) + UString("/") + name;
|
||||
}
|
||||
else if (parentFileIndex.isValid()) {
|
||||
name = model->name(parentFileIndex) + UString("/.../") + name;
|
||||
}
|
||||
|
||||
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, ®expmatch);
|
||||
#else
|
||||
offset = regexp.indexIn(hexBody, offset + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
return U_SUCCESS;
|
||||
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)
|
||||
|
@ -69,9 +123,11 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
|
|||
if (!index.isValid())
|
||||
return U_SUCCESS;
|
||||
|
||||
USTATUS ret = U_ITEM_NOT_FOUND;
|
||||
bool hasChildren = (model->rowCount(index) > 0);
|
||||
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;
|
||||
|
@ -112,20 +168,53 @@ USTATUS FfsFinder::findGuidPattern(const UModelIndex & index, const UByteArray &
|
|||
if (hexPattern.count('.') == hexPattern.length())
|
||||
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, ®expmatch);
|
||||
#else
|
||||
QRegExp regexp(UString(hexPattern), Qt::CaseInsensitive);
|
||||
|
||||
INT32 offset = regexp.indexIn(hexBody);
|
||||
#endif
|
||||
while (offset >= 0) {
|
||||
if (offset % 2 == 0) {
|
||||
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
|
||||
UString name = model->name(index);
|
||||
if (model->parent(index) == parentFileIndex) {
|
||||
name = model->name(parentFileIndex) + UString("/") + name;
|
||||
}
|
||||
else if (parentFileIndex.isValid()) {
|
||||
name = model->name(parentFileIndex) + UString("/.../") + name;
|
||||
}
|
||||
|
||||
msg(UString("GUID pattern \"") + UString(guidPattern)
|
||||
+ UString("\" found as \"") + hexBody.mid(offset, hexPattern.length()).toUpper()
|
||||
+ UString("\" in ") + model->name(index)
|
||||
+ 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, ®expmatch);
|
||||
#else
|
||||
offset = regexp.indexIn(hexBody, offset + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
return U_SUCCESS;
|
||||
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)
|
||||
|
@ -136,9 +225,11 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
|
|||
if (!index.isValid())
|
||||
return U_SUCCESS;
|
||||
|
||||
USTATUS ret = U_ITEM_NOT_FOUND;
|
||||
bool hasChildren = (model->rowCount(index) > 0);
|
||||
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;
|
||||
|
@ -155,20 +246,31 @@ USTATUS FfsFinder::findTextPattern(const UModelIndex & index, const UString & pa
|
|||
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)
|
||||
data = UString::fromUtf16((const ushort*)body.constData(), body.length() / 2);
|
||||
searchPattern = UString::fromLatin1((const char*)pattern.utf16(), pattern.length() * 2);
|
||||
else
|
||||
data = UString::fromLatin1((const char*)body.constData(), body.length());
|
||||
searchPattern = pattern;
|
||||
|
||||
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);
|
||||
UString name = model->name(index);
|
||||
if (model->parent(index) == parentFileIndex) {
|
||||
name = model->name(parentFileIndex) + UString("/") + name;
|
||||
}
|
||||
else if (parentFileIndex.isValid()) {
|
||||
name = model->name(parentFileIndex) + UString("/.../") + name;
|
||||
}
|
||||
|
||||
msg((unicode ? UString("Unicode") : UString("ASCII")) + UString(" text \"") + UString(pattern)
|
||||
+ UString("\" found in ") + model->name(index)
|
||||
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", (unicode ? offset * 2 : offset)),
|
||||
+ UString("\" found in ") + name
|
||||
+ usprintf(" at %s-offset %02Xh", mode == SEARCH_MODE_BODY ? "body" : "header", offset),
|
||||
index);
|
||||
ret = U_SUCCESS;
|
||||
}
|
||||
|
||||
return U_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#define FFSFINDER_H
|
||||
|
||||
#include <vector>
|
||||
#include <QRegExp>
|
||||
|
||||
#include "../common/ubytearray.h"
|
||||
#include "../common/ustring.h"
|
||||
|
@ -31,9 +30,9 @@ public:
|
|||
std::vector<std::pair<UString, UModelIndex> > getMessages() const { return messagesVector; }
|
||||
void clearMessages() { messagesVector.clear(); }
|
||||
|
||||
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);
|
||||
USTATUS findHexPattern(const UByteArray & hexPattern, const UINT8 mode);
|
||||
USTATUS findGuidPattern(const UByteArray & guidPattern, const UINT8 mode);
|
||||
USTATUS findTextPattern(const UString & pattern, const UINT8 mode, const bool unicode, const Qt::CaseSensitivity caseSensitive);
|
||||
|
||||
private:
|
||||
const TreeModel* model;
|
||||
|
@ -42,6 +41,10 @@ private:
|
|||
void msg(const UString & message, const UModelIndex &index = UModelIndex()) {
|
||||
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
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
/* 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
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>270</width>
|
||||
<height>70</height>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Go to address</string>
|
||||
<string>Select item at address</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>false</bool>
|
||||
|
@ -56,7 +56,7 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select tree item at address:</string>
|
||||
<string>Select item at address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
36
UEFITool/gotobasedialog.h
Normal file
36
UEFITool/gotobasedialog.h
Normal 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
|
|
@ -1,17 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GoToOffsetDialog</class>
|
||||
<widget class="QDialog" name="GoToOffsetDialog">
|
||||
<class>GoToBaseDialog</class>
|
||||
<widget class="QDialog" name="GoToBaseDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>270</width>
|
||||
<height>70</height>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Go to offset</string>
|
||||
<string>Select item at base</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>false</bool>
|
||||
|
@ -56,7 +56,7 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select tree item at offset:</string>
|
||||
<string>Select item at base:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -100,7 +100,7 @@
|
|||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>GoToOffsetDialog</receiver>
|
||||
<receiver>GoToBaseDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -116,7 +116,7 @@
|
|||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>GoToOffsetDialog</receiver>
|
||||
<receiver>GoToBaseDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef GOTOOFFSETDIALOG_H
|
||||
#define GOTOOFFSETDIALOG_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include "ui_gotooffsetdialog.h"
|
||||
class GoToOffsetDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GoToOffsetDialog(QWidget* parent = NULL):
|
||||
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
|
||||
ui(new Ui::GoToOffsetDialog) {
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
~GoToOffsetDialog() {delete ui;}
|
||||
|
||||
Ui::GoToOffsetDialog* ui;
|
||||
};
|
||||
|
||||
#endif // GOTOOFFSETDIALOG_H
|
|
@ -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
86
UEFITool/hexlineedit.cpp
Normal 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);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* guidlineedit.h
|
||||
/* hexlineedit.h
|
||||
|
||||
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
||||
This program and the accompanying materials
|
||||
|
@ -11,9 +11,11 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef GUIDLINEEDIT_H
|
||||
#define GUIDLINEEDIT_H
|
||||
#ifndef HEXLINEEDIT_H
|
||||
#define HEXLINEEDIT_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QLineEdit>
|
||||
#include <QKeyEvent>
|
||||
#include <QKeySequence>
|
||||
|
@ -21,16 +23,29 @@
|
|||
|
||||
#include "../common/basetypes.h"
|
||||
|
||||
class GuidLineEdit : public QLineEdit
|
||||
class HexLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool editAsGuid READ editAsGuid WRITE setEditAsGuid)
|
||||
|
||||
public:
|
||||
GuidLineEdit(QWidget * parent = 0);
|
||||
GuidLineEdit(const QString & contents, QWidget * parent = 0);
|
||||
~GuidLineEdit();
|
||||
HexLineEdit(QWidget * parent = 0);
|
||||
HexLineEdit(const QString & contents, QWidget * parent = 0);
|
||||
~HexLineEdit();
|
||||
|
||||
void setEditAsGuid(bool editAsGuid)
|
||||
{
|
||||
m_editAsGuid = editAsGuid;
|
||||
}
|
||||
bool editAsGuid() const
|
||||
{ return m_editAsGuid; }
|
||||
|
||||
private:
|
||||
bool m_editAsGuid;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
|
||||
};
|
||||
|
||||
#endif // GUIDLINEEDIT_H
|
||||
#endif // HEXLINEEDIT_H
|
|
@ -1,21 +1,25 @@
|
|||
/* 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
|
||||
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.
|
||||
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");
|
||||
|
|
|
@ -15,7 +15,12 @@
|
|||
#define HEXSPINBOX_H
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#include <QRegularExpressionValidator>
|
||||
#else
|
||||
#include <QRegExpValidator>
|
||||
#endif
|
||||
|
||||
class HexSpinBox : public QSpinBox
|
||||
{
|
||||
|
@ -30,7 +35,11 @@ protected:
|
|||
QString textFromValue(int value) const;
|
||||
|
||||
private:
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
QRegularExpressionValidator validator;
|
||||
#else
|
||||
QRegExpValidator validator;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // HEXSPINBOX_H
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/* hexviewdialog.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
|
||||
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.
|
||||
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 "hexviewdialog.h"
|
||||
|
||||
|
@ -20,9 +20,8 @@ hexView(NULL)
|
|||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
hexView = new QHexEdit(this);
|
||||
hexView = new QHexView(this);
|
||||
hexView->setReadOnly(true);
|
||||
hexView->setUpperCase(true);
|
||||
ui->layout->addWidget(hexView);
|
||||
}
|
||||
|
||||
|
@ -37,18 +36,33 @@ void HexViewDialog::setFont(const QFont &font)
|
|||
hexView->setFont(font);
|
||||
}
|
||||
|
||||
void HexViewDialog::setItem(const UModelIndex & index, bool bodyOnly)
|
||||
void HexViewDialog::setItem(const UModelIndex & index, HexViewType type)
|
||||
{
|
||||
const TreeModel * model = (const TreeModel*)index.model();
|
||||
|
||||
// Set dialog title
|
||||
UString itemName = model->name(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 hexdata;
|
||||
if (bodyOnly) hexdata = model->body(index);
|
||||
else hexdata = model->header(index) + model->body(index) + model->tail(index);
|
||||
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());
|
||||
}
|
|
@ -15,8 +15,8 @@
|
|||
#define HEXVIEWDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QHexView/qhexview.h>
|
||||
#include "../common/treemodel.h"
|
||||
#include "qhexedit2/qhexedit.h"
|
||||
#include "ui_hexviewdialog.h"
|
||||
|
||||
class HexViewDialog : public QDialog
|
||||
|
@ -24,15 +24,21 @@ class HexViewDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum HexViewType {
|
||||
fullHexView,
|
||||
bodyHexView,
|
||||
uncompressedHexView
|
||||
};
|
||||
|
||||
HexViewDialog(QWidget *parent = 0);
|
||||
~HexViewDialog();
|
||||
Ui::HexViewDialog* ui;
|
||||
|
||||
void setItem(const UModelIndex & index, bool bodyOnly);
|
||||
void setItem(const UModelIndex & index, HexViewType dataType);
|
||||
void setFont(const QFont &font);
|
||||
|
||||
private:
|
||||
QHexEdit * hexView;
|
||||
QHexView * hexView;
|
||||
};
|
||||
|
||||
#endif // HEXVIEWDIALOG_H
|
||||
|
|
Binary file not shown.
|
@ -1,323 +0,0 @@
|
|||
#include "chunks.h"
|
||||
#include <limits.h>
|
||||
|
||||
#define NORMAL 0
|
||||
#define HIGHLIGHTED 1
|
||||
|
||||
#define BUFFER_SIZE 0x10000
|
||||
#define CHUNK_SIZE 0x1000
|
||||
#define READ_CHUNK_MASK Q_INT64_C(0xfffffffffffff000)
|
||||
|
||||
// ***************************************** Constructors and file settings
|
||||
|
||||
Chunks::Chunks(QObject *parent): QObject(parent)
|
||||
{
|
||||
QBuffer *buf = new QBuffer(this);
|
||||
setIODevice(*buf);
|
||||
}
|
||||
|
||||
Chunks::Chunks(QIODevice &ioDevice, QObject *parent): QObject(parent)
|
||||
{
|
||||
setIODevice(ioDevice);
|
||||
}
|
||||
|
||||
bool Chunks::setIODevice(QIODevice &ioDevice)
|
||||
{
|
||||
_ioDevice = &ioDevice;
|
||||
bool ok = _ioDevice->open(QIODevice::ReadOnly);
|
||||
if (ok) // Try to open IODevice
|
||||
{
|
||||
_size = _ioDevice->size();
|
||||
_ioDevice->close();
|
||||
}
|
||||
else // Fallback is an empty buffer
|
||||
{
|
||||
QBuffer *buf = new QBuffer(this);
|
||||
_ioDevice = buf;
|
||||
_size = 0;
|
||||
}
|
||||
_chunks.clear();
|
||||
_pos = 0;
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************** Getting data out of Chunks
|
||||
|
||||
QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted)
|
||||
{
|
||||
qint64 ioDelta = 0;
|
||||
int chunkIdx = 0;
|
||||
|
||||
Chunk chunk;
|
||||
QByteArray buffer;
|
||||
|
||||
// Do some checks and some arrangements
|
||||
if (highlighted)
|
||||
highlighted->clear();
|
||||
|
||||
if (pos >= _size)
|
||||
return buffer;
|
||||
|
||||
if (maxSize < 0)
|
||||
maxSize = _size;
|
||||
else
|
||||
if ((pos + maxSize) > _size)
|
||||
maxSize = _size - pos;
|
||||
|
||||
_ioDevice->open(QIODevice::ReadOnly);
|
||||
|
||||
while (maxSize > 0)
|
||||
{
|
||||
chunk.absPos = LLONG_MAX;
|
||||
bool chunksLoopOngoing = true;
|
||||
while ((chunkIdx < _chunks.count()) && chunksLoopOngoing)
|
||||
{
|
||||
// In this section, we track changes before our required data and
|
||||
// we take the editdet data, if availible. ioDelta is a difference
|
||||
// counter to justify the read pointer to the original data, if
|
||||
// data in between was deleted or inserted.
|
||||
|
||||
chunk = _chunks[chunkIdx];
|
||||
if (chunk.absPos > pos)
|
||||
chunksLoopOngoing = false;
|
||||
else
|
||||
{
|
||||
chunkIdx += 1;
|
||||
qint64 count;
|
||||
qint64 chunkOfs = pos - chunk.absPos;
|
||||
if (maxSize > ((qint64)chunk.data.size() - chunkOfs))
|
||||
{
|
||||
count = (qint64)chunk.data.size() - chunkOfs;
|
||||
ioDelta += CHUNK_SIZE - chunk.data.size();
|
||||
}
|
||||
else
|
||||
count = maxSize;
|
||||
if (count > 0)
|
||||
{
|
||||
buffer += chunk.data.mid(chunkOfs, (int)count);
|
||||
maxSize -= count;
|
||||
pos += count;
|
||||
if (highlighted)
|
||||
*highlighted += chunk.dataChanged.mid(chunkOfs, (int)count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((maxSize > 0) && (pos < chunk.absPos))
|
||||
{
|
||||
// In this section, we read data from the original source. This only will
|
||||
// happen, whe no copied data is available
|
||||
|
||||
qint64 byteCount;
|
||||
QByteArray readBuffer;
|
||||
if ((chunk.absPos - pos) > maxSize)
|
||||
byteCount = maxSize;
|
||||
else
|
||||
byteCount = chunk.absPos - pos;
|
||||
|
||||
maxSize -= byteCount;
|
||||
_ioDevice->seek(pos + ioDelta);
|
||||
readBuffer = _ioDevice->read(byteCount);
|
||||
buffer += readBuffer;
|
||||
if (highlighted)
|
||||
*highlighted += QByteArray(readBuffer.size(), NORMAL);
|
||||
pos += readBuffer.size();
|
||||
}
|
||||
}
|
||||
_ioDevice->close();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool Chunks::write(QIODevice &iODevice, qint64 pos, qint64 count)
|
||||
{
|
||||
if (count == -1)
|
||||
count = _size;
|
||||
bool ok = iODevice.open(QIODevice::WriteOnly);
|
||||
if (ok)
|
||||
{
|
||||
for (qint64 idx=pos; idx < count; idx += BUFFER_SIZE)
|
||||
{
|
||||
QByteArray ba = data(idx, BUFFER_SIZE);
|
||||
iODevice.write(ba);
|
||||
}
|
||||
iODevice.close();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************** Set and get highlighting infos
|
||||
|
||||
void Chunks::setDataChanged(qint64 pos, bool dataChanged)
|
||||
{
|
||||
if ((pos < 0) || (pos >= _size))
|
||||
return;
|
||||
int chunkIdx = getChunkIndex(pos);
|
||||
qint64 posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].dataChanged[(int)posInBa] = char(dataChanged);
|
||||
}
|
||||
|
||||
bool Chunks::dataChanged(qint64 pos)
|
||||
{
|
||||
QByteArray highlighted;
|
||||
data(pos, 1, &highlighted);
|
||||
return bool(highlighted.at(0));
|
||||
}
|
||||
|
||||
|
||||
// ***************************************** Search API
|
||||
|
||||
qint64 Chunks::indexOf(const QByteArray &ba, qint64 from)
|
||||
{
|
||||
qint64 result = -1;
|
||||
QByteArray buffer;
|
||||
|
||||
for (qint64 pos=from; (pos < _size) && (result < 0); pos += BUFFER_SIZE)
|
||||
{
|
||||
buffer = data(pos, BUFFER_SIZE + ba.size() - 1);
|
||||
int findPos = buffer.indexOf(ba);
|
||||
if (findPos >= 0)
|
||||
result = pos + (qint64)findPos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from)
|
||||
{
|
||||
qint64 result = -1;
|
||||
QByteArray buffer;
|
||||
|
||||
for (qint64 pos=from; (pos > 0) && (result < 0); pos -= BUFFER_SIZE)
|
||||
{
|
||||
qint64 sPos = pos - BUFFER_SIZE - (qint64)ba.size() + 1;
|
||||
if (sPos < 0)
|
||||
sPos = 0;
|
||||
buffer = data(sPos, pos - sPos);
|
||||
int findPos = buffer.lastIndexOf(ba);
|
||||
if (findPos >= 0)
|
||||
result = sPos + (qint64)findPos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************** Char manipulations
|
||||
|
||||
bool Chunks::insert(qint64 pos, char b)
|
||||
{
|
||||
if ((pos < 0) || (pos > _size))
|
||||
return false;
|
||||
int chunkIdx;
|
||||
if (pos == _size)
|
||||
chunkIdx = getChunkIndex(pos-1);
|
||||
else
|
||||
chunkIdx = getChunkIndex(pos);
|
||||
qint64 posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data.insert(posInBa, b);
|
||||
_chunks[chunkIdx].dataChanged.insert(posInBa, char(1));
|
||||
for (int idx=chunkIdx+1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos += 1;
|
||||
_size += 1;
|
||||
_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::overwrite(qint64 pos, char b)
|
||||
{
|
||||
if ((pos < 0) || (pos >= _size))
|
||||
return false;
|
||||
int chunkIdx = getChunkIndex(pos);
|
||||
qint64 posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data[(int)posInBa] = b;
|
||||
_chunks[chunkIdx].dataChanged[(int)posInBa] = char(1);
|
||||
_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::removeAt(qint64 pos)
|
||||
{
|
||||
if ((pos < 0) || (pos >= _size))
|
||||
return false;
|
||||
int chunkIdx = getChunkIndex(pos);
|
||||
qint64 posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data.remove(posInBa, 1);
|
||||
_chunks[chunkIdx].dataChanged.remove(posInBa, 1);
|
||||
for (int idx=chunkIdx+1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos -= 1;
|
||||
_size -= 1;
|
||||
_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************** Utility functions
|
||||
|
||||
char Chunks::operator[](qint64 pos)
|
||||
{
|
||||
return data(pos, 1)[0];
|
||||
}
|
||||
|
||||
qint64 Chunks::pos()
|
||||
{
|
||||
return _pos;
|
||||
}
|
||||
|
||||
qint64 Chunks::size()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
int Chunks::getChunkIndex(qint64 absPos)
|
||||
{
|
||||
// This routine checks, if there is already a copied chunk available. If os, it
|
||||
// returns a reference to it. If there is no copied chunk available, original
|
||||
// data will be copied into a new chunk.
|
||||
|
||||
int foundIdx = -1;
|
||||
int insertIdx = 0;
|
||||
qint64 ioDelta = 0;
|
||||
|
||||
|
||||
for (int idx=0; idx < _chunks.size(); idx++)
|
||||
{
|
||||
Chunk chunk = _chunks[idx];
|
||||
if ((absPos >= chunk.absPos) && (absPos < (chunk.absPos + chunk.data.size())))
|
||||
{
|
||||
foundIdx = idx;
|
||||
break;
|
||||
}
|
||||
if (absPos < chunk.absPos)
|
||||
{
|
||||
insertIdx = idx;
|
||||
break;
|
||||
}
|
||||
ioDelta += chunk.data.size() - CHUNK_SIZE;
|
||||
insertIdx = idx + 1;
|
||||
}
|
||||
|
||||
if (foundIdx == -1)
|
||||
{
|
||||
Chunk newChunk;
|
||||
qint64 readAbsPos = absPos - ioDelta;
|
||||
qint64 readPos = (readAbsPos & READ_CHUNK_MASK);
|
||||
_ioDevice->open(QIODevice::ReadOnly);
|
||||
_ioDevice->seek(readPos);
|
||||
newChunk.data = _ioDevice->read(CHUNK_SIZE);
|
||||
_ioDevice->close();
|
||||
newChunk.absPos = absPos - (readAbsPos - readPos);
|
||||
newChunk.dataChanged = QByteArray(newChunk.data.size(), char(0));
|
||||
_chunks.insert(insertIdx, newChunk);
|
||||
foundIdx = insertIdx;
|
||||
}
|
||||
return foundIdx;
|
||||
}
|
||||
|
||||
|
||||
#ifdef MODUL_TEST
|
||||
int Chunks::chunkSize()
|
||||
{
|
||||
return _chunks.size();
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,77 +0,0 @@
|
|||
#ifndef CHUNKS_H
|
||||
#define CHUNKS_H
|
||||
|
||||
/** \cond docNever */
|
||||
|
||||
/*! The Chunks class is the storage backend for QHexEdit.
|
||||
*
|
||||
* When QHexEdit loads data, Chunks access them using a QIODevice interface. When the app uses
|
||||
* a QByteArray interface, QBuffer is used to provide again a QIODevice like interface. No data
|
||||
* will be changed, therefore Chunks opens the QIODevice in QIODevice::ReadOnly mode. After every
|
||||
* access Chunks closes the QIODevice, that's why external applications can overwrite files while
|
||||
* QHexEdit shows them.
|
||||
*
|
||||
* When the the user starts to edit the data, Chunks creates a local copy of a chunk of data (4
|
||||
* kilobytes) and notes all changes there. Parallel to that chunk, there is a second chunk,
|
||||
* which keep track of which bytes are changed and which not.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
struct Chunk
|
||||
{
|
||||
QByteArray data;
|
||||
QByteArray dataChanged;
|
||||
qint64 absPos;
|
||||
};
|
||||
|
||||
class Chunks: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Constructors and file settings
|
||||
Chunks(QObject *parent);
|
||||
Chunks(QIODevice &ioDevice, QObject *parent);
|
||||
bool setIODevice(QIODevice &ioDevice);
|
||||
|
||||
// Getting data out of Chunks
|
||||
QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0);
|
||||
bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1);
|
||||
|
||||
// Set and get highlighting infos
|
||||
void setDataChanged(qint64 pos, bool dataChanged);
|
||||
bool dataChanged(qint64 pos);
|
||||
|
||||
// Search API
|
||||
qint64 indexOf(const QByteArray &ba, qint64 from);
|
||||
qint64 lastIndexOf(const QByteArray &ba, qint64 from);
|
||||
|
||||
// Char manipulations
|
||||
bool insert(qint64 pos, char b);
|
||||
bool overwrite(qint64 pos, char b);
|
||||
bool removeAt(qint64 pos);
|
||||
|
||||
// Utility functions
|
||||
char operator[](qint64 pos);
|
||||
qint64 pos();
|
||||
qint64 size();
|
||||
|
||||
|
||||
private:
|
||||
int getChunkIndex(qint64 absPos);
|
||||
|
||||
QIODevice * _ioDevice;
|
||||
qint64 _pos;
|
||||
qint64 _size;
|
||||
QList<Chunk> _chunks;
|
||||
|
||||
#ifdef MODUL_TEST
|
||||
public:
|
||||
int chunkSize();
|
||||
#endif
|
||||
};
|
||||
|
||||
/** \endcond docNever */
|
||||
|
||||
#endif // CHUNKS_H
|
|
@ -1,167 +0,0 @@
|
|||
#include "commands.h"
|
||||
#include <QUndoCommand>
|
||||
|
||||
|
||||
// Helper class to store single byte commands
|
||||
class CharCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
enum CCmd {insert, removeAt, overwrite};
|
||||
|
||||
CharCommand(Chunks * chunks, CCmd cmd, qint64 charPos, char newChar,
|
||||
QUndoCommand *parent=0);
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
bool mergeWith(const QUndoCommand *command);
|
||||
int id() const { return 1234; }
|
||||
|
||||
private:
|
||||
Chunks * _chunks;
|
||||
qint64 _charPos;
|
||||
bool _wasChanged;
|
||||
char _newChar;
|
||||
char _oldChar;
|
||||
CCmd _cmd;
|
||||
};
|
||||
|
||||
CharCommand::CharCommand(Chunks * chunks, CCmd cmd, qint64 charPos, char newChar, QUndoCommand *parent)
|
||||
: QUndoCommand(parent)
|
||||
{
|
||||
_chunks = chunks;
|
||||
_charPos = charPos;
|
||||
_newChar = newChar;
|
||||
_cmd = cmd;
|
||||
_wasChanged = false;
|
||||
_oldChar = ' ';
|
||||
}
|
||||
|
||||
bool CharCommand::mergeWith(const QUndoCommand *command)
|
||||
{
|
||||
const CharCommand *nextCommand = static_cast<const CharCommand *>(command);
|
||||
bool result = false;
|
||||
|
||||
if (_cmd != CharCommand::removeAt)
|
||||
{
|
||||
if (nextCommand->_cmd == overwrite)
|
||||
if (nextCommand->_charPos == _charPos)
|
||||
{
|
||||
_newChar = nextCommand->_newChar;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CharCommand::undo()
|
||||
{
|
||||
switch (_cmd)
|
||||
{
|
||||
case insert:
|
||||
_chunks->removeAt(_charPos);
|
||||
break;
|
||||
case overwrite:
|
||||
_chunks->overwrite(_charPos, _oldChar);
|
||||
_chunks->setDataChanged(_charPos, _wasChanged);
|
||||
break;
|
||||
case removeAt:
|
||||
_chunks->insert(_charPos, _oldChar);
|
||||
_chunks->setDataChanged(_charPos, _wasChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CharCommand::redo()
|
||||
{
|
||||
switch (_cmd)
|
||||
{
|
||||
case insert:
|
||||
_chunks->insert(_charPos, _newChar);
|
||||
break;
|
||||
case overwrite:
|
||||
_oldChar = (*_chunks)[_charPos];
|
||||
_wasChanged = _chunks->dataChanged(_charPos);
|
||||
_chunks->overwrite(_charPos, _newChar);
|
||||
break;
|
||||
case removeAt:
|
||||
_oldChar = (*_chunks)[_charPos];
|
||||
_wasChanged = _chunks->dataChanged(_charPos);
|
||||
_chunks->removeAt(_charPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UndoStack::UndoStack(Chunks * chunks, QObject * parent)
|
||||
: QUndoStack(parent)
|
||||
{
|
||||
_chunks = chunks;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
void UndoStack::insert(qint64 pos, char c)
|
||||
{
|
||||
if ((pos >= 0) && (pos <= _chunks->size()))
|
||||
{
|
||||
QUndoCommand *cc = new CharCommand(_chunks, CharCommand::insert, pos, c);
|
||||
this->push(cc);
|
||||
}
|
||||
}
|
||||
|
||||
void UndoStack::insert(qint64 pos, const QByteArray &ba)
|
||||
{
|
||||
if ((pos >= 0) && (pos <= _chunks->size()))
|
||||
{
|
||||
QString txt = QString(tr("Inserting %1 bytes")).arg(ba.size());
|
||||
beginMacro(txt);
|
||||
for (int idx=0; idx < ba.size(); idx++)
|
||||
{
|
||||
QUndoCommand *cc = new CharCommand(_chunks, CharCommand::insert, pos + idx, ba.at(idx));
|
||||
this->push(cc);
|
||||
}
|
||||
endMacro();
|
||||
}
|
||||
}
|
||||
|
||||
void UndoStack::removeAt(qint64 pos, qint64 len)
|
||||
{
|
||||
if ((pos >= 0) && (pos < _chunks->size()))
|
||||
{
|
||||
if (len==1)
|
||||
{
|
||||
QUndoCommand *cc = new CharCommand(_chunks, CharCommand::removeAt, pos, char(0));
|
||||
this->push(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString txt = QString(tr("Delete %1 chars")).arg(len);
|
||||
beginMacro(txt);
|
||||
for (qint64 cnt=0; cnt<len; cnt++)
|
||||
{
|
||||
QUndoCommand *cc = new CharCommand(_chunks, CharCommand::removeAt, pos, char(0));
|
||||
push(cc);
|
||||
}
|
||||
endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UndoStack::overwrite(qint64 pos, char c)
|
||||
{
|
||||
if ((pos >= 0) && (pos < _chunks->size()))
|
||||
{
|
||||
QUndoCommand *cc = new CharCommand(_chunks, CharCommand::overwrite, pos, c);
|
||||
this->push(cc);
|
||||
}
|
||||
}
|
||||
|
||||
void UndoStack::overwrite(qint64 pos, int len, const QByteArray &ba)
|
||||
{
|
||||
if ((pos >= 0) && (pos < _chunks->size()))
|
||||
{
|
||||
QString txt = QString(tr("Overwrite %1 chars")).arg(len);
|
||||
beginMacro(txt);
|
||||
removeAt(pos, len);
|
||||
insert(pos, ba);
|
||||
endMacro();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef COMMANDS_H
|
||||
#define COMMANDS_H
|
||||
|
||||
/** \cond docNever */
|
||||
|
||||
#include <QUndoStack>
|
||||
|
||||
#include "chunks.h"
|
||||
|
||||
/*! CharCommand is a class to provid undo/redo functionality in QHexEdit.
|
||||
A QUndoCommand represents a single editing action on a document. CharCommand
|
||||
is responsable for manipulations on single chars. It can insert. overwrite and
|
||||
remove characters. A manipulation stores allways two actions
|
||||
1. redo (or do) action
|
||||
2. undo action.
|
||||
|
||||
CharCommand also supports command compression via mergeWidht(). This allows
|
||||
the user to execute a undo command contation e.g. 3 steps in a single command.
|
||||
If you for example insert a new byt "34" this means for the editor doing 3
|
||||
steps: insert a "00", overwrite it with "03" and the overwrite it with "34". These
|
||||
3 steps are combined into a single step, insert a "34".
|
||||
|
||||
The byte array oriented commands are just put into a set of single byte commands,
|
||||
which are pooled together with the macroBegin() and macroEnd() functionality of
|
||||
Qt's QUndoStack.
|
||||
*/
|
||||
|
||||
class UndoStack : public QUndoStack
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UndoStack(Chunks *chunks, QObject * parent=0);
|
||||
void insert(qint64 pos, char c);
|
||||
void insert(qint64 pos, const QByteArray &ba);
|
||||
void removeAt(qint64 pos, qint64 len=1);
|
||||
void overwrite(qint64 pos, char c);
|
||||
void overwrite(qint64 pos, int len, const QByteArray &ba);
|
||||
|
||||
private:
|
||||
Chunks * _chunks;
|
||||
QObject * _parent;
|
||||
};
|
||||
|
||||
/** \endcond docNever */
|
||||
|
||||
#endif // COMMANDS_H
|
|
@ -1,502 +0,0 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 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.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
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 and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, 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 library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete 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 distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
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 Library or any portion
|
||||
of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
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 Library, 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 Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you 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.
|
||||
|
||||
If distribution of 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 satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be 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.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library 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.
|
||||
|
||||
9. 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 Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
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 with
|
||||
this License.
|
||||
|
||||
11. 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 Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library 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 Library.
|
||||
|
||||
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.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library 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.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
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 Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
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
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. 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 LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. 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 library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; 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.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
File diff suppressed because it is too large
Load diff
|
@ -1,411 +0,0 @@
|
|||
#ifndef QHEXEDIT_H
|
||||
#define QHEXEDIT_H
|
||||
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
|
||||
#include "chunks.h"
|
||||
#include "commands.h"
|
||||
|
||||
#ifdef QHEXEDIT_EXPORTS
|
||||
#define QHEXEDIT_API Q_DECL_EXPORT
|
||||
#elif QHEXEDIT_IMPORTS
|
||||
#define QHEXEDIT_API Q_DECL_IMPORT
|
||||
#else
|
||||
#define QHEXEDIT_API
|
||||
#endif
|
||||
|
||||
/** \mainpage
|
||||
QHexEdit is a binary editor widget for Qt.
|
||||
|
||||
\version Version 0.8.2
|
||||
\image html qhexedit.png
|
||||
*/
|
||||
|
||||
|
||||
/** QHexEdit is a hex editor widget written in C++ for the Qt (Qt4, Qt5) framework.
|
||||
It is a simple editor for binary data, just like QPlainTextEdit is for text
|
||||
data. There are sip configuration files included, so it is easy to create
|
||||
bindings for PyQt and you can use this widget also in python 2 and 3.
|
||||
|
||||
QHexEdit takes the data of a QByteArray (setData()) and shows it. You can use
|
||||
the mouse or the keyboard to navigate inside the widget. If you hit the keys
|
||||
(0..9, a..f) you will change the data. Changed data is highlighted and can be
|
||||
accessed via data().
|
||||
|
||||
Normaly QHexEdit works in the overwrite Mode. You can set overwriteMode(false)
|
||||
and insert data. In this case the size of data() increases. It is also possible
|
||||
to delete bytes (del or backspace), here the size of data decreases.
|
||||
|
||||
You can select data with keyboard hits or mouse movements. The copy-key will
|
||||
copy the selected data into the clipboard. The cut-key copies also but delets
|
||||
it afterwards. In overwrite mode, the paste function overwrites the content of
|
||||
the (does not change the length) data. In insert mode, clipboard data will be
|
||||
inserted. The clipboard content is expected in ASCII Hex notation. Unknown
|
||||
characters will be ignored.
|
||||
|
||||
QHexEdit comes with undo/redo functionality. All changes can be undone, by
|
||||
pressing the undo-key (usually ctr-z). They can also be redone afterwards.
|
||||
The undo/redo framework is cleared, when setData() sets up a new
|
||||
content for the editor. You can search data inside the content with indexOf()
|
||||
and lastIndexOf(). The replace() function is to change located subdata. This
|
||||
'replaced' data can also be undone by the undo/redo framework.
|
||||
|
||||
QHexEdit is based on QIODevice, that's why QHexEdit can handle big amounts of
|
||||
data. The size of edited data can be more then two gigabytes without any
|
||||
restrictions.
|
||||
*/
|
||||
class QHEXEDIT_API QHexEdit : public QAbstractScrollArea
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/*! Property address area switch the address area on or off. Set addressArea true
|
||||
(show it), false (hide it).
|
||||
*/
|
||||
Q_PROPERTY(bool addressArea READ addressArea WRITE setAddressArea)
|
||||
|
||||
/*! Property address area color sets (setAddressAreaColor()) the backgorund
|
||||
color of address areas. You can also read the color (addressaAreaColor()).
|
||||
*/
|
||||
Q_PROPERTY(QColor addressAreaColor READ addressAreaColor WRITE setAddressAreaColor)
|
||||
|
||||
/*! Property addressOffset is added to the Numbers of the Address Area.
|
||||
A offset in the address area (left side) is sometimes usefull, whe you show
|
||||
only a segment of a complete memory picture. With setAddressOffset() you set
|
||||
this property - with addressOffset() you get the current value.
|
||||
*/
|
||||
Q_PROPERTY(qint64 addressOffset READ addressOffset WRITE setAddressOffset)
|
||||
|
||||
/*! Set and get the minimum width of the address area, width in characters.
|
||||
*/
|
||||
Q_PROPERTY(int addressWidth READ addressWidth WRITE setAddressWidth)
|
||||
|
||||
/*! Switch the ascii area on (true, show it) or off (false, hide it).
|
||||
*/
|
||||
Q_PROPERTY(bool asciiArea READ asciiArea WRITE setAsciiArea)
|
||||
|
||||
/*! Set and get bytes number per line.*/
|
||||
Q_PROPERTY(int bytesPerLine READ bytesPerLine WRITE setBytesPerLine)
|
||||
|
||||
/*! Porperty cursorPosition sets or gets the position of the editor cursor
|
||||
in QHexEdit. Every byte in data has to cursor positions: the lower and upper
|
||||
Nibble. Maximum cursor position is factor two of data.size().
|
||||
*/
|
||||
Q_PROPERTY(qint64 cursorPosition READ cursorPosition WRITE setCursorPosition)
|
||||
|
||||
/*! Property data holds the content of QHexEdit. Call setData() to set the
|
||||
content of QHexEdit, data() returns the actual content. When calling setData()
|
||||
with a QByteArray as argument, QHexEdit creates a internal copy of the data
|
||||
If you want to edit big files please use setData(), based on QIODevice.
|
||||
*/
|
||||
Q_PROPERTY(QByteArray data READ data WRITE setData NOTIFY dataChanged)
|
||||
|
||||
/*! Switch the highlighting feature on or of: true (show it), false (hide it).
|
||||
*/
|
||||
Q_PROPERTY(bool highlighting READ highlighting WRITE setHighlighting)
|
||||
|
||||
/*! Property highlighting color sets (setHighlightingColor()) the backgorund
|
||||
color of highlighted text areas. You can also read the color
|
||||
(highlightingColor()).
|
||||
*/
|
||||
Q_PROPERTY(QColor highlightingColor READ highlightingColor WRITE setHighlightingColor)
|
||||
|
||||
/*! Porperty overwrite mode sets (setOverwriteMode()) or gets (overwriteMode()) the mode
|
||||
in which the editor works. In overwrite mode the user will overwrite existing data. The
|
||||
size of data will be constant. In insert mode the size will grow, when inserting
|
||||
new data.
|
||||
*/
|
||||
Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
|
||||
|
||||
/*! Property selection color sets (setSelectionColor()) the backgorund
|
||||
color of selected text areas. You can also read the color
|
||||
(selectionColor()).
|
||||
*/
|
||||
Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor)
|
||||
|
||||
/*! Property readOnly sets (setReadOnly()) or gets (isReadOnly) the mode
|
||||
in which the editor works. In readonly mode the the user can only navigate
|
||||
through the data and select data; modifying is not possible. This
|
||||
property's default is false.
|
||||
*/
|
||||
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||
|
||||
/*! Property upperCase sets (setUpperCase()) or gets (isUpperCase) the case of hex
|
||||
data. Default is lowercase.
|
||||
*/
|
||||
Q_PROPERTY(bool upperCase READ isUpperCase WRITE setUpperCase)
|
||||
|
||||
/*! Set the font of the widget. Please use fixed width fonts like Mono or Courier.*/
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont)
|
||||
|
||||
public:
|
||||
/*! Creates an instance of QHexEdit.
|
||||
\param parent Parent widget of QHexEdit.
|
||||
*/
|
||||
QHexEdit(QWidget *parent=0);
|
||||
|
||||
// Access to data of qhexedit
|
||||
|
||||
/*! Sets the data of QHexEdit. The QIODevice will be opend just before reading
|
||||
and closed immediately afterwards. This is to allow other programs to rewrite
|
||||
the file while editing it.
|
||||
*/
|
||||
bool setData(QIODevice &iODevice);
|
||||
|
||||
/*! Gives back the data as a QByteArray starting at position \param pos and
|
||||
delivering \param count bytes.
|
||||
*/
|
||||
QByteArray dataAt(qint64 pos, qint64 count=-1);
|
||||
|
||||
/*! Gives back the data into a \param iODevice starting at position \param pos
|
||||
and delivering \param count bytes.
|
||||
*/
|
||||
bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1);
|
||||
|
||||
|
||||
// Char handling
|
||||
|
||||
/*! Inserts a char.
|
||||
\param pos Index position, where to insert
|
||||
\param ch Char, which is to insert
|
||||
The char will be inserted and size of data grows.
|
||||
*/
|
||||
void insert(qint64 pos, char ch);
|
||||
|
||||
/*! Removes len bytes from the content.
|
||||
\param pos Index position, where to remove
|
||||
\param len Amount of bytes to remove
|
||||
*/
|
||||
void remove(qint64 pos, qint64 len=1);
|
||||
|
||||
/*! Replaces a char.
|
||||
\param pos Index position, where to overwrite
|
||||
\param ch Char, which is to insert
|
||||
The char will be overwritten and size remains constant.
|
||||
*/
|
||||
void replace(qint64 pos, char ch);
|
||||
|
||||
|
||||
// ByteArray handling
|
||||
|
||||
/*! Inserts a byte array.
|
||||
\param pos Index position, where to insert
|
||||
\param ba QByteArray, which is to insert
|
||||
The QByteArray will be inserted and size of data grows.
|
||||
*/
|
||||
void insert(qint64 pos, const QByteArray &ba);
|
||||
|
||||
/*! Replaces \param len bytes with a byte array \param ba
|
||||
\param pos Index position, where to overwrite
|
||||
\param ba QByteArray, which is inserted
|
||||
\param len count of bytes to overwrite
|
||||
The data is overwritten and size of data may change.
|
||||
*/
|
||||
void replace(qint64 pos, qint64 len, const QByteArray &ba);
|
||||
|
||||
|
||||
// Utility functioins
|
||||
/*! Calc cursor position from graphics position
|
||||
* \param point from where the cursor position should be calculated
|
||||
* \return Cursor postioin
|
||||
*/
|
||||
qint64 cursorPosition(QPoint point);
|
||||
|
||||
/*! Ensure the cursor to be visble
|
||||
*/
|
||||
void ensureVisible();
|
||||
|
||||
/*! Find first occurence of ba in QHexEdit data
|
||||
* \param ba Data to find
|
||||
* \param from Point where the search starts
|
||||
* \return pos if fond, else -1
|
||||
*/
|
||||
qint64 indexOf(const QByteArray &ba, qint64 from);
|
||||
|
||||
/*! Returns if any changes where done on document
|
||||
* \return true when document is modified else false
|
||||
*/
|
||||
bool isModified();
|
||||
|
||||
/*! Find last occurence of ba in QHexEdit data
|
||||
* \param ba Data to find
|
||||
* \param from Point where the search starts
|
||||
* \return pos if fond, else -1
|
||||
*/
|
||||
qint64 lastIndexOf(const QByteArray &ba, qint64 from);
|
||||
|
||||
/*! Gives back a formatted image of the selected content of QHexEdit
|
||||
*/
|
||||
QString selectionToReadableString();
|
||||
|
||||
/*! Set Font of QHexEdit
|
||||
* \param font
|
||||
*/
|
||||
void setFont(const QFont &font);
|
||||
|
||||
/*! Gives back a formatted image of the content of QHexEdit
|
||||
*/
|
||||
QString toReadableString();
|
||||
|
||||
|
||||
public slots:
|
||||
/*! Redoes the last operation. If there is no operation to redo, i.e.
|
||||
there is no redo step in the undo/redo history, nothing happens.
|
||||
*/
|
||||
void redo();
|
||||
|
||||
/*! Undoes the last operation. If there is no operation to undo, i.e.
|
||||
there is no undo step in the undo/redo history, nothing happens.
|
||||
*/
|
||||
void undo();
|
||||
|
||||
signals:
|
||||
|
||||
/*! Contains the address, where the cursor is located. */
|
||||
void currentAddressChanged(qint64 address);
|
||||
|
||||
/*! Contains the size of the data to edit. */
|
||||
void currentSizeChanged(qint64 size);
|
||||
|
||||
/*! The signal is emitted every time, the data is changed. */
|
||||
void dataChanged();
|
||||
|
||||
/*! The signal is emitted every time, the overwrite mode is changed. */
|
||||
void overwriteModeChanged(bool state);
|
||||
|
||||
|
||||
/*! \cond docNever */
|
||||
public:
|
||||
~QHexEdit();
|
||||
|
||||
// Properties
|
||||
bool addressArea();
|
||||
void setAddressArea(bool addressArea);
|
||||
|
||||
QColor addressAreaColor();
|
||||
void setAddressAreaColor(const QColor &color);
|
||||
|
||||
qint64 addressOffset();
|
||||
void setAddressOffset(qint64 addressArea);
|
||||
|
||||
int addressWidth();
|
||||
void setAddressWidth(int addressWidth);
|
||||
|
||||
bool asciiArea();
|
||||
void setAsciiArea(bool asciiArea);
|
||||
|
||||
int bytesPerLine();
|
||||
void setBytesPerLine(int count);
|
||||
|
||||
qint64 cursorPosition();
|
||||
void setCursorPosition(qint64 position);
|
||||
|
||||
QByteArray data();
|
||||
void setData(const QByteArray &ba);
|
||||
|
||||
bool highlighting();
|
||||
void setHighlighting(bool mode);
|
||||
|
||||
QColor highlightingColor();
|
||||
void setHighlightingColor(const QColor &color);
|
||||
|
||||
bool overwriteMode();
|
||||
void setOverwriteMode(bool overwriteMode);
|
||||
|
||||
bool isReadOnly();
|
||||
void setReadOnly(bool readOnly);
|
||||
|
||||
bool isUpperCase();
|
||||
void setUpperCase(bool upperCase);
|
||||
|
||||
QColor selectionColor();
|
||||
void setSelectionColor(const QColor &color);
|
||||
|
||||
protected:
|
||||
// Handle events
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent * event);
|
||||
void mousePressEvent(QMouseEvent * event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
virtual bool focusNextPrevChild(bool next);
|
||||
private:
|
||||
// Handle selections
|
||||
void resetSelection(qint64 pos); // set selectionStart and selectionEnd to pos
|
||||
void resetSelection(); // set selectionEnd to selectionStart
|
||||
void setSelection(qint64 pos); // set min (if below init) or max (if greater init)
|
||||
int getSelectionBegin();
|
||||
int getSelectionEnd();
|
||||
|
||||
// Private utility functions
|
||||
void init();
|
||||
void readBuffers();
|
||||
QString toReadable(const QByteArray &ba);
|
||||
|
||||
private slots:
|
||||
void adjust(); // recalc pixel positions
|
||||
void dataChangedPrivate(int idx=0); // emit dataChanged() signal
|
||||
void refresh(); // ensureVisible() and readBuffers()
|
||||
void updateCursor(); // update blinking cursor
|
||||
|
||||
private:
|
||||
// Name convention: pixel positions start with _px
|
||||
int _pxCharWidth, _pxCharHeight; // char dimensions (dpendend on font)
|
||||
int _pxPosHexX; // X-Pos of HeaxArea
|
||||
int _pxPosAdrX; // X-Pos of Address Area
|
||||
int _pxPosAsciiX; // X-Pos of Ascii Area
|
||||
int _pxGapAdr; // gap left from AddressArea
|
||||
int _pxGapAdrHex; // gap between AddressArea and HexAerea
|
||||
int _pxGapHexAscii; // gap between HexArea and AsciiArea
|
||||
int _pxCursorWidth; // cursor width
|
||||
int _pxSelectionSub; // offset selection rect
|
||||
int _pxCursorX; // current cursor pos
|
||||
int _pxCursorY; // current cursor pos
|
||||
|
||||
// Name convention: absolute byte positions in chunks start with _b
|
||||
qint64 _bSelectionBegin; // first position of Selection
|
||||
qint64 _bSelectionEnd; // end of Selection
|
||||
qint64 _bSelectionInit; // memory position of Selection
|
||||
qint64 _bPosFirst; // position of first byte shown
|
||||
qint64 _bPosLast; // position of last byte shown
|
||||
qint64 _bPosCurrent; // current position
|
||||
|
||||
// variables to store the property values
|
||||
bool _addressArea; // left area of QHexEdit
|
||||
QColor _addressAreaColor;
|
||||
int _addressWidth;
|
||||
bool _asciiArea;
|
||||
qint64 _addressOffset;
|
||||
int _bytesPerLine;
|
||||
int _hexCharsInLine;
|
||||
bool _highlighting;
|
||||
bool _overwriteMode;
|
||||
QBrush _brushSelection;
|
||||
QPen _penSelection;
|
||||
QBrush _brushHighlighted;
|
||||
QPen _penHighlighted;
|
||||
bool _readOnly;
|
||||
bool _upperCase;
|
||||
|
||||
// other variables
|
||||
bool _editAreaIsAscii; // flag about the ascii mode edited
|
||||
int _addrDigits; // real no of addressdigits, may be > addressWidth
|
||||
bool _blink; // help get cursor blinking
|
||||
QBuffer _bData; // buffer, when setup with QByteArray
|
||||
Chunks *_chunks; // IODevice based access to data
|
||||
QTimer _cursorTimer; // for blinking cursor
|
||||
qint64 _cursorPosition; // absolute position of cursor, 1 Byte == 2 tics
|
||||
QRect _cursorRect; // physical dimensions of cursor
|
||||
QByteArray _data; // QHexEdit's data, when setup with QByteArray
|
||||
QByteArray _dataShown; // data in the current View
|
||||
QByteArray _hexDataShown; // data in view, transformed to hex
|
||||
qint64 _lastEventSize; // size, which was emitted last time
|
||||
QByteArray _markedShown; // marked data in view
|
||||
bool _modified; // Is any data in editor modified?
|
||||
int _rowsShown; // lines of text shown
|
||||
UndoStack * _undoStack; // Stack to store edit actions for undo/redo
|
||||
/*! \endcond docNever */
|
||||
};
|
||||
|
||||
#endif // QHEXEDIT_H
|
|
@ -1,23 +1,28 @@
|
|||
/* searchdialog.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
|
||||
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.
|
||||
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 "searchdialog.h"
|
||||
|
||||
SearchDialog::SearchDialog(QWidget *parent) :
|
||||
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
|
||||
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\\. ])*")),
|
||||
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
|
||||
ui->setupUi(this);
|
||||
|
|
|
@ -15,7 +15,13 @@
|
|||
#define SEARCHDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#include <QRegularExpressionValidator>
|
||||
#else
|
||||
#include <QRegExpValidator>
|
||||
#endif
|
||||
|
||||
#include "ui_searchdialog.h"
|
||||
|
||||
class SearchDialog : public QDialog
|
||||
|
@ -31,8 +37,13 @@ private slots:
|
|||
void setEditFocus(int index);
|
||||
|
||||
private:
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
QRegularExpressionValidator hexValidator;
|
||||
QRegularExpressionValidator guidValidator;
|
||||
#else
|
||||
QRegExpValidator hexValidator;
|
||||
QRegExpValidator guidValidator;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // SEARCHDIALOG_H
|
||||
|
|
|
@ -35,7 +35,10 @@
|
|||
</widget>
|
||||
</item>
|
||||
<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">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -89,7 +92,10 @@
|
|||
</widget>
|
||||
</item>
|
||||
<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">
|
||||
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
|
||||
</property>
|
||||
|
@ -241,9 +247,9 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GuidLineEdit</class>
|
||||
<class>HexLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>guidlineedit.h</header>
|
||||
<header>hexlineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
/* uefitool.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
|
||||
Copyright (c) 2022, 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.
|
||||
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 "../version.h"
|
||||
#include "uefitool.h"
|
||||
#include "ui_uefitool.h"
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#include <QStyleHints>
|
||||
#endif
|
||||
|
||||
UEFITool::UEFITool(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::UEFITool),
|
||||
|
@ -27,8 +31,8 @@ markingEnabled(true)
|
|||
ui->setupUi(this);
|
||||
searchDialog = new SearchDialog(this);
|
||||
hexViewDialog = new HexViewDialog(this);
|
||||
goToOffsetDialog = new GoToOffsetDialog(this);
|
||||
goToAddressDialog = new GoToAddressDialog(this);
|
||||
goToBaseDialog = new GoToBaseDialog(this);
|
||||
model = NULL;
|
||||
ffsParser = NULL;
|
||||
ffsFinder = NULL;
|
||||
|
@ -43,6 +47,7 @@ markingEnabled(true)
|
|||
connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search()));
|
||||
connect(ui->actionHexView, SIGNAL(triggered()), this, SLOT(hexView()));
|
||||
connect(ui->actionBodyHexView, SIGNAL(triggered()), this, SLOT(bodyHexView()));
|
||||
connect(ui->actionUncompressedHexView, SIGNAL(triggered()), this, SLOT(uncompressedHexView()));
|
||||
connect(ui->actionExtract, SIGNAL(triggered()), this, SLOT(extractAsIs()));
|
||||
connect(ui->actionExtractBody, SIGNAL(triggered()), this, SLOT(extractBody()));
|
||||
connect(ui->actionExtractBodyUncompressed, SIGNAL(triggered()), this, SLOT(extractBodyUncompressed()));
|
||||
|
@ -60,11 +65,12 @@ markingEnabled(true)
|
|||
connect(ui->actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt()));
|
||||
connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(exit()));
|
||||
connect(ui->actionGoToData, SIGNAL(triggered()), this, SLOT(goToData()));
|
||||
connect(ui->actionGoToOffset, SIGNAL(triggered()), this, SLOT(goToOffset()));
|
||||
connect(ui->actionGoToBase, SIGNAL(triggered()), this, SLOT(goToBase()));
|
||||
connect(ui->actionGoToAddress, SIGNAL(triggered()), this, SLOT(goToAddress()));
|
||||
connect(ui->actionLoadGuidDatabase, SIGNAL(triggered()), this, SLOT(loadGuidDatabase()));
|
||||
connect(ui->actionUnloadGuidDatabase, SIGNAL(triggered()), this, SLOT(unloadGuidDatabase()));
|
||||
connect(ui->actionLoadDefaultGuidDatabase, SIGNAL(triggered()), this, SLOT(loadDefaultGuidDatabase()));
|
||||
connect(ui->actionExportDiscoveredGuids, SIGNAL(triggered()), this, SLOT(exportDiscoveredGuids()));
|
||||
connect(ui->actionGenerateReport, SIGNAL(triggered()), this, SLOT(generateReport()));
|
||||
connect(ui->actionToggleBootGuardMarking, SIGNAL(toggled(bool)), this, SLOT(toggleBootGuardMarking(bool)));
|
||||
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(writeSettings()));
|
||||
|
@ -121,7 +127,7 @@ void UEFITool::init()
|
|||
|
||||
// Disable menus
|
||||
ui->actionSearch->setEnabled(false);
|
||||
ui->actionGoToOffset->setEnabled(false);
|
||||
ui->actionGoToBase->setEnabled(false);
|
||||
ui->actionGoToAddress->setEnabled(false);
|
||||
ui->menuCapsuleActions->setEnabled(false);
|
||||
ui->menuImageActions->setEnabled(false);
|
||||
|
@ -146,11 +152,11 @@ void UEFITool::init()
|
|||
model->setMarkingEnabled(markingEnabled);
|
||||
ui->actionToggleBootGuardMarking->setChecked(markingEnabled);
|
||||
|
||||
// Connect
|
||||
// Connect signals to slots
|
||||
connect(ui->structureTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
||||
this, SLOT(populateUi(const QModelIndex &)));
|
||||
this, SLOT(populateUi(const QModelIndex &)));
|
||||
connect(ui->structureTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
|
||||
this, SLOT(populateUi(const QItemSelection &)));
|
||||
this, SLOT(populateUi(const QItemSelection &)));
|
||||
connect(ui->parserMessagesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(scrollTreeView(QListWidgetItem*)));
|
||||
connect(ui->parserMessagesListWidget, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(enableMessagesCopyActions(QListWidgetItem*)));
|
||||
connect(ui->finderMessagesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(scrollTreeView(QListWidgetItem*)));
|
||||
|
@ -159,8 +165,52 @@ void UEFITool::init()
|
|||
connect(ui->builderMessagesListWidget, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(enableMessagesCopyActions(QListWidgetItem*)));
|
||||
connect(ui->fitTableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(scrollTreeView(QTableWidgetItem*)));
|
||||
connect(ui->messagesTabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
||||
|
||||
// Allow enter/return pressing to scroll tree view
|
||||
ui->parserMessagesListWidget->installEventFilter(this);
|
||||
ui->finderMessagesListWidget->installEventFilter(this);
|
||||
ui->builderMessagesListWidget->installEventFilter(this);
|
||||
|
||||
// Detect and set UI light or dark mode
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
#if QT_VERSION_MINOR < 5
|
||||
#if defined Q_OS_WIN
|
||||
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat);
|
||||
if (settings.value("AppsUseLightTheme", 1).toInt() == 0) {
|
||||
model->setMarkingDarkMode(true);
|
||||
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
QApplication::setPalette(QApplication::style()->standardPalette());
|
||||
}
|
||||
#else
|
||||
const QPalette palette = QApplication::palette();
|
||||
const QColor& color = palette.color(QPalette::Active, QPalette::Base);
|
||||
if (color.lightness() < 127) { // TreeView has dark background
|
||||
model->setMarkingDarkMode(true);
|
||||
}
|
||||
#endif // defined Q_OS_WIN
|
||||
#else // QT_VERSION_MINOR >= 5
|
||||
// Qt 6.5.0 added proper support for dark UI mode, including detection and notification on mode change
|
||||
// It also supposed to work in all OSes, but still requires changing the default style on Windows from Vista to Fusion
|
||||
auto styleHints = QGuiApplication::styleHints();
|
||||
model->setMarkingDarkMode(styleHints->colorScheme() == Qt::ColorScheme::Dark);
|
||||
connect(styleHints, SIGNAL(colorSchemeChanged(Qt::ColorScheme)), this, SLOT(updateUiForNewColorScheme(Qt::ColorScheme)));
|
||||
|
||||
#if defined Q_OS_WIN
|
||||
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
QApplication::setPalette(QApplication::style()->standardPalette());
|
||||
#endif
|
||||
#endif // QT_VERSION_MINOR
|
||||
#endif // QT_VERSION_MAJOR
|
||||
}
|
||||
|
||||
#if QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 5
|
||||
void UEFITool::updateUiForNewColorScheme(Qt::ColorScheme scheme)
|
||||
{
|
||||
model->setMarkingDarkMode(scheme == Qt::ColorScheme::Dark);
|
||||
QApplication::setPalette(QApplication::style()->standardPalette());
|
||||
}
|
||||
#endif
|
||||
|
||||
void UEFITool::populateUi(const QItemSelection &selected)
|
||||
{
|
||||
if (selected.isEmpty()) {
|
||||
|
@ -191,25 +241,47 @@ void UEFITool::populateUi(const QModelIndex ¤t)
|
|||
ui->menuVolumeActions->setEnabled(type == Types::Volume);
|
||||
ui->menuFileActions->setEnabled(type == Types::File);
|
||||
ui->menuSectionActions->setEnabled(type == Types::Section);
|
||||
ui->menuEntryActions->setEnabled(type == Types::NvarEntry
|
||||
|| type == Types::VssEntry
|
||||
|| type == Types::FsysEntry
|
||||
|| type == Types::EvsaEntry
|
||||
|| type == Types::FlashMapEntry);
|
||||
ui->menuEntryActions->setEnabled(type == Types::Microcode
|
||||
|| type == Types::SlicData
|
||||
|| type == Types::NvarEntry
|
||||
|| type == Types::VssEntry
|
||||
|| type == Types::SysFEntry
|
||||
|| type == Types::EvsaEntry
|
||||
|| type == Types::PhoenixFlashMapEntry
|
||||
|| type == Types::InsydeFlashDeviceMapEntry
|
||||
|| type == Types::DellDvarEntry
|
||||
|| type == Types::IfwiHeader
|
||||
|| type == Types::IfwiPartition
|
||||
|| type == Types::FptPartition
|
||||
|| type == Types::FptEntry
|
||||
|| type == Types::BpdtPartition
|
||||
|| type == Types::BpdtEntry
|
||||
|| type == Types::CpdPartition
|
||||
|| type == Types::CpdEntry
|
||||
|| type == Types::CpdExtension
|
||||
|| type == Types::CpdSpiEntry
|
||||
|| type == Types::StartupApDataEntry
|
||||
);
|
||||
ui->menuStoreActions->setEnabled(type == Types::VssStore
|
||||
|| type == Types::Vss2Store
|
||||
|| type == Types::FdcStore
|
||||
|| type == Types::FsysStore
|
||||
|| type == Types::EvsaStore
|
||||
|| type == Types::FtwStore
|
||||
|| type == Types::FlashMapStore
|
||||
|| type == Types::CmdbStore
|
||||
|| type == Types::Microcode
|
||||
|| type == Types::SlicData);
|
||||
|| type == Types::Vss2Store
|
||||
|| type == Types::FdcStore
|
||||
|| type == Types::SysFStore
|
||||
|| type == Types::EvsaStore
|
||||
|| type == Types::FtwStore
|
||||
|| type == Types::PhoenixFlashMapStore
|
||||
|| type == Types::InsydeFlashDeviceMapStore
|
||||
|| type == Types::DellDvarStore
|
||||
|| type == Types::NvarGuidStore
|
||||
|| type == Types::CmdbStore
|
||||
|| type == Types::FptStore
|
||||
|| type == Types::BpdtStore
|
||||
|| type == Types::CpdStore
|
||||
);
|
||||
|
||||
// Enable actions
|
||||
ui->actionHexView->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current) && model->hasEmptyTail(current));
|
||||
ui->actionBodyHexView->setDisabled(model->hasEmptyBody(current));
|
||||
ui->actionUncompressedHexView->setDisabled(model->hasEmptyUncompressedData(current));
|
||||
ui->actionExtract->setDisabled(model->hasEmptyHeader(current) && model->hasEmptyBody(current) && model->hasEmptyTail(current));
|
||||
ui->actionGoToData->setEnabled(type == Types::NvarEntry && subtype == Subtypes::LinkNvarEntry);
|
||||
|
||||
|
@ -219,7 +291,7 @@ void UEFITool::populateUi(const QModelIndex ¤t)
|
|||
|
||||
//ui->actionRebuild->setEnabled(type == Types::Volume || type == Types::File || type == Types::Section);
|
||||
ui->actionExtractBody->setDisabled(model->hasEmptyBody(current));
|
||||
ui->actionExtractBodyUncompressed->setEnabled(enableExtractBodyUncompressed(current));
|
||||
ui->actionExtractBodyUncompressed->setDisabled(model->hasEmptyUncompressedData(current));
|
||||
//ui->actionRemove->setEnabled(type == Types::Volume || type == Types::File || type == Types::Section);
|
||||
//ui->actionInsertInto->setEnabled((type == Types::Volume && subtype != Subtypes::UnknownVolume) ||
|
||||
// (type == Types::File && subtype != EFI_FV_FILETYPE_ALL && subtype != EFI_FV_FILETYPE_RAW && subtype != EFI_FV_FILETYPE_PAD) ||
|
||||
|
@ -232,20 +304,11 @@ void UEFITool::populateUi(const QModelIndex ¤t)
|
|||
ui->menuMessageActions->setEnabled(false);
|
||||
}
|
||||
|
||||
bool UEFITool::enableExtractBodyUncompressed(const QModelIndex ¤t)
|
||||
{
|
||||
// TODO: rewrite based on model->compressed()
|
||||
U_UNUSED_PARAMETER(current);
|
||||
return false;
|
||||
}
|
||||
|
||||
void UEFITool::search()
|
||||
{
|
||||
if (searchDialog->exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
QModelIndex rootIndex = model->index(0, 0);
|
||||
|
||||
int index = searchDialog->ui->tabWidget->currentIndex();
|
||||
if (index == 0) { // Hex pattern
|
||||
searchDialog->ui->hexEdit->setFocus();
|
||||
|
@ -259,7 +322,7 @@ void UEFITool::search()
|
|||
mode = SEARCH_MODE_BODY;
|
||||
else
|
||||
mode = SEARCH_MODE_ALL;
|
||||
ffsFinder->findHexPattern(rootIndex, pattern, mode);
|
||||
ffsFinder->findHexPattern(pattern, mode);
|
||||
showFinderMessages();
|
||||
}
|
||||
else if (index == 1) { // GUID
|
||||
|
@ -275,7 +338,7 @@ void UEFITool::search()
|
|||
mode = SEARCH_MODE_BODY;
|
||||
else
|
||||
mode = SEARCH_MODE_ALL;
|
||||
ffsFinder->findGuidPattern(rootIndex, pattern, mode);
|
||||
ffsFinder->findGuidPattern(pattern, mode);
|
||||
showFinderMessages();
|
||||
}
|
||||
else if (index == 2) { // Text string
|
||||
|
@ -290,8 +353,8 @@ void UEFITool::search()
|
|||
mode = SEARCH_MODE_BODY;
|
||||
else
|
||||
mode = SEARCH_MODE_ALL;
|
||||
ffsFinder->findTextPattern(rootIndex, pattern, mode, searchDialog->ui->textUnicodeCheckBox->isChecked(),
|
||||
(Qt::CaseSensitivity) searchDialog->ui->textCaseSensitiveCheckBox->isChecked());
|
||||
ffsFinder->findTextPattern(pattern, mode, searchDialog->ui->textUnicodeCheckBox->isChecked(),
|
||||
(Qt::CaseSensitivity) searchDialog->ui->textCaseSensitiveCheckBox->isChecked());
|
||||
showFinderMessages();
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +365,7 @@ void UEFITool::hexView()
|
|||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
hexViewDialog->setItem(index, false);
|
||||
hexViewDialog->setItem(index, HexViewDialog::HexViewType::fullHexView);
|
||||
hexViewDialog->exec();
|
||||
}
|
||||
|
||||
|
@ -312,19 +375,29 @@ void UEFITool::bodyHexView()
|
|||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
hexViewDialog->setItem(index, true);
|
||||
hexViewDialog->setItem(index, HexViewDialog::HexViewType::bodyHexView);
|
||||
hexViewDialog->exec();
|
||||
}
|
||||
|
||||
void UEFITool::goToOffset()
|
||||
void UEFITool::uncompressedHexView()
|
||||
{
|
||||
goToOffsetDialog->ui->hexSpinBox->setFocus();
|
||||
goToOffsetDialog->ui->hexSpinBox->selectAll();
|
||||
if (goToOffsetDialog->exec() != QDialog::Accepted)
|
||||
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
UINT32 offset = (UINT32)goToOffsetDialog->ui->hexSpinBox->value();
|
||||
QModelIndex index = model->findByOffset(offset);
|
||||
hexViewDialog->setItem(index, HexViewDialog::HexViewType::uncompressedHexView);
|
||||
hexViewDialog->exec();
|
||||
}
|
||||
|
||||
void UEFITool::goToBase()
|
||||
{
|
||||
goToBaseDialog->ui->hexSpinBox->setFocus();
|
||||
goToBaseDialog->ui->hexSpinBox->selectAll();
|
||||
if (goToBaseDialog->exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
UINT32 offset = (UINT32)goToBaseDialog->ui->hexSpinBox->value();
|
||||
QModelIndex index = model->findByBase(offset);
|
||||
if (index.isValid()) {
|
||||
ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
|
||||
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear);
|
||||
|
@ -339,7 +412,7 @@ void UEFITool::goToAddress()
|
|||
return;
|
||||
|
||||
UINT32 address = (UINT32)goToAddressDialog->ui->hexSpinBox->value();
|
||||
QModelIndex index = model->findByOffset(address - (UINT32)ffsParser->getAddressDiff());
|
||||
QModelIndex index = model->findByBase(address - (UINT32)ffsParser->getAddressDiff());
|
||||
if (index.isValid()) {
|
||||
ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
|
||||
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear);
|
||||
|
@ -361,15 +434,15 @@ void UEFITool::goToData()
|
|||
|
||||
UByteArray rdata = model->parsingData(index);
|
||||
const NVAR_ENTRY_PARSING_DATA* pdata = (const NVAR_ENTRY_PARSING_DATA*)rdata.constData();
|
||||
UINT32 lastVariableFlag = pdata->emptyByte ? 0xFFFFFF : 0;
|
||||
UINT32 offset = model->offset(index);
|
||||
if (pdata->next == lastVariableFlag) {
|
||||
if (pdata->next == 0xFFFFFF) {
|
||||
ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
|
||||
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear);
|
||||
}
|
||||
|
||||
for (int j = i + 1; j < model->rowCount(parent); j++) {
|
||||
QModelIndex currentIndex = parent.child(j, 0);
|
||||
QModelIndex currentIndex = parent.model()->index(j, 0, parent);
|
||||
|
||||
if (model->hasEmptyParsingData(currentIndex))
|
||||
continue;
|
||||
|
||||
|
@ -414,7 +487,6 @@ void UEFITool::replaceBody()
|
|||
void UEFITool::replace(const UINT8 mode)
|
||||
{
|
||||
U_UNUSED_PARAMETER(mode);
|
||||
|
||||
}
|
||||
|
||||
void UEFITool::extractAsIs()
|
||||
|
@ -455,75 +527,34 @@ void UEFITool::extract(const UINT8 mode)
|
|||
QString path;
|
||||
if (mode == EXTRACT_MODE_AS_IS) {
|
||||
switch (type) {
|
||||
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"), name + ".cap", tr("Capsule files (*.cap *.bin);;All files (*)")); break;
|
||||
case Types::Image: path = QFileDialog::getSaveFileName(this, tr("Save image to file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
|
||||
case Types::Region: path = QFileDialog::getSaveFileName(this, tr("Save region to file"), name + ".rgn", tr("Region files (*.rgn *.bin);;All files (*)")); break;
|
||||
case Types::Padding: path = QFileDialog::getSaveFileName(this, tr("Save padding to file"), name + ".pad", tr("Padding files (*.pad *.bin);;All files (*)")); break;
|
||||
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume to file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)")); break;
|
||||
case Types::File: path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"), name + ".ffs", tr("FFS files (*.ffs *.bin);;All files (*)")); break;
|
||||
case Types::Section: path = QFileDialog::getSaveFileName(this, tr("Save section to file"), name + ".sct", tr("Section files (*.sct *.bin);;All files (*)")); break;
|
||||
case Types::NvarEntry: path = QFileDialog::getSaveFileName(this, tr("Save NVAR entry to file"), name + ".nvar", tr("NVAR entry files (*.nvar *.bin);;All files (*)")); break;
|
||||
case Types::VssEntry: path = QFileDialog::getSaveFileName(this, tr("Save VSS entry to file"), name + ".vss", tr("VSS entry files (*.vss *.bin);;All files (*)")); break;
|
||||
case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save Fsys entry to file"), name + ".fse", tr("Fsys entry files (*.fse *.bin);;All files (*)")); break;
|
||||
case Types::EvsaEntry: path = QFileDialog::getSaveFileName(this, tr("Save EVSA entry to file"), name + ".evse", tr("EVSA entry files (*.evse *.bin);;All files (*)")); break;
|
||||
case Types::FlashMapEntry: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap entry to file"), name + ".fme", tr("FlashMap entry files (*.fme *.bin);;All files (*)")); break;
|
||||
case Types::VssStore: path = QFileDialog::getSaveFileName(this, tr("Save VSS store to file"), name + ".vss", tr("VSS store files (*.vss *.bin);;All files (*)")); break;
|
||||
case Types::Vss2Store: path = QFileDialog::getSaveFileName(this, tr("Save VSS2 store to file"), name + ".vss2", tr("VSS2 store files (*.vss2 *.bin);;All files (*)")); break;
|
||||
case Types::FdcStore: path = QFileDialog::getSaveFileName(this, tr("Save FDC store to file"), name + ".fdc", tr("FDC store files (*.fdc *.bin);;All files (*)")); break;
|
||||
case Types::FsysStore: path = QFileDialog::getSaveFileName(this, tr("Save Fsys store to file"), name + ".fsys", tr("Fsys store files (*.fsys *.bin);;All files (*)")); break;
|
||||
case Types::EvsaStore: path = QFileDialog::getSaveFileName(this, tr("Save EVSA store to file"), name + ".evsa", tr("EVSA store files (*.evsa *.bin);;All files (*)")); break;
|
||||
case Types::FtwStore: path = QFileDialog::getSaveFileName(this, tr("Save FTW store to file"), name + ".ftw", tr("FTW store files (*.ftw *.bin);;All files (*)")); break;
|
||||
case Types::FlashMapStore: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap store to file"), name + ".fmap", tr("FlashMap store files (*.fmap *.bin);;All files (*)")); break;
|
||||
case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save CMDB store to file"), name + ".cmdb", tr("CMDB store files (*.cmdb *.bin);;All files (*)")); break;
|
||||
case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode binary to file"), name + ".ucd", tr("Microcode binary files (*.ucd *.bin);;All files (*)")); break;
|
||||
case Types::SlicData:
|
||||
if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey to file"), name + ".spk", tr("SLIC pubkey files (*.spk *.bin);;All files (*)"));
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker to file"), name + ".smk", tr("SLIC marker files (*.smk *.bin);;All files (*)"));
|
||||
break;
|
||||
default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"), name + ".cap", tr("Capsule files (*.cap *.bin);;All files (*)")); break;
|
||||
case Types::Image: path = QFileDialog::getSaveFileName(this, tr("Save image to file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
|
||||
case Types::Region: path = QFileDialog::getSaveFileName(this, tr("Save region to file"), name + ".rgn", tr("Region files (*.rgn *.bin);;All files (*)")); break;
|
||||
case Types::Padding: path = QFileDialog::getSaveFileName(this, tr("Save padding to file"), name + ".pad", tr("Padding files (*.pad *.bin);;All files (*)")); break;
|
||||
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume to file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)")); break;
|
||||
case Types::File: path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"), name + ".ffs", tr("FFS files (*.ffs *.bin);;All files (*)")); break;
|
||||
case Types::Section: path = QFileDialog::getSaveFileName(this, tr("Save section to file"), name + ".sct", tr("Section files (*.sct *.bin);;All files (*)")); break;
|
||||
default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
}
|
||||
}
|
||||
else if (mode == EXTRACT_MODE_BODY || mode == EXTRACT_MODE_BODY_UNCOMPRESSED) {
|
||||
switch (type) {
|
||||
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
|
||||
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume body to file"), name + ".vbd", tr("Volume body files (*.vbd *.bin);;All files (*)")); break;
|
||||
case Types::File:
|
||||
if (subtype == EFI_FV_FILETYPE_ALL
|
||||
|| subtype == EFI_FV_FILETYPE_RAW) path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"), name + ".raw", tr("Raw files (*.raw *.bin);;All files (*)"));
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"), name + ".fbd", tr("FFS file body files (*.fbd *.bin);;All files (*)"));
|
||||
break;
|
||||
case Types::Section:
|
||||
if (subtype == EFI_SECTION_COMPRESSION
|
||||
|| subtype == EFI_SECTION_GUID_DEFINED
|
||||
|| subtype == EFI_SECTION_DISPOSABLE) path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"), name + ".fbd", tr("FFS file body files (*.fbd *.bin);;All files (*)"));
|
||||
else if (subtype == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)"));
|
||||
else if (subtype == EFI_SECTION_RAW) path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"), name + ".raw", tr("Raw files (*.raw *.bin);;All files (*)"));
|
||||
else if (subtype == EFI_SECTION_PE32
|
||||
|| subtype == EFI_SECTION_TE
|
||||
|| subtype == EFI_SECTION_PIC) path = QFileDialog::getSaveFileName(this, tr("Save section body to EFI executable file"), name + ".efi", tr("EFI executable files (*.efi *.bin);;All files (*)"));
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save section body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
break;
|
||||
case Types::NvarEntry:
|
||||
case Types::VssEntry:
|
||||
case Types::EvsaEntry:
|
||||
case Types::FlashMapEntry:
|
||||
case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save entry body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)")); break;
|
||||
case Types::VssStore:
|
||||
case Types::Vss2Store:
|
||||
case Types::FtwStore:
|
||||
case Types::FdcStore:
|
||||
case Types::FsysStore:
|
||||
case Types::FlashMapStore:
|
||||
case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save store body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)")); break;
|
||||
case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode body to file"), name + ".ucb", tr("Microcode body files (*.ucb *.bin);;All files (*)")); break;
|
||||
case Types::SlicData:
|
||||
if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey body to file"), name + ".spb", tr("SLIC pubkey body files (*.spb *.bin);;All files (*)"));
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker body to file"), name + ".smb", tr("SLIC marker body files (*.smb *.bin);;All files (*)"));
|
||||
break;
|
||||
default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
|
||||
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume body to file"), name + ".vbd", tr("Volume body files (*.vbd *.bin);;All files (*)")); break;
|
||||
case Types::File: path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"), name + ".fbd", tr("FFS file body files (*.fbd *.bin);;All files (*)")); break;
|
||||
case Types::Section:
|
||||
if (subtype == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {
|
||||
path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)")); break;
|
||||
}
|
||||
else if (subtype == EFI_SECTION_PE32
|
||||
|| subtype == EFI_SECTION_TE
|
||||
|| subtype == EFI_SECTION_PIC) {
|
||||
path = QFileDialog::getSaveFileName(this, tr("Save section body to EFI executable file"), name + ".efi", tr("EFI executable files (*.efi *.bin);;All files (*)")); break;
|
||||
}
|
||||
default: path = QFileDialog::getSaveFileName(this, tr("Save object body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
}
|
||||
}
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
else path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
|
||||
|
||||
if (path.trimmed().isEmpty())
|
||||
return;
|
||||
|
@ -551,17 +582,26 @@ void UEFITool::remove()
|
|||
|
||||
void UEFITool::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About UEFITool"), tr(
|
||||
"Copyright (c) 2018, LongSoft.<br>"
|
||||
"Program icon made by <a href=https://www.behance.net/alzhidkov>Alexander Zhidkov</a>.<br>"
|
||||
"The program uses QHexEdit2 library made by <a href=https://github.com/Simsys/>Simsys</a>.<br>"
|
||||
"Qt-less engine is using Bstrlib made by <a href=https://github.com/websnarf/>Paul Hsieh</a>.<br><br>"
|
||||
"The program is dedicated to <b>RevoGirl</b>. Rest in peace, young genius.<br><br>"
|
||||
"The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License.<br>"
|
||||
"The full text of the license may be found at <a href=http://opensource.org/licenses/bsd-license.php>OpenSource.org</a>.<br><br>"
|
||||
"<b>THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS, "
|
||||
"WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, "
|
||||
"EITHER EXPRESS OR IMPLIED.</b>"));
|
||||
QMessageBox::about(this,
|
||||
tr("About UEFITool"),
|
||||
tr("<b>UEFITool %1.</b><br><br>"
|
||||
"Copyright (c) 2013-2025, Nikolaj (<b>CodeRush</b>) Schlej, Vitaly (<b>vit9696</b>) Cheptsov, <a href=https://github.com/LongSoft/UEFITool/graphs/contributors>et al</a>.<br><br>"
|
||||
"Program icon made by <a href=https://www.behance.net/alzhidkov>Alexander Zhidkov</a>.<br><br>"
|
||||
"GUI uses QHexView made by <a href=https://github.com/Dax89>Antonio Davide</a>.<br>"
|
||||
"Qt-less engine uses Bstrlib made by <a href=https://github.com/websnarf>Paul Hsieh</a>.<br>"
|
||||
"Engine uses Tiano compression code made by <a href=https://github.com/tianocore>TianoCore developers</a>.<br>"
|
||||
"Engine uses LZMA compression code made by <a href=https://www.7-zip.org/sdk.html>Igor Pavlov</a>.<br>"
|
||||
"Engine uses zlib compression code made by <a href=https://github.com/madler>Mark Adler</a>.<br>"
|
||||
"Engine uses LibTomCrypt hashing code made by <a href=https://github.com/libtom>LibTom developers</a>.<br>"
|
||||
"Engine uses KaitaiStruct runtime made by <a href=https://github.com/kaitai-io>Kaitai team</a>.<br><br>"
|
||||
"The program is dedicated to <b>RevoGirl</b>. Rest in peace, young genius.<br><br>"
|
||||
"The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD-2-Clause License.<br>"
|
||||
"The full text of the license may be found at <a href=https://opensource.org/licenses/BSD-2-Clause>OpenSource.org</a>.<br><br>"
|
||||
"<b>THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS, "
|
||||
"WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, "
|
||||
"EITHER EXPRESS OR IMPLIED.</b>"
|
||||
"").arg(version)
|
||||
);
|
||||
}
|
||||
|
||||
void UEFITool::aboutQt()
|
||||
|
@ -626,8 +666,10 @@ void UEFITool::openImageFile(QString path)
|
|||
QMessageBox::critical(this, tr("Image parsing failed"), errorCodeToUString(result), QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
else
|
||||
else {
|
||||
ui->statusBar->showMessage(tr("Opened: %1").arg(fileInfo.fileName()));
|
||||
}
|
||||
ffsParser->outputInfo();
|
||||
|
||||
// Enable or disable FIT tab
|
||||
showFitTable();
|
||||
|
@ -646,14 +688,17 @@ void UEFITool::openImageFile(QString path)
|
|||
delete ffsReport;
|
||||
ffsReport = new FfsReport(model);
|
||||
|
||||
// Enable goToOffset and goToAddress
|
||||
ui->actionGoToOffset->setEnabled(true);
|
||||
if (ffsParser->getAddressDiff() < 0xFFFFFFFFUL)
|
||||
// Enable goToBase and goToAddress
|
||||
ui->actionGoToBase->setEnabled(true);
|
||||
if (ffsParser->getAddressDiff() <= 0xFFFFFFFFUL)
|
||||
ui->actionGoToAddress->setEnabled(true);
|
||||
|
||||
// Enable generateReport
|
||||
ui->actionGenerateReport->setEnabled(true);
|
||||
|
||||
// Enable saving GUIDs
|
||||
ui->actionExportDiscoveredGuids->setEnabled(true);
|
||||
|
||||
// Set current directory
|
||||
currentDir = fileInfo.absolutePath();
|
||||
|
||||
|
@ -673,7 +718,7 @@ void UEFITool::copyMessage()
|
|||
{
|
||||
clipboard->clear();
|
||||
if (ui->messagesTabWidget->currentIndex() == TAB_PARSER) // Parser tab
|
||||
clipboard->setText(ui->parserMessagesListWidget->currentItem()->text());
|
||||
clipboard->setText(ui->parserMessagesListWidget->currentItem()->text());
|
||||
else if (ui->messagesTabWidget->currentIndex() == TAB_SEARCH) // Search tab
|
||||
clipboard->setText(ui->finderMessagesListWidget->currentItem()->text());
|
||||
else if (ui->messagesTabWidget->currentIndex() == TAB_BUILDER) // Builder tab
|
||||
|
@ -728,6 +773,23 @@ void UEFITool::toggleBootGuardMarking(bool enabled)
|
|||
markingEnabled = enabled;
|
||||
}
|
||||
|
||||
// Emit double click signal of QListWidget on enter/return key pressed
|
||||
bool UEFITool::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent* key = static_cast<QKeyEvent*>(event);
|
||||
|
||||
if (key->key() == Qt::Key_Enter || key->key() == Qt::Key_Return) {
|
||||
QListWidget* list = qobject_cast<QListWidget*>(obj);
|
||||
|
||||
if (list != NULL && list->currentItem() != NULL)
|
||||
emit list->itemDoubleClicked(list->currentItem());
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void UEFITool::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("text/uri-list"))
|
||||
|
@ -747,8 +809,8 @@ void UEFITool::showParserMessages()
|
|||
return;
|
||||
|
||||
std::vector<std::pair<QString, QModelIndex> > messages = ffsParser->getMessages();
|
||||
std::pair<QString, QModelIndex> msg;
|
||||
foreach (msg, messages) {
|
||||
|
||||
for (const auto &msg : messages) {
|
||||
QListWidgetItem* item = new QListWidgetItem(msg.first, NULL, 0);
|
||||
item->setData(Qt::UserRole, QByteArray((const char*)&msg.second, sizeof(msg.second)));
|
||||
ui->parserMessagesListWidget->addItem(item);
|
||||
|
@ -765,8 +827,8 @@ void UEFITool::showFinderMessages()
|
|||
return;
|
||||
|
||||
std::vector<std::pair<QString, QModelIndex> > messages = ffsFinder->getMessages();
|
||||
std::pair<QString, QModelIndex> msg;
|
||||
foreach (msg, messages) {
|
||||
|
||||
for (const auto &msg : messages) {
|
||||
QListWidgetItem* item = new QListWidgetItem(msg.first, NULL, 0);
|
||||
item->setData(Qt::UserRole, QByteArray((const char*)&msg.second, sizeof(msg.second)));;
|
||||
ui->finderMessagesListWidget->addItem(item);
|
||||
|
@ -784,8 +846,8 @@ void UEFITool::showBuilderMessages()
|
|||
return;
|
||||
|
||||
std::vector<std::pair<QString, QModelIndex> > messages = ffsBuilder->getMessages();
|
||||
std::pair<QString, QModelIndex> msg;
|
||||
foreach (msg, messages) {
|
||||
|
||||
for (const auto &msg : messages) {
|
||||
QListWidgetItem* item = new QListWidgetItem(msg.first, NULL, 0);
|
||||
item->setData(Qt::UserRole, QByteArray((const char*)&msg.second, sizeof(msg.second)));
|
||||
ui->builderMessagesListWidget->addItem(item);
|
||||
|
@ -838,33 +900,38 @@ void UEFITool::contextMenuEvent(QContextMenuEvent* event)
|
|||
return;
|
||||
}
|
||||
|
||||
switch (model->type(index))
|
||||
{
|
||||
case Types::Capsule: ui->menuCapsuleActions->exec(event->globalPos()); break;
|
||||
case Types::Image: ui->menuImageActions->exec(event->globalPos()); break;
|
||||
case Types::Region: ui->menuRegionActions->exec(event->globalPos()); break;
|
||||
case Types::Padding: ui->menuPaddingActions->exec(event->globalPos()); break;
|
||||
case Types::Volume: ui->menuVolumeActions->exec(event->globalPos()); break;
|
||||
case Types::File: ui->menuFileActions->exec(event->globalPos()); break;
|
||||
case Types::Section: ui->menuSectionActions->exec(event->globalPos()); break;
|
||||
case Types::VssStore:
|
||||
case Types::Vss2Store:
|
||||
case Types::FdcStore:
|
||||
case Types::FsysStore:
|
||||
case Types::EvsaStore:
|
||||
case Types::FtwStore:
|
||||
case Types::FlashMapStore:
|
||||
case Types::CmdbStore: ui->menuStoreActions->exec(event->globalPos()); break;
|
||||
case Types::FreeSpace: break;
|
||||
default: ui->menuEntryActions->exec(event->globalPos()); break;
|
||||
switch (model->type(index)) {
|
||||
case Types::Capsule: ui->menuCapsuleActions->exec(event->globalPos()); break;
|
||||
case Types::Image: ui->menuImageActions->exec(event->globalPos()); break;
|
||||
case Types::Region: ui->menuRegionActions->exec(event->globalPos()); break;
|
||||
case Types::Padding: ui->menuPaddingActions->exec(event->globalPos()); break;
|
||||
case Types::Volume: ui->menuVolumeActions->exec(event->globalPos()); break;
|
||||
case Types::File: ui->menuFileActions->exec(event->globalPos()); break;
|
||||
case Types::Section: ui->menuSectionActions->exec(event->globalPos()); break;
|
||||
case Types::VssStore:
|
||||
case Types::Vss2Store:
|
||||
case Types::FdcStore:
|
||||
case Types::SysFStore:
|
||||
case Types::EvsaStore:
|
||||
case Types::FtwStore:
|
||||
case Types::PhoenixFlashMapStore:
|
||||
case Types::InsydeFlashDeviceMapStore:
|
||||
case Types::DellDvarStore:
|
||||
case Types::NvarGuidStore:
|
||||
case Types::CmdbStore:
|
||||
case Types::FptStore:
|
||||
case Types::CpdStore:
|
||||
case Types::BpdtStore: ui->menuStoreActions->exec(event->globalPos()); break;
|
||||
case Types::FreeSpace: break; // No menu needed for FreeSpace item
|
||||
default: ui->menuEntryActions->exec(event->globalPos()); break;
|
||||
}
|
||||
}
|
||||
|
||||
void UEFITool::readSettings()
|
||||
{
|
||||
QSettings settings(this);
|
||||
resize(settings.value("mainWindow/size", QSize(800, 600)).toSize());
|
||||
move(settings.value("mainWindow/position", QPoint(0, 0)).toPoint());
|
||||
restoreGeometry(settings.value("mainWindow/geometry").toByteArray());
|
||||
restoreState(settings.value("mainWindow/windowState").toByteArray());
|
||||
QList<int> horList, vertList;
|
||||
horList.append(settings.value("mainWindow/treeWidth", 600).toInt());
|
||||
horList.append(settings.value("mainWindow/infoWidth", 180).toInt());
|
||||
|
@ -879,10 +946,10 @@ void UEFITool::readSettings()
|
|||
markingEnabled = settings.value("tree/markingEnabled", true).toBool();
|
||||
ui->actionToggleBootGuardMarking->setChecked(markingEnabled);
|
||||
|
||||
// Set monospace font for some controls
|
||||
// Set monospace font
|
||||
QString fontName;
|
||||
int fontSize;
|
||||
#if defined Q_OS_OSX
|
||||
#if defined Q_OS_MACOS
|
||||
fontName = settings.value("mainWindow/fontName", QString("Menlo")).toString();
|
||||
fontSize = settings.value("mainWindow/fontSize", 10).toInt();
|
||||
#elif defined Q_OS_WIN
|
||||
|
@ -893,25 +960,15 @@ void UEFITool::readSettings()
|
|||
fontSize = settings.value("mainWindow/fontSize", 10).toInt();
|
||||
#endif
|
||||
currentFont = QFont(fontName, fontSize);
|
||||
ui->infoEdit->setFont(currentFont);
|
||||
ui->parserMessagesListWidget->setFont(currentFont);
|
||||
ui->finderMessagesListWidget->setFont(currentFont);
|
||||
ui->builderMessagesListWidget->setFont(currentFont);
|
||||
ui->fitTableWidget->setFont(currentFont);
|
||||
ui->securityEdit->setFont(currentFont);
|
||||
ui->structureTreeView->setFont(currentFont);
|
||||
searchDialog->ui->guidEdit->setFont(currentFont);
|
||||
searchDialog->ui->hexEdit->setFont(currentFont);
|
||||
hexViewDialog->setFont(currentFont);
|
||||
goToOffsetDialog->ui->hexSpinBox->setFont(currentFont);
|
||||
goToAddressDialog->ui->hexSpinBox->setFont(currentFont);
|
||||
currentFont.setStyleHint(QFont::Monospace);
|
||||
QApplication::setFont(currentFont);
|
||||
}
|
||||
|
||||
void UEFITool::writeSettings()
|
||||
{
|
||||
QSettings settings(this);
|
||||
settings.setValue("mainWindow/size", size());
|
||||
settings.setValue("mainWindow/position", pos());
|
||||
settings.setValue("mainWindow/geometry", saveGeometry());
|
||||
settings.setValue("mainWindow/windowState", saveState());
|
||||
settings.setValue("mainWindow/treeWidth", ui->structureGroupBox->width());
|
||||
settings.setValue("mainWindow/infoWidth", ui->infoGroupBox->width());
|
||||
settings.setValue("mainWindow/treeHeight", ui->structureGroupBox->height());
|
||||
|
@ -999,7 +1056,7 @@ void UEFITool::unloadGuidDatabase()
|
|||
{
|
||||
initGuidDatabase();
|
||||
if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("GUID database unloaded"), tr("Apply changes on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No))
|
||||
openImageFile(currentPath);
|
||||
openImageFile(currentPath);
|
||||
}
|
||||
|
||||
void UEFITool::loadDefaultGuidDatabase()
|
||||
|
@ -1009,6 +1066,16 @@ void UEFITool::loadDefaultGuidDatabase()
|
|||
openImageFile(currentPath);
|
||||
}
|
||||
|
||||
void UEFITool::exportDiscoveredGuids()
|
||||
{
|
||||
GuidDatabase db = guidDatabaseFromTreeRecursive(model, model->index(0, 0));
|
||||
if (!db.empty()) {
|
||||
QString path = QFileDialog::getSaveFileName(this, tr("Save parsed GUIDs to database"), currentPath + ".guids.csv", tr("Comma-separated values files (*.csv);;All files (*)"));
|
||||
if (!path.isEmpty())
|
||||
guidDatabaseExportToFile(path, db);
|
||||
}
|
||||
}
|
||||
|
||||
void UEFITool::generateReport()
|
||||
{
|
||||
QString path = QFileDialog::getSaveFileName(this, tr("Save report to text file"), currentPath + ".report.txt", tr("Text files (*.txt);;All files (*)"));
|
||||
|
|
|
@ -3,9 +3,8 @@ Type=Application
|
|||
Version=1.0
|
||||
Name=UEFITool
|
||||
Comment=UEFI firmware image viewer and editor
|
||||
Path=/usr/bin
|
||||
Exec=uefitool
|
||||
Icon=uefitool
|
||||
Terminal=false
|
||||
Categories=Development;System;Utility;HardwareSettings;Electronics;Engineering;
|
||||
Keywords=BIOS;
|
||||
Keywords=BIOS;UEFI;
|
||||
|
|
20
UEFITool/uefitool.entitlements
Normal file
20
UEFITool/uefitool.entitlements
Normal 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>
|
|
@ -27,10 +27,12 @@
|
|||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QPalette>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QProcess>
|
||||
#include <QSettings>
|
||||
#include <QSplitter>
|
||||
#include <QStyleFactory>
|
||||
#include <QString>
|
||||
#include <QTableWidget>
|
||||
#include <QTreeView>
|
||||
|
@ -46,7 +48,7 @@
|
|||
#include "../common/guiddatabase.h"
|
||||
|
||||
#include "searchdialog.h"
|
||||
#include "gotooffsetdialog.h"
|
||||
#include "gotobasedialog.h"
|
||||
#include "gotoaddressdialog.h"
|
||||
#include "hexviewdialog.h"
|
||||
#include "ffsfinder.h"
|
||||
|
@ -78,11 +80,12 @@ private slots:
|
|||
void saveImageFile();
|
||||
|
||||
void search();
|
||||
void goToOffset();
|
||||
void goToBase();
|
||||
void goToAddress();
|
||||
|
||||
void hexView();
|
||||
void bodyHexView();
|
||||
void uncompressedHexView();
|
||||
void goToData();
|
||||
|
||||
void extract(const UINT8 mode);
|
||||
|
@ -117,12 +120,17 @@ private slots:
|
|||
void writeSettings();
|
||||
|
||||
void loadGuidDatabase();
|
||||
void unloadGuidDatabase();
|
||||
void loadDefaultGuidDatabase();
|
||||
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:
|
||||
Ui::UEFITool* ui;
|
||||
TreeModel* model;
|
||||
|
@ -133,7 +141,7 @@ private:
|
|||
FfsBuilder* ffsBuilder;
|
||||
SearchDialog* searchDialog;
|
||||
HexViewDialog* hexViewDialog;
|
||||
GoToOffsetDialog* goToOffsetDialog;
|
||||
GoToBaseDialog* goToBaseDialog;
|
||||
GoToAddressDialog* goToAddressDialog;
|
||||
QClipboard* clipboard;
|
||||
QString currentDir;
|
||||
|
@ -143,8 +151,7 @@ private:
|
|||
const QString version;
|
||||
bool markingEnabled;
|
||||
|
||||
bool enableExtractBodyUncompressed(const QModelIndex ¤t);
|
||||
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
void dropEvent(QDropEvent* event);
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
QT += core gui widgets
|
||||
|
||||
TARGET = UEFITool
|
||||
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 \
|
||||
searchdialog.h \
|
||||
hexviewdialog.h \
|
||||
gotooffsetdialog.h \
|
||||
gotobasedialog.h \
|
||||
gotoaddressdialog.h \
|
||||
guidlineedit.h \
|
||||
hexlineedit.h \
|
||||
ffsfinder.h \
|
||||
hexspinbox.h \
|
||||
../common/fitparser.h \
|
||||
../common/guiddatabase.h \
|
||||
../common/nvram.h \
|
||||
../common/nvramparser.h \
|
||||
|
@ -25,7 +29,6 @@ HEADERS += uefitool.h \
|
|||
../common/gbe.h \
|
||||
../common/me.h \
|
||||
../common/ffs.h \
|
||||
../common/fit.h \
|
||||
../common/peimage.h \
|
||||
../common/types.h \
|
||||
../common/utility.h \
|
||||
|
@ -34,6 +37,8 @@ HEADERS += uefitool.h \
|
|||
../common/ffsparser.h \
|
||||
../common/ffsreport.h \
|
||||
../common/treeitem.h \
|
||||
../common/intel_fit.h \
|
||||
../common/intel_microcode.h \
|
||||
../common/treemodel.h \
|
||||
../common/LZMA/LzmaCompress.h \
|
||||
../common/LZMA/LzmaDecompress.h \
|
||||
|
@ -41,34 +46,61 @@ HEADERS += uefitool.h \
|
|||
../common/Tiano/EfiTianoCompress.h \
|
||||
../common/ustring.h \
|
||||
../common/ubytearray.h \
|
||||
../common/bootguard.h \
|
||||
../common/sha256.h \
|
||||
../common/zlib/zconf.h \
|
||||
../common/umemstream.h \
|
||||
../common/digest/sha1.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 \
|
||||
../common/zlib/deflate.h \
|
||||
../common/zlib/gzguts.h \
|
||||
../common/zlib/inffast.h \
|
||||
../common/zlib/inffixed.h \
|
||||
../common/zlib/inflate.h \
|
||||
../common/zlib/inftrees.h \
|
||||
../common/zlib/trees.h \
|
||||
../common/zlib/zutil.h \
|
||||
../version.h \
|
||||
qhexedit2/qhexedit.h \
|
||||
qhexedit2/chunks.h \
|
||||
qhexedit2/commands.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 \
|
||||
uefitool.cpp \
|
||||
searchdialog.cpp \
|
||||
hexviewdialog.cpp \
|
||||
guidlineedit.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 \
|
||||
|
@ -82,6 +114,9 @@ SOURCES += uefitool_main.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 \
|
||||
|
@ -89,7 +124,28 @@ SOURCES += uefitool_main.cpp \
|
|||
../common/Tiano/EfiTianoCompress.c \
|
||||
../common/Tiano/EfiTianoCompressLegacy.c \
|
||||
../common/ustring.cpp \
|
||||
../common/sha256.c \
|
||||
../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_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 \
|
||||
|
@ -105,17 +161,31 @@ SOURCES += uefitool_main.cpp \
|
|||
../common/zlib/trees.c \
|
||||
../common/zlib/uncompr.c \
|
||||
../common/zlib/zutil.c \
|
||||
qhexedit2/qhexedit.cpp \
|
||||
qhexedit2/chunks.cpp \
|
||||
qhexedit2/commands.cpp
|
||||
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 \
|
||||
searchdialog.ui \
|
||||
hexviewdialog.ui \
|
||||
gotooffsetdialog.ui \
|
||||
gotobasedialog.ui \
|
||||
gotoaddressdialog.ui
|
||||
|
||||
RESOURCES += uefitool.qrc
|
||||
RC_FILE = uefitool.rc
|
||||
ICON = icons/uefitool.icns
|
||||
|
||||
QMAKE_BUNDLE_DATA += ICONFILE
|
||||
QMAKE_INFO_PLIST = Info.plist
|
||||
|
|
|
@ -327,6 +327,7 @@
|
|||
<addaction name="actionLoadGuidDatabase"/>
|
||||
<addaction name="actionLoadDefaultGuidDatabase"/>
|
||||
<addaction name="actionUnloadGuidDatabase"/>
|
||||
<addaction name="actionExportDiscoveredGuids"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
|
@ -350,6 +351,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExtract"/>
|
||||
<addaction name="actionExtractBody"/>
|
||||
|
@ -400,6 +402,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExtract"/>
|
||||
<addaction name="actionExtractBody"/>
|
||||
|
@ -420,6 +423,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExtract"/>
|
||||
<addaction name="actionExtractBody"/>
|
||||
|
@ -444,6 +448,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExtract"/>
|
||||
<addaction name="actionExtractBody"/>
|
||||
|
@ -481,6 +486,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionGoToData"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -506,6 +512,7 @@
|
|||
</property>
|
||||
<addaction name="actionHexView"/>
|
||||
<addaction name="actionBodyHexView"/>
|
||||
<addaction name="actionUncompressedHexView"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExtract"/>
|
||||
<addaction name="actionExtractBody"/>
|
||||
|
@ -519,7 +526,7 @@
|
|||
<addaction name="actionReplace"/>
|
||||
<addaction name="actionReplaceBody"/>
|
||||
</widget>
|
||||
<addaction name="actionGoToOffset"/>
|
||||
<addaction name="actionGoToBase"/>
|
||||
<addaction name="actionGoToAddress"/>
|
||||
<addaction name="actionSearch"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -822,12 +829,12 @@
|
|||
<string>Ctrl+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGoToOffset">
|
||||
<action name="actionGoToBase">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Go to offset...</string>
|
||||
<string>&Select item at base...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
|
@ -844,6 +851,17 @@
|
|||
<string>Ctrl+Shift+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUncompressedHexView">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Un&compressed hex view...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Alt+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoadGuidDatabase">
|
||||
<property name="text">
|
||||
<string>Load &GUID database...</string>
|
||||
|
@ -857,7 +875,7 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Go to &address...</string>
|
||||
<string>Select item at &address...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+G</string>
|
||||
|
@ -907,6 +925,17 @@
|
|||
<string>Ctrl+Alt+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExportDiscoveredGuids">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Export discovered GUIDs...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Alt+E</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
|
|
@ -1,32 +1,64 @@
|
|||
/* uefitool_main.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
|
||||
Copyright (c) 2022, 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.
|
||||
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 <QApplication>
|
||||
#include <QString>
|
||||
#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[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setOrganizationName("LongSoft");
|
||||
a.setOrganizationDomain("longsoft.org");
|
||||
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();
|
||||
UEFIToolApplication a(argc, argv);
|
||||
return a.startup();
|
||||
}
|
BIN
appstream/UEFITool.png
Normal file
BIN
appstream/UEFITool.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 428 KiB |
23
appstream/appdata.xml
Normal file
23
appstream/appdata.xml
Normal 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>
|
|
@ -19,11 +19,11 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
|
||||
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
||||
|
||||
static void * AllocForLzma(void *p, size_t size) { (void)p; return malloc(size); }
|
||||
static void FreeForLzma(void *p, void *address) { (void)p; free(address); }
|
||||
static void * AllocForLzma(ISzAllocPtr p, size_t size) { (void)p; return malloc(size); }
|
||||
static void FreeForLzma(ISzAllocPtr p, void *address) { (void)p; free(address); }
|
||||
static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma };
|
||||
|
||||
SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize)
|
||||
SRes OnProgress(const ICompressProgress *p, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
(void)p; (void)inSize; (void)outSize;
|
||||
return SZ_OK;
|
||||
|
@ -64,7 +64,8 @@ LzmaCompress (
|
|||
CONST UINT8 *Source,
|
||||
UINT32 SourceSize,
|
||||
UINT8 *Destination,
|
||||
UINT32 *DestinationSize
|
||||
UINT32 *DestinationSize,
|
||||
UINT32 DictionarySize
|
||||
)
|
||||
{
|
||||
SRes LzmaResult;
|
||||
|
@ -79,8 +80,7 @@ LzmaCompress (
|
|||
}
|
||||
|
||||
LzmaEncProps_Init(&props);
|
||||
// TODO: need to detect this instead of hardcoding
|
||||
props.dictSize = LZMA_DICTIONARY_SIZE;
|
||||
props.dictSize = DictionarySize;
|
||||
props.level = 9;
|
||||
props.fb = 273;
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
#ifndef LZMACOMPRESS_H
|
||||
#define LZMACOMPRESS_H
|
||||
|
||||
#include "SDK/C/Types.h"
|
||||
#include "SDK/C/7zTypes.h"
|
||||
#include "../basetypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LZMA_DICTIONARY_SIZE 0x800000
|
||||
#define DEFAULT_LZMA_DICTIONARY_SIZE 0x800000
|
||||
#define _LZMA_SIZE_OPT
|
||||
|
||||
USTATUS
|
||||
|
@ -30,7 +30,8 @@ extern "C" {
|
|||
const UINT8 *Source,
|
||||
UINT32 SourceSize,
|
||||
UINT8 *Destination,
|
||||
UINT32 *DestinationSize
|
||||
UINT32 *DestinationSize,
|
||||
UINT32 DictionarySize
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -12,7 +12,7 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
*/
|
||||
|
||||
#include "LzmaDecompress.h"
|
||||
#include "SDK/C/Types.h"
|
||||
#include "SDK/C/7zTypes.h"
|
||||
#include "SDK/C/7zVersion.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -27,8 +27,8 @@ LShiftU64 (
|
|||
return Operand << Count;
|
||||
}
|
||||
|
||||
static void * AllocForLzma(void *p, size_t size) { (void)p; return malloc(size); }
|
||||
static void FreeForLzma(void *p, void *address) { (void)p; free(address); }
|
||||
static void * AllocForLzma(ISzAllocPtr p, size_t size) { (void)p; return malloc(size); }
|
||||
static void FreeForLzma(ISzAllocPtr p, void *address) { (void)p; free(address); }
|
||||
static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma };
|
||||
|
||||
/*
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "../basetypes.h"
|
||||
#include "SDK/C/LzmaDec.h"
|
||||
#include "SDK/C/Bra.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
597
common/LZMA/SDK/C/7zTypes.h
Normal file
597
common/LZMA/SDK/C/7zTypes.h
Normal file
|
@ -0,0 +1,597 @@
|
|||
/* 7zTypes.h -- Basic types
|
||||
2024-01-24 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef ZIP7_7Z_TYPES_H
|
||||
#define ZIP7_7Z_TYPES_H
|
||||
|
||||
#ifdef _WIN32
|
||||
/* #include <windows.h> */
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef EXTERN_C_BEGIN
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C_BEGIN extern "C" {
|
||||
#define EXTERN_C_END }
|
||||
#else
|
||||
#define EXTERN_C_BEGIN
|
||||
#define EXTERN_C_END
|
||||
#endif
|
||||
#endif
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
#define SZ_OK 0
|
||||
|
||||
#define SZ_ERROR_DATA 1
|
||||
#define SZ_ERROR_MEM 2
|
||||
#define SZ_ERROR_CRC 3
|
||||
#define SZ_ERROR_UNSUPPORTED 4
|
||||
#define SZ_ERROR_PARAM 5
|
||||
#define SZ_ERROR_INPUT_EOF 6
|
||||
#define SZ_ERROR_OUTPUT_EOF 7
|
||||
#define SZ_ERROR_READ 8
|
||||
#define SZ_ERROR_WRITE 9
|
||||
#define SZ_ERROR_PROGRESS 10
|
||||
#define SZ_ERROR_FAIL 11
|
||||
#define SZ_ERROR_THREAD 12
|
||||
|
||||
#define SZ_ERROR_ARCHIVE 16
|
||||
#define SZ_ERROR_NO_ARCHIVE 17
|
||||
|
||||
typedef int SRes;
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER > 1200
|
||||
#define MY_ALIGN(n) __declspec(align(n))
|
||||
#else
|
||||
#define MY_ALIGN(n)
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
// C11/C++11:
|
||||
#include <stdalign.h>
|
||||
#define MY_ALIGN(n) alignas(n)
|
||||
*/
|
||||
#define MY_ALIGN(n) __attribute__ ((aligned(n)))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* typedef DWORD WRes; */
|
||||
typedef unsigned WRes;
|
||||
#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
|
||||
|
||||
// #define MY_HRES_ERROR_INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
// #define ENV_HAVE_LSTAT
|
||||
typedef int WRes;
|
||||
|
||||
// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
|
||||
#define MY_FACILITY_ERRNO 0x800
|
||||
#define MY_FACILITY_WIN32 7
|
||||
#define MY_FACILITY_WRes MY_FACILITY_ERRNO
|
||||
|
||||
#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
|
||||
( (HRESULT)(x) & 0x0000FFFF) \
|
||||
| (MY_FACILITY_WRes << 16) \
|
||||
| (HRESULT)0x80000000 ))
|
||||
|
||||
#define MY_SRes_HRESULT_FROM_WRes(x) \
|
||||
((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
|
||||
|
||||
// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
|
||||
#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
|
||||
|
||||
/*
|
||||
#define ERROR_FILE_NOT_FOUND 2L
|
||||
#define ERROR_ACCESS_DENIED 5L
|
||||
#define ERROR_NO_MORE_FILES 18L
|
||||
#define ERROR_LOCK_VIOLATION 33L
|
||||
#define ERROR_FILE_EXISTS 80L
|
||||
#define ERROR_DISK_FULL 112L
|
||||
#define ERROR_NEGATIVE_SEEK 131L
|
||||
#define ERROR_ALREADY_EXISTS 183L
|
||||
#define ERROR_DIRECTORY 267L
|
||||
#define ERROR_TOO_MANY_POSTS 298L
|
||||
|
||||
#define ERROR_INTERNAL_ERROR 1359L
|
||||
#define ERROR_INVALID_REPARSE_DATA 4392L
|
||||
#define ERROR_REPARSE_TAG_INVALID 4393L
|
||||
#define ERROR_REPARSE_TAG_MISMATCH 4394L
|
||||
*/
|
||||
|
||||
// we use errno equivalents for some WIN32 errors:
|
||||
|
||||
#define ERROR_INVALID_PARAMETER EINVAL
|
||||
#define ERROR_INVALID_FUNCTION EINVAL
|
||||
#define ERROR_ALREADY_EXISTS EEXIST
|
||||
#define ERROR_FILE_EXISTS EEXIST
|
||||
#define ERROR_PATH_NOT_FOUND ENOENT
|
||||
#define ERROR_FILE_NOT_FOUND ENOENT
|
||||
#define ERROR_DISK_FULL ENOSPC
|
||||
// #define ERROR_INVALID_HANDLE EBADF
|
||||
|
||||
// we use FACILITY_WIN32 for errors that has no errno equivalent
|
||||
// Too many posts were made to a semaphore.
|
||||
#define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL)
|
||||
#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
|
||||
#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
|
||||
|
||||
// if (MY_FACILITY_WRes != FACILITY_WIN32),
|
||||
// we use FACILITY_WIN32 for COM errors:
|
||||
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
|
||||
#define E_INVALIDARG ((HRESULT)0x80070057L)
|
||||
#define MY_E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
|
||||
|
||||
/*
|
||||
// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
|
||||
#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
|
||||
#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
|
||||
#define MY_E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
|
||||
*/
|
||||
|
||||
#define TEXT(quote) quote
|
||||
|
||||
#define FILE_ATTRIBUTE_READONLY 0x0001
|
||||
#define FILE_ATTRIBUTE_HIDDEN 0x0002
|
||||
#define FILE_ATTRIBUTE_SYSTEM 0x0004
|
||||
#define FILE_ATTRIBUTE_DIRECTORY 0x0010
|
||||
#define FILE_ATTRIBUTE_ARCHIVE 0x0020
|
||||
#define FILE_ATTRIBUTE_DEVICE 0x0040
|
||||
#define FILE_ATTRIBUTE_NORMAL 0x0080
|
||||
#define FILE_ATTRIBUTE_TEMPORARY 0x0100
|
||||
#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
|
||||
#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
|
||||
#define FILE_ATTRIBUTE_COMPRESSED 0x0800
|
||||
#define FILE_ATTRIBUTE_OFFLINE 0x1000
|
||||
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
|
||||
#define FILE_ATTRIBUTE_ENCRYPTED 0x4000
|
||||
|
||||
#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { const int _result_ = (x); if (_result_ != 0) return _result_; }
|
||||
#endif
|
||||
|
||||
#ifndef RINOK_WRes
|
||||
#define RINOK_WRes(x) { const WRes _result_ = (x); if (_result_ != 0) return _result_; }
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
#ifdef Z7_DECL_Int32_AS_long
|
||||
typedef long Int32;
|
||||
typedef unsigned long UInt32;
|
||||
#else
|
||||
typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
typedef int INT;
|
||||
typedef Int32 INT32;
|
||||
typedef unsigned int UINT;
|
||||
typedef UInt32 UINT32;
|
||||
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
|
||||
typedef UINT32 ULONG;
|
||||
|
||||
#undef DWORD
|
||||
typedef UINT32 DWORD;
|
||||
|
||||
#define VOID void
|
||||
|
||||
#define HRESULT LONG
|
||||
|
||||
typedef void *LPVOID;
|
||||
// typedef void VOID;
|
||||
// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
|
||||
// gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
|
||||
typedef long INT_PTR;
|
||||
typedef unsigned long UINT_PTR;
|
||||
typedef long LONG_PTR;
|
||||
typedef unsigned long DWORD_PTR;
|
||||
|
||||
typedef size_t SIZE_T;
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
#define MY_HRES_ERROR_INTERNAL_ERROR ((HRESULT)0x8007054FL)
|
||||
|
||||
|
||||
#ifdef Z7_DECL_Int64_AS_long
|
||||
|
||||
typedef long Int64;
|
||||
typedef unsigned long UInt64;
|
||||
|
||||
#else
|
||||
|
||||
#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__clang__)
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#include <stdint.h>
|
||||
typedef int64_t Int64;
|
||||
typedef uint64_t UInt64;
|
||||
#else
|
||||
typedef long long int Int64;
|
||||
typedef unsigned long long int UInt64;
|
||||
// #define UINT64_CONST(n) n ## ULL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define UINT64_CONST(n) n
|
||||
|
||||
|
||||
#ifdef Z7_DECL_SizeT_AS_unsigned_int
|
||||
typedef unsigned int SizeT;
|
||||
#else
|
||||
typedef size_t SizeT;
|
||||
#endif
|
||||
|
||||
/*
|
||||
#if (defined(_MSC_VER) && _MSC_VER <= 1200)
|
||||
typedef size_t MY_uintptr_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
typedef uintptr_t MY_uintptr_t;
|
||||
#endif
|
||||
*/
|
||||
|
||||
typedef int BoolInt;
|
||||
/* typedef BoolInt Bool; */
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define Z7_STDCALL __stdcall
|
||||
#else
|
||||
#define Z7_STDCALL
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define Z7_NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define Z7_NO_INLINE
|
||||
#endif
|
||||
|
||||
#define Z7_FORCE_INLINE __forceinline
|
||||
|
||||
#define Z7_CDECL __cdecl
|
||||
#define Z7_FASTCALL __fastcall
|
||||
|
||||
#else // _MSC_VER
|
||||
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 4)) \
|
||||
|| (defined(__clang__) && (__clang_major__ >= 4)) \
|
||||
|| defined(__INTEL_COMPILER) \
|
||||
|| defined(__xlC__)
|
||||
#define Z7_NO_INLINE __attribute__((noinline))
|
||||
#define Z7_FORCE_INLINE __attribute__((always_inline)) inline
|
||||
#else
|
||||
#define Z7_NO_INLINE
|
||||
#define Z7_FORCE_INLINE
|
||||
#endif
|
||||
|
||||
#define Z7_CDECL
|
||||
|
||||
#if defined(_M_IX86) \
|
||||
|| defined(__i386__)
|
||||
// #define Z7_FASTCALL __attribute__((fastcall))
|
||||
// #define Z7_FASTCALL __attribute__((cdecl))
|
||||
#define Z7_FASTCALL
|
||||
#elif defined(MY_CPU_AMD64)
|
||||
// #define Z7_FASTCALL __attribute__((ms_abi))
|
||||
#define Z7_FASTCALL
|
||||
#else
|
||||
#define Z7_FASTCALL
|
||||
#endif
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */
|
||||
|
||||
// #define Z7_C_IFACE_CONST_QUAL
|
||||
#define Z7_C_IFACE_CONST_QUAL const
|
||||
|
||||
#define Z7_C_IFACE_DECL(a) \
|
||||
struct a ## _; \
|
||||
typedef Z7_C_IFACE_CONST_QUAL struct a ## _ * a ## Ptr; \
|
||||
typedef struct a ## _ a; \
|
||||
struct a ## _
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (IByteIn)
|
||||
{
|
||||
Byte (*Read)(IByteInPtr p); /* reads one byte, returns 0 in case of EOF or error */
|
||||
};
|
||||
#define IByteIn_Read(p) (p)->Read(p)
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (IByteOut)
|
||||
{
|
||||
void (*Write)(IByteOutPtr p, Byte b);
|
||||
};
|
||||
#define IByteOut_Write(p, b) (p)->Write(p, b)
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (ISeqInStream)
|
||||
{
|
||||
SRes (*Read)(ISeqInStreamPtr p, void *buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
};
|
||||
#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
||||
|
||||
/* try to read as much as avail in stream and limited by (*processedSize) */
|
||||
SRes SeqInStream_ReadMax(ISeqInStreamPtr stream, void *buf, size_t *processedSize);
|
||||
/* it can return SZ_ERROR_INPUT_EOF */
|
||||
// SRes SeqInStream_Read(ISeqInStreamPtr stream, void *buf, size_t size);
|
||||
// SRes SeqInStream_Read2(ISeqInStreamPtr stream, void *buf, size_t size, SRes errorType);
|
||||
SRes SeqInStream_ReadByte(ISeqInStreamPtr stream, Byte *buf);
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (ISeqOutStream)
|
||||
{
|
||||
size_t (*Write)(ISeqOutStreamPtr p, const void *buf, size_t size);
|
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */
|
||||
};
|
||||
#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SZ_SEEK_SET = 0,
|
||||
SZ_SEEK_CUR = 1,
|
||||
SZ_SEEK_END = 2
|
||||
} ESzSeek;
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (ISeekInStream)
|
||||
{
|
||||
SRes (*Read)(ISeekInStreamPtr p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||
SRes (*Seek)(ISeekInStreamPtr p, Int64 *pos, ESzSeek origin);
|
||||
};
|
||||
#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
||||
#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (ILookInStream)
|
||||
{
|
||||
SRes (*Look)(ILookInStreamPtr p, const void **buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
SRes (*Skip)(ILookInStreamPtr p, size_t offset);
|
||||
/* offset must be <= output(*size) of Look */
|
||||
SRes (*Read)(ILookInStreamPtr p, void *buf, size_t *size);
|
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||
SRes (*Seek)(ILookInStreamPtr p, Int64 *pos, ESzSeek origin);
|
||||
};
|
||||
|
||||
#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
|
||||
#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
|
||||
#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
||||
#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
|
||||
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStreamPtr stream, void *buf, size_t *size);
|
||||
SRes LookInStream_SeekTo(ILookInStreamPtr stream, UInt64 offset);
|
||||
|
||||
/* reads via ILookInStream::Read */
|
||||
SRes LookInStream_Read2(ILookInStreamPtr stream, void *buf, size_t size, SRes errorType);
|
||||
SRes LookInStream_Read(ILookInStreamPtr stream, void *buf, size_t size);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ILookInStream vt;
|
||||
ISeekInStreamPtr realStream;
|
||||
|
||||
size_t pos;
|
||||
size_t size; /* it's data size */
|
||||
|
||||
/* the following variables must be set outside */
|
||||
Byte *buf;
|
||||
size_t bufSize;
|
||||
} CLookToRead2;
|
||||
|
||||
void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
|
||||
|
||||
#define LookToRead2_INIT(p) { (p)->pos = (p)->size = 0; }
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream vt;
|
||||
ILookInStreamPtr realStream;
|
||||
} CSecToLook;
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p);
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream vt;
|
||||
ILookInStreamPtr realStream;
|
||||
} CSecToRead;
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p);
|
||||
|
||||
|
||||
Z7_C_IFACE_DECL (ICompressProgress)
|
||||
{
|
||||
SRes (*Progress)(ICompressProgressPtr p, UInt64 inSize, UInt64 outSize);
|
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */
|
||||
};
|
||||
|
||||
#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
|
||||
|
||||
|
||||
|
||||
typedef struct ISzAlloc ISzAlloc;
|
||||
typedef const ISzAlloc * ISzAllocPtr;
|
||||
|
||||
struct ISzAlloc
|
||||
{
|
||||
void *(*Alloc)(ISzAllocPtr p, size_t size);
|
||||
void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
|
||||
};
|
||||
|
||||
#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
|
||||
#define ISzAlloc_Free(p, a) (p)->Free(p, a)
|
||||
|
||||
/* deprecated */
|
||||
#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
|
||||
#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef MY_offsetof
|
||||
#ifdef offsetof
|
||||
#define MY_offsetof(type, m) offsetof(type, m)
|
||||
/*
|
||||
#define MY_offsetof(type, m) FIELD_OFFSET(type, m)
|
||||
*/
|
||||
#else
|
||||
#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef Z7_container_of
|
||||
|
||||
/*
|
||||
#define Z7_container_of(ptr, type, m) container_of(ptr, type, m)
|
||||
#define Z7_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
|
||||
#define Z7_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
|
||||
#define Z7_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
|
||||
*/
|
||||
|
||||
/*
|
||||
GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
|
||||
GCC 3.4.4 : classes with constructor
|
||||
GCC 4.8.1 : classes with non-public variable members"
|
||||
*/
|
||||
|
||||
#define Z7_container_of(ptr, type, m) \
|
||||
((type *)(void *)((char *)(void *) \
|
||||
(1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
|
||||
|
||||
#define Z7_container_of_CONST(ptr, type, m) \
|
||||
((const type *)(const void *)((const char *)(const void *) \
|
||||
(1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
|
||||
|
||||
/*
|
||||
#define Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m) \
|
||||
((type *)(void *)(const void *)((const char *)(const void *) \
|
||||
(1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
#define Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
|
||||
|
||||
// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
|
||||
#define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of(ptr, type, m)
|
||||
// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m)
|
||||
|
||||
#define Z7_CONTAINER_FROM_VTBL_CONST(ptr, type, m) Z7_container_of_CONST(ptr, type, m)
|
||||
|
||||
#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
|
||||
/*
|
||||
#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL(ptr, type, m)
|
||||
*/
|
||||
#if defined (__clang__) || defined(__GNUC__)
|
||||
#define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
|
||||
#define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
#define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL
|
||||
#define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL
|
||||
#endif
|
||||
|
||||
#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(ptr, type, m, p) \
|
||||
Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \
|
||||
type *p = Z7_CONTAINER_FROM_VTBL(ptr, type, m); \
|
||||
Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL
|
||||
|
||||
#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(type) \
|
||||
Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(pp, type, vt, p)
|
||||
|
||||
|
||||
// #define ZIP7_DECLARE_HANDLE(name) typedef void *name;
|
||||
#define Z7_DECLARE_HANDLE(name) struct name##_dummy{int unused;}; typedef struct name##_dummy *name;
|
||||
|
||||
|
||||
#define Z7_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
|
||||
|
||||
#ifndef Z7_ARRAY_SIZE
|
||||
#define Z7_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define CHAR_PATH_SEPARATOR '\\'
|
||||
#define WCHAR_PATH_SEPARATOR L'\\'
|
||||
#define STRING_PATH_SEPARATOR "\\"
|
||||
#define WSTRING_PATH_SEPARATOR L"\\"
|
||||
|
||||
#else
|
||||
|
||||
#define CHAR_PATH_SEPARATOR '/'
|
||||
#define WCHAR_PATH_SEPARATOR L'/'
|
||||
#define STRING_PATH_SEPARATOR "/"
|
||||
#define WSTRING_PATH_SEPARATOR L"/"
|
||||
|
||||
#endif
|
||||
|
||||
#define k_PropVar_TimePrec_0 0
|
||||
#define k_PropVar_TimePrec_Unix 1
|
||||
#define k_PropVar_TimePrec_DOS 2
|
||||
#define k_PropVar_TimePrec_HighPrec 3
|
||||
#define k_PropVar_TimePrec_Base 16
|
||||
#define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7)
|
||||
#define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9)
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef Z7_ST
|
||||
#ifdef _7ZIP_ST
|
||||
#define Z7_ST
|
||||
#endif
|
||||
#endif
|
||||
*/
|
|
@ -1,7 +1,27 @@
|
|||
#define MY_VER_MAJOR 9
|
||||
#define MY_VER_MINOR 20
|
||||
#define MY_VER_MAJOR 24
|
||||
#define MY_VER_MINOR 9
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION "9.20"
|
||||
#define MY_DATE "2010-11-18"
|
||||
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
|
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
|
||||
#define MY_VERSION_NUMBERS "24.09"
|
||||
#define MY_VERSION MY_VERSION_NUMBERS
|
||||
|
||||
#ifdef MY_CPU_NAME
|
||||
#define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")"
|
||||
#else
|
||||
#define MY_VERSION_CPU MY_VERSION
|
||||
#endif
|
||||
|
||||
#define MY_DATE "2024-11-29"
|
||||
#undef MY_COPYRIGHT
|
||||
#undef MY_VERSION_COPYRIGHT_DATE
|
||||
#define MY_AUTHOR_NAME "Igor Pavlov"
|
||||
#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
|
||||
#define MY_COPYRIGHT_CR "Copyright (c) 1999-2024 Igor Pavlov"
|
||||
|
||||
#ifdef USE_COPYRIGHT_CR
|
||||
#define MY_COPYRIGHT MY_COPYRIGHT_CR
|
||||
#else
|
||||
#define MY_COPYRIGHT MY_COPYRIGHT_PD
|
||||
#endif
|
||||
|
||||
#define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE
|
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE
|
||||
|
|
101
common/LZMA/SDK/C/7zWindows.h
Normal file
101
common/LZMA/SDK/C/7zWindows.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* 7zWindows.h -- StdAfx
|
||||
2023-04-02 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef ZIP7_INC_7Z_WINDOWS_H
|
||||
#define ZIP7_INC_7Z_WINDOWS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4668) // '_WIN32_WINNT' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
|
||||
|
||||
#if _MSC_VER == 1900
|
||||
// for old kit10 versions
|
||||
// #pragma warning(disable : 4255) // winuser.h(13979): warning C4255: 'GetThreadDpiAwarenessContext':
|
||||
#endif
|
||||
// win10 Windows Kit:
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64)
|
||||
// for msvc6 without sdk2003
|
||||
#define RPC_NO_WINDOWS_H
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||
// #if defined(__GNUC__) && !defined(__clang__)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
// #include <basetsd.h>
|
||||
// #include <wtypes.h>
|
||||
|
||||
// but if precompiled with clang-cl then we need
|
||||
// #include <windows.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64)
|
||||
#ifndef _W64
|
||||
|
||||
typedef long LONG_PTR, *PLONG_PTR;
|
||||
typedef unsigned long ULONG_PTR, *PULONG_PTR;
|
||||
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
|
||||
|
||||
#define Z7_OLD_WIN_SDK
|
||||
#endif // _W64
|
||||
#endif // _MSC_VER == 1200
|
||||
|
||||
#ifdef Z7_OLD_WIN_SDK
|
||||
|
||||
#ifndef INVALID_FILE_ATTRIBUTES
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
||||
#endif
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
#ifndef FILE_SPECIAL_ACCESS
|
||||
#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
|
||||
#endif
|
||||
|
||||
// ShlObj.h:
|
||||
// #define BIF_NEWDIALOGSTYLE 0x0040
|
||||
|
||||
#pragma warning(disable : 4201)
|
||||
// #pragma warning(disable : 4115)
|
||||
|
||||
#undef VARIANT_TRUE
|
||||
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
|
||||
#endif
|
||||
|
||||
#endif // Z7_OLD_WIN_SDK
|
||||
|
||||
#ifdef UNDER_CE
|
||||
#undef VARIANT_TRUE
|
||||
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if _MSC_VER >= 1400 && _MSC_VER <= 1600
|
||||
// BaseTsd.h(148) : 'HandleToULong' : unreferenced inline function has been removed
|
||||
// string.h
|
||||
// #pragma warning(disable : 4514)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* #include "7zTypes.h" */
|
||||
|
||||
#endif
|
709
common/LZMA/SDK/C/Bra.c
Normal file
709
common/LZMA/SDK/C/Bra.c
Normal file
|
@ -0,0 +1,709 @@
|
|||
/* Bra.c -- Branch converters for RISC code
|
||||
2024-01-20 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "Bra.h"
|
||||
#include "RotateDefs.h"
|
||||
#include "CpuArch.h"
|
||||
|
||||
#if defined(MY_CPU_SIZEOF_POINTER) \
|
||||
&& ( MY_CPU_SIZEOF_POINTER == 4 \
|
||||
|| MY_CPU_SIZEOF_POINTER == 8)
|
||||
#define BR_CONV_USE_OPT_PC_PTR
|
||||
#endif
|
||||
|
||||
#ifdef BR_CONV_USE_OPT_PC_PTR
|
||||
#define BR_PC_INIT pc -= (UInt32)(SizeT)p;
|
||||
#define BR_PC_GET (pc + (UInt32)(SizeT)p)
|
||||
#else
|
||||
#define BR_PC_INIT pc += (UInt32)size;
|
||||
#define BR_PC_GET (pc - (UInt32)(SizeT)(lim - p))
|
||||
// #define BR_PC_INIT
|
||||
// #define BR_PC_GET (pc + (UInt32)(SizeT)(p - data))
|
||||
#endif
|
||||
|
||||
#define BR_CONVERT_VAL(v, c) if (encoding) v += c; else v -= c;
|
||||
// #define BR_CONVERT_VAL(v, c) if (!encoding) c = (UInt32)0 - c; v += c;
|
||||
|
||||
#define Z7_BRANCH_CONV(name) z7_ ## name
|
||||
|
||||
#define Z7_BRANCH_FUNC_MAIN(name) \
|
||||
static \
|
||||
Z7_FORCE_INLINE \
|
||||
Z7_ATTRIB_NO_VECTOR \
|
||||
Byte *Z7_BRANCH_CONV(name)(Byte *p, SizeT size, UInt32 pc, int encoding)
|
||||
|
||||
#define Z7_BRANCH_FUNC_IMP(name, m, encoding) \
|
||||
Z7_NO_INLINE \
|
||||
Z7_ATTRIB_NO_VECTOR \
|
||||
Byte *m(name)(Byte *data, SizeT size, UInt32 pc) \
|
||||
{ return Z7_BRANCH_CONV(name)(data, size, pc, encoding); } \
|
||||
|
||||
#ifdef Z7_EXTRACT_ONLY
|
||||
#define Z7_BRANCH_FUNCS_IMP(name) \
|
||||
Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_DEC_2, 0)
|
||||
#else
|
||||
#define Z7_BRANCH_FUNCS_IMP(name) \
|
||||
Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_DEC_2, 0) \
|
||||
Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_ENC_2, 1)
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#define BR_EXTERNAL_FOR
|
||||
#define BR_NEXT_ITERATION continue;
|
||||
#else
|
||||
#define BR_EXTERNAL_FOR for (;;)
|
||||
#define BR_NEXT_ITERATION break;
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && (__clang_major__ >= 8) \
|
||||
|| defined(__GNUC__) && (__GNUC__ >= 1000) \
|
||||
// GCC is not good for __builtin_expect() here
|
||||
/* || defined(_MSC_VER) && (_MSC_VER >= 1920) */
|
||||
// #define Z7_unlikely [[unlikely]]
|
||||
// #define Z7_LIKELY(x) (__builtin_expect((x), 1))
|
||||
#define Z7_UNLIKELY(x) (__builtin_expect((x), 0))
|
||||
// #define Z7_likely [[likely]]
|
||||
#else
|
||||
// #define Z7_LIKELY(x) (x)
|
||||
#define Z7_UNLIKELY(x) (x)
|
||||
// #define Z7_likely
|
||||
#endif
|
||||
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_ARM64)
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim;
|
||||
const UInt32 flag = (UInt32)1 << (24 - 4);
|
||||
const UInt32 mask = ((UInt32)1 << 24) - (flag << 1);
|
||||
size &= ~(SizeT)3;
|
||||
// if (size == 0) return p;
|
||||
lim = p + size;
|
||||
BR_PC_INIT
|
||||
pc -= 4; // because (p) will point to next instruction
|
||||
|
||||
BR_EXTERNAL_FOR
|
||||
{
|
||||
// Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
|
||||
for (;;)
|
||||
{
|
||||
UInt32 v;
|
||||
if Z7_UNLIKELY(p == lim)
|
||||
return p;
|
||||
v = GetUi32a(p);
|
||||
p += 4;
|
||||
if Z7_UNLIKELY(((v - 0x94000000) & 0xfc000000) == 0)
|
||||
{
|
||||
UInt32 c = BR_PC_GET >> 2;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
v &= 0x03ffffff;
|
||||
v |= 0x94000000;
|
||||
SetUi32a(p - 4, v)
|
||||
BR_NEXT_ITERATION
|
||||
}
|
||||
// v = rotlFixed(v, 8); v += (flag << 8) - 0x90; if Z7_UNLIKELY((v & ((mask << 8) + 0x9f)) == 0)
|
||||
v -= 0x90000000; if Z7_UNLIKELY((v & 0x9f000000) == 0)
|
||||
{
|
||||
UInt32 z, c;
|
||||
// v = rotrFixed(v, 8);
|
||||
v += flag; if Z7_UNLIKELY(v & mask) continue;
|
||||
z = (v & 0xffffffe0) | (v >> 26);
|
||||
c = (BR_PC_GET >> (12 - 3)) & ~(UInt32)7;
|
||||
BR_CONVERT_VAL(z, c)
|
||||
v &= 0x1f;
|
||||
v |= 0x90000000;
|
||||
v |= z << 26;
|
||||
v |= 0x00ffffe0 & ((z & (((flag << 1) - 1))) - flag);
|
||||
SetUi32a(p - 4, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_ARM64)
|
||||
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_ARM)
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim;
|
||||
size &= ~(SizeT)3;
|
||||
lim = p + size;
|
||||
BR_PC_INIT
|
||||
/* in ARM: branch offset is relative to the +2 instructions from current instruction.
|
||||
(p) will point to next instruction */
|
||||
pc += 8 - 4;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if Z7_UNLIKELY(p >= lim) { return p; } p += 4; if Z7_UNLIKELY(p[-1] == 0xeb) break;
|
||||
if Z7_UNLIKELY(p >= lim) { return p; } p += 4; if Z7_UNLIKELY(p[-1] == 0xeb) break;
|
||||
}
|
||||
{
|
||||
UInt32 v = GetUi32a(p - 4);
|
||||
UInt32 c = BR_PC_GET >> 2;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
v &= 0x00ffffff;
|
||||
v |= 0xeb000000;
|
||||
SetUi32a(p - 4, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_ARM)
|
||||
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_PPC)
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim;
|
||||
size &= ~(SizeT)3;
|
||||
lim = p + size;
|
||||
BR_PC_INIT
|
||||
pc -= 4; // because (p) will point to next instruction
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 v;
|
||||
for (;;)
|
||||
{
|
||||
if Z7_UNLIKELY(p == lim)
|
||||
return p;
|
||||
// v = GetBe32a(p);
|
||||
v = *(UInt32 *)(void *)p;
|
||||
p += 4;
|
||||
// if ((v & 0xfc000003) == 0x48000001) break;
|
||||
// if ((p[-4] & 0xFC) == 0x48 && (p[-1] & 3) == 1) break;
|
||||
if Z7_UNLIKELY(
|
||||
((v - Z7_CONV_BE_TO_NATIVE_CONST32(0x48000001))
|
||||
& Z7_CONV_BE_TO_NATIVE_CONST32(0xfc000003)) == 0) break;
|
||||
}
|
||||
{
|
||||
v = Z7_CONV_NATIVE_TO_BE_32(v);
|
||||
{
|
||||
UInt32 c = BR_PC_GET;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
}
|
||||
v &= 0x03ffffff;
|
||||
v |= 0x48000000;
|
||||
SetBe32a(p - 4, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_PPC)
|
||||
|
||||
|
||||
#ifdef Z7_CPU_FAST_ROTATE_SUPPORTED
|
||||
#define BR_SPARC_USE_ROTATE
|
||||
#endif
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_SPARC)
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim;
|
||||
const UInt32 flag = (UInt32)1 << 22;
|
||||
size &= ~(SizeT)3;
|
||||
lim = p + size;
|
||||
BR_PC_INIT
|
||||
pc -= 4; // because (p) will point to next instruction
|
||||
for (;;)
|
||||
{
|
||||
UInt32 v;
|
||||
for (;;)
|
||||
{
|
||||
if Z7_UNLIKELY(p == lim)
|
||||
return p;
|
||||
/* // the code without GetBe32a():
|
||||
{ const UInt32 v = GetUi16a(p) & 0xc0ff; p += 4; if (v == 0x40 || v == 0xc07f) break; }
|
||||
*/
|
||||
v = GetBe32a(p);
|
||||
p += 4;
|
||||
#ifdef BR_SPARC_USE_ROTATE
|
||||
v = rotlFixed(v, 2);
|
||||
v += (flag << 2) - 1;
|
||||
if Z7_UNLIKELY((v & (3 - (flag << 3))) == 0)
|
||||
#else
|
||||
v += (UInt32)5 << 29;
|
||||
v ^= (UInt32)7 << 29;
|
||||
v += flag;
|
||||
if Z7_UNLIKELY((v & (0 - (flag << 1))) == 0)
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
{
|
||||
// UInt32 v = GetBe32a(p - 4);
|
||||
#ifndef BR_SPARC_USE_ROTATE
|
||||
v <<= 2;
|
||||
#endif
|
||||
{
|
||||
UInt32 c = BR_PC_GET;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
}
|
||||
v &= (flag << 3) - 1;
|
||||
#ifdef BR_SPARC_USE_ROTATE
|
||||
v -= (flag << 2) - 1;
|
||||
v = rotrFixed(v, 2);
|
||||
#else
|
||||
v -= (flag << 2);
|
||||
v >>= 2;
|
||||
v |= (UInt32)1 << 30;
|
||||
#endif
|
||||
SetBe32a(p - 4, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_SPARC)
|
||||
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_ARMT)
|
||||
{
|
||||
// Byte *p = data;
|
||||
Byte *lim;
|
||||
size &= ~(SizeT)1;
|
||||
// if (size == 0) return p;
|
||||
if (size <= 2) return p;
|
||||
size -= 2;
|
||||
lim = p + size;
|
||||
BR_PC_INIT
|
||||
/* in ARM: branch offset is relative to the +2 instructions from current instruction.
|
||||
(p) will point to the +2 instructions from current instruction */
|
||||
// pc += 4 - 4;
|
||||
// if (encoding) pc -= 0xf800 << 1; else pc += 0xf800 << 1;
|
||||
// #define ARMT_TAIL_PROC { goto armt_tail; }
|
||||
#define ARMT_TAIL_PROC { return p; }
|
||||
|
||||
do
|
||||
{
|
||||
/* in MSVC 32-bit x86 compilers:
|
||||
UInt32 version : it loads value from memory with movzx
|
||||
Byte version : it loads value to 8-bit register (AL/CL)
|
||||
movzx version is slightly faster in some cpus
|
||||
*/
|
||||
unsigned b1;
|
||||
// Byte / unsigned
|
||||
b1 = p[1];
|
||||
// optimized version to reduce one (p >= lim) check:
|
||||
// unsigned a1 = p[1]; b1 = p[3]; p += 2; if Z7_LIKELY((b1 & (a1 ^ 8)) < 0xf8)
|
||||
for (;;)
|
||||
{
|
||||
unsigned b3; // Byte / UInt32
|
||||
/* (Byte)(b3) normalization can use low byte computations in MSVC.
|
||||
It gives smaller code, and no loss of speed in some compilers/cpus.
|
||||
But new MSVC 32-bit x86 compilers use more slow load
|
||||
from memory to low byte register in that case.
|
||||
So we try to use full 32-bit computations for faster code.
|
||||
*/
|
||||
// if (p >= lim) { ARMT_TAIL_PROC } b3 = b1 + 8; b1 = p[3]; p += 2; if ((b3 & b1) >= 0xf8) break;
|
||||
if Z7_UNLIKELY(p >= lim) { ARMT_TAIL_PROC } b3 = p[3]; p += 2; if Z7_UNLIKELY((b3 & (b1 ^ 8)) >= 0xf8) break;
|
||||
if Z7_UNLIKELY(p >= lim) { ARMT_TAIL_PROC } b1 = p[3]; p += 2; if Z7_UNLIKELY((b1 & (b3 ^ 8)) >= 0xf8) break;
|
||||
}
|
||||
{
|
||||
/* we can adjust pc for (0xf800) to rid of (& 0x7FF) operation.
|
||||
But gcc/clang for arm64 can use bfi instruction for full code here */
|
||||
UInt32 v =
|
||||
((UInt32)GetUi16a(p - 2) << 11) |
|
||||
((UInt32)GetUi16a(p) & 0x7FF);
|
||||
/*
|
||||
UInt32 v =
|
||||
((UInt32)p[1 - 2] << 19)
|
||||
+ (((UInt32)p[1] & 0x7) << 8)
|
||||
+ (((UInt32)p[-2] << 11))
|
||||
+ (p[0]);
|
||||
*/
|
||||
p += 2;
|
||||
{
|
||||
UInt32 c = BR_PC_GET >> 1;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
}
|
||||
SetUi16a(p - 4, (UInt16)(((v >> 11) & 0x7ff) | 0xf000))
|
||||
SetUi16a(p - 2, (UInt16)(v | 0xf800))
|
||||
/*
|
||||
p[-4] = (Byte)(v >> 11);
|
||||
p[-3] = (Byte)(0xf0 | ((v >> 19) & 0x7));
|
||||
p[-2] = (Byte)v;
|
||||
p[-1] = (Byte)(0xf8 | (v >> 8));
|
||||
*/
|
||||
}
|
||||
}
|
||||
while (p < lim);
|
||||
return p;
|
||||
// armt_tail:
|
||||
// if ((Byte)((lim[1] & 0xf8)) != 0xf0) { lim += 2; } return lim;
|
||||
// return (Byte *)(lim + ((Byte)((lim[1] ^ 0xf0) & 0xf8) == 0 ? 0 : 2));
|
||||
// return (Byte *)(lim + (((lim[1] ^ ~0xfu) & ~7u) == 0 ? 0 : 2));
|
||||
// return (Byte *)(lim + 2 - (((((unsigned)lim[1] ^ 8) + 8) >> 7) & 2));
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_ARMT)
|
||||
|
||||
|
||||
// #define BR_IA64_NO_INLINE
|
||||
|
||||
Z7_BRANCH_FUNC_MAIN(BranchConv_IA64)
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim;
|
||||
size &= ~(SizeT)15;
|
||||
lim = p + size;
|
||||
pc -= 1 << 4;
|
||||
pc >>= 4 - 1;
|
||||
// pc -= 1 << 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned m;
|
||||
for (;;)
|
||||
{
|
||||
if Z7_UNLIKELY(p == lim)
|
||||
return p;
|
||||
m = (unsigned)((UInt32)0x334b0000 >> (*p & 0x1e));
|
||||
p += 16;
|
||||
pc += 1 << 1;
|
||||
if (m &= 3)
|
||||
break;
|
||||
}
|
||||
{
|
||||
p += (ptrdiff_t)m * 5 - 20; // negative value is expected here.
|
||||
do
|
||||
{
|
||||
const UInt32 t =
|
||||
#if defined(MY_CPU_X86_OR_AMD64)
|
||||
// we use 32-bit load here to reduce code size on x86:
|
||||
GetUi32(p);
|
||||
#else
|
||||
GetUi16(p);
|
||||
#endif
|
||||
UInt32 z = GetUi32(p + 1) >> m;
|
||||
p += 5;
|
||||
if (((t >> m) & (0x70 << 1)) == 0
|
||||
&& ((z - (0x5000000 << 1)) & (0xf000000 << 1)) == 0)
|
||||
{
|
||||
UInt32 v = (UInt32)((0x8fffff << 1) | 1) & z;
|
||||
z ^= v;
|
||||
#ifdef BR_IA64_NO_INLINE
|
||||
v |= (v & ((UInt32)1 << (23 + 1))) >> 3;
|
||||
{
|
||||
UInt32 c = pc;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
}
|
||||
v &= (0x1fffff << 1) | 1;
|
||||
#else
|
||||
{
|
||||
if (encoding)
|
||||
{
|
||||
// pc &= ~(0xc00000 << 1); // we just need to clear at least 2 bits
|
||||
pc &= (0x1fffff << 1) | 1;
|
||||
v += pc;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pc |= 0xc00000 << 1; // we need to set at least 2 bits
|
||||
pc |= ~(UInt32)((0x1fffff << 1) | 1);
|
||||
v -= pc;
|
||||
}
|
||||
}
|
||||
v &= ~(UInt32)(0x600000 << 1);
|
||||
#endif
|
||||
v += (0x700000 << 1);
|
||||
v &= (0x8fffff << 1) | 1;
|
||||
z |= v;
|
||||
z <<= m;
|
||||
SetUi32(p + 1 - 5, z)
|
||||
}
|
||||
m++;
|
||||
}
|
||||
while (m &= 3); // while (m < 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
Z7_BRANCH_FUNCS_IMP(BranchConv_IA64)
|
||||
|
||||
|
||||
#define BR_CONVERT_VAL_ENC(v) v += BR_PC_GET;
|
||||
#define BR_CONVERT_VAL_DEC(v) v -= BR_PC_GET;
|
||||
|
||||
#if 1 && defined(MY_CPU_LE_UNALIGN)
|
||||
#define RISCV_USE_UNALIGNED_LOAD
|
||||
#endif
|
||||
|
||||
#ifdef RISCV_USE_UNALIGNED_LOAD
|
||||
#define RISCV_GET_UI32(p) GetUi32(p)
|
||||
#define RISCV_SET_UI32(p, v) { SetUi32(p, v) }
|
||||
#else
|
||||
#define RISCV_GET_UI32(p) \
|
||||
((UInt32)GetUi16a(p) + \
|
||||
((UInt32)GetUi16a((p) + 2) << 16))
|
||||
#define RISCV_SET_UI32(p, v) { \
|
||||
SetUi16a(p, (UInt16)(v)) \
|
||||
SetUi16a((p) + 2, (UInt16)(v >> 16)) }
|
||||
#endif
|
||||
|
||||
#if 1 && defined(MY_CPU_LE)
|
||||
#define RISCV_USE_16BIT_LOAD
|
||||
#endif
|
||||
|
||||
#ifdef RISCV_USE_16BIT_LOAD
|
||||
#define RISCV_LOAD_VAL(p) GetUi16a(p)
|
||||
#else
|
||||
#define RISCV_LOAD_VAL(p) (*(p))
|
||||
#endif
|
||||
|
||||
#define RISCV_INSTR_SIZE 2
|
||||
#define RISCV_STEP_1 (4 + RISCV_INSTR_SIZE)
|
||||
#define RISCV_STEP_2 4
|
||||
#define RISCV_REG_VAL (2 << 7)
|
||||
#define RISCV_CMD_VAL 3
|
||||
#if 1
|
||||
// for code size optimization:
|
||||
#define RISCV_DELTA_7F 0x7f
|
||||
#else
|
||||
#define RISCV_DELTA_7F 0
|
||||
#endif
|
||||
|
||||
#define RISCV_CHECK_1(v, b) \
|
||||
(((((b) - RISCV_CMD_VAL) ^ ((v) << 8)) & (0xf8000 + RISCV_CMD_VAL)) == 0)
|
||||
|
||||
#if 1
|
||||
#define RISCV_CHECK_2(v, r) \
|
||||
((((v) - ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL | 8)) \
|
||||
<< 18) \
|
||||
< ((r) & 0x1d))
|
||||
#else
|
||||
// this branch gives larger code, because
|
||||
// compilers generate larger code for big constants.
|
||||
#define RISCV_CHECK_2(v, r) \
|
||||
((((v) - ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL)) \
|
||||
& ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL)) \
|
||||
< ((r) & 0x1d))
|
||||
#endif
|
||||
|
||||
|
||||
#define RISCV_SCAN_LOOP \
|
||||
Byte *lim; \
|
||||
size &= ~(SizeT)(RISCV_INSTR_SIZE - 1); \
|
||||
if (size <= 6) return p; \
|
||||
size -= 6; \
|
||||
lim = p + size; \
|
||||
BR_PC_INIT \
|
||||
for (;;) \
|
||||
{ \
|
||||
UInt32 a, v; \
|
||||
/* Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE */ \
|
||||
for (;;) \
|
||||
{ \
|
||||
if Z7_UNLIKELY(p >= lim) { return p; } \
|
||||
a = (RISCV_LOAD_VAL(p) ^ 0x10u) + 1; \
|
||||
if ((a & 0x77) == 0) break; \
|
||||
a = (RISCV_LOAD_VAL(p + RISCV_INSTR_SIZE) ^ 0x10u) + 1; \
|
||||
p += RISCV_INSTR_SIZE * 2; \
|
||||
if ((a & 0x77) == 0) \
|
||||
{ \
|
||||
p -= RISCV_INSTR_SIZE; \
|
||||
if Z7_UNLIKELY(p >= lim) { return p; } \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
// (xx6f ^ 10) + 1 = xx7f + 1 = xx80 : JAL
|
||||
// (xxef ^ 10) + 1 = xxff + 1 = xx00 + 100 : JAL
|
||||
// (xx17 ^ 10) + 1 = xx07 + 1 = xx08 : AUIPC
|
||||
// (xx97 ^ 10) + 1 = xx87 + 1 = xx88 : AUIPC
|
||||
|
||||
Byte * Z7_BRANCH_CONV_ENC(RISCV)(Byte *p, SizeT size, UInt32 pc)
|
||||
{
|
||||
RISCV_SCAN_LOOP
|
||||
v = a;
|
||||
a = RISCV_GET_UI32(p);
|
||||
#ifndef RISCV_USE_16BIT_LOAD
|
||||
v += (UInt32)p[1] << 8;
|
||||
#endif
|
||||
|
||||
if ((v & 8) == 0) // JAL
|
||||
{
|
||||
if ((v - (0x100 /* - RISCV_DELTA_7F */)) & 0xd80)
|
||||
{
|
||||
p += RISCV_INSTR_SIZE;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
v = ((a & 1u << 31) >> 11)
|
||||
| ((a & 0x3ff << 21) >> 20)
|
||||
| ((a & 1 << 20) >> 9)
|
||||
| (a & 0xff << 12);
|
||||
BR_CONVERT_VAL_ENC(v)
|
||||
// ((v & 1) == 0)
|
||||
// v: bits [1 : 20] contain offset bits
|
||||
#if 0 && defined(RISCV_USE_UNALIGNED_LOAD)
|
||||
a &= 0xfff;
|
||||
a |= ((UInt32)(v << 23))
|
||||
| ((UInt32)(v << 7) & ((UInt32)0xff << 16))
|
||||
| ((UInt32)(v >> 5) & ((UInt32)0xf0 << 8));
|
||||
RISCV_SET_UI32(p, a)
|
||||
#else // aligned
|
||||
#if 0
|
||||
SetUi16a(p, (UInt16)(((v >> 5) & 0xf000) | (a & 0xfff)))
|
||||
#else
|
||||
p[1] = (Byte)(((v >> 13) & 0xf0) | ((a >> 8) & 0xf));
|
||||
#endif
|
||||
|
||||
#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
|
||||
v <<= 15;
|
||||
v = Z7_BSWAP32(v);
|
||||
SetUi16a(p + 2, (UInt16)v)
|
||||
#else
|
||||
p[2] = (Byte)(v >> 9);
|
||||
p[3] = (Byte)(v >> 1);
|
||||
#endif
|
||||
#endif // aligned
|
||||
}
|
||||
p += 4;
|
||||
continue;
|
||||
} // JAL
|
||||
|
||||
{
|
||||
// AUIPC
|
||||
if (v & 0xe80) // (not x0) and (not x2)
|
||||
{
|
||||
const UInt32 b = RISCV_GET_UI32(p + 4);
|
||||
if (RISCV_CHECK_1(v, b))
|
||||
{
|
||||
{
|
||||
const UInt32 temp = (b << 12) | (0x17 + RISCV_REG_VAL);
|
||||
RISCV_SET_UI32(p, temp)
|
||||
}
|
||||
a &= 0xfffff000;
|
||||
{
|
||||
#if 1
|
||||
const int t = -1 >> 1;
|
||||
if (t != -1)
|
||||
a += (b >> 20) - ((b >> 19) & 0x1000); // arithmetic right shift emulation
|
||||
else
|
||||
#endif
|
||||
a += (UInt32)((Int32)b >> 20); // arithmetic right shift (sign-extension).
|
||||
}
|
||||
BR_CONVERT_VAL_ENC(a)
|
||||
#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
|
||||
a = Z7_BSWAP32(a);
|
||||
RISCV_SET_UI32(p + 4, a)
|
||||
#else
|
||||
SetBe32(p + 4, a)
|
||||
#endif
|
||||
p += 8;
|
||||
}
|
||||
else
|
||||
p += RISCV_STEP_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 r = a >> 27;
|
||||
if (RISCV_CHECK_2(v, r))
|
||||
{
|
||||
v = RISCV_GET_UI32(p + 4);
|
||||
r = (r << 7) + 0x17 + (v & 0xfffff000);
|
||||
a = (a >> 12) | (v << 20);
|
||||
RISCV_SET_UI32(p, r)
|
||||
RISCV_SET_UI32(p + 4, a)
|
||||
p += 8;
|
||||
}
|
||||
else
|
||||
p += RISCV_STEP_2;
|
||||
}
|
||||
}
|
||||
} // for
|
||||
}
|
||||
|
||||
|
||||
Byte * Z7_BRANCH_CONV_DEC(RISCV)(Byte *p, SizeT size, UInt32 pc)
|
||||
{
|
||||
RISCV_SCAN_LOOP
|
||||
#ifdef RISCV_USE_16BIT_LOAD
|
||||
if ((a & 8) == 0)
|
||||
{
|
||||
#else
|
||||
v = a;
|
||||
a += (UInt32)p[1] << 8;
|
||||
if ((v & 8) == 0)
|
||||
{
|
||||
#endif
|
||||
// JAL
|
||||
a -= 0x100 - RISCV_DELTA_7F;
|
||||
if (a & 0xd80)
|
||||
{
|
||||
p += RISCV_INSTR_SIZE;
|
||||
continue;
|
||||
}
|
||||
{
|
||||
const UInt32 a_old = (a + (0xef - RISCV_DELTA_7F)) & 0xfff;
|
||||
#if 0 // unaligned
|
||||
a = GetUi32(p);
|
||||
v = (UInt32)(a >> 23) & ((UInt32)0xff << 1)
|
||||
| (UInt32)(a >> 7) & ((UInt32)0xff << 9)
|
||||
#elif 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
|
||||
v = GetUi16a(p + 2);
|
||||
v = Z7_BSWAP32(v) >> 15
|
||||
#else
|
||||
v = (UInt32)p[3] << 1
|
||||
| (UInt32)p[2] << 9
|
||||
#endif
|
||||
| (UInt32)((a & 0xf000) << 5);
|
||||
BR_CONVERT_VAL_DEC(v)
|
||||
a = a_old
|
||||
| (v << 11 & 1u << 31)
|
||||
| (v << 20 & 0x3ff << 21)
|
||||
| (v << 9 & 1 << 20)
|
||||
| (v & 0xff << 12);
|
||||
RISCV_SET_UI32(p, a)
|
||||
}
|
||||
p += 4;
|
||||
continue;
|
||||
} // JAL
|
||||
|
||||
{
|
||||
// AUIPC
|
||||
v = a;
|
||||
#if 1 && defined(RISCV_USE_UNALIGNED_LOAD)
|
||||
a = GetUi32(p);
|
||||
#else
|
||||
a |= (UInt32)GetUi16a(p + 2) << 16;
|
||||
#endif
|
||||
if ((v & 0xe80) == 0) // x0/x2
|
||||
{
|
||||
const UInt32 r = a >> 27;
|
||||
if (RISCV_CHECK_2(v, r))
|
||||
{
|
||||
UInt32 b;
|
||||
#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
|
||||
b = RISCV_GET_UI32(p + 4);
|
||||
b = Z7_BSWAP32(b);
|
||||
#else
|
||||
b = GetBe32(p + 4);
|
||||
#endif
|
||||
v = a >> 12;
|
||||
BR_CONVERT_VAL_DEC(b)
|
||||
a = (r << 7) + 0x17;
|
||||
a += (b + 0x800) & 0xfffff000;
|
||||
v |= b << 20;
|
||||
RISCV_SET_UI32(p, a)
|
||||
RISCV_SET_UI32(p + 4, v)
|
||||
p += 8;
|
||||
}
|
||||
else
|
||||
p += RISCV_STEP_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
const UInt32 b = RISCV_GET_UI32(p + 4);
|
||||
if (!RISCV_CHECK_1(v, b))
|
||||
p += RISCV_STEP_1;
|
||||
else
|
||||
{
|
||||
v = (a & 0xfffff000) | (b >> 20);
|
||||
a = (b << 12) | (0x17 + RISCV_REG_VAL);
|
||||
RISCV_SET_UI32(p, a)
|
||||
RISCV_SET_UI32(p + 4, v)
|
||||
p += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for
|
||||
}
|
|
@ -1,68 +1,105 @@
|
|||
/* Bra.h -- Branch converters for executables
|
||||
2009-02-07 : Igor Pavlov : Public domain */
|
||||
2024-01-20 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BRA_H
|
||||
#define __BRA_H
|
||||
#ifndef ZIP7_INC_BRA_H
|
||||
#define ZIP7_INC_BRA_H
|
||||
|
||||
#include "Types.h"
|
||||
#include "7zTypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
/* #define PPC BAD_PPC_11 // for debug */
|
||||
|
||||
#define Z7_BRANCH_CONV_DEC_2(name) z7_ ## name ## _Dec
|
||||
#define Z7_BRANCH_CONV_ENC_2(name) z7_ ## name ## _Enc
|
||||
#define Z7_BRANCH_CONV_DEC(name) Z7_BRANCH_CONV_DEC_2(BranchConv_ ## name)
|
||||
#define Z7_BRANCH_CONV_ENC(name) Z7_BRANCH_CONV_ENC_2(BranchConv_ ## name)
|
||||
#define Z7_BRANCH_CONV_ST_DEC(name) z7_BranchConvSt_ ## name ## _Dec
|
||||
#define Z7_BRANCH_CONV_ST_ENC(name) z7_BranchConvSt_ ## name ## _Enc
|
||||
|
||||
#define Z7_BRANCH_CONV_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc)
|
||||
#define Z7_BRANCH_CONV_ST_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc, UInt32 *state)
|
||||
|
||||
typedef Z7_BRANCH_CONV_DECL( (*z7_Func_BranchConv));
|
||||
typedef Z7_BRANCH_CONV_ST_DECL((*z7_Func_BranchConvSt));
|
||||
|
||||
#define Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL 0
|
||||
Z7_BRANCH_CONV_ST_DECL (Z7_BRANCH_CONV_ST_DEC(X86));
|
||||
Z7_BRANCH_CONV_ST_DECL (Z7_BRANCH_CONV_ST_ENC(X86));
|
||||
|
||||
#define Z7_BRANCH_FUNCS_DECL(name) \
|
||||
Z7_BRANCH_CONV_DECL (Z7_BRANCH_CONV_DEC_2(name)); \
|
||||
Z7_BRANCH_CONV_DECL (Z7_BRANCH_CONV_ENC_2(name));
|
||||
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_ARM64)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_ARM)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_ARMT)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_PPC)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_SPARC)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_IA64)
|
||||
Z7_BRANCH_FUNCS_DECL (BranchConv_RISCV)
|
||||
|
||||
/*
|
||||
These functions convert relative addresses to absolute addresses
|
||||
in CALL instructions to increase the compression ratio.
|
||||
These functions convert data that contain CPU instructions.
|
||||
Each such function converts relative addresses to absolute addresses in some
|
||||
branch instructions: CALL (in all converters) and JUMP (X86 converter only).
|
||||
Such conversion allows to increase compression ratio, if we compress that data.
|
||||
|
||||
In:
|
||||
data - data buffer
|
||||
size - size of data
|
||||
ip - current virtual Instruction Pinter (IP) value
|
||||
state - state variable for x86 converter
|
||||
encoding - 0 (for decoding), 1 (for encoding)
|
||||
There are 2 types of converters:
|
||||
Byte * Conv_RISC (Byte *data, SizeT size, UInt32 pc);
|
||||
Byte * ConvSt_X86(Byte *data, SizeT size, UInt32 pc, UInt32 *state);
|
||||
Each Converter supports 2 versions: one for encoding
|
||||
and one for decoding (_Enc/_Dec postfixes in function name).
|
||||
|
||||
Out:
|
||||
state - state variable for x86 converter
|
||||
In params:
|
||||
data : data buffer
|
||||
size : size of data
|
||||
pc : current virtual Program Counter (Instruction Pointer) value
|
||||
In/Out param:
|
||||
state : pointer to state variable (for X86 converter only)
|
||||
|
||||
Returns:
|
||||
The number of processed bytes. If you call these functions with multiple calls,
|
||||
you must start next call with first byte after block of processed bytes.
|
||||
Return:
|
||||
The pointer to position in (data) buffer after last byte that was processed.
|
||||
If the caller calls converter again, it must call it starting with that position.
|
||||
But the caller is allowed to move data in buffer. So pointer to
|
||||
current processed position also will be changed for next call.
|
||||
Also the caller must increase internal (pc) value for next call.
|
||||
|
||||
Each converter has some characteristics: Endian, Alignment, LookAhead.
|
||||
Type Endian Alignment LookAhead
|
||||
|
||||
x86 little 1 4
|
||||
X86 little 1 4
|
||||
ARMT little 2 2
|
||||
RISCV little 2 6
|
||||
ARM little 4 0
|
||||
ARM64 little 4 0
|
||||
PPC big 4 0
|
||||
SPARC big 4 0
|
||||
IA64 little 16 0
|
||||
|
||||
size must be >= Alignment + LookAhead, if it's not last block.
|
||||
If (size < Alignment + LookAhead), converter returns 0.
|
||||
(data) must be aligned for (Alignment).
|
||||
processed size can be calculated as:
|
||||
SizeT processed = Conv(data, size, pc) - data;
|
||||
if (processed == 0)
|
||||
it means that converter needs more data for processing.
|
||||
If (size < Alignment + LookAhead)
|
||||
then (processed == 0) is allowed.
|
||||
|
||||
Example:
|
||||
|
||||
UInt32 ip = 0;
|
||||
for ()
|
||||
{
|
||||
; size must be >= Alignment + LookAhead, if it's not last block
|
||||
SizeT processed = Convert(data, size, ip, 1);
|
||||
data += processed;
|
||||
size -= processed;
|
||||
ip += processed;
|
||||
}
|
||||
Example code for conversion in loop:
|
||||
UInt32 pc = 0;
|
||||
size = 0;
|
||||
for (;;)
|
||||
{
|
||||
size += Load_more_input_data(data + size);
|
||||
SizeT processed = Conv(data, size, pc) - data;
|
||||
if (processed == 0 && no_more_input_data_after_size)
|
||||
break; // we stop convert loop
|
||||
data += processed;
|
||||
size -= processed;
|
||||
pc += processed;
|
||||
}
|
||||
*/
|
||||
|
||||
#define x86_Convert_Init(state) { state = 0; }
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,85 +1,187 @@
|
|||
/* Bra86.c -- Converter for x86 code (BCJ)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
/* Bra86.c -- Branch converter for X86 code (BCJ)
|
||||
2023-04-02 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "Bra.h"
|
||||
#include "CpuArch.h"
|
||||
|
||||
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
|
||||
|
||||
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
|
||||
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
#if defined(MY_CPU_SIZEOF_POINTER) \
|
||||
&& ( MY_CPU_SIZEOF_POINTER == 4 \
|
||||
|| MY_CPU_SIZEOF_POINTER == 8)
|
||||
#define BR_CONV_USE_OPT_PC_PTR
|
||||
#endif
|
||||
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
|
||||
#ifdef BR_CONV_USE_OPT_PC_PTR
|
||||
#define BR_PC_INIT pc -= (UInt32)(SizeT)p; // (MY_uintptr_t)
|
||||
#define BR_PC_GET (pc + (UInt32)(SizeT)p)
|
||||
#else
|
||||
#define BR_PC_INIT pc += (UInt32)size;
|
||||
#define BR_PC_GET (pc - (UInt32)(SizeT)(lim - p))
|
||||
// #define BR_PC_INIT
|
||||
// #define BR_PC_GET (pc + (UInt32)(SizeT)(p - data))
|
||||
#endif
|
||||
|
||||
#define BR_CONVERT_VAL(v, c) if (encoding) v += c; else v -= c;
|
||||
// #define BR_CONVERT_VAL(v, c) if (!encoding) c = (UInt32)0 - c; v += c;
|
||||
|
||||
#define Z7_BRANCH_CONV_ST(name) z7_BranchConvSt_ ## name
|
||||
|
||||
#define BR86_NEED_CONV_FOR_MS_BYTE(b) ((((b) + 1) & 0xfe) == 0)
|
||||
|
||||
#ifdef MY_CPU_LE_UNALIGN
|
||||
#define BR86_PREPARE_BCJ_SCAN const UInt32 v = GetUi32(p) ^ 0xe8e8e8e8;
|
||||
#define BR86_IS_BCJ_BYTE(n) ((v & ((UInt32)0xfe << (n) * 8)) == 0)
|
||||
#else
|
||||
#define BR86_PREPARE_BCJ_SCAN
|
||||
// bad for MSVC X86 (partial write to byte reg):
|
||||
#define BR86_IS_BCJ_BYTE(n) ((p[n - 4] & 0xfe) == 0xe8)
|
||||
// bad for old MSVC (partial write to byte reg):
|
||||
// #define BR86_IS_BCJ_BYTE(n) (((*p ^ 0xe8) & 0xfe) == 0)
|
||||
#endif
|
||||
|
||||
static
|
||||
Z7_FORCE_INLINE
|
||||
Z7_ATTRIB_NO_VECTOR
|
||||
Byte *Z7_BRANCH_CONV_ST(X86)(Byte *p, SizeT size, UInt32 pc, UInt32 *state, int encoding)
|
||||
{
|
||||
SizeT bufferPos = 0, prevPosT;
|
||||
UInt32 prevMask = *state & 0x7;
|
||||
if (size < 5)
|
||||
return 0;
|
||||
ip += 5;
|
||||
prevPosT = (SizeT)0 - 1;
|
||||
return p;
|
||||
{
|
||||
// Byte *p = data;
|
||||
const Byte *lim = p + size - 4;
|
||||
unsigned mask = (unsigned)*state; // & 7;
|
||||
#ifdef BR_CONV_USE_OPT_PC_PTR
|
||||
/* if BR_CONV_USE_OPT_PC_PTR is defined: we need to adjust (pc) for (+4),
|
||||
because call/jump offset is relative to the next instruction.
|
||||
if BR_CONV_USE_OPT_PC_PTR is not defined : we don't need to adjust (pc) for (+4),
|
||||
because BR_PC_GET uses (pc - (lim - p)), and lim was adjusted for (-4) before.
|
||||
*/
|
||||
pc += 4;
|
||||
#endif
|
||||
BR_PC_INIT
|
||||
goto start;
|
||||
|
||||
for (;;)
|
||||
for (;; mask |= 4)
|
||||
{
|
||||
Byte *p = data + bufferPos;
|
||||
Byte *limit = data + size - 4;
|
||||
for (; p < limit; p++)
|
||||
if ((*p & 0xFE) == 0xE8)
|
||||
break;
|
||||
bufferPos = (SizeT)(p - data);
|
||||
if (p >= limit)
|
||||
break;
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
if (prevPosT > 3)
|
||||
prevMask = 0;
|
||||
else
|
||||
// cont: mask |= 4;
|
||||
start:
|
||||
if (p >= lim)
|
||||
goto fin;
|
||||
{
|
||||
prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
|
||||
if (prevMask != 0)
|
||||
{
|
||||
Byte b = p[4 - kMaskToBitNumber[prevMask]];
|
||||
if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
|
||||
{
|
||||
prevPosT = bufferPos;
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
BR86_PREPARE_BCJ_SCAN
|
||||
p += 4;
|
||||
if (BR86_IS_BCJ_BYTE(0)) { goto m0; } mask >>= 1;
|
||||
if (BR86_IS_BCJ_BYTE(1)) { goto m1; } mask >>= 1;
|
||||
if (BR86_IS_BCJ_BYTE(2)) { goto m2; } mask = 0;
|
||||
if (BR86_IS_BCJ_BYTE(3)) { goto a3; }
|
||||
}
|
||||
prevPosT = bufferPos;
|
||||
goto main_loop;
|
||||
|
||||
if (Test86MSByte(p[4]))
|
||||
m0: p--;
|
||||
m1: p--;
|
||||
m2: p--;
|
||||
if (mask == 0)
|
||||
goto a3;
|
||||
if (p > lim)
|
||||
goto fin_p;
|
||||
|
||||
// if (((0x17u >> mask) & 1) == 0)
|
||||
if (mask > 4 || mask == 3)
|
||||
{
|
||||
UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
|
||||
UInt32 dest;
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
int index;
|
||||
if (encoding)
|
||||
dest = (ip + (UInt32)bufferPos) + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)bufferPos);
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
index = kMaskToBitNumber[prevMask] * 8;
|
||||
b = (Byte)(dest >> (24 - index));
|
||||
if (!Test86MSByte(b))
|
||||
break;
|
||||
src = dest ^ ((1 << (32 - index)) - 1);
|
||||
}
|
||||
p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
|
||||
p[3] = (Byte)(dest >> 16);
|
||||
p[2] = (Byte)(dest >> 8);
|
||||
p[1] = (Byte)dest;
|
||||
bufferPos += 5;
|
||||
mask >>= 1;
|
||||
continue; // goto cont;
|
||||
}
|
||||
else
|
||||
mask >>= 1;
|
||||
if (BR86_NEED_CONV_FOR_MS_BYTE(p[mask]))
|
||||
continue; // goto cont;
|
||||
// if (!BR86_NEED_CONV_FOR_MS_BYTE(p[3])) continue; // goto cont;
|
||||
{
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
UInt32 v = GetUi32(p);
|
||||
UInt32 c;
|
||||
v += (1 << 24); if (v & 0xfe000000) continue; // goto cont;
|
||||
c = BR_PC_GET;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
{
|
||||
mask <<= 3;
|
||||
if (BR86_NEED_CONV_FOR_MS_BYTE(v >> mask))
|
||||
{
|
||||
v ^= (((UInt32)0x100 << mask) - 1);
|
||||
#ifdef MY_CPU_X86
|
||||
// for X86 : we can recalculate (c) to reduce register pressure
|
||||
c = BR_PC_GET;
|
||||
#endif
|
||||
BR_CONVERT_VAL(v, c)
|
||||
}
|
||||
mask = 0;
|
||||
}
|
||||
// v = (v & ((1 << 24) - 1)) - (v & (1 << 24));
|
||||
v &= (1 << 25) - 1; v -= (1 << 24);
|
||||
SetUi32(p, v)
|
||||
p += 4;
|
||||
goto main_loop;
|
||||
}
|
||||
|
||||
main_loop:
|
||||
if (p >= lim)
|
||||
goto fin;
|
||||
for (;;)
|
||||
{
|
||||
BR86_PREPARE_BCJ_SCAN
|
||||
p += 4;
|
||||
if (BR86_IS_BCJ_BYTE(0)) { goto a0; }
|
||||
if (BR86_IS_BCJ_BYTE(1)) { goto a1; }
|
||||
if (BR86_IS_BCJ_BYTE(2)) { goto a2; }
|
||||
if (BR86_IS_BCJ_BYTE(3)) { goto a3; }
|
||||
if (p >= lim)
|
||||
goto fin;
|
||||
}
|
||||
|
||||
a0: p--;
|
||||
a1: p--;
|
||||
a2: p--;
|
||||
a3:
|
||||
if (p > lim)
|
||||
goto fin_p;
|
||||
// if (!BR86_NEED_CONV_FOR_MS_BYTE(p[3])) continue; // goto cont;
|
||||
{
|
||||
UInt32 v = GetUi32(p);
|
||||
UInt32 c;
|
||||
v += (1 << 24); if (v & 0xfe000000) continue; // goto cont;
|
||||
c = BR_PC_GET;
|
||||
BR_CONVERT_VAL(v, c)
|
||||
// v = (v & ((1 << 24) - 1)) - (v & (1 << 24));
|
||||
v &= (1 << 25) - 1; v -= (1 << 24);
|
||||
SetUi32(p, v)
|
||||
p += 4;
|
||||
goto main_loop;
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
*state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
|
||||
return bufferPos;
|
||||
|
||||
fin_p:
|
||||
p--;
|
||||
fin:
|
||||
// the following processing for tail is optional and can be commented
|
||||
/*
|
||||
lim += 4;
|
||||
for (; p < lim; p++, mask >>= 1)
|
||||
if ((*p & 0xfe) == 0xe8)
|
||||
break;
|
||||
*/
|
||||
*state = (UInt32)mask;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define Z7_BRANCH_CONV_ST_FUNC_IMP(name, m, encoding) \
|
||||
Z7_NO_INLINE \
|
||||
Z7_ATTRIB_NO_VECTOR \
|
||||
Byte *m(name)(Byte *data, SizeT size, UInt32 pc, UInt32 *state) \
|
||||
{ return Z7_BRANCH_CONV_ST(name)(data, size, pc, state, encoding); }
|
||||
|
||||
Z7_BRANCH_CONV_ST_FUNC_IMP(X86, Z7_BRANCH_CONV_ST_DEC, 0)
|
||||
#ifndef Z7_EXTRACT_ONLY
|
||||
Z7_BRANCH_CONV_ST_FUNC_IMP(X86, Z7_BRANCH_CONV_ST_ENC, 1)
|
||||
#endif
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue