mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-31 13:25:58 -05:00
Compare commits
76 Commits
ImHex-v1.2
...
ImHex-v1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04ef9d6085 | ||
|
|
dc5b219d24 | ||
|
|
e6c800b71c | ||
|
|
5c9a7b1ac0 | ||
|
|
22390d0adf | ||
|
|
dfc9b17067 | ||
|
|
d33fdfafb8 | ||
|
|
58d63d1d4a | ||
|
|
86f38ca545 | ||
|
|
27d98d4552 | ||
|
|
dba93afe06 | ||
|
|
5481c2ff6a | ||
|
|
efa9957935 | ||
|
|
073768fec3 | ||
|
|
ceb322019c | ||
|
|
befd05f8dd | ||
|
|
6a1abd8fec | ||
|
|
b2ebbc6d66 | ||
|
|
24c003b333 | ||
|
|
caea4544ef | ||
|
|
36b107f0ca | ||
|
|
6367f434ab | ||
|
|
2cfd3c43a7 | ||
|
|
4bda291de1 | ||
|
|
ce542887c4 | ||
|
|
44216762fd | ||
|
|
3621144815 | ||
|
|
244dd88098 | ||
|
|
93c53f2d2e | ||
|
|
ccd163b981 | ||
|
|
cfc6a442de | ||
|
|
62b1eb927e | ||
|
|
2baae9c5f6 | ||
|
|
6ccb3bf465 | ||
|
|
fc997133a1 | ||
|
|
966c4e15b0 | ||
|
|
935a26e9f9 | ||
|
|
529c419ca8 | ||
|
|
befd6ef448 | ||
|
|
45da27275d | ||
|
|
60c5f795a0 | ||
|
|
72acac1082 | ||
|
|
a9d6c882ac | ||
|
|
7ecfcd446d | ||
|
|
b094757b03 | ||
|
|
1d0b11372f | ||
|
|
f01ddec350 | ||
|
|
64136ba16c | ||
|
|
1e45938887 | ||
|
|
f32b162647 | ||
|
|
d2685aabf5 | ||
|
|
8027cda032 | ||
|
|
a178509b3c | ||
|
|
56411ae067 | ||
|
|
7ee489237d | ||
|
|
4d97e79097 | ||
|
|
9fec10000a | ||
|
|
b0d8b81861 | ||
|
|
c7fbb661ae | ||
|
|
7e19b4cb10 | ||
|
|
ff2726ce8a | ||
|
|
ed47fa65f1 | ||
|
|
f0963603bf | ||
|
|
15548b92e2 | ||
|
|
87efc6cf54 | ||
|
|
5e48adcb9d | ||
|
|
f548643933 | ||
|
|
575e4d5381 | ||
|
|
6b0fad199e | ||
|
|
ece86f1124 | ||
|
|
ce2b4d60ca | ||
|
|
7c88439681 | ||
|
|
8d3c94be8f | ||
|
|
0b15299980 | ||
|
|
eda13b2518 | ||
|
|
aa6c90fa5b |
8
.gitattributes
vendored
8
.gitattributes
vendored
@@ -1,10 +1,2 @@
|
||||
*.pat linguist-language=Rust
|
||||
*.hexpat linguist-language=Rust
|
||||
constants/* text eol=lf
|
||||
encodings/* text eol=lf
|
||||
includes/* text eol=lf
|
||||
magic/* text eol=lf
|
||||
patterns/* text eol=lf
|
||||
structs/* text eol=lf
|
||||
tips/* text eol=lf
|
||||
yara/* text eol=lf
|
||||
10
.github/PULL_REQUEST_TEMPLATE/pattern_template.md
vendored
Normal file
10
.github/PULL_REQUEST_TEMPLATE/pattern_template.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Pattern
|
||||
|
||||
[Information about your pattern]
|
||||
|
||||
## Checklist
|
||||
- [ ] A pattern for this format doesn't exist yet (or this PR improves the existing one)
|
||||
- [ ] The new pattern has been added to the relevant table in the Readme
|
||||
- [ ] The pattern was associated with all relevant MIME types (using `#pragma MIME mime-type` in the source code)
|
||||
- [ ] A test file for this pattern has been added to [/tests/patterns/test_data](/tests/patterns/test_data)
|
||||
- Try to keep this file below ~ 1 MB
|
||||
27
.github/workflows/tests.yml
vendored
27
.github/workflows/tests.yml
vendored
@@ -5,6 +5,8 @@ on:
|
||||
branches: [ '*' ]
|
||||
pull_request:
|
||||
branches: [ '*' ]
|
||||
repository_dispatch:
|
||||
types: [run_tests]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
@@ -34,7 +36,8 @@ jobs:
|
||||
make \
|
||||
python3 \
|
||||
python3-pip \
|
||||
libmagic-dev
|
||||
libmagic-dev \
|
||||
lcov
|
||||
|
||||
sudo pip install jsonschema
|
||||
|
||||
@@ -43,17 +46,29 @@ jobs:
|
||||
cd tests
|
||||
mkdir -p build
|
||||
cd build
|
||||
CC=gcc-12 CXX=g++-12 cmake \
|
||||
-DCMAKE_C_FLAGS="-fuse-ld=lld" \
|
||||
-DCMAKE_CXX_FLAGS="-fuse-ld=lld" \
|
||||
-DLIBPL_ENABLE_TESTS=OFF \
|
||||
CC=gcc-12 CXX=g++-12 cmake \
|
||||
-DCMAKE_C_FLAGS="-fuse-ld=lld --coverage" \
|
||||
-DCMAKE_CXX_FLAGS="-fuse-ld=lld --coverage" \
|
||||
-DLIBPL_ENABLE_TESTS=OFF \
|
||||
..
|
||||
make -j4
|
||||
|
||||
- name: 🧪 Perform Unit Tests
|
||||
run: |
|
||||
cd tests/build
|
||||
ctest
|
||||
ctest --output-on-failure
|
||||
|
||||
- name: ⚗️ Generate Coverage Report
|
||||
run: |
|
||||
cd tests/build
|
||||
lcov -d ./_deps/pattern_language-build/lib --gcov-tool /usr/bin/gcov-12 -c -o coverage.info
|
||||
|
||||
- name: ⬆️ Upload Coverage Report
|
||||
uses: coverallsapp/github-action@master
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path-to-lcov: tests/build/coverage.info
|
||||
|
||||
- name: 📎 Validate JSON Files
|
||||
run: |
|
||||
cd constants
|
||||
|
||||
150
README.md
150
README.md
@@ -8,106 +8,122 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
|
||||
|
||||
| Name | MIME | Path | Description |
|
||||
|------|------|------|-------------|
|
||||
| BMP | `image/bmp` | `patterns/bmp.hexpat` | OS2/Windows Bitmap files |
|
||||
| ELF | `application/x-executable`, `application/x-sharedlib` | `patterns/elf.hexpat` | ELF header in elf binaries |
|
||||
| PE | `application/x-dosexec` | `patterns/pe.hexpat` | PE header, COFF header, Standard COFF fields and Windows Specific fields |
|
||||
| Intel HEX | | `patterns/intel_hex.hexpat` | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
|
||||
| MIDI | `audio/midi` | `patterns/midi.hexpat` | MIDI header, event fields provided |
|
||||
| WAV | `audio/wav` | `patterns/wav.hexpat` | RIFF header, WAVE header, PCM header |
|
||||
| ZIP | `application/zip` | `patterns/zip.hexpat` | End of Central Directory Header, Central Directory File Headers |
|
||||
| PCAP | `application/vnd.tcpdump.pcap` | `patterns/pcap.hexpat` | pcap header and packets |
|
||||
| SPIRV | | `patterns/spirv.hexpat` | SPIR-V header and instructions |
|
||||
| AFE2 | | `patterns/afe2.hexpat` | Nintendo Switch Atmosphère CFW Fatal Error log |
|
||||
| AR | `application/x-archive` | `patterns/ar.hexpat` | Static library archive files |
|
||||
| NACP | | `patterns/nacp.hexpat` | Nintendo Switch NACP files |
|
||||
| NRO | | `patterns/nro.hexpat` | Nintendo Switch NRO files |
|
||||
| PRODINFO | | `patterns/prodinfo.hexpat` | Nintendo Switch PRODINFO |
|
||||
| Java Class | `application/x-java-applet` | `patterns/java_class.hexpat` | Java Class files |
|
||||
| ARM VTOR | | `patterns/arm_cm_vtor.hexpat` | ARM Cortex M Vector Table Layout |
|
||||
| ICO | | `patterns/ico.hexpat` | Icon (.ico) or Cursor (.cur) files |
|
||||
| PNG | `image/png` | `patterns/png.hexpat` | PNG image files |
|
||||
| DDS | `image/vnd-ms.dds` | `patterns/dds.hexpat` | DirectDraw Surface |
|
||||
| TGA | `image/tga` | `patterns/tga.hexpat` | Truevision TGA/TARGA image |
|
||||
| ISO | | `patterns/iso.hexpat` | ISO 9660 file system |
|
||||
| VDF | | `patterns/vdf.hexpat` | Binary Value Data Format (.vdf) files |
|
||||
| IP | | `patterns/ip.hexpat` | Ethernet II Frames (IP Packets) |
|
||||
| UF2 | | `patterns/uf2.hexpat` | [USB Flashing Format](https://github.com/microsoft/uf2) |
|
||||
| BMP | `image/bmp` | [`patterns/bmp.hexpat`](patterns/bmp.hexpat) | OS2/Windows Bitmap files |
|
||||
| ELF | `application/x-executable` | [`patterns/elf.hexpat`](patterns/elf.hexpat) | ELF header in elf binaries |
|
||||
| PE | `application/x-dosexec` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
|
||||
| Intel HEX | | [`patterns/intel_hex.hexpat`](patterns/intel_hex.hexpat) | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
|
||||
| MIDI | `audio/midi` | [`patterns/midi.hexpat`](patterns/midi.hexpat) | MIDI header, event fields provided |
|
||||
| WAV | `audio/wav` | [`patterns/wav.hexpat`](patterns/wav.hexpat) | RIFF header, WAVE header, PCM header |
|
||||
| ZIP | `application/zip` | [`patterns/zip.hexpat`](patterns/zip.hexpat) | End of Central Directory Header, Central Directory File Headers |
|
||||
| PCAP | `application/vnd.tcpdump.pcap` | [`patterns/pcap.hexpat`](patterns/pcap.hexpat) | pcap header and packets |
|
||||
| SPIRV | | [`patterns/spirv.hexpat`](patterns/spirv.hexpat) | SPIR-V header and instructions |
|
||||
| AFE2 | | [`patterns/afe2.hexpat`](patterns/afe2.hexpat) | Nintendo Switch Atmosphère CFW Fatal Error log |
|
||||
| AR | `application/x-archive` | [`patterns/ar.hexpat`](patterns/ar.hexpat) | Static library archive files |
|
||||
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
|
||||
| NRO | | [`patterns/nro.hexpat`](patterns/nro.hexpat) | Nintendo Switch NRO files |
|
||||
| PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO |
|
||||
| Java Class | `application/x-java-applet` | [`patterns/java_class.hexpat`](patterns/java_class.hexpat) | Java Class files |
|
||||
| ARM VTOR | | [`patterns/arm_cm_vtor.hexpat`](patterns/arm_cm_vtor.hexpat) | ARM Cortex M Vector Table Layout |
|
||||
| ICO | | [`patterns/ico.hexpat`](patterns/ico.hexpat) | Icon (.ico) or Cursor (.cur) files |
|
||||
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
|
||||
| DDS | `image/vnd-ms.dds` | [`patterns/dds.hexpat`](patterns/dds.hexpat) | DirectDraw Surface |
|
||||
| TGA | `image/tga` | [`patterns/tga.hexpat`](patterns/tga.hexpat) | Truevision TGA/TARGA image |
|
||||
| ISO | | [`patterns/iso.hexpat`](patterns/iso.hexpat) | ISO 9660 file system |
|
||||
| VDF | | [`patterns/vdf.hexpat`](patterns/vdf.hexpat) | Binary Value Data Format (.vdf) files |
|
||||
| IP | | [`patterns/ip.hexpat`](patterns/ip.hexpat) | Ethernet II Frames (IP Packets) |
|
||||
| UF2 | | [`patterns/uf2.hexpat`](patterns/uf2.hexpat) | [USB Flashing Format](https://github.com/microsoft/uf2) |
|
||||
| File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System |
|
||||
| Bencode | `application/x-bittorrent` | [`patterns/bencode.hexpat`](patterns/bencode.hexpat) | Bencode encoding, used by Torrent files |
|
||||
| Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding |
|
||||
| OGG | `audio/ogg` | [`patterns/ogg.hexpat`](patterns/ogg.hexpat) | OGG Audio format |
|
||||
| STL | `model/stl` | [`patterns/stl.hexpat`](patterns/stl.hexpat) | STL 3D Model format |
|
||||
| VHDX | | [`patterns/vhdx.hexpat`](patterns/vhdx.hexpat) | Microsoft Hyper-V Virtual Hard Disk format |
|
||||
| NTAG | | [`patterns/ntag.hexpat`](patterns/ntag.hexpat) | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC |
|
||||
| Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format |
|
||||
| Xilinx BIT | | [`patterns/xilinx_bit.hexpat`](patterns/xilinx_bit.hexpat) | Xilinx FPGA Bitstreams |
|
||||
| FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format |
|
||||
| BSON | `application/bson` | [`patterns/bson.hexpat`](patterns/bson.hexpat) | BSON (Binary JSON) format |
|
||||
| msgpack | `application/x-msgpack` | [`patterns/msgpack.hexpat`](patterns/msgpack.hexpat) | MessagePack binary serialization format |
|
||||
| MiniDump | `application/x-dmp` | [`patterns/minidump.hexpat`](patterns/minidump.hexpat) | Windows MiniDump files |
|
||||
|
||||
### Scripts
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| svd2pat | `scripts/svd2pat.py` | Converts a ARM .svd register MMIO definition file into a pattern |
|
||||
| csv2tbl | `scripts/csv2tbl.py` | Converts a 010 editor CSV encoding file into a table file |
|
||||
| svd2pat | [`scripts/svd2pat.py`](scripts/svd2pat.py) | Converts a ARM .svd register MMIO definition file into a pattern |
|
||||
| csv2tbl | [`scripts/csv2tbl.py`](scripts/csv2tbl.py) | Converts a 010 editor CSV encoding file into a table file |
|
||||
|
||||
### Pattern Libraries
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| libstd | `includes/std/*` | Pattern Language Standard Libaray |
|
||||
| cstdint | `includes/cstdint.pat` | C integer types |
|
||||
| libstd | [`includes/std/*`](includes/std) | Pattern Language Standard Libaray |
|
||||
| libtype | [`includes/type/*`](includes/type) | Various custom types with special formatters |
|
||||
| libhex | [`includes/hex/*`](includes/hex) | Functions to interact with ImHex |
|
||||
|
||||
### Yara rules
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| Official Rules | `yara/official_rules/*` | Official Yara rules repository |
|
||||
| Official Rules | [`yara/official_rules/*`](yara/official_rules) | Official Yara rules repository |
|
||||
|
||||
### Magic files
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| Nintendo Switch | `magic/nintendo_switch_magic` | Identifies common file types used on the Nintendo Switch |
|
||||
| Portable Executable | `magic/portable_executable_magic` | Identifies PE files used on Windows
|
||||
| Nintendo Switch | [`magic/nintendo_switch_magic`](magic/nintendo_switch_magic) | Identifies common file types used on the Nintendo Switch |
|
||||
| Portable Executable | [`magic/portable_executable_magic`](magic/portable_executable_magic) | Identifies PE files used on Windows
|
||||
|
||||
### Constants files
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| CRC-16 | `constants/crc16.json` | Constants associated with CRC-16 operations |
|
||||
| CRC-32 | `constants/crc32.json` | Constants associated with CRC-32 operations |
|
||||
| HTTP-Codes | `constants/http_status.json` | HTTP Status code values |
|
||||
| Linux Error Codes | `constants/linux_errors.json` | Values of Linux error results |
|
||||
| CRC-16 | [`constants/crc16.json`](constants/crc16.json) | Constants associated with CRC-16 operations |
|
||||
| CRC-32 | [`constants/crc32.json`](constants/crc32.json) | Constants associated with CRC-32 operations |
|
||||
| HTTP-Codes | [`constants/http_status.json`](constants/http_status.json) | HTTP Status code values |
|
||||
| Linux Error Codes | [`constants/linux_errors.json`](constants/linux_errors.json) | Values of Linux error results |
|
||||
|
||||
### Encoding files
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| Arabic ISO | `encodings/arabic_iso.tbl` | Arabic ISO encoding |
|
||||
| Arabic Windows | `encodings/arabic_windows.tbl` | Arabic Windows encoding |
|
||||
| ASCII | `encodings/ascii.tbl` | Regular ASCII encoding |
|
||||
| ASCII+ANSI | `encodings/ascii_ansi.tbl` | Extended ASCII encoding |
|
||||
| ASCII+OEM | `encodings/ascii_oem.tbl` | ASCII encoding with Windows OEM characters |
|
||||
| Baltic ISO | `encodings/baltic_iso.tbl` | Baltic ISO encoding |
|
||||
| Baltic Windows | `encodings/baltic_windows.tbl` | Baltic Windows encoding |
|
||||
| Cyrillic ISO | `encodings/cyrillic_iso.tbl` | Cyrillic ISO encoding |
|
||||
| Cyrillic Windows | `encodings/cyrillic_windows.tbl` | Cyrillic Windows encoding |
|
||||
| Cyrillic KOI8-R | `encodings/cyrillic_koi8_r.tbl` | Cyrillic KOI8-R encoding (Russian Characters) |
|
||||
| Cyrillic KOI8-U | `encodings/cyrillic_koi8_u.tbl` | Cyrillic KOI8-U encoding (Ukranian Characters) |
|
||||
| Eastern Europe ISO | `encodings/eastern_europe_iso.tbl` | Eastern Europe ISO encoding |
|
||||
| Eastern Europe Windows | `encodings/eastern_europe_windows.tbl` | Eastern Europe Windows encoding |
|
||||
| EBCDIC | `encodings/ebcdic.tbl` | Extended Binary Coded Decimal Interchange Code, developed by IBM for their Main Frames |
|
||||
| EUC-JP | `encodings/euc_jp.tbl` | EUC-JP encoding with NEC special and IBM extended characters |
|
||||
| Greek ISO | `encodings/greek_iso.tbl` | Greek ISO encoding |
|
||||
| Greek Windows | `encodings/greek_windows.tbl` | Greek Windows encoding |
|
||||
| Hebrew ISO | `encodings/hebrew_iso.tbl` | Hebrew ISO encoding |
|
||||
| Hebrew Windows | `encodings/hebrew_windows.tbl` | Hebrew Windows encoding |
|
||||
| ISO/IEC 646 | `encodings/iso_646.tbl` | ISO/IEC 646 encoding, an older version of ASCII |
|
||||
| ISO/IEC 6937 | `encodings/iso_6937.tbl` | ISO/IEC 6937 encoding, an extension of ASCII containing additional character |
|
||||
| JIS 0201 | `encodings/jis_x_0201.tbl` | JIS X 0201 encoding in UTF-8 |
|
||||
| JIS X 0211 | `encodings/jis_x_0211.tbl` | JIS X 0211 encoding in UTF-8 |
|
||||
| JIS 0213 | `encodings/jis_x_0213.tbl` | JIS X 0213 encoding in UTF-8 |
|
||||
| Macintosh | `encodings/macintosh.tbl` | Macintosh character encoding used by the Kermit protocol |
|
||||
| Shift-JIS UTF-8 | `encodings/shiftjis.tbl` | Shift-JIS encoding in UTF-8 |
|
||||
| Thai | `encodings/thai.tbl` | Thai character encoding |
|
||||
| Turkish ISO | `encodings/turkish_iso.tbl` | Turkish ISO encoding |
|
||||
| Turkish Windows | `encodings/turkish_windows.tbl` | Turkish Windows encoding |
|
||||
| UTF-8 | `encodings/utf8.tbl` | UTF-8 encoding |
|
||||
| Vietnamese | `encodings/vietnamese.tbl` | Vietnamese character encoding |
|
||||
| Arabic ISO | [`encodings/arabic_iso.tbl`](encodings/arabic_iso.tbl) | Arabic ISO encoding |
|
||||
| Arabic Windows | [`encodings/arabic_windows.tbl`](encodings/arabic_windows.tbl) | Arabic Windows encoding |
|
||||
| ASCII | [`encodings/ascii.tbl`](encodings/ascii.tbl) | Regular ASCII encoding |
|
||||
| ASCII+ANSI | [`encodings/ascii_ansi.tbl`](encodings/ascii_ansi.tbl) | Extended ASCII encoding |
|
||||
| ASCII+OEM | [`encodings/ascii_oem.tbl`](encodings/ascii_oem.tbl) | ASCII encoding with Windows OEM characters |
|
||||
| Baltic ISO | [`encodings/baltic_iso.tbl`](encodings/baltic_iso.tbl) | Baltic ISO encoding |
|
||||
| Baltic Windows | [`encodings/baltic_windows.tbl`](encodings/baltic_windows.tbl) | Baltic Windows encoding |
|
||||
| Cyrillic ISO | [`encodings/cyrillic_iso.tbl`](encodings/cyrillic_iso.tbl) | Cyrillic ISO encoding |
|
||||
| Cyrillic Windows | [`encodings/cyrillic_windows.tbl`](encodings/cyrillic_windows.tbl) | Cyrillic Windows encoding |
|
||||
| Cyrillic KOI8-R | [`encodings/cyrillic_koi8_r.tbl`](encodings/cyrillic_koi8_r.tbl) | Cyrillic KOI8-R encoding (Russian Characters) |
|
||||
| Cyrillic KOI8-U | [`encodings/cyrillic_koi8_u.tbl`](encodings/cyrillic_koi8_u.tbl) | Cyrillic KOI8-U encoding (Ukranian Characters) |
|
||||
| Eastern Europe ISO | [`encodings/eastern_europe_iso.tbl`](encodings/eastern_europe_iso.tbl) | Eastern Europe ISO encoding |
|
||||
| Eastern Europe Windows | [`encodings/eastern_europe_windows.tbl`](encodings/eastern_europe_windows.tbl) | Eastern Europe Windows encoding |
|
||||
| EBCDIC | [`encodings/ebcdic.tbl`](encodings/ebcdic.tbl) | Extended Binary Coded Decimal Interchange Code, developed by IBM for their Main Frames |
|
||||
| EUC-JP | [`encodings/euc_jp.tbl`](encodings/euc_jp.tbl) | EUC-JP encoding with NEC special and IBM extended characters |
|
||||
| EUC-KR | [`encodings/euc_kr.tbl`](encodings/euc_kr.tbl) | EUC-KR encoding |
|
||||
| Greek ISO | [`encodings/greek_iso.tbl`](encodings/greek_iso.tbl) | Greek ISO encoding |
|
||||
| Greek Windows | [`encodings/greek_windows.tbl`](encodings/greek_windows.tbl) | Greek Windows encoding |
|
||||
| Hebrew ISO | [`encodings/hebrew_iso.tbl`](encodings/hebrew_iso.tbl) | Hebrew ISO encoding |
|
||||
| Hebrew Windows | [`encodings/hebrew_windows.tbl`](encodings/hebrew_windows.tbl) | Hebrew Windows encoding |
|
||||
| ISO/IEC 646 | [`encodings/iso_646.tbl`](encodings/iso_646.tbl) | ISO/IEC 646 encoding, an older version of ASCII |
|
||||
| ISO/IEC 6937 | [`encodings/iso_6937.tbl`](encodings/iso_6937.tbl) | ISO/IEC 6937 encoding, an extension of ASCII containing additional character |
|
||||
| JIS 0201 | [`encodings/jis_x_0201.tbl`](encodings/jis_x_0201.tbl) | JIS X 0201 encoding in UTF-8 |
|
||||
| JIS X 0211 | [`encodings/jis_x_0211.tbl`](encodings/jis_x_0211.tbl) | JIS X 0211 encoding in UTF-8 |
|
||||
| JIS 0213 | [`encodings/jis_x_0213.tbl`](encodings/jis_x_0213.tbl) | JIS X 0213 encoding in UTF-8 |
|
||||
| Macintosh | [`encodings/macintosh.tbl`](encodings/macintosh.tbl) | Macintosh character encoding used by the Kermit protocol |
|
||||
| Pokémon (English, Generation 1) | [`encodings/pokegen1_en.tbl`](encodings/pokegen1_en.tbl) | Character encoding used by the English generation 1 Pokémon games |
|
||||
| Shift-JIS UTF-8 | [`encodings/shiftjis.tbl`](encodings/shiftjis.tbl) | Shift-JIS encoding in UTF-8 |
|
||||
| Thai | [`encodings/thai.tbl`](encodings/thai.tbl) | Thai character encoding |
|
||||
| Turkish ISO | [`encodings/turkish_iso.tbl`](encodings/turkish_iso.tbl) | Turkish ISO encoding |
|
||||
| Turkish Windows | [`encodings/turkish_windows.tbl`](encodings/turkish_windows.tbl) | Turkish Windows encoding |
|
||||
| UTF-8 | [`encodings/utf8.tbl`](encodings/utf8.tbl) | UTF-8 encoding |
|
||||
| Vietnamese | [`encodings/vietnamese.tbl`](encodings/vietnamese.tbl) | Vietnamese character encoding |
|
||||
|
||||
## Contributing
|
||||
|
||||
If you want to contribute a file to the database, please make a PR which adds it to the right folder and adds a new entry to the table in this readme.
|
||||
To take advantage of the automatic pattern testing, please consider adding a test file named `<pattern_name>.hexpat.<extension>` to the `/tests/patterns/test_data` directory. Try to keep this file as small as possible so the repository doesn't become excessively large
|
||||
|
||||
Thanks a lot :)
|
||||
Thanks a lot :)
|
||||
|
||||
256
encodings/cyrillic_cp866.tbl
Normal file
256
encodings/cyrillic_cp866.tbl
Normal file
@@ -0,0 +1,256 @@
|
||||
00=NUL
|
||||
01=☺
|
||||
02=☻
|
||||
03=♥
|
||||
04=♦
|
||||
05=♣
|
||||
06=♠
|
||||
07=•
|
||||
08=◘
|
||||
09=○
|
||||
0A=◙
|
||||
0B=♂
|
||||
0C=♀
|
||||
0D=♪
|
||||
0E=♫
|
||||
0F=☼
|
||||
10=►
|
||||
11=◄
|
||||
12=↕
|
||||
13=‼
|
||||
14=¶
|
||||
15=§
|
||||
16=▬
|
||||
17=↨
|
||||
18=↑
|
||||
19=↓
|
||||
1A=→
|
||||
1B=←
|
||||
1C=∟
|
||||
1D=↔
|
||||
1E=▲
|
||||
1F=▼
|
||||
20=
|
||||
21=!
|
||||
22="
|
||||
23=#
|
||||
24=$
|
||||
25=%
|
||||
26=&
|
||||
27='
|
||||
28=(
|
||||
29=)
|
||||
2A=*
|
||||
2B=+
|
||||
2C=,
|
||||
2D=-
|
||||
2E=.
|
||||
2F=/
|
||||
30=0
|
||||
31=1
|
||||
32=2
|
||||
33=3
|
||||
34=4
|
||||
35=5
|
||||
36=6
|
||||
37=7
|
||||
38=8
|
||||
39=9
|
||||
3A=:
|
||||
3B=;
|
||||
3C=<
|
||||
3D==
|
||||
3E=>
|
||||
3F=?
|
||||
40=@
|
||||
41=A
|
||||
42=B
|
||||
43=C
|
||||
44=D
|
||||
45=E
|
||||
46=F
|
||||
47=G
|
||||
48=H
|
||||
49=I
|
||||
4A=J
|
||||
4B=K
|
||||
4C=L
|
||||
4D=M
|
||||
4E=N
|
||||
4F=O
|
||||
50=P
|
||||
51=Q
|
||||
52=R
|
||||
53=S
|
||||
54=T
|
||||
55=U
|
||||
56=V
|
||||
57=W
|
||||
58=X
|
||||
59=Y
|
||||
5A=Z
|
||||
5B=[
|
||||
5C=\
|
||||
5D=]
|
||||
5E=^
|
||||
5F=_
|
||||
60=`
|
||||
61=a
|
||||
62=b
|
||||
63=c
|
||||
64=d
|
||||
65=e
|
||||
66=f
|
||||
67=g
|
||||
68=h
|
||||
69=i
|
||||
6A=j
|
||||
6B=k
|
||||
6C=l
|
||||
6D=m
|
||||
6E=n
|
||||
6F=o
|
||||
70=p
|
||||
71=q
|
||||
72=r
|
||||
73=s
|
||||
74=t
|
||||
75=u
|
||||
76=v
|
||||
77=w
|
||||
78=x
|
||||
79=y
|
||||
7A=z
|
||||
7B={
|
||||
7C=|
|
||||
7D=}
|
||||
7E=~
|
||||
7F=⌂
|
||||
80=А
|
||||
81=Б
|
||||
82=В
|
||||
83=Г
|
||||
84=Д
|
||||
85=Е
|
||||
86=Ж
|
||||
87=З
|
||||
88=И
|
||||
89=Й
|
||||
8A=К
|
||||
8B=Л
|
||||
8C=М
|
||||
8D=Н
|
||||
8E=О
|
||||
8F=П
|
||||
90=Р
|
||||
91=С
|
||||
92=Т
|
||||
93=У
|
||||
94=Ф
|
||||
95=Х
|
||||
96=Ц
|
||||
97=Ч
|
||||
98=Ш
|
||||
99=Щ
|
||||
9A=Ъ
|
||||
9B=Ы
|
||||
9C=Ь
|
||||
9D=Э
|
||||
9E=Ю
|
||||
9F=Я
|
||||
A0=а
|
||||
A1=б
|
||||
A2=в
|
||||
A3=г
|
||||
A4=д
|
||||
A5=е
|
||||
A6=ж
|
||||
A7=з
|
||||
A8=и
|
||||
A9=й
|
||||
AA=к
|
||||
AB=л
|
||||
AC=м
|
||||
AD=н
|
||||
AE=о
|
||||
AF=п
|
||||
B0=░
|
||||
B1=▒
|
||||
B2=▓
|
||||
B3=│
|
||||
B4=┤
|
||||
B5=╡
|
||||
B6=╢
|
||||
B7=╖
|
||||
B8=╕
|
||||
B9=╣
|
||||
BA=║
|
||||
BB=╗
|
||||
BC=╝
|
||||
BD=╜
|
||||
BE=╛
|
||||
BF=┐
|
||||
C0=└
|
||||
C1=┴
|
||||
C2=┬
|
||||
C3=├
|
||||
C4=─
|
||||
C5=┼
|
||||
C6=╞
|
||||
C7=╟
|
||||
C8=╚
|
||||
C9=╔
|
||||
CA=╩
|
||||
CB=╦
|
||||
CC=╠
|
||||
CD=═
|
||||
CE=╬
|
||||
CF=╧
|
||||
D0=╨
|
||||
D1=╤
|
||||
D2=╥
|
||||
D3=╙
|
||||
D4=╘
|
||||
D5=╒
|
||||
D6=╓
|
||||
D7=╫
|
||||
D8=╪
|
||||
D9=┘
|
||||
DA=┌
|
||||
DB=█
|
||||
DC=▄
|
||||
DD=▌
|
||||
DE=▐
|
||||
DF=▀
|
||||
E0=р
|
||||
E1=с
|
||||
E2=т
|
||||
E3=у
|
||||
E4=ф
|
||||
E5=х
|
||||
E6=ц
|
||||
E7=ч
|
||||
E8=ш
|
||||
E9=щ
|
||||
EA=ъ
|
||||
EB=ы
|
||||
EC=ь
|
||||
ED=э
|
||||
EE=ю
|
||||
EF=я
|
||||
F0=Ё
|
||||
F1=ё
|
||||
F2=Є
|
||||
F3=є
|
||||
F4=Ї
|
||||
F5=ї
|
||||
F6=Ў
|
||||
F7=ў
|
||||
F8=°
|
||||
F9=∙
|
||||
FA=·
|
||||
FB=√
|
||||
FC=№
|
||||
FD=¤
|
||||
FE=■
|
||||
FF=
|
||||
16674
encodings/euc_kr.tbl
Normal file
16674
encodings/euc_kr.tbl
Normal file
File diff suppressed because it is too large
Load Diff
255
encodings/pokegen1_en.tbl
Normal file
255
encodings/pokegen1_en.tbl
Normal file
@@ -0,0 +1,255 @@
|
||||
00=NUL
|
||||
01
|
||||
02
|
||||
03
|
||||
04
|
||||
05
|
||||
06
|
||||
07
|
||||
08
|
||||
09
|
||||
0A
|
||||
0B
|
||||
0C
|
||||
0D
|
||||
0E
|
||||
0F
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
1A
|
||||
1B
|
||||
1C
|
||||
1D
|
||||
1E
|
||||
1F
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
2A
|
||||
2B
|
||||
2C
|
||||
2D
|
||||
2E
|
||||
2F
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
3A
|
||||
3B
|
||||
3C
|
||||
3D
|
||||
3E
|
||||
3F
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49=page
|
||||
4A=PkMn
|
||||
4B=_cont
|
||||
4C=autocont
|
||||
4D
|
||||
4E=next line
|
||||
4F=bottom line
|
||||
50=end
|
||||
51=paragraph
|
||||
52=player name
|
||||
53=rival name
|
||||
54=Poké
|
||||
55=cont
|
||||
56=......
|
||||
57=done
|
||||
58=prompt
|
||||
59=target
|
||||
5A=user
|
||||
5B=PC
|
||||
5C=TM
|
||||
5D=TRAINER
|
||||
5E=ROCKET
|
||||
5F=dex
|
||||
60=A
|
||||
61=B
|
||||
62=C
|
||||
63=D
|
||||
64=E
|
||||
65=F
|
||||
66=G
|
||||
67=H
|
||||
68=I
|
||||
69=V
|
||||
6A=S
|
||||
6B=L
|
||||
6C=M
|
||||
6D=:
|
||||
6E=ぃ
|
||||
6F=ぅ
|
||||
70=‘
|
||||
71=’
|
||||
72=“
|
||||
73=”
|
||||
74=・
|
||||
75=⋯
|
||||
76=ぁ
|
||||
77=ぇ
|
||||
78=ぉ
|
||||
79
|
||||
7A
|
||||
7B
|
||||
7C
|
||||
7D
|
||||
7E
|
||||
7F
|
||||
80=A
|
||||
81=B
|
||||
82=C
|
||||
83=D
|
||||
84=E
|
||||
85=F
|
||||
86=G
|
||||
87=H
|
||||
88=I
|
||||
89=J
|
||||
8A=K
|
||||
8B=L
|
||||
8C=M
|
||||
8D=N
|
||||
8E=O
|
||||
8F=P
|
||||
90=Q
|
||||
91=R
|
||||
92=S
|
||||
93=T
|
||||
94=U
|
||||
95=V
|
||||
96=W
|
||||
97=X
|
||||
98=Y
|
||||
99=Z
|
||||
9A=(
|
||||
9B=)
|
||||
9C=
|
||||
9D=;
|
||||
9E=[
|
||||
9F=]
|
||||
A0=a
|
||||
A1=b
|
||||
A2=c
|
||||
A3=d
|
||||
A4=e
|
||||
A5=f
|
||||
A6=g
|
||||
A7=h
|
||||
A8=i
|
||||
A9=j
|
||||
AA=k
|
||||
AB=l
|
||||
AC=m
|
||||
AD=n
|
||||
AE=o
|
||||
AF=p
|
||||
B0=q
|
||||
B1=r
|
||||
B2=s
|
||||
B3=t
|
||||
B4=u
|
||||
B5=v
|
||||
B6=w
|
||||
B7=x
|
||||
B8=y
|
||||
B9=z
|
||||
BA=é
|
||||
BB='d
|
||||
BC='l
|
||||
BD='s
|
||||
BE='t
|
||||
BF='v
|
||||
C0
|
||||
C1
|
||||
C2
|
||||
C3
|
||||
C4
|
||||
C5
|
||||
C6
|
||||
C7
|
||||
C8
|
||||
C9
|
||||
CA
|
||||
CB
|
||||
CC
|
||||
CD
|
||||
CE
|
||||
CF
|
||||
D0
|
||||
D1
|
||||
D2
|
||||
D3
|
||||
D4
|
||||
D5
|
||||
D6
|
||||
D7
|
||||
D8
|
||||
D9
|
||||
DA
|
||||
DB
|
||||
DC
|
||||
DD
|
||||
DE
|
||||
DF
|
||||
E0='
|
||||
E1=Pk
|
||||
E2=Mn
|
||||
E3=-
|
||||
E4='r
|
||||
E5='m
|
||||
E6=?
|
||||
E7=!
|
||||
E8=.
|
||||
E9=ァ
|
||||
EA=ゥ
|
||||
EB=ェ
|
||||
EC=▷
|
||||
ED=▶
|
||||
EE=▼
|
||||
EF=♂
|
||||
F0=$
|
||||
F1=×
|
||||
F2=.
|
||||
F3=/
|
||||
F4=,
|
||||
F5=♀
|
||||
F6=0
|
||||
F7=1
|
||||
F8=2
|
||||
F9=3
|
||||
FA=4
|
||||
FB=5
|
||||
FC=6
|
||||
FD=7
|
||||
FE=8
|
||||
FF=9
|
||||
@@ -1,6 +1,10 @@
|
||||
00=
|
||||
090D=(R)
|
||||
0A=(BR)
|
||||
08=\b
|
||||
09=\t
|
||||
0A=\n
|
||||
0B=\v
|
||||
0C=\f
|
||||
0D=\r
|
||||
20=
|
||||
21=!
|
||||
22="
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
using uint8_t = u8;
|
||||
using uint16_t = u16;
|
||||
using uint32_t = u32;
|
||||
using uint64_t = u64;
|
||||
using uint128_t = u128;
|
||||
|
||||
using int8_t = s8;
|
||||
using int16_t = s16;
|
||||
using int32_t = s32;
|
||||
using int64_t = s64;
|
||||
using int128_t = s128;
|
||||
|
||||
using size_t = u32;
|
||||
using ssize_t = s32;
|
||||
29
includes/hex/core.pat
Normal file
29
includes/hex/core.pat
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
|
||||
namespace hex::core {
|
||||
|
||||
struct Selection {
|
||||
bool valid;
|
||||
u64 address, size;
|
||||
};
|
||||
|
||||
fn get_selection() {
|
||||
u128 result = builtin::hex::core::get_selection();
|
||||
|
||||
Selection result;
|
||||
if (result == u128(-1)) {
|
||||
result.valid = false;
|
||||
result.address = 0x00;
|
||||
result.size = 0x00;
|
||||
} else {
|
||||
result.valid = true;
|
||||
result.address = result >> 64;
|
||||
result.size = result & u64(-1);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
}
|
||||
11
includes/hex/dec.pat
Normal file
11
includes/hex/dec.pat
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
|
||||
namespace hex::dec {
|
||||
|
||||
fn demangle(str mangled_name) {
|
||||
return builtin::hex::dec::demangle(mangled_name);
|
||||
};
|
||||
|
||||
}
|
||||
11
includes/hex/http.pat
Normal file
11
includes/hex/http.pat
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
|
||||
namespace hex::http {
|
||||
|
||||
fn get(str url) {
|
||||
return builtin::hex::http::get(url);
|
||||
};
|
||||
|
||||
}
|
||||
7
includes/hex/impl/imhex_check.pat
Normal file
7
includes/hex/impl/imhex_check.pat
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __PL_UNIT_TESTS__
|
||||
#ifndef __IMHEX__
|
||||
|
||||
#error This library is only available in the ImHex Hex editor
|
||||
|
||||
#endif
|
||||
#endif
|
||||
23
includes/hex/type/mangled.pat
Normal file
23
includes/hex/type/mangled.pat
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
#include <hex/impl/imhex_check.pat>
|
||||
#include <hex/dec.pat>
|
||||
|
||||
namespace hex::type {
|
||||
|
||||
struct MangledName {
|
||||
char value[];
|
||||
} [[sealed, format("hex::type::impl::format_mangled_name")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_mangled_name(ref MangledName name) {
|
||||
return hex::dec::demangle(name.value);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace std {
|
||||
|
||||
using uint8_t = u8;
|
||||
using uint16_t = u16;
|
||||
using uint32_t = u32;
|
||||
using uint64_t = u64;
|
||||
using uint128_t = u128;
|
||||
|
||||
using int8_t = s8;
|
||||
using int16_t = s16;
|
||||
using int32_t = s32;
|
||||
using int64_t = s64;
|
||||
using int128_t = s128;
|
||||
|
||||
using float32_t = float;
|
||||
using float64_t = double;
|
||||
|
||||
using size_t = u64;
|
||||
using ssize_t = s64;
|
||||
|
||||
}
|
||||
57
includes/std/core.pat
Normal file
57
includes/std/core.pat
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace std::core {
|
||||
|
||||
enum BitfieldOrder : u8 {
|
||||
LeftToRight = 0,
|
||||
RightToLeft = 1
|
||||
};
|
||||
|
||||
|
||||
fn has_attribute(ref auto pattern, str attribute) {
|
||||
return builtin::std::core::has_attribute(pattern, attribute);
|
||||
};
|
||||
|
||||
|
||||
fn get_attribute_value(ref auto pattern, str attribute) {
|
||||
return builtin::std::core::get_attribute_value(pattern, attribute);
|
||||
};
|
||||
|
||||
|
||||
fn set_endian(std::mem::Endian endian) {
|
||||
builtin::std::core::set_endian(u32(endian));
|
||||
};
|
||||
|
||||
fn get_endian() {
|
||||
return builtin::std::core::get_endian();
|
||||
};
|
||||
|
||||
|
||||
fn set_bitfield_order(BitfieldOrder order) {
|
||||
builtin::std::core::set_bitfield_order(order);
|
||||
};
|
||||
|
||||
fn get_bitfield_order() {
|
||||
return builtin::std::core::get_bitfield_order();
|
||||
};
|
||||
|
||||
|
||||
fn array_index() {
|
||||
return builtin::std::core::array_index();
|
||||
};
|
||||
|
||||
fn member_count(ref auto pattern) {
|
||||
return builtin::std::core::member_count(pattern);
|
||||
};
|
||||
|
||||
fn has_member(ref auto pattern, str name) {
|
||||
return builtin::std::core::has_member(pattern, name);
|
||||
};
|
||||
|
||||
fn formatted_value(ref auto pattern) {
|
||||
return builtin::std::core::formatted_value(pattern);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace std::file {
|
||||
|
||||
|
||||
fn open(str path, Mode mode) {
|
||||
return builtin::std::file::open(path, mode);
|
||||
return builtin::std::file::open(path, u32(mode));
|
||||
};
|
||||
|
||||
fn close(Handle handle) {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::http {
|
||||
|
||||
fn get(str url) {
|
||||
return builtin::std::http::get(url);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace std::mem {
|
||||
|
||||
enum Endian : u8 {
|
||||
Native = 0,
|
||||
Big = 1,
|
||||
Little = 2
|
||||
};
|
||||
|
||||
fn eof() {
|
||||
return $ >= std::mem::size();
|
||||
};
|
||||
@@ -29,12 +35,12 @@ namespace std::mem {
|
||||
return builtin::std::mem::find_sequence_in_range(occurrence_index, offsetFrom, offsetTo, bytes);
|
||||
};
|
||||
|
||||
fn read_unsigned(u128 address, u8 size) {
|
||||
return builtin::std::mem::read_unsigned(address, size);
|
||||
fn read_unsigned(u128 address, u8 size, Endian endian = Endian::Native) {
|
||||
return builtin::std::mem::read_unsigned(address, size, u32(endian));
|
||||
};
|
||||
|
||||
fn read_signed(u128 address, u8 size) {
|
||||
return builtin::std::mem::read_signed(address, size);
|
||||
fn read_signed(u128 address, u8 size, Endian endian = Endian::Native) {
|
||||
return builtin::std::mem::read_signed(address, size, u32(endian));
|
||||
};
|
||||
|
||||
fn read_string(u128 address, u8 size) {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace std {
|
||||
|
||||
using i8 = s8;
|
||||
using i16 = s16;
|
||||
using i32 = s32;
|
||||
using i64 = s64;
|
||||
using i128 = s128;
|
||||
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
using usize = u64;
|
||||
using isize = s64;
|
||||
|
||||
}
|
||||
@@ -39,15 +39,12 @@ namespace std::string {
|
||||
};
|
||||
|
||||
fn contains(str a, str b) {
|
||||
s32 a_len, b_len;
|
||||
a_len = std::string::length(a);
|
||||
b_len = std::string::length(b);
|
||||
s32 a_len = std::string::length(a);
|
||||
s32 b_len = std::string::length(b);
|
||||
|
||||
s32 i;
|
||||
while (i < a_len - b_len) {
|
||||
for (s32 i = 0, i <= (a_len - b_len), i += 1) {
|
||||
if (std::string::substr(a, i, b_len) == b)
|
||||
return true;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
44
includes/type/color.pat
Normal file
44
includes/type/color.pat
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct RGBA8 {
|
||||
u8 r, g, b, a;
|
||||
} [[sealed, format("type::impl::format_color")]];
|
||||
|
||||
bitfield RGB565 {
|
||||
r : 5;
|
||||
g : 6;
|
||||
b : 5;
|
||||
} [[sealed, format("type::impl::format_color")]];
|
||||
|
||||
bitfield RGBA4 {
|
||||
r : 4;
|
||||
g : 4;
|
||||
b : 4;
|
||||
a : 4;
|
||||
} [[sealed, format("type::impl::format_color")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_color(ref auto color) {
|
||||
if (!std::core::has_member(color, "a")) {
|
||||
return std::format("#{0:02X}{1:02X}{2:02X} | rgb({0}, {1}, {2})",
|
||||
color.r,
|
||||
color.g,
|
||||
color.b);
|
||||
} else {
|
||||
return std::format("#{0:02X}{1:02X}{2:02X}{3:02X} | rgba({0}, {1}, {2}, {3})",
|
||||
color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
color.a);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,23 +7,46 @@ namespace type {
|
||||
|
||||
using float16 = u16 [[format("type::impl::format_float16")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_float16(float16 value) {
|
||||
float sign = (value >> 15) == 0b01 ? -1.0 : 1.0;
|
||||
float exponent = std::math::pow(2.0, float((value >> 10) & 0x1F) - 14);
|
||||
u16 mantissa = value & 0x3FF;
|
||||
|
||||
float fraction = 0;
|
||||
for (s8 i = 9, i >= 0, i -= 1) {
|
||||
if ((mantissa & (1 << i)) != 0) {
|
||||
fraction += 1.0 / std::math::pow(2.0, (10.0 - i));
|
||||
}
|
||||
}
|
||||
|
||||
return std::format("{:f}", sign * exponent * fraction);
|
||||
namespace impl {
|
||||
|
||||
union U32ToFloatConverter {
|
||||
u32 intValue;
|
||||
float floatValue;
|
||||
};
|
||||
|
||||
}
|
||||
fn format_float16(float16 value) {
|
||||
u32 sign = value >> 15;
|
||||
u32 exponent = (value >> 10) & 0x1F;
|
||||
u32 mantissa = value & 0x3FF;
|
||||
|
||||
u32 result = 0x00;
|
||||
|
||||
if (exponent == 0) {
|
||||
if (mantissa == 0) {
|
||||
result = sign << 31;
|
||||
} else {
|
||||
exponent = 0x7F - 14;
|
||||
|
||||
while ((mantissa & (1 << 10)) == 0) {
|
||||
exponent -= 1;
|
||||
mantissa <<= 1;
|
||||
}
|
||||
|
||||
mantissa &= 0x3FF;
|
||||
result = (sign << 31) | (exponent << 23) | (mantissa << 13);
|
||||
}
|
||||
} else if (exponent == 0x1F) {
|
||||
result = (sign << 31) | (0xFF << 23) | (mantissa << 13);
|
||||
} else {
|
||||
result = (sign << 31) | ((exponent + (0x7F - 15)) << 23) | (mantissa << 13);
|
||||
}
|
||||
|
||||
U32ToFloatConverter converter;
|
||||
converter.intValue = result;
|
||||
|
||||
return std::format("{}", converter.floatValue);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,36 +4,53 @@
|
||||
|
||||
namespace type {
|
||||
|
||||
struct IPv4Address {
|
||||
u8 bytes[4];
|
||||
} [[sealed, format("type::impl::format_ipv4_address")]];
|
||||
struct IPv4Address {
|
||||
u8 bytes[4];
|
||||
} [[sealed, format("type::impl::format_ipv4_address")]];
|
||||
|
||||
struct IPv6Address {
|
||||
u16 words[8];
|
||||
} [[sealed, format("type::impl::format_ipv6_address")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_ipv4_address(IPv4Address address) {
|
||||
return std::format("{}.{}.{}.{}",
|
||||
address.bytes[0],
|
||||
address.bytes[1],
|
||||
address.bytes[2],
|
||||
address.bytes[3]);
|
||||
};
|
||||
u16 words[8];
|
||||
} [[sealed, format("type::impl::format_ipv6_address")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_ipv4_address(IPv4Address address) {
|
||||
return std::format("{}.{}.{}.{}",
|
||||
address.bytes[0],
|
||||
address.bytes[1],
|
||||
address.bytes[2],
|
||||
address.bytes[3]);
|
||||
};
|
||||
|
||||
fn format_ipv6_address(IPv6Address address) {
|
||||
return std::format("{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}:{:04X}",
|
||||
address.words[0],
|
||||
address.words[1],
|
||||
address.words[2],
|
||||
address.words[3],
|
||||
address.words[4],
|
||||
address.words[5],
|
||||
address.words[6],
|
||||
address.words[7]);
|
||||
};
|
||||
|
||||
}
|
||||
str result;
|
||||
|
||||
bool hadZeros = false;
|
||||
s8 startIndex = -1;
|
||||
|
||||
for (u8 i = 0, i < 8, i += 1) {
|
||||
if (address.words[i] == 0x00 && !hadZeros) {
|
||||
hadZeros = true;
|
||||
startIndex = i;
|
||||
|
||||
while (i < 7) {
|
||||
if (address.words[i + 1] != 0x00)
|
||||
break;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
if (startIndex == 0 || i == 7)
|
||||
result += ":";
|
||||
} else {
|
||||
result += std::format("{:04X}", address.words[i]);
|
||||
}
|
||||
|
||||
result += ":";
|
||||
}
|
||||
|
||||
return std::string::substr(result, 0, std::string::length(result) - 1);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
33
includes/type/leb128.pat
Normal file
33
includes/type/leb128.pat
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct LEB128 {
|
||||
u8 array[while($ == addressof(this) || std::mem::read_unsigned($-1, 1) & 0x80 != 0)] [[hidden]];
|
||||
} [[sealed, format("type::impl::format_leb128"), transform("type::impl::transform_leb128")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn transform_leb128_array(auto array) {
|
||||
u128 res = array[0] & 0x7f;
|
||||
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
|
||||
res |= u64(array[i] & 0x7f) << 7 * i;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn format_leb128(auto leb128) {
|
||||
u128 res = type::impl::transform_leb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_leb128(auto leb128) {
|
||||
return type::impl::transform_leb128_array(leb128.array);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
includes/type/path.pat
Normal file
32
includes/type/path.pat
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct UnixPathSegment {
|
||||
char string[while(std::mem::read_unsigned($, 1) != '/' && std::mem::read_unsigned($, 1) != 0x00)];
|
||||
char separator [[hidden]];
|
||||
|
||||
if (separator == 0x00) {
|
||||
$ -= 1;
|
||||
break;
|
||||
}
|
||||
} [[sealed, format("type::impl::format_unix_path_segment")]];
|
||||
|
||||
struct UnixPath {
|
||||
UnixPathSegment segments[while(true)];
|
||||
} [[format("type::impl::format_unix_path")]];
|
||||
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_unix_path_segment(UnixPathSegment segment) {
|
||||
return segment.string;
|
||||
};
|
||||
|
||||
fn format_unix_path(UnixPath path) {
|
||||
return std::mem::read_string($, sizeof(path));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
48
includes/type/size.pat
Normal file
48
includes/type/size.pat
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <std/io.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
using Size8 = u8 [[format("type::impl::size_formatter")]];
|
||||
using Size16 = u16 [[format("type::impl::size_formatter")]];
|
||||
using Size32 = u32 [[format("type::impl::size_formatter")]];
|
||||
using Size64 = u64 [[format("type::impl::size_formatter")]];
|
||||
using Size128 = u128 [[format("type::impl::size_formatter")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn size_formatter(u128 size) {
|
||||
double sizeFloat = size;
|
||||
|
||||
u32 i = 0;
|
||||
while (sizeFloat >= 1024 && i <= 6) {
|
||||
i += 1;
|
||||
sizeFloat /= 1024;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
if (size == 1)
|
||||
return std::format("{} Byte", size);
|
||||
else
|
||||
return std::format("{} Bytes", size);
|
||||
} else {
|
||||
str result = std::format("{:.3f} ", sizeFloat);
|
||||
|
||||
if (i == 1)
|
||||
return result + "kiB";
|
||||
else if (i == 2)
|
||||
return result + "MiB";
|
||||
else if (i == 3)
|
||||
return result + "GiB";
|
||||
else if (i == 4)
|
||||
return result + "TiB";
|
||||
else if (i == 5)
|
||||
return result + "PiB";
|
||||
else
|
||||
return result + "EiB";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
|
||||
namespace type {
|
||||
|
||||
using time_t = u16 [[format("type::impl::format_time_t")]];
|
||||
using time32_t = u32 [[format("type::impl::format_time_t")]];
|
||||
using time64_t = u64 [[format("type::impl::format_time_t")]];
|
||||
|
||||
namespace impl {
|
||||
namespace impl {
|
||||
|
||||
fn format_time_t(time_t value) {
|
||||
fn format_time_t(u128 value) {
|
||||
return std::time::format(std::time::to_utc(value));
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
62
includes/type/types/010.pat
Normal file
62
includes/type/types/010.pat
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
|
||||
// using char = s8;
|
||||
using byte = s8;
|
||||
using CHAR = s8;
|
||||
using BYTE = s8;
|
||||
|
||||
using uchar = u8;
|
||||
using ubyte = u8;
|
||||
using UCHAR = u8;
|
||||
using UBYTE = u8;
|
||||
|
||||
|
||||
using short = s16;
|
||||
using int16 = s16;
|
||||
using SHORT = s16;
|
||||
using INT16 = s16;
|
||||
|
||||
using ushort = u16;
|
||||
using uint16 = u16;
|
||||
using USHORT = u16;
|
||||
using UINT16 = u16;
|
||||
using WORD = u16;
|
||||
|
||||
using int = s32;
|
||||
using int32 = s32;
|
||||
using long = s32;
|
||||
using INT = s32;
|
||||
using INT32 = s32;
|
||||
using LONG = s32;
|
||||
|
||||
using uint = u32;
|
||||
using uint32 = u32;
|
||||
using ulong = u32;
|
||||
using UINT = u32;
|
||||
using UINT32 = u32;
|
||||
using ULONG = u32;
|
||||
using DWORD = u32;
|
||||
|
||||
using int64 = s64;
|
||||
using quad = s64;
|
||||
using QUAD = s64;
|
||||
using INT64 = s64;
|
||||
using __int64 = s64;
|
||||
|
||||
using uint64 = u64;
|
||||
using uquad = u64;
|
||||
using UQUAD = u64;
|
||||
using UINT64 = u64;
|
||||
using QWORD = u64;
|
||||
using __uint64 = u64;
|
||||
|
||||
// using float = float;
|
||||
using FLOAT = float;
|
||||
|
||||
// using double = double;
|
||||
using DOUBLE = double;
|
||||
|
||||
// }
|
||||
39
includes/type/types/c.pat
Normal file
39
includes/type/types/c.pat
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
|
||||
using uint8_t = u8;
|
||||
using uint16_t = u16;
|
||||
using uint32_t = u32;
|
||||
using uint64_t = u64;
|
||||
using __uint64_t = u64;
|
||||
using uint128_t = u128;
|
||||
using __uint128_t = u128;
|
||||
|
||||
using int8_t = s8;
|
||||
using int16_t = s16;
|
||||
using int32_t = s32;
|
||||
using int64_t = s64;
|
||||
using __int64_t = s64;
|
||||
using int128_t = s128;
|
||||
using __int128_t = s128;
|
||||
|
||||
using size_t = u64;
|
||||
using ssize_t = s64;
|
||||
|
||||
using uintptr_t = u64;
|
||||
using intptr_t = s64;
|
||||
using ptrdiff_t = s64;
|
||||
|
||||
// using char = char;
|
||||
using wchar_t = char16;
|
||||
using char8_t = char;
|
||||
using char16_t = char16;
|
||||
using char32_t = u32;
|
||||
|
||||
using short = s16;
|
||||
using int = s32;
|
||||
using long = s32;
|
||||
|
||||
// }
|
||||
13
includes/type/types/linux.pat
Normal file
13
includes/type/types/linux.pat
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
|
||||
using le16 = le u16;
|
||||
using be16 = be u16;
|
||||
using le32 = le u32;
|
||||
using be32 = be u32;
|
||||
using le64 = le u64;
|
||||
using be64 = be u64;
|
||||
|
||||
// }
|
||||
24
includes/type/types/rust.pat
Normal file
24
includes/type/types/rust.pat
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
|
||||
// using u8 = u8;
|
||||
// using u16 = u16;
|
||||
// using u32 = u32;
|
||||
// using u64 = u64;
|
||||
// using u128 = u128;
|
||||
|
||||
using i8 = s8;
|
||||
using i16 = s16;
|
||||
using i32 = s32;
|
||||
using i64 = s64;
|
||||
using i128 = s128;
|
||||
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
using usize = u64;
|
||||
using isize = i64;
|
||||
|
||||
// }
|
||||
53
includes/type/types/win32.pat
Normal file
53
includes/type/types/win32.pat
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
// Explicitly don't add these types to the `type` namespace for usability
|
||||
// namespace type {
|
||||
|
||||
using BYTE = u8;
|
||||
using WORD = u16;
|
||||
using DWORD = u32;
|
||||
using QWORD = u64;
|
||||
using DWORDLONG = u64;
|
||||
using DWORD32 = u32;
|
||||
using DWORD64 = u64;
|
||||
|
||||
using INT = s32;
|
||||
using UINT = u32;
|
||||
using FLOAT = float;
|
||||
using SHORT = s16;
|
||||
using USHORT = u16;
|
||||
using BOOL = bool;
|
||||
using BOOLEAN = bool;
|
||||
|
||||
using INT8 = s8;
|
||||
using INT16 = s16;
|
||||
using INT32 = s32;
|
||||
using INT64 = s64;
|
||||
using UINT8 = u8;
|
||||
using UINT16 = u16;
|
||||
using UINT32 = u32;
|
||||
using UINT64 = u64;
|
||||
|
||||
using LONG = s32;
|
||||
using ULONG = u32;
|
||||
using LONG32 = s32;
|
||||
using ULONG32 = u32;
|
||||
using LONG64 = s64;
|
||||
using ULONG64 = u64;
|
||||
using LONGLONG = s64;
|
||||
using ULONGLONG = u64;
|
||||
|
||||
using SIZE_T = u64;
|
||||
using SSIZE_T = s64;
|
||||
|
||||
using UCHAR = u8;
|
||||
using CHAR = char;
|
||||
using CCHAR = char;
|
||||
|
||||
using ATOM = WORD;
|
||||
using PVOID = SIZE_T;
|
||||
using HANDLE = PVOID;
|
||||
using HINSTANCE = HANDLE;
|
||||
using HRESULT = LONG;
|
||||
|
||||
// }
|
||||
73
patterns/bencode.hexpat
Normal file
73
patterns/bencode.hexpat
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma MIME application/x-bittorrent
|
||||
|
||||
#include <std/ctype.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
namespace bencode {
|
||||
|
||||
struct ASCIIDecimal {
|
||||
char value[while(std::ctype::isdigit(std::mem::read_unsigned($, 1)))];
|
||||
} [[sealed, format("bencode::format_ascii_decimal"), transform("bencode::format_ascii_decimal")]];
|
||||
|
||||
fn format_ascii_decimal(ASCIIDecimal adsasd) {
|
||||
return std::string::parse_int(adsasd.value, 10);
|
||||
};
|
||||
|
||||
enum Type : u8 {
|
||||
Integer = 'i',
|
||||
Dictionary = 'd',
|
||||
List = 'l',
|
||||
|
||||
String0 = '0',
|
||||
String1 = '1',
|
||||
String2 = '2',
|
||||
String3 = '3',
|
||||
String4 = '4',
|
||||
String5 = '5',
|
||||
String6 = '6',
|
||||
String7 = '7',
|
||||
String8 = '8',
|
||||
String9 = '9'
|
||||
};
|
||||
|
||||
struct String {
|
||||
ASCIIDecimal length;
|
||||
char separator [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("bencode::format_string"), transform("bencode::format_string")]];
|
||||
|
||||
fn format_string(String string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
using Bencode;
|
||||
using Value;
|
||||
|
||||
struct DictionaryEntry {
|
||||
String key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
struct Value {
|
||||
Type type;
|
||||
|
||||
if (type == Type::Dictionary) {
|
||||
DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')];
|
||||
} else if (type == Type::Integer) {
|
||||
ASCIIDecimal value;
|
||||
char end;
|
||||
} else {
|
||||
$ -= 1;
|
||||
String value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Bencode {
|
||||
Value value[while(!std::mem::eof())] [[inline]];
|
||||
char end;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bencode::Bencode bencode @ 0x00;
|
||||
128
patterns/bson.hexpat
Normal file
128
patterns/bson.hexpat
Normal file
@@ -0,0 +1,128 @@
|
||||
#pragma MIME application/bson
|
||||
|
||||
#include <type/time.pat>
|
||||
|
||||
enum Type : u8 {
|
||||
Double = 0x01,
|
||||
String = 0x02,
|
||||
EmbeddedDocument = 0x03,
|
||||
Array = 0x04,
|
||||
Binary = 0x05,
|
||||
Undefined = 0x06,
|
||||
ObjectId = 0x07,
|
||||
Boolean = 0x08,
|
||||
UTCDatetime = 0x09,
|
||||
Null = 0x0A,
|
||||
Regex = 0x0B,
|
||||
DBPointer = 0x0C,
|
||||
JavaScript = 0x0D,
|
||||
Symbol = 0x0E,
|
||||
JavaScriptWithScope = 0x0F,
|
||||
Int32 = 0x10,
|
||||
Timestamp = 0x11,
|
||||
Int64 = 0x12,
|
||||
Decimal128 = 0x13,
|
||||
|
||||
MinKey = 0xFF,
|
||||
MaxKey = 0x7F
|
||||
};
|
||||
|
||||
enum Subtype : u8 {
|
||||
GenericBinarySubtype = 0x00,
|
||||
Function = 0x01,
|
||||
BinaryOld = 0x02,
|
||||
UUIDOld = 0x03,
|
||||
UUID = 0x04,
|
||||
MD5 = 0x05,
|
||||
EncryptedBSONValue = 0x06,
|
||||
CompressedBSONColumn = 0x07,
|
||||
UserDefined = 0x80
|
||||
};
|
||||
|
||||
struct Binary {
|
||||
s32 length;
|
||||
Subtype subtype;
|
||||
u8 data[length];
|
||||
};
|
||||
|
||||
struct String {
|
||||
u32 length [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
struct CString {
|
||||
char value[];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
fn format_string(auto string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
struct ObjectId {
|
||||
type::time32_t timestamp;
|
||||
u8 randomValue[5];
|
||||
u24 counter;
|
||||
};
|
||||
|
||||
struct DBPointer {
|
||||
String name;
|
||||
ObjectId value;
|
||||
};
|
||||
|
||||
|
||||
using Document;
|
||||
|
||||
struct Element {
|
||||
Type type;
|
||||
|
||||
CString name;
|
||||
|
||||
if (type == Type::Double) {
|
||||
double value;
|
||||
} else if (type == Type::String) {
|
||||
String value;
|
||||
} else if (type == Type::EmbeddedDocument) {
|
||||
Document value;
|
||||
} else if (type == Type::Array) {
|
||||
Document value;
|
||||
} else if (type == Type::Binary) {
|
||||
Binary value;
|
||||
} else if (type == Type::Undefined) {
|
||||
/* undefined */
|
||||
} else if (type == Type::ObjectId) {
|
||||
ObjectId value;
|
||||
} else if (type == Type::Boolean) {
|
||||
bool value;
|
||||
} else if (type == Type::UTCDatetime) {
|
||||
type::time64_t value;
|
||||
} else if (type == Type::Null) {
|
||||
/* null */
|
||||
} else if (type == Type::Regex) {
|
||||
CString regexPattern;
|
||||
CString regexOptions;
|
||||
} else if (type == Type::DBPointer) {
|
||||
DBPointer value;
|
||||
} else if (type == Type::JavaScript) {
|
||||
String value;
|
||||
} else if (type == Type::Symbol) {
|
||||
String value;
|
||||
} else if (type == Type::JavaScriptWithScope) {
|
||||
String value;
|
||||
} else if (type == Type::Int32) {
|
||||
s32 value;
|
||||
} else if (type == Type::Timestamp) {
|
||||
u64 value;
|
||||
} else if (type == Type::Int64) {
|
||||
s64 value;
|
||||
} else if (type == Type::Decimal128) {
|
||||
u128 value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Document {
|
||||
s32 listLength;
|
||||
Element elements[while($ < ((addressof(this) + listLength) - 1))];
|
||||
padding[1];
|
||||
};
|
||||
|
||||
Document document @ 0x00;
|
||||
@@ -1,261 +1,742 @@
|
||||
#pragma MIME application/x-executable
|
||||
#pragma MIME application/x-elf
|
||||
#pragma MIME application/x-coredump
|
||||
#pragma MIME application/x-object
|
||||
#pragma MIME application/x-sharedlib
|
||||
|
||||
namespace elf {
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
enum Class : u8 {
|
||||
_32Bit = 1,
|
||||
_64Bit = 2
|
||||
};
|
||||
|
||||
enum Endian : u8 {
|
||||
Little = 1,
|
||||
Big = 2
|
||||
};
|
||||
|
||||
enum OSABI : u8 {
|
||||
SystemV = 0x00,
|
||||
HP_UX = 0x01,
|
||||
NetBSD = 0x02,
|
||||
Linux = 0x03,
|
||||
GNU_Hurd = 0x04,
|
||||
Solaris = 0x06,
|
||||
AIX = 0x07,
|
||||
IRIX = 0x08,
|
||||
FreeBSD = 0x09,
|
||||
Tru64 = 0x0A,
|
||||
NovellModesto = 0x0B,
|
||||
OpenBSD = 0x0C,
|
||||
OpenVMS = 0x0D,
|
||||
NonStop_Kernel = 0x0E,
|
||||
AROS = 0x0F,
|
||||
FenixOS = 0x10,
|
||||
CloudABI = 0x11,
|
||||
Stratus_Technologies_OpenVOS = 0x12
|
||||
};
|
||||
|
||||
enum Type : u16 {
|
||||
using EI_ABIVERSION = u8;
|
||||
using Elf32_Addr = u32;
|
||||
using Elf32_BaseAddr = u32;
|
||||
using Elf32_BaseOff = u32;
|
||||
using Elf32_Half = u16;
|
||||
using Elf32_Off = u32;
|
||||
using Elf32_Sword = s32;
|
||||
using Elf32_VAddr = u32;
|
||||
using Elf32_Word = u32;
|
||||
using Elf64_Addr = u64;
|
||||
using Elf64_BaseAddr = u64;
|
||||
using Elf64_BaseOff = u64;
|
||||
using Elf64_Half = u16;
|
||||
using Elf64_Off = u64;
|
||||
using Elf64_Sword = s32;
|
||||
using Elf64_Sxword = s64;
|
||||
using Elf64_VAddr = u64;
|
||||
using Elf64_Word = u32;
|
||||
using Elf64_Xword = u64;
|
||||
using E_VERSION = u32;
|
||||
|
||||
enum EI_CLASS : u8 {
|
||||
ELFCLASSNONE = 0x00,
|
||||
ELFCLASS32 = 0x01,
|
||||
ELFCLASS64 = 0x02,
|
||||
};
|
||||
|
||||
enum EI_DATA : u8 {
|
||||
ELFDATANONE = 0x00,
|
||||
ELFDATA2LSB = 0x01,
|
||||
ELFDATA2MSB = 0x02,
|
||||
};
|
||||
|
||||
enum EI_OSABI : u8 {
|
||||
SYSV = 0x00,
|
||||
HPUX = 0x01,
|
||||
NetBSD = 0x02,
|
||||
Linux = 0x03,
|
||||
GNUHurd = 0x04,
|
||||
Solaris = 0x06,
|
||||
AIX = 0x07,
|
||||
IRIX = 0x08,
|
||||
FreeBSD = 0x09,
|
||||
Tru64 = 0x0A,
|
||||
NovellModesto = 0x0B,
|
||||
OpenBSD = 0x0C,
|
||||
OpenVMS = 0x0D,
|
||||
NonStopKernel = 0x0E,
|
||||
AROS = 0x0F,
|
||||
FenixOS = 0x10,
|
||||
CloudABI = 0x11,
|
||||
OpenVOS = 0x12,
|
||||
ARM_EABI = 0x40,
|
||||
STANDALONE = 0xFF,
|
||||
};
|
||||
|
||||
enum EI_VERSION : u8 {
|
||||
NONE = 0x00,
|
||||
REL = 0x01,
|
||||
EXEC = 0x02,
|
||||
DYN = 0x03,
|
||||
CORE = 0x04,
|
||||
LOOS = 0xFE00,
|
||||
HIOS = 0xFEFF,
|
||||
LOPROC = 0xFF00,
|
||||
HIPROC = 0xFFFF
|
||||
};
|
||||
|
||||
enum Machine : u16 {
|
||||
Undefined = 0x00,
|
||||
ATNT_WE_32100 = 0x01,
|
||||
SPARC = 0x02,
|
||||
x86 = 0x03,
|
||||
Motorola_68000 = 0x04,
|
||||
Motorola_88000 = 0x05,
|
||||
IntelMCU = 0x06,
|
||||
Intel_80860 = 0x07,
|
||||
MIPS = 0x08,
|
||||
IBM_System370 = 0x09,
|
||||
MIPS_RS300_LE = 0x0A,
|
||||
/* 0x0B - 0x0D: Reserved */
|
||||
HP_PA_RISC = 0x0E,
|
||||
/* 0x0F: Reserved */
|
||||
Intel_80960 = 0x13,
|
||||
PowerPC = 0x14,
|
||||
PowerPC_64 = 0x15,
|
||||
S390 = 0x16,
|
||||
IBM_SPU_SPC = 0x17,
|
||||
/* 0x18 - 0x23: Reserved */
|
||||
NEC_V800 = 0x24,
|
||||
Fujitsu_FR20 = 0x25,
|
||||
TRW_RH_32 = 0x26,
|
||||
Motorola_RCE = 0x27,
|
||||
ARM32 = 0x28,
|
||||
Digital_Alpha = 0x29,
|
||||
SuperH = 0x2A,
|
||||
SPARCv9 = 0x2B,
|
||||
Siemens_TriCore = 0x2C,
|
||||
Argonaut_RISC_Core = 0x2D,
|
||||
Hitachi_H8_300 = 0x2E,
|
||||
Hitachi_H8_300H = 0x2F,
|
||||
Hitachi_H8S = 0x30,
|
||||
Hitachi_H8_500 = 0x31,
|
||||
IA_64 = 0x32,
|
||||
Standford_MIPS_X = 0x33,
|
||||
Motorola_ColdFire = 0x34,
|
||||
Motorola_M68HC12 = 0x35,
|
||||
Fujitsu_MMA = 0x36,
|
||||
Siemens_PCP = 0x37,
|
||||
Sony_nCPU = 0x38,
|
||||
Denso_NDR1 = 0x39,
|
||||
Motorola_StarCore = 0x3A,
|
||||
Toyota_ME16 = 0x3B,
|
||||
STMicroelectronics_ST100 = 0x3C,
|
||||
Advanced_Logic_Corp_TinyJ = 0x3D,
|
||||
AMD_x86_64 = 0x3E,
|
||||
TMS320C6000 = 0x8C,
|
||||
MCST_Elbrus_e2k = 0xAF,
|
||||
ARM64 = 0xB7,
|
||||
RISC_V = 0xF3,
|
||||
Berkeley_Packet_Filter = 0xF7,
|
||||
WDC_65C816 = 0x101
|
||||
};
|
||||
|
||||
struct Identity {
|
||||
char magic[4];
|
||||
Class class;
|
||||
Endian endian;
|
||||
u8 version;
|
||||
OSABI os_abi;
|
||||
|
||||
if (os_abi == elf::OSABI::Linux)
|
||||
u8 dynamic_linker_version;
|
||||
else
|
||||
u8 abi_version;
|
||||
};
|
||||
CURRENT = 0x01,
|
||||
};
|
||||
|
||||
struct Header {
|
||||
Identity identity;
|
||||
enum EM : u16 {
|
||||
EM_NONE = 0x0000,
|
||||
EM_M32 = 0x0001,
|
||||
EM_SPARC = 0x0002,
|
||||
EM_386 = 0x0003,
|
||||
EM_68K = 0x0004,
|
||||
EM_88K = 0x0005,
|
||||
EM_IAMCU = 0x0006,
|
||||
EM_860 = 0x0007,
|
||||
EM_MIPS = 0x0008,
|
||||
EM_S370 = 0x0009,
|
||||
EM_MIPS_RS4_BE = 0x000a,
|
||||
EM_PARISC = 0x000f,
|
||||
EM_VPP500 = 0x0011,
|
||||
EM_SPARC32PLUS = 0x0012,
|
||||
EM_960 = 0x0013,
|
||||
EM_PPC = 0x0014,
|
||||
EM_PPC64 = 0x0015,
|
||||
EM_S390 = 0x0016,
|
||||
EM_SPU = 0x0017,
|
||||
EM_V800 = 0x0024,
|
||||
EM_FR20 = 0x0025,
|
||||
EM_RH32 = 0x0026,
|
||||
EM_RCE = 0x0027,
|
||||
EM_ARM = 0x0028,
|
||||
EM_ALPHA = 0x0029,
|
||||
EM_SH = 0x002A,
|
||||
EM_SPARCV9 = 0x002B,
|
||||
EM_TRICORE = 0x002C,
|
||||
EM_ARC = 0x002D,
|
||||
EM_H8_300 = 0x002E,
|
||||
EM_H8_300H = 0x002F,
|
||||
EM_H8S = 0x0030,
|
||||
EM_H8_500 = 0x0031,
|
||||
EM_IA_64 = 0x0032,
|
||||
EM_MIPS_X = 0x0033,
|
||||
EM_COLDFIRE = 0x0034,
|
||||
EM_68HC12 = 0x0035,
|
||||
EM_MMA = 0x0036,
|
||||
EM_PCP = 0x0037,
|
||||
EM_NCPU = 0x0038,
|
||||
EM_NDR1 = 0x0039,
|
||||
EM_STARCORE = 0x003A,
|
||||
EM_ME16 = 0x003B,
|
||||
EM_ST100 = 0x003C,
|
||||
EM_TINYJ = 0x003D,
|
||||
EM_X86_64 = 0x003E,
|
||||
EM_PDSP = 0x003F,
|
||||
EM_PDP10 = 0x0040,
|
||||
EM_PDP11 = 0x0041,
|
||||
EM_FX66 = 0x0042,
|
||||
EM_ST9PLUS = 0x0043,
|
||||
EM_ST7 = 0x0044,
|
||||
EM_68HC16 = 0x0045,
|
||||
EM_68HC11 = 0x0046,
|
||||
EM_68HC08 = 0x0047,
|
||||
EM_68HC05 = 0x0048,
|
||||
EM_SVX = 0x0049,
|
||||
EM_ST19 = 0x004A,
|
||||
EM_VAX = 0x004B,
|
||||
EM_CRIS = 0x004C,
|
||||
EM_JAVELIN = 0x004D,
|
||||
EM_FIREPATH = 0x004E,
|
||||
EM_ZSP = 0x004F,
|
||||
EM_MMIX = 0x0050,
|
||||
EM_HUANY = 0x0051,
|
||||
EM_PRISM = 0x0052,
|
||||
EM_AVR = 0x0053,
|
||||
EM_FR30 = 0x0054,
|
||||
EM_D10V = 0x0055,
|
||||
EM_D30V = 0x0056,
|
||||
EM_V850 = 0x0057,
|
||||
EM_M32R = 0x0058,
|
||||
EM_MN10300 = 0x0059,
|
||||
EM_MN10200 = 0x005A,
|
||||
EM_PJ = 0x005B,
|
||||
EM_OPENRISC = 0x005C,
|
||||
EM_ARC_COMPACT = 0x005D,
|
||||
EM_XTENSA = 0x005E,
|
||||
EM_VIDEOCORE = 0x005F,
|
||||
EM_TMM_GPP = 0x0060,
|
||||
EM_NS32K = 0x0061,
|
||||
EM_TPC = 0x0062,
|
||||
EM_SNP1K = 0x0063,
|
||||
EM_ST200 = 0x0064,
|
||||
EM_IP2K = 0x0065,
|
||||
EM_MAX = 0x0066,
|
||||
EM_CR = 0x0067,
|
||||
EM_F2MC16 = 0x0068,
|
||||
EM_MSP430 = 0x0069,
|
||||
EM_BLACKFIN = 0x006A,
|
||||
EM_SE_C33 = 0x006B,
|
||||
EM_SEP = 0x006C,
|
||||
EM_ARCA = 0x006D,
|
||||
EM_UNICORE = 0x006E,
|
||||
EM_EXCESS = 0x006F,
|
||||
EM_DXP = 0x0070,
|
||||
EM_ALTERA_NIOS2 = 0x0071,
|
||||
EM_CRX = 0x0072,
|
||||
EM_XGATE = 0x0073,
|
||||
EM_C166 = 0x0074,
|
||||
EM_M16C = 0x0075,
|
||||
EM_DSPIC30F = 0x0076,
|
||||
EM_CE = 0x0077,
|
||||
EM_M32C = 0x0078,
|
||||
EM_TSK3000 = 0x0083,
|
||||
EM_RS08 = 0x0084,
|
||||
EM_SHARC = 0x0085,
|
||||
EM_ECOG2 = 0x0086,
|
||||
EM_SCORE7 = 0x0087,
|
||||
EM_DSP24 = 0x0088,
|
||||
EM_VIDEOCORE3 = 0x0089,
|
||||
EM_LATTICEMICO32 = 0x008A,
|
||||
EM_SE_C17 = 0x008B,
|
||||
EM_TI_C6000 = 0x008C,
|
||||
EM_TI_C2000 = 0x008D,
|
||||
EM_TI_C5500 = 0x008E,
|
||||
EM_TI_ARP32 = 0x008F,
|
||||
EM_TI_PRU = 0x0090,
|
||||
EM_MMDSP_PLUS = 0x00A0,
|
||||
EM_CYPRESS_M8C = 0x00A1,
|
||||
EM_R32C = 0x00A2,
|
||||
EM_TRIMEDIA = 0x00A3,
|
||||
EM_QDSP6 = 0x00A4,
|
||||
EM_8051 = 0x00A5,
|
||||
EM_STXP7X = 0x00A6,
|
||||
EM_NDS32 = 0x00A7,
|
||||
EM_ECOG1 = 0x00A8,
|
||||
EM_ECOG1X = 0x00A8,
|
||||
EM_MAXQ30 = 0x00A9,
|
||||
EM_XIMO16 = 0x00AA,
|
||||
EM_MANIK = 0x00AB,
|
||||
EM_CRAYNV2 = 0x00AC,
|
||||
EM_RX = 0x00AD,
|
||||
EM_METAG = 0x00AE,
|
||||
EM_MCST_ELBRUS = 0x00AF,
|
||||
EM_ECOG16 = 0x00B0,
|
||||
EM_CR16 = 0x00B1,
|
||||
EM_ETPU = 0x00B2,
|
||||
EM_SLE9X = 0x00B3,
|
||||
EM_L10M = 0x00B4,
|
||||
EM_K10M = 0x00B5,
|
||||
EM_AARCH64 = 0x00B7,
|
||||
EM_AVR32 = 0x00B9,
|
||||
EM_STM8 = 0x00BA,
|
||||
EM_TILE64 = 0x00BB,
|
||||
EM_TILEPRO = 0x00BC,
|
||||
EM_MICROBLAZE = 0x00BD,
|
||||
EM_CUDA = 0x00BE,
|
||||
EM_TILEGX = 0x00BF,
|
||||
EM_CLOUDSHIELD = 0x00C0,
|
||||
EM_COREA_1ST = 0x00C1,
|
||||
EM_COREA_2ND = 0x00C2,
|
||||
EM_ARC_COMPACT2 = 0x00C3,
|
||||
EM_OPEN8 = 0x00C4,
|
||||
EM_RL78 = 0x00C5,
|
||||
EM_VIDEOCORE5 = 0x00C6,
|
||||
EM_78KOR = 0x00C7,
|
||||
EM_56800EX = 0x00C8,
|
||||
EM_BA1 = 0x00C9,
|
||||
EM_BA2 = 0x00CA,
|
||||
EM_XCORE = 0x00CB,
|
||||
EM_MCHP_PIC = 0x00CC,
|
||||
EM_INTEL205 = 0x00CD,
|
||||
EM_INTEL206 = 0x00CE,
|
||||
EM_INTEL207 = 0x00CF,
|
||||
EM_INTEL208 = 0x00D0,
|
||||
EM_INTEL209 = 0x00D1,
|
||||
EM_KM32 = 0x00D2,
|
||||
EM_KMX32 = 0x00D3,
|
||||
EM_KMX16 = 0x00D4,
|
||||
EM_KMX8 = 0x00D5,
|
||||
EM_KVARC = 0x00D6,
|
||||
EM_CDP = 0x00D7,
|
||||
EM_COGE = 0x00D8,
|
||||
EM_COOL = 0x00D9,
|
||||
EM_NORC = 0x00DA,
|
||||
EM_CSR_KALIMBA = 0x00DB,
|
||||
EM_Z80 = 0x00DC,
|
||||
EM_VISIUM = 0x00DD,
|
||||
EM_FT32 = 0x00DE,
|
||||
EM_MOXIE = 0x00DF,
|
||||
EM_AMDGPU = 0x00E0,
|
||||
EM_RISCV = 0x00F3,
|
||||
};
|
||||
|
||||
enum ET : u16 {
|
||||
NONE = 0x0000,
|
||||
REL = 0x0001,
|
||||
EXEC = 0x0002,
|
||||
DYN = 0x0003,
|
||||
CORE = 0x0004,
|
||||
};
|
||||
|
||||
enum DT : u32 {
|
||||
DT_NULL = 0x0,
|
||||
DT_NEEDED = 0x1,
|
||||
DT_PLTRELSZ = 0x2,
|
||||
DT_PLTGOT = 0x3,
|
||||
DT_HASH = 0x4,
|
||||
DT_STRTAB = 0x5,
|
||||
DT_SYMTAB = 0x6,
|
||||
DT_RELA = 0x7,
|
||||
DT_RELASZ = 0x8,
|
||||
DT_RELAENT = 0x9,
|
||||
DT_STRSZ = 0xA,
|
||||
DT_SYMENT = 0xB,
|
||||
DT_INIT = 0xC,
|
||||
DT_FINI = 0xD,
|
||||
DT_SONAME = 0xE,
|
||||
DT_RPATH = 0xF,
|
||||
DT_SYMBOLIC = 0x10,
|
||||
DT_REL = 0x11,
|
||||
DT_RELSZ = 0x12,
|
||||
DT_RELENT = 0x13,
|
||||
DT_PLTREL = 0x14,
|
||||
DT_DEBUG = 0x15,
|
||||
DT_TEXTREL = 0x16,
|
||||
DT_JMPREL = 0x17,
|
||||
DT_BIND_NOW = 0x18,
|
||||
DT_INIT_ARRAY = 0x19,
|
||||
DT_FINI_ARRAY = 0x1A,
|
||||
DT_INIT_ARRAYSZ = 0x1B,
|
||||
DT_FINI_ARRAYSZ = 0x1C,
|
||||
DT_RUNPATH = 0x1D,
|
||||
DT_FLAGS = 0x1E,
|
||||
DT_PREINIT_ARRAY = 0x20,
|
||||
DT_PREINIT_ARRAYSZ = 0x21,
|
||||
DT_MAXPOSTAGS = 0x22,
|
||||
DT_NUM = 0x23,
|
||||
DT_GNU_PRELINKED = 0x6FFFFDF5,
|
||||
DT_GNU_CONFLICTSZ = 0x6FFFFDF6,
|
||||
DT_GNU_LIBLISTSZ = 0x6FFFFDF7,
|
||||
DT_CHECKSUM = 0x6FFFFDF8,
|
||||
DT_PLTPADSZ = 0x6FFFFDF9,
|
||||
DT_MOVEENT = 0x6FFFFDFA,
|
||||
DT_MOVESZ = 0x6FFFFDFB,
|
||||
DT_FEATURE_1 = 0x6FFFFDFC,
|
||||
DT_POSFLAG_1 = 0x6FFFFDFD,
|
||||
DT_SYMINSZ = 0x6FFFFDFE,
|
||||
DT_SYMINENT = 0x6FFFFDFF,
|
||||
DT_GNU_HASH = 0x6FFFFEF5,
|
||||
DT_TLSDESC_PLT = 0x6FFFFEF6,
|
||||
DT_TLSDESC_GOT = 0x6FFFFEF7,
|
||||
DT_GNU_CONFLICT = 0x6FFFFEF8,
|
||||
DT_GNU_LIBLIST = 0x6FFFFEF9,
|
||||
DT_CONFIG = 0x6FFFFEFA,
|
||||
DT_DEPAUDIT = 0x6FFFFEFB,
|
||||
DT_AUDIT = 0x6FFFFEFC,
|
||||
DT_PLTPAD = 0x6FFFFEFD,
|
||||
DT_MOVETAB = 0x6FFFFEFE,
|
||||
DT_SYMINFO = 0x6FFFFEFF,
|
||||
DT_VERSYM = 0x6FFFFFF0,
|
||||
DT_RELACOUNT = 0x6FFFFFF9,
|
||||
DT_RELCOUNT = 0x6FFFFFFA,
|
||||
DT_FLAGS_1 = 0x6FFFFFFB,
|
||||
DT_VERDEF = 0x6FFFFFFC,
|
||||
DT_VERDEFNUM = 0x6FFFFFFD,
|
||||
DT_VERNEED = 0x6FFFFFFE,
|
||||
DT_VERNEEDNUM = 0x6FFFFFFF,
|
||||
DT_AUXILIARY = 0x7FFFFFFD,
|
||||
DT_USED = 0x7FFFFFFE,
|
||||
DT_FILTER = 0x7FFFFFFF,
|
||||
DT_DEPRECATED_SPARC_REGISTER = 0x7000001,
|
||||
DT_SUNW_AUXILIARY = 0x6000000D,
|
||||
DT_SUNW_RTLDINF = 0x6000000E,
|
||||
DT_SUNW_FILTER = 0x6000000F,
|
||||
DT_SUNW_CAP = 0x60000010,
|
||||
DT_SUNW_SYMTAB = 0x60000011,
|
||||
DT_SUNW_SYMSZ = 0x60000012,
|
||||
DT_SUNW_SORTENT = 0x60000013,
|
||||
DT_SUNW_SYMSORT = 0x60000014,
|
||||
DT_SUNW_SYMSORTSZ = 0x60000015,
|
||||
DT_SUNW_TLSSORT = 0x60000016,
|
||||
DT_SUNW_TLSSORTSZ = 0x60000017,
|
||||
DT_SUNW_STRPAD = 0x60000019,
|
||||
DT_SUNW_LDMACH = 0x6000001B,
|
||||
};
|
||||
|
||||
enum RT : Elf32_Word {
|
||||
CONSISTENT = 0x00,
|
||||
ADD = 0x01,
|
||||
DELETE = 0x02,
|
||||
};
|
||||
|
||||
enum PT : Elf32_Word {
|
||||
NULL = 0x00,
|
||||
LOAD = 0x01,
|
||||
DYNAMIC = 0x02,
|
||||
INTERP = 0x03,
|
||||
NOTE = 0x04,
|
||||
SHLIB = 0x05,
|
||||
PHDR = 0x06,
|
||||
TLS = 0x07,
|
||||
LOOS = 0x60000000,
|
||||
HIOS = 0x6FFFFFFF,
|
||||
GNU_EH_FRAME = PT::LOOS + 0x474E550,
|
||||
GNU_STACK = PT::LOOS + 0x474E551,
|
||||
GNU_RELRO = PT::LOOS + 0x474E552,
|
||||
GNU_PROPERTY = PT::LOOS + 0x474E553,
|
||||
SUNWBSS = 0x6FFFFFFA,
|
||||
SUNWSTACK = 0x6FFFFFFB,
|
||||
ARM_ARCHEXT = 0x70000000,
|
||||
ARM_UNWIND = 0x70000001,
|
||||
};
|
||||
|
||||
enum ELFCOMPRESS : u8 {
|
||||
ZLIB = 0x01,
|
||||
};
|
||||
|
||||
enum SHN : u16 {
|
||||
UNDEF = 0x00,
|
||||
BEFORE = 0xFF00,
|
||||
AFTER = 0xFF01,
|
||||
ABS = 0xFFF1,
|
||||
COMMON = 0xFFF2,
|
||||
XINDEX = 0xFFFF,
|
||||
};
|
||||
|
||||
enum SHT : Elf32_Word {
|
||||
NULL = 0x00,
|
||||
PROGBITS = 0x01,
|
||||
SYMTAB = 0x02,
|
||||
STRTAB = 0x03,
|
||||
RELA = 0x04,
|
||||
HASH = 0x05,
|
||||
DYNAMIC = 0x06,
|
||||
NOTE = 0x07,
|
||||
NOBITS = 0x08,
|
||||
REL = 0x09,
|
||||
SHLIB = 0x0A,
|
||||
DYNSYM = 0x0B,
|
||||
UNKNOWN12 = 0x0C,
|
||||
UNKNOWN13 = 0x0D,
|
||||
INIT_ARRAY = 0x0E,
|
||||
FINI_ARRAY = 0x0F,
|
||||
PREINIT_ARRAY = 0x10,
|
||||
GROUP = 0x11,
|
||||
SYMTAB_SHNDX = 0x12,
|
||||
GNU_INCREMENTAL_INPUTS = 0x6FFF4700,
|
||||
GNU_ATTRIBUTES = 0x6FFFFFF5,
|
||||
GNU_HASH = 0x6FFFFFF6,
|
||||
GNU_LIBLIST = 0x6FFFFFF7,
|
||||
CHECKSUM = 0x6FFFFFF8,
|
||||
SUNW_move = 0x6FFFFFFA,
|
||||
SUNW_COMDAT = 0x6FFFFFFB,
|
||||
SUNW_syminfo = 0x6FFFFFFC,
|
||||
GNU_verdef = 0x6FFFFFFD,
|
||||
GNU_verneed = 0x6FFFFFFE,
|
||||
GNU_versym = 0x6FFFFFFF,
|
||||
ARM_EXIDX = 0x70000001,
|
||||
ARM_PREEMPTMAP = 0x70000002,
|
||||
ARM_ATTRIBUTES = 0x70000003,
|
||||
ARM_DEBUGOVERLAY = 0x70000004,
|
||||
ARM_OVERLAYSECTION = 0x70000005,
|
||||
};
|
||||
|
||||
enum STV : u8 {
|
||||
DEFAULT = 0x00,
|
||||
INTERNAL = 0x01,
|
||||
HIDDEN = 0x02,
|
||||
PROTECTED = 0x03,
|
||||
};
|
||||
|
||||
enum SYMINFO_BT : Elf32_Half {
|
||||
SELF = 0xFFFF,
|
||||
PARENT = 0xFFFE,
|
||||
NONE = 0xFFFD,
|
||||
};
|
||||
|
||||
enum VER_DEF : Elf32_Half {
|
||||
NON = 0x00,
|
||||
CURRENT = 0x01,
|
||||
NUM = 0x02,
|
||||
};
|
||||
|
||||
enum VER_NDX : Elf32_Half {
|
||||
LOCAL = 0x00,
|
||||
GLOBAL = 0x01,
|
||||
ELIMINATE = 0xFF01,
|
||||
};
|
||||
|
||||
enum VER_NEED : Elf32_Half {
|
||||
NONE = 0x00,
|
||||
CURRENT = 0x01,
|
||||
NUM = 0x02,
|
||||
};
|
||||
|
||||
bitfield SYMINFO_FLG {
|
||||
padding : 10;
|
||||
NOEXTDIRECT : 1;
|
||||
DIRECTBIND : 1;
|
||||
LAZYLOAD : 1;
|
||||
COPY : 1;
|
||||
RESERVED : 1;
|
||||
DIRECT : 1;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield ST {
|
||||
ST_BIND : 4;
|
||||
ST_TYPE : 4;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield SHF {
|
||||
MASKPROC : 4;
|
||||
MASKOS : 8;
|
||||
UNKNOWN : 8;
|
||||
COMPRESSED : 1;
|
||||
TLS : 1;
|
||||
GROUP : 1;
|
||||
OS_NONCONFORMING : 1;
|
||||
LINK_ORDER : 1;
|
||||
INFO_LINK : 1;
|
||||
STRINGS : 1;
|
||||
MERGE : 1;
|
||||
padding : 1;
|
||||
EXECINSTR : 1;
|
||||
ALLOC : 1;
|
||||
WRITE : 1;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield ELF32_R_INFO {
|
||||
SYM : 8;
|
||||
TYPE : 8;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield ELF64_R_INFO {
|
||||
SYM : 32;
|
||||
TYPE : 32;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield PF {
|
||||
MASKPROC : 4;
|
||||
MASKOS : 4;
|
||||
padding : 17;
|
||||
R : 1;
|
||||
W : 1;
|
||||
X : 1;
|
||||
} [[left_to_right]];
|
||||
|
||||
struct E_IDENT {
|
||||
char EI_MAG[4];
|
||||
EI_CLASS EI_CLASS;
|
||||
EI_DATA EI_DATA;
|
||||
EI_VERSION EI_VERSION;
|
||||
EI_OSABI EI_OSABI;
|
||||
EI_ABIVERSION EI_ABIVERSION;
|
||||
padding[7];
|
||||
Type type;
|
||||
Machine machine;
|
||||
u32 version;
|
||||
};
|
||||
|
||||
struct Elf32_Ehdr {
|
||||
ET e_type;
|
||||
EM e_machine;
|
||||
E_VERSION e_version;
|
||||
Elf32_VAddr e_entry;
|
||||
Elf32_Off e_phoff;
|
||||
Elf32_Off e_shoff;
|
||||
Elf32_Word e_flags;
|
||||
Elf32_Half e_ehsize;
|
||||
Elf32_Half e_phentsize;
|
||||
Elf32_Half e_phnum;
|
||||
Elf32_Half e_shentsize;
|
||||
Elf32_Half e_shnum;
|
||||
Elf32_Half e_shstrndx;
|
||||
};
|
||||
|
||||
struct Elf64_Ehdr {
|
||||
ET e_type;
|
||||
EM e_machine;
|
||||
E_VERSION e_version;
|
||||
Elf64_VAddr e_entry;
|
||||
Elf64_Off e_phoff;
|
||||
Elf64_Off e_shoff;
|
||||
Elf64_Word e_flags;
|
||||
Elf64_Half e_ehsize;
|
||||
Elf64_Half e_phentsize;
|
||||
Elf64_Half e_phnum;
|
||||
Elf64_Half e_shentsize;
|
||||
Elf64_Half e_shnum;
|
||||
Elf64_Half e_shstrndx;
|
||||
};
|
||||
|
||||
struct Elf32_Phdr {
|
||||
PT p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
PF p_flags;
|
||||
Elf32_Word p_align;
|
||||
|
||||
if (identity.class == elf::Class::_32Bit) {
|
||||
u32 entry_point;
|
||||
u32 program_header_offset;
|
||||
u32 section_header_offset;
|
||||
} else {
|
||||
u64 entry_point;
|
||||
u64 program_header_offset;
|
||||
u64 section_header_offset;
|
||||
if (p_offset > 0 && p_filesz > 0 && (p_offset + p_filesz) < std::mem::data_size() && p_filesz < std::mem::data_size())
|
||||
u8 p_data[p_filesz] @ p_offset;
|
||||
};
|
||||
|
||||
struct Elf64_Phdr {
|
||||
PT p_type;
|
||||
PF p_flags;
|
||||
Elf64_Off p_offset;
|
||||
Elf64_Addr p_vaddr;
|
||||
Elf64_Addr p_paddr;
|
||||
Elf64_Xword p_filesz;
|
||||
Elf64_Xword p_memsz;
|
||||
Elf64_Xword p_align;
|
||||
|
||||
if (p_offset > 0 && p_filesz > 0 && (p_offset + p_filesz) < std::mem::size() && p_filesz < std::mem::size())
|
||||
u8 p_data[p_filesz] @ p_offset;
|
||||
};
|
||||
|
||||
struct Elf32_Chdr {
|
||||
u32 ch_type;
|
||||
Elf32_Word ch_size;
|
||||
Elf32_Word ch_addralign;
|
||||
};
|
||||
|
||||
struct Elf32_Rel {
|
||||
Elf32_Off r_offset;
|
||||
ELF32_R_INFO r_info;
|
||||
};
|
||||
|
||||
struct Elf32_Rela {
|
||||
Elf32_Off r_offset;
|
||||
ELF32_R_INFO r_info;
|
||||
Elf32_Sword r_addend;
|
||||
};
|
||||
|
||||
struct Elf32_Sym {
|
||||
u32 st_name;
|
||||
Elf32_VAddr st_value;
|
||||
Elf32_Word st_size;
|
||||
ST st_info;
|
||||
STV st_other;
|
||||
u16 st_shndx;
|
||||
};
|
||||
|
||||
struct Elf32_Syminfo {
|
||||
u16 si_boundto;
|
||||
SYMINFO_FLG si_flags;
|
||||
};
|
||||
|
||||
s64 stringTableIndex;
|
||||
|
||||
struct String {
|
||||
char value[];
|
||||
} [[sealed, format("format_string")]];
|
||||
|
||||
fn format_string(String string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
struct Elf32_Shdr {
|
||||
u32 sh_name;
|
||||
SHT sh_type;
|
||||
SHF sh_flags;
|
||||
u32 sh_addr;
|
||||
u32 sh_offset;
|
||||
Elf32_Word sh_size;
|
||||
Elf32_Word sh_link;
|
||||
Elf32_Word sh_info;
|
||||
Elf32_Word sh_addralign;
|
||||
Elf32_Word sh_entsize;
|
||||
|
||||
if (sh_size > 0 && sh_offset + sh_size < std::mem::size()) {
|
||||
if (sh_type == SHT::NOBITS || sh_type == SHT::NULL) {
|
||||
// Section has no data
|
||||
} else if (sh_type == SHT::STRTAB) {
|
||||
String stringTable[while($ < (sh_offset + sh_size))] @ sh_offset;
|
||||
stringTableIndex = std::core::array_index();
|
||||
} else if (sh_type == SHT::DYNSYM) {
|
||||
Elf32_Sym symbolTable[sh_size / sh_entsize] @ sh_offset;
|
||||
} else if (sh_type == SHT::INIT_ARRAY || sh_type == SHT::FINI_ARRAY) {
|
||||
u32 pointer[while($ < (sh_offset + sh_size))] @ sh_offset;
|
||||
} else {
|
||||
u8 data[sh_size] @ sh_offset;
|
||||
}
|
||||
}
|
||||
} [[format("format_section_header")]];;
|
||||
|
||||
struct Elf64_Chdr {
|
||||
u32 ch_type;
|
||||
Elf64_Word ch_size;
|
||||
Elf64_Word ch_addralign;
|
||||
};
|
||||
|
||||
struct Elf64_Rel {
|
||||
Elf64_Off r_offset;
|
||||
ELF64_R_INFO r_info;
|
||||
};
|
||||
|
||||
struct Elf64_Rela {
|
||||
Elf64_Off r_offset;
|
||||
ELF64_R_INFO r_info;
|
||||
Elf64_Sxword r_addend;
|
||||
};
|
||||
|
||||
struct Elf64_Sym {
|
||||
u32 st_name;
|
||||
ST st_info;
|
||||
STV st_other;
|
||||
u16 st_shndx;
|
||||
Elf64_VAddr st_value;
|
||||
Elf64_Xword st_size;
|
||||
};
|
||||
|
||||
struct Elf64_Syminfo {
|
||||
u16 si_boundto;
|
||||
SYMINFO_FLG si_flags;
|
||||
};
|
||||
|
||||
struct Elf64_Shdr {
|
||||
u32 sh_name;
|
||||
SHT sh_type;
|
||||
SHF sh_flags;
|
||||
padding[4];
|
||||
u64 sh_addr;
|
||||
u64 sh_offset;
|
||||
Elf64_Xword sh_size;
|
||||
Elf64_Word sh_link;
|
||||
Elf64_Word sh_info;
|
||||
Elf64_Xword sh_addralign;
|
||||
Elf64_Xword sh_entsize;
|
||||
|
||||
u32 flags;
|
||||
|
||||
u16 elf_header_size;
|
||||
u16 program_header_entry_size;
|
||||
u16 program_header_entry_count;
|
||||
u16 section_header_entry_size;
|
||||
u16 section_header_entry_count;
|
||||
u16 section_name_entry_id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace program {
|
||||
|
||||
enum Type : u32 {
|
||||
NULL = 0x00,
|
||||
LOAD = 0x01,
|
||||
DYNAMIC = 0x02,
|
||||
INTERP = 0x03,
|
||||
NOTE = 0x04,
|
||||
SHLIB = 0x05,
|
||||
PHDR = 0x06,
|
||||
TLS = 0x07,
|
||||
LOOS = 0x60000000,
|
||||
HIOS = 0x6FFFFFFF,
|
||||
LOPROC = 0x70000000,
|
||||
HIPROC = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
struct Header {
|
||||
Type type;
|
||||
|
||||
if (parent.header.identity.class == elf::Class::_32Bit) {
|
||||
u32 offset;
|
||||
u32 virtual_address;
|
||||
u32 physical_address;
|
||||
u32 file_size;
|
||||
u32 memory_size;
|
||||
u32 flags;
|
||||
u32 alignment;
|
||||
} else {
|
||||
u32 flags;
|
||||
u64 offset;
|
||||
u64 virtual_address;
|
||||
u64 physical_address;
|
||||
u64 file_size;
|
||||
u64 memory_size;
|
||||
u64 alignment;
|
||||
if (sh_size > 0 && sh_offset + sh_size < std::mem::size()) {
|
||||
if (sh_type == SHT::NOBITS || sh_type == SHT::NULL) {
|
||||
// Section has no data
|
||||
} else if (sh_type == SHT::STRTAB) {
|
||||
String stringTable[while($ < (sh_offset + sh_size))] @ sh_offset;
|
||||
stringTableIndex = std::core::array_index();
|
||||
} else if (sh_type == SHT::DYNSYM) {
|
||||
Elf64_Sym symbolTable[sh_size / sh_entsize] @ sh_offset;
|
||||
} else if (sh_type == SHT::INIT_ARRAY || sh_type == SHT::FINI_ARRAY) {
|
||||
u32 pointer[while($ < (sh_offset + sh_size))] @ sh_offset;
|
||||
} else {
|
||||
u8 data[sh_size] @ sh_offset;
|
||||
}
|
||||
}
|
||||
} [[static]];
|
||||
} [[format("format_section_header")]];
|
||||
|
||||
}
|
||||
fn format_section_header(auto shdr) {
|
||||
u32 i = 0;
|
||||
|
||||
u32 nameAddress = addressof(elf.shdr[stringTableIndex].stringTable) + shdr.sh_name;
|
||||
while (i < std::core::member_count(elf.shdr[stringTableIndex].stringTable)) {
|
||||
if (nameAddress >= addressof(elf.shdr[stringTableIndex].stringTable[i]) && nameAddress < (addressof(elf.shdr[stringTableIndex].stringTable[i]) + sizeof(elf.shdr[stringTableIndex].stringTable[i])))
|
||||
break;
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
namespace section {
|
||||
|
||||
struct String {
|
||||
char characters[];
|
||||
};
|
||||
|
||||
enum Type : u32 {
|
||||
NULL = 0x00,
|
||||
PROGBITS = 0x01,
|
||||
SYMTAB = 0x02,
|
||||
STRTAB = 0x03,
|
||||
RELA = 0x04,
|
||||
HASH = 0x05,
|
||||
DYNAMIC = 0x06,
|
||||
NOTE = 0x07,
|
||||
NOBITS = 0x08,
|
||||
REL = 0x09,
|
||||
SHLIB = 0x0A,
|
||||
DYNSYM = 0x0B,
|
||||
INIT_ARRAY = 0x0E,
|
||||
FINI_ARRAY = 0x0F,
|
||||
PREINIT_ARRAY = 0x10,
|
||||
GROUP = 0x11,
|
||||
SYMTAB_SHNDX = 0x12,
|
||||
NUM = 0x13,
|
||||
LOOS = 0x60000000
|
||||
};
|
||||
|
||||
bitfield Flags {
|
||||
WRITE : 1;
|
||||
ALLOC : 1;
|
||||
EXECINSTR : 1;
|
||||
pad1 : 1;
|
||||
MERGE : 1;
|
||||
STRINGS : 1;
|
||||
INFO_LINK : 1;
|
||||
LINK_ORDER : 1;
|
||||
OS_NONCONFORMING : 1;
|
||||
GROUP : 1;
|
||||
TLS : 1;
|
||||
};
|
||||
|
||||
struct Header {
|
||||
u32 name_offset;
|
||||
section::Type type;
|
||||
Flags flags;
|
||||
padding[2];
|
||||
|
||||
if (parent.header.identity.class == elf::Class::_32Bit) {
|
||||
u32 address;
|
||||
u32 offset;
|
||||
u32 size;
|
||||
u32 link;
|
||||
u32 info;
|
||||
u32 address_alignment;
|
||||
u32 entry_size;
|
||||
} else {
|
||||
padding[4];
|
||||
u64 address;
|
||||
u64 offset;
|
||||
u64 size;
|
||||
u32 link;
|
||||
u32 info;
|
||||
u64 address_alignment;
|
||||
u64 entry_size;
|
||||
}
|
||||
} [[static]];
|
||||
|
||||
}
|
||||
return elf.shdr[stringTableIndex].stringTable[i].value;
|
||||
};
|
||||
|
||||
|
||||
elf::Header header @ 0x00;
|
||||
program::Header program_headers[header.program_header_entry_count] @ header.program_header_offset;
|
||||
section::Header section_headers[header.section_header_entry_count] @ header.section_header_offset;
|
||||
struct ELF {
|
||||
E_IDENT e_ident;
|
||||
|
||||
if (e_ident.EI_DATA == EI_DATA::ELFDATA2LSB)
|
||||
std::core::set_endian(std::mem::Endian::Little);
|
||||
else
|
||||
std::core::set_endian(std::mem::Endian::Big);
|
||||
|
||||
if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS32) {
|
||||
Elf32_Ehdr header;
|
||||
} else if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS64) {
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff;
|
||||
Elf64_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff;
|
||||
}
|
||||
};
|
||||
|
||||
ELF elf @ 0x00;
|
||||
|
||||
321
patterns/flac.hexpat
Normal file
321
patterns/flac.hexpat
Normal file
@@ -0,0 +1,321 @@
|
||||
#include <std/sys.pat>
|
||||
#include <std/core.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
#pragma endian big
|
||||
|
||||
u32 sampleSize;
|
||||
u32 bitsPerSample;
|
||||
|
||||
// METADATA
|
||||
|
||||
enum BLOCK_TYPE : u8 {
|
||||
STREAMINFO = 0,
|
||||
PADDING = 1,
|
||||
APPLICATION = 2,
|
||||
SEEKTABLE = 3,
|
||||
VORBIS_COMMENT = 4,
|
||||
CUESHEET = 5,
|
||||
PICTURE = 6,
|
||||
|
||||
INVALID = 127
|
||||
};
|
||||
|
||||
bitfield METADATA_BLOCK_HEADER {
|
||||
lastMetadataBlock : 1;
|
||||
blockType : 7;
|
||||
length : 24;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield STREAMINFO_FLAGS {
|
||||
sampleRate : 20;
|
||||
numChannels : 3 [[format("format_channels")]];
|
||||
bitsPerSample : 5;
|
||||
numSamplesInStream : 36;
|
||||
} [[inline, left_to_right]];
|
||||
|
||||
fn format_channels(u8 value) {
|
||||
return value + 1;
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_STREAMINFO {
|
||||
u16 minBlockSize, maxBlockSize;
|
||||
u24 minFrameSize, maxFrameSize;
|
||||
STREAMINFO_FLAGS flags;
|
||||
u128 md5Signature;
|
||||
|
||||
bitsPerSample = flags.bitsPerSample;
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_PADDING {
|
||||
padding[parent.header.length];
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_APPLICATION {
|
||||
char applicationID[4];
|
||||
u8 applicationData[parent.header.length - sizeof(applicationID)];
|
||||
};
|
||||
|
||||
struct SEEKPOINT {
|
||||
u64 sampleNumber;
|
||||
u64 byteOffset;
|
||||
u16 numSamples;
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_SEEKTABLE {
|
||||
SEEKPOINT seekPoints[parent.header.length / 18];
|
||||
};
|
||||
|
||||
struct VORBIS_USER_COMMENT {
|
||||
le u32 length;
|
||||
char comment[length];
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_VORBIS_COMMENT {
|
||||
le u32 vendorLength;
|
||||
u8 vendor[vendorLength];
|
||||
|
||||
le u32 userCommentListLength;
|
||||
VORBIS_USER_COMMENT userCommentList[userCommentListLength];
|
||||
};
|
||||
|
||||
bitfield TRACK_FLAGS {
|
||||
audioTrack : 1;
|
||||
preEmphasis : 1;
|
||||
padding : 6;
|
||||
} [[inline]];
|
||||
|
||||
struct CUESHEET_TRACK_INDEX {
|
||||
u64 sampleOffset;
|
||||
u8 indexPointNumber;
|
||||
padding[3];
|
||||
};
|
||||
|
||||
struct CUESHEET_TRACK {
|
||||
u64 trackOffset;
|
||||
u8 trackNumber;
|
||||
char trackISRC[12];
|
||||
TRACK_FLAGS flags;
|
||||
padding[13];
|
||||
u8 numTrackIndexPoints;
|
||||
CUESHEET_TRACK_INDEX indexes[numTrackIndexPoints];
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_CUESHEET {
|
||||
char mediaCatalogNumber[128];
|
||||
u64 numLeadInSamples;
|
||||
bool isCD;
|
||||
padding[258];
|
||||
u8 numTracks;
|
||||
CUESHEET_TRACK tracks[numTracks];
|
||||
};
|
||||
|
||||
enum PICTURE_TYPE : u32 {
|
||||
Other = 0,
|
||||
FileIcon = 1,
|
||||
OtherFileIcon = 2,
|
||||
CoverFront = 3,
|
||||
CoverBack = 4,
|
||||
LeafletPage = 5,
|
||||
Media = 6,
|
||||
LeadArtist = 7,
|
||||
Artist = 8,
|
||||
Conductor = 9,
|
||||
Band = 10,
|
||||
Composer = 11,
|
||||
Lyricist = 12,
|
||||
RecordingLocation = 13,
|
||||
DuringRecording = 14,
|
||||
DuringPerformance = 15,
|
||||
MovieScreenCapture = 16,
|
||||
ABrightColoredFish = 17,
|
||||
Illustration = 18,
|
||||
BandLogoType = 19,
|
||||
PublisherLogoType = 20
|
||||
};
|
||||
|
||||
struct METADATA_BLOCK_PICTURE {
|
||||
PICTURE_TYPE pictureType;
|
||||
u32 mimeTypeLength;
|
||||
char mimeType[mineTypeLength];
|
||||
u32 descriptionLength;
|
||||
char description[descriptionLength];
|
||||
u32 width, height;
|
||||
u32 colorDepth;
|
||||
u32 colorCount;
|
||||
u32 pictureDataLength;
|
||||
u8 pictureData[pictureDataLength];
|
||||
};
|
||||
|
||||
|
||||
|
||||
// FRAME DATA
|
||||
// TODO: THIS IS INCOMPLETE / NOT WORKING CURRENTLY
|
||||
|
||||
bitfield FRAME_HEADER_FLAGS {
|
||||
syncCode : 14;
|
||||
padding : 1;
|
||||
blockingStrategy : 1;
|
||||
blockSize : 4;
|
||||
sampleRate : 4;
|
||||
channelAssignment : 4;
|
||||
sampleSize : 3;
|
||||
padding : 1;
|
||||
} [[inline]];
|
||||
|
||||
struct FRAME_HEADER {
|
||||
FRAME_HEADER_FLAGS flags;
|
||||
|
||||
sampleSize = flags.sampleSize;
|
||||
|
||||
if (flags.blockingStrategy)
|
||||
char16 sampleNumber[7];
|
||||
else
|
||||
char16 frameNumber[6];
|
||||
|
||||
if (flags.blockSize == 0b0110)
|
||||
u8 blockSize;
|
||||
else if (flags.blockSize == 0b0111)
|
||||
u16 blockSize;
|
||||
|
||||
if (flags.sampleRate == 0b1100)
|
||||
u8 sampleRate;
|
||||
else if (flags.sampleRate == 0b1101 || flags.sampleRate == 0b1110)
|
||||
u16 sampleRate;
|
||||
|
||||
u8 crc8;
|
||||
};
|
||||
|
||||
struct FRAME_FOOTER {
|
||||
u16 crc16;
|
||||
};
|
||||
|
||||
bitfield SUBFRAME_HEADER {
|
||||
padding : 1;
|
||||
type : 6;
|
||||
wastedBits : 1;
|
||||
};
|
||||
|
||||
fn getBitsPerSample() {
|
||||
if (sampleSize == 0b000)
|
||||
return bitsPerSample;
|
||||
else if (sampleSize == 0b001)
|
||||
return 8;
|
||||
else if (sampleSize == 0b010)
|
||||
return 12;
|
||||
else if (sampleSize == 0b100)
|
||||
return 16;
|
||||
else if (sampleSize == 0b101)
|
||||
return 20;
|
||||
else if (sampleSize == 0b110)
|
||||
return 24;
|
||||
};
|
||||
|
||||
bitfield SUBFRAME_CONSTANT {
|
||||
value : getBitsPerSample();
|
||||
};
|
||||
|
||||
bitfield SUBFRAME_VERBATIM {
|
||||
value : getBitsPerSample() * parent.parent.header.flags.blockSize;
|
||||
};
|
||||
|
||||
bitfield SUBFRAME_FIXED_VALUE {
|
||||
value : getBitsPerSample() * (parent.parent.header.type & 0b111);
|
||||
codingMethod : 2;
|
||||
} [[inline]];
|
||||
|
||||
bitfield RESIDUAL_CODING_METHOD_PARTITIONED_RICE {
|
||||
partitionOrder : 4;
|
||||
riceParameter : 4;
|
||||
if (riceParameter == 0b1111)
|
||||
bitsPerSample : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 {
|
||||
partitionOrder : 4;
|
||||
riceParameter : 5;
|
||||
if (riceParameter == 0b11111)
|
||||
bitsPerSample : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct RESIDUAL {
|
||||
if (parent.value.codingMethod == 0b00)
|
||||
RESIDUAL_CODING_METHOD_PARTITIONED_RICE rice;
|
||||
else if (parent.value.codingMethod == 0b01)
|
||||
RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 rice;
|
||||
|
||||
|
||||
if ((parent.parent.header.type & 0b111) == 0b000)
|
||||
u8 samples[(getBitsPerSample() * (parent.parent.parent.header.flags.blockSize - (parent.parent.header.type & 0b111))) / 8];
|
||||
else if (std::core::array_index() != 0)
|
||||
u8 samples[(getBitsPerSample() * (parent.parent.parent.header.flags.blockSize / (1 << rice.partitionOrder))) / 8];
|
||||
else
|
||||
u8 samples[(getBitsPerSample() * ((parent.parent.parent.header.flags.blockSize / (1 << rice.partitionOrder)) - (parent.parent.header.type & 0b111))) / 8];
|
||||
};
|
||||
|
||||
struct SUBFRAME_FIXED {
|
||||
SUBFRAME_FIXED_VALUE value;
|
||||
RESIDUAL residual;
|
||||
};
|
||||
|
||||
bitfield SUBFRAME_LPC_VALUE {
|
||||
warmUpSamples : getBitsPerSample() * ((parent.header.type & 0b011111) + 1);
|
||||
quantizedLinearPredictorCoefficient : 4;
|
||||
quantizedLinearPredictorCoefficientShift : 5;
|
||||
predictorCoefficients : quantizedLinearPredictorCoefficient * ((parent.header.type & 0b011111) + 1);
|
||||
} [[inline]];
|
||||
|
||||
struct SUBFRAME_LPC {
|
||||
SUBFRAME_LPC_VALUE value;
|
||||
RESIDUAL residual;
|
||||
};
|
||||
|
||||
|
||||
struct SUBFRAME {
|
||||
SUBFRAME_HEADER header;
|
||||
|
||||
if (header.type == 0b00000)
|
||||
SUBFRAME_CONSTANT constant;
|
||||
else if (header.type == 0b000001)
|
||||
SUBFRAME_VERBATIM verbatim;
|
||||
else if ((header.type >> 3) == 0b001 && (header.type & 0b111) <= 4)
|
||||
SUBFRAME_FIXED fixed;
|
||||
else if (header.type == 0b100000)
|
||||
SUBFRAME_LPC lpc;
|
||||
};
|
||||
|
||||
struct FRAME {
|
||||
FRAME_HEADER header;
|
||||
SUBFRAME subframes[parent.metadata[0].data.flags.numChannels + 1];
|
||||
FRAME_FOOTER footer;
|
||||
};
|
||||
|
||||
|
||||
struct METADATA_BLOCK {
|
||||
METADATA_BLOCK_HEADER header;
|
||||
if (header.lastMetadataBlock)
|
||||
break;
|
||||
|
||||
if (header.blockType == BLOCK_TYPE::STREAMINFO)
|
||||
METADATA_BLOCK_STREAMINFO data;
|
||||
else if (header.blockType == BLOCK_TYPE::PADDING)
|
||||
METADATA_BLOCK_PADDING data;
|
||||
else if (header.blockType == BLOCK_TYPE::APPLICATION)
|
||||
METADATA_BLOCK_APPLICATION data;
|
||||
else if (header.blockType == BLOCK_TYPE::VORBIS_COMMENT)
|
||||
METADATA_BLOCK_VORBIS_COMMENT data;
|
||||
else if (header.blockType == BLOCK_TYPE::CUESHEET)
|
||||
METADATA_BLOCK_CUESHEET data;
|
||||
else if (header.blockType == BLOCK_TYPE::PICTURE)
|
||||
METADATA_BLOCK_PICTURE data;
|
||||
else
|
||||
std::error("Invalid metadata block type!");
|
||||
};
|
||||
|
||||
struct STREAM {
|
||||
char magic[4];
|
||||
METADATA_BLOCK metadata[while(true)];
|
||||
//FRAME frames[while(!std::mem::eof())];
|
||||
};
|
||||
|
||||
STREAM stream @ 0x00;
|
||||
168
patterns/fs.hexpat
Normal file
168
patterns/fs.hexpat
Normal file
@@ -0,0 +1,168 @@
|
||||
#include <std/io.pat>
|
||||
|
||||
struct DiskTimeStamp {
|
||||
u8 seconds, minutes, hours;
|
||||
};
|
||||
|
||||
enum DiskProtection : u16 {
|
||||
None = 0x0000,
|
||||
CopyProtected = 0x5A5A
|
||||
};
|
||||
|
||||
bitfield CHS {
|
||||
h : 8;
|
||||
s : 6;
|
||||
c : 10;
|
||||
} [[right_to_left, format("chs_formatter")]];
|
||||
|
||||
fn chs_formatter(CHS chs) {
|
||||
return std::format("({:X}, {:X}, {:X}) | 0x{:X}", chs.c, chs.h, chs.s, (chs.c * 16 + chs.h) * 63 + (chs.s - 1));
|
||||
};
|
||||
|
||||
enum PartitionStatus : u8 {
|
||||
None = 0x00,
|
||||
Active = 0x80
|
||||
};
|
||||
|
||||
enum PartitionType : u8 {
|
||||
EmptyPartitionEntry = 0x00,
|
||||
FAT32_CHS = 0x0B,
|
||||
FAT32_LBA = 0x0C
|
||||
};
|
||||
|
||||
namespace fat32 {
|
||||
|
||||
u64 bytesPerCluster;
|
||||
|
||||
struct FSInfo {
|
||||
u32 leadSignature;
|
||||
padding[480];
|
||||
u32 structSignature;
|
||||
u32 freeClusterCount;
|
||||
u32 nextFreeCluster;
|
||||
padding[12];
|
||||
u32 trailSignature;
|
||||
};
|
||||
|
||||
bitfield SequenceNumber {
|
||||
padding : 1;
|
||||
lastLogical : 1;
|
||||
padding : 1;
|
||||
number : 5;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum EntryStatus : u8 {
|
||||
Regular = 0x00,
|
||||
DotEntry = 0x2E,
|
||||
DeletedEntry = 0xE5
|
||||
};
|
||||
|
||||
union EntryStatusOrSequenceNumber {
|
||||
EntryStatus entryStatus;
|
||||
SequenceNumber sequenceNumber;
|
||||
};
|
||||
|
||||
bitfield Attributes {
|
||||
readOnly : 1;
|
||||
hidden : 1;
|
||||
systemFile : 1;
|
||||
volumeLabel : 1;
|
||||
subdirectory : 1;
|
||||
archive : 1;
|
||||
padding : 2;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DirEntry {
|
||||
char fileName[8];
|
||||
char extension[3];
|
||||
Attributes attributes;
|
||||
u8 reserved[10];
|
||||
u16 time, date;
|
||||
u16 startingCluster;
|
||||
u32 fileSize;
|
||||
|
||||
u8 data[fileSize] @ startingCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
struct VFATDirEntry {
|
||||
EntryStatusOrSequenceNumber entryStatusOrSequenceNumber;
|
||||
char16 name1[5];
|
||||
Attributes attributes;
|
||||
u8 type;
|
||||
u8 nameChecksum;
|
||||
char16 name2[6];
|
||||
u16 startingCluster;
|
||||
char16 name3[2];
|
||||
|
||||
if (entryStatusOrSequenceNumber.sequenceNumber.number > 1)
|
||||
VFATDirEntry nextLogicalEntry;
|
||||
else
|
||||
DirEntry physicalEntry;
|
||||
};
|
||||
|
||||
struct Partition {
|
||||
u8 jmpCode[3];
|
||||
char oemName[8];
|
||||
u16 bytesPerSector;
|
||||
u8 sectorsPerCluster;
|
||||
u16 reservedAreaSize;
|
||||
u8 numFats;
|
||||
u16 rootEntryCount;
|
||||
u16 numSectors;
|
||||
u8 mediaType;
|
||||
u16 fatSize;
|
||||
u16 sectorsPerTrack;
|
||||
u16 numHeads;
|
||||
u32 numHiddenSectors;
|
||||
u32 numFsSectors;
|
||||
u32 numFatSectors;
|
||||
u16 extFlags;
|
||||
u16 fsVersion;
|
||||
u32 rootCluster;
|
||||
u16 fsInfoSector;
|
||||
u16 backupBootSector;
|
||||
padding[12];
|
||||
u8 driveNumber;
|
||||
padding[1];
|
||||
u8 bootSignature;
|
||||
u32 volumeID;
|
||||
char volumeLabel[11];
|
||||
char fsType[8];
|
||||
u8 bootstrapCode[420];
|
||||
u16 signature;
|
||||
|
||||
bytesPerCluster = (sectorsPerCluster * 1024) * bytesPerSector;
|
||||
|
||||
FSInfo fsInfo @ addressof(this) + fsInfoSector * bytesPerSector;
|
||||
VFATDirEntry rootDirEntry @ addressof(this) + rootCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct PartitionEntry {
|
||||
PartitionStatus status;
|
||||
CHS chsFirstSectorAddress;
|
||||
PartitionType type;
|
||||
CHS chsLastSectorAddress;
|
||||
u32 lbaFirstSectorAddress;
|
||||
u32 numSectors;
|
||||
|
||||
if (type == PartitionType::EmptyPartitionEntry)
|
||||
continue;
|
||||
else if (type == PartitionType::FAT32_CHS || type == PartitionType::FAT32_LBA)
|
||||
fat32::Partition partition @ lbaFirstSectorAddress * 512;
|
||||
};
|
||||
|
||||
struct MasterBootRecord {
|
||||
u8 bootstrapCodeArea1[218];
|
||||
padding[2];
|
||||
u8 originalPhysicalDrive;
|
||||
DiskTimeStamp diskTimeStamp;
|
||||
u8 bootstrapCodeArea2[216];
|
||||
u32 diskSignature;
|
||||
DiskProtection diskProtection;
|
||||
PartitionEntry partitionEntries[4];
|
||||
u16 bootSignature;
|
||||
};
|
||||
|
||||
MasterBootRecord mbr @ 0x00;
|
||||
459
patterns/lnk.hexpat
Normal file
459
patterns/lnk.hexpat
Normal file
@@ -0,0 +1,459 @@
|
||||
#pragma MIME application/x-ms-shortcut
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
bitfield LinkFlags {
|
||||
HasLinkTargetIDList : 1;
|
||||
HasLinkInfo : 1;
|
||||
HasName : 1;
|
||||
HasRelativePath : 1;
|
||||
HasWorkingDir : 1;
|
||||
HasArguments : 1;
|
||||
HasIconLocation : 1;
|
||||
IsUnicode : 1;
|
||||
ForceNoLinkInfo : 1;
|
||||
HasExpString : 1;
|
||||
RunInSeparateProcess : 1;
|
||||
padding : 1;
|
||||
HasDarwinID : 1;
|
||||
RunAsUser : 1;
|
||||
HasExpIcon : 1;
|
||||
NoPidlAlias : 1;
|
||||
padding : 1;
|
||||
RunWithShimLayer : 1;
|
||||
ForceNoLinkTrack : 1;
|
||||
EnableTargetMetadata : 1;
|
||||
DisableLinkPathTracking : 1;
|
||||
DisableKnownFolderTracking : 1;
|
||||
DisableKnownFolderAlias : 1;
|
||||
AllowLinkToLink : 1;
|
||||
UnaliasOnSave : 1;
|
||||
PreferEnvironmentPath : 1;
|
||||
KeepLocalIDListForUNCTarget : 1;
|
||||
padding : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield FileAttributesFlags {
|
||||
FILE_ATTRIBUTE_READONLY : 1;
|
||||
FILE_ATTRIBUTE_HIDDEN : 1;
|
||||
FILE_ATTRIBUTE_SYSTEM : 1;
|
||||
padding : 1;
|
||||
FILE_ATTRIBUTE_DIRECTORY : 1;
|
||||
FILE_ATTRIBUTE_ARCHIVE : 1;
|
||||
padding : 1;
|
||||
FILE_ATTRIBUTE_NORMAL : 1;
|
||||
FILE_ATTRIBUTE_TEMPORARY : 1;
|
||||
FILE_ATTRIBUTE_SPARSE_FILE : 1;
|
||||
FILE_ATTRIBUTE_REPARSE_POINT : 1;
|
||||
FILE_ATTRIBUTE_COMPRESSED : 1;
|
||||
FILE_ATTRIBUTE_OFFLINE : 1;
|
||||
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : 1;
|
||||
FILE_ATTRIBUTE_ENCRYPTED : 1;
|
||||
padding : 17;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield ModifierKeys {
|
||||
HOTKEYF_SHIFT : 1;
|
||||
HOTKEYF_CONTROL : 1;
|
||||
HOTKEYF_ALT : 1;
|
||||
padding : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
enum Keys : u8 {
|
||||
KEY_NONE = 0x00,
|
||||
KEY_0 = 0x30,
|
||||
KEY_1 = 0x31,
|
||||
KEY_2 = 0x32,
|
||||
KEY_3 = 0x33,
|
||||
KEY_4 = 0x34,
|
||||
KEY_5 = 0x35,
|
||||
KEY_6 = 0x36,
|
||||
KEY_7 = 0x37,
|
||||
KEY_8 = 0x38,
|
||||
KEY_9 = 0x39,
|
||||
KEY_A = 0x41,
|
||||
KEY_B = 0x42,
|
||||
KEY_C = 0x43,
|
||||
KEY_D = 0x44,
|
||||
KEY_E = 0x45,
|
||||
KEY_F = 0x46,
|
||||
KEY_G = 0x47,
|
||||
KEY_H = 0x48,
|
||||
KEY_I = 0x49,
|
||||
KEY_J = 0x4A,
|
||||
KEY_K = 0x4B,
|
||||
KEY_L = 0x4C,
|
||||
KEY_M = 0x4D,
|
||||
KEY_N = 0x4E,
|
||||
KEY_O = 0x4F,
|
||||
KEY_P = 0x50,
|
||||
KEY_Q = 0x51,
|
||||
KEY_R = 0x52,
|
||||
KEY_S = 0x53,
|
||||
KEY_T = 0x54,
|
||||
KEY_U = 0x55,
|
||||
KEY_V = 0x56,
|
||||
KEY_W = 0x57,
|
||||
KEY_X = 0x58,
|
||||
KEY_Y = 0x59,
|
||||
KEY_Z = 0x5A,
|
||||
|
||||
VK_F1 = 0x70,
|
||||
VK_F2 = 0x71,
|
||||
VK_F3 = 0x72,
|
||||
VK_F4 = 0x73,
|
||||
VK_F5 = 0x74,
|
||||
VK_F6 = 0x75,
|
||||
VK_F7 = 0x76,
|
||||
VK_F8 = 0x77,
|
||||
VK_F9 = 0x78,
|
||||
VK_F10 = 0x79,
|
||||
VK_F11 = 0x7A,
|
||||
VK_F12 = 0x7B,
|
||||
VK_F13 = 0x7C,
|
||||
VK_F14 = 0x7D,
|
||||
VK_F15 = 0x7E,
|
||||
VK_F16 = 0x7F,
|
||||
VK_F17 = 0x80,
|
||||
VK_F18 = 0x81,
|
||||
VK_F19 = 0x82,
|
||||
VK_F20 = 0x83,
|
||||
VK_F21 = 0x84,
|
||||
VK_F22 = 0x85,
|
||||
VK_F23 = 0x86,
|
||||
VK_F24 = 0x87,
|
||||
VK_NUMLOCK = 0x90,
|
||||
VK_SCROLL = 0x91,
|
||||
};
|
||||
|
||||
struct HotKeyFlags {
|
||||
Keys Key;
|
||||
ModifierKeys ModifierKeys;
|
||||
};
|
||||
|
||||
struct FILETIME {
|
||||
u32 dwLowDateTime;
|
||||
u32 dwHighDateTime;
|
||||
};
|
||||
|
||||
enum SHOWWINDOW_FLAGS : u32 {
|
||||
SW_SHOWNORMAL = 0x00000001,
|
||||
SW_SHOWMAXIMIZED = 0x00000003,
|
||||
SW_SHOWMINNOACTIVE = 0x00000007
|
||||
};
|
||||
|
||||
struct ShellLinkHeader {
|
||||
type::Size32 HeaderSize;
|
||||
type::GUID LinkCLSID;
|
||||
LinkFlags LinkFlags;
|
||||
FileAttributesFlags FileAttributes;
|
||||
FILETIME CreationTime, AccessTime, WriteTime;
|
||||
type::Size32 FileSize;
|
||||
u32 IconIndex;
|
||||
SHOWWINDOW_FLAGS ShowCommand;
|
||||
HotKeyFlags HotKey;
|
||||
padding[2];
|
||||
padding[4];
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct ItemID {
|
||||
type::Size16 ItemIDSize;
|
||||
|
||||
if (ItemIDSize == 0x00)
|
||||
break;
|
||||
else
|
||||
u8 Data[ItemIDSize - sizeof(ItemIDSize)];
|
||||
};
|
||||
|
||||
struct IDList {
|
||||
ItemID ItemIDList[while(true)];
|
||||
};
|
||||
|
||||
struct LinkTargetIDList {
|
||||
type::Size16 IDListSize;
|
||||
IDList IDList[while($ < (addressof(IDListSize) + IDListSize))];
|
||||
};
|
||||
|
||||
bitfield LinkInfoFlags {
|
||||
VolumeIDAndLocalBasePath : 1;
|
||||
CommonNetworkRelativeLinkAndPathSuffix : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
enum DriveType : u32 {
|
||||
DRIVE_UNKNOWN = 0x00000000,
|
||||
DRIVE_NO_ROOT_DIR = 0x00000001,
|
||||
DRIVE_REMOVABLE = 0x00000002,
|
||||
DRIVE_FIXED = 0x00000003,
|
||||
DRIVE_REMOTE = 0x00000004,
|
||||
DRIVE_CDROM = 0x00000005,
|
||||
DRIVE_RAMDISK = 0x00000006
|
||||
};
|
||||
|
||||
struct VolumeID {
|
||||
type::Size32 VolumeIDSize;
|
||||
DriveType DriveType;
|
||||
u32 DriveSerialNumber;
|
||||
u32 VolumeLabelOffset;
|
||||
if (VolumeLabelOffset == 0x14)
|
||||
u32 VolumeLabelOffsetUnicode;
|
||||
char Data[VolumeIDSize - ($ - addressof(this))];
|
||||
};
|
||||
|
||||
bitfield CommonNetworkRelativeLinkFlags {
|
||||
ValidDevice : 1;
|
||||
ValidNetType : 1;
|
||||
padding : 30;
|
||||
} [[right_to_left]];
|
||||
|
||||
enum NetworkProviderType : u32 {
|
||||
WNNC_NET_AVID = 0x001A0000,
|
||||
WNNC_NET_DOCUSPACE = 0x001B0000,
|
||||
WNNC_NET_MANGOSOFT = 0x001C0000,
|
||||
WNNC_NET_SERNET = 0x001D0000,
|
||||
WNNC_NET_RIVERFRONT1 = 0x001E0000,
|
||||
WNNC_NET_RIVERFRONT2 = 0x001F0000,
|
||||
WNNC_NET_DECORB = 0x00200000,
|
||||
WNNC_NET_PROTSTOR = 0x00210000,
|
||||
WNNC_NET_FJ_REDIR = 0x00220000,
|
||||
WNNC_NET_DISTINCT = 0x00230000,
|
||||
WNNC_NET_TWINS = 0x00240000,
|
||||
WNNC_NET_RDR2SAMPLE = 0x00250000,
|
||||
WNNC_NET_CSC = 0x00260000,
|
||||
WNNC_NET_3IN1 = 0x00270000,
|
||||
WNNC_NET_EXTENDNET = 0x00290000,
|
||||
WNNC_NET_STAC = 0x002A0000,
|
||||
WNNC_NET_FOXBAT = 0x002B0000,
|
||||
WNNC_NET_YAHOO = 0x002C0000,
|
||||
WNNC_NET_EXIFS = 0x002D0000,
|
||||
WNNC_NET_DAV = 0x002E0000,
|
||||
WNNC_NET_KNOWARE = 0x002F0000,
|
||||
WNNC_NET_OBJECT_DIRE = 0x00300000,
|
||||
WNNC_NET_MASFAX = 0x00310000,
|
||||
WNNC_NET_HOB_NFS = 0x00320000,
|
||||
WNNC_NET_SHIVA = 0x00330000,
|
||||
WNNC_NET_IBMAL = 0x00340000,
|
||||
WNNC_NET_LOCK = 0x00350000,
|
||||
WNNC_NET_TERMSRV = 0x00360000,
|
||||
WNNC_NET_SRT = 0x00370000,
|
||||
WNNC_NET_QUINCY = 0x00380000,
|
||||
WNNC_NET_OPENAFS = 0x00390000,
|
||||
WNNC_NET_AVID1 = 0x003A0000,
|
||||
WNNC_NET_DFS = 0x003B0000,
|
||||
WNNC_NET_KWNP = 0x003C0000,
|
||||
WNNC_NET_ZENWORKS = 0x003D0000,
|
||||
WNNC_NET_DRIVEONWEB = 0x003E0000,
|
||||
WNNC_NET_VMWARE = 0x003F0000,
|
||||
WNNC_NET_RSFX = 0x00400000,
|
||||
WNNC_NET_MFILES = 0x00410000,
|
||||
WNNC_NET_MS_NFS = 0x00420000,
|
||||
WNNC_NET_GOOGLE = 0x00430000
|
||||
};
|
||||
|
||||
struct CommonNetworkRelativeLink {
|
||||
type::Size32 CommonNetworkRelativeLinkSize;
|
||||
CommonNetworkRelativeLinkFlags CommonNetworkRelativeLinkFlags;
|
||||
u32 NetNameOffset;
|
||||
u32 DeviceNameOffset;
|
||||
NetworkProviderType NetworkProviderType;
|
||||
|
||||
if (NetNameOffset > 0x14) {
|
||||
u32 NetNameOffsetUnicode;
|
||||
u32 DeviceNameOffsetUnicode;
|
||||
}
|
||||
|
||||
char NetName[];
|
||||
char DeviceName[];
|
||||
|
||||
if (NetNameOffset > 0x14) {
|
||||
char16 NetNameUnicode[];
|
||||
char16 DeviceNameUnicode[];
|
||||
}
|
||||
};
|
||||
|
||||
struct LinkInfo {
|
||||
type::Size32 LinkInfoSize;
|
||||
type::Size32 LinkInfoHeaderSize;
|
||||
LinkInfoFlags LinkInfoFlags;
|
||||
u32 VolumeIDOffset;
|
||||
u32 LocalBasePathOffset;
|
||||
u32 CommonNetworkRelativeLinkOffset;
|
||||
u32 CommonPathSuffixOffset;
|
||||
|
||||
if (LinkInfoHeaderSize >= 0x24) {
|
||||
u32 LocalBasePathOffsetUnicode;
|
||||
u32 CommonPathSuffixOffsetUnicode;
|
||||
}
|
||||
|
||||
if (LinkInfoFlags.VolumeIDAndLocalBasePath) {
|
||||
VolumeID VolumeID;
|
||||
char LocalBasePath[];
|
||||
}
|
||||
|
||||
if (LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix)
|
||||
CommonNetworkRelativeLink CommonNetworkRelativeLink;
|
||||
|
||||
char CommonPathSuffix[];
|
||||
|
||||
if (LinkInfoHeaderSize >= 0x24) {
|
||||
if (LinkInfoFlags.VolumeIDAndLocalBasePath)
|
||||
char16 LocalBasePathUnicode[];
|
||||
char16 CommonPathSuffixUnicode[];
|
||||
}
|
||||
};
|
||||
|
||||
struct String {
|
||||
u16 CountCharacters;
|
||||
char16 String[CountCharacters];
|
||||
};
|
||||
|
||||
struct StringData {
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasName)
|
||||
String NAME_STRING;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasRelativePath)
|
||||
String RELATIVE_PATH;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasWorkingDir)
|
||||
String WORKING_DIR;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasArguments)
|
||||
String COMMAND_LINE_ARGUMENTS;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasIconLocation)
|
||||
String ICON_LOCATION;
|
||||
};
|
||||
|
||||
bitfield FillAttributes {
|
||||
FOREGROUND_BLUE : 1;
|
||||
FOREGROUND_GREEN : 1;
|
||||
FOREGROUND_RED : 1;
|
||||
FOREGROUND_INTENSITY : 1;
|
||||
|
||||
BACKGROUND_BLUE : 1;
|
||||
BACKGROUND_GREEN : 1;
|
||||
BACKGROUND_RED : 1;
|
||||
BACKGROUND_INTENSITY : 1;
|
||||
|
||||
padding : 8;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct ConsoleDataBlock {
|
||||
FillAttributes FillAttributes;
|
||||
FillAttributes PopupFillAttributes;
|
||||
u16 ScreenBufferSizeX, ScreenBufferSizeY;
|
||||
u16 WindowSizeX, WindowSizeY;
|
||||
u16 WindowOriginX, WindowOriginY;
|
||||
padding[4];
|
||||
padding[4];
|
||||
u32 FontSize;
|
||||
u32 FontFamily;
|
||||
u32 FontWeight;
|
||||
char16 FaceName[32];
|
||||
u32 CursorSize;
|
||||
u32 FullScreen;
|
||||
u32 QuickEdit;
|
||||
u32 InsertMode;
|
||||
u32 AutoPosition;
|
||||
u32 HistoryBufferSize;
|
||||
u32 NumberOfHistoryBuffers;
|
||||
u32 HistoryNoDup;
|
||||
u32 ColorTable[16];
|
||||
};
|
||||
|
||||
struct ConsoleFEDataBlock {
|
||||
u32 CodePage;
|
||||
};
|
||||
|
||||
struct DarwinDataBlock {
|
||||
char DarwinDataAnsi[260];
|
||||
char16 DarwinDataUnicode[260];
|
||||
};
|
||||
|
||||
struct EnvironmentVariableDataBlock {
|
||||
char TargetAnsi[260];
|
||||
char16 TargetUnicode[260];
|
||||
};
|
||||
|
||||
struct IconEnvironmentDataBlock {
|
||||
char TargetAnsi[260];
|
||||
char16 TargetUnicode[260];
|
||||
};
|
||||
|
||||
struct KnownFolderDataBlock {
|
||||
type::GUID KnownFolderID;
|
||||
u32 Offset;
|
||||
};
|
||||
|
||||
struct PropertyStoreDataBlock {
|
||||
u8 Bytes[parent.BlockSize - sizeof(parent.BlockSize) - sizeof(parent.BlockSignature)];
|
||||
std::warning("PropertyStoreDataBlock is not yet implemented!");
|
||||
};
|
||||
|
||||
struct ShimDataBlock {
|
||||
char16 LayerName[(parent.BlockSize - sizeof(parent.BlockSize) - sizeof(parent.BlockSignature)) / sizeof(char16)];
|
||||
};
|
||||
|
||||
struct SpecialFolderDataBlock {
|
||||
u32 SpecialFolderID;
|
||||
u32 Offset;
|
||||
};
|
||||
|
||||
struct TrackerDataBlock {
|
||||
type::Size32 Length;
|
||||
u32 Version;
|
||||
char MachineID[16];
|
||||
type::GUID Droid[2];
|
||||
type::GUID DroidBirth[2];
|
||||
};
|
||||
|
||||
struct VistaAndAboveIDListDataBlock {
|
||||
IDList IDList;
|
||||
};
|
||||
|
||||
struct ExtraDataBlock {
|
||||
type::Size32 BlockSize;
|
||||
|
||||
if (BlockSize < 0x04)
|
||||
break;
|
||||
else {
|
||||
u32 BlockSignature;
|
||||
|
||||
if (BlockSignature == 0xA000'0002)
|
||||
ConsoleDataBlock CONSOLE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0004)
|
||||
ConsoleFEDataBlock CONSOLE_FE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0006)
|
||||
DarwinDataBlock DARWIN_PROPS;
|
||||
else if (BlockSignature == 0xA000'0001)
|
||||
EnvironmentVariableDataBlock ENVIRONMENT_PROPS;
|
||||
else if (BlockSignature == 0xA000'0007)
|
||||
IconEnvironmentDataBlock ICON_ENVIRONMENT_PROPS;
|
||||
else if (BlockSignature == 0xA000'000B)
|
||||
KnownFolderDataBlock KNOWN_FOLDER_PROPS;
|
||||
else if (BlockSignature == 0xA000'0009)
|
||||
PropertyStoreDataBlock PROPERTY_STORE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0008)
|
||||
ShimDataBlock SHIM_PROPS;
|
||||
else if (BlockSignature == 0xA000'0005)
|
||||
SpecialFolderDataBlock SPECIAL_FOLDER_PROPS;
|
||||
else if (BlockSignature == 0xA000'0003)
|
||||
TrackerDataBlock TRACKER_PROPS;
|
||||
else if (BlockSignature == 0xA000'000C)
|
||||
VistaAndAboveIDListDataBlock VISTA_AND_ABOVE_IDLIST_PROPS;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExtraData {
|
||||
ExtraDataBlock ExtraDataBlock[while(true)];
|
||||
};
|
||||
|
||||
struct LNK {
|
||||
ShellLinkHeader ShellLinkHeader;
|
||||
if (ShellLinkHeader.LinkFlags.HasLinkTargetIDList)
|
||||
LinkTargetIDList LinkTargetIDList;
|
||||
if (ShellLinkHeader.LinkFlags.HasLinkInfo)
|
||||
LinkInfo LinkInfo;
|
||||
StringData StringData;
|
||||
ExtraData ExtraData;
|
||||
};
|
||||
|
||||
LNK lnk @ 0x00;
|
||||
423
patterns/minidump.hexpat
Normal file
423
patterns/minidump.hexpat
Normal file
@@ -0,0 +1,423 @@
|
||||
#pragma MIME application/x-dmp
|
||||
|
||||
#include <type/time.pat>
|
||||
#include <type/types/win32.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
using RVA = ULONG32;
|
||||
using RVA64 = ULONG64;
|
||||
|
||||
enum MINIDUMP_STREAM_TYPE : ULONG32 {
|
||||
UnusedStream = 0,
|
||||
ReservedStream0 = 1,
|
||||
ReservedStream1 = 2,
|
||||
ThreadListStream = 3,
|
||||
ModuleListStream = 4,
|
||||
MemoryListStream = 5,
|
||||
ExceptionStream = 6,
|
||||
SystemInfoStream = 7,
|
||||
ThreadExListStream = 8,
|
||||
Memory64ListStream = 9,
|
||||
CommentStreamA = 10,
|
||||
CommentStreamW = 11,
|
||||
HandleDataStream = 12,
|
||||
FunctionTableStream = 13,
|
||||
UnloadedModuleListStream = 14,
|
||||
MiscInfoStream = 15,
|
||||
MemoryInfoListStream = 16,
|
||||
ThreadInfoListStream = 17,
|
||||
HandleOperationListStream = 18,
|
||||
TokenStream = 19,
|
||||
JavaScriptDataStream = 20,
|
||||
SystemMemoryInfoStream = 21,
|
||||
ProcessVmCountersStream = 22,
|
||||
IptTraceStream = 23,
|
||||
ThreadNamesStream = 24,
|
||||
ceStreamNull = 0x8000,
|
||||
ceStreamSystemInfo = 0x8001,
|
||||
ceStreamException = 0x8002,
|
||||
ceStreamModuleList = 0x8003,
|
||||
ceStreamProcessList = 0x8004,
|
||||
ceStreamThreadList = 0x8005,
|
||||
ceStreamThreadContextList = 0x8006,
|
||||
ceStreamThreadCallStackList = 0x8007,
|
||||
ceStreamMemoryVirtualList = 0x8008,
|
||||
ceStreamMemoryPhysicalList = 0x8009,
|
||||
ceStreamBucketParameters = 0x800A,
|
||||
ceStreamProcessModuleMap = 0x800B,
|
||||
ceStreamDiagnosisList = 0x800C,
|
||||
LastReservedStream = 0xFFFF
|
||||
};
|
||||
|
||||
struct MINIDUMP_LOCATION_DESCRIPTOR {
|
||||
type::Size32 DataSize;
|
||||
RVA Rva;
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY_DESCRIPTOR {
|
||||
ULONG64 StartOfMemoryRange;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR Memory;
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD {
|
||||
ULONG32 ThreadId;
|
||||
ULONG32 SuspendCount;
|
||||
ULONG32 PriorityClass;
|
||||
ULONG32 Priority;
|
||||
ULONG64 Teb;
|
||||
MINIDUMP_MEMORY_DESCRIPTOR Stack;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD_LIST {
|
||||
ULONG32 NumberOfThreads;
|
||||
MINIDUMP_THREAD Threads[NumberOfThreads];
|
||||
};
|
||||
|
||||
struct VS_FIXEDFILEINFO {
|
||||
DWORD dwSignature;
|
||||
DWORD dwStrucVersion;
|
||||
DWORD dwFileVersionMS;
|
||||
DWORD dwFileVersionLS;
|
||||
DWORD dwProductVersionMS;
|
||||
DWORD dwProductVersionLS;
|
||||
DWORD dwFileFlagsMask;
|
||||
DWORD dwFileFlags;
|
||||
DWORD dwFileOS;
|
||||
DWORD dwFileType;
|
||||
DWORD dwFileSubtype;
|
||||
DWORD dwFileDateMS;
|
||||
DWORD dwFileDateLS;
|
||||
};
|
||||
|
||||
struct MINIDUMP_MODULE {
|
||||
ULONG64 BaseOfImage;
|
||||
type::Size32 SizeOfImage;
|
||||
ULONG32 CheckSum;
|
||||
type::time32_t TimeDateStamp;
|
||||
RVA ModuleNameRva;
|
||||
VS_FIXEDFILEINFO VersionInfo;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR CvRecord;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR MiscRecord;
|
||||
ULONG64 Reserved0;
|
||||
ULONG64 Reserved1;
|
||||
|
||||
char16 ModuleName[] @ ModuleNameRva + 4 [[hidden]];
|
||||
} [[format("format_module")]];
|
||||
|
||||
fn format_module(ref MINIDUMP_MODULE module) {
|
||||
return module.ModuleName;
|
||||
};
|
||||
|
||||
struct MINIDUMP_MODULE_LIST {
|
||||
ULONG32 NumberOfModules;
|
||||
MINIDUMP_MODULE Modules[NumberOfModules];
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY_LIST {
|
||||
ULONG32 NumberOfMemoryRanges;
|
||||
MINIDUMP_MEMORY_DESCRIPTOR MemoryRanges[NumberOfMemoryRanges];
|
||||
};
|
||||
|
||||
struct MINIDUMP_EXCEPTION {
|
||||
ULONG32 ExceptionCode;
|
||||
ULONG32 ExceptionFlags;
|
||||
ULONG64 ExceptionRecord;
|
||||
ULONG64 ExceptionAddress;
|
||||
ULONG32 NumberParameters;
|
||||
padding[4];
|
||||
ULONG64 ExceptionInformation[15];
|
||||
};
|
||||
|
||||
struct MINIDUMP_EXCEPTION_STREAM {
|
||||
ULONG32 ThreadId;
|
||||
padding[4];
|
||||
MINIDUMP_EXCEPTION ExceptionRecord;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
|
||||
};
|
||||
|
||||
struct CPU_INFORMATION {
|
||||
ULONG32 VendorId[3];
|
||||
ULONG32 VersionInformation;
|
||||
ULONG32 FeatureInformation;
|
||||
ULONG32 AMDExtendedCpuFeatures;
|
||||
};
|
||||
|
||||
struct MINIDUMP_SYSTEM_INFO {
|
||||
USHORT ProcessorArchitecture;
|
||||
USHORT ProcessorLevel;
|
||||
USHORT ProcessorRevision;
|
||||
UCHAR NumberOfProcessors;
|
||||
UCHAR ProductType;
|
||||
ULONG32 MajorVersion;
|
||||
ULONG32 MinorVersion;
|
||||
ULONG32 BuildNumber;
|
||||
ULONG32 PlatformId;
|
||||
RVA CSDVersionRva;
|
||||
USHORT SuiteMask;
|
||||
USHORT Reserved;
|
||||
CPU_INFORMATION Cpu;
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD_EX {
|
||||
ULONG32 ThreadId;
|
||||
ULONG32 SuspendCount;
|
||||
ULONG32 PriorityClass;
|
||||
ULONG32 Priority;
|
||||
ULONG64 Teb;
|
||||
MINIDUMP_MEMORY_DESCRIPTOR Stack;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
|
||||
MINIDUMP_MEMORY_DESCRIPTOR BackingStore;
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD_EX_LIST {
|
||||
ULONG32 NumberOfThreads;
|
||||
MINIDUMP_THREAD_EX Threads[NumberOfThreads];
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY_DESCRIPTOR64 {
|
||||
ULONG64 StartOfMemoryRange;
|
||||
type::Size64 DataSize;
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY64_LIST {
|
||||
ULONG64 NumberOfMemoryRanges;
|
||||
RVA64 BaseRva;
|
||||
MINIDUMP_MEMORY_DESCRIPTOR64 MemoryRanges[NumberOfMemoryRanges];
|
||||
};
|
||||
|
||||
struct MINIDUMP_HANDLE_DESCRIPTOR {
|
||||
ULONG64 Handle;
|
||||
RVA TypeNameRva;
|
||||
RVA ObjectNameRva;
|
||||
ULONG32 Attributes;
|
||||
ULONG32 GrantedAccess;
|
||||
ULONG32 HandleCount;
|
||||
ULONG32 PointerCount;
|
||||
};
|
||||
|
||||
struct MINIDUMP_HANDLE_DESCRIPTOR_2 {
|
||||
ULONG64 Handle;
|
||||
RVA TypeNameRva;
|
||||
RVA ObjectNameRva;
|
||||
ULONG32 Attributes;
|
||||
ULONG32 GrantedAccess;
|
||||
ULONG32 HandleCount;
|
||||
ULONG32 PointerCount;
|
||||
RVA ObjectInfoRva;
|
||||
ULONG32 Reserved0;
|
||||
};
|
||||
|
||||
struct MINIDUMP_HANDLE_DATA_STREAM {
|
||||
ULONG32 SizeOfHeader;
|
||||
ULONG32 SizeOfDescriptor;
|
||||
ULONG32 NumberOfDescriptors;
|
||||
ULONG32 Reserved;
|
||||
|
||||
if (SizeOfDescriptor == 32)
|
||||
MINIDUMP_HANDLE_DESCRIPTOR HandleDescriptors[NumberOfDescriptors];
|
||||
else if (SizeOfDescriptor == 40)
|
||||
MINIDUMP_HANDLE_DESCRIPTOR_2 HandleDescriptors[NumberOfDescriptors];
|
||||
};
|
||||
|
||||
struct MINIDUMP_FUNCTION_TABLE_DESCRIPTOR {
|
||||
ULONG64 MinimumAddress;
|
||||
ULONG64 MaximumAddress;
|
||||
ULONG64 BaseAddress;
|
||||
ULONG32 EntryCount;
|
||||
type::Size32 SizeOfAlignPad;
|
||||
};
|
||||
|
||||
struct MINIDUMP_FUNCTION_TABLE_STREAM {
|
||||
type::Size32 SizeOfHeader;
|
||||
type::Size32 SizeOfDescriptor;
|
||||
type::Size32 SizeOfNativeDescriptor;
|
||||
type::Size32 SizeOfFunctionEntry;
|
||||
ULONG32 NumberOfDescriptors;
|
||||
ULONG32 SizeOfAlignPad;
|
||||
|
||||
MINIDUMP_FUNCTION_TABLE_DESCRIPTOR FunctionDescriptors[NumberOfDescriptors];
|
||||
};
|
||||
|
||||
struct MINIDUMP_UNLOADED_MODULE {
|
||||
ULONG64 BaseOfImage;
|
||||
type::Size32 SizeOfImage;
|
||||
ULONG32 CheckSum;
|
||||
ULONG32 TimeDateStamp;
|
||||
RVA ModuleNameRva;
|
||||
|
||||
char16 ModuleName[] @ ModuleNameRva + 4 [[hidden]];
|
||||
} [[format("format_unloaded_module")]];
|
||||
|
||||
fn format_unloaded_module(ref MINIDUMP_UNLOADED_MODULE module) {
|
||||
return module.ModuleName;
|
||||
};
|
||||
|
||||
struct MINIDUMP_UNLOADED_MODULE_LIST {
|
||||
ULONG32 SizeOfHeader;
|
||||
ULONG32 SizeOfEntry;
|
||||
ULONG32 NumberOfEntries;
|
||||
|
||||
if (SizeOfHeader > 12)
|
||||
padding[header.SizeOfHeader - 12];
|
||||
|
||||
MINIDUMP_UNLOADED_MODULE Modules[NumberOfEntries];
|
||||
};
|
||||
|
||||
struct MINIDUMP_MISC_INFO {
|
||||
ULONG32 SizeOfInfo;
|
||||
ULONG32 Flags1;
|
||||
ULONG32 ProcessId;
|
||||
ULONG32 ProcessCreateTime;
|
||||
ULONG32 ProcessUserTime;
|
||||
ULONG32 ProcessKernelTime;
|
||||
|
||||
if (SizeOfInfo > 24) {
|
||||
ULONG32 ProcessorMaxMhz;
|
||||
ULONG32 ProcessorCurrentMhz;
|
||||
ULONG32 ProcessorMhzLimit;
|
||||
ULONG32 ProcessorMaxIdleState;
|
||||
ULONG32 ProcessorCurrentIdleState;
|
||||
}
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY_INFO {
|
||||
ULONG64 BaseAddress;
|
||||
ULONG64 AllocationBase;
|
||||
ULONG32 AllocationProtect;
|
||||
padding[4];
|
||||
type::Size64 RegionSize;
|
||||
ULONG32 State;
|
||||
ULONG32 Protect;
|
||||
ULONG32 Type;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct MINIDUMP_MEMORY_INFO_LIST {
|
||||
ULONG SizeOfHeader;
|
||||
ULONG SizeOfEntry;
|
||||
ULONG64 NumberOfEntries;
|
||||
|
||||
if (SizeOfHeader > 16)
|
||||
padding[SizeOfHeader - 16];
|
||||
|
||||
MINIDUMP_MEMORY_INFO Info[NumberOfEntries];
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD_INFO {
|
||||
ULONG32 ThreadId;
|
||||
ULONG32 DumpFlags;
|
||||
ULONG32 DumpError;
|
||||
ULONG32 ExitStatus;
|
||||
ULONG64 CreateTime;
|
||||
ULONG64 ExitTime;
|
||||
ULONG64 KernelTime;
|
||||
ULONG64 UserTime;
|
||||
ULONG64 StartAddress;
|
||||
ULONG64 Affinity;
|
||||
};
|
||||
|
||||
struct MINIDUMP_THREAD_INFO_LIST {
|
||||
ULONG SizeOfHeader;
|
||||
ULONG SizeOfEntry;
|
||||
ULONG NumberOfEntries;
|
||||
|
||||
if (SizeOfHeader > 12)
|
||||
padding[SizeOfHeader - 12];
|
||||
|
||||
MINIDUMP_THREAD_INFO Info[NumberOfEntries];
|
||||
};
|
||||
|
||||
struct MINIDUMP_HANDLE_OPERATION_LIST {
|
||||
ULONG32 SizeOfHeader;
|
||||
ULONG32 SizeOfEntry;
|
||||
ULONG32 NumberOfEntries;
|
||||
ULONG32 Reserved;
|
||||
};
|
||||
|
||||
struct MINIDUMP_DIRECTORY {
|
||||
MINIDUMP_STREAM_TYPE StreamType;
|
||||
MINIDUMP_LOCATION_DESCRIPTOR Location;
|
||||
|
||||
if (StreamType == MINIDUMP_STREAM_TYPE::ThreadListStream)
|
||||
MINIDUMP_THREAD_LIST ThreadList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::ModuleListStream)
|
||||
MINIDUMP_MODULE_LIST ModuleList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::MemoryListStream)
|
||||
MINIDUMP_MEMORY_LIST MemoryList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::ExceptionStream)
|
||||
MINIDUMP_EXCEPTION_STREAM ExceptionInfo @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::SystemInfoStream)
|
||||
MINIDUMP_SYSTEM_INFO SystemInfo @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::ThreadExListStream)
|
||||
MINIDUMP_THREAD_EX_LIST ThreadExList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::Memory64ListStream)
|
||||
MINIDUMP_MEMORY64_LIST Mem64List @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::CommentStreamA)
|
||||
char Comment[] @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::CommentStreamW)
|
||||
char16 Comment[] @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::HandleDataStream)
|
||||
MINIDUMP_HANDLE_DATA_STREAM HandleData @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::FunctionTableStream)
|
||||
MINIDUMP_FUNCTION_TABLE_STREAM FunctionTable @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::UnloadedModuleListStream)
|
||||
MINIDUMP_UNLOADED_MODULE_LIST UnloadModuleList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::MiscInfoStream)
|
||||
MINIDUMP_MISC_INFO MiscInfo @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::MemoryInfoListStream)
|
||||
MINIDUMP_MEMORY_INFO_LIST MemInfoList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::ThreadInfoListStream)
|
||||
MINIDUMP_THREAD_INFO_LIST ThreadInfoList @ Location.Rva;
|
||||
else if (StreamType == MINIDUMP_STREAM_TYPE::HandleOperationListStream)
|
||||
MINIDUMP_HANDLE_OPERATION_LIST HandleOperList @ Location.Rva;
|
||||
};
|
||||
|
||||
bitfield MINIDUMP_TYPE {
|
||||
MiniDumpWithDataSegs : 1;
|
||||
MiniDumpWithFullMemory : 1;
|
||||
MiniDumpWithHandleData : 1;
|
||||
MiniDumpFilterMemory : 1;
|
||||
MiniDumpScanMemory : 1;
|
||||
MiniDumpWithUnloadedModules : 1;
|
||||
MiniDumpWithIndirectlyReferencedMemory : 1;
|
||||
MiniDumpFilterModulePaths : 1;
|
||||
MiniDumpWithProcessThreadData : 1;
|
||||
MiniDumpWithPrivateReadWriteMemory : 1;
|
||||
MiniDumpWithoutOptionalData : 1;
|
||||
MiniDumpWithFullMemoryInfo : 1;
|
||||
MiniDumpWithThreadInfo : 1;
|
||||
MiniDumpWithCodeSegs : 1;
|
||||
MiniDumpWithoutAuxiliaryState : 1;
|
||||
MiniDumpWithFullAuxiliaryState : 1;
|
||||
MiniDumpWithPrivateWriteCopyMemory : 1;
|
||||
MiniDumpIgnoreInaccessibleMemory : 1;
|
||||
MiniDumpWithTokenInformation : 1;
|
||||
MiniDumpWithModuleHeaders : 1;
|
||||
MiniDumpFilterTriage : 1;
|
||||
MiniDumpWithAvxXStateContext : 1;
|
||||
MiniDumpWithIptTrace : 1;
|
||||
MiniDumpScanInaccessiblePartialPages : 1;
|
||||
padding : 40;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct MINIDUMP_HEADER {
|
||||
char Signature[4];
|
||||
ULONG32 Version;
|
||||
ULONG32 NumberOfStreams;
|
||||
RVA StreamDirectoryRva;
|
||||
ULONG32 Checksum;
|
||||
type::time32_t TimeDateStamp;
|
||||
MINIDUMP_TYPE Flags;
|
||||
};
|
||||
|
||||
struct MINIDUMP {
|
||||
MINIDUMP_HEADER Header;
|
||||
MINIDUMP_DIRECTORY Streams[Header.NumberOfStreams] [[format_entries("format_stream")]];
|
||||
};
|
||||
|
||||
fn format_stream(ref MINIDUMP_DIRECTORY stream) {
|
||||
return stream.StreamType;
|
||||
};
|
||||
|
||||
MINIDUMP MiniDump @ 0x00;
|
||||
154
patterns/msgpack.hexpat
Normal file
154
patterns/msgpack.hexpat
Normal file
@@ -0,0 +1,154 @@
|
||||
#pragma MIME application/x-msgpack
|
||||
|
||||
enum Type : u8 {
|
||||
PositiveFixInt = 0x00 ... 0x7F,
|
||||
FixMap = 0x80 ... 0x8F,
|
||||
FixArray = 0x90 ... 0x9F,
|
||||
FixStr = 0xA0 ... 0xBF,
|
||||
Nil = 0xC0,
|
||||
Unused = 0xC1,
|
||||
False = 0xC2,
|
||||
True = 0xC3,
|
||||
Bin8 = 0xC4,
|
||||
Bin16 = 0xC5,
|
||||
Bin32 = 0xC6,
|
||||
Ext8 = 0xC7,
|
||||
Ext16 = 0xC8,
|
||||
Ext32 = 0xC9,
|
||||
Float32 = 0xCA,
|
||||
Float64 = 0xCB,
|
||||
Uint8 = 0xCC,
|
||||
Uint16 = 0xCD,
|
||||
Uint32 = 0xCE,
|
||||
Uint64 = 0xCF,
|
||||
Int8 = 0xD0,
|
||||
Int16 = 0xD1,
|
||||
Int32 = 0xD2,
|
||||
Int64 = 0xD3,
|
||||
FixExt1 = 0xD4,
|
||||
FixExt2 = 0xD5,
|
||||
FixExt4 = 0xD6,
|
||||
FixExt8 = 0xD7,
|
||||
FixExt16 = 0xD8,
|
||||
Str8 = 0xD9,
|
||||
Str16 = 0xDA,
|
||||
Str32 = 0xDB,
|
||||
Array16 = 0xDC,
|
||||
Array32 = 0xDD,
|
||||
Map16 = 0xDE,
|
||||
Map32 = 0xDF,
|
||||
NegativeFixInt = 0xE0 ... 0xFF
|
||||
};
|
||||
|
||||
fn format_positive_fixint(u8 value) {
|
||||
return value & 0b0111'1111;
|
||||
};
|
||||
|
||||
fn format_negative_fixint(u8 value) {
|
||||
return -(value & 0b0001'1111);
|
||||
};
|
||||
|
||||
using MessagePack;
|
||||
|
||||
struct MapEntry {
|
||||
MessagePack key, value;
|
||||
};
|
||||
|
||||
struct MessagePack {
|
||||
Type type;
|
||||
|
||||
if (u8(type) <= 0x7F) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_positive_fixint")]];
|
||||
} else if (u8(type) >= Type::NegativeFixInt) {
|
||||
$ -= 1;
|
||||
u8 value [[format("format_negative_fixint")]];
|
||||
} else if (type == Type::Uint8)
|
||||
be u8 value;
|
||||
else if (type == Type::Uint16)
|
||||
be u16 value;
|
||||
else if (type == Type::Uint32)
|
||||
be u32 value;
|
||||
else if (type == Type::Uint64)
|
||||
be u64 value;
|
||||
else if (type == Type::Int8)
|
||||
be s8 value;
|
||||
else if (type == Type::Int16)
|
||||
be s16 value;
|
||||
else if (type == Type::Int32)
|
||||
be s32 value;
|
||||
else if (type == Type::Int64)
|
||||
be s64 value;
|
||||
else if (type == Type::Float32)
|
||||
be float value;
|
||||
else if (type == Type::Float64)
|
||||
be double value;
|
||||
else if ((u8(type) & 0b1110'0000) == Type::FixStr)
|
||||
char value[u8(type) & 0b0001'1111];
|
||||
else if (type == Type::Str8) {
|
||||
be u8 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str16) {
|
||||
be u16 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Str32) {
|
||||
be u32 length;
|
||||
char value[length];
|
||||
} else if (type == Type::Bin8) {
|
||||
be u8 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin16) {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
} else if (type == Type::Bin32) {
|
||||
be u32 length;
|
||||
u8 value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixArray)
|
||||
MessagePack value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Array16) {
|
||||
be u16 length;
|
||||
MessagePack value[length];
|
||||
} else if (type == Type::Array32) {
|
||||
be u32 length;
|
||||
MessagePack value[length];
|
||||
} else if ((u8(type) & 0b1111'0000) == Type::FixMap)
|
||||
MapEntry value[u8(type) & 0b0000'1111];
|
||||
else if (type == Type::Map16) {
|
||||
be u16 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::Map32) {
|
||||
be u32 length;
|
||||
MapEntry value[length];
|
||||
} else if (type == Type::FixExt1) {
|
||||
s8 type;
|
||||
u8 data;
|
||||
} else if (type == Type::FixExt2) {
|
||||
s8 type;
|
||||
u16 data;
|
||||
} else if (type == Type::FixExt4) {
|
||||
s8 type;
|
||||
u32 data;
|
||||
} else if (type == Type::FixExt8) {
|
||||
s8 type;
|
||||
u64 data;
|
||||
} else if (type == Type::FixExt16) {
|
||||
s8 type;
|
||||
u128 data;
|
||||
} else if (type == Type::Ext8) {
|
||||
u8 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext16) {
|
||||
u16 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
} else if (type == Type::Ext32) {
|
||||
u32 length;
|
||||
s8 type;
|
||||
u8 data[length];
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
MessagePack pack @ 0x00;
|
||||
161
patterns/ntag.hexpat
Normal file
161
patterns/ntag.hexpat
Normal file
@@ -0,0 +1,161 @@
|
||||
bitfield AccessCapability {
|
||||
Read : 4;
|
||||
Write : 4;
|
||||
} [[left_to_right]];
|
||||
|
||||
struct CapabilityContainer {
|
||||
u8 magic;
|
||||
u8 version;
|
||||
u8 memorySize;
|
||||
AccessCapability accessCapability;
|
||||
};
|
||||
|
||||
bitfield NDEFFlags {
|
||||
MB : 1;
|
||||
ME : 1;
|
||||
CF : 1;
|
||||
SR : 1;
|
||||
IL : 1;
|
||||
TNF : 3;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum TNFType : u8 {
|
||||
Empty = 0x00,
|
||||
NFCForumWellKnownType = 0x01,
|
||||
MediaType = 0x02,
|
||||
AbsoluteURI = 0x03,
|
||||
NFCForumExternalType = 0x04,
|
||||
Unknown = 0x05,
|
||||
Unchanged = 0x06,
|
||||
Reserved = 0x07
|
||||
};
|
||||
|
||||
struct NDEF {
|
||||
NDEFFlags flags;
|
||||
u8 typeLength;
|
||||
|
||||
if (flags.SR)
|
||||
u8 payloadLength;
|
||||
else
|
||||
u32 payloadLength;
|
||||
|
||||
if (flags.IL)
|
||||
u8 idLength;
|
||||
|
||||
char type[typeLength];
|
||||
|
||||
if (flags.IL)
|
||||
u8 id[idLength];
|
||||
|
||||
u8 payload[payloadLength];
|
||||
|
||||
if (flags.ME)
|
||||
break;
|
||||
};
|
||||
|
||||
struct LockControl {
|
||||
u8 dynamicLockByteOffset;
|
||||
u8 numBits;
|
||||
u8 pageControlInfo;
|
||||
};
|
||||
|
||||
struct MemoryControl {
|
||||
u8 reservedBytesOffset;
|
||||
u8 numBytes;
|
||||
u8 pageSize;
|
||||
};
|
||||
|
||||
struct Length {
|
||||
u8 byte [[hidden, no_unique_address]];
|
||||
if (byte == 0xFF)
|
||||
u24 length;
|
||||
else
|
||||
u8 length;
|
||||
} [[sealed, transform("transform_length"), format("transform_length")]];
|
||||
|
||||
fn transform_length(Length length) {
|
||||
return length.length;
|
||||
};
|
||||
|
||||
enum Tag : u8 {
|
||||
NULL = 0x00,
|
||||
LockControl = 0x01,
|
||||
MemoryControl = 0x02,
|
||||
NDEFMessage = 0x03,
|
||||
Proprietary = 0xFD,
|
||||
TerminatorTLV = 0xFE
|
||||
};
|
||||
|
||||
struct TLV {
|
||||
Tag tag;
|
||||
if (tag == Tag::TerminatorTLV) {
|
||||
break;
|
||||
} else if (tag == Tag::NULL) {
|
||||
// Empty
|
||||
} else {
|
||||
Length length;
|
||||
|
||||
if (length > 0) {
|
||||
if (tag == Tag::LockControl) {
|
||||
LockControl lockControl;
|
||||
} else if (tag == Tag::MemoryControl) {
|
||||
LockControl lockControl;
|
||||
} else if (tag == Tag::NDEFMessage) {
|
||||
NDEF ndef[while(true)];
|
||||
} else {
|
||||
u8 value[length];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ManufacturerData {
|
||||
u8 serial1[3];
|
||||
u8 checkByte0;
|
||||
u8 serial2[4];
|
||||
u8 checkByte1;
|
||||
u8 internal;
|
||||
u16 lockBytes;
|
||||
};
|
||||
|
||||
struct DynamicLockBytes {
|
||||
u8 bytes[3];
|
||||
padding[1];
|
||||
};
|
||||
|
||||
bitfield MIRROR {
|
||||
MIRROR_CONF : 2;
|
||||
MIRROR_BYTE : 2;
|
||||
padding : 1;
|
||||
STRG_MOD_EN : 1;
|
||||
padding : 2;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield ACCESS {
|
||||
PROT : 1;
|
||||
CFGLCK : 1;
|
||||
padding : 1;
|
||||
NFC_CNT_EN : 1;
|
||||
NFC_CNT_PWD_PROT : 1;
|
||||
AUTHLIM : 3;
|
||||
};
|
||||
|
||||
struct Config {
|
||||
MIRROR MIRROR;
|
||||
u8 MIRROR_PAGE;
|
||||
u8 AUTH0;
|
||||
ACCESS ACCESS;
|
||||
u32 PWD;
|
||||
u16 PACK;
|
||||
};
|
||||
|
||||
struct NTAG {
|
||||
ManufacturerData manufacturerData;
|
||||
CapabilityContainer cc;
|
||||
TLV tlv[while(true)];
|
||||
padding[addressof(tlv) + cc.memorySize * 8 - sizeof(tlv)];
|
||||
DynamicLockBytes dynamicLockBytes;
|
||||
Config config;
|
||||
};
|
||||
|
||||
NTAG ntag @ 0x00;
|
||||
29
patterns/ogg.hexpat
Normal file
29
patterns/ogg.hexpat
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma MIME audio/ogg
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
bitfield HeaderType {
|
||||
Continuation : 1;
|
||||
BeginOfStream : 1;
|
||||
EndOfStream : 1;
|
||||
};
|
||||
|
||||
struct SegmentData {
|
||||
u8 data[parent.segmentTable[std::core::array_index()]];
|
||||
};
|
||||
|
||||
struct Ogg {
|
||||
char capturePattern[4];
|
||||
u8 version;
|
||||
HeaderType headerType;
|
||||
u64 granulePosition;
|
||||
u32 bitstreamSerialNumber;
|
||||
u32 pageSequenceNumber;
|
||||
u32 checksum;
|
||||
u8 pageSegments;
|
||||
u8 segmentTable[pageSegments];
|
||||
SegmentData data[pageSegments];
|
||||
};
|
||||
|
||||
Ogg ogg[while(!std::mem::eof())] @ 0x00;
|
||||
@@ -1,5 +1,14 @@
|
||||
#pragma MIME application/x-msdownload
|
||||
#pragma MIME application/x-dosexec
|
||||
|
||||
#pragma pattern_limit 100000
|
||||
#pragma array_limit 10000
|
||||
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/ctype.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
enum MachineType : u16 {
|
||||
Unknown = 0x00,
|
||||
AM33 = 0x1D3,
|
||||
@@ -7,9 +16,13 @@ enum MachineType : u16 {
|
||||
ARM = 0x1C0,
|
||||
ARM64 = 0xAA64,
|
||||
ARMNT = 0x1C4,
|
||||
DECAlphaAXP = 0x183,
|
||||
EBC = 0xEBC,
|
||||
I386 = 0x14C,
|
||||
I860 = 0x14D,
|
||||
IA64 = 0x200,
|
||||
LOONGARCH32 = 0x6232,
|
||||
LOONGARCH64 = 0x6264,
|
||||
M32R = 0x9041,
|
||||
MIPS16 = 0x266,
|
||||
MIPSFPU = 0x366,
|
||||
@@ -28,32 +41,99 @@ enum MachineType : u16 {
|
||||
WCEMIPSV2 = 0x169
|
||||
};
|
||||
|
||||
enum PEFormat : u16 {
|
||||
PE32 = 0x10B,
|
||||
PE32Plus = 0x20B
|
||||
};
|
||||
|
||||
enum SubsystemType : u16 {
|
||||
Unknown = 0x00,
|
||||
Native = 0x01,
|
||||
WindowsGUI = 0x02,
|
||||
WindowsCUI = 0x03,
|
||||
OS2CUI = 0x05,
|
||||
POSIXCUI = 0x07,
|
||||
Windows9xNative = 0x08,
|
||||
WindowsCEGUI = 0x09,
|
||||
EFIApplication = 0x0A,
|
||||
EFIBootServiceDriver = 0x0B,
|
||||
EFIRuntimeDriver = 0x0C,
|
||||
EFIROM = 0x0D,
|
||||
Xbox = 0x0E,
|
||||
WindowsBootApplication = 0x10
|
||||
};
|
||||
|
||||
bitfield Characteristics {
|
||||
stripped : 1;
|
||||
relocationsStripped : 1;
|
||||
executableImage : 1;
|
||||
lineNumsStripped : 1;
|
||||
localSymsStripped : 1;
|
||||
lineNumbersStripped : 1;
|
||||
localSymbolsStripped : 1;
|
||||
aggressiveWsTrim : 1;
|
||||
largeAddressAware : 1;
|
||||
reserved : 1;
|
||||
padding : 1;
|
||||
bytesReversedLo : 1;
|
||||
is32BitMachine : 1;
|
||||
debugStripped : 1;
|
||||
debugInfoStripped : 1;
|
||||
removableRunFromSwap : 1;
|
||||
netRunFromSwap : 1;
|
||||
system : 1;
|
||||
dll : 1;
|
||||
upSystemOnly : 1;
|
||||
uniprocessorMachineOnly : 1;
|
||||
bytesReversedHi : 1;
|
||||
};
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield DLLCharacteristics {
|
||||
padding : 4;
|
||||
padding : 1;
|
||||
highEntropyVA : 1;
|
||||
dynamicBase : 1;
|
||||
forceIntegrity : 1;
|
||||
nxCompatible : 1;
|
||||
noIsolation : 1;
|
||||
noSEH : 1;
|
||||
doNotBind : 1;
|
||||
appContainer : 1;
|
||||
wdmDriver : 1;
|
||||
cfGuard : 1;
|
||||
terminalServerAware : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield SectionFlags {
|
||||
padding : 3;
|
||||
doNotPad : 1;
|
||||
padding : 1;
|
||||
containsCode : 1;
|
||||
containsInitializedData : 1;
|
||||
containsUninitializedData : 1;
|
||||
linkOther : 1;
|
||||
comments : 1;
|
||||
padding : 1;
|
||||
remove : 1;
|
||||
comdat : 1;
|
||||
padding : 2;
|
||||
globalPointerRelocation : 1;
|
||||
purgeable : 1;
|
||||
is16Bit : 1;
|
||||
locked : 1;
|
||||
preloaded : 1;
|
||||
dataAlignment : 4;
|
||||
extendedRelocations : 1;
|
||||
discardable : 1;
|
||||
notCacheable : 1;
|
||||
notPageable : 1;
|
||||
shared : 1;
|
||||
executed : 1;
|
||||
read : 1;
|
||||
writtenTo : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DataDirectory {
|
||||
u32 virtualAddress;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct OptionalHeader32 {
|
||||
u16 magic;
|
||||
struct OptionalHeader {
|
||||
PEFormat magic;
|
||||
u8 majorLinkerVersion;
|
||||
u8 minorLinkerVersion;
|
||||
u32 sizeOfCode;
|
||||
@@ -61,8 +141,13 @@ struct OptionalHeader32 {
|
||||
u32 sizeOfUninitializedData;
|
||||
u32 addressOfEntryPoint;
|
||||
u32 baseOfCode;
|
||||
u32 baseOfData;
|
||||
u32 imageBase;
|
||||
if (magic == PEFormat::PE32) {
|
||||
u32 baseOfData;
|
||||
u32 imageBase;
|
||||
}
|
||||
else if (magic == PEFormat::PE32Plus) {
|
||||
u64 imageBase;
|
||||
}
|
||||
u32 sectionAlignment;
|
||||
u32 fileAlignment;
|
||||
u16 majorOperatingSystemVersion;
|
||||
@@ -75,87 +160,90 @@ struct OptionalHeader32 {
|
||||
u32 sizeOfImage;
|
||||
u32 sizeOfHeaders;
|
||||
u32 checksum;
|
||||
u16 subsystem;
|
||||
u16 dllCharacteristics;
|
||||
u32 sizeOfStackReserve;
|
||||
u32 sizeOfStackCommit;
|
||||
u32 sizeOfHeapReserve;
|
||||
u32 sizeOfHeapCommit;
|
||||
SubsystemType subsystem;
|
||||
DLLCharacteristics dllCharacteristics;
|
||||
if (magic == PEFormat::PE32) {
|
||||
u32 sizeOfStackReserve;
|
||||
u32 sizeOfStackCommit;
|
||||
u32 sizeOfHeapReserve;
|
||||
u32 sizeOfHeapCommit;
|
||||
}
|
||||
else if (magic == PEFormat::PE32Plus) {
|
||||
u64 sizeOfStackReserve;
|
||||
u64 sizeOfStackCommit;
|
||||
u64 sizeOfHeapReserve;
|
||||
u64 sizeOfHeapCommit;
|
||||
}
|
||||
u32 loaderFlags;
|
||||
u32 numberOfRvaAndSizes;
|
||||
DataDirectory directories[numberOfRvaAndSizes];
|
||||
u32 numberOfRVAsAndSizes;
|
||||
DataDirectory directories[numberOfRVAsAndSizes];
|
||||
};
|
||||
|
||||
struct OptionalHeader64 {
|
||||
u16 magic;
|
||||
u8 majorLinkerVersion;
|
||||
u8 minorLinkerVersion;
|
||||
u32 sizeOfCode;
|
||||
u32 sizeOfInitializedData;
|
||||
u32 sizeOfUninitializedData;
|
||||
u32 addressOfEntryPoint;
|
||||
u32 baseOfCode;
|
||||
u64 imageBase;
|
||||
u32 sectionAlignment;
|
||||
u32 fileAlignment;
|
||||
u16 majorOperatingSystemVersion;
|
||||
u16 minorOperatingSystemVersion;
|
||||
u16 majorImageVersion;
|
||||
u16 minorImageVersion;
|
||||
u16 majorSubsystemVersion;
|
||||
u16 minorSubSystemVersion;
|
||||
u32 win32VersionValue;
|
||||
u32 sizeOfImage;
|
||||
u32 sizeOfHeaders;
|
||||
u32 checksum;
|
||||
u16 subsystem;
|
||||
u16 dllCharacteristics;
|
||||
u64 sizeOfStackReserve;
|
||||
u64 sizeOfStackCommit;
|
||||
u64 sizeOfHeapReserve;
|
||||
u64 sizeOfHeapCommit;
|
||||
u32 loaderFlags;
|
||||
u32 numberOfRvaAndSizes;
|
||||
DataDirectory directories[numberOfRvaAndSizes];
|
||||
};
|
||||
|
||||
struct COFFHeader {
|
||||
u32 signature;
|
||||
struct COFFHeader {
|
||||
char signature[4];
|
||||
MachineType machine;
|
||||
u16 numberOfSections;
|
||||
u32 timeDateStamp;
|
||||
u32 pointerToSymbolTable;
|
||||
u32 numberOfSymbolTable;
|
||||
u32 numberOfSymbols;
|
||||
u16 sizeOfOptionalHeader;
|
||||
Characteristics characteristics;
|
||||
|
||||
if (machine == MachineType::AMD64) {
|
||||
OptionalHeader64 optionalHeader;
|
||||
} else {
|
||||
OptionalHeader32 optionalHeader;
|
||||
|
||||
if (sizeOfOptionalHeader > 0x00) {
|
||||
OptionalHeader optionalHeader;
|
||||
}
|
||||
};
|
||||
|
||||
struct DOSHeader {
|
||||
u16 signature;
|
||||
u8 header[0x3A];
|
||||
COFFHeader *coffHeaderPointer : u32;
|
||||
char signature[2];
|
||||
u16 lastPageSize;
|
||||
u16 numberOfPages;
|
||||
u16 relocations;
|
||||
u16 headerSizeInParagraphs;
|
||||
u16 minimumAllocatedParagraphs;
|
||||
u16 maximumAllocatedParagraphs;
|
||||
u16 initialSSValue;
|
||||
u16 initialRelativeSPValue;
|
||||
u16 checksum;
|
||||
u16 initialRelativeIPValue;
|
||||
u16 initialCSValue;
|
||||
u16 relocationsTablePointer;
|
||||
u16 overlayNumber;
|
||||
padding[4 * 2];
|
||||
u16 oemIdentifier;
|
||||
u16 oemInformation;
|
||||
padding[10 * 2];
|
||||
u32 coffHeaderPointer;
|
||||
};
|
||||
|
||||
fn isdosmessage(char c) {
|
||||
return std::ctype::isalnum(c) || c == '.' || c == ' ';
|
||||
};
|
||||
|
||||
struct DOSStub {
|
||||
u8 code[14];
|
||||
s8 message[0x27];
|
||||
u8 data[11];
|
||||
u8 code[while(std::mem::read_string($, 4) != "This")];
|
||||
char message[while(isdosmessage(std::mem::read_unsigned($, 1)))];
|
||||
char data[while(std::mem::read_unsigned($, 1) != 0x00)];
|
||||
};
|
||||
|
||||
union SectionMisc {
|
||||
u32 physicalAddress;
|
||||
u32 virtualSize;
|
||||
struct PEHeader {
|
||||
DOSHeader dosHeader;
|
||||
if (dosHeader.headerSizeInParagraphs * 16 < std::mem::size()) {
|
||||
DOSStub dosStub @ dosHeader.headerSizeInParagraphs * 16;
|
||||
}
|
||||
};
|
||||
|
||||
struct Section {
|
||||
PEHeader peHeader @ 0x00;
|
||||
|
||||
COFFHeader coffHeader @ peHeader.dosHeader.coffHeaderPointer;
|
||||
|
||||
struct SectionHeader {
|
||||
char name[8];
|
||||
SectionMisc misc;
|
||||
if (coffHeader.characteristics.executableImage) {
|
||||
u32 virtualSize;
|
||||
} else {
|
||||
u32 physicalAddress;
|
||||
}
|
||||
u32 virtualAddress;
|
||||
u32 sizeOfRawData;
|
||||
u32 ptrRawData;
|
||||
@@ -163,15 +251,436 @@ struct Section {
|
||||
u32 ptrLineNumbers;
|
||||
u16 numberOfRelocations;
|
||||
u16 numberOfLineNumbers;
|
||||
SectionFlags characteristics;
|
||||
};
|
||||
|
||||
SectionHeader sectionTable[coffHeader.numberOfSections] @ (addressof(coffHeader.characteristics) + 2) + coffHeader.sizeOfOptionalHeader;
|
||||
|
||||
u16 currentSectionIndex;
|
||||
fn updateSectionIndex() {
|
||||
currentSectionIndex = currentSectionIndex + 1;
|
||||
};
|
||||
|
||||
struct NullTerminatedString {
|
||||
char string[while(std::mem::read_unsigned($, 1) != 0x00)];
|
||||
padding[1];
|
||||
} [[inline]];
|
||||
|
||||
// Declarations of sections and variables used by it
|
||||
// Imports + Readonly Data Section
|
||||
struct DirectoryTable {
|
||||
u32 lookupTableRVA;
|
||||
u32 timeDateStamp;
|
||||
u32 forwarderChain;
|
||||
u32 dllNameRVA;
|
||||
u32 addressTableRVA;
|
||||
};
|
||||
|
||||
struct ImportsSection {
|
||||
DirectoryTable directoryTables[while(std::mem::read_unsigned($, 16) != 0x00)];
|
||||
DirectoryTable nullDirectoryTable;
|
||||
};
|
||||
|
||||
struct ReadonlyDataSection {
|
||||
u8 readonlyDataStart[while($ < coffHeader.optionalHeader.directories[1].virtualAddress - (sectionTable[currentSectionIndex].virtualAddress - sectionTable[currentSectionIndex].ptrRawData))];
|
||||
ImportsSection importsSection;
|
||||
u8 readonlyDataEnd[while($ < sectionTable[currentSectionIndex+1].ptrRawData)];
|
||||
};
|
||||
|
||||
// Resource Section
|
||||
struct ResourceDirectoryTable {
|
||||
u32 characteristics;
|
||||
u32 timeDateStamp;
|
||||
u16 majorVersion;
|
||||
u16 minorVersion;
|
||||
u16 nameEntriesAmount;
|
||||
u16 idEntriesAmount;
|
||||
};
|
||||
|
||||
enum ResourceID : u32 {
|
||||
Bitmap = 0x02,
|
||||
Icon = 0x03,
|
||||
Menu = 0x04,
|
||||
Dialog = 0x05,
|
||||
String = 0x06,
|
||||
GroupIcon = 0x0D,
|
||||
Version = 0x10,
|
||||
Manifest = 0x18
|
||||
};
|
||||
|
||||
struct IdDirectoryEntry {
|
||||
ResourceID id;
|
||||
u32 relativeOffsetToData;
|
||||
};
|
||||
|
||||
struct ResourceDirectory {
|
||||
ResourceDirectoryTable resourceDirectoryTable;
|
||||
IdDirectoryEntry idEntries[resourceDirectoryTable.idEntriesAmount];
|
||||
};
|
||||
|
||||
struct ResourceSection {
|
||||
ResourceDirectory rootDirectory;
|
||||
};
|
||||
|
||||
// Exports Section
|
||||
struct ExportDirectoryTable {
|
||||
u32 exportFlags;
|
||||
u32 timeDateStamp;
|
||||
u16 majorVersion;
|
||||
u16 minorVersion;
|
||||
u32 nameRVA;
|
||||
u32 ordinalBase;
|
||||
u32 addressTableEntries;
|
||||
u32 numberOfNamePointers;
|
||||
u32 exportAddressTableRVA;
|
||||
u32 namePointerRVA;
|
||||
u32 ordinalTableRVA;
|
||||
};
|
||||
|
||||
struct ExportAddress {
|
||||
if (std::mem::read_unsigned($, 4) > sectionTable[currentSectionIndex].sizeOfRawData && std::mem::read_unsigned($, 4) < sectionTable[currentSectionIndex].ptrRawData) {
|
||||
u32 exportRVA;
|
||||
}
|
||||
else {
|
||||
u32 forwarderRVA;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExportsSection {
|
||||
ExportDirectoryTable exportDirectoryTable;
|
||||
ExportAddress exportAddressTable[exportDirectoryTable.addressTableEntries];
|
||||
u32 exportNamePointerTable[exportDirectoryTable.numberOfNamePointers];
|
||||
};
|
||||
|
||||
// Exception Section
|
||||
bitfield ExceptionSectionBits {
|
||||
functionLength : 22;
|
||||
instructions32Bit : 1;
|
||||
exceptionHandler : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct FunctionTableEntry {
|
||||
if (coffHeader.machine == MachineType::MIPSFPU) {
|
||||
u32 beginVA;
|
||||
u32 endVA;
|
||||
u32 exceptionHandlerPointer;
|
||||
u32 handlerDataPointer;
|
||||
u32 prologEndVA;
|
||||
} else if (coffHeader.machine == MachineType::ARM || MachineType::ARM64 || MachineType::ARMNT || MachineType::POWERPC || MachineType::POWERPCFP || MachineType::SH3 || MachineType::SH4) {
|
||||
u32 beginVA;
|
||||
u8 prologLength;
|
||||
ExceptionSectionBits miscellaneousBits;
|
||||
} else if (coffHeader.machine == MachineType::AMD64 || MachineType::IA64) {
|
||||
u32 beginRVA;
|
||||
u32 endRVA;
|
||||
u32 unwindInformationRVA;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExceptionSection {
|
||||
FunctionTableEntry functionTableEntries[while($ < sectionTable[currentSectionIndex].ptrRawData + sectionTable[currentSectionIndex].sizeOfRawData)];
|
||||
};
|
||||
|
||||
// TLS Section
|
||||
struct TLSSection {
|
||||
if (coffHeader.optionalHeader.magic == PEFormat::PE32) {
|
||||
u32 rawDataStartVA;
|
||||
u32 rawDataEndVA;
|
||||
u32 indexAddress;
|
||||
u32 callbacksAddress;
|
||||
}
|
||||
else if (coffHeader.optionalHeader.magic == PEFormat::PE32Plus) {
|
||||
u64 rawDataStartVA;
|
||||
u64 rawDataEndVA;
|
||||
u64 indexAddress;
|
||||
u64 callbacksAddress;
|
||||
}
|
||||
u32 zeroFillSize;
|
||||
u32 characteristics;
|
||||
};
|
||||
|
||||
struct PEHeader {
|
||||
DOSHeader dosHeader;
|
||||
DOSStub dosStub;
|
||||
// Relocations Section
|
||||
bitfield RelocationWord {
|
||||
type : 4;
|
||||
offset : 12;
|
||||
};
|
||||
|
||||
PEHeader peHeader @ 0x00;
|
||||
struct BaseRelocationBlock {
|
||||
u32 pageRVA;
|
||||
u32 blockSize;
|
||||
RelocationWord word;
|
||||
};
|
||||
|
||||
Section sectionsTable[peHeader.dosHeader.coffHeaderPointer.numberOfSections]
|
||||
@ addressof(peHeader.dosHeader.coffHeaderPointer) + sizeof(peHeader.dosHeader.coffHeaderPointer);
|
||||
struct BaseRelocationTable {
|
||||
BaseRelocationBlock baseRelocationBlocks[while(std::mem::read_unsigned($, 8) != 0x00)];
|
||||
};
|
||||
|
||||
// General Section things
|
||||
enum I386Relocations : u16 {
|
||||
Absolute = 0x00,
|
||||
Dir16 = 0x01,
|
||||
Rel16 = 0x02,
|
||||
Dir32 = 0x06
|
||||
};
|
||||
|
||||
struct Relocation {
|
||||
u32 virtualAddress;
|
||||
u32 symbolTableIndex;
|
||||
if (coffHeader.machine == MachineType::I386) {
|
||||
I386Relocations type;
|
||||
}
|
||||
else {
|
||||
u16 type;
|
||||
}
|
||||
};
|
||||
|
||||
struct LineNumber {
|
||||
u32 lineNumber @ $ + 4;
|
||||
if (lineNumber > 0x00) {
|
||||
u32 virtualAddress @ $ - 8;
|
||||
} else {
|
||||
u32 symbolTableIndex @ $ - 8;
|
||||
}
|
||||
$ += 8;
|
||||
};
|
||||
|
||||
fn importsSectionExists() {
|
||||
bool returnedValue = false;
|
||||
std::print("Checking which section is .idata for read-only data section");
|
||||
for (u16 i = 0, i < coffHeader.numberOfSections, i = i + 1) {
|
||||
std::print("Checking section " + std::string::to_string(i));
|
||||
if (sectionTable[i].name == ".idata") {
|
||||
std::print("Check successful. Section " + std::string::to_string(i) + " is .idata, so the read-only data section won't have an imports section in it");
|
||||
returnedValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!returnedValue) {
|
||||
std::print("Check failed! This means there is no separate imports section");
|
||||
}
|
||||
return returnedValue;
|
||||
};
|
||||
|
||||
struct Section {
|
||||
if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".pdata")) { // Exception section
|
||||
ExceptionSection exceptionSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".rdata")) {// Read-only data section
|
||||
if (importsSectionExists() || coffHeader.optionalHeader.directories[1].size == 0) {
|
||||
u8 readonlyDataSection[sectionTable[currentSectionIndex].sizeOfRawData];
|
||||
}
|
||||
else {
|
||||
ReadonlyDataSection readonlyDataSection;
|
||||
}
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".idata")) {// Imports section
|
||||
ImportsSection importsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".edata")) {// Exports section
|
||||
ExportsSection exportsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".rsrc")) { // Resource section
|
||||
ResourceSection resourceSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".tls")) { // Thread-local storage section
|
||||
TLSSection tlsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".reloc")) {// Thread-local storage section
|
||||
BaseRelocationTable relocationsSection;
|
||||
}
|
||||
else {
|
||||
u8 freeformSection[sectionTable[currentSectionIndex].sizeOfRawData]; // Freeform data section
|
||||
}
|
||||
|
||||
// Additional things
|
||||
//Relocation relocations[sectionTable[currentSectionIndex].numberOfRelocations] @ sectionTable[currentSectionIndex].ptrRelocations;
|
||||
LineNumber lineNumbers[sectionTable[currentSectionIndex].numberOfLineNumbers] @ sectionTable[currentSectionIndex].ptrLineNumbers;
|
||||
|
||||
// Next section
|
||||
if (currentSectionIndex < coffHeader.numberOfSections-1) { // If it's not the last section (to avoid problems this code would have with it)
|
||||
updateSectionIndex(); // Make the current section index the next section's index
|
||||
if (sectionTable[currentSectionIndex].sizeOfRawData > 0) { // If the size of this section is bigger than 0
|
||||
$ = sectionTable[currentSectionIndex].ptrRawData; // Put the current offset at the start of the next section
|
||||
}
|
||||
}
|
||||
} [[inline]];
|
||||
|
||||
Section sections[coffHeader.numberOfSections] @ sectionTable[0].ptrRawData;
|
||||
|
||||
// Symbol & String Tables
|
||||
enum SectionNumberType : s16 {
|
||||
Undefined = 0,
|
||||
Absolute = -1,
|
||||
Debug = -2
|
||||
};
|
||||
|
||||
enum SymbolTypeMSB : u8 {
|
||||
Null = 0x00,
|
||||
Pointer = 0x10,
|
||||
Function = 0x20,
|
||||
Array = 0x30
|
||||
};
|
||||
|
||||
enum SymbolTypeLSB : u8 {
|
||||
Null = 0x00,
|
||||
Void = 0x01,
|
||||
Char = 0x02,
|
||||
Short = 0x03,
|
||||
Integer = 0x04,
|
||||
Long = 0x05,
|
||||
Float = 0x06,
|
||||
Double = 0x07,
|
||||
Struct = 0x08,
|
||||
Union = 0x09,
|
||||
Enum = 0x0A,
|
||||
MemberOfEnum = 0x0B,
|
||||
Byte = 0x0C,
|
||||
Word = 0x0D,
|
||||
UInt = 0x0E,
|
||||
DWord = 0x0F
|
||||
};
|
||||
|
||||
enum StorageClassType : s8 {
|
||||
EndOfFunction = -1,
|
||||
Null = 0,
|
||||
Automatic = 1,
|
||||
External = 2,
|
||||
Static = 3,
|
||||
Register = 4,
|
||||
DefinedExternally = 5,
|
||||
Label = 6,
|
||||
UndefinedLabel = 7,
|
||||
MemberOfStruct = 8,
|
||||
Argument = 9,
|
||||
StructTag = 10,
|
||||
MemberOfUnion = 11,
|
||||
UnionTag = 12,
|
||||
TypeDefinition = 13,
|
||||
UndefinedStatic = 14,
|
||||
EnumTag = 15,
|
||||
MemberOfEnum = 16,
|
||||
RegisterParameter = 17,
|
||||
Bitfield = 18,
|
||||
Block = 100,
|
||||
BlockFunction = 101,
|
||||
EndOfStruct = 102,
|
||||
File = 103,
|
||||
Section = 104,
|
||||
WeakExternal = 105,
|
||||
CLRToken = 107
|
||||
};
|
||||
|
||||
struct SymbolNameAddress {
|
||||
u32 zeroes;
|
||||
u32 offset;
|
||||
};
|
||||
|
||||
struct SymbolName {
|
||||
if (std::mem::read_unsigned($, 4) == 0) {
|
||||
SymbolNameAddress nameAddress;
|
||||
}
|
||||
else {
|
||||
char shortName[8];
|
||||
}
|
||||
};
|
||||
|
||||
struct SymbolType {
|
||||
SymbolTypeMSB msb;
|
||||
SymbolTypeLSB lsb;
|
||||
};
|
||||
|
||||
struct Symbol {
|
||||
SymbolName name;
|
||||
u32 value;
|
||||
SectionNumberType sectionNumber;
|
||||
SymbolType type;
|
||||
StorageClassType storageClass;
|
||||
u8 numberOfAuxSymbols;
|
||||
};
|
||||
|
||||
Symbol symbolTable[coffHeader.numberOfSymbols] @ coffHeader.pointerToSymbolTable;
|
||||
|
||||
struct StringTable {
|
||||
u32 size;
|
||||
NullTerminatedString strings[while($ < addressof(this) + size)];
|
||||
} [[inline]];
|
||||
|
||||
StringTable stringTable[coffHeader.numberOfSymbols > 0] @ addressof(symbolTable) + sizeof(symbolTable);
|
||||
|
||||
// Rich Header
|
||||
enum ProductType : u16 {
|
||||
Unmarked = 0x00 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
Imports = 0x01 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
STDLIBDLL = 0x04 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CVTRes = 0x06 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CCompiler = 0x0A ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CPPCompiler = 0x0B ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
OldNames = 0x0C ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
MASM613 = 0x0E ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003Assembler = 0x0F ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002Linker = 0x19 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002CCompiler = 0x1C ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002CPPCompiler = 0x1D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003SDKIMP = 0x5D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003CPPCompiler = 0x60 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2008SDKIMP = 0x93 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
Linker12 = 0x9D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
MASM10 = 0x9E ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2010CCompiler = 0xAA ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2010CPPCompiler = 0xAB ^ richHeaderEnd[0].mask.maskArray[1]
|
||||
};
|
||||
|
||||
union RichHeaderMask {
|
||||
u32 maskVariable;
|
||||
u16 maskArray[2];
|
||||
};
|
||||
|
||||
struct RichHeaderEnd {
|
||||
char signature[4];
|
||||
RichHeaderMask mask;
|
||||
} [[inline]];
|
||||
|
||||
u8 richHeaderAmount;
|
||||
u8 richHeaderEndPosition;
|
||||
u8 richHeaderCorpusPosition;
|
||||
fn initializeRichHeader() {
|
||||
$ = sizeof(peHeader);
|
||||
while ($ < peHeader.dosHeader.coffHeaderPointer) {
|
||||
if (std::mem::read_string($, 4) == "Rich") {
|
||||
richHeaderAmount = 1;
|
||||
richHeaderEndPosition = $;
|
||||
break;
|
||||
}
|
||||
$ += 1;
|
||||
}
|
||||
};
|
||||
initializeRichHeader();
|
||||
|
||||
RichHeaderEnd richHeaderEnd[richHeaderAmount] @ richHeaderEndPosition;
|
||||
|
||||
struct Product {
|
||||
u16 buildNumber;
|
||||
ProductType productID;
|
||||
u32 objectCount;
|
||||
};
|
||||
|
||||
struct RichHeaderCorpus {
|
||||
char maskedSignature[4];
|
||||
u32 nullPadding[3];
|
||||
Product products[while($ != richHeaderEndPosition)];
|
||||
} [[inline]];
|
||||
|
||||
fn setupRichHeader() {
|
||||
if (richHeaderAmount > 0) {
|
||||
//0x20 is the size of a Rich Header with one product
|
||||
for (u8 richCursor = $ - 0x20, richCursor > sizeof(peHeader), richCursor = richCursor - 0x01) {
|
||||
if (str(std::mem::read_unsigned(richCursor, 4) ^ richHeaderEnd[0].mask.maskVariable) == "DanS") {
|
||||
richHeaderCorpusPosition = richCursor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
setupRichHeader();
|
||||
|
||||
RichHeaderCorpus richHeaderCorpus[richHeaderAmount] @ richHeaderCorpusPosition;
|
||||
|
||||
66
patterns/protobuf.hexpat
Normal file
66
patterns/protobuf.hexpat
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <std/mem.pat>
|
||||
|
||||
#include <type/leb128.pat>
|
||||
|
||||
struct ZigZag32 {
|
||||
u32 value;
|
||||
} [[sealed, format("format_zigzag32")]];
|
||||
|
||||
fn format_zigzag32(ZigZag32 zigzag) {
|
||||
return s32((s32(zigzag.value) << 1) ^ (s32(zigzag.value) >> 31));
|
||||
};
|
||||
|
||||
struct ZigZag64 {
|
||||
u64 value;
|
||||
} [[sealed, format("format_zigzag64")]];
|
||||
|
||||
fn format_zigzag64(ZigZag64 zigzag) {
|
||||
return s64((s64(zigzag.value) << 1) ^ (s64(zigzag.value) >> 63));
|
||||
};
|
||||
|
||||
enum WireType : u8 {
|
||||
Varint = 0,
|
||||
_64Bit = 1,
|
||||
LengthDelimited = 2,
|
||||
StartGroup = 3,
|
||||
EndGroup = 4,
|
||||
_32Bit = 5
|
||||
};
|
||||
|
||||
bitfield Key {
|
||||
field_number : 5;
|
||||
wire_type : 3;
|
||||
} [[left_to_right]];
|
||||
|
||||
union _64Bit {
|
||||
u64 fixed64;
|
||||
ZigZag64 sfixed64;
|
||||
double dbl;
|
||||
};
|
||||
|
||||
union _32Bit {
|
||||
u32 fixed32;
|
||||
ZigZag32 sfixed32;
|
||||
float flt;
|
||||
};
|
||||
|
||||
struct LengthDelimited {
|
||||
type::LEB128 length;
|
||||
char data[length];
|
||||
};
|
||||
|
||||
|
||||
struct Entry {
|
||||
Key key;
|
||||
|
||||
if (key.wire_type == WireType::Varint)
|
||||
type::LEB128 value;
|
||||
else if (key.wire_type == WireType::_64Bit)
|
||||
_64Bit value;
|
||||
else if (key.wire_type == WireType::LengthDelimited)
|
||||
LengthDelimited value;
|
||||
else if (key.wire_type == WireType::_32Bit)
|
||||
_32Bit value;
|
||||
};
|
||||
|
||||
Entry entries[while(!std::mem::eof())] @ 0x00;
|
||||
38
patterns/stl.hexpat
Normal file
38
patterns/stl.hexpat
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma MIME model/stl
|
||||
#pragma MIME model/x.stl-binary
|
||||
#pragma MIME model/x.stl-ascii
|
||||
#pragma MIME application/sla
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
struct Vector3f {
|
||||
float x, y, z;
|
||||
} [[static, format("format_vector3f")]];
|
||||
|
||||
fn format_vector3f(Vector3f vec) {
|
||||
return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z);
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
Vector3f normal;
|
||||
Vector3f points[3];
|
||||
u16 flags;
|
||||
} [[static]];
|
||||
|
||||
struct BinarySTLHeader {
|
||||
char caption[];
|
||||
padding[80 - sizeof(caption)];
|
||||
u32 triangleCount;
|
||||
};
|
||||
|
||||
struct STL {
|
||||
if (std::mem::read_string(0, 6) == "solid ")
|
||||
std::warning("ASCII STL file!");
|
||||
else {
|
||||
BinarySTLHeader header;
|
||||
Triangle triangles[header.triangleCount];
|
||||
}
|
||||
};
|
||||
|
||||
STL stl @ 0x00;
|
||||
193
patterns/vhdx.hexpat
Normal file
193
patterns/vhdx.hexpat
Normal file
@@ -0,0 +1,193 @@
|
||||
#include <std/io.pat>
|
||||
#include <std/ptr.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
struct FileTypeIdentifier {
|
||||
char signature[8];
|
||||
char16 creator[256];
|
||||
padding[0x1'0000 - sizeof(signature) - sizeof(creator)];
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
u32 sequenceHigh;
|
||||
u8 data[4084];
|
||||
u32 sequenceLow;
|
||||
} [[static]];
|
||||
|
||||
struct ZeroDescriptor {
|
||||
padding[4];
|
||||
u64 zeroLength;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct DataDescriptor {
|
||||
u32 trailingBytes;
|
||||
u64 leadingBytes;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct LogDescriptor {
|
||||
char signature[4];
|
||||
|
||||
if (signature == "zero")
|
||||
ZeroDescriptor descriptor [[inline]];
|
||||
else if (signature == "desc")
|
||||
DataDescriptor descriptor [[inline]];
|
||||
};
|
||||
|
||||
struct LogEntry {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
type::Size32 entryLength;
|
||||
u32 tail;
|
||||
u64 sequenceNumber;
|
||||
u32 descriptorCount;
|
||||
padding[4];
|
||||
type::GUID logGuid;
|
||||
u64 flushedFileOffset;
|
||||
u64 lastFileOffset;
|
||||
} [[static]];
|
||||
|
||||
bitfield BAT {
|
||||
State : 3;
|
||||
padding : 17;
|
||||
FileOffsetMB : 44;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield MetadataEntryFlags {
|
||||
IsUser : 1;
|
||||
IsVirtualDisk : 1;
|
||||
IsRequired : 1;
|
||||
padding : 29;
|
||||
};
|
||||
|
||||
bitfield FileParameterFlags {
|
||||
LeaveBlockAllocated : 1;
|
||||
HasParent : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
struct MetadataFileParameters {
|
||||
type::Size32 blockSize;
|
||||
FileParameterFlags flags;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskSize {
|
||||
type::Size64 virtualDiskSize;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskID {
|
||||
type::GUID virtualDiskID;
|
||||
};
|
||||
|
||||
struct MetadataLogicalSectorSize {
|
||||
type::Size32 logicalSectorSize;
|
||||
};
|
||||
|
||||
struct MetadataPhysicalSectorSize {
|
||||
type::Size32 physicalSectorSize;
|
||||
};
|
||||
|
||||
struct ParentLocatorEntry {
|
||||
u32 keyOffset;
|
||||
u32 valueOffset;
|
||||
u16 keyLength;
|
||||
u16 valueLength;
|
||||
|
||||
char key[keyLength] @ addressof(parent) + keyOffset;
|
||||
char value[valueLength] @ addressof(parent) + valueOffset;
|
||||
};
|
||||
|
||||
struct MetadataParentLocator {
|
||||
type::GUID locatorType;
|
||||
padding[2];
|
||||
u16 keyValueCount;
|
||||
ParentLocatorEntry entries[keyValueCount];
|
||||
};
|
||||
|
||||
fn metadata_relative(u128 offset) {
|
||||
return addressof(parent.parent);
|
||||
};
|
||||
|
||||
struct MetadataTableEntry {
|
||||
type::GUID itemID;
|
||||
|
||||
if (std::core::formatted_value(itemID) == "{CAA16737-FA36-4D43-B3B6-33F0AA44E76B}")
|
||||
MetadataFileParameters *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}")
|
||||
MetadataVirtualDiskSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}")
|
||||
MetadataVirtualDiskID *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}")
|
||||
MetadataLogicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}")
|
||||
MetadataPhysicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}")
|
||||
MetadataParentLocator *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else
|
||||
u32 dataOffset;
|
||||
|
||||
type::Size32 length;
|
||||
MetadataEntryFlags flags;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct MetadataRegion {
|
||||
char signature[8];
|
||||
padding[2];
|
||||
u16 entryCount;
|
||||
padding[20];
|
||||
MetadataTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct RegionTableEntry {
|
||||
type::GUID guid;
|
||||
|
||||
if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}")
|
||||
BAT *bat : u64;
|
||||
else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}")
|
||||
MetadataRegion *metadata : u64;
|
||||
else
|
||||
u64 fileOffset;
|
||||
|
||||
type::Size32 length;
|
||||
u32 required;
|
||||
};
|
||||
|
||||
struct RegionTable {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u32 entryCount;
|
||||
padding[4];
|
||||
|
||||
RegionTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u64 sequenceNumber;
|
||||
type::GUID fileWriteGuid, dataWriteGuid, logGuid;
|
||||
u16 logVersion;
|
||||
u16 version;
|
||||
type::Size32 logLength;
|
||||
LogEntry *log : u64;
|
||||
padding[4016];
|
||||
};
|
||||
|
||||
struct VHDX {
|
||||
FileTypeIdentifier fileTypeIdentifier;
|
||||
|
||||
Header header @ 0x1'0000;
|
||||
Header headerBackup @ 0x2'0000;
|
||||
|
||||
RegionTable regionTable @ 0x3'0000;
|
||||
RegionTable regionTableBackup @ 0x4'0000;
|
||||
};
|
||||
|
||||
VHDX vhdx @ 0x00;
|
||||
@@ -17,6 +17,7 @@ enum WaveFormatType : u16 {
|
||||
Unknown,
|
||||
PCM,
|
||||
MS_ADPCM,
|
||||
IEEEFloatingPoint,
|
||||
ALAW = 6,
|
||||
MULAW,
|
||||
IMA_ADPCM = 0x11,
|
||||
@@ -83,6 +84,10 @@ bitfield WaveMPEGFlags {
|
||||
padding : 11;
|
||||
};
|
||||
|
||||
struct WaveFormatIEEEFloatingPoint : WaveFormatPCM {
|
||||
|
||||
};
|
||||
|
||||
struct WaveFormatMPEG : WaveFormatEx {
|
||||
WaveMPEGLayer headLayersUsed;
|
||||
u32 headBitrate;
|
||||
@@ -169,7 +174,7 @@ struct WaveListItem : WaveChunk {
|
||||
} else if (chunkId == "note") {
|
||||
WaveNote note;
|
||||
} else {
|
||||
padding[chunkSize];
|
||||
padding[(chunkSize + 1) >> 1 << 1];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,38 +186,53 @@ struct WaveList {
|
||||
WaveListItem item[while ($ < listEnd)];
|
||||
};
|
||||
|
||||
u32 paddedChunkSize;
|
||||
|
||||
struct WavData {
|
||||
WaveChunk chunk;
|
||||
paddedChunkSize = (chunk.chunkSize + 1) >> 1 << 1;
|
||||
|
||||
if (chunk.chunkId == "fmt ") {
|
||||
WaveFormat fmt;
|
||||
|
||||
if (fmt.formatTag == WaveFormatType::PCM) {
|
||||
WaveFormatPCM pcmExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(pcmExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MS_ADPCM) {
|
||||
WaveFormatMSADPCM msAdpcmExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(msAdpcmExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MPEG) {
|
||||
WaveFormatMPEG mpegExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(mpegExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MPEGLAYER3) {
|
||||
WaveFormatMPEGLayer3 mpegLayer3ExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(mpegLayer3ExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::IEEEFloatingPoint) {
|
||||
WaveFormatIEEEFloatingPoint ieeFloatingPointExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(ieeFloatingPointExtraData)];
|
||||
} else {
|
||||
WaveFormatExDummy unknown;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(unknown)];
|
||||
}
|
||||
} else if (chunk.chunkId == "data") {
|
||||
padding[chunk.chunkSize];
|
||||
padding[paddedChunkSize];
|
||||
} else if (chunk.chunkId == "fact") {
|
||||
WaveFact fact;
|
||||
padding[paddedChunkSize - sizeof(fact)];
|
||||
} else if (chunk.chunkId == "smpl") {
|
||||
WaveSample smpl;
|
||||
padding[paddedChunkSize - sizeof(smpl)];
|
||||
} else if (chunk.chunkId == "cue ") {
|
||||
WaveCue cue;
|
||||
padding[paddedChunkSize - sizeof(cue)];
|
||||
} else if (chunk.chunkId == "LIST") {
|
||||
listEnd = $ + chunk.chunkSize;
|
||||
WaveList list;
|
||||
padding[paddedChunkSize % 1];
|
||||
} else {
|
||||
padding[chunk.chunkSize];
|
||||
padding[paddedChunkSize];
|
||||
}
|
||||
};
|
||||
|
||||
RiffHeader header @0x00;
|
||||
WavData data[while (!std::mem::eof())] @$;
|
||||
WavData data[while (!std::mem::eof())] @ $;
|
||||
|
||||
52
patterns/xilinx_bit.hexpat
Normal file
52
patterns/xilinx_bit.hexpat
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <std/mem.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
struct Flags {
|
||||
be u16 length;
|
||||
u8 value[length];
|
||||
};
|
||||
|
||||
struct TLV {
|
||||
char tag[parent.keySize];
|
||||
be u16 length;
|
||||
char value[length];
|
||||
};
|
||||
|
||||
struct Command {
|
||||
be u32 value;
|
||||
} [[static, sealed, format("format_command")]];
|
||||
|
||||
fn format_command(Command command) {
|
||||
u32 x = command.value;
|
||||
|
||||
if (x == 0x20000000) return "NOP";
|
||||
if (x == 0xAA995566) return "SYNC";
|
||||
if (x == 0x000000BB) return "Bus Width Sync";
|
||||
if (x == 0x11220044) return "Bus Width Detect";
|
||||
if (x == 0x30002001) return "Write to FAR";
|
||||
if (x == 0x28006000) return "Write to FDRO";
|
||||
if (x == 0x30000001) return "Write to CRC";
|
||||
if (x == 0x30018001) return "Write to IDCODE";
|
||||
if (x == 0x30004000) return "Write to FDRI";
|
||||
if (x == 0x30008001) return "Write to CMD";
|
||||
|
||||
if ((x & 0xF0000000) == 0x30000000)
|
||||
return std::format("Write to Register {}", (x & 0x0003E000) >> 13);
|
||||
|
||||
return std::format("0x{:08X}", x);
|
||||
};
|
||||
|
||||
struct Commands {
|
||||
char tag[parent.keySize];
|
||||
be u32 length;
|
||||
Command commands[length / 4];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
Flags flags;
|
||||
be u16 keySize;
|
||||
TLV tlv[4];
|
||||
Commands data;
|
||||
};
|
||||
|
||||
Header header @ 0x00;
|
||||
35
scripts/extract_legacy_hexproj.py
Normal file
35
scripts/extract_legacy_hexproj.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def extractData(projectName, jsonData, objectName, extension):
|
||||
if objectName in jsonData:
|
||||
with open(f"./{projectName}.{extension}", mode="w", encoding="utf-8") as output:
|
||||
output.write(jsonData[objectName])
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2 or not str(sys.argv[1]).endswith(".hexproj"):
|
||||
print(f"Usage: {sys.argv[0]} <filename.hexproj>")
|
||||
exit(1)
|
||||
|
||||
projectPath = sys.argv[1]
|
||||
with open(projectPath, mode="r", encoding="utf-8") as file:
|
||||
jsonData = json.loads(file.read())
|
||||
|
||||
projectName = Path(projectPath).stem
|
||||
|
||||
extractData(projectName, jsonData, "dataProcessor", "hexnode")
|
||||
extractData(projectName, jsonData, "pattern", "hexpat")
|
||||
|
||||
if "bookmarks" in jsonData:
|
||||
with open(f"./{projectName}.hexbm", mode="w", encoding="utf-8") as output:
|
||||
jsonOutput = {}
|
||||
jsonOutput["bookmarks"] = jsonData["bookmarks"]
|
||||
|
||||
output.write(json.dumps(jsonOutput, indent=4))
|
||||
|
||||
if "filePath" in jsonData:
|
||||
print(f"Project file used file {jsonData['filePath']}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,5 +1,8 @@
|
||||
#include <pl.hpp>
|
||||
#include <helpers/file.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
|
||||
#include <pl/core/errors/preprocessor_errors.hpp>
|
||||
#include <pl/core/errors/evaluator_errors.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
@@ -19,17 +22,20 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Running test {} on test file {}\n", includeName, includeFilePath.filename().string());
|
||||
|
||||
// Open pattern file
|
||||
pl::fs::File patternFile(includeFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File patternFile(includeFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!patternFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Setup Pattern Language Runtime
|
||||
pl::PatternLanguage runtime;
|
||||
{
|
||||
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){ pl::LogConsole::abortEvaluation("Include files should never use this pragma!"); return true; };
|
||||
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){
|
||||
pl::core::err::M0006.throwError("Include files should never use this pragma!");
|
||||
return false;
|
||||
};
|
||||
|
||||
runtime.setDataSource([&](pl::u64 address, pl::u8 *data, size_t size) {
|
||||
pl::LogConsole::abortEvaluation("Include files should never read from memory directly!");
|
||||
pl::core::err::E0011.throwError("Include files should never read from memory directly!");
|
||||
}, 0x00, 0x100000);
|
||||
runtime.setDangerousFunctionCallHandler([]{ return true; });
|
||||
runtime.setIncludePaths({ includePath });
|
||||
@@ -40,6 +46,8 @@ int main(int argc, char **argv) {
|
||||
runtime.addPragma("eval_depth", DummyPragmaHandler);
|
||||
runtime.addPragma("array_limit", DummyPragmaHandler);
|
||||
runtime.addPragma("pattern_limit", DummyPragmaHandler);
|
||||
|
||||
runtime.addDefine("__PL_UNIT_TESTS__");
|
||||
}
|
||||
|
||||
// Execute pattern
|
||||
@@ -47,14 +55,15 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Error during execution!\n");
|
||||
|
||||
if (const auto &hardError = runtime.getError(); hardError.has_value())
|
||||
fmt::print("Hard error: {}\n\n", hardError.value().what());
|
||||
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
|
||||
|
||||
for (const auto &[level, message] : runtime.getConsoleLog()) {
|
||||
switch (level) {
|
||||
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
|
||||
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
|
||||
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
|
||||
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
|
||||
using enum pl::core::LogConsole::Level;
|
||||
case Debug: fmt::print(" [DEBUG] "); break;
|
||||
case Info: fmt::print(" [INFO] "); break;
|
||||
case Warning: fmt::print(" [WARN] "); break;
|
||||
case Error: fmt::print(" [ERROR] "); break;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <helpers/file.hpp>
|
||||
#include <helpers/guards.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
#include <pl/helpers/guards.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <pl.hpp>
|
||||
#include <helpers/file.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
@@ -27,12 +27,12 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Running test {} on test file {}\n", patternName, testFilePath.stem().string());
|
||||
|
||||
// Open pattern file
|
||||
pl::fs::File patternFile(patternFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File patternFile(patternFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!patternFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Open test file
|
||||
pl::fs::File testFile(testFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File testFile(testFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!testFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -48,6 +48,7 @@ int main(int argc, char **argv) {
|
||||
runtime.setDangerousFunctionCallHandler([]{ return true; });
|
||||
runtime.setIncludePaths({ includePath });
|
||||
runtime.addPragma("MIME", DummyPragmaHandler);
|
||||
runtime.addDefine("__PL_UNIT_TESTS__");
|
||||
}
|
||||
|
||||
// Execute pattern
|
||||
@@ -55,14 +56,15 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Error during execution!\n");
|
||||
|
||||
if (const auto &hardError = runtime.getError(); hardError.has_value())
|
||||
fmt::print("Hard error: {}\n\n", hardError.value().what());
|
||||
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
|
||||
|
||||
for (const auto &[level, message] : runtime.getConsoleLog()) {
|
||||
switch (level) {
|
||||
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
|
||||
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
|
||||
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
|
||||
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
|
||||
using enum pl::core::LogConsole::Level;
|
||||
case Debug: fmt::print(" [DEBUG] "); break;
|
||||
case Info: fmt::print(" [INFO] "); break;
|
||||
case Warning: fmt::print(" [WARN] "); break;
|
||||
case Error: fmt::print(" [ERROR] "); break;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", message);
|
||||
|
||||
BIN
tests/patterns/test_data/bson.hexpat.bin
Normal file
BIN
tests/patterns/test_data/bson.hexpat.bin
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/elf.hexpat.elf
Normal file
BIN
tests/patterns/test_data/elf.hexpat.elf
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/lnk.hexpat.lnk
Normal file
BIN
tests/patterns/test_data/lnk.hexpat.lnk
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/msgpack.hexpat.bin
Normal file
BIN
tests/patterns/test_data/msgpack.hexpat.bin
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/ntag.hexpat.bin
Normal file
BIN
tests/patterns/test_data/ntag.hexpat.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user