Compare commits

...

214 Commits

Author SHA1 Message Date
Nik
4646e4b965 patterns/xilinx_bootgen: Remove unnecessary parent access after recent pl upgrade 2025-12-06 16:24:17 +01:00
WerWolv
9143996589 patterns/ac_unity: Rename folder to be clonable on Windows 2025-12-06 09:34:44 +01:00
Sean Apeler
7c3dcc1fcc patterns: Add pattern for Vector BLF Frame Logging Format (#409)
* Add Vector Binary Logging Format pattern

* Combine object header extensions into single type

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:15:57 +01:00
ellie 🌸
ea8b381ac5 patterns: Add kindle firmware update pattern (#454)
* add kindle update package

* add kindle update pattern to readme

* add header of kindle update as test

* add missing kindle cs2 devices

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:15:40 +01:00
Antonio Vazquez
998655f74a patterns/PcapNG: Rewrite hexpat for bugfixing (#462)
PcapNG: Rewrite hexpat.

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:15:28 +01:00
haruse23
681b208aab pattern: Add Assassin's Creed: Unity's Forge files and Data files (Compressed and Decompressed) (#448)
* Add Capcom's Devil May Cry 3 HD .mod hexpat

Hex Pattern file for Capcom's Devil May Cry 3 HD Collection's .mod (3D Models) files

* Update DMC3 HD Mod.hexpat

* Update DMC3 HD Mod.hexpat

* Update DMC3 HD Mod.hexpat

* Add files via upload

* Update README.md

* Rename DMC3 HD Mod.hexpat to dmc3_hd_mod.hexpat

* Delete patterns/dmc3_hd_mod.hexpat

* Delete tests/patterns/test_data/dmc3_hd_mod.hexpat.mod

* Add files via upload

* Update dmc3_hd_mod.hexpat

* Add files via upload

* Update README.md

* Update README.md

* Update README.md

* Add files via upload

* Update ACU_FORGE.hexpat

* Update README.md

* Update and rename ACU_DATA_Compressed.hexpat to acu_data_compressed.hexpat

* Update and rename ACU_FORGE.hexpat to acu_forge.hexpat

* Update README.md

* Update acu_data_compressed.hexpat

* Update acu_data_compressed.hexpat

* Add files via upload

* Update and rename ACU_DATA_Decompressed.hexpat to acu_data_decompressed.hexpat

* Update README.md

* Update acu_data_compressed.hexpat

* Update README.md

* Delete patterns/acu_data_compressed.hexpat

* Delete patterns/acu_data_decompressed.hexpat

* Delete patterns/acu_forge.hexpat

* Create acu_forge.hexpat

* Add files via upload

* Update and rename ACU_DATA_Compressed.hexpat to acu_data_compressed.hexpat

* Update and rename ACU_DATA_Decompressed.hexpat to acu_data_decompressed.hexpat

* Update README.md

* Delete patterns/dmc3_hd_mod.hexpat

* Create dmc3_hd_mod.hexpat

* Update README.md

* Update dmc3_hd_mod.hexpat

* Update README.md

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:02:07 +01:00
furidosu
64d86cbdd1 pattern: Add parquet.hexpat for Apache Parquet data file (#450)
* Add parquet.hexpat for Apache Parquet data file

> Apache Parquet is an open source, column-oriented data file format designed for efficient data storage and retrieval.
> -- https://parquet.apache.org

* Add parquet.hexpat test file

* Fix parquet.hexpat boolean parsing

* Fix parquet.hexpat ColumnChunkPlacer not placing last chunk

* Fix parquet.hexpat using VarInt = LEB128

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:01:54 +01:00
adiee5
285a2fc7d1 pattern: Atari 8-bit binary format (XEX) (#453)
* add atari XEX format

* Update README.md

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 22:01:41 +01:00
tympanicblock61
2a9676238f pattern: Add lua 4.0 pattern (#465)
* add lua 4.0 pattern

* fix offset the top level function is at

* Update README.md

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 21:54:19 +01:00
Hrant
ee340409db patterns: Added APFS pattern (#400)
* updated APFS hexpat

* fix null feature

---------

Co-authored-by: Hrant Tadevosyan <Hrant.Tadevosyan@connectwise.com>
2025-12-05 21:19:37 +01:00
Fabian Neundorf
84dff0c886 patterns: Add json support for glb files (#412)
* patterns: Add json support for glb files

This makes it possible to separate display the different buffer views,
accessors and images (even visualizing them).

Unfortunately the data within the JSON gets sometimes corrupted and this
is the reason, why it parses the JSON multiple times at some places.

* Use original style and only single json variable

* patterns: Reuse json from global variable in gltf

* patterns: Check component type in gltf only once

* patterns: Fix gltf pattern and add formatting

Removes the duplicate definition of `component_type_t` and also removes
the need to pass the `component_type` to `stride_type_t`.
2025-12-05 21:19:19 +01:00
F01TECH
28a297582b patterns: Added DFIR Patterns (#442)
* Added /DFIR/ with patterns

Added /DFIR/ sub-directory.
Contains modified versions of built-in patterns for semi-automated Disk/Volume/Filesystem parsing geared towards Digital Forensics.
Originals in /fs/ should remain in tact for spot placement.

* DFIR_README.md

* DFIR_README.md

* DFIR_README.md

* DISK_PARSER.hexpat

* DISK_PARSER.hexpat

* FAT32.hexpat

* exFAT.hexpat

* README.md

Added DFIR related hexpats to table.

* README.md

---------

Co-authored-by: Xtreme-Liberty <59177844+Xtreme-Liberty@users.noreply.github.com>
2025-12-05 21:18:56 +01:00
Lexi Mayfield
681b1a1ded patterns: Add support for KTX 1.0 textures (#451)
* Commit patterns I've collected

- AppleSingle/AppleDouble pattern, used for macOS resource forks.
- MAME CHD file format, currently only supports v5.
- KEX Engine proprietary TARC format, used by various Nightdive games.

* Add to README

* Add pattern for KTX 1.0 file

* Use import, add reference ktx file

* Add to README
2025-12-05 21:17:01 +01:00
Stephen Hewitt
0a09efdd20 patterns: Pattern for DOS EXE files (#452)
* Initial DOS file

* Update README.md

* Update README.md

* More README

* More README

* Add DOS EXE

From: https://clasqm.github.io/freedos-repo/Games.html

Name: Champ Galagon
2025-12-05 21:16:36 +01:00
gmestanley
0d8bd76c2c patterns: Improvements to NES & IPS, add SNES, NSF, NSFe (#455)
* Add credit to ne.hexpat

* Add many changes to nes.hexpat

* Fixing dependance on variables declared in if statement

* Added mappers and inline to NES 2.0 header, removed needless parenthesises

* Add files via upload

* Add files via upload

* Create nsf.hexpat

* Used full name of the SNES on description

* Add SNES, NSF & NSFe, new description for NES

* Removing erroneous condition in ips.hexpat's truncatedSize

* Removing unnecessary std.string import in ips.hexpat

* Added both locations for sections in PE, clearer variable names, reorganized DOS stub

* Delete patterns/nsfe.hexpat

* Delete patterns/nsfmetadata.hexpat

* Added chunks from NSFe to NSF

* Added NSFe

* Fix size of truncatedSize in ips.hexpat

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-12-05 21:15:50 +01:00
Lucia
a525160243 patterns: Added pattern for PopCap's Lua bytecode (#458)
* patterns: Added PopCap's proprietary Lua bytecode pattern.

* updated README to include new pattern

* fixed README link

* patterns/popcap_luc.hexpat: fixed comments and sources

* patterns/popcap_luc.hexpat: Changed datatype of filename to be more clear about its structure

* patterns/popcap_luc.hexpat: fixed improper handling of Nil type and added test file
2025-12-05 21:14:53 +01:00
Dexrn ZacAttack
c3946d33a7 patterns/java_class: Add class versions up to j26 (#459) 2025-12-05 21:14:31 +01:00
Khoo Hao Yit
cc7eb7d764 patterns: Add support for Unity Asset Bundle (#461) 2025-12-05 21:14:08 +01:00
Gal1leo Gal1lei
53384a4a54 patterns: Added Windows Notepad State File Parser (#463) 2025-12-05 21:12:45 +01:00
Nik
da005f0172 git: Fix json schema checking 2025-12-05 21:10:24 +01:00
Nik
b2f126d22f constants: Update constants to new system 2025-12-02 23:06:30 +01:00
Nik
7ea863269e build: Fix variable name for Git repository reference 2025-12-01 21:44:39 +01:00
Nik
faff9e0364 git: Add option to customize pattern language repo and git hash with workflow call 2025-12-01 21:38:00 +01:00
gmestanley
a35004665f patterns: Credit to NE and improvements on NES (#445)
* Add credit to ne.hexpat

* Add many changes to nes.hexpat

* Fixing dependance on variables declared in if statement

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-09-22 07:15:37 +02:00
Tim Schneeberger
4fc11f1b91 patterns: Add ESP32 image pattern (#449)
Co-authored-by: Nik <werwolv98@gmail.com>
2025-09-21 09:30:38 +00:00
ODeux
7a9a5097a2 patterns: Add Python Pickle Pattern (#446)
* Add pickle pattern file

* Add test file

* Update README.md

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-09-21 11:17:40 +02:00
Nik
0e67ee102b patterns/ico: Disable BMP processing until issues in the pattern language have been resolved 2025-09-21 10:44:20 +02:00
Zackary Newman
69077b919d patterns/ext4: Increase pattern limit to 2 GiB (#440) 2025-09-12 22:42:55 +02:00
Nightowl
297f611fed patterns: Add terminfo pattern (#437)
* patterns/terminfo: Add pattern for compiled term info entry files.

This adds support for the compiled (legacy and extended) term info entry files that are used for determining terminal capabilities.

* Add .bin extension to the terminfo test file.
2025-09-09 22:39:59 +02:00
DmitriLeon2000
b24ae36638 patterns: Add .gmf (Game Maker 3.x Data) pattern file and its test files (#438)
* Add .fas and .was pattern files (Oska DeskMates)

* Update .was pattern file

* Update .was/.wa3 pattern file

* Update README.md

* Update README.md

* Update .fas & .was pattern files

* Update README.md

* Update fas_oskasoftware_old.hexpat

* Added WAS test file

* Update WAS test file

* Update was_oskasoftware.hexpat

* Update was_oskasoftware.hexpat

* Update fas_oskasoftware_old.hexpat

* Update fas_oskasoftware.hexpat

* Update README.md

Replacing backward slashes with forward ones in the `WAS` row.

* Update fas_oskasoftware_old.hexpat

* Update was_oskasoftware.hexpat

* Add files via upload

* Add Game Maker 3.x Data pattern

* Update gmf.hexpat
2025-09-09 18:22:02 +02:00
Zackary Newman
50d776f497 patterns/ext4: Fix group descriptor table location for non-1024 block sizes (#439) 2025-09-09 18:21:12 +02:00
WerWolv
7dfacc4139 revert: includes/std: Added section parameters to a few std::mem functions 2025-09-06 07:38:18 +02:00
WerWolv
5359e385ea git: Added build folders to gitignore 2025-09-06 07:33:32 +02:00
Nik
75bcb487ee patterns/ico: Fixed duplicate variable name 2025-09-01 22:22:43 +02:00
Ivy Fan-Chiang
fb214600ec patterns/ico: Add embedded BMP and PNG parsing to ICO pattern (#426)
Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-31 14:32:21 +02:00
Kris Dekeyser
d95390ea42 patterns/jpeg: added support for extra data in APP0 section (#417)
Apple Multi-Picture Format JPEGs often have 4 extra bytes in the APP0 section. The pattern now skips any extra bytes beyond the fixed APP0 data.

Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-31 11:40:27 +02:00
Marc Jones
284ca8d325 patterns: Add UEFI Firmare Volume Variable Store pattern (#421)
* Add UEFI Firmare Volume Variable Store pattern

Add a pattern for UEFI Firmare Volume Variable store.
This file type is commonly used with virtual machine UEFI variable files,
like OVMF.fd used with QEMU. You could also extract a UEFI firmware binary
from a flash device, search for the FV Variable Store, and set this pattern
to the FV address.

Signed-off-by: Marc Jones <marcj303@gmail.com>

* Fixed description pragma

---------

Signed-off-by: Marc Jones <marcj303@gmail.com>
Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-31 11:38:32 +02:00
ODeux
6630180276 patterns: Add .NET BinaryFormatter pattern (#416)
* Add dotnet BinaryFormatter pattern

* Add dotnet BinaryFormatter test

* Update README.md

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-31 11:37:59 +02:00
Henri Asseily
ff68d1e23d patterns: Added Apple IIGS SHR + SHR 3200 + SHR PWA Animation pattern (#432)
* Added SHR pattern

* Added IIGS SHR animation test file

* Added pattern to readme

* Added description and author

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-31 11:36:00 +02:00
Tom Arrow
70dd55aa6b patterns/q3demo: Quake 3 demos: Handle corrupted files more gracefully (#414)
Quake 3 demos: Basic safeguard against corrupted files

Co-authored-by: Tom <tomarrowtomarrow@hotmail.com>
2025-08-31 11:31:20 +02:00
DmitriLeon2000
76f850c543 patterns/fas/was: Update FAS, WAS/WA3 pattern files and README.md (#425)
* Add .fas and .was pattern files (Oska DeskMates)

* Update .was pattern file

* Update .was/.wa3 pattern file

* Update README.md

* Update README.md

* Update .fas & .was pattern files

* Update README.md

* Update fas_oskasoftware_old.hexpat

* Added WAS test file

* Update WAS test file

* Update was_oskasoftware.hexpat

* Update was_oskasoftware.hexpat

* Update fas_oskasoftware_old.hexpat

* Update fas_oskasoftware.hexpat

* Update README.md

Replacing backward slashes with forward ones in the `WAS` row.

* Update fas_oskasoftware_old.hexpat

* Update was_oskasoftware.hexpat
2025-08-31 11:28:45 +02:00
MicroBlock
74c06b74f7 patterns/lua53: Fix lua53 long string (#427)
Update lua53.hexpat
2025-08-31 11:27:59 +02:00
Vemmi
f13d9d3894 patterns/upk-ue3: Add magic pragma (#436) 2025-08-31 11:23:09 +02:00
mjarduk
c4c75a9ab2 patterns: Add a pattern for Roblox .pack files (#435)
* Added the .pack format

* Clarified some fields by changing the naming
2025-08-25 22:22:32 +02:00
Nik
7278a22eb2 includes/std: Fix MagicSearch implementation not being found 2025-08-24 13:34:47 +02:00
Nik
91fd36097c includes/std: Fix use of std::mem::size and std::mem::base_address in library 2025-08-24 12:04:33 +02:00
Nik
afffd7eced includes/std: Added section parameters to a few std::mem functions 2025-08-24 12:00:05 +02:00
Lexi Mayfield
7fd79ec9fd patterns: Added AppleSingle, AppleDouble, CHD, TARC patterns (#431)
* Commit patterns I've collected

- AppleSingle/AppleDouble pattern, used for macOS resource forks.
- MAME CHD file format, currently only supports v5.
- KEX Engine proprietary TARC format, used by various Nightdive games.

* Add to README
2025-08-20 19:32:11 +02:00
Mark Jansen
6b9f39cc21 patterns: Add SDB pattern (#424)
Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-15 17:16:50 +02:00
Stephen Hewitt
9207282bcf patterns: Added Commodore BASIC (#428)
* Commodore BASIC

* Update desc

* I made it

* Implemented suggestion

* Implemented suggestion

* Test file

* Rename file

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-08-02 20:13:35 +02:00
WerWolv
5ed64f9f08 tests: Include patterns folder as include path to support import * from X as Y
#426
2025-08-02 19:29:16 +02:00
WerWolv
a75a7a5b98 git: Let the CI still work correctly in PRs 2025-07-29 22:26:27 +02:00
WerWolv
60c8d93449 git: Make sure other repos check out the right repo 2025-07-29 21:57:54 +02:00
WerWolv
d3b05fd753 git: Allow test action to be imported by other projects 2025-07-29 21:38:20 +02:00
paxcut
3b2f098b09 fix: fixed two typos in this theme (#423) 2025-07-18 08:39:37 -07:00
paxcut
f4f004f0eb improv: Added new text editor semantic highlighting themes. (#422)
* improv: Added new text editor semantic highlighting themes.

Current themes use the same colors  for all identifier types. These two new themes are just examples of what the new feature makes possible.
One aims to simulate CLion Darcula theme and the other is an extension of the original dark theme.

* fix: corrected entries to readme file

* fix: corrected base for the theme

Made sure readme looks correctly on fork and links go to files.
2025-07-16 07:01:43 -07:00
paxcut
5c6cb9dccc fix: issues with two remaining themes. (#420)
Both one-dark and nocturne used global-doc-comment instead of the correctly named doc-global-comment. Typos in Nocturned didn't prevent the theme from loading, but left annoying messages in the log. As explained by the author, the base color map must be one of the three that imhex loads by default, dark,light and/or classic. Even if that is not the case, the name given in base must be that of a valid color map that has been loaded prior to the ones that use it as a base.
2025-07-11 03:42:45 -07:00
paxcut
44717e9b19 fix: incorrect names and values for some colormap entries of the text editor. (#419)
fix: incorrect names and values for some colormap entries of the test editor.

Some names were changed from the original that need to be changed back to make the old colormaps compatible with the new system.
Also, the colors of the console text were incorrectly set to be equal to each other.
This Pr brings back the old names and hopefully fixes problems of incorrect color being used
2025-07-11 02:25:02 -07:00
Dominik Tamiołło
bc35349e0f PEF - fix export count calculation (#418)
* Initial version of PEF

* add pef test file

* Fixed export hash slot count calculation

---------

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-07-08 15:21:07 -07:00
Nik
fed5db4109 Add Capcom's Devil May Cry 3 HD .mod hexpat (#415)
* Add Capcom's Devil May Cry 3 HD .mod hexpat

Hex Pattern file for Capcom's Devil May Cry 3 HD Collection's .mod (3D Models) files

* Update DMC3 HD Mod.hexpat

* Update DMC3 HD Mod.hexpat

* Update DMC3 HD Mod.hexpat

* Add files via upload

* Update README.md

* Rename DMC3 HD Mod.hexpat to dmc3_hd_mod.hexpat

* Delete patterns/dmc3_hd_mod.hexpat

* Delete tests/patterns/test_data/dmc3_hd_mod.hexpat.mod

* Add files via upload

* Update dmc3_hd_mod.hexpat

---------

Co-authored-by: haruse23 <mrjokeromar123@outlook.com>
2025-07-08 14:51:54 -07:00
klirktag
1d41392215 Add support for medium and large mp4 files (#413)
add support for medium and large mp4
2025-06-29 07:33:48 -07:00
ruokeqx
0b75336638 feat(pcapng): add support for Decryption Secrets Block (#411)
feat(pcapng): add support for Decryption Secrets Block
2025-06-19 05:13:43 -07:00
C3pa
e3edbd5a6f Small documentation improvements (#408)
doc: add syntax highlighting to std::ptr::NullablePtr example, fix description of type::escape_bytes

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-06-17 23:55:51 -07:00
C3pa
b10a37af67 Docs: describe how to create multidimensional std::Array (#407)
doc: descirbe how to create multidimensional std::Array

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-06-17 23:46:33 -07:00
Dominik Tamiołło
103d434cc5 Add PEF (Preffered Executable Format) support (#406)
* Initial version of PEF

* add pef test file

---------

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-06-17 22:24:54 -07:00
Fabian Neundorf
7716b9d6e7 patterns: Add support for smk (#399)
* patterns: Add support for smk

* patterns: Use builtin function and separate SMK struct

---------

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-06-17 14:57:36 -07:00
Tom Arrow
ad1e300674 Quake 3 Engine demo pattern & test file (#402)
* Quake 3 Engine demo pattern & test file

* Quake 3 Engine demo: Increase limits (demo files can be big) and additional condition

* Quake 3 demo specify little endian

* Quake 3 demo format: Add message type detection

* Quake 3 demo format: Read serverTime for snapshot messages

* Quake 3 demo pattern: fixed bug/typo/sleepy coding

* Quake 3 demo pattern: Ability to read CS_SERVERINFO

* Quake 3 demo pattern: Read CS_SYSTEMINFO as well

* Quake 3 demo pattern: Read first serverCommand per message

* Added Quake 3 engine demo pattern to readme

* Change Quake 3 engine demo entry in readme table

---------

Co-authored-by: Tom <tomarrowtomarrow@hotmail.com>
2025-06-17 02:06:24 -07:00
zn123
e918ce52b9 Add flv.hexpat (#401)
* Add flv.hexpat

https://veovera.org/docs/enhanced/enhanced-rtmp-v2#flv-file-format-overview

* test flv.hexpat

* Update README.md

add flv patterns

* Update flv.hexpat

Optimize spaces

* Update flv.hexpat

fix
2025-06-16 20:25:54 -07:00
Nik
db4d62aa20 patterns/fs: Refactor all partition types into a FS module 2025-05-25 19:51:32 +02:00
WerWolv
d96bfbb942 tests: Execute and test format functions 2025-05-25 12:43:21 +02:00
Nik
2070c95f58 yara: Added crypto identification rules 2025-05-24 23:56:56 +02:00
Nik
877895741d includes/hex: Fixed Json types being twice the size they need to be 2025-05-17 19:45:30 +02:00
Nik
6b279b8375 patterns/exfat: Fixed eval depth error 2025-05-17 16:07:11 +02:00
Khoo Hao Yit
a692b22ecc patterns: Add support for exFAT (#398) 2025-05-17 13:13:35 +02:00
Claudius Coenen
2ae0499293 patterns/wintec_tes: Slightly nicer formatting in a list of entries (#397)
slightly nicer formatting in a list of entries
2025-05-16 20:25:04 +02:00
thrasher
bd06987e8e patterns/zip: Add zip64 support (#395)
Co-authored-by: Nik <werwolv98@gmail.com>
2025-05-15 21:22:20 +02:00
Fabian Neundorf
74e08623f1 patterns: Add support for flc/flic files (#396)
* patterns: Add support for flc/flic files

* patterns: Add #pragma description for flc

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-05-15 20:17:13 +02:00
Nik
a860c396fa patterns: Added Java HPROF pattern 2025-05-15 17:23:06 +02:00
Nik
da934e2045 patterns/optee_ta: Fixed missing author and description pragmas 2025-05-15 08:07:13 +02:00
Nik
394ef80611 patterns: Added OPTEE Trusted Application format 2025-05-13 22:17:05 +02:00
Grant Kim
2ce182b1b3 patterns/tiff: Tags for DNG and TIFF extensions (#376)
Add Tags for DNG and TIFF extensions

References: https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
https://helpx.adobe.com/camera-raw/digital-negative.html

Co-authored-by: Nik <werwolv98@gmail.com>
2025-05-10 13:59:22 +02:00
Glenn Hartmann
6cadad3d1f pattern/protobuf: Allow parsing of nested messages (#378)
Mostly this enables attempted recursive parsing of submessages. Note
that it is inherently impossible to determine the underlying data type
for LengthDelimited for sure, so this is a best-effort attempt. The user
can disable recursive submessage parsing via Settings.

Other minor changes:
* added #pragma MIME and #pragma endian directives
* enabled UTF-8 display for LengthDelimited types
* added signed LEB128 display for Varint types (although this doesn't
  seem to be working on my test case)
* swapped if/else-if structure for match
* fail upon receiving unknown or unsupported WireType

Co-authored-by: Nik <werwolv98@gmail.com>
2025-05-10 13:53:01 +02:00
David Schneider
7ad9cd4f41 patterns: Added support for GNU MO files (#383) 2025-05-10 11:49:02 +00:00
0xZ3R0
bcaeef31d7 pattern: Added DJI Firmware Pattern (#392)
* added IM*H pattern

* improved README
2025-05-10 13:35:14 +02:00
Niketin
ee8d2f50b7 pattern/bencode: Various fixes (#393)
* Fix bencode dictionary

When parsing a bencode dictionary, the end character 'e' was never
consumed. This caused a misinterpretation of the character as struct Value of
an unknown type 'e'.

* Fix bencode list

A list was not included in the Value's parsing logic so it may have
been mistakenly parsed as a string.

* Fix std::ctype::isprint not including space

The space character, 0x20, is considered as a printable character in ASCII
and in >=C89. Adding it to the range of std::ctype::isprint also fixes
other std::ctype functions that use it.

* Fix bencode byte string formatting

Byte strings do not render nicely in pattern data's value column if they
contain non-printable characters. This commit makes the value of byte
strings to be surrounded by quotation marks, and renders a warning text
without quotation marks if the byte string contains non-printable
characters.
2025-05-10 13:34:36 +02:00
DEREFERENC3D
5b8dde19a9 patterns: Added definition for the OpenRGB profile format (#387)
patterns: Add definition for the OpenRGB profile format (up to version 5)
2025-05-10 13:34:16 +02:00
Dhash Shrivathsa
0b0eff0cb6 pattern/macho: Load Commands should include additional specializations (LoadDyLib) (#386)
* add additional command specialization

* address PR feedback
2025-05-10 13:34:01 +02:00
Enaium
3185503be1 patterns: Added valve vpk pattern (#384) 2025-05-10 10:29:50 +00:00
Sabhya
3a64207e58 pattern: Added pcapng capture file pattern (#385)
add: pcapng hexpat
2025-05-10 12:26:39 +02:00
bluisblu
c94d42d5c0 patterns: Added Radcore Cement v1.2 file pattern (#382)
* Add Radcore Cement file pattern

* Update pattern list in README.md
2025-05-10 11:57:51 +02:00
Caleb Denio
45c4c1d35b patterns/uf2: Added magic number (#379) 2025-05-10 11:54:29 +02:00
Jean Pereira
f93be1ea06 themes: Added Nocture theme (#377)
minimal dark theme based on Dracula but more darker
2025-05-10 11:53:28 +02:00
Shadlock0133
5ed9c0fd4d patterns/elf: use Rel{a} structs for parsing REL{A} section data (#375) 2025-05-10 11:52:35 +02:00
C3pa
11d373319f pattern/pe: Check for imageNameRVA in pe.hexpat before reading imageName (#372) 2025-05-10 11:52:00 +02:00
Jonathan Ostrus
e7d366571d pattern/pex: Added formatter for opcode and some other name cleanups (#371) 2025-05-10 11:51:43 +02:00
Caleb Denio
b6df1742b6 patterns: Add ZIM pattern (#367)
* Add ZIM pattern file

* Add test file

* namespace!
2025-05-10 11:51:04 +02:00
Jake Ryan
0b9e83ff8a patterns: Add support for MagicaVoxel .vox files (#390)
* patterns: Added support for MagicaVoxel .vox files

* Fixed incorrect IMAP field size and added basic chunk size mismatch detection and recovery.

* Fixed pattern for "_r" values and added RotationToMat3.

* Added test vox file.

---------

Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
2025-04-30 08:55:53 -07:00
paxcut
c0fc748de6 fix: rgb color attribute is always blue.
The color attribute does not nclude an alpha component but the RGB types were including an alpha of 255 in their color attributes. The 0xFF was being assigned to the blue component hence the error.
2025-04-30 08:40:32 -07:00
Hrant
89307ba8a5 added NTFS pattern (#391)
Thank you!

* added NTFS pattern

* improved the PR

* remove test-data & fixed sd

---------

Co-authored-by: Hrant Tadevosyan <Hrant.Tadevosyan@connectwise.com>
2025-04-30 04:00:52 -07:00
ZHANG Yuntian
a12b5ba406 git: Fix table formatting (#374)
Signed-off-by: ZHANG Yuntian <yt@radxa.com>
2025-03-24 07:33:01 +01:00
ZHANG Yuntian
537ce67895 patterns/partition_table: Added basic MBR and GPT patterns (#358)
Both are conbined into a single pattern due to how GPT always has a pseudo MBR to maintain backward compatibility.
2025-03-24 07:15:25 +01:00
Scrivener07
1771c1f077 patterns: Added support for PEX Papyrus executables (#370)
Added support for PEX, Bethesda's Papyrus executable for compiled script files.
- Skyrim
- Fallout 4
- Fallout 76
- Starfield

Co-authored-by: Jonathan Ostrus <12855515+jbostrus@users.noreply.github.com>
2025-03-23 11:30:43 +01:00
Caleb
cef20e24a7 patterns/zip: Fix 0x5455 extended timestamp fields crash, improve date/time presentation (#363)
Co-authored-by: Nik <werwolv98@gmail.com>
2025-03-22 13:57:42 +01:00
Andreas Wallner
8e7cfd9442 patterns: Add STDFv4 pattern (#326) 2025-03-22 13:54:50 +01:00
5ec1cff
d0ba754dc2 patterns/zip: Handling padded extra fields (#369)
* Handling unresolved extra fields

* Update zip.hexpat

* Update zip.hexpat

* Update zip.hexpat
2025-03-22 13:54:26 +01:00
mheimlich
9f92c38ecf patterns: Add ADTFDAT pattern (#368) 2025-03-22 13:52:59 +01:00
Geky
0844e07056 patterns: Added DS Cartridge Header pattern, updated pyc versions (#366)
* add support for cartridge size type $54

Added support for cartridge size type $54, corresponding to 1.5 MiB (96 banks).

* add missing license

* Add GBA Cartridge Header

* Update README.md

Added GBA information to README.md and corrected a typo.

* Add DS Cartridge Header

* Update ReadMe.md

* Update pyc.hexpat

Included additional versions
2025-03-22 13:51:46 +01:00
C3pa
66fc006b08 includes/std: Update hex::dec::zlib_decompress description (#364)
docs: Update hex::dec::zlib_decompress description
2025-03-22 13:51:00 +01:00
Eddy S.
5bc66df14f patterns/elf: Set endianness globally (#362) 2025-03-22 13:50:17 +01:00
MrMcX
7310a10214 patterns: Add pattern for microsoft prefetch files (uncompressed SCCA format only) (#361)
* Add pattern for microsoft prefetch files (uncompressed SCCA format only)

* Update pf.hexpat

Add longer explanation
2025-03-22 13:49:50 +01:00
MrMcX
34ee3107e2 patterns: Implement Windows thumbcache pattern (#359)
* Implement Windows thumbcache pattern

* Include thumbcache pattern in README.md

* Update thumbcache.hexpat

- Use English warning text
- handle unknown file version
- add thanks to joachimmetz
- create virtual file
- use more elegant magic type

* Update thumbcache.hexpat

- Use padding data type for paddings

* Update thumbcache.hexpat

- make pattern more robust against single erroneous cache record
2025-03-22 13:48:57 +01:00
Shadlock0133
c4378ffb14 patterns/elf: Use e_shstrndx to get section names instead of guessing (#357) 2025-03-22 13:47:43 +01:00
eli_w
5ad7f0c1e7 patterns/ani: Improved compatibility with error size defined in ani files (#354) 2025-03-22 13:46:49 +01:00
Mrmaxmeier
df97fc7257 patterns/includes: More misc cleanups (#353)
* patterns/zip: simplify find_sequence_in_range check

hex(340282366920938463463374607431768211455) =
0xffffffffffffffffffffffffffffffff

* patterns/7z: use Magic<> for signature, add pragma

* patterns/{nro, ogg}: use Magic<> for signature

* patterns/ttf: refactor, check magic

Use the "Field field @ position;" syntax instead of saving and restoring
the cursor position.

* readme: fix copy-paste error in pattern listing
2025-03-22 13:46:06 +01:00
Vemmi
3ad263783d patterns: Added Unreal Engine 3 UPK pattern (#352)
* patterns: Add unreal 3 upk pattern

* readme: Add link to upk-ue3.hexpat
2025-03-22 13:45:25 +01:00
Ilya Sorochan
5ccd431320 patterns: Added RPM pattern (#350) 2025-03-22 13:44:55 +01:00
Nik
fb8e5e3f77 disassemblers/jvm: Fixed mask and mnemonic of areturn and athrow 2025-02-28 11:42:44 +01:00
paxcut
375145e759 include/std: std::ptr::relative_to_base_section not working anymore (#349)
Fixes #348 

In issue #348 it is stated that the pattern fails to find the variable baseAddress in the parent of the parent of the attribute function. One parent is required to access the variables on the pattern that is using the attribute.

That pattern is used in the pattern that contains baseAddress as a pointer to an array of the children pattern and that seems to require an extra parent level to be added in order to access baseAddress without errors. The fix was tested on an xbe file extracted from an xbox cd rom and while it failed without the fix as stated in issue 348 with the fix it ran to completion without issues.
2025-02-16 12:52:01 +01:00
paxcut
71eeed981d patterns/protobuf: Remove global variables
In issue #346 it is noted that the format functions return the same value repeatidly and erroneously. This is due to the use of global variables which result on only their last value being used in format functions due to their delayed evaluation. Fixed by using local variables instead. Also remove tabs from the file and an unused tags variable.
2025-01-30 20:24:11 +01:00
Fabian Neundorf
e779b88a58 patterns/iso: Fix incorrect condition (#344) 2025-01-23 21:44:44 +01:00
Fabian Neundorf
aef3d3451f patterns/iso: Add some improvements to the ISO pattern matching (#343)
* patterns: Load all ISO volume descriptors

* patterns: Parse supplementary volume descriptors

* patterns: Add system use in directory records for iso
2025-01-23 19:23:11 +01:00
Nik
c5fa53dcea includes/type: Make type::Formatted actually work as documented 2025-01-19 18:13:48 +01:00
The Wandering Trader
9a6cbdfe28 patterns: Add CAB pattern (#342)
* Add files via upload

* Add files via upload

* Update README.md
2025-01-19 00:13:04 +01:00
Nik
083042632d includes/hex: Hide implementation data of json types 2025-01-16 19:15:10 +01:00
Nik
4d172cebc3 patterns: Removed invalid zip test file 2025-01-14 20:07:03 +01:00
Nik
53ff0a5d62 patterns/afe2: Fixed misspelled of pragma 2025-01-14 20:06:39 +01:00
WerWolv
b3b730c6e9 patterns: Fixed various test binaries 2025-01-14 20:01:51 +01:00
Nik
8db011b6e5 patterns: Added MIME types and magic numbers to all patterns that have them 2025-01-14 20:01:36 +01:00
Nik
b936c04d21 patterns/gguf: Added #pragma magic to allow auto-loading the pattern 2025-01-14 18:21:16 +01:00
bake
bf56d4ff49 patterns: Add veado pattern (#339)
* Add veado pattern

* Add veado to README

* Add veado example file
2025-01-13 21:21:05 +01:00
Known Rabbit
fdc4a87389 patterns: Add bcss (BeyondCompare SnapShot) file (#338)
* patterns: add bcss (BeyondCompare SnapShot) file

* Add entry to readme

* Change table entries in alphabetical order

* Support both bcss file and uncompressed content

* Remove misleading cases, add warning message

* Add test cases to bcss.hexpat

* ifdef out ImHex-only functionality

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2025-01-13 21:20:36 +01:00
Mia
1f6c701348 patterns: Added sup pattern file (#337)
* Add sup pattern file

* Add files via upload

* Update README.md
2025-01-09 20:01:14 +01:00
JTurtle
4092dad428 includes/type: Fix error in float16 format function (#336) 2025-01-05 09:46:09 +01:00
Nik
559faebec3 patterns: Added simple SQLite3 database pattern 2024-12-28 19:57:48 +01:00
Nik
cde46e1f15 patterns/bgcode: Improve bgcode pattern 2024-12-28 18:51:34 +01:00
Nik
17c200a92e disassemblers/jvm: Added remaining instructions besides lookupswitch and tableswitch 2024-12-27 13:41:46 +01:00
Nik
384d4c7794 disassemblers: Added half of the JVM instructions 2024-12-27 01:07:36 +01:00
Nik
37a7e59c06 disassemblers: Added Intel 8051 architecture 2024-12-26 20:08:42 +01:00
Nik
e8cea09477 include/hex: Added definitions for new built-in types 2024-12-24 12:39:28 +01:00
Andrey Andreyevich Bienkowski
883433b260 includes/type: Fix parsing of signed leb128 (#333) 2024-12-18 21:49:16 +01:00
Nik
2db9993cb1 git: Fixed ninja package name 2024-12-18 21:45:45 +01:00
Nik
01ce565c9e git: Install ninja 2024-12-18 21:35:34 +01:00
Nik
b7b949ea27 git: Updated action runners 2024-12-18 20:53:54 +01:00
BobSmun
e026ff187e build: Improve build system (#327)
* *Add top level CMakeLists.txt, to make it easier to use both independently and from within other projects
* Add a unit_test target, to attach all unit tests to

* * Fix unit tests for windows
* Silence cmake warning regarding missing top project
* update .gitignore for vscode

---------

Co-authored-by: BobSmun <6492115+BobSmun@users.noreply.github.com>
2024-12-16 20:37:38 +01:00
Nik
63504f59a1 tests: Fixed fucked up include 2024-12-14 22:31:12 +01:00
Josef Šimánek
6113df643d git: Fix typo in readme (#332) 2024-12-14 16:35:25 +01:00
WerWolv
3f42dddd19 tests: Improve unit tests for includes and patterns 2024-12-14 16:34:27 +01:00
Luca Corbatto
2cc8868727 patterns: Added rar file pattern as requested in #258 (#324)
* Add rar file pattern as requested in #258

* Fix rar pattern

Removed some experimental (and apperantly broken) code.

* Break on EndOfArchive header instead of EOF

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-12-14 13:48:06 +01:00
Sabhya
7f02510762 patterns: Added dmp64.hexpat and test files (#331)
* [+] Added dmp64.hexpat && test files

* Fix encoding of pattern file

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-12-14 13:40:22 +01:00
Sewer.
13c4168af0 patterns/bzip3: Fixed Incorrect field on branch (#330) 2024-12-13 10:21:47 +01:00
Sewer.
1e69cd7fb2 patterns: Added BZip3 File Header Pattern (#329)
* Added: BZip3 Compression

* Fixed: Bound the SmallBlock data by parent's size

* Improved: Now uses the name 'Chunk' for block wrappers, such that the name 'block' matches with what the BZ3 API does

* Improved: Import rather than Include std::mem

* Added: Missing 'description' field in pragma
2024-12-12 21:56:13 +01:00
Sabhya
16a87df2ac patterns: Added DPAPI Blob, DPAPI MasterKey, CREDHIST patterns (#328)
* [+]Added DPAPI MasterKey & Updated README.md

* [+]Added DPAPI Blob Pattern & Updated README.md

* [+] Added CREDHIST Pattern &  Updated README.md

* [+] Test Files added for dpapimasterkey, dpapiblob & CREDHIST
2024-12-05 21:26:43 +01:00
kbugstar
b7598405b5 encodings: Added Chinese GBK encoding (#308)
Chinese Gbk encoding file
2024-12-01 17:19:14 +01:00
WerWolv
d14f8de459 includes/std: Added new palette control functions 2024-12-01 17:15:24 +01:00
WerWolv
4c96bfbeb3 patterns/fs: Fixed pattern and uploaded test data 2024-11-28 21:35:25 +01:00
Geky
500a3fe26e patterns: Added GBA ROM pattern (#323)
* add support for cartridge size type $54

Added support for cartridge size type $54, corresponding to 1.5 MiB (96 banks).

* add missing license

* Add GBA Cartridge Header

* Update README.md

Added GBA information to README.md and corrected a typo.
2024-11-28 17:59:45 +01:00
WerWolv
5ffc583640 pattern/tiff: Fixed function parameter types 2024-11-27 20:44:56 +01:00
Nik
b9f5f1668b includes/type: Fixed use of Reinterpreter type 2024-11-24 14:53:30 +01:00
Nik
4c22f28a67 pattern/rgbds: Fixed bad include 2024-11-24 14:53:02 +01:00
Bananchiki
6f9b05b853 themes: Added One Dark theme (#322)
* Added One Dark theme

* theme: fixed spacing
2024-11-24 14:51:06 +01:00
Mrmaxmeier
c533017d0b git: Various style fixes everywhere, removing whitespaces (#321)
* repo-wide: trim trailing spaces

Note: This doesn't touch the .tbl files in encodings/ since they include
meaningful trailing spaces (`20= `)

* patterns: clean up duplicate semicolons

* ELF: add header magic check

* glTF: use type::Magic for magic value

* glTF: check that the file size in the header matches

* xgstexture: fix generics syntax for magic value

* JPEG: define hex enum with 0x00 instead of 0X00

* CI: update deprecated actions

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-11-24 11:41:26 +01:00
Dexrn ZacAttack
221fa70a67 patterns: Added Miles Sound System Compressed Archive (MSSCMP) (#320)
* MSSCMP readme

* Add files via upload
2024-11-24 11:39:43 +01:00
Dexrn ZacAttack
661e5b7081 patterns: Added RAD Game Tools BINKA hexpat (#319)
* Binka readme

* Binka hexpat
2024-11-24 11:39:22 +01:00
Geky
7d0bbd1e24 patterns/GameBoy: Add support for cartridge size type $54 and missing licenses (#318)
* add support for cartridge size type $54

Added support for cartridge size type $54, corresponding to 1.5 MiB (96 banks).

* add missing license
2024-11-24 11:38:54 +01:00
Maxim Savenko
55aca93a18 patterns/mp4: Add 'stsz' box definition to MP4 pattern (#317) 2024-11-24 11:38:31 +01:00
otakuxtom
255116a587 patterns/pe: Fix error when ordinalTableRVA is zero (#315)
ordinalTableRVA is not always has value. it might be zero.
Whien this happened, it will failed.

Signed-off-by: Chunhao Hung <chunhao.hung@insyde.com>
Co-authored-by: Chunhao Hung <chunhao.hung@insyde.com>
2024-11-17 14:00:43 +01:00
Luca Corbatto
79e25fdb73 patterns/zip: Added parsing of general purpose bit flag (#314)
* Add parsing of general purpose bit flag

Add "GeneralPurposeBitFlags" bitfield definition. The names are based on
the official ZIP format specification although I chose to name the
fields closer to their purpose rather than their official name. This is
intended to make reading the pattern and its output easier. Example:
official name "Language encoding flag (EFS)" my name
"filenameAndCommentAreUtf8" because this immediately explains what it
does.

I chose not to implement the specifics of the "compressionOptions" as
their meanings are specific to the compression method used and it would
make the pattern much more complicated for (in my opinion) little gain.

I also chose to unify the names of the general purpose bit filed in the
LocalFileHeader and the CentralDirectoryFileHeader. Previously, they had
different names, suggesting they might have different meaning. According
to the official docs though, these fields have the exact same meaning.

Official docs: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

* Fix typo and remove redundant type declaration
2024-11-17 14:00:16 +01:00
Dexrn ZacAttack
c8d9a8deb7 patterns: Added Minecraft LCE LOC file pattern (#311)
* create LOC hexpat

* loc to list
2024-11-17 13:59:44 +01:00
Miku-666
1d680fbf5e patterns: Added Minecraft LCE .pck format pattern (#310) 2024-11-17 13:59:20 +01:00
Dexrn ZacAttack
bc5a55affe patterns/lcesave: Use Virtual Filesystem + ZLib support + auto endian detection (#309)
* use Virtual Filesystem + ZLib support + auto endian detection

* fix builtin

* smh how am I only noticing that I just duplicated a function for no reason

* ifdefs to fix actions moment
2024-11-17 13:58:56 +01:00
Dexrn ZacAttack
85f5541350 patterns: Added Minecraft LCE ARC file format (#307)
* Create arc.hexpat

* add test file

* mention arc

* abide by contributing.md

* use virtual filesystem

* brainfart

* ifdefs to fix github actions moment #2
2024-11-17 13:58:02 +01:00
bbbbbr
61d3e110fb patterns/gb: Add 16K and 32K arrays for ROM Banks (#305)
Having arrays for dividing the GB ROM up into ROM Banks makes it much easier to jump to and inspect data at the start and end of banks.

- 16K Banks are the typical standard
- 32K banks aren't very common but are used in a couple unlicensed Games such as those using the Wisdom Tree MBC controller
2024-11-17 13:57:45 +01:00
Hikodroid
af957389c2 patterns: Added pattern for LZNT1 compressed data (#304) 2024-11-17 13:57:23 +01:00
Hikodroid
e85645897e patterns: Added pattern for Blender project files (#303)
* patterns: Added pattern for Blender project files

* patterns/blend: Added pattern file and test data

* patterns/blend: Fix the thumbnail bugs by passing the source data by reference

* patterns/blend: Added ZSTD support and test data
2024-11-17 13:56:59 +01:00
Hikodroid
abc78d1644 patterns/fbx: Improved the FBX pattern (#302)
* patterns/fbx: Improved the FBX pattern
-Added pragma magic
-Fixed sizing of compressed contents array
-Added references
-Cleaned up whitespace

* Added missing ] bracket in README.md
2024-11-17 13:56:40 +01:00
Valentin Lenhart
46e41db0a8 patterns/pe: Use appropriate pointer for first section placement (#300) 2024-11-17 13:56:01 +01:00
Valentin Lenhart
c67dc84911 patterns/pe: Fixed off by one error in coff pattern (#299) 2024-11-17 13:55:30 +01:00
Guest257351
323898d083 patterns/lua5.1: Fixed a bug in the Lua 5.1 bytecode pattern (#298)
* Fixed a bug in the Lua 5.1 bytecode pattern

Lua 5.1 bytecode upvalue fields were incorrectly defined as a `Vector<u32>` instead of `Vector<LuaString>`.

* Fixed another bug in the lua 5.1 bytecode pattern

Lua 5.1 bytecode string sizes were incorrectly parsed as a 64-bit integer, instead of a 32-bit integer.

* Updated the Lua 5.1 bytecode pattern for 32-bit compilers.

Updated the pattern to allow for 32-bit and 64-bit integers for the size of the string length field.
2024-11-17 13:55:00 +01:00
Seth Hall
abbd25e7f6 patterns: Added Windows Notepad cache file pattern (#297)
* Added Windows Notepad Cache file parser.

* Fixed Notepad windowstate link in readme

* Added a test file for notepad-cache.hexpat
2024-11-17 13:54:29 +01:00
Martín Montané
c8ebb3eb8a includes/std: Added checks to ends_with and starts_with to prevent failure (#295)
Fixing cases where part is longer than string, this cases should both return false instead of failing.

Co-authored-by: Nik <werwolv98@gmail.com>
2024-11-17 13:54:03 +01:00
applecuckoo
bf94cb7243 patterns: Added new WebP and VGM patterns (#294)
* README: fix square bracket

* patterns: add WebP pattern

* patterns/dds: add x-dds mimetype

* patterns: add vgm pattern

* patterns/vgm: remove old pointer

* patterns/protobuf: fix field number handling

* patterns/protobuf: add .pb file extension

* patterns/uf2: updating the family IDs again

* patterns/png: add cHRM and tIME chunks

* patterns/png: whoops, old description snuck back in

* new quantized-mesh pattern

* add quantized-mesh to README, implement oct16 decoding
2024-11-17 13:53:18 +01:00
paxcut
6697fc23a4 themes: Updated the custom themes to the new text editor color palettes (#255)
* Updated the custom themes to the new text editor color palettes designed for full syntax highlighting, but the existing themes should look just like they did before.

* impr: renamed pattern-placed-variable to calculated-pointer and added view
fix: pe pattern could read past the end of file if symbol search option was turned on and input file had no symbols. In that case a StringTable array that has 1 element would be created and place at offset 0 where the size variable was set to a large number creating the error. The fix is to set the size of the array using numberOfSymbols>0

* Fix: that was a bad choice for the size of the stringTable array because  even if findSymbols is not on the file can contain symbols. This was causing the pe unit test to fail. To get the right array size use sizeof(symbolTable)>0 which will be 1 only if findSymbols is true and the file actually contains symbols
2024-11-17 13:52:30 +01:00
Nik
8a6bb6612b includes/std: Fixed standard library errors with latest nightly 2024-11-17 13:51:51 +01:00
endes0
1d66949375 patterns: Added ext4 filesystem pattern (#293)
* patterns: add ext4 volume layout pattern

* patterns: improve ext4 pattern

* patterns: remove debug pragma from ext4

* patterns: fix ext4 magic and padding

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-08-20 21:56:05 +02:00
SpaceManiac
7c65d51986 patterns/msgpack: Fixed endianess of lengths and fixint definition (#291)
* Fix endianness of msgpack ext datum lengths

* Fix formatting of negative fixints
2024-08-20 20:41:12 +02:00
BobSmun
d961271c5d includes/std: Fixed std::core::set_pattern_comment (#289) 2024-08-20 20:33:18 +02:00
applecuckoo
26d48df7dd patterns/uf2: Add new RP2xxx-related family IDs (#288)
* patterns/uf2: add family ID enum

* patterns/uf2: Fix enum spacing

* patterns: add missing description pragmas and README entries, etc.

* patterns/uf2: add reference for Family ID enum

* patterns/uf2: add new RP2xxx family IDs

* patterns/uf2: whoops (comma fix)
2024-08-09 12:39:28 +02:00
Nik
8f1f4911a0 includes/std: Fixed value display error with std::string::NullString 2024-08-07 22:12:25 +02:00
Eldred Habert
1d7cc537ed patterns: Added RGBDS object file format (#287) 2024-08-07 22:11:29 +02:00
qux-bbb
62ceaae09b patterns/lua54: Add a Lua 5.4 test file (#286) 2024-08-04 21:54:24 +02:00
Nik
4a8a6cba1b patterns/flipper_settings: Removed #pragma magic as they would give too many false positives 2024-08-03 20:14:27 +02:00
Nik
c3eb9e4126 patterns: Improved pattern descriptions 2024-08-03 17:44:37 +02:00
WerWolv
a263347414 tests: Added StuffIt5 archive 2024-08-03 15:16:48 +02:00
qux-bbb
204599a70b patterns: Added Lua 5.3 bytecode pattern (#285) 2024-08-03 14:47:07 +02:00
Jan Wiesemann
bf6ee6d02f patterns: Added pattern for Flipper Zero settings (#281)
* Added pattern for Flipper Zero settings

* Added readme entry

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-08-03 14:11:02 +02:00
qux-bbb
0125ec2c57 patterns: Added Lua 5.2 bytecode pattern (#284) 2024-08-03 14:07:50 +02:00
applecuckoo
c5aaac25dd patterns/uf2: Added Family ID enum to uf2.hexpat, Added missing description pragmas and other minor fixes (#282)
* patterns/uf2: add family ID enum

* patterns/uf2: Fix enum spacing

* patterns: add missing description pragmas and README entries, etc.

* patterns/uf2: add reference for Family ID enum
2024-08-03 10:47:40 +02:00
qux-bbb
196011ead9 patterns: Added Lua 5.1 bytecode pattern (#283) 2024-08-03 10:46:25 +02:00
xtex
5b15136ea4 patterns: Add HSDT pattern (#280)
Co-authored-by: Nik <werwolv98@gmail.com>
2024-07-27 08:38:44 +02:00
qux-bbb
59c954ae28 patterns/lua54: Removed empty line (#278)
Remove an empty line.
2024-07-26 19:52:24 +02:00
Hikodroid
8a5cb1061b patterns/fbx: Simplified the fbx hexpat (#277) 2024-07-26 19:52:01 +02:00
Hikodroid
120bc84548 patterns/fbx: Fixed the fbx hexpat (#276)
* patterns: FBX - revised hexpat for fbx files but still broken

* patterns: FBX - implemented a workaround for the previously broken hexpat

* Disable ImHex-specific functions outside of ImHex

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-07-25 00:00:11 +02:00
WerWolv
0e17355db0 tests: Added more test files 2024-07-23 21:03:17 +02:00
WerWolv
6aee524d1a patterns: Fix various patterns, added more test files 2024-07-23 20:31:43 +02:00
WerWolv
b42c571d4d patterns: Fixed run problems with some patterns 2024-07-23 18:39:05 +02:00
xndcn
71e1ad8df7 patterns/jpeg: Simplify EOI marker search (#272)
Co-authored-by: Nik <werwolv98@gmail.com>
2024-07-23 18:37:03 +02:00
WerWolv
5c7d77b50f patterns: Added Kaydara FBX Binary format
Credit to @Hikodroid
2024-07-23 18:29:02 +02:00
WerWolv
a746ecb164 tests: Moved/Renamed some test files 2024-07-23 18:24:05 +02:00
Dexrn ZacAttack
569e5c4c1a patterns: Added Minecraft LCE save format (#256)
* Add Minecraft LCE save format

* Add files to the pattern

took forever lol cuz weird syntax

* NBT parsing n stuff

* Minecraft Xbox 360 Edition saves, read description

TU033 is a pre-release version, which has a slightly different file format that I documented myself [here](https://github.com/Team-Lodestone/Documentation/blob/main/LCE/Pre-Release%20Save%20Format.md)

TU5 is a release version which uses the same file format used all the way up to latest TU (aka the last version released)

All of these saves have been decompressed from XMemCompress (iirc modified LZX)
Chunk data however is still compressed, because it's not meant to be uncompressed in the scope of reading the save.

https://github.com/Team-Lodestone/Documentation/blob/main/LCE/LCE%20File%20Versions.md

* Support Pre-Release files, JANKY file type detection, min and cur version.

* fix top comment

* LCE saves to readme
2024-07-23 18:17:02 +02:00
applecuckoo
0316f2b667 patterns: Add PKM pattern + add BCC checksum verification to ntag pattern (#274)
* patterns/ntag: add BCC checksum verification

* patterns: add PKM file pattern

* Add entry to README

* Added missing import

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-07-23 08:30:05 +02:00
WerWolv
196695e37b includes/std: Allow std::print() and std::format() to take any value as format argument again 2024-07-12 21:19:43 +02:00
WerWolv
bced518508 includes/std: Added std::mem::reached() for use with while-sized arrays 2024-07-10 21:32:55 +02:00
WerWolv
2f795fc23c includes/std: Added attrs library 2024-07-10 21:32:35 +02:00
C3pa
5ff783d571 includes: Fix various spelling errors (#270)
docs: fix some spelling errors

Related issue:
https://github.com/WerWolv/ImHex/issues/1139
2024-07-10 21:09:15 +02:00
357 changed files with 53482 additions and 3591 deletions

View File

@@ -9,4 +9,4 @@
- [ ] The pattern was associated with all relevant MIME types (using `#pragma MIME mime-type` in the source code)
- Make sure to never use `application/octet-stream` here as that means "Unidentifiable binary data"
- [ ] 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
- Try to keep this file below ~ 1 MB

View File

@@ -8,7 +8,7 @@ on:
repository_dispatch:
types: [run_tests]
workflow_dispatch:
inputs:
inputs:
generate_docs:
description: "Regenerate docs"
required: false
@@ -17,7 +17,7 @@ on:
jobs:
tests:
name: 🎯 Dispatch changes
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
permissions:
@@ -27,13 +27,13 @@ jobs:
steps:
- name: 🧰 Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
- name: 📄 Check changed include files
id: changed-includes
uses: tj-actions/changed-files@v35
uses: tj-actions/changed-files@v45
with:
files: includes/**/*.pat
@@ -45,7 +45,7 @@ jobs:
repo: Documentation
owner: WerWolv
event_type: update_pl_docs
- name: ✉️ Update PatternLanguage Website
if: ${{ env.DISPATCH_TOKEN != '' }}
uses: mvasigh/dispatch-action@main

View File

@@ -7,11 +7,17 @@ on:
branches: [ '*' ]
repository_dispatch:
types: [run_tests]
workflow_call:
inputs:
pattern_language_git_repo:
type: string
pattern_language_git_hash:
type: string
jobs:
tests:
name: 🧪 Unit Tests
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
@@ -19,8 +25,9 @@ jobs:
steps:
- name: 🧰 Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/ImHex-Patterns
submodules: recursive
- name: ⬇️ Install dependencies
@@ -29,17 +36,17 @@ jobs:
sudo apt install -y \
build-essential \
ccache \
gcc-12 \
g++-12 \
gcc-14 \
g++-14 \
lld \
${PKGCONF:-} \
cmake \
make \
ninja-build \
python3 \
python3-pip \
libmagic-dev \
lcov
sudo pip install jsonschema
- name: 📜 Setup ccache
@@ -51,30 +58,33 @@ jobs:
- name: 🛠️ Build
run: |
cd tests
mkdir -p build
cd build
CC=gcc-12 CXX=g++-12 cmake \
CC=gcc-14 CXX=g++-14 cmake \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_FLAGS="-fuse-ld=lld --coverage" \
-DCMAKE_CXX_FLAGS="-fuse-ld=lld --coverage" \
-DIMHEX_PATTERNS_ENABLE_UNIT_TESTS=ON \
-DLIBPL_ENABLE_TESTS=OFF \
-DLIBPL_ENABLE_CLI=OFF \
-DIMHEX_PATTERNS_LIBPL_GIT_REPO="${{ inputs.pattern_language_git_repo }}" \
-DIMHEX_PATTERNS_LIBPL_GIT_HASH="${{ inputs.pattern_language_git_hash }}" \
-G Ninja \
..
make -j4
ninja unit_tests
- name: 🧪 Perform Unit Tests
run: |
cd tests/build
cd build
ctest --output-on-failure -j 4
- name: 📎 Validate JSON Files
run: |
cd constants
for file in ./[!_schema.json]*; do jsonschema -i $file _schema.json; done
for file in ./[!_]*; do jsonschema -i $file _schema.json; done
cd ..
cd tips
for file in ./[!_schema.json]*; do jsonschema -i $file _schema.json; done
for file in ./[!_]*; do jsonschema -i $file _schema.json; done
cd ..

9
.gitignore vendored
View File

@@ -1,6 +1,13 @@
tests/cmake*/
tests/build*/
build/
cmake-build-*/
.vscode/
.devcontainer/
.cache/
.idea/
.DS_Store
.DS_Store
compile_commands.json

42
CMakeLists.txt Normal file
View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.16)
project(ImHex-Patterns)
option(IMHEX_PATTERNS_ENABLE_UNIT_TESTS "Enable building unit tests for ImHex-Patterns" OFF)
# if enabled, add a unit_test custom target for all the unit tests to be registered against
if(IMHEX_PATTERNS_ENABLE_UNIT_TESTS)
if(NOT TARGET unit_tests)
enable_testing()
add_custom_target(unit_tests)
endif()
endif()
# If this has been manually cloned into another project, libpl may already have been set up
if(NOT TARGET libpl)
include(FetchContent)
if (NOT DEFINED IMHEX_PATTERNS_LIBPL_GIT_REPO OR IMHEX_PATTERNS_LIBPL_GIT_REPO STREQUAL "")
set(LIBPL_GIT_REPO "https://github.com/WerWolv/PatternLanguage")
else()
set(LIBPL_GIT_REPO ${IMHEX_PATTERNS_LIBPL_GIT_REPO})
endif()
if (NOT DEFINED IMHEX_PATTERNS_LIBPL_GIT_HASH OR IMHEX_PATTERNS_LIBPL_GIT_HASH STREQUAL "")
set(LIBPL_GIT_TAG "master")
else()
set(LIBPL_GIT_TAG ${IMHEX_PATTERNS_LIBPL_GIT_HASH})
endif()
FetchContent_Declare(
pattern_language
GIT_REPOSITORY ${LIBPL_GIT_REPO}
GIT_TAG ${LIBPL_GIT_TAG}
)
FetchContent_MakeAvailable(pattern_language)
endif()
if(IMHEX_PATTERNS_ENABLE_UNIT_TESTS)
add_subdirectory(tests)
endif()

View File

@@ -8,5 +8,5 @@ Thanks a lot for any additions or improvements :)
## Adding new Patterns
When adding new patterns, if possible, please also add a test file named `<pattern_name>.hexpat.<extension>` to the `/tests/patterns/test_data` directory. This allows our Unit Tests to be run against your code so we can make sure it stays up-to-date and doesn't break when changes are made to the PatternLanguage.
Please try to keep these files as small as possible (~100kiB at most) so cloning stays fast.
Please try to keep these files as small as possible (~100kiB at most) so cloning stays fast.
Please also make sure to not submit any test files that are under copyright such as game files, ROMs or files extracted from other programs. We don't want a DMCA takedown on this repo.

145
README.md
View File

@@ -25,113 +25,213 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|------|------|------|-------------|
| 3DS | | [`patterns/3ds.hexpat`](patterns/3ds.hexpat) | Autodesk 3DS Max Model file |
| 7Z | | [`patterns/7z.hexpat`](patterns/7z.hexpat) | 7z File Format |
| ADTFDAT | | [`patterns/adtfdat.hexpat`](patterns/adtfdat.hexpat) | [ADTFDAT files](https://digitalwerk.gitlab.io/solutions/adtf_content/adtf_base/adtf_file_library) |
| ADTS | `audio/x-hx-aac-adts` | [`patterns/adts.hexpat`](patterns/adts.hexpat) | ADTS/AAC audio files |
| AFE2 | | [`patterns/afe2.hexpat`](patterns/afe2.hexpat) | Nintendo Switch Atmosphère CFW Fatal Error log |
| ANI | `application/x-navi-animation` | [`patterns/ani.hexpat`](patterns/ani.hexpat) | Windows Animated Cursor file |
| APFS | | [`patterns/fs/apfs.hexpat`](patterns/fs/apfs.hexpat) | Apple File Ssytem (APFS) |
| AppleSingle | `application/applefile` | [`patterns/apple_single_double.hexpat`](patterns/apple_single_double.hexpat) | AppleSingle Dual Fork file |
| AppleDouble | `multipart/appledouble` | [`patterns/apple_single_double.hexpat`](patterns/apple_single_double.hexpat) | AppleDouble Resource Fork/Finder Metadata file |
| AR | `application/x-archive` | [`patterns/ar.hexpat`](patterns/ar.hexpat) | Static library archive files |
| ARC | | [`patterns/arc.hexpat`](patterns/arc.hexpat) | Minecraft Legacy Console Edition ARC files |
| ARIA2 | | [`patterns/aria2.hexpat`](patterns/aria2.hexpat) | ARIA2 Download Manager Control files |
| ARM VTOR | | [`patterns/arm_cm_vtor.hexpat`](patterns/arm_cm_vtor.hexpat) | ARM Cortex M Vector Table Layout |
| Assassin's Creed: Unity | | [`patterns/AC Unity`](patterns/Assassin's Creed: Unity) | Assassin's Creed: Unity archive files -- .forge & .data (compressed and decompressed) -- |
| Bastion | | [`patterns/bastion/*`](https://gitlab.com/EvelynTSMG/imhex-bastion-pats) | Various [Bastion](https://en.wikipedia.org/wiki/Bastion_(video_game)) files |
| BeyondCompare BCSS | | [`patterns/bcss.hexpat`](patterns/bcss.hexpat) | BeyondCompare Snapshot (BCSS) file |
| Bencode | `application/x-bittorrent` | [`patterns/bencode.hexpat`](patterns/bencode.hexpat) | Bencode encoding, used by Torrent files |
| Prusa BGCODE | | [`patterns/bgcode.hexpat`](patterns/bgcode.hexpat) | PrusaSlicer Binary G-Code files |
| BLEND | | [`patterns/blend.hexpat`](patterns/blend.hexpat) | Blender Project file |
| BLF | | [`patterns/blf.hexpat`](patterns/blf.hexpat) | Vector BLF Frame Logging Files |
| BMP | `image/bmp` | [`patterns/bmp.hexpat`](patterns/bmp.hexpat) | OS2/Windows Bitmap files |
| BIN | | [`patterns/selinux.hexpat`](patterns/selinux.pat) | SE Linux modules |
| BINKA | | [`patterns/binka.hexpat`](patterns/binka.pat) | RAD Game Tools Bink Audio (BINKA) files |
| BSON | `application/bson` | [`patterns/bson.hexpat`](patterns/bson.hexpat) | BSON (Binary JSON) format |
| bplist | | [`patterns/bplist.hexpat`](patterns/bplist.hexpat) | Apple's binary property list format (bplist) |
| bplist | `application/x-bplist` | [`patterns/bplist.hexpat`](patterns/bplist.hexpat) | Apple's binary property list format (bplist) |
| BSP | | [`patterns/bsp_goldsrc.hexpat`](patterns/bsp_goldsrc.hexpat) | GoldSrc engine maps format (used in Half-Life 1) |
| BZIP3 | | [`patterns/bzip3.hexpat`](patterns/bzip3.hexpat) | Parses BZip3 compression (file format) by Kamila Szewczyk |
| CAB | | [`patterns/cab.hexpat`](patterns/cab.hexpat) | Microsoft Cabinet (CAB) Files |
| CCHVA | | [`patterns/cchva.hexpat`](patterns/cchva.hexpat) | Command and Conquer Voxel Animation |
| CCVXL | | [`patterns/ccvxl.hexpat`](patterns/ccvxl.hexpat) | Command and Conquer Voxel Model |
| CCPAL | | [`patterns/ccpal.hexpat`](patterns/ccpal.hexpat) | Command and Conquer Voxel Palette |
| CDA | | [`patterns/cda.hexpat`](patterns/cda.hexpat) | Compact Disc Audio track |
| CHM | | [`patterns/chm.hexpat`](patterns/chm.hexpat) | Windows HtmlHelp Data (ITSF / CHM) |
| CHD | | [`patterns/chd.hexpat`](patterns/chd.hexpat) | MAME Compressed Hunks of Data file |
| CHM | `application/vnd.ms-htmlhelp` | [`patterns/chm.hexpat`](patterns/chm.hexpat) | Windows HtmlHelp Data (ITSF / CHM) |
| COFF | `application/x-coff` | [`patterns/coff.hexpat`](patterns/coff.hexpat) | Common Object File Format (COFF) executable |
| CPIO | `application/x-cpio` | [`patterns/cpio.hexpat`](patterns/cpio.hexpat) | Old Binary CPIO Format |
| CrashLvl | | [`patterns/Crashlvl.hexpat`](patterns/Crashlvl.hexpat) | Crash Bandicoot - Back in Time (fan game) User created level format |
| CREDHIST | | [`patterns/credhist.hexpat`](patterns/credhist.hexpat) | CREDHIST Format |
| DDS | `image/vnd-ms.dds` | [`patterns/dds.hexpat`](patterns/dds.hexpat) | DirectDraw Surface |
| DEX | | [`patterns/dex.hexpat`](patterns/dex.hexpat) | Dalvik EXecutable Format |
| Devil May Cry HD Collection | | [`patterns/Devil May Cry HD Collection`](patterns/Devil May Cry HD Collection) | 3D Model files used in Devil May Cry 3 HD Collection |
| DICOM | `application/dicom` | [`patterns/dicom.hexpat`](patterns/dicom.hexpat) | DICOM image format |
| DISK_PARSER (DFIR) | `application/x-ima` | [`patterns/DFIR/DISK_PARSER.hexpat`](patterns/DFIR/DISK_PARSER.hexpat) | Recursive Disk/Volume/Filesystem parsing |
| DMG | | [`patterns/dmg.hexpat`](patterns/dmg.hexpat) | Apple Disk Image Trailer (DMG) |
| DMP | | [`patterns/dmp64.hexpat`](patterns/dmp64.hexpat) | Windows Kernel Dump(DMP64) |
| DOS | `application/x-dosexec` | [`patterns/dos.hexpat`](patterns/dos.hexpat) | 16-bit real mode DOS EXE files |
| DOTNET_BinaryFormatter | | [`patterns/dotnet_binaryformatter.hexpat`](patterns/dotnet_binaryformatter.hexpat) | .NET BinaryFormatter |
| DPAPI_Blob | | [`patterns/dpapblob.hexpat`](patterns/dpapiblob.hexpat) | Data protection API Blob File Format |
| DPAPI_MasterKey | | [`patterns/dpapimasterkey.hexpat`](patterns/dpapimasterkey.hexpat) | Data protection API MasterKey |
| DS_Store | | [`patterns/dsstore.hexpat`](patterns/dsstore.hexpat) | .DS_Store file format |
| DTA | | [`patterns/max_v104.hexpat`](patterns/max_v104.hexpat) | Mechanized Assault and Exploration v1.04 (strategy game) save file format |
| DTED | | [`patterns/dted.hexpat`](patterns/dted.hexpat) | Digital Terrain Elevation Data (DTED) |
| ELF | `application/x-executable` | [`patterns/elf.hexpat`](patterns/elf.hexpat) | ELF header in elf binaries |
| EVTX | | [`patterns/evtx.hexpat`](patterns/evtx.hexpat) | MS Windows Vista Event Log |
| ESP32 Image | | [`patterns/esp32_image.hexpat`](patterns/esp32_image.hexpat) | Firmware image format for the ESP32 chip family |
| EVTX | `application/x-ms-evtx` | [`patterns/evtx.hexpat`](patterns/evtx.hexpat) | MS Windows Vista Event Log |
| EXFAT | | [`patterns/fs/exfat.hexpat`](patterns/fs/exfat.hexpat) | Extensible File Allocation Table (exFAT) |
| EXFAT (DFIR) | | [`patterns/DFIR/exFAT.hexpat`](patterns/DFIR/exFAT.hexpat) | Imported by DISK_PARSER.hexpat |
| EXT4 | | [`patterns/fs/ext4.hexpat`](patterns/fs/ext4.hexpat) | Ext4 File System |
| FAS | | [`patterns/fas_oskasoftware.hexpat`](patterns/fas_oskasoftware.hexpat) [`patterns/fas_oskasoftware_old.hexpat`](patterns/fas_oskasoftware_old.hexpat) (Old versions of Oska DeskMate) | Oska Software DeskMates FAS (Frames and Sequences) file |
| FAT32 | | [`patterns/fs/fat32.hexpat`](patterns/fs/fat32.hexpat) | FAT32 File System |
| FAT32 (DFIR) | | [`patterns/DFIR/FAT32.hexpat`](patterns/DFIR/FAT32.hexpat) | Imported by DISK_PARSER.hexpat |
| FBX | | [`patterns/fbx.hexpat`](patterns/fbx.hexpat) | Kaydara FBX Binary |
| FDT | | [`patterns/fdt.hexpat`](patterns/fdt.hexpat) | Flat Linux Device Tree blob |
| FFX | | [`patterns/ffx/*`](https://gitlab.com/EvelynTSMG/imhex-ffx-pats) | Various Final Fantasy X files |
| File System | | [`patterns/fs.hexpat`](patterns/fs.hexpat) | Drive File System |
| File System | `application/x-ima` | [`patterns/fs/pattern.hexpat`](patterns/fs/pattern.hexpat) | Drive File System |
| FLAC | `audio/flac` | [`patterns/flac.hexpat`](patterns/flac.hexpat) | Free Lossless Audio Codec, FLAC Audio Format |
| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Gameboy ROM |
| FLC/FLIC | | [`patterns/flc.hexpat`](patterns/flc.hexpat) | FLC/FLIC animation file |
| FLV | | [`patterns/flv.hexpat`](patterns/flv.hexpat) | FLv animation file |
| Flipper Zero Settings | | [`patterns/flipper_settings.hexpat`](patterns/flipper_settings.hexpat) | Flipper Zero Settings Files |
| GB | `application/x-gameboy-rom` | [`patterns/gb.hexpat`](patterns/gb.hexpat) | Game Boy ROM |
| GBA | `application/x-gameboy-advance-rom` | [`patterns/gba.hexpat`](patterns/gba.hexpat) | Game Boy Advance ROM header |
| GGUF | | [`patterns/gguf.hexpat`](patterns/gguf.hexpat) | GGML Inference Models |
| GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files |
| GLTF | `model/gltf-binary` | [`patterns/gltf.hexpat`](patterns/gltf.hexpat) | GL Transmission Format binary 3D model file |
| GZIP | `application/gzip` | [`patterns/gzip.hexpat`](patterns/gzip.hexpat) | GZip compressed data format |
| Halo Tag || [`patterns/hinf_tag.hexpat`](patterns/hinf_tag.hexpat) | Halo Infinite Tag Files |
| Halo Module || [`patterns/hinf_module.hexpat`](patterns/hinf_module.hexpat) | Halo Infinite Module Archive Files |
| Halo HavokScript || [`patterns/hinf_luas.hexpat`](patterns/hinf_luas.hexpat) | Halo Infinite HavokScript 5.1 Bytecode |
| HPROF || [`patterns/hprof.hexpat`](patterns/hprof.hexpat) | Java HPROF Profiler Data Format |
| HSDT || [`patterns/hsdt.hexpat`](patterns/hsdt.hexpat) | HiSilicon device-tree table images |
| ICO | | [`patterns/ico.hexpat`](patterns/ico.hexpat) | Icon (.ico) or Cursor (.cur) files |
| ID3 | `audio/mpeg` | [`patterns/id3.hexpat`](patterns/id3.hexpat) | ID3 tags in MP3 files |
| IM*H || [`patterns/imah.hexpat`](patterns/imah.hexpat) | DJI Signed Firmware (IM*H) |
| Intel HEX | | [`patterns/intel_hex.hexpat`](patterns/intel_hex.hexpat) | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
| IP | | [`patterns/ip.hexpat`](patterns/ip.hexpat) | Ethernet II Frames (IP Packets) |
| IPS | | [`patterns/ips.hexpat`](patterns/ips.hexpat) | IPS (International Patching System) files |
| ISO | | [`patterns/iso.hexpat`](patterns/iso.hexpat) | ISO 9660 file system |
| ISO | `application/x-iso9660-image` | [`patterns/iso.hexpat`](patterns/iso.hexpat) | ISO 9660 file system |
| Java Class | `application/x-java-applet` | [`patterns/java_class.hexpat`](patterns/java_class.hexpat) | Java Class files |
| JPEG | `image/jpeg` | [`patterns/jpeg.hexpat`](patterns/jpeg.hexpat) | JPEG Image Format |
| Kindle Update | | [`patterns/kindle_update.hexpat`](patterns/kindle_update.hexpat) | Kindle Update Package |
| KTX | `image/ktx` | [`patterns/ktx.hexpat`](patterns/ktx.hexpat) | Khronos TeXture 1.0 |
| LOC | | [`patterns/loc.hexpat`](patterns/loc.hexpat) | Minecraft Legacy Console Edition Language file |
| Lua 4.0 | | [`patterns/lua40.hexpat`](patterns/lua40.hexpat) | Lua 4.0 bytecode |
| LUC | | [`patterns/popcap_luc.hexpat`](patterns/popcap_luc.hexpat) | PopCap's proprietary Lua bytecode |
| Lua 5.1 | | [`patterns/lua51.hexpat`](patterns/lua51.hexpat) | Lua 5.1 bytecode |
| Lua 5.2 | | [`patterns/lua52.hexpat`](patterns/lua52.hexpat) | Lua 5.2 bytecode |
| Lua 5.3 | | [`patterns/lua53.hexpat`](patterns/lua53.hexpat) | Lua 5.3 bytecode |
| Lua 5.4 | | [`patterns/lua54.hexpat`](patterns/lua54.hexpat) | Lua 5.4 bytecode |
| LCE Savefile | | [`patterns/lcesave.hexpat`](patterns/lcesave.hexpat) | Minecraft Legacy Console Edition save file |
| LZNT1 | | [`patterns/lznt1.hexpat`](patterns/lznt1.hexpat) | LZNT1 compressed data format |
| Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable |
| MIDI | `audio/midi` | [`patterns/midi.hexpat`](patterns/midi.hexpat) | MIDI header, event fields provided |
| MiniDump | `application/x-dmp` | [`patterns/minidump.hexpat`](patterns/minidump.hexpat) | Windows MiniDump files |
| MO | | [`patterns/mo.hexpat`](patterns/mo.hexpat) | GNU Machine Object (MO) files containing translations for gettext |
| mp4 | `video/mp4` | [`patterns/mp4.hexpat`](patterns/mp4.hexpat) | MPEG-4 Part 14 digital multimedia container format |
| msgpack | `application/x-msgpack` | [`patterns/msgpack.hexpat`](patterns/msgpack.hexpat) | MessagePack binary serialization format |
| MSSCMP | | [`patterns/msscmp.hexpat`](patterns/msscmp.hexpat) | Miles Sound System Compressed Archive |
| NACP | | [`patterns/nacp.hexpat`](patterns/nacp.hexpat) | Nintendo Switch NACP files |
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
| NE | | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
| nes | | [`patterns/nes.hexpat`](patterns/nes.hexpat) | .nes file format |
| NotepadWindowState | | [`patterns/notepad-windowstate.hexpat`](patterns/notepad-windowstate.hexpat) | Windows 11 Notepad - Window State .bin file |
| NDS | `application/x-nintendo-ds-rom` | [`patterns/nds.hexpat`](patterns/nds.hexpat) | DS Cartridge Header |
| NE | `application/x-ms-ne-executable` | [`patterns/ne.hexpat`](patterns/ne.hexpat) | NE header and Standard NE fields |
| nes | | [`patterns/nes.hexpat`](patterns/nes.hexpat) | Nintendo Entertainment System ROM |
| NSF | | [`patterns/nsf.hexpat`](patterns/nsf.hexpat) | NES Sound Format |
| NSFe | | [`patterns/nsfe.hexpat`](patterns/nsfe.hexpat) | NES Sound Format extended |
| NotepadCache | | [`patterns/notepad-cache.hexpat`](patterns/notepad-cache.hexpat) | Windows Notepad Cache |
| NotepadStateFile | | [`patterns/notepad-state.hexpat`](patterns/notepad-state.hexpat) | Windows Notepad .bin State files |
| NotepadWindowState | | [`patterns/notepadwindowstate.hexpat`](patterns/notepadwindowstate.hexpat) | Windows 11 Notepad - Window State .bin file |
| NRO | | [`patterns/nro.hexpat`](patterns/nro.hexpat) | Nintendo Switch NRO files |
| NTAG | | [`patterns/ntag.hexpat`](patterns/ntag.hexpat) | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC |
| NTFS | | [`patterns/fs/ntfs.hexpat`](patterns/fs/ntfs.hexpat) | NTFS (NT File System) |
| NTFS (DFIR) | | [`patterns/DFIR/NTFS.hexpat`](patterns/DFIR/NTFS.hexpat) | Imported by DISK_PARSER.hexpat |
| OGG | `audio/ogg` | [`patterns/ogg.hexpat`](patterns/ogg.hexpat) | OGG Audio format |
| ORP / ORS | | [`patterns/orp.hexpat`](patterns/orp.hexpat) | OpenRGB profile format |
| PACK | | [`patterns/roblox_pack.hexpat`](patterns/roblox_pack.hexpat) | Roblox shader archive format |
| PAK | | [`patterns/xgspak.hexpat`](patterns/xgspak.hexpat) | Exient XGS Engine Pak files |
| PCAP | `application/vnd.tcpdump.pcap` | [`patterns/pcap.hexpat`](patterns/pcap.hexpat) | pcap header and packets |
| PcapNG | `application/vnd.tcpdump.pcap` | [`patterns/pcapng.hexpat`](patterns/pcapng.hexpat) | pcapng header and packets |
| PCK | | [`patterns/pck.hexpat`](patterns/pck.hexpat) | Minecraft Legacy Console Edition .pck file |
| PCX | `application/x-pcx` | [`patterns/pcx.hexpat`](patterns/pcx.hexpat) | PCX Image format |
| PE | `application/x-dosexec` `application/x-msdownload` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
| PP | | [`patterns/selinuxpp.hexpat`](patterns/selinuxpp.pat) | SE Linux package |
| PE | `application/x-dosexec` `application/x-msdownload` | [`patterns/pe.hexpat`](patterns/pe.hexpat) | PE header, COFF header, Standard COFF fields and Windows Specific fields |
| PEF | | [`patterns/pef.hexpat`](patterns/pef.hexpat) | Preffered Executable Format executable (for Mac OS 7.1.2 - Mac OS 10.4 / BeOS) |
| PEX | | [`patterns/pex.hexpat`](patterns/pex.hexpat) | Bethesda Papyrus executable compiled script file |
| PP | | [`patterns/selinuxpp.hexpat`](patterns/selinuxpp.pat) | SE Linux package |
| PFS0 | | [`patterns/pfs0.hexpat`](patterns/pfs0.hexpat) | Nintendo Switch PFS0 archive (NSP files) |
| PF | | [`patterns/pf.hexpat`](patterns/pf.hexpat) | Microsoft uncompressed prefetch files (.pf) |
| Pickle | | [`patterns/pickle.hexpat`](patterns/pickle.hexpat) | Python Pickle Protocol |
| PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format |
| PKM | | [`patterns/pkm.hexpat`](patterns/pkm.hexpat) | PKM texture format |
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
| PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO |
| Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding |
| psafe3 | | [`patterns/psafe3.hexpat`](patterns/psafe3.hexpat`) | Password Safe V3 |
| PyInstaller | | [`patterns/pyinstaller.hexpat`](patterns/pyinstaller.hexpat) | PyInstaller binray files |
| PYC | | [`patterns/pyc.hexpat`](patterns/pyc.hexpat) | Python bytecode files |
| PYC | `application/x-bytecode.python` | [`patterns/pyc.hexpat`](patterns/pyc.hexpat) | Python bytecode files |
| QBCL | | [`patterns/qbcl.hexpat`](patterns/qbcl.hexpat) | Qubicle voxel scene project file |
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
| RAS | `image/x-sun-raster` | [`patterns/ras.hexpat`](patterns/ras.hexpat) | RAS image files |
| ReFS | | [`patterns/refs.hexpat`](patterns/refs.hexpat) | Microsoft Resilient File System |
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
| Quake 3 engine demo | | [`patterns/q3demo.hexpat`](patterns/q3demo.hexpat) | Demos/replays of most Quake 3 engine games |
| quantized-mesh | | [`patterns/quantized-mesh.hexpat`](patterns/quantized-mesh.hexpat) | Cesium quantized-mesh terrain |
| RAR | `application/x-rar` | [`patterns/rar.hexpat`](patterns/rar.hexpat) | RAR archive file format |
| RAS | `image/x-sun-raster` | [`patterns/ras.hexpat`](patterns/ras.hexpat) | RAS image files |
| RCF 1.2 | | [`patterns/rcf_v1_2.hexpat`](patterns/rcf_v1_2.hexpat) | Radcore Cement Library 1.2 file header |
| ReFS | | [`patterns/refs.hexpat`](patterns/fs/refs.hexpat) | Microsoft Resilient File System |
| RGBDS | | [`patterns/rgbds.hexpat`](patterns/rgbds.hexpat) | [RGBDS](https://rgbds.gbdev.io) object file format |
| RPM | | [`patterns/rpm.hexpat`](patterns/rpm.hexpat) | [RPM](http://ftp.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html) package file format |
| SDB | | [`patterns/sdb.hexpat`](patterns/sdb.hexpat) | [Shim DataBase](https://learn.microsoft.com/en-us/windows/win32/devnotes/application-compatibility-database) file format |
| Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format |
| shp | | [`patterns/shp.hexpat`](patterns/shp.hexpat) | ESRI shape file |
| SHR | | [`patterns/SHR.hexpat`](patterns/SHR.hexpat) | Apple IIgs Super Hi-Res (SHR) + PaintWorks Animation (ANI) |
| shx | | [`patterns/shx.hexpat`](patterns/shx.hexpat) | ESRI index file |
| smk | | [`patterns/smk.hexpat`](patterns/smk.hexpat) | Smacker video file |
| SNES | | [`patterns/snes.hexpat`](patterns/snes.hexpat) | Super Nintendo Entertainment System ROM header |
| sup | | [`patterns/sup.hexpat`](patterns/sup.hexpat) | PGS Subtitle |
| SPIRV | | [`patterns/spirv.hexpat`](patterns/spirv.hexpat) | SPIR-V header and instructions |
| STDF | | [`patterns/stdfv4.hexpat`](patterns/stdfv4.hexpat) | Standard test data format for IC testers |
| STL | `model/stl` | [`patterns/stl.hexpat`](patterns/stl.hexpat) | STL 3D Model format |
| StuffItV5 | `application/x-stuffit` | [`patterns/sit5.hexpat`](patterns/sit5.hexpat) | StuffIt V5 archive |
| SWF | |[`patterns/swf.hexpat`](patterns/swf.hexpat) | Shockwave Flash file format |
| SQLite3 | `application/vnd.sqlite3` | [`patterns/sqlite3.hexpat`](patterns/sqlite3.hexpat) | SQLite3 Database |
| SWF | `application/x-shockwave-flash` |[`patterns/swf.hexpat`](patterns/swf.hexpat) | Shockwave Flash file format |
| TA | | [`patterns/optee_ta.hexpat`](patterns/optee_ta.hexpat) | OPTEE Trusted Application Executable |
| TAR | `application/x-tar` | [`patterns/tar.hexpat`](patterns/tar.hexpat) | Tar file format |
| TARC | | [`patterns/tarc.hexpat`](patterns/tarc.hexpat) | KEX Engine TARC file format |
| TES | | [`patterns/wintec_tes.hexpat`](patterns/wintec_tes.hexpat) | Wintec TES GPS log |
| Thumbcache | | [`patterns/thumbcache.hexpat`](patterns/thumbcache.hexpat) | Windows thumbcache_*.db |
| TIFF | `image/tiff` | [`patterns/tiff.hexpat`](patterns/tiff.hexpat) | Tag Image File Format |
| TGA | `image/tga` | [`patterns/tga.hexpat`](patterns/tga.hexpat) | Truevision TGA/TARGA image |
| TTF | `font/ttf`, `font/otf` | [`patterns/ttf.hexpat`](patterns/ttf.hexpat) | TrueType and OpenType font format |
| Ubiquiti | | [`patterns/ubiquiti.hexpat`](patterns/ubiquiti.hexpat) | Ubiquiti Firmware (update) image |
| UPK | | [`patterns/upk-ue3.hexpat`](patterns/upk-ue3.hexpat) | Unreal Engine 3 UPK file |
| UEFI | | [`patterns/uefi.hexpat`](patterns/uefi.hexpat)` | UEFI structs for parsing efivars |
| UEFI Boot Entry | | [`patterns/uefi_boot_entry.hexpat`](patterns/uefi_boot_entry.hexpat) | UEFI Boot Entry (Load option) |
| UEFI Variable Store | | [`patterns/uefi_fv_varstore.hexpat`](patterns/uefi_fv_varstore.hexpat) | UEFI Firmware Volume Variable Store |
| UF2 | | [`patterns/uf2.hexpat`](patterns/uf2.hexpat) | [USB Flashing Format](https://github.com/microsoft/uf2) |
| Unity Asset Bundle | | [`patterns/unity-asset-bundle.hexpat`](patterns/unity-asset-bundle.hexpat) | Unity Asset Bundle |
| Valve VPK | | [`patterns/valve_vpk.hexpat`](valve_vpk.hexpat) | Valve Package File |
| VBMeta | | [`patterns/vbmeta.hexpat`](patterns/vbmeta.hexpat) | Android VBMeta image |
| VDF | | [`patterns/vdf.hexpat`](patterns/vdf.hexpat) | Binary Value Data Format (.vdf) files |
| VEADO | | [`patterns/veado.hexpat`](patterns/veado.hexpat) | veadotube mini avatar file |
| VGM | | [`patterns/vgm.hexpat`](patterns/vgm.hexpat) | VGM (Video Game Music) sound log |
| VHDX | | [`patterns/vhdx.hexpat`](patterns/vhdx.hexpat) | Microsoft Hyper-V Virtual Hard Disk format |
| VOX | | [`patterns/vox.hexpat`](patterns/vox.hexpat) | MagicaVoxel scene description format |
| WAV | `audio/x-wav` | [`patterns/wav.hexpat`](patterns/wav.hexpat) | RIFF header, WAVE header, PCM header |
| WAS | | [`patterns\was_oskasoftware.hexpat`](patterns\was_oskasoftware.hexpat) | Oska Software DeskMates WAS/WA3 (WAVE/MP3 Set) file
| WAS | | [`patterns/was_oskasoftware.hexpat`](patterns/was_oskasoftware.hexpat) | Oska Software DeskMates WAS/WA3 (WAVE/MP3 Set) file
| WAD | | [`patterns/wad.hexpat`](patterns/wad.hexpat) | DOOM WAD Archive |
| WebP | `image/webp` | [`patterns/webp.hexpat`](patterns/webp.hexpat) | Google WebP image |
| XBEH | `audio/x-xbox-executable` | [`patterns/xbeh.hexpat`](patterns/xbeh.hexpat) | Xbox executable |
| XCI | | [`patterns/xci.hexpat`](patterns/xci.hexpat) | Nintendo Switch XCI cartridge ROM |
| XGT | | [`patterns/xgt.hexpat`](patterns/xgstexture.hexpat) | Exient XGS Engine Texture |
| Xilinx BIT | | [`patterns/xilinx_bit.hexpat`](patterns/xilinx_bit.hexpat) | Xilinx FPGA Bitstreams |
| Xilinx Bootgen | | [`patterns/xilinx_bootgen.hexpat`](patterns/xilinx_bootgen.hexpat) | Xilinx ZynqMP Boot Images |
| Xilinx Bootgen | `application/x-xilinx-boot-zynqmp` | [`patterns/xilinx_bootgen.hexpat`](patterns/xilinx_bootgen.hexpat) | Xilinx ZynqMP Boot Images |
| ZIM | | [`patterns/zim.hexpat`](patterns/zim.hexpat) | [ZIM](https://openzim.org) file format |
| ZIP | `application/zip` | [`patterns/zip.hexpat`](patterns/zip.hexpat) | End of Central Directory Header, Central Directory File Headers |
| ZLIB | `application/zlib` | [`patterns/zlib.hexpat`](patterns/zlib.hexpat) | ZLIB compressed data format |
| ZSTD | `application/zstd` | [`patterns/zstd.hexpat`](patterns/zstd.hexpat) | Zstandard compressed data format |
| MOD | `3d-model/mod` | [`patterns/DMC3HD-Mod.hexpat`](patterns/dmc3_hd_mod.hexpat) | 3D Model files used in Devil May Cry 3 HD Collection |
| CBM BASIC | | [`commodore_basic.hexpat`](patterns/commodore_basic.hexpat) | Commodore BASIC |
| Atari XEX | | [`xex.hexpat`](patterns/xex.hexpat) | Atari 8-bit binary format |
| Terminfo | `application/x-terminfo` and `application/x-terminfo2` | [`patterns/terminfo.hexpat`](patterns/terminfo.hexpat) | Compiled *(legacy and extended)* term info entry |
### Scripts
@@ -209,7 +309,6 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| 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 |
> import custom encoding from File -> Import... -> Custome Encoding File
### Data Processor Nodes
@@ -228,3 +327,11 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| Catppuccin Frappe | [`themes/catppuccin-frappe.json`](themes/catppuccin-frappe.json) | Catppuccin Frappe Flavor (Dark Theme) |
| Catppuccin Macchiato | [`themes/catppuccin-macchiato.json`](themes/catppuccin-macchiato.json) | Catppuccin Macchiato Flavor (Dark Theme) |
| Catppuccin Mocha | [`themes/catppuccin-mocha.json`](themes/catppuccin-mocha.json) | Catppuccin Mocha Flavor (Dark Theme) |
| Theme Lion | [`themes/theme_lion.json`](themes/theme_lion.json) | Semantic CLion inspired theme (Dark Theme) |
| Retina Dark | [`themes/retina_dark.json`](themes/retina_dark.json) | Semantic theme based on Dark Theme |
### Disassemblers
| Name | Path | Description |
|------|------|-------------|
| 8051 | [`disassemblers/8051.json`](disassemblers/8051.json) | Intel 8051 Architecture |

View File

@@ -29,23 +29,10 @@
"title": "Items",
"type": "object",
"required": [
"type",
"value",
"name"
],
"properties": {
"type": {
"$id": "#root/values/items/type",
"title": "Type",
"type": "string",
"default": "",
"examples": [
"int16be",
"int16le",
"int10"
],
"pattern": "^(int10|int16le|int16be)$"
},
"value": {
"$id": "#root/values/items/value",
"title": "Value",
@@ -54,7 +41,7 @@
"examples": [
"ACDC"
],
"pattern": "^([0-9a-fA-F]+)$"
"pattern": "^.*$"
},
"name": {
"$id": "#root/values/items/name",

View File

@@ -2,118 +2,95 @@
"name": "CRC16 Constants",
"values": [
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/CCITT-FALSE Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/ARC Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/AUG-CCITT Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/BUYPASS Polynomial"
},
{
"type": "int16be",
"value": "C867",
"value": "C8 67",
"name": "CRC-16/CDMA2000 Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/DDS-110 Polynomial"
},
{
"type": "int16be",
"value": "0589",
"value": "05 89",
"name": "CRC-16/DECT-R Polynomial"
},
{
"type": "int16be",
"value": "0589",
"value": "05 89",
"name": "CRC-16/DECT-X Polynomial"
},
{
"type": "int16be",
"value": "3D65",
"value": "3D 65",
"name": "CRC-16/DNP Polynomial"
},
{
"type": "int16be",
"value": "3D65",
"value": "3D 65",
"name": "CRC-16/EN-13757 Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/GENIBUS Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/MAXIM Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/MCRF4XX Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/RIELLO Polynomial"
},
{
"type": "int16be",
"value": "8BB7",
"value": "8B B7",
"name": "CRC-16/T10-DIF Polynomial"
},
{
"type": "int16be",
"value": "A097",
"value": "A0 97",
"name": "CRC-16/TELEDISK Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/TMS37157 Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/USB Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-A Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/KERMIT Polynomial"
},
{
"type": "int16be",
"value": "8005",
"value": "80 05",
"name": "CRC-16/MODBUS Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/X-25 Polynomial"
},
{
"type": "int16be",
"value": "1021",
"value": "10 21",
"name": "CRC-16/XMODEM Polynomial"
}
]

View File

@@ -2,48 +2,39 @@
"name": "CRC32 Constants",
"values": [
{
"type": "int16be",
"value": "04C11DB7",
"value": "04 C1 1D B7",
"name": "CRC-32 Polynomial"
},
{
"type": "int16be",
"value": "04C11DB7",
"value": "04 C1 1D B7",
"name": "CRC-32/BZIP2 Polynomial"
},
{
"type": "int16be",
"value": "1EDC6F41",
"value": "1E DC 6F 41",
"name": "CRC-32C Polynomial"
},
{
"type": "int16be",
"value": "A833982B",
"value": "A8 33 98 2B",
"name": "CRC-32D Polynomial"
},
{
"type": "int16be",
"value": "04C11DB7",
"value": "04 C1 1D B7",
"name": "CRC-32/MPEG-2 Polynomial"
},
{
"type": "int16be",
"value": "04C11DB7",
"value": "04 C1 1D B7",
"name": "CRC-32/POSIX Polynomial"
},
{
"type": "int16be",
"value": "814141AB",
"value": "81 41 41 AB",
"name": "CRC-32Q Polynomial"
},
{
"type": "int16be",
"value": "04C11DB7",
"value": "04 C1 1D B7",
"name": "CRC-32/JAMCRC Polynomial"
},
{
"type": "int16be",
"value": "000000AF",
"value": "00 00 00 AF",
"name": "CRC-32/XFER Polynomial"
}
]

View File

@@ -1,315 +0,0 @@
{
"name": "HTTP Status Codes",
"values": [
{
"type": "int10",
"value": "100",
"name": "Continue"
},
{
"type": "int10",
"value": "101",
"name": "Switching Protocols"
},
{
"type": "int10",
"value": "102",
"name": "Processing (WebDAV; RFC 2518)"
},
{
"type": "int10",
"value": "103",
"name": "Early Hints (RFC 8297)"
},
{
"type": "int10",
"value": "200",
"name": "OK"
},
{
"type": "int10",
"value": "201",
"name": "Created"
},
{
"type": "int10",
"value": "202",
"name": "Accepted"
},
{
"type": "int10",
"value": "203",
"name": "Non-Authoritative Information (since HTTP/1.1)"
},
{
"type": "int10",
"value": "204",
"name": "No Content"
},
{
"type": "int10",
"value": "205",
"name": "Reset Content"
},
{
"type": "int10",
"value": "206",
"name": "Partial Content (RFC 7233)"
},
{
"type": "int10",
"value": "207",
"name": "Multi-Status (WebDAV; RFC 4918)"
},
{
"type": "int10",
"value": "208",
"name": "Already Reported (WebDAV; RFC 5842)"
},
{
"type": "int10",
"value": "226",
"name": "IM Used (RFC 3229)"
},
{
"type": "int10",
"value": "300",
"name": "Multiple Choices"
},
{
"type": "int10",
"value": "301",
"name": "Moved Permanently"
},
{
"type": "int10",
"value": "302",
"name": "Found (Previously \"Moved temporarily\")"
},
{
"type": "int10",
"value": "303",
"name": "See Other (since HTTP/1.1)"
},
{
"type": "int10",
"value": "304",
"name": "Not Modified (RFC 7232)"
},
{
"type": "int10",
"value": "305",
"name": "Use Proxy (since HTTP/1.1)"
},
{
"type": "int10",
"value": "306",
"name": "Switch Proxy"
},
{
"type": "int10",
"value": "307",
"name": "Temporary Redirect (since HTTP/1.1)"
},
{
"type": "int10",
"value": "308",
"name": "Permanent Redirect (RFC 7538)"
},
{
"type": "int10",
"value": "400",
"name": "Bad Request"
},
{
"type": "int10",
"value": "401",
"name": "Unauthorized (RFC 7235)"
},
{
"type": "int10",
"value": "402",
"name": "Payment Required"
},
{
"type": "int10",
"value": "403",
"name": "Forbidden"
},
{
"type": "int10",
"value": "404",
"name": "Not Found"
},
{
"type": "int10",
"value": "405",
"name": "Method Not Allowed"
},
{
"type": "int10",
"value": "406",
"name": "Not Acceptable"
},
{
"type": "int10",
"value": "407",
"name": "Proxy Authentication Required (RFC 7235)"
},
{
"type": "int10",
"value": "408",
"name": "Request Timeout"
},
{
"type": "int10",
"value": "409",
"name": "Conflict"
},
{
"type": "int10",
"value": "410",
"name": "Gone"
},
{
"type": "int10",
"value": "411",
"name": "Length Required"
},
{
"type": "int10",
"value": "412",
"name": "Precondition Failed (RFC 7232)"
},
{
"type": "int10",
"value": "413",
"name": "Payload Too Large (RFC 7231)"
},
{
"type": "int10",
"value": "414",
"name": "URI Too Long (RFC 7231)"
},
{
"type": "int10",
"value": "415",
"name": "Unsupported Media Type (RFC 7231)"
},
{
"type": "int10",
"value": "416",
"name": "Range Not Satisfiable (RFC 7233)"
},
{
"type": "int10",
"value": "417",
"name": "Expectation Failed"
},
{
"type": "int10",
"value": "418",
"name": "I'm a teapot (RFC 2324, RFC 7168)"
},
{
"type": "int10",
"value": "421",
"name": "Misdirected Request (RFC 7540)"
},
{
"type": "int10",
"value": "422",
"name": "Unprocessable Entity (WebDAV; RFC 4918)"
},
{
"type": "int10",
"value": "424",
"name": "Failed Dependency (WebDAV; RFC 4918)"
},
{
"type": "int10",
"value": "425",
"name": "Too Early (RFC 8470)"
},
{
"type": "int10",
"value": "426",
"name": "Upgrade Required"
},
{
"type": "int10",
"value": "428",
"name": "Precondition Required (RFC 6585)"
},
{
"type": "int10",
"value": "429",
"name": "Too Many Requests (RFC 6585)"
},
{
"type": "int10",
"value": "431",
"name": "Request Header Fields Too Large (RFC 6585)"
},
{
"type": "int10",
"value": "451",
"name": "Unavailable For Legal Reasons (RFC 7725)"
},
{
"type": "int10",
"value": "500",
"name": "Internal Server Error"
},
{
"type": "int10",
"value": "501",
"name": "Not Implemented"
},
{
"type": "int10",
"value": "502",
"name": "Bad Gateway"
},
{
"type": "int10",
"value": "503",
"name": "Service Unavailable"
},
{
"type": "int10",
"value": "504",
"name": "Gateway Timeout"
},
{
"type": "int10",
"value": "505",
"name": "HTTP Version Not Supported"
},
{
"type": "int10",
"value": "506",
"name": "Variant Also Negotiates (RFC 2295)"
},
{
"type": "int10",
"value": "507",
"name": "Insufficient Storage (WebDAV; RFC 4918)"
},
{
"type": "int10",
"value": "508",
"name": "Loop Detected (WebDAV; RFC 5842)"
},
{
"type": "int10",
"value": "510",
"name": "Not Extended (RFC 2774)"
},
{
"type": "int10",
"value": "511",
"name": "Network Authentication Required (RFC 6585)"
}
]
}

View File

@@ -1,780 +0,0 @@
{
"name": "Linux Error Codes",
"values": [
{
"type": "int10",
"value": "1",
"name": "EPERM",
"desc": "Operation not permitted"
},
{
"type": "int10",
"value": "2",
"name": "ENOENT",
"desc": "No such file or directory"
},
{
"type": "int10",
"value": "3",
"name": "ESRCH",
"desc": "No such process"
},
{
"type": "int10",
"value": "4",
"name": "EINTR",
"desc": "Interrupted system call"
},
{
"type": "int10",
"value": "5",
"name": "EIO",
"desc": "I/O error"
},
{
"type": "int10",
"value": "6",
"name": "ENXIO",
"desc": "No such device or address"
},
{
"type": "int10",
"value": "7",
"name": "E2BIG",
"desc": "Argument list too long"
},
{
"type": "int10",
"value": "8",
"name": "ENOEXEC",
"desc": "Exec format error"
},
{
"type": "int10",
"value": "9",
"name": "EBADF",
"desc": "Bad file value"
},
{
"type": "int10",
"value": "10",
"name": "ECHILD",
"desc": "No child processes"
},
{
"type": "int10",
"value": "11",
"name": "EAGAIN",
"desc": "Try again"
},
{
"type": "int10",
"value": "12",
"name": "ENOMEM",
"desc": "Out of memory"
},
{
"type": "int10",
"value": "13",
"name": "EACCES",
"desc": "Permission denied"
},
{
"type": "int10",
"value": "14",
"name": "EFAULT",
"desc": "Bad address"
},
{
"type": "int10",
"value": "15",
"name": "ENOTBLK",
"desc": "Block device required"
},
{
"type": "int10",
"value": "16",
"name": "EBUSY",
"desc": "Device or resource busy"
},
{
"type": "int10",
"value": "17",
"name": "EEXIST",
"desc": "File exists"
},
{
"type": "int10",
"value": "18",
"name": "EXDEV",
"desc": "Cross-device link"
},
{
"type": "int10",
"value": "19",
"name": "ENODEV",
"desc": "No such device"
},
{
"type": "int10",
"value": "20",
"name": "ENOTDIR",
"desc": "Not a directory"
},
{
"type": "int10",
"value": "21",
"name": "EISDIR",
"desc": "Is a directory"
},
{
"type": "int10",
"value": "22",
"name": "EINVAL",
"desc": "Invalid argument"
},
{
"type": "int10",
"value": "23",
"name": "ENFILE",
"desc": "File table overflow"
},
{
"type": "int10",
"value": "24",
"name": "EMFILE",
"desc": "Too many open files"
},
{
"type": "int10",
"value": "25",
"name": "ENOTTY",
"desc": "Not a typewriter"
},
{
"type": "int10",
"value": "26",
"name": "ETXTBSY",
"desc": "Text file busy"
},
{
"type": "int10",
"value": "27",
"name": "EFBIG",
"desc": "File too large"
},
{
"type": "int10",
"value": "28",
"name": "ENOSPC",
"desc": "No space left on device"
},
{
"type": "int10",
"value": "29",
"name": "ESPIPE",
"desc": "Illegal seek"
},
{
"type": "int10",
"value": "30",
"name": "EROFS",
"desc": "Read-only file system"
},
{
"type": "int10",
"value": "31",
"name": "EMLINK",
"desc": "Too many links"
},
{
"type": "int10",
"value": "32",
"name": "EPIPE",
"desc": "Broken pipe"
},
{
"type": "int10",
"value": "33",
"name": "EDOM",
"desc": "Math argument out of domain of func"
},
{
"type": "int10",
"value": "34",
"name": "ERANGE",
"desc": "Math result not representable"
},
{
"type": "int10",
"value": "35",
"name": "EDEADLK",
"desc": "Resource deadlock would occur"
},
{
"type": "int10",
"value": "36",
"name": "ENAMETOOLONG",
"desc": "File name too long"
},
{
"type": "int10",
"value": "37",
"name": "ENOLCK",
"desc": "No record locks available"
},
{
"type": "int10",
"value": "38",
"name": "ENOSYS",
"desc": "Function not implemented"
},
{
"type": "int10",
"value": "39",
"name": "ENOTEMPTY",
"desc": "Directory not empty"
},
{
"type": "int10",
"value": "40",
"name": "ELOOP",
"desc": "Too many symbolic links encountered"
},
{
"type": "int10",
"value": "42",
"name": "ENOMSG",
"desc": "No message of desired type"
},
{
"type": "int10",
"value": "43",
"name": "EIDRM",
"desc": "Identifier removed"
},
{
"type": "int10",
"value": "44",
"name": "ECHRNG",
"desc": "Channel value out of range"
},
{
"type": "int10",
"value": "45",
"name": "EL2NSYNC",
"desc": "Level 2 not synchronized"
},
{
"type": "int10",
"value": "46",
"name": "EL3HLT",
"desc": "Level 3 halted"
},
{
"type": "int10",
"value": "47",
"name": "EL3RST",
"desc": "Level 3 reset"
},
{
"type": "int10",
"value": "48",
"name": "ELNRNG",
"desc": "Link value out of range"
},
{
"type": "int10",
"value": "49",
"name": "EUNATCH",
"desc": "Protocol driver not attached"
},
{
"type": "int10",
"value": "50",
"name": "ENOCSI",
"desc": "No CSI structure available"
},
{
"type": "int10",
"value": "51",
"name": "EL2HLT",
"desc": "Level 2 halted"
},
{
"type": "int10",
"value": "52",
"name": "EBADE",
"desc": "Invalid exchange"
},
{
"type": "int10",
"value": "53",
"name": "EBADR",
"desc": "Invalid request descriptor"
},
{
"type": "int10",
"value": "54",
"name": "EXFULL",
"desc": "Exchange full"
},
{
"type": "int10",
"value": "55",
"name": "ENOANO",
"desc": "No anode"
},
{
"type": "int10",
"value": "56",
"name": "EBADRQC",
"desc": "Invalid request code"
},
{
"type": "int10",
"value": "57",
"name": "EBADSLT",
"desc": "Invalid slot"
},
{
"type": "int10",
"value": "59",
"name": "EBFONT",
"desc": "Bad font file format"
},
{
"type": "int10",
"value": "60",
"name": "ENOSTR",
"desc": "Device not a stream"
},
{
"type": "int10",
"value": "61",
"name": "ENODATA",
"desc": "No data available"
},
{
"type": "int10",
"value": "62",
"name": "ETIME",
"desc": "Timer expired"
},
{
"type": "int10",
"value": "63",
"name": "ENOSR",
"desc": "Out of streams resources"
},
{
"type": "int10",
"value": "64",
"name": "ENONET",
"desc": "Machine is not on the network"
},
{
"type": "int10",
"value": "65",
"name": "ENOPKG",
"desc": "Package not installed"
},
{
"type": "int10",
"value": "66",
"name": "EREMOTE",
"desc": "Object is remote"
},
{
"type": "int10",
"value": "67",
"name": "ENOLINK",
"desc": "Link has been severed"
},
{
"type": "int10",
"value": "68",
"name": "EADV",
"desc": "Advertise error"
},
{
"type": "int10",
"value": "69",
"name": "ESRMNT",
"desc": "Srmount error"
},
{
"type": "int10",
"value": "70",
"name": "ECOMM",
"desc": "Communication error on send"
},
{
"type": "int10",
"value": "71",
"name": "EPROTO",
"desc": "Protocol error"
},
{
"type": "int10",
"value": "72",
"name": "EMULTIHOP",
"desc": "Multihop attempted"
},
{
"type": "int10",
"value": "73",
"name": "EDOTDOT",
"desc": "RFS specific error"
},
{
"type": "int10",
"value": "74",
"name": "EBADMSG",
"desc": "Not a data message"
},
{
"type": "int10",
"value": "75",
"name": "EOVERFLOW",
"desc": "Value too large for defined data type"
},
{
"type": "int10",
"value": "76",
"name": "ENOTUNIQ",
"desc": "Name not unique on network"
},
{
"type": "int10",
"value": "77",
"name": "EBADFD",
"desc": "File descriptor in bad state"
},
{
"type": "int10",
"value": "78",
"name": "EREMCHG",
"desc": "Remote address changed"
},
{
"type": "int10",
"value": "79",
"name": "ELIBACC",
"desc": "Can not access a needed shared library"
},
{
"type": "int10",
"value": "80",
"name": "ELIBBAD",
"desc": "Accessing a corrupted shared library"
},
{
"type": "int10",
"value": "81",
"name": "ELIBSCN",
"desc": ".lib section in a.out corrupted"
},
{
"type": "int10",
"value": "82",
"name": "ELIBMAX",
"desc": "Attempting to link in too many shared libraries"
},
{
"type": "int10",
"value": "83",
"name": "ELIBEXEC",
"desc": "Cannot exec a shared library directly"
},
{
"type": "int10",
"value": "84",
"name": "EILSEQ",
"desc": "Illegal byte sequence"
},
{
"type": "int10",
"value": "85",
"name": "ERESTART",
"desc": "Interrupted system call should be restarted"
},
{
"type": "int10",
"value": "86",
"name": "ESTRPIPE",
"desc": "Streams pipe error"
},
{
"type": "int10",
"value": "87",
"name": "EUSERS",
"desc": "Too many users"
},
{
"type": "int10",
"value": "88",
"name": "ENOTSOCK",
"desc": "Socket operation on non-socket"
},
{
"type": "int10",
"value": "89",
"name": "EDESTADDRREQ",
"desc": "Destination address required"
},
{
"type": "int10",
"value": "90",
"name": "EMSGSIZE",
"desc": "Message too long"
},
{
"type": "int10",
"value": "91",
"name": "EPROTOTYPE",
"desc": "Protocol wrong type for socket"
},
{
"type": "int10",
"value": "92",
"name": "ENOPROTOOPT",
"desc": "Protocol not available"
},
{
"type": "int10",
"value": "93",
"name": "EPROTONOSUPPORT",
"desc": "Protocol not supported"
},
{
"type": "int10",
"value": "94",
"name": "ESOCKTNOSUPPORT",
"desc": "Socket type not supported"
},
{
"type": "int10",
"value": "95",
"name": "EOPNOTSUPP",
"desc": "Operation not supported on transport endpoint"
},
{
"type": "int10",
"value": "96",
"name": "EPFNOSUPPORT",
"desc": "Protocol family not supported"
},
{
"type": "int10",
"value": "97",
"name": "EAFNOSUPPORT",
"desc": "Address family not supported by protocol"
},
{
"type": "int10",
"value": "98",
"name": "EADDRINUSE",
"desc": "Address already in use"
},
{
"type": "int10",
"value": "99",
"name": "EADDRNOTAVAIL",
"desc": "Cannot assign requested address"
},
{
"type": "int10",
"value": "100",
"name": "ENETDOWN",
"desc": "Network is down"
},
{
"type": "int10",
"value": "101",
"name": "ENETUNREACH",
"desc": "Network is unreachable"
},
{
"type": "int10",
"value": "102",
"name": "ENETRESET",
"desc": "Network dropped connection because of reset"
},
{
"type": "int10",
"value": "103",
"name": "ECONNABORTED",
"desc": "Software caused connection abort"
},
{
"type": "int10",
"value": "104",
"name": "ECONNRESET",
"desc": "Connection reset by peer"
},
{
"type": "int10",
"value": "105",
"name": "ENOBUFS",
"desc": "No buffer space available"
},
{
"type": "int10",
"value": "106",
"name": "EISCONN",
"desc": "Transport endpoint is already connected"
},
{
"type": "int10",
"value": "107",
"name": "ENOTCONN",
"desc": "Transport endpoint is not connected"
},
{
"type": "int10",
"value": "108",
"name": "ESHUTDOWN",
"desc": "Cannot send after transport endpoint shutdown"
},
{
"type": "int10",
"value": "109",
"name": "ETOOMANYREFS",
"desc": "Too many references: cannot splice"
},
{
"type": "int10",
"value": "110",
"name": "ETIMEDOUT",
"desc": "Connection timed out"
},
{
"type": "int10",
"value": "111",
"name": "ECONNREFUSED",
"desc": "Connection refused"
},
{
"type": "int10",
"value": "112",
"name": "EHOSTDOWN",
"desc": "Host is down"
},
{
"type": "int10",
"value": "113",
"name": "EHOSTUNREACH",
"desc": "No route to host"
},
{
"type": "int10",
"value": "114",
"name": "EALREADY",
"desc": "Operation already in progress"
},
{
"type": "int10",
"value": "115",
"name": "EINPROGRESS",
"desc": "Operation now in progress"
},
{
"type": "int10",
"value": "116",
"name": "ESTALE",
"desc": "Stale NFS file handle"
},
{
"type": "int10",
"value": "117",
"name": "EUCLEAN",
"desc": "Structure needs cleaning"
},
{
"type": "int10",
"value": "118",
"name": "ENOTNAM",
"desc": "Not a XENIX named type file"
},
{
"type": "int10",
"value": "119",
"name": "ENAVAIL",
"desc": "No XENIX semaphores available"
},
{
"type": "int10",
"value": "120",
"name": "EISNAM",
"desc": "Is a named type file"
},
{
"type": "int10",
"value": "121",
"name": "EREMOTEIO",
"desc": "Remote I/O error"
},
{
"type": "int10",
"value": "122",
"name": "EDQUOT",
"desc": "Quota exceeded"
},
{
"type": "int10",
"value": "123",
"name": "ENOMEDIUM",
"desc": "No medium found"
},
{
"type": "int10",
"value": "124",
"name": "EMEDIUMTYPE",
"desc": "Wrong medium type"
},
{
"type": "int10",
"value": "125",
"name": "ECANCELED",
"desc": "Operation Canceled"
},
{
"type": "int10",
"value": "126",
"name": "ENOKEY",
"desc": "Required key not available"
},
{
"type": "int10",
"value": "127",
"name": "EKEYEXPIRED",
"desc": "Key has expired"
},
{
"type": "int10",
"value": "128",
"name": "EKEYREVOKED",
"desc": "Key has been revoked"
},
{
"type": "int10",
"value": "129",
"name": "EKEYREJECTED",
"desc": "Key was rejected by service"
},
{
"type": "int10",
"value": "130",
"name": "EOWNERDEAD",
"desc": "Owner died"
},
{
"type": "int10",
"value": "131",
"name": "ENOTRECOVERABLE",
"desc": "State not recoverable"
}
]
}

730
disassemblers/8051.json Normal file
View File

@@ -0,0 +1,730 @@
{
"name": "Intel 8051",
"includes": [],
"options": [],
"opcodes": [
{
"mask": "0000'0000",
"mnemonic": "NOP",
"format": ""
},
{
"mask": "0000'0010 AAAA'AAAA AAAA'AAAA",
"mnemonic": "LJMP",
"format": "#0x{A:04X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "A"
}
}
]
},
{
"mask": "1000'0000 AAAA'AAAA",
"mnemonic": "SJMP",
"format": "#0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "A"
}
}
]
},
{
"mask": "0111'0011",
"mnemonic": "JMP",
"format": "@A+DPTR"
},
{
"mask": "0100'0000 AAAA'AAAA",
"mnemonic": "JC",
"format": "PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 2 + A"
}
}
]
},
{
"mask": "0011'0000 BBBB'BBBB AAAA'AAAA",
"mnemonic": "JNB",
"format": "BIT[0x{B:02X}], PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "0001'0000 BBBB'BBBB AAAA'AAAA",
"mnemonic": "JBC",
"format": "BIT[0x{B:02X}], PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "0010'0000 AAAA'AAAA RRRR'RRRR",
"mnemonic": "JB",
"format": "BIT[0x{A:02X}], PC + 0x{R:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "0001'0010 AAAA'AAAA AAAA'AAAA",
"mnemonic": "LCALL",
"format": "#0x{A:04X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "A"
}
}
]
},
{
"mask": "PPP1'0001 AAAA'AAAA",
"mnemonic": "ACALL",
"format": "page{P} #0x{A:04X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "P * 256 + A"
}
}
]
},
{
"mask": "PPP0'0001 AAAA'AAAA",
"mnemonic": "AJMP",
"format": "page{P} #0x{A:04X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "P * 256 + A"
}
}
]
},
{
"mask": "0000'0011",
"mnemonic": "RR",
"format": "A"
},
{
"mask": "0001'0011",
"mnemonic": "RRC",
"format": "A"
},
{
"mask": "0010'0011",
"mnemonic": "RL",
"format": "A"
},
{
"mask": "0011'0011",
"mnemonic": "RLC",
"format": "A"
},
{
"mask": "0000'0100",
"mnemonic": "INC",
"format": "A"
},
{
"mask": "0000'0101 AAAA'AAAA",
"mnemonic": "INC",
"format": "IRAM[0x{A:02X}]"
},
{
"mask": "0000'011R",
"mnemonic": "INC",
"format": "@R{R}"
},
{
"mask": "0000'1RRR",
"mnemonic": "INC",
"format": "R{R}"
},
{
"mask": "1010'0011",
"mnemonic": "INC",
"format": "DPTR"
},
{
"mask": "0001'0100",
"mnemonic": "DEC",
"format": "A"
},
{
"mask": "0001'0101 AAAA'AAAA",
"mnemonic": "DEC",
"format": "IRAM[0x{A:02X}]"
},
{
"mask": "0001'0110",
"mnemonic": "DEC",
"format": "@R0"
},
{
"mask": "0001'0111",
"mnemonic": "DEC",
"format": "@R1"
},
{
"mask": "0001'1RRR",
"mnemonic": "DEC",
"format": "R{R}"
},
{
"mask": "1110'0100",
"mnemonic": "CLR",
"format": "A"
},
{
"mask": "1100'0010 AAAA'AAAA",
"mnemonic": "CLR",
"format": "BIT[0x{A:02X}]"
},
{
"mask": "1100'0011",
"mnemonic": "CLR",
"format": "C"
},
{
"mask": "1111'0000",
"mnemonic": "MOVX",
"format": "@DPTR, A"
},
{
"mask": "1110'0000",
"mnemonic": "MOVX",
"format": "A, @DPTR"
},
{
"mask": "1111'001R",
"mnemonic": "MOVX",
"format": "@R{R}, A"
},
{
"mask": "1110'001R",
"mnemonic": "MOVX",
"format": "A, @R{R}"
},
{
"mask": "0111'011R AAAA'AAAA",
"mnemonic": "MOV",
"format": "@R{R}, #0x{A:02X}"
},
{
"mask": "0111'1RRR AAAA'AAAA",
"mnemonic": "MOV",
"format": "R{R}, #0x{A:02X}"
},
{
"mask": "1111'1RRR",
"mnemonic": "MOV",
"format": "R{R}, A"
},
{
"mask": "1110'011R",
"mnemonic": "MOV",
"format": "A, @R{R}"
},
{
"mask": "1111'011R",
"mnemonic": "MOV",
"format": "@R{R}, A"
},
{
"mask": "1110'1RRR",
"mnemonic": "MOV",
"format": "A, R{R}"
},
{
"mask": "1001'0010 AAAA'AAAA",
"mnemonic": "MOV",
"format": "BIT[0x{A:02X}], C"
},
{
"mask": "1010'0010 AAAA'AAAA",
"mnemonic": "MOV",
"format": "C, BIT[0x{A:02X}]"
},
{
"mask": "1001'0000 DDDD'DDDD DDDD'DDDD",
"mnemonic": "MOV",
"format": "DPTR, #0x{D:04X}"
},
{
"mask": "1110'0101 AAAA'AAAA",
"mnemonic": "MOV",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "1111'0101 AAAA'AAAA",
"mnemonic": "MOV",
"format": "IRAM[#0x{A:02X}], A"
},
{
"mask": "0111'0101 AAAA'AAAA DDDD'DDDD",
"mnemonic": "MOV",
"format": "IRAM[0x{A:02X}], #0x{D:02X}"
},
{
"mask": "1000'0101 AAAA'AAAA BBBB'BBBB",
"mnemonic": "MOV",
"format": "IRAM[0x{A:02X}], IRAM[0x{B:02X}]"
},
{
"mask": "0111'0100 DDDD'DDDD",
"mnemonic": "MOV",
"format": "A, #0x{D:02X}"
},
{
"mask": "1000'011R AAAA'AAAA",
"mnemonic": "MOV",
"format": "IRAM[0x{A:02X}], @R{R}"
},
{
"mask": "1000'1RRR AAAA'AAAA",
"mnemonic": "MOV",
"format": "IRAM[0x{A:02X}], R{R}"
},
{
"mask": "1010'011R AAAA'AAAA",
"mnemonic": "MOV",
"format": "@R{R}, IRAM[0x{A:02X}]"
},
{
"mask": "1010'1RRR AAAA'AAAA",
"mnemonic": "MOV",
"format": "R{R}, IRAM[0x{A:02X}]"
},
{
"mask": "0110'0000 AAAA'AAAA",
"mnemonic": "JZ",
"format": "PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 2 + A"
}
}
]
},
{
"mask": "0111'0000 AAAA'AAAA",
"mnemonic": "JNZ",
"format": "PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 2 + A"
}
}
]
},
{
"mask": "1001'0011",
"mnemonic": "MOVC",
"format": "A, @A+DPTR"
},
{
"mask": "1000'0011",
"mnemonic": "MOVC",
"format": "A, @A+PC"
},
{
"mask": "1101'011R",
"mnemonic": "XCHD",
"format": "A, @R{R}"
},
{
"mask": "1100'011R",
"mnemonic": "XCH",
"format": "A, @R{R}"
},
{
"mask": "1100'1RRR",
"mnemonic": "XCH",
"format": "A, R{R}"
},
{
"mask": "1100'0101 AAAA'AAAA",
"mnemonic": "XCH",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0010'0010",
"mnemonic": "RET",
"format": ""
},
{
"mask": "0011'0010",
"mnemonic": "RETI",
"format": ""
},
{
"mask": "1101'0010 AAAA'AAAA",
"mnemonic": "SETB",
"format": "BIT[0x{A:02X}]"
},
{
"mask": "1101'0011",
"mnemonic": "SETB",
"format": "C"
},
{
"mask": "0101'0010 AAAA'AAAA",
"mnemonic": "ANL",
"format": "IRAM[0x{A:02X}], A"
},
{
"mask": "0101'0101 AAAA'AAAA",
"mnemonic": "ANL",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0101'0011 AAAA'AAAA DDDD'DDDD",
"mnemonic": "ANL",
"format": "A, IRAM[0x{A:02X}], #0x{D:02X}"
},
{
"mask": "0101'0100 AAAA'AAAA",
"mnemonic": "ANL",
"format": "A, #0x{A:02X}"
},
{
"mask": "0101'011R",
"mnemonic": "ANL",
"format": "A, @R{R}"
},
{
"mask": "0101'1RRR",
"mnemonic": "ANL",
"format": "A, R{R}"
},
{
"mask": "1000'0010 AAAA'AAAA",
"mnemonic": "ANL",
"format": "C, BIT[0x{A:02X}]"
},
{
"mask": "1011'0000 AAAA'AAAA",
"mnemonic": "ANL",
"format": "C, /BIT[0x{A:02X}]"
},
{
"mask": "0100'0010 AAAA'AAAA",
"mnemonic": "ORL",
"format": "IRAM[0x{A:02X}], A"
},
{
"mask": "0100'0011 AAAA'AAAA DDDD'DDDD",
"mnemonic": "ORL",
"format": "IRAM[0x{A:02X}], #0x{D:02X}"
},
{
"mask": "0100'0100 DDDD'DDDD",
"mnemonic": "ORL",
"format": "A, #0x{D:02X}"
},
{
"mask": "0100'011R",
"mnemonic": "ORL",
"format": "A, @R{R}"
},
{
"mask": "0100'1RRR",
"mnemonic": "ORL",
"format": "A, R{R}"
},
{
"mask": "0100'0101 AAAA'AAAA",
"mnemonic": "ORL",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0111'0010 AAAA'AAAA",
"mnemonic": "ORL",
"format": "C, BIT[0x{A:02X}]"
},
{
"mask": "1010'0000 AAAA'AAAA",
"mnemonic": "ORL",
"format": "C, /BIT[0x{A:02X}]"
},
{
"mask": "0110'0010 AAAA'AAAA",
"mnemonic": "XRL",
"format": "IRAM[0x{A:02X}], A"
},
{
"mask": "0110'0011 AAAA'AAAA DDDD'DDDD",
"mnemonic": "XRL",
"format": "IRAM[0x{A:02X}], #0x{D:02X}"
},
{
"mask": "0110'0100 DDDD'DDDD",
"mnemonic": "XRL",
"format": "A, #0x{D:02X}"
},
{
"mask": "0110'011R",
"mnemonic": "XRL",
"format": "A, @R{R}"
},
{
"mask": "0110'1RRR",
"mnemonic": "XRL",
"format": "A, R{R}"
},
{
"mask": "0110'0101 AAAA'AAAA",
"mnemonic": "XRL",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0010'0100 DDDD'DDDD",
"mnemonic": "ADD",
"format": "A, #0x{D:02X}"
},
{
"mask": "0010'011R",
"mnemonic": "ADD",
"format": "A, @R{R}"
},
{
"mask": "0010'0101 AAAA'AAAA",
"mnemonic": "ADD",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0011'0100 DDDD'DDDD",
"mnemonic": "ADDC",
"format": "A, #0x{D:02X}"
},
{
"mask": "0011'011R",
"mnemonic": "ADDC",
"format": "A, @R{R}"
},
{
"mask": "0011'0101 AAAA'AAAA",
"mnemonic": "ADDC",
"format": "A, IRAM[0x{A:02X}]"
},
{
"mask": "0011'1RRR",
"mnemonic": "ADDC",
"format": "A, R{R}"
},
{
"mask": "1001'0100 DDDD'DDDD",
"mnemonic": "SUBB",
"format": "A, #0x{D:02X}"
},
{
"mask": "1001'0101 IIII'IIII",
"mnemonic": "SUBB",
"format": "A, IRAM[0x{I:02X}]"
},
{
"mask": "1001'011R",
"mnemonic": "SUBB",
"format": "A, @R{R}"
},
{
"mask": "1001'1RRR",
"mnemonic": "SUBB",
"format": "A, R{R}"
},
{
"mask": "1010'0100",
"mnemonic": "MUL",
"format": "AB"
},
{
"mask": "1000'0100",
"mnemonic": "DIV",
"format": "AB"
},
{
"mask": "0010'1RRR",
"mnemonic": "ORL",
"format": "A, R{R}"
},
{
"mask": "1011'0101 IIII'IIII AAAA'AAAA",
"mnemonic": "CJNE",
"format": "A, IRAM[0x{I:02X}], PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "1011'0100 DDDD'DDDD AAAA'AAAA",
"mnemonic": "CJNE",
"format": "A, #0x{D:02X}, PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "1011'011R DDDD'DDDD AAAA'AAAA",
"mnemonic": "CJNE",
"format": "@R{R}, #0x{D:02X}, PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "1011'1RRR DDDD'DDDD AAAA'AAAA",
"mnemonic": "CJNE",
"format": "R{R}, #0x{D:02X}, PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "1101'0101 IIII'IIII AAAA'AAAA",
"mnemonic": "DJNZ",
"format": "IRAM[0x{I:02X}], PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 3 + A"
}
}
]
},
{
"mask": "1101'1RRR AAAA'AAAA",
"mnemonic": "DJNZ",
"format": "R{R}, PC + 0x{R:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 2 + A"
}
}
]
},
{
"mask": "0101'0000 AAAA'AAAA",
"mnemonic": "JNC",
"format": "PC + 0x{A:02X}",
"metadata": [
{
"type": "jump",
"data": {
"destination": "offset + 2 + A"
}
}
]
},
{
"mask": "1101'0000 AAAA'AAAA",
"mnemonic": "POP",
"format": "IRAM[0x{A:02X}]"
},
{
"mask": "1100'0000 AAAA'AAAA",
"mnemonic": "PUSH",
"format": "IRAM[0x{A:02X}]"
},
{
"mask": "1101'0100",
"mnemonic": "DA",
"format": ""
},
{
"mask": "1100'0100",
"mnemonic": "SWAP",
"format": "A"
},
{
"mask": "1111'0100",
"mnemonic": "CPL",
"format": "A"
},
{
"mask": "1011'0011",
"mnemonic": "CPL",
"format": "C"
},
{
"mask": "1011'0010 BBBB'BBBB",
"mnemonic": "CPL",
"format": "BIT[0x{B:02X}]"
},
{
"mask": "1010'0101",
"mnemonic": "INVALID",
"format": ""
},
{
"mask": "XXXX'XXXX",
"mnemonic": "DB",
"format": "#0x{X:02X}",
"metadata": [
{
"type": "data",
"data": {
"value": "X"
}
}
]
}
]
}

1045
disassemblers/jvm.json Normal file

File diff suppressed because it is too large Load Diff

21921
encodings/gbk.tbl Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,7 @@ namespace auto hex::dec {
@param pattern The pattern whose bytes should be decompressed
@param section The section to decompress the data into
@param window_size The window size passed to zlib
@return true if successful, false otherwise
@return A value representing either the number of bytes decompressed or an error code from zlib
*/
fn zlib_decompress(ref auto pattern, std::mem::Section section, u64 window_size = 0) {
return builtin::hex::dec::zlib_decompress(pattern, section, window_size);
@@ -71,5 +71,5 @@ namespace auto hex::dec {
fn lz4_decompress(ref auto pattern, std::mem::Section section, bool frame = true) {
return builtin::hex::dec::lz4_decompress(pattern, section, frame);
};
}

View File

@@ -7,11 +7,11 @@ import hex.impl.imhex_check;
*/
namespace auto hex::prv {
/**
Queries information from the currently loaded provider. The kind of information that's available depends on the provider that's loaded
> **Available information**
> - File Provider
> - `file_path() -> str`
@@ -32,12 +32,12 @@ namespace auto hex::prv {
> - `region_size(regionName) -> u64`
> - `process_id() -> u32`
> - `process_name() -> str`
@param category Information category
@param argument Extra argument to pass along
*/
fn get_information(str category, str argument = "") {
return builtin::hex::prv::get_information(category, argument);
};
}

View File

@@ -0,0 +1,28 @@
#pragma once
import hex.impl.imhex_check;
/*!
Types to work with custom encoded strings using Thiny encoding definitions
*/
namespace auto hex::type {
/**
A string that was encoded using a custom encoding
@tparam Data Pattern whose bytes are used in the decoding process
@tparam EncodingDefinition A string containing a Thingy encoding definition as used by ImHex's custom encoding feature
*/
struct EncodedString<auto Data, auto EncodingDefinition> {
builtin::hex::dec::EncodedString<Data, EncodingDefinition> string;
} [[sealed, format("hex::type::impl::format_encoded_string")]];
namespace impl {
fn format_encoded_string(ref auto string) {
return string.string;
};
}
}

View File

@@ -0,0 +1,143 @@
#pragma once
import hex.impl.imhex_check;
/*!
Types to work with machine code
*/
namespace auto hex::type {
/**
A machine code instruction which will get disassembled
@tparam DisassemblerSetting A string containing the config for the disassembler in the form of "architecture; setting1, setting2, no-setting3"
@tparam SyntaxType Syntax used in the disassembly. Possible values are "intel", "at&t", "masm" and "motorola"
@tparam ImageBaseAddress Start address of the instruction region in the data
@tparam ImageLoadAddress Address where the instructions will be loaded into memory
Possible Values for DisassemblerSetting:
- Architecture, all may be suffixed with le or be to specify endianess (e.g armbe or mipsle)
- arm
- thumb
- aarch64
- arm64
- mips
- x86
- x86_64
- x64
- ppc
- powerpc
- sparc
- sysz
- xcore
- m68k
- m680x
- tms320c64x
- evm
- wasm
- riscv
- mos65xx
- bpf
- sh
- tricore
- Settings, not all settings make sense for each architecture. Prefixing settings with no- will remove them instead
- 16bit
- 32bit
- 64bit
- cortex-m
- armv8
- micromips
- mips2
- mips3
- mips32r6
- sparcv9
- qpx
- spe
- ps
- 68000
- 68010
- 68020
- 68030
- 68040
- 68060
- 6301
- 6309
- 6800
- 6801
- 6805
- 6808
- 6809
- 6811
- cpu12
- hcs08
- bpfe
- rv32g
- rv64g
- riscvc
- 6502
- 65c02
- w65c02
- 65816
- long-m
- long-x
- sh2
- sh2a
- sh3
- sh4
- sh4a
- shfpu
- shdsp
- 1.1
- 1.2
- 1.3
- 1.3.1
- 1.6
- 1.6.1
- 1.6.2
*/
struct Instruction<auto DisassemblerSetting, auto SyntaxType, auto ImageBaseAddress, auto ImageLoadAddress> {
builtin::hex::dec::Instruction<DisassemblerSetting, SyntaxType, ImageBaseAddress, ImageLoadAddress> instruction;
} [[sealed, format("hex::type::impl::format_instruction")]];
/**
A machine code instruction which will get disassembled using Intel syntax
@tparam DisassemblerSetting A string containing the config for the disassembler in the form of "architecture; setting1, setting2, no-setting3"
@tparam ImageBaseAddress Start address of the instruction region in the data
@tparam ImageLoadAddress Address where the instructions will be loaded into memory
*/
using InstructionIntel<auto DisassemblerSetting, auto ImageBaseAddress, auto ImageLoadAddress> = Instruction<DisassemblerSetting, "intel", ImageBaseAddress, ImageLoadAddress>;
/**
A machine code instruction which will get disassembled using AT&T syntax
@tparam DisassemblerSetting A string containing the config for the disassembler in the form of "architecture; setting1, setting2, no-setting3"
@tparam ImageBaseAddress Start address of the instruction region in the data
@tparam ImageLoadAddress Address where the instructions will be loaded into memory
*/
using InstructionATNT<auto DisassemblerSetting, auto ImageBaseAddress, auto ImageLoadAddress> = Instruction<DisassemblerSetting, "at&t", ImageBaseAddress, ImageLoadAddress>;
/**
A machine code instruction which will get disassembled using MASM syntax
@tparam DisassemblerSetting A string containing the config for the disassembler in the form of "architecture; setting1, setting2, no-setting3"
@tparam ImageBaseAddress Start address of the instruction region in the data
@tparam ImageLoadAddress Address where the instructions will be loaded into memory
*/
using InstructionMASM<auto DisassemblerSetting, auto ImageBaseAddress, auto ImageLoadAddress> = Instruction<DisassemblerSetting, "masm", ImageBaseAddress, ImageLoadAddress>;
/**
A machine code instruction which will get disassembled using Motorola syntax
@tparam DisassemblerSetting A string containing the config for the disassembler in the form of "architecture; setting1, setting2, no-setting3"
@tparam ImageBaseAddress Start address of the instruction region in the data
@tparam ImageLoadAddress Address where the instructions will be loaded into memory
*/
using InstructionMotorola<auto DisassemblerSetting, auto ImageBaseAddress, auto ImageLoadAddress> = Instruction<DisassemblerSetting, "motorola", ImageBaseAddress, ImageLoadAddress>;
namespace impl {
fn format_instruction(ref auto instruction) {
return instruction.instruction;
};
}
}

View File

@@ -0,0 +1,66 @@
#pragma once
import hex.impl.imhex_check;
/*!
Types to decode JSON and JSON-like file formats into a pattern tree
*/
namespace auto hex::type {
/**
Type representing a JSON string
@tparam Size size of the string
*/
struct Json<auto Size> {
char __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Json<__data> json [[merge]];
};
/**
Type representing Bson data
@tparam Size size of the data
*/
struct Bson<auto Size> {
u8 __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Bson<__data> bson [[merge]];
};
/**
Type representing Cbor data
@tparam Size size of the data
*/
struct Cbor<auto Size> {
u8 __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Cbor<__data> cbor [[merge]];
};
/**
Type representing Bjdata data
@tparam Size size of the data
*/
struct Bjdata<auto Size> {
u8 __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Bjdata<__data> bjdata [[merge]];
};
/**
Type representing Msgpack data
@tparam Size size of the data
*/
struct Msgpack<auto Size> {
u8 __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Msgpack<__data> msgpack [[merge]];
};
/**
Type representing Ubjson data
@tparam Size size of the data
*/
struct Ubjson<auto Size> {
u8 __data[Size] [[hidden, no_unique_address]];
builtin::hex::dec::Ubjson<__data> ubjson [[merge]];
};
}

View File

@@ -6,6 +6,22 @@ import std.core;
/*!
The array library contains a helper type to make it easier to create multi-dimensional arrays
and pass arrays to functions as parameters.
## Multi-dimensional arrays
The following example shows how to use multi-dimensional arrays with structs.
```rust
import std.array;
struct File {
u8 width, height;
std::Array<std::Array<u8, parent.width>, height> cells;
};
File file @ 0x00;
```
*/
namespace auto std {
@@ -27,7 +43,7 @@ namespace auto std {
struct ByteSizedArray<T, auto NumBytes> {
u64 startAddress = $;
T array[while($ - startAddress < NumBytes)] [[inline]];
std::assert($ - startAddress == NumBytes, "Not enough bytes available to fit a whole number of types");
} [[format("std::impl::format_array")]];

70
includes/std/attrs.pat Normal file
View File

@@ -0,0 +1,70 @@
import std.io;
import std.core;
/*!
The attributes library contains a set of attributes that can be used to annotate types with certain properties.
To use an attribute, simply make your custom type inherit from the attribute type you want to use.
For example, to make a type hidden, you can use the `Hidden` attribute like this:
```rust
struct MyType : std::attr::Hidden {
// ...
};
```
*/
namespace auto std::attr {
/**
Attribute that marks a type as a literal type.
This means the type behaves like a built-in type in the sense that it doesn't show its internal state and its display value is determined by a format function.
It can also be transformed into a different built-in literal when used in an expression.
@tparam FormatFunction The format function to use. The return value of this function is used to display the value of the literal and also determines the value returned when the literal is used in an expression.
*/
struct Literal<auto FormatFunction> { }
[[sealed, format_read(FormatFunction), transform(FormatFunction)]];
/**
Attribute that changes the name of the variable created from a type.
@tparam Name The name of the variable created
*/
struct Named<auto Name> { }
[[name(Name)]];
/**
Attribute that adds a comment to the variable created from a type.
@tparam Comment The comment to add
*/
struct Commented<auto Comment> {}
[[comment(Comment)]];
/**
Attribute that marks a type as hidden.
This means variables of this type are not displayed in the UI.
*/
struct Hidden {}
[[hidden]];
/**
Attribute that marks a type as hidden and also hides it from the highlighter.
This means variables of this type are don't display any highlighting in the UI but are still visible.
*/
struct HighlightHidden {}
[[highlight_hidden]];
/**
Attribute that marks a type as inline.
Creating a variable of this type will not create a new layer but instead dump the contents of the type directly into the current layer.
*/
struct Inlined {}
[[inline]];
/**
Attribute that marks a type as sealed.
Sealed types don't display their internal state in the UI.
*/
struct Sealed {}
[[sealed]];
}

View File

@@ -21,7 +21,7 @@ namespace auto std::bit {
x = (x & a) + ((x >> 1) & a);
x = (x & b) + ((x >> 2) & b);
x = (x & c) + ((x >> 4) & c);
return x % 0xFF;
};
@@ -33,19 +33,19 @@ namespace auto std::bit {
fn has_single_bit(u128 x) {
return x != 0 && (x & (x - 1)) == 0;
};
/**
Rounds the given number up to the next bigger power of two
@param x The number
@return Next bigger power of two that can fit `x`
*/
fn bit_ceil(u128 x) {
fn bit_ceil(u128 x) {
if (x == 0) return 0;
u8 i;
while ((1 << i) < x)
i = i + 1;
return 1 << i;
};
@@ -56,11 +56,11 @@ namespace auto std::bit {
*/
fn bit_floor(u128 x) {
if (x == 0) return 0;
u8 i;
while ((x >> i) > 0)
i = i + 1;
return 1 << (i - 1);
};

View File

@@ -56,17 +56,17 @@ namespace auto std::core {
/**
Sets the current default endianess.
Any patterns created following this attribute will be created using the set endianess.
@param endian The new default endianess
Sets the current default endianness.
Any patterns created following this attribute will be created using the set endianness.
@param endian The new default endianness
*/
fn set_endian(std::mem::Endian endian) {
builtin::std::core::set_endian(u32(endian));
};
/**
Gets the current default endianess.
@return The currently set default endianess
Gets the current default endianness.
@return The currently set default endianness
*/
fn get_endian() {
return builtin::std::core::get_endian();
@@ -159,10 +159,10 @@ namespace auto std::core {
/**
Changes the comment attached to a pattern
@param pattern The pattern to modify
@param name The new comment of the pattern
@param comment The new comment of the pattern
*/
fn set_pattern_comment(ref auto pattern, str comment) {
builtin::std::core::set_pattern_comment(pattern, name);
builtin::std::core::set_pattern_comment(pattern, comment);
};
/**
@@ -173,4 +173,20 @@ namespace auto std::core {
fn execute_function(str function_name, auto ... args) {
builtin::std::core::execute_function(function_name, args);
};
/**
Sets the pattern color palette for all future created patterns
@param args RGBA8 colors as 32 bit integers (0xAABBGGRR)
*/
fn set_pattern_palette_colors(auto ... colors) {
builtin::std::core::set_pattern_palette_colors(colors);
};
/**
Resets the current pattern palette progress back to zero.
This can be useful to force all instances of a type to have the same coloring for its members
*/
fn reset_pattern_palette() {
builtin::std::core::reset_pattern_palette();
};
}

View File

@@ -85,7 +85,7 @@ namespace auto std::ctype {
@return True if `c` is part of this range, false otherwise
*/
fn isprint(char c) {
return c >= '0' && c <= '~';
return c >= ' ' && c <= '~';
};
/**

View File

@@ -1,7 +1,7 @@
#pragma once
/*!
The File library allows reading and writing from/to external files using
The File library allows reading and writing from/to external files using
a C-like File IO API.
**These functions are considered dangerous and require the user to manually permit them**
@@ -13,7 +13,7 @@ namespace auto std::file {
A handle representing a file that has been opened
*/
using Handle = s32;
/**
The mode to open a file in.
Read opens the file in read-only mode
@@ -45,7 +45,7 @@ namespace auto std::file {
builtin::std::file::close(handle);
};
/**
Reads the content of a file into a string
@param handle The file handle to read from
@@ -85,14 +85,14 @@ namespace auto std::file {
};
/**
Resizes a file
Resizes a file
@param handle The handle of the file to resize
*/
fn resize(Handle handle, u64 size) {
builtin::std::file::resize(handle, size);
};
/**
/**
Flushes changes made to a file to disk
@param handle The handle of the file to flush
*/

View File

@@ -20,7 +20,7 @@ namespace auto std::fxpt {
fn to_float(fixed fxt, u32 precision) {
return double(fxt) / double((1 << precision));
};
/**
Converts a floating point value into a fixed point value
@param flt The floating point value to convert
@@ -41,7 +41,7 @@ namespace auto std::fxpt {
fn change_precision(fixed value, u32 start_precision, u32 end_precision) {
return std::fxpt::to_fixed(std::fxpt::to_float(value, start_precision), end_precision);
};
/**
Adds two fixed point numbers with a given precision together
@param a First fixed point number
@@ -52,7 +52,7 @@ namespace auto std::fxpt {
fn add(fixed a, fixed b, u32 precision) {
return a + b;
};
/**
Subtracts two fixed point numbers with a given precision together
@param a First fixed point number
@@ -63,7 +63,7 @@ namespace auto std::fxpt {
fn subtract(fixed a, fixed b, u32 precision) {
return a - b;
};
/**
Multiplies two fixed point numbers with a given precision together
@param a First fixed point number
@@ -74,7 +74,7 @@ namespace auto std::fxpt {
fn multiply(fixed a, fixed b, u32 precision) {
return (a * b) / (1 << precision);
};
/**
Divides two fixed point numbers with a given precision together
@param a First fixed point number

View File

@@ -14,7 +14,7 @@ namespace auto std::hash {
@param xorout The CRC8 XOR-Out value
@param reflect_in Whether or not the input bytes should be reflected
@param reflect_out Whether or not the output should be reflected
@return Calculated CRC8 hash
@return Calculated CRC8 hash
*/
fn crc8(ref auto pattern, u8 init, u8 poly, u8 xorout, bool reflect_in, bool reflect_out) {
return builtin::std::hash::crc8(pattern, init, poly, xorout, reflect_in, reflect_out);
@@ -28,7 +28,7 @@ namespace auto std::hash {
@param xorout The CRC16 XOR-Out value
@param reflect_in Whether or not the input bytes should be reflected
@param reflect_out Whether or not the output should be reflected
@return Calculated CRC16 hash
@return Calculated CRC16 hash
*/
fn crc16(ref auto pattern, u16 init, u16 poly, u16 xorout, bool reflect_in, bool reflect_out) {
return builtin::std::hash::crc16(pattern, init, poly, xorout, reflect_in, reflect_out);
@@ -42,7 +42,7 @@ namespace auto std::hash {
@param xorout The CRC32 XOR-Out value
@param reflect_in Whether or not the input bytes should be reflected
@param reflect_out Whether or not the output should be reflected
@return Calculated CRC32 hash
@return Calculated CRC32 hash
*/
fn crc32(ref auto pattern, u32 init, u32 poly, u32 xorout, bool reflect_in, bool reflect_out) {
return builtin::std::hash::crc32(pattern, init, poly, xorout, reflect_in, reflect_out);
@@ -56,7 +56,7 @@ namespace auto std::hash {
@param xorout The CRC64 XOR-Out value
@param reflect_in Whether or not the input bytes should be reflected
@param reflect_out Whether or not the output should be reflected
@return Calculated CRC64 hash
@return Calculated CRC64 hash
*/
fn crc64(ref auto pattern, u64 init, u64 poly, u64 xorout, bool reflect_in, bool reflect_out) {
return builtin::std::hash::crc64(pattern, init, poly, xorout, reflect_in, reflect_out);

View File

@@ -9,21 +9,21 @@ namespace auto std {
/**
Formats the given arguments using the format string and prints the result to the console
This function uses the C++20 `std::format` or libfmt's `fmt::format` syntax.
@param fmt Format string
@param fmt Format string or any other value that can be converted to a string
@param args Values to use in the formatting
*/
fn print(str fmt, auto ... args) {
fn print(auto fmt, auto ... args) {
builtin::std::print(fmt, args);
};
/**
Formats the given arguments using the format string and returns the result as a string
This function uses the C++20 `std::format` or libfmt's `fmt::format` syntax.
@param fmt Format string
@param fmt Format string or any other value that can be converted to a string
@param args Values to use in the formatting
@return The formatted string
*/
fn format(str fmt, auto ... args) {
fn format(auto fmt, auto ... args) {
return builtin::std::format(fmt, args);
};

View File

@@ -5,7 +5,7 @@
*/
namespace auto std::limits {
/**
Returns the minimum value that can be stored in a `u8`.
@return Minimum value
@@ -13,7 +13,7 @@ namespace auto std::limits {
fn u8_min() {
return u8(0);
};
/**
Returns the maximum value that can be stored in a `u8`.
@return Maximum value
@@ -29,7 +29,7 @@ namespace auto std::limits {
fn s8_min() {
return -s8((std::limits::u8_max() / 2)) - 1;
};
/**
Returns the maximum value that can be stored in a `s8`.
@return Maximum value
@@ -45,7 +45,7 @@ namespace auto std::limits {
fn u16_min() {
return u16(0);
};
/**
Returns the maximum value that can be stored in a `u16`.
@return Maximum value
@@ -53,7 +53,7 @@ namespace auto std::limits {
fn u16_max() {
return u16(-1);
};
/**
Returns the minimum value that can be stored in a `s16`.
@return Minimum value
@@ -61,7 +61,7 @@ namespace auto std::limits {
fn s16_min() {
return -s16((std::limits::u16_max() / 2)) - 1;
};
/**
Returns the maximum value that can be stored in a `s16`.
@return Maximum value
@@ -69,7 +69,7 @@ namespace auto std::limits {
fn s16_max() {
return s16((std::limits::u16_max() / 2));
};
/**
Returns the minimum value that can be stored in a `u32`.
@return Minimum value
@@ -77,7 +77,7 @@ namespace auto std::limits {
fn u32_min() {
return u32(0);
};
/**
Returns the maximum value that can be stored in a `u32`.
@return Maximum value
@@ -85,7 +85,7 @@ namespace auto std::limits {
fn u32_max() {
return u32(-1);
};
/**
Returns the minimum value that can be stored in a `s32`.
@return Minimum value
@@ -93,7 +93,7 @@ namespace auto std::limits {
fn s32_min() {
return -s32((std::limits::u32_max() / 2)) - 1;
};
/**
Returns the maximum value that can be stored in a `s32`.
@return Maximum value
@@ -101,7 +101,7 @@ namespace auto std::limits {
fn s32_max() {
return s32((std::limits::u32_max() / 2));
};
/**
Returns the minimum value that can be stored in a `u64`.
@return Minimum value
@@ -109,7 +109,7 @@ namespace auto std::limits {
fn u64_min() {
return u64(0);
};
/**
Returns the maximum value that can be stored in a `u64`.
@return Maximum value
@@ -117,7 +117,7 @@ namespace auto std::limits {
fn u64_max() {
return u64(-1);
};
/**
Returns the minimum value that can be stored in a `s64`.
@return Minimum value
@@ -125,7 +125,7 @@ namespace auto std::limits {
fn s64_min() {
return -s64((std::limits::u64_max() / 2)) - 1;
};
/**
Returns the maximum value that can be stored in a `s64`.
@return Maximum value
@@ -133,7 +133,7 @@ namespace auto std::limits {
fn s64_max() {
return s64((std::limits::u64_max() / 2));
};
/**
Returns the minimum value that can be stored in a `u128`.
@return Minimum value
@@ -141,7 +141,7 @@ namespace auto std::limits {
fn u128_min() {
return u128(0);
};
/**
Returns the maximum value that can be stored in a `u128`.
@return Maximum value
@@ -149,7 +149,7 @@ namespace auto std::limits {
fn u128_max() {
return u128(-1);
};
/**
Returns the minimum value that can be stored in a `s128`.
@return Minimum value
@@ -157,7 +157,7 @@ namespace auto std::limits {
fn s128_min() {
return -s128((std::limits::u128_max() / 2)) - 1;
};
/**
Returns the maximum value that can be stored in a `s128`.
@return Maximum value
@@ -165,5 +165,5 @@ namespace auto std::limits {
fn s128_max() {
return s128((std::limits::u128_max() / 2));
};
}

View File

@@ -20,7 +20,7 @@ namespace auto std::math {
else
return b;
};
/**
Compares the values `a` and `b` with each other and returns the bigger of the two
@param a First value
@@ -56,9 +56,9 @@ namespace auto std::math {
@return `x` if `x` is positive, `-x` otherwise
*/
fn abs(auto x) {
if (x < 0)
if (x < 0)
return -x;
else
else
return x;
};
@@ -96,13 +96,13 @@ namespace auto std::math {
*/
fn factorial(u128 x) {
u128 result;
result = x;
while (x > 1) {
x = x - 1;
result = result * x;
}
return result;
};
@@ -336,5 +336,5 @@ namespace auto std::math {
fn accumulate(u128 start, u128 end, u128 valueSize, std::mem::Section section = 0, AccumulateOperation operation = AccumulateOperation::Add, std::mem::Endian endian = std::mem::Endian::Native) {
return builtin::std::math::accumulate(start, end, valueSize, section, u128(operation), u128(endian));
};
}

View File

@@ -6,30 +6,13 @@
namespace auto std::mem {
namespace impl {
struct MagicSearchImpl<auto Magic, T> {
s128 address = builtin::std::mem::find_string_in_range(0, $, builtin::std::mem::size(), Magic);
if (address < 0)
break;
$ = address;
try {
T data [[inline]];
} catch {
T data;
}
};
}
/**
A Handle for a custom Section
*/
using Section = u128;
/**
The Endianess of a value
The endianness of a value
*/
enum Endian : u8 {
Native = 0,
@@ -46,6 +29,15 @@ namespace auto std::mem {
return $ >= (std::mem::base_address() + std::mem::size());
};
/**
Function that returns true if the cursor position is at or beyond the given address
@param address The address to compare against
@return True if the cursor is at or beyond the given address
*/
fn reached(u128 address) {
return $ >= address;
};
/**
Aligns the given value to the given alignment
@param alignment The alignment to align to
@@ -57,7 +49,7 @@ namespace auto std::mem {
return remainder != 0 ? value + (alignment - remainder) : value;
};
/**
Gets the base address of the data
@@ -82,8 +74,8 @@ namespace auto std::mem {
@return The address of the sequence
*/
fn find_sequence(u128 occurrence_index, auto ... bytes) {
const u128 address = builtin::std::mem::base_address();
return builtin::std::mem::find_sequence_in_range(occurrence_index, address, address + builtin::std::mem::size(), bytes);
const u128 address = std::mem::base_address();
return builtin::std::mem::find_sequence_in_range(occurrence_index, address, address + std::mem::size(), bytes);
};
/**
@@ -106,8 +98,8 @@ namespace auto std::mem {
@return The address of the sequence
*/
fn find_string(u128 occurrence_index, str string) {
const u128 address = builtin::std::mem::base_address();
return builtin::std::mem::find_string_in_range(occurrence_index, address, address + builtin::std::mem::size(), string);
const u128 address = std::mem::base_address();
return builtin::std::mem::find_string_in_range(occurrence_index, address, address + std::mem::size(), string);
};
/**
@@ -126,7 +118,7 @@ namespace auto std::mem {
Reads a unsigned value from the memory
@param address The address to read from
@param size The size of the value to read
@param [endian] The endianess of the value to read. Defaults to native
@param [endian] The endianness of the value to read. Defaults to native
@return The value read
*/
fn read_unsigned(u128 address, u8 size, Endian endian = Endian::Native) {
@@ -137,7 +129,7 @@ namespace auto std::mem {
Reads a signed value from the memory
@param address The address to read from
@param size The size of the value to read
@param [endian] The endianess of the value to read. Defaults to native
@param [endian] The endianness of the value to read. Defaults to native
@return The value read
*/
fn read_signed(u128 address, u8 size, Endian endian = Endian::Native) {
@@ -233,26 +225,16 @@ namespace auto std::mem {
return builtin::std::mem::current_bit_offset();
};
/**
Searches for a sequence of bytes and places the given type at that address
@tparam Magic The magic sequence to search for
@tparam T The type to place at the address
*/
struct MagicSearch<auto Magic, T> {
std::mem::impl::MagicSearchImpl<Magic, T> impl[while(!std::mem::eof())] [[inline]];
};
/**
Reinterprets a value as a different one
@tparam From The type to reinterpret from
@tparam To The type to reinterpret to
*/
union Reinterpreter<From, To> {
From from;
To to;
From from_value;
To to_value;
};
/**
Aligns the cursor to the given alignment
@@ -271,11 +253,33 @@ namespace auto std::mem {
} [[sealed, format("std::mem::impl::format_bytes")]];
namespace impl {
fn format_bytes(auto bytes) {
return "";
};
struct MagicSearchImpl<auto Magic, T> {
s128 address = builtin::std::mem::find_string_in_range(0, $, std::mem::size(), Magic);
if (address < 0)
break;
$ = address;
try {
T data [[inline]];
} catch {
T data;
}
};
}
/**
Searches for a sequence of bytes and places the given type at that address
@tparam Magic The magic sequence to search for
@tparam T The type to place at the address
*/
struct MagicSearch<auto Magic, T> {
std::mem::impl::MagicSearchImpl<Magic, T> impl[while(!std::mem::eof())] [[inline]];
};
}

View File

@@ -47,9 +47,9 @@ namespace auto std::ptr {
Example:
A struct field called `p_myInfo` which is a nullable 64-bit pointer to an
element of type `MyInfoTy` would be written as:
```
```rust
struct MyStruct {
std::ptr::NullablePtr<MyInfoTy, u64> p_myInfo;
std::ptr::NullablePtr<MyInfoTy, u64> p_myInfo;
}
```
*/
@@ -57,7 +57,7 @@ namespace auto std::ptr {
// `pointerValue` is `no_unique_address` because we don't want to advance
// the current memory location after reading the value of the pointer itself;
// we want to examine the value at this address to determine what should be
// displayed. It's also `hidden` so the editor only displays either thee
// displayed. It's also `hidden` so the editor only displays either thee
// padding or the populated pointer/pointee field.
PointerTy pointerValue [[no_unique_address, hidden]];
if (pointerValue == 0x0) {

View File

@@ -7,7 +7,7 @@ import std.limits;
*/
namespace auto std::random {
/**
Represents the type of distribution to use to generate a random number
*/
@@ -68,7 +68,7 @@ namespace auto std::random {
return builtin::std::random::generate(u32(distribution), param1, param2);
};
/**
Generates a uniformly distributed random number between `min` and `max`
@param [min] Minimum number. Defaults to 0
@@ -77,5 +77,5 @@ namespace auto std::random {
fn generate(u64 min = std::limits::u64_min(), u64 max = std::limits::u64_max()) {
return std::random::generate_using(Distribution::Uniform, min, max);
};
}

View File

@@ -4,13 +4,13 @@ import std.io;
import std.mem;
/*!
Libray to interact with strings.
Library to interact with strings.
*/
namespace auto std::string {
/**
Base type for sized strings. Represents a string with its size preceeding it.
Base type for sized strings. Represents a string with its size preceding it.
@tparam SizeType The type of the size field.
@tparam DataType The type of the characters.
*/
@@ -36,7 +36,7 @@ namespace auto std::string {
@tparam DataType The type of the characters.
*/
struct NullStringBase<DataType> {
DataType string[while(std::mem::read_unsigned($, sizeof(DataType)) != 0x00)];
DataType data[while(std::mem::read_unsigned($, sizeof(DataType)) != 0x00)];
DataType null_terminator;
} [[sealed, format("std::string::impl::format_string"), transform("std::string::impl::format_string")]];
@@ -125,6 +125,8 @@ namespace auto std::string {
@return True if the string starts with the substring, false otherwise.
*/
fn starts_with(str string, str part) {
if (std::string::length(string) < std::string::length(part))
return false;
return std::string::substr(string, 0, std::string::length(part)) == part;
};
@@ -135,6 +137,8 @@ namespace auto std::string {
@return True if the string ends with the substring, false otherwise.
*/
fn ends_with(str string, str part) {
if (std::string::length(string) < std::string::length(part))
return false;
return std::string::substr(string, std::string::length(string) - std::string::length(part), std::string::length(part)) == part;
};
@@ -161,16 +165,16 @@ namespace auto std::string {
@param string The string to reverse.
@return The reversed string.
*/
fn reverse(str string) {
fn reverse(str string) {
str result;
s32 i;
i = std::string::length(string);
while (i > 0) {
i = i - 1;
result = result + std::string::at(string, i);
}
return result;
};
@@ -181,23 +185,23 @@ namespace auto std::string {
*/
fn to_upper(str string) {
str result;
u32 i;
char c;
while (i < std::string::length(string)) {
c = std::string::at(string, i);
if (c >= 'a' && c <= 'z')
result = result + char(c - 0x20);
else
result = result + c;
i = i + 1;
}
return result;
};
/**
Converts a string to lower case.
@param string The string to convert.
@@ -205,20 +209,20 @@ namespace auto std::string {
*/
fn to_lower(str string) {
str result;
u32 i;
char c;
while (i < std::string::length(string)) {
c = std::string::at(string, i);
if (c >= 'A' && c <= 'Z')
result = result + char(c + 0x20);
else
result = result + c;
i = i + 1;
}
return result;
};

View File

@@ -50,7 +50,7 @@ namespace auto std {
};
/**
Throws an error notifying the developer that the current codepath is not implemented currently.
Throws an error notifying the developer that the current code path is not implemented currently.
*/
fn unimplemented() {
std::error("Unimplemented code path reached!");

View File

@@ -8,7 +8,7 @@ import std.core;
*/
namespace auto type {
/**
Type visualizing the value of each individual bit
*/
@@ -22,7 +22,7 @@ namespace auto type {
bit6 : 1;
bit7 : 1;
} [[format("type::impl::format_bits"), bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
/**
Type visualizing the value of the two nibbles
*/
@@ -30,9 +30,9 @@ namespace auto type {
low : 4;
high : 4;
} [[format("type::impl::format_nibbles")]];
/**
Type representing a single Byte. Decodes the byte as it's hexadeicmal value, individual bits and nibbles
Type representing a single Byte. Decodes the byte as it's hexadecimal value, individual bits and nibbles
*/
union Byte {
u8 value;
@@ -50,9 +50,9 @@ namespace auto type {
byte.bits.bit0,
byte.bits.bit7);
};
fn format_bits(Bits bits) {
return std::format("0b{}{}{}{}{}{}{}{}",
return std::format("0b{}{}{}{}{}{}{}{}",
bits.bit7,
bits.bit6,
bits.bit5,
@@ -62,7 +62,7 @@ namespace auto type {
bits.bit1,
bits.bit0);
};
fn format_nibbles(Nibbles nibbles) {
return std::format("{{ {0:0X}, {1:0X} }}", nibbles.high, nibbles.low);
};

View File

@@ -14,15 +14,15 @@ namespace auto type {
@tparam R Number of bits used for the red component
@tparam G Number of bits used for the green component
@tparam B Number of bits used for the blue component
@tparam A Number of bits used for the alpha component
@tparam A Number of bits used for the alpha component
*/
bitfield RGBA<auto R, auto G, auto B, auto A> {
r : R;
g : G;
b : B;
if (A > 0) a : A;
} [[sealed, format("type::impl::format_color"), color(std::format("{0:02X}{1:02X}{2:02X}FF", r, g, b))]];
} [[sealed, format("type::impl::format_color"), color(std::format("{0:02X}{1:02X}{2:02X}", r, g, b))]];
/**
Type representing a generic RGB color with a variable number of bits for each color
@tparam R Number of bits used for the red component
@@ -30,7 +30,7 @@ namespace auto type {
@tparam B Number of bits used for the blue component
*/
using RGB<auto R, auto G, auto B> = RGBA<R,G,B,0>;
/**
Type representing a RGBA color with 8 bits for the red component, 8 bits for green, 8 bits for blue and 8 bits for alpha
@@ -56,7 +56,7 @@ namespace auto type {
Type representing a RGBA color with 5 bits for the red component, 5 bits for green, 5 bits for blue and 1 bits for alpha
*/
using RGBA5551 = RGBA<5,5,5,1>;
namespace impl {
@@ -76,5 +76,5 @@ namespace auto type {
};
}
}
}

View File

@@ -9,14 +9,14 @@ import std.mem;
*/
namespace auto type {
/**
Type representing a 16 bit half precision floating point number
*/
using float16 = u16 [[format("type::impl::format_float16")]];
namespace impl {
union U32ToFloatConverter {
u32 intValue;
float floatValue;
@@ -26,20 +26,20 @@ namespace auto type {
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);
}
@@ -48,11 +48,11 @@ namespace auto type {
} else {
result = (sign << 31) | ((exponent + (0x7F - 15)) << 23) | (mantissa << 13);
}
std::mem::Reinterpreter<u32, float> converter;
converter.from = result;
return std::format("{}", converter.to);
converter.from_value = result;
return std::format("{}", converter.to_value);
};
}

View File

@@ -30,7 +30,7 @@ namespace auto type {
namespace impl {
fn format_formatted(ref auto formatted) {
return std::format(std::format("{{0:{}}}", formatted.FormatString), formatted.value);
return std::format(formatted.FormatString, formatted.value);
};
fn transform_formatted(ref auto formatted) {
@@ -39,4 +39,4 @@ namespace auto type {
}
}
}

View File

@@ -29,7 +29,7 @@ namespace auto type {
fn format_guid(GUID guid) {
bool valid = ((le u16(guid.time_high_and_version) >> 12) <= 5) && (((guid.clock_seq_and_reserved >> 4) >= 8) || ((guid.clock_seq_and_reserved >> 4) == 0));
return std::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
valid ? "" : "Invalid ",
le u32(guid.time_low),

View File

@@ -8,7 +8,7 @@ import std.mem;
*/
namespace auto type {
/**
Base LEB128 type. Use `uLEB128` and `sLEB128` instead.
*/
@@ -30,9 +30,9 @@ namespace auto type {
Legacy alias for uLEB128
*/
using LEB128 = uLEB128;
namespace impl {
fn transform_uleb128_array(ref auto array) {
u128 res = array[0] & 0x7f;
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
@@ -41,19 +41,19 @@ namespace auto type {
return res;
};
fn transform_sleb128_array(ref auto array) {
fn transform_sleb128_array(ref auto array) {
s128 res = type::impl::transform_uleb128_array(array);
if (res & 0x40 != 0) {
if (res & 1 << ((sizeof(array) / sizeof(u8)) * 7 - 1) != 0) {
res |= ~0 << (sizeof(array) / sizeof(u8)) * 7;
}
return res;
};
fn format_uleb128(ref auto leb128) {
u128 res = type::impl::transform_uleb128_array(leb128.array);
return std::format("{} ({:#x})", res, res);
};
fn transform_uleb128(ref auto leb128) {
return type::impl::transform_uleb128_array(leb128.array);
};
@@ -62,11 +62,11 @@ namespace auto type {
s128 res = type::impl::transform_sleb128_array(leb128.array);
return std::format("{} ({:#x})", res, res);
};
fn transform_sleb128(ref auto leb128) {
return type::impl::transform_sleb128_array(leb128.array);
};
}
}

View File

@@ -9,8 +9,13 @@ import std.ctype;
namespace auto type
{
fn fm(ref auto value)
{
/**
Escapes all bytes in a string to only contain printable characters. All non-printable bytes will be transformed to sequences in the \xFF form
@param value Byte array to escape
@return Escaped string
*/
fn escape_bytes(ref auto value) {
str result;
for (u32 i = 0, i < sizeof(value), i += 1)
{
@@ -21,23 +26,20 @@ namespace auto type
else
result += std::format("\\x{:02X}", u8(c));
}
return std::format("\"{}\"", result);
return result;
};
/**
A Magic number. Throws an error if the magic number does not match the expected value
@tparam ExpectedValue A string representing the expected value
*/
struct Magic<auto ExpectedValue>
{
struct Magic<auto ExpectedValue> {
char value[std::string::length(ExpectedValue)];
std::assert_warn(value == ExpectedValue, std::format("Invalid magic value! Expected {}, got {} at position 0x{:X}", type::fm(ExpectedValue), type::fm(value), $ - std::string::length(ExpectedValue)));
std::assert(value == ExpectedValue, std::format("Invalid magic value! Expected \"{}\", got \"{}\" at position 0x{:X}", type::escape_bytes(ExpectedValue), type::escape_bytes(value), $ - std::string::length(ExpectedValue)));
} [[sealed, format("type::impl::format_magic")]];
namespace impl
{
fn format_magic(ref auto magic)
{
return type::fm(magic.value);
namespace impl {
fn format_magic(ref auto magic) {
return std::format("\"{}\"", type::escape_bytes(magic.value));
};
}
}

View File

@@ -8,10 +8,10 @@ namespace auto type {
/**
Type representing a single path segment. Use the `Path` type instead of using this on its own
@tparam Delimeter The delimeter sequence used to separate two path segments
@tparam Delimiter The delimiter sequence used to separate two path segments
*/
struct PathSegment<auto Delimeter> {
char string[while(std::mem::read_string($, std::string::length(Delimeter)) != Delimeter && std::mem::read_unsigned($, 1) != 0x00)];
struct PathSegment<auto Delimiter> {
char string[while(std::mem::read_string($, std::string::length(Delimiter)) != Delimiter && std::mem::read_unsigned($, 1) != 0x00)];
char separator [[hidden]];
if (separator == 0x00) {
@@ -21,20 +21,20 @@ namespace auto type {
} [[sealed, format("type::impl::format_path_segment")]];
/**
A generic type representing a path with an arbitrary delimeter
@tparam Delimeter The delimeter sequence used to separate two path segments
A generic type representing a path with an arbitrary delimiter
@tparam Delimiter The delimiter sequence used to separate two path segments
*/
struct Path<auto Delimeter> {
PathSegment<Delimeter> segments[while(true)];
struct Path<auto Delimiter> {
PathSegment<Delimiter> segments[while(true)];
} [[format("type::impl::format_path")]];
/**
A type representing a Unix path using a '/' forwardslash as delimeter
A type representing a Unix path using a '/' forward slash as delimiter
*/
using UnixPath = Path<"/">;
/**
A type representing a DOS path using a '\\' backslash as delimeter
A type representing a DOS path using a '\\' backslash as delimiter
*/
using DOSPath = Path<"\\">;

View File

@@ -13,9 +13,9 @@ namespace auto type {
A 32 bit Unix time value
*/
using time32_t = u32 [[format("type::impl::format_time_t")]];
/**
Alias name for `time32_t`
Alias name for `time32_t`
*/
using time_t = time32_t;

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description Autodesk 3DS Max Model file
#pragma description Autodesk 3DS Max Model
import std.io;
import type.base;
@@ -7,7 +7,7 @@ import type.base;
#pragma MIME image/x-3ds
// Heavily based off of ZiZi's 010 Editor 3DS Template
enum ChunkIdentifier : u16 {
enum ChunkIdentifier : u16 {
NULL_CHUNK = 0x0000,
ChunkType = 0x0995,
ChunkUnique = 0x0996,
@@ -40,10 +40,10 @@ enum ChunkIdentifier : u16 {
COLOR_24 = 0x0011, // r,g,b: Byte
LIN_COLOR_24 = 0x0012, // r,g,b: Byte (gamma corrected)
LIN_COLOR_F = 0x0013, // r,g,b: Single precision float (gamma corrected)
INT_PERCENTAGE = 0x0030, // u16 integer
FLOAT_PERCENTAGE = 0x0031, // Single precision float
M3DMAGIC = 0x4D4D,
SMAGIC = 0x2D2D,
LMAGIC = 0x2D3D,
@@ -72,7 +72,7 @@ enum ChunkIdentifier : u16 {
RAY_BIAS = 0x1460,
USE_RAYTRACE = 0x1470,
O_CONSTS = 0x1500,
AMBIENT_LIGHT = 0x2100,
FOG = 0x2200,
@@ -82,7 +82,7 @@ enum ChunkIdentifier : u16 {
USE_DISTANCE_CUE = 0x2301,
WORLD_LAYERED_FOG = 0x2302,
WORLD_USE_LAYERED_FOG = 0x2303,
DEFAULT_VIEW = 0x3000,
VIEW_TOP = 0x3010,
VIEW_BOTTOM = 0x3020,
@@ -93,7 +93,7 @@ enum ChunkIdentifier : u16 {
VIEW_USER = 0x3070,
VIEW_CAMERA = 0x3080,
VIEW_WINDOW = 0x3090,
NAMED_OBJECT = 0x4000,
OBJ_HIDDEN = 0x4010,
OBJ_VIS_LOFTER = 0x4011,
@@ -103,7 +103,7 @@ enum ChunkIdentifier : u16 {
OBJ_PROCEDURAL = 0x4015,
OBJ_FROZEN = 0x4016,
OBJ_DONT_RCVSHADOW = 0x4017,
N_TRI_OBJECT = 0x4100,
POINT_ARRAY = 0x4110,
POINT_FLAG_ARRAY = 0x4111,
@@ -134,7 +134,7 @@ enum ChunkIdentifier : u16 {
DL_SPOT_OVERSHOOT = 0x4652,
DL_SPOT_PROJECTOR = 0x4653,
DL_EXCLUDE = 0x4654,
DL_RANGE = 0x4655, /* Not used in R3 */
DL_RANGE = 0x4655, /* Not used in R3 */
DL_SPOT_ROLL = 0x4656,
DL_SPOT_ASPECT = 0x4657,
DL_RAY_BIAS = 0x4658,
@@ -143,22 +143,22 @@ enum ChunkIdentifier : u16 {
DL_INNER_RANGE = 0x4659,
DL_OUTER_RANGE = 0x465A,
DL_MULTIPLIER = 0x465B,
N_AMBIENT_LIGHT = 0x4680,
N_CAMERA = 0x4700,
CAM_SEE_CONE = 0x4710,
CAM_RANGES = 0x4720,
HIERARCHY = 0x4F00,
PARENT_OBJECT = 0x4F10,
PIVOT_OBJECT = 0x4F20,
PIVOT_LIMITS = 0x4F30,
PIVOT_ORDER = 0x4F40,
XLATE_RANGE = 0x4F50,
POLY_2D = 0x5000,
/* Flags in shaper file that tell whether polys make up an ok shape */
SHAPE_OK = 0x5010,
SHAPE_NOT_OK = 0x5011,
@@ -177,8 +177,8 @@ enum ChunkIdentifier : u16 {
YZ_CURVE = 0x6080,
INTERPCT = 0x6090,
DEFORM_LIMIT = 0x60A0,
/* Flags for Modeler options */
/* Flags for Modeler options */
USE_CONTOUR = 0x6100,
USE_TWEEN = 0x6110,
USE_SCALE = 0x6120,
@@ -187,7 +187,7 @@ enum ChunkIdentifier : u16 {
USE_FIT = 0x6150,
USE_BEVEL = 0x6160,
/* Viewport description chunks */
/* Viewport description chunks */
VIEWPORT_LAYOUT_OLD = 0x7000,
VIEWPORT_DATA_OLD = 0x7010,
VIEWPORT_LAYOUT = 0x7001,
@@ -196,7 +196,7 @@ enum ChunkIdentifier : u16 {
VIEWPORT_SIZE = 0x7020,
NETWORK_VIEW = 0x7030,
/* External Application Data */
/* External Application Data */
XDATA_SECTION = 0x8000,
XDATA_ENTRY = 0x8001,
XDATA_APPNAME = 0x8002,
@@ -215,8 +215,8 @@ enum ChunkIdentifier : u16 {
XDATA_RFU1 = 0x800F,
PARENT_NAME = 0x80F0,
/* Material Chunk IDs */
/* Material Chunk IDs */
MAT_ENTRY = 0xAFFF,
MAT_NAME = 0xA000,
MAT_AMBIENT = 0xA010,
@@ -228,7 +228,7 @@ enum ChunkIdentifier : u16 {
MAT_TRANSPARENCY = 0xA050,
MAT_XPFALL = 0xA052,
MAT_REFBLUR = 0xA053,
MAT_SELF_ILLUM = 0xA080,
MAT_TWO_SIDE = 0xA081,
MAT_DECAL = 0xA082,
@@ -241,13 +241,13 @@ enum ChunkIdentifier : u16 {
MAT_XPFALLIN = 0xA08A,
MAT_PHONGSOFT = 0xA08C,
MAT_WIREABS = 0xA08E,
MAT_SHADING = 0xA100,
MAT_TEXMAP = 0xA200,
MAT_MAPNAME = 0xA300,
MAT_ACUBIC = 0xA310,
MAT_MAP_TILINGOLD = 0xA350,
MAT_MAP_TILING = 0xA351,
MAT_MAP_TEXBLUR_OLD = 0xA352,
@@ -262,14 +262,14 @@ enum ChunkIdentifier : u16 {
MAT_MAP_RCOL = 0xA364,
MAT_MAP_GCOL = 0xA366,
MAT_MAP_BCOL = 0xA368,
MAT_SPECMAP = 0xA204,
MAT_OPACMAP = 0xA210,
MAT_REFLMAP = 0xA220,
MAT_BUMPMAP = 0xA230,
MAT_USE_REFBLUR = 0xA250,
MAT_BUMP_PERCENT = 0xA252,
MAT_SXP_TEXT_DATA = 0xA320,
MAT_SXP_TEXT2_DATA = 0xA321,
MAT_SXP_OPAC_DATA = 0xA322,
@@ -285,7 +285,7 @@ enum ChunkIdentifier : u16 {
MAT_SXP_SHIN_MASKDATA = 0xA334,
MAT_SXP_SELFI_MASKDATA = 0xA336,
MAT_SXP_REFL_MASKDATA = 0xA338,
MAT_TEX2MAP = 0xA33A,
MAT_SHINMAP = 0xA33C,
MAT_SELFIMAP = 0xA33D,
@@ -297,8 +297,8 @@ enum ChunkIdentifier : u16 {
MAT_SPECMASK = 0xA348,
MAT_SELFIMASK = 0xA34A,
MAT_REFLMASK = 0xA34C,
/* Keyframe Chunk IDs */
/* Keyframe Chunk IDs */
KFDATA = 0xB000,
KFHDR = 0xB00A,
AMBIENT_NODE_TAG = 0xB001,
@@ -308,13 +308,13 @@ enum ChunkIdentifier : u16 {
LIGHT_NODE_TAG = 0xB005,
L_TARGET_NODE_TAG = 0xB006,
SPOTLIGHT_NODE_TAG = 0xB007,
KFSEG = 0xB008,
KFCURTIME = 0xB009,
NODE_HDR = 0xB010,
INSTANCE_NAME = 0xB011,
PRESCALE = 0xB012,
PRESCALE = 0xB012,
PIVOT = 0xB013,
BOUNDBOX = 0xB014,
MORPH_SMOOTH = 0xB015,
@@ -329,10 +329,10 @@ enum ChunkIdentifier : u16 {
FALL_TRACK_TAG = 0xB028,
HIDE_TRACK_TAG = 0xB029,
NODE_ID = 0xB030,
CMAGIC = 0xC23D,
C_MDRAWER = 0xC010,
C_TDRAWER = 0xC020,
C_SHPDRAWER = 0xC030,
@@ -395,7 +395,7 @@ enum ChunkIdentifier : u16 {
C_BITMAP_DRAWER = 0xC25B,
C_RGB_FILE = 0xC260,
C_RGB_OVASPECT = 0xC270,
C_RGB_ANIMTYPE = 0xC271,
C_RENDER_ALL = 0xC272,
C_REND_FROM = 0xC273,
@@ -513,16 +513,16 @@ enum ChunkIdentifier : u16 {
C_VTR_IN = 0xC775,
C_VTR_PK = 0xC780,
C_VTR_SH = 0xC785,
/* Material chunks */
C_WORK_MTLS = 0xC790, /* Old-style -- now ignored */
C_WORK_MTLS_2 = 0xC792, /* Old-style -- now ignored */
C_WORK_MTLS_3 = 0xC793, /* Old-style -- now ignored */
C_WORK_MTLS_4 = 0xC794, /* Old-style -- now ignored */
C_WORK_MTLS_5 = 0xCB00, /* Old-style -- now ignored */
C_WORK_MTLS_6 = 0xCB01, /* Old-style -- now ignored */
C_WORK_MTLS_7 = 0xCB02, /* Old-style -- now ignored */
C_WORK_MTLS_8 = 0xCB03, /* Old-style -- now ignored */
/* Material chunks */
C_WORK_MTLS = 0xC790, /* Old-style -- now ignored */
C_WORK_MTLS_2 = 0xC792, /* Old-style -- now ignored */
C_WORK_MTLS_3 = 0xC793, /* Old-style -- now ignored */
C_WORK_MTLS_4 = 0xC794, /* Old-style -- now ignored */
C_WORK_MTLS_5 = 0xCB00, /* Old-style -- now ignored */
C_WORK_MTLS_6 = 0xCB01, /* Old-style -- now ignored */
C_WORK_MTLS_7 = 0xCB02, /* Old-style -- now ignored */
C_WORK_MTLS_8 = 0xCB03, /* Old-style -- now ignored */
C_WORKMTL = 0xCB04,
C_SXP_TEXT_DATA = 0xCB10,
C_SXP_TEXT2_DATA = 0xCB20,
@@ -542,15 +542,15 @@ enum ChunkIdentifier : u16 {
C_BGTYPE = 0xC7A1,
C_MEDTILE = 0xC7B0,
/* Contrast */
C_LO_CONTRAST = 0xC7D0,
C_HI_CONTRAST = 0xC7D1,
/* 3d frozen display */
/* 3d frozen display */
C_FROZ_DISPLAY = 0xC7E0,
/* Booleans */
/* Booleans */
C_BOOLWELD = 0xc7f0,
C_BOOLTYPE = 0xc7f1,
@@ -569,8 +569,8 @@ enum ChunkIdentifier : u16 {
C_MAPDRAWER8 = 0xCA08,
C_MAPDRAWER9 = 0xCA09,
C_MAPDRAWER_ENTRY = 0xCA10,
/* System Options */
/* System Options */
C_BACKUP_FILE = 0xCA20,
C_DITHER_256 = 0xCA21,
C_SAVE_LAST = 0xCA22,
@@ -596,8 +596,8 @@ enum ChunkIdentifier : u16 {
C_AUTO_SMOOTH = 0xCA80,
C_DXF_SMOOTH_ANG = 0xCA90,
C_SMOOTH_ANG = 0xCAA0,
/* Special network-use chunks */
/* Special network-use chunks */
C_NET_USE_VPOST = 0xCC00,
C_NET_USE_GAMMA = 0xCC10,
C_NET_FIELD_ORDER = 0xCC20,
@@ -628,8 +628,8 @@ enum ChunkIdentifier : u16 {
C_VIEW_PRES_RATIO = 0xCE50,
C_BGND_PRES_RATIO = 0xCE60,
C_NTH_SERIAL_NUM = 0xCE70,
/* Video Post */
/* Video Post */
VPDATA = 0xd000,
P_QUEUE_ENTRY = 0xd100,
@@ -648,7 +648,7 @@ enum ChunkIdentifier : u16 {
P_QUEUE_ALIGN = 0xd190,
P_CUSTOM_SIZE = 0xd1a0,
P_ALPH_NONE = 0xd210,
P_ALPH_PSEUDO = 0xd220, /* Old chunk */
P_ALPH_OP_PSEUDO = 0xd221, /* Old chunk */
@@ -732,7 +732,7 @@ bitfield Spline {
Use_Bias : 1;
Use_Ease_To : 1;
Use_Ease_From : 1;
padding : 3;
if (Use_Tension == 1)
@@ -745,7 +745,7 @@ bitfield Spline {
float Ease_To;
if (Use_Ease_From == 1)
float Ease_From;
padding : 8;
};
@@ -795,7 +795,7 @@ struct Keys<auto identifier> {
) : {
RotationKey data[count];
}
(
ChunkIdentifier::FOV_TRACK_TAG |
ChunkIdentifier::ROLL_TRACK_TAG |
@@ -804,13 +804,13 @@ struct Keys<auto identifier> {
) : {
AngleKey data[count];
}
(
ChunkIdentifier::MORPH_TRACK_TAG
) : {
MorphKey data[count];
}
(
ChunkIdentifier::HIDE_TRACK_TAG
) : {
@@ -842,7 +842,7 @@ struct Chunk {
u32 chunkSize;
u32 dataLength = chunkSize - 6 [[export]];
u32 chunkEnd = $ + dataLength;
if (chunkSize > 0) {
std::print("{}", identifier);
match (identifier) {
@@ -894,14 +894,14 @@ struct Chunk {
): {
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::M3D_VERSION |
ChunkIdentifier::MESH_VERSION
): {
u32 version;
}
(
ChunkIdentifier::LO_SHADOW_BIAS |
ChunkIdentifier::HI_SHADOW_BIAS |
@@ -921,41 +921,41 @@ struct Chunk {
): {
float value;
}
(
ChunkIdentifier::V_GRADIENT
) : {
float position;
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::NAMED_OBJECT
) : {
char name[];
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::POINT_ARRAY
) : {
u16 count;
Vector3f vectices[count] [[hex::visualize("3d", this, null)]];
}
(
ChunkIdentifier::TEX_VERTS
) : {
u16 count;
Vector2f coords[count];
}
(
ChunkIdentifier::MESH_MATRIX
) : {
Vector3f x, y, z, w;
}
(
ChunkIdentifier::FACE_ARRAY
) : {
@@ -963,26 +963,26 @@ struct Chunk {
Face faces[count];
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::POINT_FLAG_ARRAY
) : {
u16 count;
VertexFlags flags[count];
}
(
ChunkIdentifier::SMOOTH_GROUP
) : {
u32 groups[dataLength / sizeof(u32)];
}
(
ChunkIdentifier::MESH_COLOR
) : {
u8 value;
}
(
ChunkIdentifier::MSH_MAT_GROUP
) : {
@@ -990,7 +990,7 @@ struct Chunk {
u16 count;
u16 groups[count];
}
(
ChunkIdentifier::KFHDR
) : {
@@ -998,25 +998,25 @@ struct Chunk {
char name[];
u32 animationLength;
}
(
ChunkIdentifier::KFSEG
) : {
u32 start, end;
}
(
ChunkIdentifier::KFCURTIME
) : {
u32 frameIndex;
}
(
ChunkIdentifier::NODE_ID
) : {
type::Hex<u16> id;
}
(
ChunkIdentifier::NODE_HDR
) : {
@@ -1026,47 +1026,47 @@ struct Chunk {
KeyFlags2 flags2;
type::Hex<u16> parentId;
}
(
ChunkIdentifier::PIVOT
) : {
Vector3f value;
}
(
ChunkIdentifier::BOUNDBOX
) : {
Vector3f min, max;
}
(
ChunkIdentifier::COLOR_24 |
ChunkIdentifier::LIN_COLOR_24
) : {
RGB<u8> color;
}
(
ChunkIdentifier::COLOR_F |
ChunkIdentifier::LIN_COLOR_F
) : {
RGB<float> color;
}
(
ChunkIdentifier::INT_PERCENTAGE |
ChunkIdentifier::MAT_BUMP_PERCENT
) : {
u16 value;
}
(
ChunkIdentifier::SHADOW_MAP_SIZE |
ChunkIdentifier::MAT_SHADING
) : {
u16 value;
}
(
ChunkIdentifier::POS_TRACK_TAG |
ChunkIdentifier::ROT_TRACK_TAG |
@@ -1077,13 +1077,13 @@ struct Chunk {
ChunkIdentifier::MORPH_TRACK_TAG |
ChunkIdentifier::HOT_TRACK_TAG |
ChunkIdentifier::FALL_TRACK_TAG |
ChunkIdentifier::HIDE_TRACK_TAG
ChunkIdentifier::HIDE_TRACK_TAG
) : {
TrackFlags flags;
u8 unknown[8];
Keys<identifier> keys;
}
(
ChunkIdentifier::INSTANCE_NAME |
ChunkIdentifier::BIT_MAP |
@@ -1093,26 +1093,26 @@ struct Chunk {
) : {
char name[];
}
(
ChunkIdentifier::MAT_MAP_TILING
) : {
u16 tiling;
}
(
ChunkIdentifier::WORLD_VIEWPORT_SIZE
) : {
u16 x, y, w, h;
}
(
ChunkIdentifier::N_DIRECT_LIGHT
) : {
Vector3f position;
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::DL_SPOTLIGHT
) : {
@@ -1120,16 +1120,16 @@ struct Chunk {
float hotspot, falloff;
Chunk chunks[while($ < chunkEnd)];
}
(
ChunkIdentifier::N_CAMERA
) : {
Vector3f position, target;
float roll, fov;
}
(_) : {
std::warning(std::format("Unhandled Chunk ID: {}, Skipping 0x{:04X} bytes", identifier, dataLength));
$ += dataLength;

View File

@@ -1,102 +1,93 @@
#pragma description 7z File Format
#pragma description 7z Archive
#pragma MIME application/x-7z-compressed
#pragma magic [ 37 7A BC AF 27 1C ] @ 0x00
import std.io;
import std.mem;
import std.math;
import std.io;
import std.mem;
import std.math;
import type.magic;
enum Type:u8{
startPosition = 0x00, // Start position
sizeStartHeader = 0x20, // Size of start Header
};
enum Type:u8{
startPosition = 0x00, // Start position
sizeStartHeader = 0x20, // Size of start Header
};
enum TypeB:u48{
sevenZipSignature = 0x1C27AFBC7A37, // Defining 7z signature
};
struct StartHeader {
// File signature
type::Magic<"7z\xBC\xAF\x27\x1C"> signature [[color("FF0000")] ];
// Version format
u16 formatVersion [[color("00FF00")]];
// CRC start header
u32 crcOfTheFollowing20Bytes [[color("0000FF")]];
// Relative offset of End Header
u64 relativeOffsetEndHeader [[color("FFFF00")]];
// Length of End Header
u64 theLengthOfEndHeader [[color("00FFFF")]];
// CRC of End Ender
u32 crcOftheEndHeader [[color("FF00FF")]];
// File size calculation
u64 fileSize = relativeOffsetEndHeader + theLengthOfEndHeader + Type::sizeStartHeader;
// Absolute offset calculation End Header
u64 startEndHeader = relativeOffsetEndHeader + Type::sizeStartHeader;
};
struct StartHeader {
// File signature
u48 signature [[color("FF0000")] ];
// Version format
u16 formatVersion [[color("00FF00")]];
// CRC start header
u32 crcOfTheFollowing20Bytes [[color("0000FF")]];
// Relative offset of End Header
u64 relativeOffsetEndHeader [[color("FFFF00")]];
// Length of End Header
u64 theLengthOfEndHeader [[color("00FFFF")]];
// CRC of End Ender
u32 crcOftheEndHeader [[color("FF00FF")]];
// File size calculation
u64 fileSize = relativeOffsetEndHeader + theLengthOfEndHeader + Type::sizeStartHeader;
// Absolute offset calculation End Header
u64 startEndHeader = relativeOffsetEndHeader + Type::sizeStartHeader;
};
StartHeader startheader @ Type::startPosition;
StartHeader startheader @ Type::startPosition;
struct CompressedData {
// Start of compressed data
u8 startOfCompressedData[4] [[color("C0C0C0")]];
};
struct CompressedData {
// Start of compressed data
u8 startOfCompressedData[4] [[color("C0C0C0")]];
};
CompressedData compresseddata @ Type::sizeStartHeader;
CompressedData compresseddata @ Type::sizeStartHeader;
struct EndHeader {
// Set padding to place End Header in right position
padding[startheader.relativeOffsetEndHeader];
// Mark link to meta block
u8 linkToMetaBlock [[color("FF0000")]];
// Mark all End Header
char fullEndHeader[startheader.theLengthOfEndHeader] [[color("63954A")]];
// Detect LZMA signature
u64 lzmaSignaturePosition = std::mem::find_sequence_in_range(0, addressof(fullEndHeader), addressof(fullEndHeader) + sizeof(fullEndHeader), 0x23, 0x03, 0x01, 0x01, 0x05, 0x5D);
// Mark positions if LZMA signature was detected
if(lzmaSignaturePosition != 0xFFFFFFFFFFFFFFFF){
u48 lzmaSignature @ lzmaSignaturePosition [[color("0000FF")]];
}
};
EndHeader endheader @ Type::sizeStartHeader;
// Check 7z type
if(startheader.signature == TypeB::sevenZipSignature){
std::print("It is a 7z File Type");
}else{
std::print("The file is not 7z type");
}
struct EndHeader {
// Set padding to place End Header in right position
padding[startheader.relativeOffsetEndHeader];
// Mark link to meta block
u8 linkToMetaBlock [[color("FF0000")]];
// Mark all End Header
char fullEndHeader[startheader.theLengthOfEndHeader] [[color("63954A")]];
// Detect LZMA signature
u64 lzmaSignaturePosition = std::mem::find_sequence_in_range(0, addressof(fullEndHeader), addressof(fullEndHeader) + sizeof(fullEndHeader), 0x23, 0x03, 0x01, 0x01, 0x05, 0x5D);
std::print("Format Version {} ",startheader.formatVersion);
// Mark positions if LZMA signature was detected
if(lzmaSignaturePosition != 0xFFFFFFFFFFFFFFFF){
u48 lzmaSignature @ lzmaSignaturePosition [[color("0000FF")]];
}
};
// Version verification
if(startheader.formatVersion == 0x0400){
std::print("Major Version 0x00 || 0 - Minor Version 0x04 || 4");
}
EndHeader endheader @ Type::sizeStartHeader;
// Verification of the compressed method is LZMA, Bzip2 or LZMA2
if(compresseddata.startOfCompressedData[0] == Type::startPosition){
std::print("Compressed Method LZMA");
}else if(compresseddata.startOfCompressedData[0] == 0x42){
std::print("Compressed Method Bzip2");
}else{
std::print("Compressed Method LZMA2");
}
std::print("Format Version {} ",startheader.formatVersion);
// Version verification
if(startheader.formatVersion == 0x0400){
std::print("Major Version 0x00 || 0 - Minor Version 0x04 || 4");
}
std::print("CRC Start Header 0x{:X}",startheader.crcOfTheFollowing20Bytes);
// Verification of the compressed method is LZMA, Bzip2 or LZMA2
if(compresseddata.startOfCompressedData[0] == Type::startPosition){
std::print("Compressed Method LZMA");
}else if(compresseddata.startOfCompressedData[0] == 0x42){
std::print("Compressed Method Bzip2");
}else{
std::print("Compressed Method LZMA2");
}
std::print("CRC End Header 0x{:X} ", startheader.crcOftheEndHeader);
std::print("CompressedData length 0x{:X} || {} bytes ",startheader.relativeOffsetEndHeader, startheader.relativeOffsetEndHeader);
std::print("Relative Offset of End Header 0x{:X} || {} bytes",startheader.relativeOffsetEndHeader, startheader.relativeOffsetEndHeader);
std::print("CRC Start Header 0x{:X}",startheader.crcOfTheFollowing20Bytes);
std::print("Offset to start End Header 0x{:X} || {} bytes",startheader.startEndHeader,startheader.startEndHeader);
std::print("CRC End Header 0x{:X} ", startheader.crcOftheEndHeader);
std::print("End Header length 0x{:X} || {} bytes",startheader.theLengthOfEndHeader,startheader.theLengthOfEndHeader);
std::print("CompressedData length 0x{:X} || {} bytes ",startheader.relativeOffsetEndHeader, startheader.relativeOffsetEndHeader);
std::print("File size 0x{:X} || {} bytes",startheader.fileSize, startheader.fileSize);
std::print("Relative Offset of End Header 0x{:X} || {} bytes",startheader.relativeOffsetEndHeader, startheader.relativeOffsetEndHeader);
std::print("Offset to start End Header 0x{:X} || {} bytes",startheader.startEndHeader,startheader.startEndHeader);
std::print("End Header length 0x{:X} || {} bytes",startheader.theLengthOfEndHeader,startheader.theLengthOfEndHeader);
std::print("File size 0x{:X} || {} bytes",startheader.fileSize, startheader.fileSize);

View File

@@ -0,0 +1,47 @@
#pragma description Assassin's Creed: Unity's Compressed .data file
#pragma author haru233
// many thanks to AxCut
// ImHex Hex Pattern File for Assassin's Creed: Unity's Compressed .data files
import std.core;
import std.mem;
enum CompressionType : u8 {
LZO1X_ = 0x00, // Both 0x00 and 0x01 mean LZO1X
LZO1X = 0x01,
LZO2A = 0x02,
xmemdecompress = 0x03,
LZO1C = 0x05
};
struct CHUNK {
u16 Uncompressed_Size;
u16 Compressed_Size;
};
struct CHUNK_Data {
u32 Hash;
u64 i = std::core::array_index();
u8 data[parent.chunk[i].Compressed_Size];
};
struct PACK {
u64 ID;
padding[2];
CompressionType Compression_Type;
padding[3];
u8 Version;
u16 CHUNK_Count;
CHUNK chunk[CHUNK_Count];
CHUNK_Data data[CHUNK_Count];
};
PACK pack[while(!std::mem::eof())] @0x00;

View File

@@ -0,0 +1,93 @@
#pragma description Assassin's Creed: Unity's Decompressed .data file
#pragma author haru233
// Thanks to yretenai on GitHub for helping with the Block Allocator part
import std.core;
import std.mem;
struct Block_Allocator_Type0 {
padding[4];
u32 Class_ID;
u32 Size;
};
struct Block_Allocator_Type1 {
padding[4];
u32 Type_ID;
u32 Size;
};
struct Block_Allocator {
u16 Version;
if (Version == 0) {
u32 Block_Allocator_Number;
Block_Allocator_Type0 block_allocator_type0[Block_Allocator_Number];
}
else if (Version == 1) {
u32 Block_Allocator_Number;
Block_Allocator_Type1 block_allocator_type1_[Block_Allocator_Number];
}
else if (Version == 2) {
bool Has_Secondary_Block_Allocator;
u32 Main_Block_Allocator_Number;
Block_Allocator_Type1 block_allocator_type1__[Main_Block_Allocator_Number];
if (Has_Secondary_Block_Allocator) {
u32 Secondary_Block_Allocator_Number;
Block_Allocator_Type1 block_allocator_type1___[Secondary_Block_Allocator_Number+1];
}
}
};
struct File {
u32 Object_Hash;
u32 File_Size;
u32 Filename_Length;
if (File_Size > 0) {
if (Filename_Length == 0) {
bool HasBlockAllocator;
if (HasBlockAllocator) {
Block_Allocator block_allocator;
u8 File_Data[File_Size];
}
else
u8 File_Data[File_Size];
}
else {
char Filename[Filename_Length];
bool HasBlockAllocator;
if (HasBlockAllocator) {
Block_Allocator block_allocator;
u8 File_Data[File_Size];
}
else
u8 File_Data[File_Size];
}
}
else
continue;
};
File file[while(!std::mem::eof())] @0x00;

View File

@@ -0,0 +1,64 @@
#pragma description Assassin's Creed: Unity's .forge archive file
#pragma author haru233
// many thanks to AxCut
// ImHex Hex Pattern File for Assassin's Creed: Unity's .forge files
import std.core;
struct Forge_Header {
char MAGIC[8];
padding[1];
u32 Version;
u32 File_Data_Header_Offset;
};
struct File_Data_Header {
u32 File_Count;
padding[32];
u64 File_Data_Header2_Offset;
};
struct File_Data_Header2 {
u32 File_Count2;
padding[4];
u64 File_Table_Offset;
padding[12];
u32 File_Count3;
u64 File_Name_Table_Offset;
padding[8];
};
struct File_Table {
u64 Raw_Data_Offset;
u64 File_ID;
u32 Raw_Data_Size;
};
struct File_Name_Table {
u32 Raw_Data_Size;
padding[40];
char Filename[128];
padding[20];
};
Forge_Header forge_header @0x00;
File_Data_Header file_data_header @(forge_header.File_Data_Header_Offset);
File_Data_Header2 file_data_header2 @(file_data_header.File_Data_Header2_Offset);
File_Table file_table[file_data_header.File_Count] @(file_data_header2.File_Table_Offset);
File_Name_Table file_name_table[file_data_header.File_Count] @(file_data_header2.File_Name_Table_Offset);
struct Raw_Data_Table {
u64 i = std::core::array_index();
u8 Raw_Data[file_table[i].Raw_Data_Size] @ file_table[i].Raw_Data_Offset;
};
Raw_Data_Table raw_data_table[file_data_header.File_Count] @0x00;

View File

@@ -1,5 +1,6 @@
#pragma author AdventureT
#pragma description Crash Bandicoot - Back in Time (fan game) User created level format
#pragma description Crash Bandicoot - Back in Time (fan game) User created level
#pragma magic [ 43 52 41 53 48 4C 56 4C ] @ 0x00
#pragma history
#pragma 0.3 2024-05-15 Added support for version 0.95
#pragma 0.2 2023-10-29 Added support for version 0.94c
@@ -353,7 +354,7 @@ struct Object {
u16 numOfMetafields;
u8 metafields[numOfMetafields];
}
}
}
else {
u32 x;
u32 y;

View File

@@ -0,0 +1,81 @@
ImHex Pattern Files - Digital Forensics:
- [ImHex-DFIR-Patterns](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns)
Enhanced features of the stock Disk/Filesystem pattern files for forensic review of disk content.
- [ImHex](https://github.com/WerWolv/ImHex)
- [ImHex Patterns](https://github.com/WerWolv/ImHex-Patterns)
Use:
- Open a physical disk via Raw Provider (read-only)
- EXAMPLE: /dev/disk6
- Import Pattern File
- EXAMPLE: DISK_PARSER.hexpat
- [Pattern_Selection (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/2-DISK_PARSER-Pattern.png)
- DISK_PARSER.hexpat
- Recognize MBR/GPT Disks and parse MPT/GPT
- Including Logical Volumes in an Extended Partition (container)
- Auto load file system patterns for FAT32, exFAT, NTFS formatted volumes
- Optional Disk Report
- [DISK > MBR/GPT (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/3-DISK-HYBRID.png)
- [DISK > MBR > MPT > 3 Primaries | 2 Logicals in an Extended (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/3a-DISK-MBR.png)
- FAT32.hexpat
- Auto loaded by DISK_PARSER.hexpat
- Parse VBR, FAT1, FAT2, Root Dir, and 1 level of SubDirs
- FAT1/FAT2 Cluster chaining with SFN resolution
- LFN/SFN Alias grouping in Root Dir
- Recognize deleted entries (xE5)
- File Content pointer
- D/T Conversions
- Optional FAT32 Volume Report
- [VOLUME > FAT32 > FAT1 (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/4-FAT32-1_SMALL_TXT.png)
- [VOLUME > FAT32 > Root Dir (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/5-FAT32_ROOT_DIR.png)
- [VOLUME > FAT32 > Data Pointer (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/6-FAT32_SFN_POINTER.png)
- exFAT.hexpat
- Auto loaded by DISK_PARSER.hexpat
- Parse VBR/Boot Sector/Extended Sectors, FAT1, Root Dir
- Recognize active directory entries (x85, xC0, xC1)
- Recognize inactive directory entries (x05, x40, x41)
- xC0/x40 File Content pointer
- D/T Conversions
- Optional exFAT Volume Report
- [VOLUME > exFAT (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/7-exFAT-1.png)
- [VOLUME > exFAT > Root Dir > xC0 (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/8-exFAT_xC0.png)
- [VOLUME > exFAT > Data Pointer (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/9-exFAT-Data_Pointer.png)
- NTFS.hexpat
- Auto loaded by DISK_PARSER.hexpat
- Parse VBR (Boot Sector), $MFT, Root Dir, and Indexes
- Recursively parse the $Metadata files, $Attributes, and user files/dirs
- Added file record | parent [MFT#] [SEQ#] indicators
- Parse x80/xB0 Data Runs
- File Content pointer
- D/T Conversions
- Optional NTFS Volume Report
- [VOLUME > NTFS > $MFT > D/T Conversion (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/10-NTFS-DT.png)
- [VOLUME > NTFS > $MFT > x80 Run List (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/11-NTFS-DATA_RUN.png)
- [VOLUME > NTFS > Data Pointer (screenshot)](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/screenshots/12-NTFS-DATA_POINTER.png)
- Optional Reports
- Simply copy the console output to a file...
- To enable/disable the reports:
- Open each DFIR related .hexpat
- Find the report constant (near the top)
- "true" = enabled
- "false" = disabled
Example Report: GPT > FAT32|exFAT
- [exFAT_Report](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/reports/exFAT_Report.txt)
Example Report: MBR > 5 Logical Volumes (2 in an Extended) > All FAT32 Volumes
- [MBR_5_VOLs](https://github.com/Xtreme-Liberty/ImHex-DFIR-Patterns/blob/main/reports/MBR_5_VOLs.txt)

View File

@@ -0,0 +1,677 @@
#pragma author Formula Zero One Technologies
#pragma description DFIR_DISK_PARSER_v2.0
#pragma MIME application/x-ima
#pragma endian little
// -----------------------------------------------------------------------------
// CREDIT
// -----------------------------------------------------------------------------
// Based on /fs/pattern.hexpat by WerWolv
// -----------------------------------------------------------------------------
// TODO
// -----------------------------------------------------------------------------
// Refine File System Detection/Match
// -----------------------------------------------------------------------------
// IMPORTS
// -----------------------------------------------------------------------------
import std.core;
import std.io;
import std.time;
import type.guid;
import type.magic;
import type.time;
import type.base;
import hex.provider;
// WORKING IMPORTS
import * from DFIR.FAT32 as FAT32Pat;
import * from DFIR.exFAT as EXFATPat;
import * from DFIR.NTFS as NTFSPat;
// ------------------------------------
// DISABLED IMPORTS
// REFS - UNTESTED
// EXT4 - GROUP DESC ERRORS
// APFS - PARTIALLY WORKS
// Comment out "using uuid_t = type::GUID"
// Replace all instances of "uuid_t" with "type::GUID"
// Comment out line 1456-EOF
// JPEG/PNG - OFFSET ERRORS
// ------------------------------------
//import * from fs.apfs as APFSPat;
//import * from fs.ext4 as EXT4Pat;
//import * from fs.refs as REFSPat;
//import * from jpeg as JPEGPat;
//import * from png as PNGPat;
// -----------------------------------------------------------------------------
// FWD DECs - GLOBAL
// -----------------------------------------------------------------------------
bool has_ext = false;
bool has_gpt = false;
u64 partitionOffset = 0;
u64 containerStartOffset = 0;
u32 mptIndex = 0;
u32 extIndex = 0;
str entryName = "";
u32 MPT_Count = 0;
u32 EXT_VolCount = 0;
u32 GPT_Count = 0;
u32 memory_size = std::mem::size();
str disk_path = hex::prv::get_information("file_path","");
u128 sector_size = hex::prv::get_information("sector_size","");
// -----------------------------------------------------------------------------
// REPORT HEADER ** ATTENTION **
// -----------------------------------------------------------------------------
// ---******---*******---vvvv--- |
const bool DISK_REPORT = true;
// ---******---*******---^^^^--- |
if (DISK_REPORT) {
std::print(" # # # # # # ");
std::print(" # # # ");
std::print(" # # # ");
std::print(" # # # # # # # ");
std::print(" I m H e x ");
std::print(" ");
std::print("-----------------------------------------");
std::print(" ");
std::print(" ENTITY: _____________________");
std::print(" ");
std::print("EXAMINER: _____________________");
std::print(" ");
u128 timestamp = std::time::epoch();
std::time::Time local_ts = std::time::to_local(timestamp);
std::time::Time utc_ts = std::time::to_utc(timestamp);
std::print("-----------------------------------------");
std::print(" LOCAL: {}",
std::format("{:02}/{:02}/{:04} @ {:02}:{:02}:{:02}",
local_ts.mon + 1,
local_ts.mday,
local_ts.year + 1900,
local_ts.hour,
local_ts.min,
local_ts.sec
));
std::print(" UTC: {}",
std::format("{:02}/{:02}/{:04} @ {:02}:{:02}:{:02}",
utc_ts.mon + 1,
utc_ts.mday,
utc_ts.year + 1900,
utc_ts.hour,
utc_ts.min,
utc_ts.sec
));
std::print("-----------------------------------------");
std::print(" ");
}
// -----------------------------------------------------------------------------
// SIGNATURE HELPER
// -----------------------------------------------------------------------------
enum MBRSignature : u16 {
MBR_SIG = 0xAA55 // 0x55AA -> Read LE
};
// -----------------------------------------------------------------------------
// CHS HELPER
// -----------------------------------------------------------------------------
bitfield CHS_Decoder {
head : 8;
sector : 6;
cylinder : 10;
} [[format("chs_formatter")]];
fn chs_formatter(CHS_Decoder CHS) {
return std::format("({:X}, {:X}, {:X}) | 0x{:X}", CHS.cylinder, CHS.head, CHS.sector, (CHS.cylinder * 16 + CHS.head) * 63 + (CHS.sector - 1));
};
// -----------------------------------------------------------------------------
// TIMESTAMP HELPER
// -----------------------------------------------------------------------------
struct DiskTimeStamp {
u8 seconds, minutes, hours;
};
// -----------------------------------------------------------------------------
// DISK PROTECTION HELPER
// -----------------------------------------------------------------------------
enum DiskProtection : u16 {
NotProtected = 0x0000,
CopyProtected = 0x5A5A
};
// -----------------------------------------------------------------------------
// PARTITION STATUS HELPER
// -----------------------------------------------------------------------------
enum PartitionStatus : u8 {
Not_Active = 0x00, // not_bootable
Active = 0x80 // bootable
};
enum MPTPartLabel : u8 {
UNUSED_OR_HIDDEN_ENTRY = 0x00,
PRIMARY = 0x07,
PRIMARY_F32_SMALL = 0x0B,
PRIMARY_0C_BIG = 0x0C,
EXTENDED_CONT_SMALL = 0x05,
EXTENDED_CONT_BIG = 0x0F,
LEGACY_MBR = 0xEE
};
// -----------------------------------------------------------------------------
// PARTITION TYPE HELPER
// -----------------------------------------------------------------------------
enum PartitionTypeCode : u8 {
UNUSED_ENTRY = 0x00,
FAT12_HDD = 0x01,
FAT12_HIDDEN = 0x11,
FAT16_SMALL = 0x04,
FAT16_SMALL_HIDDEN = 0x14,
FAT16_BIG = 0x06,
FAT16_BIG_HIDDEN = 0x16,
FAT32_SMALL = 0x0B,
FAT32_SMALL_HIDDEN = 0x1B,
FAT32_BIG = 0x0C,
FAT32_BIG_HIDDEN = 0x1C,
EXT_PART_SMALL = 0x05,
EXT_PART_SMALL_HIDDEN = 0x15,
EXT_PART_BIG = 0x0F,
EXT_PART_BIG_HIDDEN = 0x1F,
NTFS_EXFAT = 0x07,
NTFS_EXFAT_HIDDEN = 0x17,
WINDOWS_RECOVERY = 0x27,
NTFS_VOL_SET_1 = 0x86,
NTFS_VOL_SET_2 = 0x87,
macOSX = 0xA8,
OS2_HIDDEN_CDRIVE = 0x84,
LINUX_EXT = 0x83,
LINUX_EXT2 = 0x85,
LINUX_LVM = 0x8E,
LINUX_PA_RISC = 0xF0,
LINUX_RAID = 0xFD,
FREE_BSD = 0xA5,
OPEN_BSD = 0xA6,
QNX_1 = 0x4D,
QNX_2 = 0x4E,
QNX_3 = 0x4F,
GPT_DISK_STD = 0xEE,
GPT_DISK_SYS = 0xEF,
UNKNOWN = 0xFF,
};
// -----------------------------------------------------------------------------
// GUID PARTITION TABLE (GPT) PARTIONING SCHEME RELATED
// -----------------------------------------------------------------------------
// V V V V V V V V V V
// -----------------------------------------------------------------------------
// GPT PARTITION LABEL HELPER
// -----------------------------------------------------------------------------
enum GUIDPartLabel : u128 {
// ---------------- COMMON ----------------
UNUSED_ENTRY = 0x00000000000000000000000000000000,
EFI_SYSTEM_PART = 0x3BC93EC9A0004BBA11D2F81FC12A7328,
APPLE_APFS_CONT = 0xACEC4365300011AA11AA00007C3457EF,
APPLE_HFS_PLUS_PART = 0xACEC4365300011AA11AA000048465300,
MICROSOFT_RESERVED_PART = 0xAE1502F92DF97D81B84D5C0BE3E3C9E3,
WINDOWS_REC_ENVIRONMENT = 0xACD67901D5BF6AA1404DD106A4BB94DE,
BASIC_DATA_PART = 0xC79926B7B668C0874433B9E5EBD0A0A2,
// ---------------- LINUX ----------------
LINUX_FILE_SYSTEM = 0xE47D47D8693D798E477284830FC63DAF,
RAID_PART = 0x1E91840F3F7406A04D3B05FCA19D880F,
ROOT_PART_X86 = 0x8A45F0D531D1F79A41B2F29744479540,
ROOT_PART_X86_64 = 0x09B784F9CAFBE7964DB1E8CD4F68BCE3,
ROOT_PART_ARM = 0xD3BE9AD4A1216CB14E3C2CE469DAD710,
ROOT_PART_ARM_64 = 0xAE3F0D286F4C44AF41C31DF0B921B045,
BOOT_PART = 0x72716FFD75B252A3426259E6BC13C2FF,
SWAP_PART = 0x4F4F4BC83309E58443C4A4AB0657FD6D,
LOGICAL_VOLUME_MGR_PART = 0x28F93D2A8F233CA244C2F507E6D6D379,
HOME_PART = 0x15F9AEE2140E44B84F132EB4933AC7E1,
SRV_SERVER_DATA_PART = 0xE8986FA7251A7F904F3B20E03B8F8425,
PLAIN_DMCRYPT_PART = 0xB786550AA13E418949B72D007FFEC5C9,
LUKS_PART = 0xCC59605342171C864C5363EDCA7D7CCB,
// ---------------- APPLE ----------------
APPLE_UFS_CONT = 0xACEC4365300011AA11AA000055465300,
APPLE_ZFS = 0x316673200008A69911B21DD26A898CC3,
APPLE_RAID_PART = 0xACEC4365300011AA11AA000052414944,
APPLE_RAID_PART_OFFLINE = 0xACEC4365300011AA11AA5F4F52414944,
APPLE_BOOT_PART_REC_HD = 0xACEC4365300011AA11AA0000426F6F74,
APPLE_LABEL = 0xACEC4365300011AA11AA6C004C616265,
APPLE_TV_RECOVERY_PART = 0xACEC4365300011AA11AA76655265636F,
APPLE_CORE_STORAGE_CONT = 0xACEC4365300011AA11AA616753746F72,
HFS_FILEVAULT_VOLUME_CONT = 0xACEC4365300011AA11AA616753746F72,
APPLE_APFS_PREBOOT_PART = 0xACEC4365300011AA11AA006769646961,
APPLE_APFS_RECOVERY_PART = 0xACEC4365300011AA11AA007972637652,
// ---------------- WINDOWS ----------------
LOGICAL_DISK_MGR_META_PART = 0xB3CF34E104E1D28542E08F7EAAC80858,
LOGICAL_DISK_MGR_DATA_PART = 0xAD694A71113368BC4F621431A0609BAF,
IBM_GENERAL_PARALLEL_FILE_SYS_PART = 0x74B155E07A2DC3914E4EEF7D90FFAA37,
STORAGE_SPACES_PART = 0x2DECF6E501B0A3AFEE4CF6808FAF5CE7,
STORAGE_REPLICA_PART = 0xD123292BD147C8AAC043A1ACC58D4355,
};
// -----------------------------------------------------------------------------
// BASIC DATA PARTITION ATTRIBUTES
// -----------------------------------------------------------------------------
bitfield GPT_BDP_Attributes {
bool platform_required : 1 [[comment("Bit 0: RequiredPartition - Volume must be preserved")]];
bool io_ignore : 1 [[comment("Bit 1: NoBlockIOProtocol - EFI ignores this Volume, no FS Mapping")]];
bool legacy_flag : 1 [[comment("Bit 2: LegacyBIOSBootable - Active/Bootable under BIOS")]];
reserved_UEFI : 45 [[comment("Bits 347: Reserved for UEFI")]];
reserved_MS : 12 [[comment("Bits 4859: Reserved for Microsoft")]];
bool read_only : 1 [[comment("Bit 60: BasicDataPart - Read-Only Volume")]];
bool shadow_copy : 1 [[comment("Bit 61: BasicDataPart - Shadow Copy Volume")]];
bool hidden : 1 [[comment("Bit 62: BasicDataPart - Hidden Volume")]];
bool no_drive_letter : 1 [[comment("Bit 63: BasicDataPart - Do not Auto-Assign Drive Letter")]];
} [[bitfield_order(
std::core::BitfieldOrder::LeastToMostSignificant, 64)]];
// -----------------------------------------------------------------------------
// GPT ENTRIES PARSER
// LBA2-LBA33
// EACH ENTRY IS 128 BYTES (DESCRIBES A VOLUME)
// -----------------------------------------------------------------------------
union PartitionUnion {
le type::GUID PartTypeGUID; // HUMAN READABLE GUID
GUIDPartLabel PartTypeLabel [[name(std::format("PartTypeLabel (DERIVED)"))]]; // OBJECT LABEL
};
struct GPT_PartitionEntry {
PartitionUnion Type [[comment("Known Partition Type GUID: Global Identifier")]];
le type::GUID Unique_GUID [[comment("Unique Partition GUID: Every Volume has its own Unique GUID")]];
u64 Start_LBA [[comment("The first Sector of the Volume (Offset by 1)")]];
u64 End_LBA [[comment("The last Sector of the Volume (Offset by 1)")]];
GPT_BDP_Attributes ATTR [[comment("ATTRs for a Basic Data Partition may not be the same as a Microsoft Reserved Partition")]];
char16 PartName[36] [[comment("Partition Name: Based on Known Partition Type GUID, except for Disk Images")]];
if (Type.PartTypeLabel != GUIDPartLabel::UNUSED_ENTRY) {
GPT_Count += 1;
}
u64 GPTpartitionOffset = Start_LBA * sector_size
[[name(std::format("VOL_OFFSET {} | 0x{:02X} (DERIVED)", Start_LBA * sector_size, Start_LBA * sector_size)),
export]];
match (Type.PartTypeLabel) {
(GUIDPartLabel::UNUSED_ENTRY):
continue;
(GUIDPartLabel::EFI_SYSTEM_PART):
FAT32Pat EFI_SYS_VOL @ GPTpartitionOffset;
(GUIDPartLabel::BASIC_DATA_PART |
GUIDPartLabel::WINDOWS_REC_ENVIRONMENT): {
char gpt_fat32_magic[8] @ GPTpartitionOffset + 82 [[hidden]];
char gpt_ntfs_magic[8] @ GPTpartitionOffset + 3 [[hidden]];
char gpt_exfat_magic[8] @ GPTpartitionOffset + 3 [[hidden]];
if (gpt_fat32_magic == "FAT32 ")
FAT32Pat FAT32_VOL @ GPTpartitionOffset;
if (gpt_ntfs_magic == "NTFS ")
NTFSPat NTFS_VOL @ GPTpartitionOffset;
else if (gpt_exfat_magic == "EXFAT ")
EXFATPat EXFAT_VOL @ GPTpartitionOffset;
}
// --------- DISABLED -----------------
// EXT4 PATTERN WAS INOP WHEN TESTED
//(GUIDPartLabel::LINUX_FILE_SYSTEM):
//EXT4Pat EXT4_VOL @ GPTpartitionOffset;
//(GUIDPartLabel::APPLE_APFS_CONT):
// APFSPat APFS_VOL @ GPTpartitionOffset;
}
} [[name(std::format("GPT_ENTRY [{}]", std::core::array_index()))]];
// -----------------------------------------------------------------------------
// GPT HEADER PARSER
// LBA1 OFFSETS 0-91 (92 bytes of 512 bytes used)
// -----------------------------------------------------------------------------
struct GPT_Header {
type::Magic<"EFI PART"> signature [[comment("Signature (EFI PART)")]];
u32 revision [[comment("Header Revision Value")]];
u32 header_size [[comment("Size of Header - 92 Bytes")]];
type::Hex<u32> header_crc32 [[comment("GPT Header Checksum")]];
u32 reserved [[comment("Zeros")]];
u64 current_lba [[comment("Current LBA - GPT Header Location")]];
u64 backup_lba [[comment("Location of Backup - Header & GPT")]];
u64 first_usable_lba [[comment("1st Sector Available for Logical VOL")]];
u64 last_usable_lba [[comment("Last Sector Available for Logical VOL")]];
type::GUID disk_guid [[comment("Unique Disk GUID")]];
u64 partition_entries_lba [[comment("1st Sector of GPT")]];
u32 num_partition_entries [[comment("Total Number of Partition Entries Available - 128 on Windows")]];
u32 size_of_partition_entry [[comment("Size in Bytes of each GPT Entry")]];
type::Hex<u32> partition_entries_crc32 [[comment("GPT Array Checksum")]];
};
// -----------------------------------------------------------------------------
// MASTER BOOT RECORD (MBR) PARTIONING SCHEME RELATED
// -----------------------------------------------------------------------------
// V V V V V V V V V V
// -----------------------------------------------------------------------------
// MASTER PARTITION TABLE (MPT)
// LBA0 > 0FFSETS 446-509
// Each Entry Describes a Logical Volume (type/start_loc/size)
// -----------------------------------------------------------------------------
union MBRPartitionUnion {
PartitionTypeCode Part_Type;
MPTPartLabel PartTypeLabel; // overlay for 0x00
};
struct PartitionTableEntry {
// partition table fields
PartitionStatus ActiveFlag;
CHS_Decoder Starting_CHS;
MBRPartitionUnion Type;
CHS_Decoder Ending_CHS;
u32 Start_LBA;
u32 Total_Sectors;
if (Type.PartTypeLabel != MPTPartLabel::UNUSED_OR_HIDDEN_ENTRY) {
// Track Count of Logical Volumes in the Extended Container
//MPT_Count += 1;
if (containerStartOffset == 0) {
// top-level MBR entry
MPT_Count = MPT_Count + 1;
} else {
// a logical inside an extended container
EXT_VolCount = EXT_VolCount + 1;
}
}
partitionOffset = containerStartOffset + (Start_LBA * sector_size);
match (Type.PartTypeLabel) {
(PartitionTypeCode::UNUSED_ENTRY): continue;
(PartitionTypeCode::FAT32_SMALL | PartitionTypeCode::FAT32_BIG): {
FAT32Pat FAT32_VOL @ partitionOffset;
}
(PartitionTypeCode::NTFS_EXFAT): {
char magic[8] @ partitionOffset + 3;
if (magic == "NTFS ")
NTFSPat NTFS_VOL @ partitionOffset;
else
EXFATPat EXFAT_VOL @ partitionOffset;
}
(PartitionTypeCode::EXT_PART_SMALL | PartitionTypeCode::EXT_PART_BIG): {
// Save parent state
bool parent_has_ext = has_ext;
has_ext = true;
containerStartOffset = partitionOffset;
// Parse first two entries of the extended partition
PartitionTableEntry EXTENDED_PARTITION[2] @ partitionOffset + 446;
has_ext = parent_has_ext;
}
(PartitionTypeCode::GPT_DISK_STD | PartitionTypeCode::GPT_DISK_SYS):
// Set global flag
has_gpt = true;
}
if (!has_ext) {
entryName = std::format("MPT_ENTRY [{}]", mptIndex);
mptIndex += 1;
} else {
if (std::core::array_index() <= 0) {
entryName = std::format("LOGICAL_VOL (EXT) [{}]", extIndex);
} else if (std::core::array_index() == 1) {
entryName = "NEXT VOL POINTER (EXT)";
} else {
entryName = std::format("LOGICAL_VOL (EXT) [{}]", extIndex);
}
extIndex += 1;
}
} [[name(entryName)]];
// -----------------------------------------------------------------------------
// MBR PARSER
// LBA0 > OFFSETS 0-511 (512 bytes)
// -----------------------------------------------------------------------------
struct MasterBootRecord {
u8 bootstrapCodeArea1[218] [[comment("Boot Strapping Code")]];
padding[2] [[comment("Zeros")]];
u8 originalPhysicalDrive [[comment("???")]];
DiskTimeStamp diskTimeStamp [[comment("Timestamp of Disk OG Partitioning")]];
u8 bootstrapCodeArea2[216] [[comment("Boot Strapping Code")]];
u32 diskSignature [[comment("Disk Signature")]];
DiskProtection diskProtection [[comment("Disk Protection - 0x0000=Not | 0x5A5A=Prot")]];
PartitionTableEntry PT[4] [[comment("Master Partition Table (MPT) Offset 446-509")]];
MBRSignature MBR_SIG [[comment("End of MBR - 0x55AA")]];
};
// -----------------------------------------------------------------------------
// DISK PARSER
// -----------------------------------------------------------------------------
struct DiskRoot {
// Master Boot Record at LBA 0 (1st physical sector)
MasterBootRecord MBR @ 0x00;
if (has_gpt) {
// GPT Header at LBA 1 (2nd physical sector)
GPT_Header GPT_HEADER @ 0x200;
// The GPT (table) at LBA 2 (3rd physical sector) to LBA 33 (34th physical sector)
// 32 sectors total (Windows) that can define up to 128 - (primary) logical volumes
GPT_PartitionEntry GPT_ENTRIES[GPT_HEADER.num_partition_entries] @ (GPT_HEADER.partition_entries_lba * 512);
}
};
// -----------------------------------------------------------------------------
// ROOT OBJECT
// -----------------------------------------------------------------------------
// ---
DiskRoot DISK @ 0x0;
// ---
// ------------------------------
// DISK REPORT
// ------------------------------
if (DISK_REPORT) {
std::print("-----------------------------------------");
std::print("-------------- DISK_REPORT --------------");
std::print("-----------------------------------------");
// Disk Basics
std::print("DISK_PATH = {}", disk_path);
std::print("SECTOR_SIZE = {} BYTES", sector_size);
std::print("DISK_SIZE = {} SECTORS", memory_size / sector_size);
std::print("DISK_SIZE = {:.4f} GB @ 1000", memory_size / 1000.0 / 1000.0 / 1000.0);
std::print("DISK_SIZE = {:.4f} GiB @ 1024", memory_size / 1024.0 / 1024.0 / 1024.0);
// Disk Protection
str diskProtectionStr;
if (DISK.MBR.diskProtection == DiskProtection::NotProtected) {
diskProtectionStr = "NOT_COPY_PROTECTED";
} else if (DISK.MBR.diskProtection == DiskProtection::CopyProtected) {
diskProtectionStr = "COPY_PROTECTED";
} else {
diskProtectionStr = "UNKNOWN";
}
std::print("DISK_PROTECT = {}", diskProtectionStr);
// Partition Scheme
if (MPT_Count >= 1 && GPT_Count == 0) {
std::print("PART_SCHEME = MBR");
} else if (GPT_Count >= 1 && MPT_Count == 0) {
std::print("PART_SCHEME = GPT");
} else if (GPT_Count >= 1 && MPT_Count >= 1) {
std::print("PART_SCHEME = HYBRID (MBR + GPT)");
} else {
std::print("PART_SCHEME = UNKNOWN");
}
// MBR MPT Partitions
for (u32 i = 0, i < MPT_Count, i = i + 1) {
std::print("-----------------------------------------");
std::print("-------------- MBR_MPT [{}] --------------", i);
std::print("-----------------------------------------");
// STATUS
str statusStr;
if (DISK.MBR.PT[i].ActiveFlag == PartitionStatus::Active) {
statusStr = "ACTIVE/BOOTABLE";
} else if (DISK.MBR.PT[i].ActiveFlag == PartitionStatus::Not_Active) {
statusStr = "INACTIVE/NOT_BOOTABLE";
} else {
statusStr = "UNKNOWN";
}
std::print(" STATUS = {}", statusStr);
// TYPE_CODE
str typeStr;
if (DISK.MBR.PT[i].Type.Part_Type == PartitionTypeCode::FAT32_SMALL) {
typeStr = "FAT32 (CHS) (0x0B)";
} else if (DISK.MBR.PT[i].Type.Part_Type == PartitionTypeCode::FAT32_BIG) {
typeStr = "FAT32 (LBA) (0x0C)";
} else if (DISK.MBR.PT[i].Type.Part_Type == PartitionTypeCode::NTFS_EXFAT) {
typeStr = "NTFS/EXFAT (0x07)";
} else if (DISK.MBR.PT[i].Type.Part_Type == PartitionTypeCode::GPT_DISK_STD) {
typeStr = "GPT_PROTECTIVE (0xEE)";
} else if (DISK.MBR.PT[i].Type.Part_Type == PartitionTypeCode::EXT_PART_BIG) {
typeStr = "EXTENDED (0x0F)";
} else {
typeStr = "OTHER/UNKNOWN";
}
std::print(" TYPE_CODE = {}", typeStr);
// LBA and size
std::print(" FIRST_LBA = {:02}", DISK.MBR.PT[i].Start_LBA);
std::print(" LAST_LBA = {:02}", DISK.MBR.PT[i].Start_LBA + DISK.MBR.PT[i].Total_Sectors - 1);
std::print(" VOL_SIZE = {:02} SECTORS", DISK.MBR.PT[i].Total_Sectors);
std::print(" VOL_SIZE = {:.4f} GB", (DISK.MBR.PT[i].Total_Sectors * sector_size) / 1000.0 / 1000.0 / 1000.0);
std::print(" VOL_SIZE = {:.4f} GiB", (DISK.MBR.PT[i].Total_Sectors * sector_size) / 1024.0 / 1024.0 / 1024.0);
if (DISK.MBR.PT[i].Type.PartTypeLabel == MPTPartLabel::EXTENDED_CONT_SMALL ||
DISK.MBR.PT[i].Type.PartTypeLabel == MPTPartLabel::EXTENDED_CONT_BIG) {
u32 logicalCount = std::core::member_count(DISK.MBR.PT[i].EXTENDED_PARTITION);
//u32 logicalCount = std::mem::size(DISK.MBR.PT[i].EXTENDED_PARTITION);
for (u32 e = 0, e < logicalCount, e = e + 1) {
if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.PartTypeLabel == MPTPartLabel::UNUSED_OR_HIDDEN_ENTRY)
continue;
std::print("-----------------------------------------");
std::print("---------- LOGICAL (EXT) [{}] ------------", e);
std::print("-----------------------------------------");
// STATUS
str EXTstatusStr;
if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].ActiveFlag == PartitionStatus::Active) {
EXTstatusStr = "ACTIVE/BOOTABLE";
} else if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].ActiveFlag == PartitionStatus::Not_Active) {
EXTstatusStr = "INACTIVE/NOT_BOOTABLE";
} else {
EXTstatusStr = "UNKNOWN";
}
std::print(" STATUS = {}", EXTstatusStr);
// TYPE_CODE
str EXTtypeStr;
if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.Part_Type == PartitionTypeCode::FAT32_SMALL) {
EXTtypeStr = "FAT32 (CHS) (0x0B)";
} else if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.Part_Type == PartitionTypeCode::FAT32_BIG) {
EXTtypeStr = "FAT32 (LBA) (0x0C)";
} else if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.Part_Type == PartitionTypeCode::NTFS_EXFAT) {
EXTtypeStr = "NTFS/EXFAT (0x07)";
} else if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.Part_Type == PartitionTypeCode::GPT_DISK_STD) {
EXTtypeStr = "GPT_PROTECTIVE (0xEE)";
} else if (DISK.MBR.PT[i].EXTENDED_PARTITION[e].Type.Part_Type == PartitionTypeCode::EXT_PART_BIG) {
EXTtypeStr = "EXTENDED (0x0F)";
} else {
EXTtypeStr = "OTHER/UNKNOWN";
}
std::print(" TYPE_CODE = {}", EXTtypeStr);
std::print(" FIRST_LBA = {}", DISK.MBR.PT[i].EXTENDED_PARTITION[e].Start_LBA);
std::print(" LAST_LBA = {}", DISK.MBR.PT[i].EXTENDED_PARTITION[e].Start_LBA +
DISK.MBR.PT[i].EXTENDED_PARTITION[e].Total_Sectors - 1);
std::print(" VOL_SIZE = {} SECTORS", DISK.MBR.PT[i].EXTENDED_PARTITION[e].Total_Sectors);
std::print(" VOL_SIZE = {:.4f} GB",
(DISK.MBR.PT[i].EXTENDED_PARTITION[e].Total_Sectors * sector_size) / 1000.0 / 1000.0 / 1000.0);
std::print(" VOL_SIZE = {:.4f} GiB",
(DISK.MBR.PT[i].EXTENDED_PARTITION[e].Total_Sectors * sector_size) / 1024.0 / 1024.0 / 1024.0);
}
}
}
// GPT Header
if (GPT_Count >= 1) {
std::print("-----------------------------------------");
std::print("-------------- GPT_HEADER ---------------");
std::print("-----------------------------------------");
std::print("SIGNATURE = {}", DISK.GPT_HEADER.signature);
std::print("REVISION = 0x{:02X}", DISK.GPT_HEADER.revision);
std::print("GPT_HDR_CRC = 0x{:02X}", DISK.GPT_HEADER.header_crc32);
std::print("GPT_HDR_BACKUP_LBA = {}", DISK.GPT_HEADER.backup_lba);
std::print("DISK_GUID = {}", DISK.GPT_HEADER.disk_guid);
std::print("FIRST_USABLE_LBA = {}", DISK.GPT_HEADER.first_usable_lba);
std::print("LAST_USABLE_LBA = {}", DISK.GPT_HEADER.last_usable_lba);
std::print("MAX_GPT_ENTRIES = {:02}", DISK.GPT_HEADER.num_partition_entries);
std::print("GPT_ENTRY_SIZE = {:02} BYTES", DISK.GPT_HEADER.size_of_partition_entry);
std::print("GPT_ARRAY_CRC = 0x{:02X}", DISK.GPT_HEADER.partition_entries_crc32);
// GPT Partitions
for (u32 j = 0, j < GPT_Count, j = j + 1) {
std::print("-----------------------------------------");
std::print("------------- GPT_PART [{}] --------------", j);
std::print("-----------------------------------------");
std::print(" PART_TYPE_LABEL = {}", DISK.GPT_ENTRIES[j].Type.PartTypeLabel);
std::print(" PART_TYPE_GUID = {}", DISK.GPT_ENTRIES[j].Type.PartTypeGUID);
std::print(" UNIQUE_PART_GUID = {}", DISK.GPT_ENTRIES[j].Unique_GUID);
std::print(" FIRST_LBA = {:02}", DISK.GPT_ENTRIES[j].Start_LBA);
std::print(" LAST_LBA = {:02}", DISK.GPT_ENTRIES[j].End_LBA);
bool _any = false;
std::print(" ATTR_FLAGS |");
if(DISK.GPT_ENTRIES[j].ATTR.platform_required) {
std::print(" |- - - - > PlatformRequired");
_any = true;
}
if(DISK.GPT_ENTRIES[j].ATTR.io_ignore) {
std::print(" |- - - - > NO_FS_MAP");
_any = true;
}
if(DISK.GPT_ENTRIES[j].ATTR.legacy_flag) {
std::print(" |- - - - > LEGACY_BOOT");
_any = true;
}
if(DISK.GPT_ENTRIES[j].Type.PartTypeLabel == GUIDPartLabel::BASIC_DATA_PART) {
if(DISK.GPT_ENTRIES[j].ATTR.read_only) {
std::print(" |- - - - > READ_ONLY");
_any = true;
}
if(DISK.GPT_ENTRIES[j].ATTR.shadow_copy) {
std::print(" |- - - - > SHADOW_COPY");
_any = true;
}
if(DISK.GPT_ENTRIES[j].ATTR.hidden) {
std::print(" |- - - - > HIDDEN");
_any = true;
}
if(DISK.GPT_ENTRIES[j].ATTR.no_drive_letter) {
std::print(" |- - - - > NO_AUTO_MOUNT");
_any = true;
}
}
// if nothing was printed, say "NONE"
if (!_any) {
//std::print(" |> NONE");
std::print(" |- - - - > NONE");
}
std::print(" PART_TYPE_NAME = {}", DISK.GPT_ENTRIES[j].PartName);
}
}
std::print("-----------------------------------------");
std::print("------------------ END ------------------");
std::print("-----------------------------------------");
std::print(" ");
}

789
patterns/DFIR/FAT32.hexpat Normal file
View File

@@ -0,0 +1,789 @@
#pragma author Formula Zero One Technologies
#pragma description FAT32 File System (FAT32_v2.0)
#pragma MIME application/x-ima
#pragma endian little
// -----------------------------------------------------------------------------
// CREDIT
// -----------------------------------------------------------------------------
// OG AUTHOR: WerWolv
// OG DESC: fs/fat32.hexpat_v1.0
// -----------------------------------------------------------------------------
// NOTES FOR v2.0 ** GLOBALS NEED YOUR INPUT **
// -----------------------------------------------------------------------------
// Imported by DISK_PARSER.hexpat
// Added section separators for organization
// Added recursive parsing for Root Dir and a next level
// Added D/T conversions
// Show filenames on hover
// Added comments to DFIR fields of interest
// Changed pattern output naming/structure.
// Parse FAT1/FAT2
// Show SFN <-> Starting Cluster Relation Overlay
// -----------------------------------------------------------------------------
// TODO
// -----------------------------------------------------------------------------
// Parse all SFN/LFN entries, not just Root + 1
// -----------------------------------------------------------------------------
// IMPORTS
// -----------------------------------------------------------------------------
import std.core;
import std.io;
import std.mem;
import std.time;
import std.string;
import type.time;
// -----------------------------------------------------------------------------
// FORWARD DECS/GLOBALS
// -----------------------------------------------------------------------------
// *** ATTENTION ***
// SET MAXIMUM NUMBER OF 4 BYTE CHUNKS TO PARSE FROM FAT1
// DEFAULT IS 4096
// Choose a value greater than 1 and less than 65536 OR increase the Array size limit with "#define... "
// -------**************---vvvv--- |
const u64 MAX_FAT_CHUNKS = 4096;
// -------**************---^^^^--- |
// *** ATTENTION ***
// SET MAXIMUM NUMBER OF SFN = STARTING CLUSTER TO PROCESS
// DEFAULT IS 100 (2 LEVELS DEEP | ROOT DIR + 1)
// Choose a value greater than 1 and less than 65536 OR increase the Array size limit with "#define... "
// ---**************---************---vvv--- |
const u64 MAX_SFN_CLUSTER_RELATIONS = 100;
// ---**************---************---^^^--- |
// ---*******---*******----vvvv--- |
const bool VOLUME_REPORT = true;
// ---*******---*******----^^^^--- |
u64 bytesPerCluster = 0;
u64 rootDirSectors = 0;
u64 firstDataSector = 0;
u64 dataRegionStart = 0;
u64 sfn_count = 0;
u64 sfn_del_count = 0;
u64 lfn_count = 0;
u64 lfn_del_count = 0;
u64 start_index = 0;
u64 root_dir_start = 0;
u64 allocated_file_count = 0;
u64 VBR_OFFSET = 0;
u64 FAT1_start_offset = 0;
u64 FAT2_start_offset = 0;
u64 FAT_ClusterHeap_Count = 0;
u64 abs_FAT1_start_offset = 0;
u64 abs_FAT2_start_offset = 0;
u64 abs_rootDirStart_offset = 0;
// -----------------------------------------------------------------------------
// FILE ALLOCATION TABLE RELATED
// -----------------------------------------------------------------------------
// V V V V V V V V V V
// -----------------------------------------------------------------------------
// ------------------------------
// SFN <-> CLUSTER OVERLAY
// ------------------------------
struct INFO_Overlay {
u64 index = std::core::array_index();
u64 start_location = FAT1_start_offset + 8 + (index * 4);
u32 current_cluster = 2 + index;
str filename = overlay_func_name(current_cluster);
if (filename != "") {
char hover_label[4] @ start_location [[
name(std::format(
"SFN: {} | CLUSTER {}",
filename,
current_cluster
))]];
}
} [[inline]];
fn overlay_func_name(u32 cluster_num) {
str fname = "";
str ext = "";
str combo = "";
// Loop through all ROOT_DIR_ENTRIES
for (u32 i = 0, i < std::core::member_count(ROOT_DIR_ENTRIES), i = i + 1) {
// Check SFN_ALIAS and SFN_ENTRY in root entries
if (std::core::has_member(ROOT_DIR_ENTRIES[i], "SFN_ALIAS")) {
if (ROOT_DIR_ENTRIES[i].SFN_ALIAS.first_cluster == cluster_num) {
combo = std::format("{}.{}",
ROOT_DIR_ENTRIES[i].SFN_ALIAS.fileName,
ROOT_DIR_ENTRIES[i].SFN_ALIAS.extension);
return combo;
}
} else if (std::core::has_member(ROOT_DIR_ENTRIES[i], "SFN_ENTRY")) {
if (ROOT_DIR_ENTRIES[i].SFN_ENTRY.first_cluster == cluster_num) {
combo = std::format("{}.{}",
ROOT_DIR_ENTRIES[i].SFN_ENTRY.fileName,
ROOT_DIR_ENTRIES[i].SFN_ENTRY.extension);
return combo;
}
}
// Loop through all SUB_DIR_INDEX arrays for this root entry
if (std::core::has_member(ROOT_DIR_ENTRIES[i], "SUB_DIR_INDEX")) {
for (u32 j = 0, j < std::core::member_count(ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX), j = j + 1) {
if (std::core::has_member(ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j], "SFN_ALIAS")) {
if (ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ALIAS.first_cluster == cluster_num) {
combo = std::format("{}.{}",
ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ALIAS.fileName,
ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ALIAS.extension);
return combo;
}
} else if (std::core::has_member(ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j], "SFN_ENTRY")) {
if (ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ENTRY.first_cluster == cluster_num) {
combo = std::format("{}.{}",
ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ENTRY.fileName,
ROOT_DIR_ENTRIES[i].SUB_DIR_INDEX[j].SFN_ENTRY.extension);
return combo;
}
}
}
}
}
return ""; // no match found
};
// -----------------------------------------------------------------------------
// FAT32 FILE ALLOCATION TABLE (FAT) PARSER
// -----------------------------------------------------------------------------
const u32 CLUSTER_SIZE_BYTES = 4; // Each FAT32 entry = 4 bytes
const u32 FAT32_EOF = 0x0FFFFFFF; // End-of-file marker
const u32 FAT32_BAD = 0x0FFFFFF7; // Bad cluster marker
const u32 FIRST_ALLOC_CLUSTER = 2; // First usable cluster after reserved
enum FAT_Flags : u32 {
UNALLOCATED = 0x00000000,
END_OF_FILE = 0x0FFFFFFF, // L.END
BAD_CLUSTER = 0xFFFFFFF7, // L.END
//POINTER = Num >= 1 // INFO
};
union FAT_Union {
u32 DECIMAL [[hidden]];
FAT_Flags FAT_FLAG;
};
// ------------------------------
// Helper function for pointer label
// ------------------------------
fn cluster_label(u32 val) {
if (val == FAT_Flags::UNALLOCATED)
return "UNALLOCATED";
if (val == FAT_Flags::BAD_CLUSTER)
return "BAD";
if (val >= 0x0FFFFFF8)
return "EOF";
return std::format("{}", val);
};
// ------------------------------
// FAT1/FAT2 HEAPS/CHAINS
// ------------------------------
struct FAT_Entry {
FAT_Union FAT [[inline]];
u32 cluster_num = (FIRST_ALLOC_CLUSTER) + (std::core::array_index());
u32 next_cluster = FAT.DECIMAL & 0x0FFFFFFF;
char hover_label[4] @ $ - 4 [[
name(std::format(
"Cluster: {} → {}",
cluster_num,
cluster_label(next_cluster)
))
]];
bool is_eof = next_cluster >= 0x0FFFFFF8;
bool is_bad = next_cluster == FAT32_BAD;
bool is_free = next_cluster == 0;
if (is_eof) {
allocated_file_count += 1;
}
} [[name(format_fat_entry(FAT.DECIMAL, std::core::array_index(), FIRST_ALLOC_CLUSTER))]];
// ------------------------------
// FAT FORMATTER FUNC
// ------------------------------
fn format_fat_entry(u32 raw_value, u32 cluster_index, u32 first_alloc_cluster) {
u32 next_cluster = raw_value & 0x0FFFFFFF;
str next_label;
if (next_cluster == 0)
next_label = "UNALLOCATED";
else if (next_cluster == FAT32_BAD)
next_label = "BAD";
else if (next_cluster == 0x0FFFFFFF)
next_label = "EOF";
else
next_label = std::format("{}", next_cluster);
u32 logical_cluster = first_alloc_cluster + cluster_index;
if (next_label == "UNALLOCATED" || next_label == "BAD" || next_label == "EOF")
return std::format("Cluster {}: {}", logical_cluster, next_label);
else
return std::format("Cluster {} → {}", logical_cluster, next_label);
};
// ------------------------------
// MEDIA DESCRIPTOR HELPER
// ------------------------------
enum Media_Descriptor : u8 {
SINGLE_SIDE_FLOPPY = 0xF0,
DOUBLE_SIDE_FLOPPY = 0xF9,
HARD_DISK_DRIVE = 0xF8,
};
// ------------------------------
// FAT1/FAT2 HEADER PARSER
// ------------------------------
struct FAT_Header {
Media_Descriptor mediaDescriptor [[comment("0xF8=FIXED DISK | 0xF0=REMOVABLE")]];;
u8 FAT32_FAT_HEADER[7] [[comment("8 BYTES TOTAL: 4 BYTES REPRESENT PSUEDO CLUSTER 0 (SYSTEM) | 4 BYTES REPRESENT PSUEDO CLUSTER 1 (SYSTEM)(EOF)")]];
char root_dir_label[4] @ $ [[
name(std::format(
"ROOT_DIRECTORY"
))
]];
// WHICH IS WHY THE ROOT DIRECTORY (FIRST DATA AREA ITEM) STARTS IN CLUSTER 2
};
// -----------------------------------------------------------------------------
// ROOT DIRECTORY RELATED
// -----------------------------------------------------------------------------
// V V V V V V V V V V
// -----------------------------------------------------------------------------
// ------------------------------
// ACTIVE LFN SEQUENCE NUMBER BITFIELD
// * EXCEPT DELETED ENTRIES - 0xE5 *
// ------------------------------
bitfield LFN_Sequence {
padding : 1;
IS_LAST_ENTRY : 1 [[name("IS_LAST_ENTRY: [0=NO | 1=YES] ==")]];
padding : 1;
LFN_SEQ_NUM : 5;
} [[bitfield_order(
std::core::BitfieldOrder::MostToLeastSignificant, 8)]];
// ------------------------------
// DIRECTORY ENTRY STATUS/SEQUENCE HELPERS
// ------------------------------
enum Entry_Status : u8 {
EMPTY_ENTRY = 0x00,
DOT_ENTRY = 0x2E,
DELETED_ENTRY = 0xE5,
ACTIVE_1ST_ENTRY = 0x01,
ACTIVE_2ND_ENTRY = 0x02,
ACTIVE_3RD_ENTRY = 0x03,
ACTIVE_4TH_ENTRY = 0x04,
ACTIVE_5TH_ENTRY = 0x05,
ACTIVE_6TH_ENTRY = 0x06,
ACTIVE_7TH_ENTRY = 0x07,
ACTIVE_8TH_ENTRY = 0x08,
ACTIVE_9TH_ENTRY = 0x09,
ACTIVE_10TH_ENTRY = 0x0A,
ACTIVE_11TH_ENTRY = 0x0B,
ACTIVE_12TH_ENTRY = 0x0C,
ACTIVE_13TH_ENTRY = 0x0D,
ACTIVE_14TH_ENTRY = 0x0E,
ACTIVE_15TH_ENTRY = 0x0F,
ACTIVE_16TH_ENTRY = 0x10,
ACTIVE_17TH_ENTRY = 0x11,
ACTIVE_18TH_ENTRY = 0x12,
ACTIVE_19TH_ENTRY = 0x13,
ACTIVE_20TH_ENTRY = 0x14,
ACTIVE_1ST_ENTRY_LAST = 0x41,
ACTIVE_2ND_ENTRY_LAST = 0x42,
ACTIVE_3RD_ENTRY_LAST = 0x43,
ACTIVE_4TH_ENTRY_LAST = 0x44,
ACTIVE_5TH_ENTRY_LAST = 0x45,
ACTIVE_6TH_ENTRY_LAST = 0x46,
ACTIVE_7TH_ENTRY_LAST = 0x47,
ACTIVE_8TH_ENTRY_LAST = 0x48,
ACTIVE_9TH_ENTRY_LAST = 0x49,
ACTIVE_10TH_ENTRY_LAST = 0x4A,
ACTIVE_11TH_ENTRY_LAST = 0x4B,
ACTIVE_12TH_ENTRY_LAST = 0x4C,
ACTIVE_13TH_ENTRY_LAST = 0x4D,
ACTIVE_14TH_ENTRY_LAST = 0x4E,
ACTIVE_15TH_ENTRY_LAST = 0x4F,
ACTIVE_16TH_ENTRY_LAST = 0x50,
ACTIVE_17TH_ENTRY_LAST = 0x51,
ACTIVE_18TH_ENTRY_LAST = 0x52,
ACTIVE_19TH_ENTRY_LAST = 0x53,
ACTIVE_20TH_ENTRY_LAST = 0x54,
};
// ------------------------------
// HELPER FOR LFN FIRST BYTE
// ------------------------------
union LFNEntry_FirstByte {
Entry_Status status;
LFN_Sequence seq_num;
};
// ------------------------------
// SFN ATTRIBUTE HELPER
// ------------------------------
bitfield Attributes {
readOnly : 1;
hidden : 1;
systemFile : 1;
volumeLabel : 1;
subDirectory : 1;
archive : 1;
padding : 2;
} [[bitfield_order(
std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
// ------------------------------
// ROOT DIRECTORY ENTRY FUNC
// ------------------------------
fn dir_entry_marker(u64 abs_off) {
u8 first @ abs_off;
return first;
};
// ------------------------------
// ROOT DIRECTORY ENTRY FUNC
// ------------------------------
fn dir_entry_attr(u64 abs_off) {
u8 attr @ abs_off + 0x0B;
return attr;
};
// ------------------------------
// DATES AND TIMES FUNC
// ------------------------------
fn format_dos_time_field(std::time::DOSTime t) {
return std::time::format_dos_time(t, "{:02}:{:02}:{:02}");
};
fn format_dos_date_field(std::time::DOSDate d) {
return std::time::format_dos_date(d, "{1:02}-{0:02}-{2:04}");
};
// ------------------------------
// SHORT FILE NAME ALIAS PARSER
// ------------------------------
struct SFN_Entry_Alias {
char fileName[8] [[name("SFN"), comment("Short File Name (8dot3)")]];
char extension[3] [[name("EXT"), comment("File Extension (8dot3)")]];
Attributes attributes [[name("RASH ATTR"), comment("Read-Only | Archive | System | Hidden | SubDir...")]];
u8 reserved [[comment("Zeros")]];
u8 milliseconds [[comment("Add to Times for Refinement")]];
std::time::DOSTime Created_Time [[format("format_dos_time_field")]];
std::time::DOSDate Created_Date [[format("format_dos_date_field")]];
std::time::DOSDate Accessed_Date [[format("format_dos_date_field")]];
u16 Cluster_Hi [[comment("High Cluster if Needed")]];
std::time::DOSTime Modified_Time [[format("format_dos_time_field")]];
std::time::DOSDate Modified_Date [[format("format_dos_date_field")]];
u16 Cluster_Lo [[comment("Starting Cluster or Combine with Cluster_Hi")]];
u32 fileSize [[name("FILE_SIZE"), comment("File Size in Bytes")]];
u32 first_cluster = (Cluster_Hi << 16) | Cluster_Lo;
u8 FILE_DATA[fileSize] @ dataRegionStart + (first_cluster -2) * bytesPerCluster [[comment("Pointer to the Files Content")]];
sfn_count += 1;
if (fileName[0] == 0xE5) {
sfn_del_count += 1;
}
};
// ------------------------------
// LOOOONG FILE NAME PARSER
// ------------------------------
struct LFN_Entry {
u64 curr_first_byte = $;
u8 curr_attr = dir_entry_attr(curr_first_byte);
LFNEntry_FirstByte SeqByte [[name("SEQUENCE_NUM"), comment("0x01-0x20 | Add 0x40 to Last LFN Entry")]];
char16 NAME_1[5] [[comment("First 5 Characters of LFN")]];
Attributes attributes [[name("LFN_ATTR"), comment("0x0F = LFN")]];
padding[1] [[comment("Zeros")]];
u8 nameChecksum [[name("Checksum"), comment("Checksum Calculated on SFN_ALIAS")]];
char16 NAME_2[6] [[comment("Next 6 Characters of LFN")]];
padding[2] [[comment("Zeros")]];
char16 NAME_3[2] [[comment("Next 2 Characters of LFN")]];
// ATTEMPT TO CLEANUP UNICODE LFN... DOES NOT ACCOUNT FOR MULTI LFN ENTRIES
if (curr_attr == 0x0F) {
char display_name[32] @ $ - 32 [[
name(
(NAME_1[0] >= 0x20 && NAME_1[0] <= 0x7E ? std::string::to_string(NAME_1[0]) : "") +
(NAME_1[1] >= 0x20 && NAME_1[1] <= 0x7E ? std::string::to_string(NAME_1[1]) : "") +
(NAME_1[2] >= 0x20 && NAME_1[2] <= 0x7E ? std::string::to_string(NAME_1[2]) : "") +
(NAME_1[3] >= 0x20 && NAME_1[3] <= 0x7E ? std::string::to_string(NAME_1[3]) : "") +
(NAME_1[4] >= 0x20 && NAME_1[4] <= 0x7E ? std::string::to_string(NAME_1[4]) : "") +
(NAME_2[0] >= 0x20 && NAME_2[0] <= 0x7E ? std::string::to_string(NAME_2[0]) : "") +
(NAME_2[1] >= 0x20 && NAME_2[1] <= 0x7E ? std::string::to_string(NAME_2[1]) : "") +
(NAME_2[2] >= 0x20 && NAME_2[2] <= 0x7E ? std::string::to_string(NAME_2[2]) : "") +
(NAME_2[3] >= 0x20 && NAME_2[3] <= 0x7E ? std::string::to_string(NAME_2[3]) : "") +
(NAME_2[4] >= 0x20 && NAME_2[4] <= 0x7E ? std::string::to_string(NAME_2[4]) : "") +
(NAME_2[5] >= 0x20 && NAME_2[5] <= 0x7E ? std::string::to_string(NAME_2[5]) : "") +
(NAME_3[0] >= 0x20 && NAME_3[0] <= 0x7E ? std::string::to_string(NAME_3[0]) : "") +
(NAME_3[1] >= 0x20 && NAME_3[1] <= 0x7E ? std::string::to_string(NAME_3[1]) : "")
)
]];
}
lfn_count += 1;
if (SeqByte.status == Entry_Status::DELETED_ENTRY) {
lfn_del_count += 1;
}
};
// ------------------------------
// SHORT FILE NAME PARSER
// ------------------------------
struct SFN_Entry {
char fileName[8] [[name("SFN"), comment("Short File Name (8dot3)")]];
char extension[3] [[name("EXT"), comment("File Extension (8dot3)")]];
Attributes attributes [[name("RASH ATTR"), comment("Read-Only | Archive | System | Hidden | SubDir...")]];
u8 reserved [[comment("Zeros")]];
u8 milliseconds [[comment("Add to Times for Refinement")]];
std::time::DOSTime Created_Time [[format("format_dos_time_field")]];
std::time::DOSDate Created_Date [[format("format_dos_date_field")]];
std::time::DOSDate Accessed_Date [[format("format_dos_date_field")]];
u16 Cluster_Hi [[comment("High Cluster if Needed")]];
std::time::DOSTime Modified_Time [[format("format_dos_time_field")]];
std::time::DOSDate Modified_Date [[format("format_dos_date_field")]];
u16 Cluster_Lo [[comment("Starting Cluster or Combine with Cluster_Hi")]];
u32 fileSize [[name("FILE_SIZE"), comment("File Size in Bytes")]];
u32 first_cluster = (Cluster_Hi << 16) | Cluster_Lo;
u8 FILE_DATA[fileSize] @ dataRegionStart + (first_cluster -2) * bytesPerCluster [[comment("Pointer to the File Content")]];
sfn_count += 1;
if (fileName[0] == 0xE5) {
sfn_del_count += 1;
}
};
// ------------------------------
// SUBDIRECTORY PARSER | LEVEL 2
// ------------------------------
struct SubDirParser {
u8 first = dir_entry_marker($);
u8 attr = dir_entry_attr($);
u64 next_first_byte = $ + 32;
u8 next_attr = dir_entry_attr(next_first_byte); // current offset plus 12 bytes (offset 0x0B of entry)
if (first != 0x00 && attr == 0x0F) {
LFN_Entry LFN_ENTRY;
if (next_first_byte != 0x00 && next_first_byte != 0xE5 && next_attr == 0x0F) {
LFN_Entry next_LFN_ENTRY;
SFN_Entry_Alias SFN_ALIAS;
}
} else if (first != 0x00 && attr != 0x0F) {
SFN_Entry SFN_ENTRY;
}
};
// ------------------------------
// ROOT DIRECTORY ENTRY PARSER
// ROUGH METHOD OF PARSING SFN/LFN/SFN_ALIAS/SUBDIR TWO LEVELS DEEP
// IF THE PATTERN CRASHES - THIS IS LIKELY WHY
// ------------------------------
struct RootDirParser {
u64 curr_first_byte = $;
u8 curr_attr = dir_entry_attr(curr_first_byte); // current offset plus 12 bytes (offset 0x0B of entry)
u64 next_first_byte = $ + 32;
u8 next_attr = dir_entry_attr(next_first_byte); // current offset plus 12 bytes (offset 0x0B of entry)
bool is_subdir = false;
if (curr_first_byte != 0x00 && curr_first_byte != 0xE5 && curr_attr == 0x0F) {
LFN_Entry LFN_ENTRY;
if (next_first_byte != 0x00 && next_first_byte != 0xE5 && next_attr == 0x0F) {
LFN_Entry next_LFN_ENTRY;
SFN_Entry_Alias SFN_ALIAS;
is_subdir = SFN_ALIAS.attributes.subDirectory;
if (SFN_ALIAS.attributes.subDirectory && next_first_byte != 0x00 && next_attr != 0xE5) {
is_subdir = SFN_ALIAS.attributes.subDirectory;
u64 dir_start_addr = dataRegionStart + (SFN_ALIAS.first_cluster - 2) * bytesPerCluster;
SubDirParser SUB_DIR_INDEX[while(std::mem::read_unsigned($, 1) != 0x00)] @ dir_start_addr;
}
}
if (next_first_byte != 0x00 && next_first_byte != 0xE5 && next_attr != 0x0F) {
SFN_Entry_Alias SFN_ALIAS;
is_subdir = SFN_ALIAS.attributes.subDirectory;
if (SFN_ALIAS.attributes.subDirectory && next_first_byte != 0x00 && next_attr != 0xE5) {
is_subdir = SFN_ALIAS.attributes.subDirectory;
u64 dir_start_addr = dataRegionStart + (SFN_ALIAS.first_cluster - 2) * bytesPerCluster;
SubDirParser SUB_DIR_INDEX[while(std::mem::read_unsigned($, 1) != 0x00)] @ dir_start_addr;
}
}
} else if (curr_first_byte != 0x00 && curr_first_byte != 0xE5 && curr_attr != 0x0F) {
SFN_Entry SFN_ENTRY;
is_subdir = SFN_ENTRY.attributes.subDirectory;
if (SFN_ENTRY.attributes.subDirectory && next_first_byte != 0x00 && next_attr != 0xE5) {
is_subdir = SFN_ENTRY.attributes.subDirectory;
u64 dir_start_addr = dataRegionStart + (SFN_ENTRY.first_cluster - 2) * bytesPerCluster;
SubDirParser SUB_DIR_INDEX[while(std::mem::read_unsigned($, 1) != 0x00)] @ dir_start_addr;
}
} else if (curr_first_byte != 0x00 && current_first_byte == 0xE5) {
if (next_first_byte != 0x00 && next_attr == 0x0F) {
LFN_Entry LFN_ENTRY;
if (next_first_byte != 0x00 && next_first_byte != 0xE5) {
if (next_attr != 0x0F) {
SFN_Entry_Alias SFN_ALIAS;
is_subdir = SFN_ALIAS.attributes.subDirectory;
if (next_first_byte != 0x00 && next_first_byte != 0xE5 && next_attr != 0x0F) {
SFN_Entry_Alias SFN_ALIAS2; // otherwise switch to SFN
is_subdir = SFN_ALIAS.attributes.subDirectory;
if (SFN_ALIAS.attributes.subDirectory && next_first_byte != 0x00 && next_attr != 0xE5) {
is_subdir = SFN_ALIAS.attributes.subDirectory;
u64 dir_start_addr = dataRegionStart + (SFN_ALIAS.first_cluster - 2) * bytesPerCluster;
SubDirParser SUB_DIR_INDEX[while(std::mem::read_unsigned($, 1) != 0x00)] @ dir_start_addr;
}
}
}
}
} else {
SFN_Entry SFN_ENTRY;
is_subdir = SFN_ENTRY.attributes.subDirectory;
}
}
} [[name(format_element($, start_index, is_subdir)), comment("FILE/DIR [INDX #]")]];
// ------------------------------
// NAME FORMATTER
// ------------------------------
fn format_element(auto v, u64 offset, bool subdir) {
if (subdir) {
return std::format("SUB_DIR [{:02}]", std::core::array_index() + offset);
} else {
return std::format("FILE [{:02}]", std::core::array_index() + offset);
}
};
// ------------------------------
// ROOT DIRECTORY HEADER PARSER
// ------------------------------
struct RootDirHeader {
char VolumeName[11] [[comment("User Defined Name of the VOL")]];
u8 VolumeLabelFlag [[comment("Indicates the Preceding VOL LABEL")]];
padding[10] [[comment("Zeros")]];
std::time::DOSTime Created_Time [[format("format_dos_time_field"), comment("Last Write Time - Typically when Created/Formatted, but NOT ALWAYS...(DISK IMAGE/FAT DRIVERS)")]];
std::time::DOSDate Created_Date [[format("format_dos_date_field"), comment("Last Write Date - Typically when Created/Formatted, but NOT ALWAYS...(DISK IMAGE/FAT DRIVERS)")]];
padding[6] [[comment("Zeros")]];
};
// ------------------------------
// VBR SIGNATURE HELPER
// ------------------------------
enum VBRSignature : u16 {
VBR_SIG = 0xAA55
};
// ------------------------------
// FILE SYSTEM INFO BLOCK
// ------------------------------
struct FSInfo {
u32 leadSignature [[comment("RRaA")]];
padding[480] [[comment("Zeros")]];
u32 structSignature [[comment("FSINFO Signature")]];
u32 freeClusterCount [[comment("Approximate Free Cluster Count")]];
u32 nextFreeCluster [[comment("FAT1: Suggested Starting Point")]];
padding[14] [[comment("Zeros")]];
VBRSignature VBR_SIG [[comment("0x55AA")]];
};
// ------------------------------
// FAT12/16/32 BIOS PARAMETER BLOCK (BPB)
// ------------------------------
struct BPB_Common {
u8 jmp_boot[3] [[comment("Assembly Instructions to Jump to Boot Code")]];
char oem_name[8] [[comment("MSDOS/BSD")]];
u16 bytes_per_sector [[comment("512,1024,2048,4096")]];
u8 sectors_per_cluster [[comment("Under 32K - Must be a power of 2")]];
u16 reserved_sectors [[comment("Size of Reserved Area in Sectors")]];
u8 num_fats [[comment("Typically 2, but can be 1 for Small Volumes")]];
u16 root_entry_count [[comment("Max Num of Entries -- 0 for FAT32| 512 for FAT16")]];
u16 total_sectors16 [[comment("if 0, use total_sectors32")]];
u8 media_type [[comment("0xF8=FIXED DISK | 0xF0=REMOVABLE")]];
u16 fat_size16 [[comment("Size of each FAT in Sectors for FAT12/16; 0 for FAT32")]];
u16 sectors_per_track [[comment("Legacy")]];
u16 num_heads [[comment("Legacy")]];
u32 hidden_sectors [[comment("Num of Sectors before the Volume")]];
u32 total_sectors32 [[comment("32bit Value of Total Num of Sectors in Volume")]];
// ----------------------vvv-----
// FAT32 EXTENDED
// ----------------------vvv-----
u32 FAT_Sector_Count [[comment("Total Sectors per FAT")]];
u16 ext_flags [[comment("16bit Value: BIT_7 = 1 == 1 FAT USED | Otherwise both FATs USED")]];
u16 fs_version [[comment("Major and Minor | None")]];
u32 root_cluster [[comment("Cluster Num of Root Dir")]];
u16 fs_info_sector [[comment("FS_INFO Location")]];
u16 backup_boot_sector [[comment("VBR Backup Location")]];
u8 reserved[12] [[comment("Zeros")]];
u8 drive_number [[comment("BIOS INT13h Drive Num")]];
u8 reserved1 [[comment("Zeros")]];
u8 boot_signature [[comment("Extended Boot Sig = 0x29")]];
u32 volume_id [[comment("Volume Serial Number - Based on Created Date/Time")]];
char volume_label[11] [[comment("No Name | User Defined Name | Check Root Dir")]];
char fs_type[8] [[comment("FAT32 ")]];
u8 bootstrap[420] [[comment("Until Signature")]];
VBRSignature VBR_SIG [[comment("0x55AA")]];
// ----------------------vvv-----
// UPDATE CONSTANTS/GLOBALS
// ----------------------vvv-----
bytesPerCluster = sectors_per_cluster * bytes_per_sector;
rootDirSectors = ((root_entry_count * 32) + (bytes_per_sector - 1)) / bytes_per_sector;
firstDataSector = reserved_sectors + (num_fats * FAT_Sector_Count) + rootDirSectors;
dataRegionStart = firstDataSector * bytes_per_sector;
};
// -----------------------------------------------------------------------------
// FAT32 MAIN RELATED
// -----------------------------------------------------------------------------
// V V V V V V V V V V
// -----------------------------------------------------------------------------
// ------------------------------
// FAT32 VOLUME BOOT RECORD
// ------------------------------
BPB_Common F32_VBR @ $;
VBR_OFFSET = F32_VBR.hidden_sectors * F32_VBR.bytes_per_sector;
/// ------------------------------
// FILE SYSTEM INFO BLOCK
// ------------------------------
FSInfo FS_INFO @ F32_VBR.fs_info_sector * F32_VBR.bytes_per_sector;
root_dir_start = dataRegionStart + ((F32_VBR.root_cluster - 2) * bytesPerCluster) + 32;
// ------------------------------
// FILE ALLOCATION TABLE
// *** HAS GLOBAL AT TOP ***
// ------------------------------
FAT1_start_offset = F32_VBR.reserved_sectors * F32_VBR.bytes_per_sector;
FAT2_start_offset = FAT1_start_offset + (F32_VBR.FAT_Sector_Count * F32_VBR.bytes_per_sector);
FAT_ClusterHeap_Count = F32_VBR.FAT_Sector_Count * F32_VBR.bytes_per_sector / CLUSTER_SIZE_BYTES;
FAT_Header FAT1_HEADER @ FAT1_start_offset;
FAT_Entry FAT1[MAX_FAT_CHUNKS] @ FAT1_start_offset + 8;
FAT_Header FAT2_HEADER @ FAT2_start_offset;
FAT_Entry FAT2[MAX_FAT_CHUNKS] @ FAT2_start_offset + 8;
// ------------------------------
// ROOT DIRECTORY HEADER
// ------------------------------
RootDirHeader ROOT_DIR_HEADER @ dataRegionStart + ((F32_VBR.root_cluster - 2) * bytesPerCluster);
// ----*-----*------*------*-----
// * * ROOT DIRECTORY PARSER * *
// ----*-----*------*------*-----
RootDirParser ROOT_DIR_ENTRIES[while(std::mem::read_unsigned($, 1) != 0x00)] @ root_dir_start;
// ------------------------------
// SFN <-> CLUSTER RELATION OVERLAY
// *** HAS GLOBAL AT TOP ***
// ------------------------------
INFO_Overlay SFN_CLUSTER_LIST[MAX_SFN_CLUSTER_RELATIONS] @ FAT1_start_offset [[name("SFN <-> CLUSTER (DERIVED)")]];
// ------------------------------
// FAT32 VOLUME REPORT
// *** HAS GLOBAL AT TOP ***
// ------------------------------
abs_FAT1_start_offset = VBR_OFFSET + (F32_VBR.reserved_sectors * F32_VBR.bytes_per_sector);
abs_FAT2_start_offset = abs_FAT1_start_offset + (F32_VBR.FAT_Sector_Count * F32_VBR.bytes_per_sector);
abs_rootDirStart_offset = VBR_OFFSET + dataRegionStart;
if (VOLUME_REPORT) {
std::print(" ");
std::print("-----------------------------------------");
std::print("---------- FAT32 VOLUME_REPORT ----------");
std::print("-----------------------------------------");
std::print("VOL_LABEL = {}", F32_VBR.volume_label);
std::print("FILE_SYSTEM = {}", F32_VBR.fs_type);
std::print("SERIAL_NUMBER = 0x{:X}", F32_VBR.volume_id);
std::print("-----------------------------------------");
std::print("BYTES/SECTOR = {:02}", F32_VBR.bytes_per_sector);
std::print("SECTORS/CLUSTER = {:02}", F32_VBR.sectors_per_cluster);
std::print("BYTES/CLUSTER = {:02}", bytesPerCluster);
std::print("ROOT_ENTRIES = {:02}", F32_VBR.root_entry_count);
std::print("CLUSTER_COUNT = {:02}", (F32_VBR.total_sectors32 - firstDataSector) / F32_VBR.sectors_per_cluster);
std::print("-----------------------------------------");
std::print("VOLUME_SIZE = {:02} SECTORS", F32_VBR.total_sectors32);
std::print("VOLUME_SIZE = {:.4f} GB @ 1000", (F32_VBR.total_sectors32 * F32_VBR.bytes_per_sector) / 1000.0 / 1000.0 / 1000.0);
std::print("VOLUME_SIZE = {:.4f} GiB @ 1024", (F32_VBR.total_sectors32 * F32_VBR.bytes_per_sector) / 1024.0 / 1024.0 / 1024.0);
std::print("-----------------------------------------");
std::print("RESERVED_SECTORS = {:02}", F32_VBR.reserved_sectors);
std::print("FAT_COUNT = {:02}", F32_VBR.num_fats);
std::print("FAT_SIZE = {:02} SECTORS", F32_VBR.FAT_Sector_Count);
std::print("FAT1_START_OFF = {} | 0x{:02X}", abs_FAT1_start_offset, abs_FAT1_start_offset);
std::print("FAT2_START_OFF = {} | 0x{:02X}", abs_FAT2_start_offset, abs_FAT2_start_offset);
std::print("ROOT_DIR_CLUSTER = {:02}", F32_VBR.root_cluster);
std::print("ROOT_DIR_OFFSET = {} | 0x{:02X}", abs_rootDirStart_offset, abs_rootDirStart_offset);
std::print("-----------------------------------------");
if (sfn_del_count >= 1) {
std::print("SFN_DEL(xE5) = DETECTED");
}
if (lfn_del_count >= 1) {
std::print("LFN_DEL(xE5) = DETECTED");
}
std::print("FAT1_EOF_COUNT = {:02}", allocated_file_count / 2); // divided by 2 (FAT1/FAT2)
std::print("-----------------------------------------");
std::print("------------------ END ------------------");
std::print("-----------------------------------------");
std::print(" ");
}

1571
patterns/DFIR/NTFS.hexpat Normal file

File diff suppressed because it is too large Load Diff

616
patterns/DFIR/exFAT.hexpat Normal file
View File

@@ -0,0 +1,616 @@
#pragma author Formula Zero One Technologies
#pragma description exFAT Filesystem (exFAT_v2.0)
#pragma MIME application/x-ima
#pragma endian little
// -----------------------------------------------------------------------------
// CREDIT
// -----------------------------------------------------------------------------
// Based on /fs/exfat.hexpat by WerWolv
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// NOTES
// -----------------------------------------------------------------------------
// Imported by DISK_PARSER.hexpat
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// TODO
// -----------------------------------------------------------------------------
// Recursive parsing of Root Directory / SubDirs
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// IMPORTS
// -----------------------------------------------------------------------------
import std.core;
import std.io;
import std.time;
import std.mem;
import type.guid;
import type.magic;
import type.base;
// ------------------------------
// FORWARD DECS/GLOBALS
// ------------------------------
// *** ATTENTION ***
// SET MAXIMUM NUMBER OF 4 BYTE CHUNKS TO PARSE FROM FAT1
// SET MAXIMUM NUMBER OF DIRECTORY ENTRIES TO PARSE FROM ROOT DIRECTORY
// DEFAULTS ARE 4096 | 2500
// Choose a value greater than 1 and less than 65536 OR increase the Array size limit with "#define... "
// -------**************---vvvv--- |
const u64 MAX_FAT_CHUNKS = 4096;
// -------**************---^^^^--- |
// -------**************---vvvv--- |
const u64 MAX_DIR_ENTRIES = 2500;
// -------**************---^^^^--- |
// *** ATTENTION ***
// ---*******---*******----vvvv--- |
const bool VOLUME_REPORT = true;
// ---*******---*******----^^^^--- |
u64 allocated_file_count;
u64 rdc;
// --------------------------
// exFAT DIRECTORY ENTRY HELPER
// --------------------------
enum EntryType : u8 {
UNUSED_ENTRY = 0x00,
ACTIVE_VOLUME_GUID_ENTRY = 0xA0,
INACTIVE_VOLUME_GUID_ENTRY = 0x20,
ACTIVE_TEXFAT_ENTRY = 0xA1,
INACTIVE_TEXFAT_ENTRY = 0x21,
ACTIVE_ACCESS_CONTROL_ENTRY = 0xA2,
INACTIVE_ACCESS_CONTROL_ENTRY = 0x22,
ACTIVE_VOLUME_LABEL_ENTRY = 0x83,
INACTIVE_VOLUME_LABEL_ENTRY = 0x03,
ACTIVE_ALLOCATION_BITMAP_ENTRY = 0x81,
INACTIVE_ALLOCATION_BITMAP_ENTRY = 0x01,
ACTIVE_UPCASE_TABLE_ENTRY = 0x82,
INACTIVE_UPCASE_TABLE_ENTRY = 0x02,
ACTIVE_FILE_INFO_ENTRY = 0x85,
INACTIVE_FILE_INFO_ENTRY = 0x05,
ACTIVE_STREAM_ENTRY = 0xC0,
INACTIVE_STREAM_ENTRY = 0x40,
ACTIVE_FILENAME_ENTRY = 0xC1,
INACTIVE_FILENAME_ENTRY = 0x41,
};
// ------------------------------
// DATES AND TIMES FUNC
// ------------------------------
fn format_dos_time_field(std::time::DOSTime t) {
return std::time::format_dos_time(t, "{:02}:{:02}:{:02}");
};
fn format_dos_date_field(std::time::DOSDate d) {
return std::time::format_dos_date(d, "{1:02}-{0:02}-{2:04}");
};
// ------------------------------
// BITFIELD HELPERS
// ------------------------------
bitfield Entry_Flags {
unsigned TypeCode : 5;
unsigned Importance : 1;
unsigned Category : 1;
unsigned InUse : 1;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
bitfield Bitmap_Flags {
unsigned Bitmap_1 : 1;
unsigned Bitmap_2 : 1;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
bitfield General_Primary_Flags {
unsigned Allocation_Possible : 1;
unsigned No_FAT_Chain : 1;
unsigned Reserved : 6;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
bitfield General_Secondary_Flags {
unsigned Allocation_Possible : 1;
unsigned No_FAT_Chain : 1;
unsigned Reserved : 6;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 8)]];
bitfield File_Attr_Flags {
unsigned Read_Only : 1;
unsigned Hidden : 1;
unsigned System : 1;
unsigned Directory : 1;
unsigned Archive : 1;
Reserved : 11;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 16)]];
// --------------------------
// exFAT DIRECTORY ENTRY STRUCTURES
// --------------------------
// xA0 / x20 = Volume GUID Entry
struct VolumeGUID_Entry {
Entry_Flags EntryFlags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 SecondaryCount[3] [[comment("COUNT OF SUBSEQUENT ENTRIES")]];
type::Hex<u16> SetChecksum [[comment("16bit CHECKSUM")]];
General_Primary_Flags PrimaryFlags;
type::GUID GUID;
u8 Reserved_1[9];
};
// xA1 / x21 = TexFAT / Padding Entry
struct TexFATPadding_Entry {
Entry_Flags Flags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 Reserved_1[31];
};
// xA2 / x22 = Access Control Entry
struct AccessControl_Entry {
Entry_Flags Flags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 Reserved[31];
};
// x83 / x03 = Volume Label Entry
struct VolumeLabel_Entry {
Entry_Flags Flags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 LabelLength [[comment("NUMBER OF UTF-16 CHARACTERS")]];
char16 Label[LabelLength] [[comment("VOLUME LABEL: UTF-16")]];
u8 Reserved[32-2-(LabelLength * 2)];
};
// x81 / x01 = Allocation Bitmap Entry
struct AllocationBitmap_Entry {
Entry_Flags Flags [[comment("ENTRY TYPE IDENTIFIER")]];
Bitmap_Flags BitmapFlags;
u8 Reserved_1[18];
u32 FirstCluster [[comment("FIRST LOGICAL CLUSTER NUMBER")]];
u64 DataLength [[comment("DATA SIZE")]];
u8 FILE_DATA[DataLength] @ temp_root_location + (FirstCluster - exFAT_VBR.root_dir_cluster) * bytesPerCluster [[comment("POINTER TO THE CLUSTER CONTENT")]];
};
// x82 / x02 = UpCase Table Entry
struct UpCaseTable_Entry {
Entry_Flags Flags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 Reserved_1[3];
type::Hex<u32> TableChecksum [[comment("16bit CHECKSUM")]];
u8 Reserved_2[12];
u32 FirstCluster [[comment("FIRST LOGICAL CLUSTER NUMBER")]];
u64 DataLength [[comment("DATA SIZE")]];
u8 FILE_DATA[DataLength] @ temp_root_location + (FirstCluster - exFAT_VBR.root_dir_cluster) * bytesPerCluster [[comment("POINTER TO THE CLUSTER CONTENT")]];
};
// x85 / x05 = File Info Entry
struct FileInfo_Entry {
Entry_Flags EntryFlags [[comment("ENTRY TYPE IDENTIFIER")]];
u8 SecondaryCount [[comment("COUNT OF SUBSEQUENT ENTRIES")]];
type::Hex<u16> SetChecksum [[comment("16bit CHECKSUM")]];
File_Attr_Flags AttrFlags [[comment("FILE ATTRS: RASH")]];
u16 Reserved_1;
std::time::DOSTime Created_Time [[format("format_dos_time_field")]];
std::time::DOSDate Created_Date [[format("format_dos_date_field")]];
std::time::DOSTime Accessed_Time [[format("format_dos_time_field")]];
std::time::DOSDate Accessed_Date [[format("format_dos_date_field")]];
std::time::DOSTime Modified_Time [[format("format_dos_time_field")]];
std::time::DOSDate Modified_Date [[format("format_dos_date_field")]];
u8 Created_10ms_Increments [[comment("Add to Times for Refinement")]];
u8 Modified_10ms_Increments [[comment("Add to Times for Refinement")]];
s8 Created_UTC_Diff [[comment("Add to Times for Refinement")]];
s8 Modified_UTC_Diff [[comment("Add to Times for Refinement")]];
s8 Accessed_UTC_Diff [[comment("Add to Times for Refinement")]];
u8 Reserved[7];
};
// xC1 / x41 = File Name Entry
struct FileName_Entry {
Entry_Flags EntryFlags [[comment("ENTRY TYPE IDENTIFIER")]];
General_Secondary_Flags SecondaryFlags [[comment("COUNT OF SUBSEQUENT ENTRIES")]];
char16 FileName[15] [[comment("FILE NAME: UTF-16")]];
};
// xC0 / x40 = Stream Extension Entry
struct Stream_Entry {
Entry_Flags EntryFlags [[comment("ENTRY TYPE IDENTIFIER")]];;
General_Secondary_Flags SecondaryFlags [[comment("COUNT OF SUBSEQUENT ENTRIES")]];
u8 Reserved_1;
u8 NameLength [[comment("STREAM LENGTH")]];
type::Hex<u16> NameHash [[comment("16bit QUICK HASH: USED FOR FILE SEARCHING")]];
u16 Reserved_2;
u64 InitSize [[comment("INITIALIZED SIZE")]];
u32 Reserved_3;
u32 FirstCluster [[comment("FIRST LOGICAL CLUSTER NUMBER")]];
u64 ActualSize [[comment("PHYSICAL DATA SIZE")]];;
u8 FILE_DATA[InitSize] @ temp_root_location + (FirstCluster - exFAT_VBR.root_dir_cluster) * bytesPerCluster [[comment("POINTER TO THE CLUSTER CONTENT")]];
};
// --------------------------
// exFAT ROOT DIRECTORY
// --------------------------
struct RootDir {
EntryType Type;
padding[31];
match (Type) {
(EntryType::UNUSED_ENTRY): {
continue;
}
(EntryType::ACTIVE_VOLUME_GUID_ENTRY | EntryType::INACTIVE_VOLUME_GUID_ENTRY):{
VolumeGUID_Entry VOLUME_GUID_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_TEXFAT_ENTRY | EntryType::INACTIVE_TEXFAT_ENTRY):{
TexFATPadding_Entry TEXFAT_PADDING_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_ACCESS_CONTROL_ENTRY | EntryType::INACTIVE_ACCESS_CONTROL_ENTRY):{
AccessControl_Entry ACCESS_CONTROL_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_VOLUME_LABEL_ENTRY | EntryType::INACTIVE_VOLUME_LABEL_ENTRY):{
VolumeLabel_Entry VOLUME_LABEL_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_ALLOCATION_BITMAP_ENTRY | EntryType::INACTIVE_ALLOCATION_BITMAP_ENTRY):{
AllocationBitmap_Entry ALLOCATION_BITMAP_ENTRY @ $ - 32;
u64 bitmap_cluster = ALLOCATION_BITMAP_ENTRY.FirstCluster;
char dolla_BITMAP_label[4] @ FAT1_start_offset + (bitmap_cluster * 4) [[name(std::format("$Bitmap"))]];
}
(EntryType::ACTIVE_UPCASE_TABLE_ENTRY | EntryType::INACTIVE_UPCASE_TABLE_ENTRY):{
UpCaseTable_Entry UPCASE_TABLE_ENTRY @ $ - 32;
u64 upcase_cluster = UPCASE_TABLE_ENTRY.FirstCluster;
char dolla_UPCASE_label[4] @ FAT1_start_offset + (upcase_cluster * 4) [[name(std::format("$UpCase"))]];
}
(EntryType::ACTIVE_FILE_INFO_ENTRY | EntryType::INACTIVE_FILE_INFO_ENTRY):{
FileInfo_Entry FILE_INFO_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_STREAM_ENTRY | EntryType::INACTIVE_STREAM_ENTRY):{
Stream_Entry STREAM_EXT_ENTRY @ $ - 32;
}
(EntryType::ACTIVE_FILENAME_ENTRY | EntryType::INACTIVE_FILENAME_ENTRY):{
FileName_Entry FILE_NAME_ENTRY @ $ - 32;
}
}
} [[name(format_entry_name(std::mem::read_unsigned($-32, 1), std::core::array_index()))]];
fn format_entry_name(auto entry_type, u64 idx) {
return std::format("{}[{}]", type_name(entry_type), idx);
};
// ------------------------------
// TYPE RE-NAMER
// ------------------------------
fn type_name(u32 type) {
if (type == EntryType::UNUSED_ENTRY) return "UNUSED_ENTRY";
if (type == EntryType::ACTIVE_VOLUME_GUID_ENTRY) return "ACTIVE_VOLUME_GUID_ENTRY";
if (type == EntryType::INACTIVE_VOLUME_GUID_ENTRY) return "INACTIVE_VOLUME_GUID_ENTRY";
if (type == EntryType::ACTIVE_TEXFAT_ENTRY) return "ACTIVE_TEXFAT_ENTRY";
if (type == EntryType::INACTIVE_TEXFAT_ENTRY) return "INACTIVE_TEXFAT_ENTRY";
if (type == EntryType::ACTIVE_ACCESS_CONTROL_ENTRY) return "ACTIVE_ACCESS_CONTROL_ENTRY";
if (type == EntryType::INACTIVE_ACCESS_CONTROL_ENTRY) return "INACTIVE_ACCESS_CONTROL_ENTRY";
if (type == EntryType::ACTIVE_VOLUME_LABEL_ENTRY) return "ACTIVE_VOLUME_LABEL_ENTRY";
if (type == EntryType::INACTIVE_VOLUME_LABEL_ENTRY) return "INACTIVE_VOLUME_LABEL_ENTRY";
if (type == EntryType::ACTIVE_ALLOCATION_BITMAP_ENTRY) return "ACTIVE_ALLOCATION_BITMAP_ENTRY";
if (type == EntryType::INACTIVE_ALLOCATION_BITMAP_ENTRY) return "INACTIVE_ALLOCATION_BITMAP_ENTRY";
if (type == EntryType::ACTIVE_UPCASE_TABLE_ENTRY) return "ACTIVE_UPCASE_TABLE_ENTRY";
if (type == EntryType::INACTIVE_UPCASE_TABLE_ENTRY) return "INACTIVE_UPCASE_TABLE_ENTRY";
if (type == EntryType::ACTIVE_FILE_INFO_ENTRY) return "ACTIVE_FILE_INFO_ENTRY";
if (type == EntryType::INACTIVE_FILE_INFO_ENTRY) return "INACTIVE_FILE_INFO_ENTRY";
if (type == EntryType::ACTIVE_STREAM_ENTRY) return "ACTIVE_STREAM_ENTRY";
if (type == EntryType::INACTIVE_STREAM_ENTRY) return "INACTIVE_STREAM_ENTRY";
if (type == EntryType::ACTIVE_FILENAME_ENTRY) return "ACTIVE_FILENAME_ENTRY";
if (type == EntryType::INACTIVE_FILENAME_ENTRY) return "INACTIVE_FILENAME_ENTRY";
return "UNKNOWN";
};
// -----------------------------------------------------------------------------
// exFAT FILE ALLOCATION TABLE (FAT1) PARSER
// -----------------------------------------------------------------------------
const u32 CLUSTER_SIZE_BYTES = 4; // Each FAT32 entry = 4 bytes
const u32 FAT_EOF = 0x0FFFFFFF; // End-of-file marker
const u32 FAT_BAD = 0x0FFFFFF7; // Bad cluster marker
const u32 FIRST_ALLOC_CLUSTER = 2; // First usable cluster after reserved
enum FAT_Flags : u32 {
UNALLOCATED = 0x00000000,
END_OF_FILE = 0xFFFFFFFF, // L.END
BAD_CLUSTER = 0xFFFFFFF7, // L.END
};
union FAT_Union {
u32 DECIMAL [[hidden]];
FAT_Flags FAT_FLAG;
};
// ------------------------------
// Helper function for pointer label
// ------------------------------
fn cluster_label(u32 val) {
if (val == FAT_Flags::UNALLOCATED)
return "UNALLOCATED";
if (val == FAT_Flags::BAD_CLUSTER)
return "BAD";
if (val >= 0x0FFFFFF8)
return "EOF";
return std::format("{}", val);
};
// ------------------------------
// FAT1 HEAPS/CHAINS
// ------------------------------
struct FAT_Entry {
FAT_Union FAT [[inline]];
u32 cluster_num = (FIRST_ALLOC_CLUSTER) + (std::core::array_index());
u32 next_cluster = FAT.DECIMAL & 0x0FFFFFFF;
char hover_label[4] @ $ - 4 [[
name(std::format(
"Cluster: {} → {}",
cluster_num,
cluster_label(next_cluster)
))
]];
bool is_eof = next_cluster >= 0x0FFFFFF8;
bool is_bad = next_cluster == FAT_BAD;
bool is_free = next_cluster == 0;
if (is_eof) {
allocated_file_count += 1;
}
} [[name(format_fat_entry(FAT.DECIMAL, std::core::array_index(), FIRST_ALLOC_CLUSTER))]];
// ------------------------------
// FAT FORMATTER FUNC
// ------------------------------
fn format_fat_entry(u32 raw_value, u32 cluster_index, u32 first_alloc_cluster) {
u32 next_cluster = raw_value & 0x0FFFFFFF;
str next_label;
if (next_cluster == 0)
next_label = "UNALLOCATED";
else if (next_cluster == FAT_BAD)
next_label = "BAD";
else if (next_cluster == 0x0FFFFFFF)
next_label = "EOF";
else
next_label = std::format("{}", next_cluster);
u32 logical_cluster = first_alloc_cluster + cluster_index;
if (next_label == "UNALLOCATED" || next_label == "BAD" || next_label == "EOF")
return std::format("Cluster {}: {}", logical_cluster, next_label);
else
return std::format("Cluster {} → {}", logical_cluster, next_label);
};
// ------------------------------
// MEDIA DESCRIPTOR HELPER
// ------------------------------
enum Media_Descriptor : u8 {
SINGLE_SIDE_FLOPPY = 0xF0,
DOUBLE_SIDE_FLOPPY = 0xF9,
HARD_DISK_DRIVE = 0xF8,
};
// ------------------------------
// FAT HEADER PARSER
// ------------------------------
struct FAT_Header {
Media_Descriptor mediaDescriptor [[comment("0xF8=FIXED DISK | 0xF0=REMOVABLE")]];;
u8 exFAT_FAT_HEADER[7] [[comment("8 BYTES TOTAL: 4 BYTES REPRESENT PSUEDO CLUSTER 0 (SYSTEM) | 4 BYTES REPRESENT PSUEDO CLUSTER 1 (SYSTEM)(EOF)")]];
//Bitmap and UpCase overlays handled in RootDir parser
char root_dir_label[4] @ $ + ((rdc - 2) * 4) [[
name(std::format(
"ROOT_DIRECTORY"
))
]];
};
// ------------------------------
//SIGNATURE HELPER
// ------------------------------
enum VBRSignature : u16 {
VBR_SIG = 0xAA55
};
// ------------------------------
// EXTENDED BOOT REGION
// ------------------------------
struct ExtendedBoot {
u8 Extended_Boot_Sector[1 * bytesPerSector];
VBRSignature VBR_SIG @ $ - 2;
};
// ------------------------------
// BOOT SECTOR BITFIELD FLAGS
// ------------------------------
bitfield VolumeFlags {
unsigned Active : 1;
unsigned VolumeDirty : 1;
unsigned Media_Failure : 1;
unsigned Clear_to_Zero : 1;
Rserved : 12;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 16)]];
// ------------------------------
// EXFAT VOLUME BOOT RECORD
// ------------------------------
struct exFAT_BootSector {
u8 jmp_boot[3];
char fs_name[8]; // "EXFAT "
u8 must_be_zero[53];
u64 partition_offset; // in sectors
u64 volume_length; // in sectors
u32 fat_offset; // in sectors
u32 fat_length; // in sectors
u32 cluster_heap_offset; // in sectors
u32 cluster_count;
u32 root_dir_cluster;
u32 volume_serial;
u16 fs_revision;
VolumeFlags volume_flags;
u8 bytes_per_sector_shift; // 2^n
u8 sectors_per_cluster_shift; // 2^n
u8 number_of_fats;
u8 drive_select;
u8 percent_in_use;
u8 reserved[7];
u8 bootstrap[390];
VBRSignature VBR_SIG; // 0x55AA
rdc = root_dir_cluster;
};
// -------------------------------------------------------------------------
// MAIN
// -------------------------------------------------------------------------
// V V V V V V V V V
// -------------------------------------------------------------------------
exFAT_BootSector exFAT_VBR @ 0x0;
// -------------------------------------------------------------------------
// DERIVED CONSTANTS
// -------------------------------------------------------------------------
// ============= SIZES ===================================================================
u32 bytesPerSector = 1 << exFAT_VBR.bytes_per_sector_shift;
u32 bytesPerCluster = bytesPerSector << exFAT_VBR.sectors_per_cluster_shift;
// ============= OFFSETS =================================================================
u64 volumeStartSector = exFAT_VBR.partition_offset;
u64 volumeStartOffset = volumeStartSector * bytesPerSector;
u64 volumeSize = exFAT_VBR.volume_length * bytesPerSector;
u64 FAT1_start_offset = exFAT_VBR.fat_offset * bytesPerSector;
//For printing absolute offset
u64 RootDir_Offset = (exFAT_VBR.cluster_heap_offset +
((exFAT_VBR.root_dir_cluster - 2) << exFAT_VBR.sectors_per_cluster_shift))
* bytesPerSector + volumeStartOffset;
// ============= CLUSTERS ================================================================
u32 clusterSize = bytesPerCluster;
u32 clusterCount = exFAT_VBR.cluster_count;
u64 clusterHeapOffset = exFAT_VBR.cluster_heap_offset * bytesPerSector;
// -------------------------------------------------------------------------
// SECONDARY
// -------------------------------------------------------------------------
// V V V V V V V V V
// -------------------------------------------------------------------------
// ============= USAGE ===================================================================
u8 percentInUse = exFAT_VBR.percent_in_use;
// ============= EBS =====================================================================
ExtendedBoot Extended_Boot_Sectors[8] @ $;
// ============= OEM =====================================================================
u8 OEM_Parameters[1 * bytesPerSector] @ $;
// ============= ER ======================================================================
u8 Extended_Reserved[1 * bytesPerSector] @ $;
// ============= BCS =====================================================================
u8 Boot_Checksum[1 * bytesPerSector] @ $;
// ============= BBS =====================================================================
exFAT_BootSector Backup_Boot_Sector @ $;
// ============= BEBS ====================================================================
ExtendedBoot Backup_Extended_Boot_Sectors[8] @ $;
// ============= BOEM ====================================================================
u8 Backup_OEM_Parameters[1 * bytesPerSector] @ $;
// ============= BER =====================================================================
u8 Backup_Extended_Reserved[1 * bytesPerSector] @ $;
// ============= BBCS ====================================================================
u8 Backup_Boot_Checksum[1 * bytesPerSector] @ $;
// ============= FAT =====================================================================
// *** HAS GLOBAL AT TOP ***
FAT_Header FAT1_HEADER @ FAT1_start_offset;
FAT_Entry FAT1[MAX_FAT_CHUNKS] @ FAT1_start_offset + 8;
// ============= ROOT ====================================================================
// ROOT DIRECTORY
// *** HAS GLOBAL AT TOP ***
// for locating root directory within memory
u64 temp_root_location = (exFAT_VBR.root_dir_cluster - 2) * clusterSize + clusterHeapOffset;
RootDir ROOT_DIRECTORY[MAX_DIR_ENTRIES] @ temp_root_location;
// ============= REPORT ==================================================================
// VOLUME REPORT
// *** HAS GLOBAL AT TOP ***
if (VOLUME_REPORT) {
std::print(" ");
std::print("-----------------------------------------");
std::print("---------- EXFAT VOLUME_REPORT ----------");
std::print("-----------------------------------------");
std::print("FILE_SYSTEM = {}", exFAT_VBR.fs_name);
std::print("SERIAL_NUMBER = 0x{:X}", exFAT_VBR.volume_serial);
std::print("FS_REVISION = {}.{}", (exFAT_VBR.fs_revision >> 8) & 0xFF, exFAT_VBR.fs_revision & 0xFF);
bool _any = false;
if(exFAT_VBR.volume_flags.Active) {
std::print("FAT_FLAG = 0b{:X}", exFAT_VBR.volume_flags.Active);
_any = true;
}
if(exFAT_VBR.volume_flags.VolumeDirty) {
std::print("DIRTY_FLAG = 0b{:X}", exFAT_VBR.volume_flags.Volume_Dirty);
_any = true;
}
if(exFAT_VBR.volume_flags.Media_Failure) {
std::print("FAILURE_FLAG = 0b{:X}", exFAT_VBR.volume_flags.Media_Failure);
_any = true;
}
if(exFAT_VBR.volume_flags.Clear_to_Zero) {
std::print("CLEAR_TO_ZERO_FLAG = 0b{:X}", exFAT_VBR.volume_flags.Clear_to_Zero);
_any = true;
}
if (!_any){
std::print("VOL_FLAGS = NONE");
}
std::print("-----------------------------------------");
std::print("BYTES/SECTOR = {}", bytesPerSector);
std::print("SECTORS/CLUSTER = {}", 1 << exFAT_VBR.sectors_per_cluster_shift);
std::print("BYTES/CLUSTER = {}", bytesPerCluster);
std::print("CLUSTER_COUNT = {}", clusterCount);
std::print("-----------------------------------------");
std::print("VOLUME_SIZE = {} SECTORS", exFAT_VBR.volume_length);
std::print("VOLUME_SIZE = {:.4f} GB @ 1000", volumeSize / 1000.0 / 1000.0 / 1000.0);
std::print("VOLUME_SIZE = {:.4f} GiB @ 1024", volumeSize / 1024.0 / 1024.0 / 1024.0);
std::print("-----------------------------------------");
std::print("VOLUME_START_SEC = {}", volumeStartSector);
std::print("VOLUME_START_OFF = 0x{:X}", volumeStartOffset);
std::print("FAT1_START_OFF = 0x{:02X}", FAT1_start_offset);
std::print("CLUSTER_HEAP_OFF = 0x{:02X}", clusterHeapOffset);
std::print("ROOT_DIR_CLUSTER = {:02}", exFAT_VBR.root_dir_cluster);
std::print("ROOT_DIR_OFFSET = 0x{:02X}", RootDir_Offset);
std::print("-----------------------------------------");
std::print("PERCENT_IN_USE = {:02} %", percentInUse);
std::print("NUMBER_OF_FATS = {:02}", exFAT_VBR.number_of_fats);
std::print("DRIVE_SELECT = 0x{:02X}", exFAT_VBR.drive_select);
std::print("-----------------------------------------");
std::print("------------------ END ------------------");
std::print("-----------------------------------------");
std::print(" ");
}

View File

@@ -0,0 +1,165 @@
#pragma description Devil May Cry 3 HD .mod 3D model file
#pragma author haru233
// many thanks to AxCut
// ImHex Hex Pattern File for Capcom's Devil May Cry 3 HD .mod files
import std.core;
struct ModelHeader {
char ID[4];
float Version;
padding[8];
u8 objectCount;
u8 boneCount;
u8 numberTextures;
u8;
u32;
u64;
u64 skeletonOffset;
padding[24];
};
struct ObjectInfo {
u8 meshCount;
u8;
u16 numberVertices;
padding[4];
u64 meshOffset;
u32 flags;
padding[28];
float X, Y, Z;
float radius;
};
struct Positions {
float positions[3];
};
struct Normals {
float normal[3];
};
struct UVs {
s16 uv[2];
};
struct BoneIndices {
u8 boneindex[4];
};
struct Weights {
u16 weight[1];
};
struct MeshSCM {
u16 numberVertices;
u16 textureIndex;
padding[12];
u64 VerticesPositionsOffset;
u64 NormalsPositionsOffset;
u64 UVsPositionsOffset;
padding[16];
u64 unknownOffset;
u64;
padding[8];
Positions positions[numberVertices] @VerticesPositionsOffset;
Normals normals[numberVertices] @NormalsPositionsOffset;
UVs uvs[numberVertices] @UVsPositionsOffset;
};
struct Mesh {
u16 numberVertices;
u16 textureIndex;
padding[12];
u64 VerticesPositionsOffset;
u64 NormalsPositionsOffset;
u64 UVsPositionsOffset;
u64 BoneIndicesOffset;
u64 WeightsOffset;
padding[8];
u64;
padding[8];
Positions positions[numberVertices] @VerticesPositionsOffset;
Normals normals[numberVertices] @NormalsPositionsOffset;
UVs uvs[numberVertices] @UVsPositionsOffset;
BoneIndices b_index[numberVertices] @BoneIndicesOffset;
Weights weights[numberVertices] @WeightsOffset;
};
struct Hierarchy {
u8 hierarchy;
};
struct HierarchyOrder {
u8 hierarchyorder;
};
struct Unknown {
u8;
};
struct Transform {
float x;
float y;
float z;
float length; // sqrt(x*x + y*y + z*z)
padding[16];
};
struct Skeleton{
u32 hierarchyOffset;
u32 hierarchyOrderOffset;
u32 unknownOffset;
u32 transformsOffset;
};
ModelHeader modelheader @ 0x00;
ObjectInfo objects_info[modelheader.objectCount] @ 0x40;
u32 objectOffset;
struct Object {
u64 i = std::core::array_index();
if (modelheader.ID == "SCM ") {
objectOffset = objects_info[0].meshOffset;
MeshSCM meshscm[objects_info[i].meshCount] @ objects_info[i].meshOffset;
} else {
objectOffset = objects_info[0].meshOffset;
Mesh mesh[objects_info[i].meshCount] @ objects_info[i].meshOffset;
}
};
Object objects[modelheader.objectCount] @objectOffset;
Skeleton skeleton @modelheader.skeletonOffset;
Hierarchy hierarchy[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.hierarchyOffset);
HierarchyOrder hierarchyorder[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.hierarchyOrderOffset);
Unknown unknown[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.unknownOffset);
Transform transform[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.transformsOffset);

189
patterns/SHR.hexpat Normal file
View File

@@ -0,0 +1,189 @@
/*!
Apple IIgs Super Hi-Res (SHR) + PaintWorks Animation (ANI) — ImHex pattern
Supports:
• PIC $C1/$0000 — 32 KB uncompressed SHR screen image
• PIC $C1/$0002 — 3200-color (“Brooks”) per-scanline palettes
• ANI $C2/$0000 — PaintWorks animation:
0x0000..0x7FFF : base SHR $C1/$0000 image
0x8000.. : animation header + chunks
PaintWorks animation structure (per reversed docs):
- Base image: uncompressed SHR ($C1/$0000)
- +0x8000 u32: total animation data length after header (file_len - 0x8008)
- +0x8004 u16: global frame delay in VBLs
- +0x8006 u16: flag/? (commonly 0x00C0 or 0x00C1)
- +0x8008 ...: one or more animation chunks:
chunk:
u32 chunk_len (includes this length field)
repeated { u16 offset; u16 value; } pairs
offset==0x0000 marks End-of-Frame (value is ignored)
- Offsets may target any byte in the 32 KB SHR space (pixels, SCBs, palettes).
This enables palette-cycling and SCB effects.
References:
- CiderPress2 PaintWorks Animation notes (file structure, fields, semantics).
*/
import std.core;
import std.sys;
import std.math;
#pragma endian little
#include <std/mem.pat>
#pragma description Apple IIgs Super Hi-Res (SHR) + PaintWorks Animation (ANI)
#pragma author hasseily
// ------------------------------ Constants ------------------------------
const u32 SHR_ROWS = 200;
const u32 SHR_BYTES_PER_ROW = 160;
const u32 SHR_PIXEL_DATA_SIZE = SHR_ROWS * SHR_BYTES_PER_ROW; // 32000 (0x7D00)
const u32 PIC0000_FILE_SIZE = 0x8000; // 32768
const u32 PIC0002_FILE_SIZE = 0x9600; // 38400 (32000 + 200*32)
const u32 PIC0000_OFF_PIXELS = 0x0000;
const u32 PIC0000_OFF_SCB = 0x7D00;
const u32 PIC0000_OFF_RESERVED = 0x7DC8;
const u32 PIC0000_OFF_PALETTES = 0x7E00;
const u32 PALETTE_COUNT = 16;
const u32 PALETTE_COLORS = 16;
const u32 ANI_BASE_SHR_SIZE = 0x8000; // First 32 KB is a $C1/$0000 image
const u32 ANI_HDR_OFF = 0x8000; // Animation header starts here
const u32 ANI_MIN_TOTAL_SIZE = 0x8008; // base + header (no chunks)
// ------------------------------ Types: SHR core ------------------------------
struct Row160 { u8 data[SHR_BYTES_PER_ROW]; };
// Scanline Control Byte
bitfield ShrSCB {
palette : 4; // 0..15
reserved : 1;
color_fill : 1;
interrupt : 1;
mode_640 : 1; // 0=320, 1=640
};
// helper: expand a 4-bit channel to 8-bit (0x0..0xF -> 0x00..0xFF)
fn expand4(u8 v) { return (v << 4) | v; };
bitfield Colors_gb {
blue : 4; // Blue (B3..B0)
green : 4; // Green (G3..G0)
};
bitfield Colors_r0 {
red : 4; // Red (R3..R0)
unused : 4; // Unused / reserved
};
// RGB444 stored as 0RGB
struct Rgb444_0RGB {
Colors_gb gb;
Colors_r0 r0;
} [[color(std::format("{:02X}{:02X}{:02X}", expand4(r0.red), expand4(gb.green), expand4(gb.blue)))]];
struct Palette16 { Rgb444_0RGB color[PALETTE_COLORS]; };
// $C1/$0000 raw 32 KB screen dump
struct SHR_PIC0000 {
Row160 pixels[SHR_ROWS] @ PIC0000_OFF_PIXELS;
ShrSCB scb[SHR_ROWS] @ PIC0000_OFF_SCB;
u8 reserved[56] @ PIC0000_OFF_RESERVED;
Palette16 palettes[PALETTE_COUNT] @ PIC0000_OFF_PALETTES;
};
// “Brooks” 3200-color: pixels + 200 per-line palettes (no SCBs)
struct BrooksLinePalette { Rgb444_0RGB color[PALETTE_COLORS]; };
struct SHR_PIC0002 {
Row160 pixels[SHR_ROWS] @ 0x0000;
BrooksLinePalette line_palettes[SHR_ROWS] @ SHR_PIXEL_DATA_SIZE; // 0x7D00
};
// ------------------------------ Types: PaintWorks ANI ($C2/$0000) ------------------------------
/* Each operation modifies 1 word at an absolute offset in the 32 KB SHR area.
End-of-frame marker: offset == 0x0000 (value is ignored). */
struct AniOp {
u16 offset [[color("0000AA")]]; // 0x0000..0x7FFE valid; 0x0000 = End-of-Frame
u16 value [[color("00AAAA")]]; // word to store at [offset]
// For convenience in the sidebar:
bool is_eof = (offset == 0x0000);
};
// A contiguous animation chunk: length + packed AniOp pairs.
// Most files have exactly one chunk that spans all frames.
struct AniChunk {
u32 chunk_len; // includes this field
// ops_count = (chunk_len - 4)/4, unless chunk_len == 4
// in which case: (__file_size - 0x8000 - 12)/4
u64 ops_count64 =
(chunk_len == 4)
? ( (__file_size > (0x8000 + 12)) ? ((__file_size - 0x8000 - 12) / 4) : 0 )
: ( (chunk_len >= 4) ? (u64(chunk_len - 4) / 4) : 0 );
u32 ops_count = u32(ops_count64);
// ops start immediately after chunk_len (offset +4)
AniOp ops[ops_count];
};
// Header located at 0x8000 after the base 32 KB image
struct AniHeader {
u32 anim_data_len [[color("660000")]]; // total bytes of animation data after header
u16 frame_delay_vbl [[color("CC0000")]]; // global per-frame delay in VBLs (NTSC/PAL differ)
u16 flag_unknown; // usually 0x00C0 or 0x00C1
};
// Full PaintWorks animation container
struct ANI_PaintWorks {
// Base frame: a normal uncompressed SHR image
SHR_PIC0000 base @ 0x0000;
// Global animation header
AniHeader hdr @ ANI_HDR_OFF;
// One or more chunks, typically exactly one:
AniChunk chunks[ std::math::min(
u32(16), // cap to keep ImHex happy in pathological cases
u32((__file_size - (ANI_HDR_OFF + sizeof(AniHeader))) > 3 ?
1 + u32((__file_size - (ANI_HDR_OFF + sizeof(AniHeader))) / 0x10000000) :
1)
) ] @ (ANI_HDR_OFF + sizeof(AniHeader));
// Helpful computed values for inspection:
u64 file_len = __file_size;
u64 expected_anim_end = ANI_HDR_OFF + sizeof(AniHeader) + u64(hdr.anim_data_len);
};
// ------------------------------ Dispatcher ------------------------------
u64 __file_size = std::mem::size();
if (__file_size == PIC0000_FILE_SIZE) {
// Plain SHR dump
SHR_PIC0000 pic0000 @ 0x0000;
} else if (__file_size == PIC0002_FILE_SIZE) {
// Brooks 3200-color
SHR_PIC0002 pic0002 @ 0x0000;
} else if (__file_size >= ANI_MIN_TOTAL_SIZE) {
// Heuristic: treat as PaintWorks ANI if theres room for base+header.
// (Many PW ANI files use ProDOS type $C2/$0000.)
ANI_PaintWorks ani @ 0x0000;
} else if (__file_size >= SHR_PIXEL_DATA_SIZE) {
// Fallback: show pixels only for odd dumps
Row160 pixels_only[SHR_ROWS] @ 0x0000;
}
ANI_PaintWorks ani_paintworks_at_0 @ 0;

176
patterns/adtfdat.hexpat Normal file
View File

@@ -0,0 +1,176 @@
#pragma description ADTFDAT File
#pragma magic [ 49 46 48 44 ] @ 0x00
#pragma endian little
import std.io;
import std.mem;
import type.time;
enum FileVersion : u32 {
with_history_end_offset = 0x00000301,
v500 = 0x00000500
};
bitfield ChunkFlags {
key : 1;
info : 1;
marker : 1;
type : 1;
trigger : 1;
reserved: 11;
};
struct Extension
{
char identifier[384];
u16 stream_id;
u8 reserved1[2];
u32 user_id;
u32 type_id;
u32 version_id;
u64 data_pos;
u64 data_size;
u8 reserved[96];
u8 payload[data_size] @ data_pos;
};
struct ChunkHeader {
u64 time_stamp [[format("format_timestamp_with_offset")]];;
u32 ref_master_table_index;
u32 offset_to_last;
u32 size;
u16 stream_id;
ChunkFlags flags;
u64 stream_index;
};
struct SampleInfo {
u8 memory_layout_version;
u32 size;
u8 payload[size];
};
struct Sample {
s64 timestamp [[format("format_timestamp")]];;
s32 flags;
u64 buffer_size;
u8 payload[buffer_size];
if (flags & 0x100) {
SampleInfo sample_info;
}
if (flags & 0x200) {
u32 substream_id;
} else {
u32 substream_id = 0 [[export]];
}
};
struct Chunk {
auto start_address = $;
ChunkHeader header;
if (header.size < 32 || start_address + header.size > std::mem::size()) {
std::warning(std::format("Invalid header size {} in chunk {} at offset 0x{:X}, last valid chunk at 0x{:X}.", header.size, chunk_index, start_address, last_valid_chunk_offset));
break;
}
last_valid_chunk_offset = start_address;
u8 payload[header.size - 32];
if (!skip_valid_chunks) {
if (!header.flags.info && !header.flags.marker && !header.flags.type && !header.flags.trigger) {
try {
Sample sample @ addressof(payload);
} catch {
std::warning(std::format("Invalid sample payload at chunk {} at 0x{:X}", chunk_index, start_address));
}
}
}
chunk_index += 1;
// Padding with 0xEE to the next chunk header
std::mem::AlignTo<16>;
if (skip_valid_chunks) {
continue;
}
};
struct Header {
u32 file_id;
u32 version_id;
u32 flags;
u32 extension_count;
u64 extension_offset;
u64 data_offset;
u64 data_size;
u64 chunk_count;
u64 max_chunk_size;
u64 duration;
type::time64_t filetime;
u8 header_byte_order;
u64 time_offset [[format("format_timestamp")]];
u8 patch_number;
u64 first_chunk_offset;
u64 continuous_offset;
u64 ring_buffer_end_offset;
u8 reserved[30];
char description[1912];
};
struct IndexedFile {
Header header;
Extension extensions[header.extension_count] @ header.extension_offset;
if (header.version_id >= FileVersion::with_history_end_offset &&
header.continuous_offset != header.data_offset) {
try {
Chunk ring_front[while($ < header.continuous_offset)] @ header.first_chunk_offset;
Chunk ring_back[while($ < header.ring_buffer_end_offset)] @ header.data_offset;
Chunk continueous[header.chunk_count - chunk_index] @ header.continuous_offset;
} catch {
std::warning("Too many chunks. Performing check only.");
skip_valid_chunks = true;
chunk_index = 0;
Chunk ring_front[while($ < header.continuous_offset)] @ header.first_chunk_offset;
Chunk ring_back[while($ < header.ring_buffer_end_offset)] @ header.data_offset;
Chunk continueous[while(chunk_index < header.chunk_count)] @ header.continuous_offset;
}
} else {
try {
Chunk chunks[header.chunk_count] @ header.data_offset;
} catch {
std::warning("Too many chunks. Performing check only.");
skip_valid_chunks = true;
chunk_index = 0;
Chunk chunks[while(chunk_index < header.chunk_count)] @ header.data_offset;
}
}
};
fn format_timestamp(u64 data) {
double seconds = 0;
if (file.header.version_id < FileVersion::v500) {
// microseconds
seconds = data / double(1000000);
} else {
// nanoseconds
seconds = data / double(1000000000);
}
std::time::Time time64 = std::time::to_utc(seconds);
return std::time::format(time64);
};
fn format_timestamp_with_offset(u64 data) {
return format_timestamp(data + file.header.time_offset);
};
bool skip_valid_chunks = false;
u64 last_valid_chunk_offset = 0;
u64 chunk_index = 0;
IndexedFile file @ 0x00;

View File

@@ -1,14 +1,13 @@
#pragma authors: zhoubo
#pragma version: 0.4
#pragma description: Parse AAC's ADTS(Audio Data Transport Stream) audio files.
#pragma category: Audio
#pragma filemask: *.aac
#pragma IDBytes: FF F //ADTS Syncword
#pragma history:
#pragma 0.4 2024-02-12 zhoubo: Porting from 010 Editor Templates.
#pragma 0.3 2024-02-09 zhoubo: use BitfieldDisablePadding(Unpadded Bitfields) for odd header bytes(7,9 bytes) color, and remove FSeek.
#pragma 0.2 2024-02-05 zhoubo: fix some comment & color.
#pragma 0.1 2022-06-13 zhoubo: Init release. only ADTS, not support ADIF,LATM.
#pragma author zhoubo
#pragma description AAC ADTSn (Audio Data Transport Stream) Audio
#pragma MIME audio/x-hx-aac-adts
#pragma pattern_limit 0xFFFFFF
// History
// 0.4 2024-02-12 zhoubo: Porting from 010 Editor Templates.
// 0.3 2024-02-09 zhoubo: use BitfieldDisablePadding(Unpadded Bitfields) for odd header bytes(7,9 bytes) color, and remove FSeek.
// 0.2 2024-02-05 zhoubo: fix some comment & color.
// 0.1 2022-06-13 zhoubo: Init release. only ADTS, not support ADIF,LATM.
// More information available at:
// 1. https://wiki.multimedia.cx/index.php?title=ADTS

View File

@@ -1,6 +1,10 @@
#pragma author WerWolv
#pragma description Nintendo Switch Atmosphère CFW Fatal Error log
#pragma magic [ 41 46 45 30 ] @ 0x00
#pragma magic [ 41 46 45 31 ] @ 0x00
#pragma magic [ 41 46 45 32 ] @ 0x00
#pragma endian little
import std.io;
@@ -52,8 +56,8 @@ std::assert(ctx.magic == ATMOSPHERE_REBOOT_TO_FATAL_MAGIC ||
ctx.magic == ATMOSPHERE_REBOOT_TO_FATAL_MAGIC_1 ||
ctx.magic == ATMOSPHERE_REBOOT_TO_FATAL_MAGIC_0,
"File is not a valid Atmosphere fatal error binary!");
std::assert_warn(ctx.magic == ATMOSPHERE_REBOOT_TO_FATAL_MAGIC,
std::assert_warn(ctx.magic == ATMOSPHERE_REBOOT_TO_FATAL_MAGIC,
"Atmosphere fatal error binary is for an older version!");

View File

@@ -36,7 +36,12 @@ struct RiffChunk {
u32 size;
if (signature == "RIFF" || signature == "LIST") {
char type[4];
RiffChunk chunks[while($ - addressof(type) < size)];
// Compatible with error size defined in ani files
u32 remain = sizeof($) - addressof(type);
u32 marked = size > remain ? remain : size;
RiffChunk chunks[while($ - addressof(type) < marked)];
} else if (signature[0] == 'I' && parent.type == "INFO") {
char info[size];
} else if (signature == "anih") {

View File

@@ -0,0 +1,50 @@
#pragma author Lexi Mayfield
#pragma description AppleSingle/AppleDouble file format
#pragma endian big
#pragma magic [00 05 16 0?] @ 0x00
import type.magic;
enum EntryID : u32 {
DataFork = 1,
ResourceFork = 2,
RealName = 3,
Comment = 4,
IconBW = 5,
IconColor = 6,
FileDatesInfo = 8,
FinderInfo = 9,
MacFileInfo = 10,
ProDOSFileInfo = 11,
MSDOSFileInfo = 12,
ShortName = 13,
AFPFileInfo = 14,
DirectoryID = 15,
};
struct Entry {
EntryID entryID;
u32 offset;
u32 length;
u8 data[length] @ offset [[sealed]];
};
enum FileType : u32 {
AppleSingle = 0x00051600,
AppleDouble = 0x00051607,
};
enum Version : u32 {
V1 = 0x00010000,
V2 = 0x00020000,
};
struct AppleSingleDouble {
FileType fileType;
Version version;
char homeFileSystem[16];
u16 numEntries;
Entry entryDescs[numEntries];
};
AppleSingleDouble appleSingleDouble @ 0x00;

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description Static library archive files
#pragma description GNU Static library archive
#pragma MIME application/x-archive
@@ -15,7 +15,7 @@ struct ARFile {
char file_mode[8];
char file_size[10];
u16 end_marker;
if (end_marker == 0x0A60) {
u8 data[std::string::parse_int(this.file_size, 10)];
padding[sizeof(data) & 1];
@@ -23,6 +23,9 @@ struct ARFile {
};
char signature[8] @ 0x00;
if (signature == "!<arch>\r") {
std::error("Archive file got corrupted due to CRLF line ending conversion!");
}
std::assert(signature == "!<arch>\n", "File is not a valid archive!");
ARFile files[while($ < std::mem::size())] @ $;

26
patterns/arc.hexpat Normal file
View File

@@ -0,0 +1,26 @@
#pragma author DexrnZacAttack
#pragma description Minecraft LCE ARC File
#pragma endian big
import std.string;
#ifdef __IMHEX__
import hex.core;
#endif
struct Table {
u16 nameSize;
char fileName[nameSize];
u32 offset;
u32 size;
u8 file[size] @ offset;
#ifdef __IMHEX__
hex::core::add_virtual_file(fileName, file);
#endif
} [[name(std::string::to_string(fileName))]];
struct ARC {
u32 count;
Table table[count];
};
ARC arc @ 0x00;

View File

@@ -40,21 +40,21 @@ VectorTable vector_table @ VTOR;
fn main() {
u32 table_size = sizeof(vector_table);
u32 default_handler_address = 0x00;
for (u32 i = 4, i < table_size, i = i + 4) {
u32 occurrences = 0;
for (u32 j = 4, j < table_size, j = j + 4) {
if (std::mem::read_unsigned(i, 4) == std::mem::read_unsigned(j, 4)) {
occurrences = occurrences + 1;
if (occurrences > 1)
default_handler_address = std::mem::read_unsigned(i, 4);
}
}
}
if (default_handler_address != 0x00)
std::print("Default Handler implementation at 0x{:08X}", default_handler_address);
};

168
patterns/bcss.hexpat Normal file
View File

@@ -0,0 +1,168 @@
#pragma author ttimasdf
#pragma description BeyondCompare Snapshot (BCSS) file
#pragma magic [42 43 53 53] @ 0x00
#pragma array_limit 4294967295
#pragma pattern_limit 4294967295
import std.io;
import std.mem;
import std.array;
import std.string;
import type.magic;
#ifdef __IMHEX__
import hex.dec;
import hex.core;
#endif
const u8 max_path_size = 1000;
str current_path[max_path_size];
u8 current_path_level = 0;
enum EntryType : u8 {
DIRECTORY = 0x01,
FILE = 0x02,
SYMLINK = 0x03,
// NULL = 0x00,
DIR_END = 0xFF,
};
struct BCSSEntry {
EntryType type;
match (type) {
(EntryType::DIRECTORY) : {
// FileName name;
std::string::SizedString<u8> name;
if (name.size != 0) {
u8 unknown[12];
on_dir_enter(name.data); // std::string::to_string(name)
} else {
// some buggy edge cases
u8 unknown[6];
std::warning(std::format("invalid empty entry current_lvl={} current_pos=0x{:02x}", current_path_level, $));
}
}
(EntryType::FILE) : {
std::string::SizedString<u8> name;
if (name.size != 0) {
u8 unknown[20];
#ifdef __IMHEX__
hex::core::add_virtual_file(get_vfs_path(name), this); // std::string::to_string(name)
#endif
} else {
// some buggy edge cases
u8 unknown[6];
std::warning(std::format("invalid empty entry current_lvl={} current_pos=0x{:02x}", current_path_level, $));
}
//try {
// u8 unknown[20];
//} catch {
// u8 unknown[0];
//}
}
(EntryType::SYMLINK) : {
std::string::SizedString<u8> name;
u8 unknown[23];
std::string::SizedString<u8> target;
#ifdef __IMHEX__
hex::core::add_virtual_file(get_vfs_path(name + " [s]"), this); // std::string::to_string(name)
#endif
}
(EntryType::DIR_END) : {
on_dir_exit();
}
// (EntryType::NULL) : {
// // some buggy edge cases
// u8 unknown[7];
// std::warning(std::format("invalid empty entry current_lvl={} current_pos=0x{:02x}", current_path_level, $));
// }
(_): {
std::error(std::format("unknown EntryType idx={} current_pos=0x{:02x}", std::core::array_index(), $));
}
}
}[[format_read("fmt_BCSSEntry")]];
fn on_dir_enter(str folder_name) {
// std::print("on_dir_enter folder={} current_lvl={}", folder_name, current_path_level);
if (std::string::length(folder_name) > 0) {
current_path[current_path_level] = folder_name;
current_path_level += 1;
} else {
std::warning(std::format("invalid folder name {} current_lvl={} current_pos=0x{:02x}", folder_name, current_path_level, $));
}
};
fn on_dir_exit() {
if (current_path_level > 0) {
current_path_level -= 1;
} else if (!std::mem::eof()) {
std::warning(std::format("on_dir_exit current_lvl already == 0 current_pos=0x{:02x}", $));
}
// std::print("on_dir_exit current_lvl={}", current_path_level);
};
fn get_vfs_path(str file_name) {
str vfs_path = "";
if (current_path_level > 0) {
vfs_path = current_path[0];
for(u8 i = 1, i < current_path_level, i += 1) {
//hash_hex = hash_hex + std::format("{:02X}",bytes[i]);
vfs_path = vfs_path + "/" + current_path[i];
}
return vfs_path + "/" + file_name;
} else {
return file_name;
}
};
fn fmt_BCSSEntry(BCSSEntry e) {
try {
match (e.type) {
(EntryType::DIRECTORY | EntryType::FILE) : {
return std::format("{}: {}", (e.type == EntryType::DIRECTORY ? "Dir" : "File"), e.name.data);
}
(EntryType::SYMLINK) : {
return std::format("Symlink: {} -> {}", e.name.data, e.target.data);
}
(EntryType::DIR_END) : {
return "Directory End";
}
}
} catch {
return "[FmtErr]";
}
};
struct BCSSFile {
if (std::mem::read_unsigned(0, 4) == 0x53534342) {
type::Magic<"BCSS"> magic;
u8 unknown[14];
std::string::SizedString<u16> root_path;
u8 zlib_content[std::mem::size()-$];
// manually add zlib header which is essential for hex::dec::zlib_decompress
const str zlib_header = "\x78\x9c";
std::mem::Section zlib_compressed = std::mem::create_section("zlib_compressed");
std::mem::copy_value_to_section(zlib_header, zlib_compressed, 0);
std::mem::copy_value_to_section(zlib_content, zlib_compressed, 2);
u8 zlib[std::mem::get_section_size(zlib_compressed)] @ 0x00 in zlib_compressed;
#ifdef __IMHEX__
std::mem::Section zlib_decompressed = std::mem::create_section("zlib_decompressed");
hex::dec::zlib_decompress(zlib, zlib_decompressed, 15);
u8 decompressed_content[std::mem::get_section_size(zlib_decompressed)] @ 0x00 in zlib_decompressed;
hex::core::add_virtual_file("bcss_content", decompressed_content);
std::warning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! BCSS file content is compressed !\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nopen `bcss_content` file from the Virtual Filesystem tab and run this pattern on it.");
#endif
} else {
BCSSEntry entries[while(!std::mem::eof())];
}
};
BCSSFile bcss_file @ 0x00;

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description Bencode encoding, used by Torrent files
#pragma description Torrent data (Bencode)
#pragma MIME application/x-bittorrent
@@ -8,20 +8,20 @@ import std.mem;
import std.string;
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',
@@ -33,30 +33,39 @@ namespace bencode {
String8 = '8',
String9 = '9'
};
struct String {
ASCIIDecimal length;
char separator [[hidden]];
char value[length];
} [[sealed, format("bencode::format_string"), transform("bencode::format_string")]];
} [[sealed, format("bencode::format_string")]];
fn format_string(String string) {
return string.value;
for (u64 i = 0, i < string.length, i = i + 1) {
if (!std::ctype::isprint(string.value[i])) {
return "Contains non-printable characters";
}
}
return std::format("\"{}\"", 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')];
DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')];
char end;
} else if (type == Type::List) {
Value entry[while(std::mem::read_unsigned($, 1) != 'e')];
char end;
} else if (type == Type::Integer) {
ASCIIDecimal value;
char end;
@@ -65,12 +74,12 @@ namespace bencode {
String value;
}
};
struct Bencode {
Value value[while(!std::mem::eof())] [[inline]];
Value value[while(!std::mem::eof())] [[inline]];
char end;
};
}
bencode::Bencode bencode @ 0x00;

View File

@@ -1,80 +1,101 @@
#pragma author Shadlock0133 (aka Aurora)
#pragma description Binary G-Code from Prusa
#pragma author Shadlock0133 (aka Aurora) / WerWolv
#pragma description Prusa Binary G-Code
#pragma magic [ 47 43 44 45 ] @ 0x00
#include <type/magic.pat>
#include <std/mem.pat>
import type.magic;
import std.mem;
enum ChecksumType : u16 {
None,
CRC32,
None = 0,
CRC32 = 1
};
enum BlockType : u16 {
FileMetadata,
GCode,
SlicerMetadata,
PrinterMetadata,
PrintMetadata,
Thumbnail,
FileMetadata = 0,
GCode = 1,
SlicerMetadata = 2,
PrinterMetadata = 3,
PrintMetadata = 4,
Thumbnail = 5
};
enum Compression : u16 {
None,
Deflate,
Heatshrink11_4,
Heatshrink12_4,
enum CompressionType : u16 {
NoCompression = 0,
Deflate = 1,
HeatshrinkWindowSize11 = 2,
HeatshrinkWindowSize12 = 3
};
struct BlockHeader {
BlockType type;
CompressionType compressionType;
u32 uncompressedSize;
if (compressionType != CompressionType::NoCompression) {
u32 compressedSize;
}
u32 dataSize = compressionType == CompressionType::NoCompression ? uncompressedSize : compressedSize;
};
enum Encoding : u16 {
Ini,
INI = 0
};
struct Metadata {
Encoding encoding;
char data[parent.header.dataSize];
};
enum ImageFormat : u16 {
Png,
Jpg,
Qoi,
PNG = 0,
JPG = 1,
QOI = 2
};
struct Header {
struct Thumbnail {
ImageFormat format;
u16 width, height;
std::mem::Bytes<parent.header.dataSize> imageData;
} [[hex::visualize("image", imageData)]];
enum GCodeEncoding : u16 {
NoEncoding = 0,
MeatPack = 1,
MeatPackWithComments = 2
};
struct GCode {
GCodeEncoding encoding;
std::mem::Bytes<parent.header.dataSize> gcode;
};
struct Block {
BlockHeader header;
match (header.type) {
(BlockType::FileMetadata): Metadata fileMetadata;
(BlockType::PrinterMetadata): Metadata printerMetadata;
(BlockType::Thumbnail): Thumbnail thumbnail;
(BlockType::PrintMetadata): Metadata printMetadata;
(BlockType::SlicerMetadata): Metadata slicerMetadata;
(BlockType::GCode): GCode gcode;
(_): std::error("Invalid Block type!");
}
if (parent.checksumType != ChecksumType::None)
u32 checksum;
};
struct BGCode {
type::Magic<"GCDE"> magic;
u32 version;
ChecksumType checksum_type;
};
Header header @ 0;
std::assert(header.version == 1, "only version 1 supported");
std::assert(version == 1, "Only Version 1 is supported");
struct Block {
BlockType type;
Compression compression;
u32 uncompressed_size;
auto size = uncompressed_size;
if (compression != Compression::None) {
u32 compressed_size;
size = compressed_size;
}
match (type) {
(BlockType::FileMetadata
| BlockType::PrinterMetadata
| BlockType::PrintMetadata
| BlockType::SlicerMetadata): {
Encoding encoding;
}
(BlockType::Thumbnail): {
ImageFormat image_format;
u16 width;
u16 height;
}
(BlockType::GCode): {
u16;
}
(_): { std::assert(false, "unknown type"); }
}
u8 data[size];
match (header.checksum_type) {
(ChecksumType::None): {}
(ChecksumType::CRC32): { u32 checksum; }
}
ChecksumType checksumType;
Block blocks[while(!std::mem::eof())];
};
Block blocks[while(!std::mem::eof())] @ $;
BGCode bgcode @ 0x00;

24
patterns/binka.hexpat Normal file
View File

@@ -0,0 +1,24 @@
#pragma author DexrnZacAttack
#pragma description RAD Game Tools BINKA (Bink Audio)
#pragma magic [31 46 43 42] @ 0x00
import std.string;
import std.math;
import type.magic;
fn getDuration(u32 duration_ts, u32 sample_rate) {
return float(duration_ts) / float(sample_rate);
};
struct Binka {
type::Magic<"1FCB"> magic;
u8; // can't get this to change anything when using ffprobe
u8 channel_count [[name(std::format("Channel Count: {}", this))]];
u16 sample_rate [[name(std::format("Sample Rate: {}", this))]];
u32 duration_ts [[name(std::format("Duration: {}s", std::math::floor(getDuration(this, sample_rate))))]];
u32;
u32 size [[name(std::format("File Size: {} bytes", this))]];
u8 data[size - 20];
};
Binka binka @ 0x00;

196
patterns/blend.hexpat Normal file
View File

@@ -0,0 +1,196 @@
#pragma description Blender file
#pragma magic [42 4C 45 4E 44 45 52] @ 0x00
/*
* References:
* https://projects.blender.org/blender/blender
* https://github.com/facebook/zstd/blob/master/contrib/seekable_format/zstd_seekable_compression_format.md
*
* Refer to the following files/structs:
* source/blender/blenloader/intern/writefile.cc
* source/blender/blenkernel/BKE_main.hh BlendThumbnail
* source/blender/makesdna/DNA_sdna_types.h BHead
*/
// Increased the pattern limit to be able to evaluate all pixels of the embedded thumbnail.
#pragma pattern_limit 1000000
#ifdef __IMHEX__
import hex.dec;
#endif
import std.core;
import std.io;
import std.mem;
import std.string;
import std.sys;
import type.color;
import type.magic;
// Useful for extracting the thumbnail if the rest of the blend file is corrupted or truncated.
bool quitAfterThumbnailIsParsed in;
// Allow the pattern evaluator to skip the thumbnail e.g. if evaluation takes too long.
bool skipThumbnail in;
struct BHead<Ptr> {
char code[4];
s32 len;
Ptr old;
s32 SDNAnr;
s32 nr;
// ENDB marks the last data block in the file.
if (code == "ENDB") {
break;
}
};
struct ThumbnailLine<auto width> {
type::RGBA8 pixels[width];
};
fn copyThumbnail(u32 height, ref auto lines, std::mem::Section target) {
for (s64 l = (height - 1), l >= 0, l = l - 1) {
u64 currentSectionSize = std::mem::get_section_size(target);
// Append the current line to section.
std::mem::copy_value_to_section(lines[l], target, currentSectionSize);
}
};
struct Thumbnail {
u32 width;
u32 height;
u128 size = width * height;
ThumbnailLine<width> lines[height];
// Generate the thumbnail section.
std::mem::Section thumbnailFlipped = std::mem::create_section("thumbnail");
copyThumbnail(height, lines, thumbnailFlipped);
type::RGBA8 image[size] @ 0x00 in thumbnailFlipped;
}
#ifdef __IMHEX__
[[hex::visualize("bitmap", image, width, height)]]
#endif
;
struct DataBlock<Ptr> {
BHead<Ptr> bHead;
if (bHead.SDNAnr == 0 && bHead.code == "TEST") {
if (skipThumbnail) {
u8 thumbnail[bHead.len]; // Interpret as raw binary data.
} else {
Thumbnail thumbnail;
auto thumbnailSize = sizeof(thumbnail);
std::assert(thumbnailSize == bHead.len,
std::format("The thumbnail (size={:#x}) does not fit exactly into its DataBlock (len={:#x})!",
thumbnailSize, bHead.len));
}
if (quitAfterThumbnailIsParsed) {
break;
}
} else {
u8 data[bHead.len]; // Unknown. Interpret as raw binary data.
}
};
enum PointerSize : char {
POINTER_4BYTE = '_',
POINTER_8BYTE = '-'
};
enum Endianness : char {
BIG_ENDIAN = 'V',
LITTLE_ENDIAN = 'v'
};
struct Blend<auto inputSize> {
type::Magic<"BLENDER"> magic;
PointerSize pointerSize;
Endianness endianness;
char version[3];
match (endianness) {
(Endianness::LITTLE_ENDIAN): std::core::set_endian(std::mem::Endian::Little);
(Endianness::BIG_ENDIAN): std::core::set_endian(std::mem::Endian::Big);
(_): std::error("Invalid value for endianness!");
}
match (pointerSize) {
(PointerSize::POINTER_4BYTE): DataBlock<u32> dataBlock[while($ < inputSize)];
(PointerSize::POINTER_8BYTE): DataBlock<u64> dataBlock[while($ < inputSize)];
(_): std::error("Invalid pointer size!");
}
};
struct BlendWrapper {
u128 currentPos = $;
char magic[4] @ currentPos [[hidden]];
if (magic != "\x28\xB5\x2F\xFD") { // ZSTD magic
// Assume the blend file is uncompressed.
Blend<sizeof($)> blend @ currentPos;
return;
}
} [[inline]];
BlendWrapper blendWrapper @ 0x00;
// Assume the blend file is ZSTD compressed.
struct SeekTableFooter {
u32 numFrames;
char flag;
type::Magic<"\xB1\xEA\x92\x8F"> footerMagic;
};
u128 seekTableFooterSize = 9;
SeekTableFooter seekTableFooter @ (sizeof($) - seekTableFooterSize);
struct SeekTableEntry {
u32 compressedSize;
u32 uncompressedSize;
};
u128 seekTableEntrySize = 8;
SeekTableEntry seekTableEntries[seekTableFooter.numFrames]
@ (addressof(seekTableFooter) - seekTableFooter.numFrames * seekTableEntrySize);
struct SeekTableHeader {
type::Magic<"\x5E\x2A\x4D\x18"> magic;
u32 frameSize;
};
u128 seekTableHeaderSize = 8;
std::assert(seekTableFooter.numFrames > 0, "The seek table must contain entries!");
SeekTableHeader seekTableHeader @ (addressof(seekTableEntries[0]) - seekTableHeaderSize);
u32 frameIndex = 0;
struct ZSTDFrame {
u8 data[seekTableEntries[frameIndex].compressedSize];
frameIndex = frameIndex + 1;
};
ZSTDFrame zstdFrames[seekTableFooter.numFrames] @ 0x00;
#ifdef __IMHEX__
std::mem::Section decompressedSection = std::mem::create_section("decompressedBlend");
u128 previousSectionSize = 0;
for (u32 i = 0, i < seekTableFooter.numFrames, i = i + 1) {
std::assert(hex::dec::zstd_decompress(zstdFrames[i].data, decompressedSection),
"Decompression failed!");
u32 uncompressedSize = seekTableEntries[i].uncompressedSize;
u128 currentSectionSize = std::mem::get_section_size(decompressedSection)
- previousSectionSize;
std::assert_warn(uncompressedSize == currentSectionSize,
std::format("The uncompressedSize {} for ZSTDFrame #{} "
+ "must be equal to its actual decompressed size{}!",
uncompressedSize, i, currentSectionSize));
previousSectionSize += currentSectionSize;
};
Blend<previousSectionSize> blend @ 0x00 in decompressedSection;
#endif

533
patterns/blf.hexpat Normal file
View File

@@ -0,0 +1,533 @@
// Pattern for binary logging files (Vector BLF)
// References used for writing this:
// https://python-can.readthedocs.io/en/stable/_modules/can/io/blf.html
// https://bitbucket.org/tobylorenz/vector_blf
#pragma magic [ 4C 4F 47 47 ] @ 0x00
#pragma description Vector BLF Frame Logging Files
#pragma array_limit 4194304
#pragma pattern_limit 4294967296
#pragma endian little
import hex.dec;
import std.io;
import type.magic;
enum object_type : u32 {
unknown = 0, //< unknown object
can_message = 1, //< CAN message object
can_error = 2, //< CAN error frame object
can_overload = 3, //< CAN overload frame object
can_statistic = 4, //< CAN driver statistics object
app_trigger = 5, //< application trigger object
env_integer = 6, //< environment integer object
env_double = 7, //< environment double object
env_string = 8, //< environment string object
env_data = 9, //< environment data object
log_container = 10, //< container object
lin_message = 11, //< LIN message object
lin_crc_error = 12, //< LIN CRC error object
lin_dlc_info = 13, //< LIN DLC info object
lin_rcv_error = 14, //< LIN receive error object
lin_snd_error = 15, //< LIN send error object
lin_slv_timeout = 16, //< LIN slave timeout object
lin_sched_modch = 17, //< LIN scheduler mode change object
lin_syn_error = 18, //< LIN sync error object
lin_baudrate = 19, //< LIN baudrate event object
lin_sleep = 20, //< LIN sleep mode event object
lin_wakeup = 21, //< LIN wakeup event object
most_spy = 22, //< MOST spy message object
most_ctrl = 23, //< MOST control message object
most_lightlock = 24, //< MOST light lock object
most_statistic = 25, //< MOST statistic object
flexray_data = 29, //< FLEXRAY data object
flexray_sync = 30, //< FLEXRAY sync object
can_driver_error = 31, //< CAN driver error object
most_pkt = 32, //< MOST Packet
most_pkt2 = 33, //< MOST Packet including original timestamp
most_hwmode = 34, //< MOST hardware mode event
most_reg = 35, //< MOST register data (various chips)
most_genreg = 36, //< MOST register data (MOST register)
most_netstate = 37, //< MOST NetState event
most_datalost = 38, //< MOST data lost
most_trigger = 39, //< MOST trigger
flexray_cycle = 40, //< FLEXRAY V6 start cycle object
flexray_message = 41, //< FLEXRAY V6 message object
lin_checksum_info = 42, //< LIN checksum info event object
lin_spike_event = 43, //< LIN spike event object
can_driver_sync = 44, //< CAN driver hardware sync
flexray_status = 45, //< FLEXRAY status event object
gps_event = 46, //< GPS event object
flexray_error = 47, //< FLEXRAY error event object
flexray_status = 48, //< FLEXRAY status event object
flexray_startcycle = 49, //< FLEXRAY start cycle event object
flexray_rcv_message = 50, //< FLEXRAY receive message event object
realtime_clock = 51, //< Realtime clock object
lin_statistic = 54, //< LIN statistic event object
j1708_message = 55, //< J1708 message object
j1708_virtual_message = 56, //< J1708 message object with more than 21 data bytes
lin_message2 = 57, //< LIN frame object - extended
lin_snd_error2 = 58, //< LIN transmission error object - extended
lin_syn_error2 = 59, //< LIN sync error object - extended
lin_crc_error2 = 60, //< LIN checksum error object - extended
lin_crv_error2 = 61, //< LIN receive error object
lin_wakeup2 = 62, //< LIN wakeup event object - extended
lin_spike_event2 = 63, //< LIN spike event object - extended
lin_long_dom_sig = 64, //< LIN long dominant signal object
app_text = 65, //< text object
flexray_rcvmessage_ex = 66, //< FLEXRAY receive message ex event object
most_statistic_ex = 67, //< MOST extended statistic event
most_txlight = 68, //< MOST TxLight event
most_alloctab = 69, //< MOST Allocation table event
most_stress = 70, //< MOST Stress event
ethernet_frame = 71, //< Ethernet frame object
sys_variable = 72, //< system variable object
can_error_ext = 73, //< CAN error frame object (extended)
can_driver_error_ext = 74, //< CAN driver error object (extended)
lin_long_dom_sig2 = 75, //< LIN long dominant signal object - extended
most_150_message = 76, //< MOST150 Control channel message
most_150_pkt = 77, //< MOST150 Asynchronous channel message
most_ethernet_pkt = 78, //< MOST Ethernet channel message
most_150_message_fragment = 79, //< Partial transmitted MOST50/150 Control channel message
most_150_pkt_fragment = 80, //< Partial transmitted MOST50/150 data packet on asynchronous channel
most_ethernet_pkt_fragment = 81, //< Partial transmitted MOST Ethernet packet on asynchronous channel
most_system_event = 82, //< Event for various system states on MOST
most_150_alloctab = 83, //< MOST50/150 Allocation table event
most_50_message = 84, //< MOST50 Control channel message
most_50_pkg = 85, //< MOST50 Asynchronous channel message
can_message2 = 86, //< CAN message object - extended
lin_unexpected_wakeup = 87,
lin_short_or_slow_response = 88,
lin_disturbance_event = 89,
serial_event = 90,
overrun_error = 91, //< driver overrun event
event_comment = 92,
wlan_frame = 93,
wlan_statistic = 94,
most_ecl = 95, //< MOST Electrical Control Line event
global_marker = 96,
afdx_frame = 97,
afdx_statistic = 98,
kline_statusevent = 99, //< E.g. wake-up pattern
can_fd_message = 100, //< CAN FD message object
can_fd_message_64 = 101, //< CAN FD message object
ethernet_rx_error = 102, //< Ethernet RX error object
ethernet_status = 103, //< Ethernet status object
can_fd_error_64 = 104, //< CAN FD Error Frame object
lin_short_or_slow_response2 = 105,
afdx_status = 106, //< AFDX status object
afdx_bus_statistic = 107, //< AFDX line-dependent busstatistic object
afdx_error_event = 109, //< AFDX asynchronous error event
a429_error = 110, //< A429 error object
a429_status = 111, //< A429 status object
a429_bus_statistic = 112, //< A429 busstatistic object
a429_message = 113, //< A429 Message
ethernet_statistic = 114, //< Ethernet statistic object
restore_point_container = 115, //< Restore point container, use unknown
test_structure = 118, //< Event for test execution flow
diag_request_information = 119, //< Event for correct interpretation of diagnostic requests
ethernet_frame_ex = 120, //< Ethernet packet extended object
ethernet_frame_forwarded = 121, //< Ethernet packet forwarded object
ethernet_error_ex = 122, //< Ethernet error extended object
ethernet_error_forwarded = 123, //< Ethernet error forwarded object
function_bus = 124, //< FunctionBus object
data_lost_begin = 125, //< Data lost begin
data_lost_end = 126, //< Data lost end
water_mark_event = 127, //< Watermark event
trigger_condition = 128, //< Trigger Condition event
can_setting_changed = 129, //< CAN Settings Changed object
distributed_object_member = 130, //< Distributed object member (communication setup)
attribute_event = 131, //< ATTRIBUTE event (communication setup)
};
bitfield can_msg_flags {
is_tx : 1;
padding : 4;
nerr : 1;
wu : 1;
rtr : 1;
};
struct can_msg {
u16 channel;
can_msg_flags flags;
u8 dlc;
u32 id;
u8 data[8];
};
struct can_msg2 {
u16 channel;
can_msg_flags flags;
u8 dlc;
u32 id;
auto struct_len = 2 + 1 + 1 + 4 + 4 + 1 + 1 + 2; // TODO: Alternative way of doing this?
u8 data[parent.header.object_size - parent.header.header_size - struct_len];
// The frame length in nanoseconds
u32 frame_length;
// Total number of bits of the CAN frame
u8 bit_count;
padding[1];
padding[2];
};
bitfield can_fd_msg_flags {
edl : 1; //< Extended data length
brs : 1; //< Bit rate switch
esi : 1; //< Error state indicator
padding : 5;
};
fn format_can_fd_dlc(u8 dlc) {
if (dlc > 8)
return 8 + (dlc - 8) * 4;
return dlc;
};
struct can_fd_msg {
u16 channel;
u8 flags;
u8 dlc [[format("format_can_fd_dlc")]];
u32 id;
// The frame length in nanoseconds
u32 frame_length;
u8 arbitration_bit_count;
can_fd_msg_flags fd_flags;
u8 valid_data_bytes;
padding[1];
padding[4];
u8 data[64];
padding[4];
};
bitfield can_fd_msg_64_flags {
padding : 2;
nerr : 1;
hv_wake_up : 1;
remote_frame : 1;
padding : 1;
tx_ack : 1;
tx_req : 1;
padding : 1;
srr : 1;
r0 : 1;
r1 : 1;
edl : 1; //< Extended data length
brs : 1; //< Bit rate switch
esi : 1; //< Error state indicator
padding : 2;
burst : 1;
padding : 13;
};
struct can_bitrate_cfg {
u8 quartz_frequency;
u8 prescaler;
u8 btl_cycles;
u8 sampling_point;
};
struct can_fd_msg_64 {
u8 channel;
u8 dlc [[format("format_can_fd_dlc")]];
u8 valid_data_bytes;
u8 tx_count;
u32 id;
u32 frame_length;
can_fd_msg_64_flags flags;
can_bitrate_cfg arbitration_bitrate;
can_bitrate_cfg data_bitrate;
u32 brs_time_offset;
u32 crc_time_offset;
u16 bit_length;
u8 direction;
u8 data_offset;
u32 crc;
u8 data[valid_data_bytes];
};
fn format_bus_load(u16 bus_load) {
return std::format("{}%", float(bus_load) / 100.f);
};
struct can_statistic {
u16 channel;
// Bus load in 1/100 percent
u16 bus_load [[format("format_bus_load")]];
u32 standard_data_frames;
u32 extended_data_frames;
u32 standard_remote_frames;
u32 extended_remote_frames;
u32 error_frames;
u32 overload_frames;
u32 reserved;
};
struct can_driver_error {
u16 channel;
u8 tx_errors;
u8 rx_errors;
u32 error_code;
};
enum app_text_source : u32 {
comment = 0,
database_info = 1,
metadata = 2,
};
enum database_bus_type : u8 {
can = 1,
lin = 5,
most = 6,
flexray = 7,
j1708 = 9,
ethernet = 10,
wlan = 13,
afdx = 14,
};
bitfield app_text_database_info {
version : 8;
channel_num : 8;
database_bus_type bus_type : 8;
is_can_fd : 1;
padding : 7;
};
struct app_text {
app_text_source source;
if (source == 1)
app_text_database_info database_info;
else
padding[4]; // TODO: This is not necessarily padding, there's data here
u32 text_length;
padding[4];
char text[text_length];
};
// No idea what this is or does
struct restore_point_container {
u8 rpc[14];
u16 data_len;
u8 data[data_len];
};
enum compression_method : u16 {
no_compression = 0,
zlib = 2,
};
// The following section contains all of the decompressed data at once
std::mem::Section decompressed_data = std::mem::create_section("Decompressed data");
// This section is used only for decompressing data
std::mem::Section zlib_decompress_result = std::mem::create_section("zlib decompress result");
struct log_container {
u64 container_begin = $;
compression_method compression_method;
padding[2];
padding[4];
u32 uncompressed_size;
padding[4];
if (compression_method == compression_method::zlib) {
std::mem::set_section_size(zlib_decompress_result, uncompressed_size);
// Create a pattern that defines the compressed array data
auto compressed_byte_len = parent.header.object_size - parent.header.header_size - ($ - container_begin);
u8 compressed[compressed_byte_len];
if (uncompressed_size != 0)
padding[parent.header.object_size % 4]; // Idk, the format wants this... for some reason
std::assert(hex::dec::zlib_decompress(compressed, zlib_decompress_result) == compressed_byte_len,
"zlib decompress needs to succeed");
// Copy the decompressed data to the end of the section
std::mem::copy_section_to_section(zlib_decompress_result, 0,
decompressed_data, std::mem::get_section_size(decompressed_data),
std::mem::get_section_size(zlib_decompress_result));
} else if (compression_method == compression_method::no_compression) {
u8 data[uncompressed_size];
std::mem::copy_value_to_section(data, decompressed_data, std::mem::get_section_size(decompressed_data));
} else {
std::assert(false, "Invalid/unknown compression method");
}
};
enum object_flags : u32 {
// Timestamps are stored with a unit of 10us (10 microseconds)
time_10_us = 1,
// Timestamps are stored with a unit of 1ns (1 nanosecond)
time_1_ns = 2,
};
enum timestamp_status : u8 {
// Means original timestamps are valid
orig = 0x01,
// Timestamp is generated by software (1) or by hardware (0)
swhw = 0x02,
user = 0x10,
};
struct obj_header_ext {
object_flags flags;
if (parent.header.header_version == 1)
u16 client_index;
else if (parent.header.header_version == 2) {
timestamp_status timestamp_status;
padding[1];
}
u16 object_version;
u64 object_timestamp;
if (parent.header.header_version == 2)
u64 original_timestamp;
};
struct obj_header {
type::Magic<"LOBJ"> magic; // 4C 4F 42 4A
u16 header_size;
u16 header_version;
u32 object_size;
object_type object_type;
std::assert(header_version == 1 || header_version == 2, "Invalid/unknown header version");
};
struct obj_struct {
auto object_begin = $;
obj_header header [[inline]];
if (header.object_type == object_type::log_container) {
// Log containers seem to never include additional V1 or V2 headers
log_container log [[inline]];
} else {
obj_header_ext ext_header [[inline]];
match(header.object_type) {
(object_type::can_message): {
can_msg message [[inline]];
}
(object_type::can_statistic): {
can_statistic statistics [[inline]];
}
(object_type::can_driver_error): {
can_driver_error errors [[inline]];
}
(object_type::can_message2): {
can_msg2 message [[inline]];
}
(object_type::can_fd_message): {
can_fd_msg message [[inline]];
}
(object_type::can_fd_message_64): {
can_fd_msg_64 message [[inline]];
padding[header.object_size - ($ - object_begin)]; // TODO: This pattern doesn't support the extra data for this object
}
(object_type::app_text): {
app_text text [[inline]];
padding[header.object_size % 4];
}
(object_type::restore_point_container): {
restore_point_container rpc [[inline]];
}
(_): u8 bytes[header.object_size - header.header_size];
}
}
};
enum application_id : u8 {
unknown = 0,
canalyzer = 1,
canoe = 2,
canstress = 3,
canlog = 4,
canape = 5,
cancasexl = 6,
vlconfig = 7,
porsche_logger = 200,
caetec_logger = 201,
vector_net_sim = 202,
ipetronik_logger = 203,
rtpk = 204,
piketec = 205,
sparks = 206,
};
fn format_api_version(u32 api_version) {
return std::format("{}.{}.{}",
api_version / 1000000,
(api_version % 1000000) / 1000,
(api_version % 1000) / 100);
};
// Mostly just the zlib compression levels, but with some extras
enum compression_level : u8 {
no_compression = 0,
best_speed = 1,
default_compression = 6,
best_compression = 9,
// This means that the file contains only log containers, usually compressed at level 6
default_container_compression = 10,
};
struct timestamp {
u16 year;
u16 month;
u16 day_of_week;
u16 day;
u16 hour;
u16 minute;
u16 second;
u16 millisecond;
} [[format("format_timestamp")]];
fn format_timestamp(timestamp ts) {
return std::format("{}-{}-{}_{}-{}-{}",
ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
};
struct file_header {
type::Magic<"LOGG"> magic; // 4C 4F 47 47
u32 header_length;
u32 api_version [[format("format_api_version")]];
application_id app_id;
compression_level compression_level;
u8 app_major;
u8 app_minor;
u64 file_length;
u64 uncompressed_length;
u32 object_count;
u32 application_build;
timestamp start_timestamp;
timestamp stop_timestamp;
u64 restore_point_offset; // ?
} [[inline]];
struct file_layout {
file_header header;
padding[header.header_length - sizeof(header)];
obj_struct objects[while($ < std::mem::size())];
// Decode all objects from the zlib compressed data
if (std::mem::get_section_size(decompressed_data) != 0)
obj_struct decompressed_objects[header.object_count] @ 0x00 in decompressed_data;
} [[inline]];
file_layout file @ 0x00;
std::assert_warn(std::mem::size() == file.header.file_length, "file size mismatch");

View File

@@ -1,4 +1,4 @@
#pragma description OS2/Windows Bitmap files
#pragma description OS2/Windows Bitmap
#pragma MIME image/bmp
#pragma endian little
@@ -97,7 +97,7 @@ struct Bitmap {
(_): BitmapInfoHeaderV1 bmih;
}
padding[bmih.biSize - sizeof(bmih)];
if (bmih.biBitCount <= 8)
{
if (bmih.biClrUsed > 0 )
@@ -105,7 +105,7 @@ struct Bitmap {
else
Colors rgbq[1 << bmih.biBitCount];
}
if (bmih.biSizeImage > 0 )
u8 lineData[bmih.biSizeImage];
else

View File

@@ -1,4 +1,5 @@
#pragma description TODO
#pragma description Apple binary property list
#pragma MIME application/x-bplist
import std.math;
import std.core;
@@ -29,14 +30,14 @@ enum Marker : u8 {
UNK_0xF0 = 0xF0
};
fn get_marker_name(u8 marker) {
fn get_marker_name(u8 marker) {
if (marker == Marker::Null){// null 0000 0000
return "Null ";
}else if (marker == Marker::False){ //bool 0000 1000 // false
return "False";
}else if (marker == Marker::True){//bool 0000 1001 // true
return "True";
}else if (marker == Marker::Fill){ //fill 0000 1111 // fill byte
}else if (marker == Marker::Fill){ //fill 0000 1111 // fill byte
return "Fill";
}else if (marker & 0xF0 == Marker::Int){ //int 0001 nnnn ... // # of bytes is 2^nnnn, big-endian bytes
return "Int";
@@ -45,10 +46,10 @@ fn get_marker_name(u8 marker) {
}else if (marker == Marker::Date){ //date 0011 0011 ... // 8 byte float follows, big-endian bytes
return "Date";
}else if (marker & 0xF0 == Marker::Data){ //data 0100 nnnn [int] ... // nnnn is number of bytes unless 1111 then int count follows, followed by bytes
return "Data";
return "Data";
}else if (marker & 0xF0 == Marker::ASCIIString){ //string 0101 nnnn [int] ... // ASCII string, nnnn is # of chars, else 1111 then int count, then bytes
return "ASCIIString";
}else if (marker & 0xF0 == Marker::Unicode16String){ //string 0110 nnnn [int] ... // Unicode string, nnnn is # of chars, else 1111 then int count, then big-endian 2-byte
}else if (marker & 0xF0 == Marker::Unicode16String){ //string 0110 nnnn [int] ... // Unicode string, nnnn is # of chars, else 1111 then int count, then big-endian 2-byte
return "Unicode16String";
}else if (marker & 0xF0 == Marker::UNK_0x70){ //0111 xxxx // unused
return "UNK_0x70";
@@ -56,19 +57,19 @@ fn get_marker_name(u8 marker) {
return "UID";
}else if (marker & 0xF0 == Marker::UNK_0x90){ // 1001 xxxx // unused
return "UNK_0x90";
}else if (marker & 0xF0 == Marker::Array){ //array 1010 nnnn [int] objref* // nnnn is count, unless '1111', then int count follows
}else if (marker & 0xF0 == Marker::Array){ //array 1010 nnnn [int] objref* // nnnn is count, unless '1111', then int count follows
return "Array";
}else if (marker & 0xF0 == Marker::UNK_0xB0){ //1011 xxxx // unused
return "UNK_0xB0";
}else if (marker & 0xF0 == Marker::Set){ //set 1100 nnnn [int] objref* // nnnn is count, unless '1111', then int count follows
return "Set";
}else if (marker & 0xF0 == Marker::Dict){ //dict 1101 nnnn [int] keyref* objref* // nnnn is count, unless '1111', then int count follows
}else if (marker & 0xF0 == Marker::Dict){ //dict 1101 nnnn [int] keyref* objref* // nnnn is count, unless '1111', then int count follows
return "Dict";
}else if (marker & 0xF0 == Marker::UNK_0xE0){ // 1110 xxxx // unused
return "UNK_0xE0";
}else if (marker & 0xF0 == Marker::UNK_0xF0){ //1111 xxxx // unused
return "UNK_0xF0";
}
}
};
fn format_tag(u8 marker) {
@@ -79,12 +80,12 @@ fn coredata_to_date (double val){
return type::impl::format_time_t(978307200 + val);
};
struct DictElement {
struct DictElement {
CFBinaryPlistObject key @ offsetTable[parent.objReference.key_refs[std::core::array_index()]].offset;
CFBinaryPlistObject value @ offsetTable[parent.objReference.value_refs[std::core::array_index()]].offset;
};
struct ArrayElement {
struct ArrayElement {
CFBinaryPlistObject value @ offsetTable[parent.objReference.value_refs[std::core::array_index()]].offset;
};
@@ -142,23 +143,23 @@ struct CFBinaryPlistOffset{
struct CFBinaryPlistObject{
u8 marker [[format("get_marker_name")]];
u8 marker_msb = marker & 0xF0;
u8 marker_lsb = marker & 0x0F;
match (marker_msb){
match (marker_msb){
(0x0): {
match (marker_lsb){
(Marker::Null): {
u8 value = 0x00 [[export]];
}
(Marker::False): {
(Marker::False): {
bool value = false [[export]];
}
(Marker::True): {
bool value = true [[export]];
}
(Marker::Fill): {
(Marker::Fill): {
//I think the correct implementation is to do nothing here. The marker will be used as padding (Fill) ???
}
(_): {
@@ -167,7 +168,7 @@ struct CFBinaryPlistObject{
}
}
(Marker::Int): {
be u8 size = std::math::pow(2, marker_lsb);
be u8 size = std::math::pow(2, marker_lsb);
// in format version '00', 1, 2, and 4-byte integers have to be interpreted as unsigned,
// whereas 8-byte integers are signed (and 16-byte when available)
// negative 1, 2, 4-byte integers are always emitted as 8 bytes in format '00'
@@ -181,10 +182,10 @@ struct CFBinaryPlistObject{
(8): be s64 value;
(16): be s128 value;
(_): std::error(std::format("Invalid size detected for 'Int' marker. Got size: {}.", size));
}
}
}
(Marker::Real): {
be u8 size = std::math::pow(2, marker_lsb);
be u8 size = std::math::pow(2, marker_lsb);
match (size){
(4): be float value;
(8): be double value;
@@ -196,7 +197,7 @@ struct CFBinaryPlistObject{
}
(Marker::Data): {
ObjectLen ObjectLen;
u8 value[ObjectLen.size];
u8 value[ObjectLen.size];
}
(Marker::ASCIIString): {
ObjectLen ObjectLen;
@@ -216,7 +217,7 @@ struct CFBinaryPlistObject{
(8): be u64 value;
(16): be u128 value;
(_): std::error(std::format("Invalid size detected for 'UID' marker. Got size: {}.", size));
}
}
}
(Marker::Set | Marker::Array): {
ObjectLen ObjectLen;
@@ -226,7 +227,7 @@ struct CFBinaryPlistObject{
}
(Marker::Dict): {
ObjectLen ObjectLen;
ObjectReference objReference;
DictElement value[ObjectLen.size];
}
@@ -235,7 +236,7 @@ struct CFBinaryPlistObject{
}
(_): {
std::error(std::format("Got unknown marker 0x{:x}", marker));
}
}
}
};
@@ -249,13 +250,13 @@ struct CFBinaryPlistHeader{
struct CFBinaryPlistTrailer {
u8 unused[5];
u8 sortVersion;
u8 sortVersion;
be u8 offsetIntSize;
match (offsetIntSize){
(1|2|4|8): {}
(_): {std::error("Invalid offsetIntSize.");}
}
be u8 objectRefSize;
be u8 objectRefSize;
match (objectRefSize){
(1|2|4|8): {}
(_): {std::error("Invalid objectRefSize.");}

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description BSON (Binary JSON) format
#pragma description BSON (Binary JSON)
#pragma MIME application/bson
@@ -26,8 +26,8 @@ enum Type : u8 {
Timestamp = 0x11,
Int64 = 0x12,
Decimal128 = 0x13,
MinKey = 0xFF,
MinKey = 0xFF,
MaxKey = 0x7F
};
@@ -78,9 +78,9 @@ using Document;
struct Element {
Type type;
CString name;
if (type == Type::Double) {
double value;
} else if (type == Type::String) {
@@ -93,9 +93,9 @@ struct Element {
Binary value;
} else if (type == Type::Undefined) {
/* undefined */
} else if (type == Type::ObjectId) {
} else if (type == Type::ObjectId) {
ObjectId value;
} else if (type == Type::Boolean) {
} else if (type == Type::Boolean) {
bool value;
} else if (type == Type::UTCDatetime) {
type::time64_t value;

View File

@@ -1,4 +1,4 @@
#pragma description GoldSrc engine maps format (used in Half-Life 1)
#pragma description GoldSrc engine map (Half-Life 1)
import std.ptr;
import std.mem;
@@ -163,7 +163,7 @@ struct dmiptexlump_t
MiptexPointer dataofs[nummiptex];
};
struct VisibilityData
struct VisibilityData
{
u8 data[file_header.lumps[LumpIndex::Visibility].filelen];
u8 pad[std::mem::align_to(4, sizeof(this)) - sizeof(this)];

64
patterns/bzip3.hexpat Normal file
View File

@@ -0,0 +1,64 @@
#pragma author Sewer56
#pragma description Parses BZip3 compression (file format) by Kamila Szewczyk
#pragma MIME application/x-bzip3
#pragma endian little
#pragma magic [42 5A 33 76 31] @ 0x00
import std.mem;
// Helper function for bit counting
fn popcount(u8 b) {
u32 count = 0;
while (b != 0) {
count = count + (b & 1);
b = b >> 1;
}
return count;
};
// Frame header structure
struct FrameHeader {
char magic[5]; // "BZ3v1"
u32 blockSize; // Maximum block size
};
// Small block header (for blocks < 64 bytes)
struct SmallBlock {
u32 crc32; // CRC32 checksum
u32 literal; // Always 0xFFFFFFFF for small blocks
u8 data[parent.compressedSize - 8]; // Uncompressed data
};
// Regular block (blocks > 64 bytes)
struct Block {
u32 crc32; // CRC32 checksum of uncompressed data
u32 bwtIndex; // Burrows-Wheeler transform index
u8 model; // Compression model flags
if ((model & 0x02) != 0)
u32 lzpSize; // Size after LZP compression
if ((model & 0x04) != 0)
u32 rleSize; // Size after RLE compression
u8 data[parent.compressedSize - (popcount(model) * 4 + 9)];
};
// Main block structure
struct Chunk {
u32 compressedSize; // Size of compressed block
u32 origSize; // Original uncompressed size
if (origSize < 64) {
SmallBlock block;
} else {
Block block;
}
};
// Main parsing structure
struct BZip3File {
FrameHeader header;
// Read blocks until end of file
Chunk chunks[while(!std::mem::eof())];
};
BZip3File file @ 0x0;

110
patterns/cab.hexpat Normal file
View File

@@ -0,0 +1,110 @@
#pragma author The Wandering Trader
#pragma description Microsoft Cabinet (CAB) Files
#pragma magic [4D 53 43 46] @ 0x00
import type.time;
import type.magic;
import type.size;
fn format_string(auto string) {
return std::format("{}",string);
};
bitfield flags {
bool cfhdrPREV_CABINET : 1;
bool cfhdrNEXT_CABINET : 1;
bool cfhdrRESERVE_PRESENT : 1;
padding : 13;
};
struct CFHEADER {
type::Magic<"MSCF"> signature;
u32 reserved1;
type::Size32 cbCabinet;
u32 reserved2;
u32 coffFiles;
u32 reserved3;
u8 versionMajor;
u8 versionMinor;
u16 cFolders;
u16 cFiles;
flags flags;
u16 setID;
u16 iCabinet;
if (flags.cfhdrRESERVE_PRESENT) {
type::Size16 cbCFHeader;
type::Size8 cbCFFolder;
type::Size8 cbCFData;
u8 abReserve[cbCFHeader];
}
if (flags.cfhdrPREV_CABINET) {
char szCabinetPrev[] [[format("format_string")]];
char szDiskPrev[] [[format("format_string")]];
}
if (flags.cfhdrNEXT_CABINET) {
char szCabinetNext[] [[format("format_string")]];
char szDiskNext[] [[format("format_string")]];
}
};
enum typeCompress : u8{
tcompMASK_TYPE = 0x000F,
tcompTYPE_NONE = 0x0000,
tcompTYPE_MSZIP = 0x0001,
tcompTYPE_QUANTUM = 0x0002,
tcompTYPE_LZX = 0x0003,
};
using CFDATA;
struct CFFOLDER {
u32 coffCabStart;
u16 cCfData;
typeCompress typeCompress;
u8 compressionLevel;
if (CFHEADER.flags.cfhdrRESERVE_PRESENT) {
u8 abReserve[CFHEADER.cbCFFolder];
}
CFDATA CFDATA[cCfData] @ coffCabStart;
};
bitfield attribs {
bool _A_RDONLY : 1;
bool _A_HIDDEN : 1;
bool _A_SYSTEM : 1;
padding : 2;
bool _A_ARCH : 1;
bool _A_EXEC : 1;
bool _A_NAME_IS_UTF : 1;
padding : 8;
};
struct CFFILE {
type::Size32 cbFile;
u32 uoffFolderStart;
u16 iFolder;
type::DOSDate date;
type::DOSTime time;
attribs attribs;
if (attribs._A_NAME_IS_UTF) {
char16 szName[];
} else {
char szName[] [[format("format_string")]];
}
};
struct CFDATA {
u32 csum;
type::Size16 cbData;
type::Size16 cbUncomp;
if (CFHEADER.flags.cfhdrRESERVE_PRESENT) {
u8 abReserve[CFHEADER.cbCFData];
}
u8 ab[cbData];
};
CFHEADER CFHEADER @ 0;
CFFOLDER CFFOLDER[CFHEADER.cFolders] @ $;
CFFILE CFFILE[CFHEADER.cFiles] @ $;

View File

@@ -1,29 +1,29 @@
#pragma description Compact Disc Audio track
#pragma magic [ 52 49 46 46 ] @ 0x00
struct Header {
u32 RIFF;
s32 size;
u32 CDDA;
u32 fmt;
u32 lenghtofthechunck;
u16 versionofcdformat;
u16 numberofrange;
u32 identifier;
u32 RIFF;
s32 size;
u32 CDDA;
u32 fmt;
u32 lenghtofthechunck;
u16 versionofcdformat;
u16 numberofrange;
u32 identifier;
};
struct DataInfo {
u32 range;
u32 duration;
u8 rangepositionframes;
u8 rangepositionseconds;
u8 rangepositionminutes;
u8 nullbyte;
u8 durationtrackframes;
u8 durationtrackseconds;
u8 durationtrackminutes;
u8 nullbytee;
u32 range;
u32 duration;
u8 rangepositionframes;
u8 rangepositionseconds;
u8 rangepositionminutes;
u8 nullbyte;
u8 durationtrackframes;
u8 durationtrackseconds;
u8 durationtrackminutes;
u8 nullbytee;
};

105
patterns/chd.hexpat Normal file
View File

@@ -0,0 +1,105 @@
#pragma author Lexi Mayfield
#pragma description MAME Compressed Hunks of Data
#pragma endian big
fn CHD_MAKE_TAG(char a, char b, char c, char d) {
return (u32(u8(a)) << 24) |
u32(u8((b)) << 16) |
u32(u8((c)) << 8) |
u32(u8(d));
};
enum CHDv5_CODEC : u32 {
NONE = 0,
ZLIB = CHD_MAKE_TAG('z','l','i','b'),
ZSTD = CHD_MAKE_TAG('z','s','t','d'),
LZMA = CHD_MAKE_TAG('l','z','m','a'),
HUFFMAN = CHD_MAKE_TAG('h','u','f','f'),
FLAC = CHD_MAKE_TAG('f','l','a','c'),
CD_ZLIB = CHD_MAKE_TAG('c','d','z','l'),
CD_ZSTD = CHD_MAKE_TAG('c','d','z','s'),
CD_LZMA = CHD_MAKE_TAG('c','d','l','z'),
CD_FLAC = CHD_MAKE_TAG('c','d','f','l'),
AVHUFF = CHD_MAKE_TAG('a','v','h','u'),
};
enum CHDv5_METADATA_TAG : u32 {
CHDMETATAG_WILDCARD = 0,
HARD_DISK_METADATA_TAG = CHD_MAKE_TAG('G','D','D','D'),
HARD_DISK_IDENT_METADATA_TAG = CHD_MAKE_TAG('I','D','N','T'),
HARD_DISK_KEY_METADATA_TAG = CHD_MAKE_TAG('K','E','Y',' '),
PCMCIA_CIS_METADATA_TAG = CHD_MAKE_TAG('C','I','S',' '),
CDROM_OLD_METADATA_TAG = CHD_MAKE_TAG('C','H','C','D'),
CDROM_TRACK_METADATA_TAG = CHD_MAKE_TAG('C','H','T','R'),
CDROM_TRACK_METADATA2_TAG = CHD_MAKE_TAG('C','H','T','2'),
GDROM_OLD_METADATA_TAG = CHD_MAKE_TAG('C','H','G','T'),
GDROM_TRACK_METADATA_TAG = CHD_MAKE_TAG('C','H','G','D'),
DVD_METADATA_TAG = CHD_MAKE_TAG('D','V','D',' '),
AV_METADATA_TAG = CHD_MAKE_TAG('A','V','A','V'),
AV_LD_METADATA_TAG = CHD_MAKE_TAG('A','V','L','D'),
};
struct CHDv5UncompressedMap {
u32 offset;
};
struct CHDv5CompressedMapEntry {
u8 compression;
u24 complength;
u48 offset;
u16 crc;
};
struct CHDv5CompressedMap {
u32 length;
u48 datastart;
u16 crc;
u8 lengthbits;
u8 hunkbits;
u8 parentunitbits;
u8 reserved;
};
struct CHDv5MetadataEntry {
CHDv5_METADATA_TAG metatag;
u8 flags;
u24 length;
u64 next;
char entry[length];
if (next != 0) {
CHDv5MetadataEntry nextMeta @ next;
}
};
struct CHDv5 {
CHDv5_CODEC compressors[4];
u64 logicalbytes;
u64 mapoffset;
u64 metaoffset;
u32 hunkbytes;
u32 unitbytes;
u8 rawsha1[20];
u8 sha1[20];
u8 parentsha1[20];
if (compressors[0] == CHDv5_CODEC::NONE) {
CHDv5UncompressedMap map @ mapoffset;
} else {
CHDv5CompressedMap map @ mapoffset;
}
CHDv5MetadataEntry meta @ metaoffset;
};
struct CHD {
char tag[8];
u32 length;
u32 version;
if (version == 5) {
CHDv5 chd;
}
};
CHD chd @ 0x00;

View File

@@ -1,5 +1,6 @@
#pragma author WerWolv
#pragma description Windows HtmlHelp Data (ITSF / CHM)
#pragma MIME application/vnd.ms-htmlhelp
import type.magic;
import type.size;
@@ -285,26 +286,26 @@ struct DirectoryIndexEntry {
struct ListingChunk {
char magic[4];
if (magic == "PMGL") {
type::Size<u32> freeSpaceLength;
u32;
u32 prevChunkNumber, nextChunkNumber;
u16 directoryListingEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryListingEntryCount) - (freeSpaceLength - 2);
DirectoryListingEntry directories[directoryListingEntryCount];
$ = addressof(directoryListingEntryCount) + sizeof(directoryListingEntryCount);
} else if (magic == "PMGI") {
type::Size<u32> freeSpaceLength;
u16 directoryIndexEntryCount @ addressof(this) + parent.directoryChunkSize - 2;
u16 offsets[(freeSpaceLength - 2) / 2] @ addressof(directoryIndexEntryCount) - (freeSpaceLength - 2);
DirectoryIndexEntry indexes[directoryIndexEntryCount];
$ = addressof(directoryIndexEntryCount) + sizeof(directoryIndexEntryCount);
} else {
std::error("Invalid chunk magic!");
@@ -313,7 +314,7 @@ struct ListingChunk {
struct HeaderSection {
char magic[4];
if (magic == "\xFE\x01\x00\x00") {
u32;
type::Size<u64> fileSize;
@@ -337,7 +338,7 @@ struct HeaderSection {
u32;
u32;
u32;
ListingChunk chunk[directoryChunkCount];
} else {
std::error("Invalid header section magic!");
@@ -347,22 +348,22 @@ struct HeaderSection {
struct HeaderSectionTableEntry {
u64 offset;
type::Size<u64> size;
HeaderSection headerSection @ offset;
};
struct NameListEntry {
type::Size<u16> nameLength;
char16 name[nameLength];
char16 name[nameLength];
padding[2];
};
struct NameListFile {
u16 fileLengthWords;
u16 entriesInFile;
NameListEntry nameList[entriesInFile];
padding[0x2E];
};
@@ -376,7 +377,7 @@ struct SectionData {
u32;
};
struct Content {
struct Content {
NameListFile nameListFile;
SectionData sectionData;
};
@@ -389,9 +390,9 @@ struct CHM {
be u32 timeStamp;
WindowsLanguageId languageId;
type::GUID guids[2];
HeaderSectionTableEntry headerSectionTable[2];
Content *dataOffset : u64;
};

View File

@@ -116,11 +116,11 @@ struct SymbolTable {
Type type;
StorageClass storageClass;
u8 numberOfAuxSymbols;
countedSymbols += 1 + numberOfAuxSymbols;
AuxSymbol auxSymbols[numberOfAuxSymbols];
if (countedSymbols >= parent.header.numberOfSymbols)
break;
};
@@ -164,7 +164,10 @@ bitfield SectionFlags {
};
fn format_alignment(u8 alignment) {
return 1 << alignment;
if(alignment > 0) {
return 1 << (alignment - 1);
}
return alignment;
};
struct Relocations {
@@ -184,7 +187,7 @@ struct Section {
u16 numberOfRelocations;
u16 numberOfLineNumbers;
SectionFlags characteristics;
u8 rawData[sizeOfRawData] @ pointerToRawData [[sealed]];
Relocations relocations[numberOfRelocations] @ pointerToRelocations;
};
@@ -202,9 +205,9 @@ struct Header {
struct COFF {
Header header;
Section sectionTable[header.numberOfSections];
SymbolTable symbolTable[header.numberOfSymbols] @ header.pointerToSymbolTable;
StringTable stringTable @ addressof(symbolTable) + sizeof(symbolTable);
};

View File

@@ -0,0 +1,158 @@
#pragma description Commodore BASIC
#pragma author Stephen Hewitt
import std.io;
import std.mem;
bool in_quotes = false;
le u16 LoadAddress @0 [[color("ff0000")]];
fn formatll(u16 offset) {
if (offset&0xff00 == 0)
return "No next line";
u16 fo = offset-LoadAddress+2;
return std::format("Next line: ${:04X} (offset ${:04X})", offset, fo);
};
enum Token : u8 {
END = 0x80,
FOR = 0x81,
NEXT = 0x82,
DATA = 0x83,
INPUT_ = 0x84,
INPUT = 0x85,
DIM = 0x86,
READ = 0x87,
LET = 0x88,
GOTO = 0x89,
RUN = 0x8a,
IF = 0x8b,
RESTORE = 0x8c,
GOSUB = 0x8d,
RETURN = 0x8e,
REM = 0x8f,
STOP = 0x90,
ON = 0x91,
WAIT = 0x92,
LOAD = 0x93,
SAVE = 0x94,
VERIFY = 0x95,
DEF = 0x96,
POKE = 0x97,
PRINT_ = 0x98,
PRINT = 0x99,
CONT = 0x9a,
LIST = 0x9b,
CLR = 0x9c,
CMD = 0x9d,
SYS = 0x9e,
OPEN = 0x9f,
CLOSE = 0xa0,
GET = 0xa1,
NEW = 0xa2,
TAB_ = 0xa3,
TO = 0xa4,
FN = 0xa5,
SPC_ = 0xa6,
THEN = 0xa7,
NOT = 0xa8,
STEP = 0xa9,
PLUS_ = 0xaa,
MINUS_ = 0xab,
TIMES_ = 0xac,
DIVIDE_ = 0xad,
POW_ = 0xae,
AND = 0xaf,
OR = 0xb0,
GT_ = 0xb1,
EQ_ = 0xb2,
LT_ = 0xb3,
SGN = 0xb4,
INT = 0xb5,
ABS = 0xb6,
USR = 0xb7,
FRE = 0xb7,
POS = 0xb9,
SQR = 0xba,
RND = 0xbb,
LOG = 0xbc,
EXP = 0xbd,
COS = 0xbe,
SIN = 0xbf,
TAN = 0xc0,
ATN = 0xc1,
PEEK = 0xc2,
LEN = 0xc3,
STR_ = 0xc4,
VAL = 0xc5,
ASC = 0xc6,
CHR_ = 0xc7,
LEFT_ = 0xc8,
RIGHT_ = 0xc9,
MID_ = 0xca,
PI_ = 0xff
} [[format("formate")]];
// Can't seem to put attributes on enum members. Hack around it.
fn formate(Token t) {
match (t) {
(Token::INPUT_): return "INPUT#"; // $84
(Token::PRINT_): return "PRINT#"; // $98
(Token::TAB_): return "TAB("; // $a3
(Token::SPC_): return "SPC("; // $a6
(Token::PLUS_): return "+"; // $aa
(Token::MINUS_): return "-"; // $ab
(Token::TIMES_): return "*"; // $ac
(Token::DIVIDE_): return "/"; // $ad
//(Token::POW_): return "↑"; // $ae
(Token::GT_): return ">"; // $b1
(Token::EQ_): return "="; // $b2
(Token::LT_): return "<"; // $b3
(Token::STR_): return "STR$"; // $c4
(Token::CHR_): return "CHR$"; // $c7
(Token::LEFT_): return "LEFT$"; // $c8
(Token::RIGHT_): return "RIGHT$"; // $c9
(Token::MID_): return "MID$"; // $ca
//(Token::PI_): return "π"; // $ff
}
return t;
};
fn NotZero() {
u8 b = std::mem::read_unsigned($, 1);
return b!=0;
};
fn IsToken() {
u8 b = std::mem::read_unsigned($, 1);
return b&0x80!=0;
};
fn IsPETSCII() {
u8 b = std::mem::read_unsigned($, 1);
if (b == '"')
in_quotes = !in_quotes;
return (b!=0) && (in_quotes || (b&0x80)==0);
};
struct LineSegment
{
Token tokens[while(IsToken())] [[color("a040a0")]];
char petscii[while(IsPETSCII())] [[color("a0a0a0")]];
};
struct Line
{
in_quotes = false;
u16 next [[color("8080ff"), format("formatll")]];
if (next&0xff00 == 0)
break;
le u16 line_number [[color("00FF00")]];
LineSegment contents[while(NotZero())];
u8 eol [[color("00ffff")]];
};
Line Lines[while(!std::mem::eof())] @ 2;

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description Old Binary CPIO Format
#pragma description Old Binary CPIO
import type.base;
@@ -19,7 +19,7 @@ namespace old_binary {
};
fn format_time(u32 value) {
return std::time::format(std::time::to_utc(swap_32bit(value)));
return std::time::format(std::time::to_utc(old_binary::swap_32bit(value)));
};
using SwappedU32 = u32 [[transform("old_binary::swap_32bit"), format("old_binary::swap_32bit")]];
@@ -42,7 +42,7 @@ namespace old_binary {
std::core::set_endian(std::mem::Endian::Little);
else
std::error("Invalid CPIO Magic!");
u16 dev;
u16 ino;
Mode mode;
@@ -59,7 +59,7 @@ namespace old_binary {
CpioHeader header;
char pathname[header.namesize % 2 == 0 ? header.namesize : header.namesize + 1];
u8 data[header.filesize % 2 == 0 ? header.filesize : header.filesize + 1];
if (pathname == "TRAILER!!!\x00\x00")
break;
};

99
patterns/credhist.hexpat Normal file
View File

@@ -0,0 +1,99 @@
#pragma description "CREDHIST"
/*
FilePath: C:\Users\<USER>\AppData\Roaming\Microsoft\Protect\
The files/folders are hidden.
To unhide it
1. Open Command Prompt (cmd.exe).
2. Run the following command:
=> attrib -h -s
*/
import type.guid;
import std.mem;
// https://learn.microsoft.com/en-us/windows/win32/seccrypto/alg-id
enum ALG_ID : u32 {
CALG_DH_EPHEM = 0x0000aa02, // Diffie-Hellman ephemeral key exchange algorithm.
CALG_DH_SF = 0x0000aa01, // Diffie-Hellman store and forward key exchange algorithm.
CALG_DSS_SIGN = 0x00002200, // DSA public key signature algorithm.
CALG_ECDH = 0x0000aa05, // Elliptic curve Diffie-Hellman key exchange algorithm.
CALG_ECDH_EPHEM = 0x0000ae06, // Ephemeral elliptic curve Diffie-Hellman key exchange algorithm.
CALG_ECDSA = 0x00002203, // Elliptic curve digital signature algorithm.
CALG_ECMQV = 0x0000a001, // Elliptic curve Menezes, Qu, and Vanstone (MQV) key exchange algorithm.
CALG_HASH_REPLACE_OWF = 0x0000800b, // One way function hashing algorithm.
CALG_HUGHES_MD5 = 0x0000a003, // Hughes MD5 hashing algorithm.
CALG_HMAC = 0x00008009, // HMAC keyed hash algorithm.
CALG_KEA_KEYX = 0x0000aa04, // KEA key exchange algorithm (FORTEZZA).
CALG_MAC = 0x00008005, // MAC keyed hash algorithm.
CALG_MD2 = 0x00008001, // MD2 hashing algorithm.
CALG_MD4 = 0x00008002, // MD4 hashing algorithm.
CALG_MD5 = 0x00008003, // MD5 hashing algorithm.
CALG_NO_SIGN = 0x00002000, // No signature algorithm.
CALG_OID_INFO_CNG_ONLY = 0xffffffff, // Algorithm is only implemented in CNG.
CALG_OID_INFO_PARAMETERS = 0xfffffffe, // Algorithm is defined in the encoded parameters.
CALG_PCT1_MASTER = 0x00004c04, // Used by the Schannel.dll operations system.
CALG_RC2 = 0x00006602, // RC2 block encryption algorithm.
CALG_RC4 = 0x00006801, // RC4 stream encryption algorithm.
CALG_RC5 = 0x0000660d, // RC5 block encryption algorithm.
CALG_RSA_KEYX = 0x0000a400, // RSA public key exchange algorithm.
CALG_RSA_SIGN = 0x00002400, // RSA public key signature algorithm.
CALG_SCHANNEL_ENC_KEY = 0x00004c07, // Used by the Schannel.dll operations system.
CALG_SCHANNEL_MAC_KEY = 0x00004c03, // Used by the Schannel.dll operations system.
CALG_SCHANNEL_MASTER_HASH = 0x00004c02, // Used by the Schannel.dll operations system.
CALG_SEAL = 0x00006802, // SEAL encryption algorithm.
CALG_SHA = 0x00008004, // SHA hashing algorithm.
CALG_SHA1 = 0x00008004, // Same as CALG_SHA.
CALG_SHA_256 = 0x0000800c, // 256-bit SHA hashing algorithm.
CALG_SHA_384 = 0x0000800d, // 384-bit SHA hashing algorithm.
CALG_SHA_512 = 0x0000800e, // 512-bit SHA hashing algorithm.
CALG_SKIPJACK = 0x0000660a, // Skipjack block encryption algorithm (FORTEZZA).
CALG_SSL2_MASTER = 0x00004c05, // Used by the Schannel.dll operations system.
CALG_SSL3_MASTER = 0x00004c01, // Used by the Schannel.dll operations system.
CALG_SSL3_SHAMD5 = 0x00008008, // Used by the Schannel.dll operations system.
CALG_TEK = 0x0000660b, // TEK (FORTEZZA).
CALG_TLS1_MASTER = 0x00004c06, // Used by the Schannel.dll operations system.
CALG_TLS1PRF = 0x0000800a // Used by the Schannel.dll operations system.
};
// https://devblogs.microsoft.com/oldnewthing/20040315-00/?p=40253
struct SID {
u8 revisionlvl[[name("RevisionLevel"), comment("SID_REVISION")]];
u8 dashes[[name("NoOfDashes"), comment("number of dashes minus two")]]; // dashes = actualdashes - 0x2
char ntauth[0x6][[name("NtAuthority"), comment("SECURITY_NT_AUTHORITY")]];
u32 subatuh1[[name("SubAuthority1"), comment("SECURITY_NT_NON_UNIQUE")]];
u32 subatuh2[[name("SubAuthority2"), comment("these identify the machine that issued the SID")]];
u32 subatuh3[[name("SubAuthority3"), comment("these identify the machine that issued the SID")]];
u32 subatuh4[[name("SubAuthority4"), comment("these identify the machine that issued the SID")]];
u32 rid[[name("RID"), comment("unique user id on the machine")]];
};
struct CREDHIST_HEADER{
u32 version[[name("Version")]];
type::GUID guid[[name("GUID")]];
u32 nextlen[[name("NextCredSize")]];
};
struct CREDHIST {
CREDHIST_HEADER credheader[[name("CredHistHeader")]];
if (std::mem::eof()){
break;
}
u32 flgas [[name("Flags")]];
ALG_ID alghashid[[name("AlgorithmHashId")]];
u32 rounds [[name("Rounds")]];
u32 sidlen [[name("SIDLen")]];
ALG_ID algcryptid[[name("AlgorithmCryptId")]];
u32 sha1len[[name("SHA1Len")]];
u32 md4len[[name("ntlmlen")]];
char salt[0x10][[name("Salt")]];
SID sid[[name("SID")]];
char sha1hash[sha1len][[name("SHA1Hash")]];
char md4hash[md4len][[name("NTLMHash")]];
u64 unk1[[name("Unknown")]];
};
CREDHIST credhist [while(!std::mem::eof())] @ 0x0[[name("CredHist")]];

View File

@@ -1,6 +1,7 @@
#pragma description DirectDraw Surface
#pragma MIME image/vnd-ms.dds
#pragma MIME image/x-dds
#pragma endian little
enum DXGI_FORMAT : u32 {
@@ -202,7 +203,7 @@ enum DX10AlphaMode : u32 {
Straight,
PreMultiplied,
Opaque,
Custom,
Custom,
};
bitfield DX10MiscFlags {

View File

@@ -1,4 +1,5 @@
#pragma description Dalvik EXecutable Format
#pragma description Dalvik EXecutable
#pragma magic [ 64 65 78 0A ?? ?? ?? 00 ]
import type.leb128;
@@ -99,7 +100,7 @@ enum access_flag : type::uLEB128{
static = 0x8,
final = 0x10,
synchronized = 0x20,
volatile = 0x40
volatile = 0x40
};
struct encoded_field {
@@ -134,7 +135,7 @@ struct class_def_item {
u32 class_data_off;
//class_data_item *class_data_off:u32;
u32 static_values_off;
char class_name[] @ addressof(parent.type_ids[class_idx].type_name);
char class_name[] @ addressof(parent.type_ids[class_idx].type_name);
}[[name(class_name)]];
struct type_item {

View File

@@ -1,4 +1,4 @@
#pragma description DICOM file
#pragma description DICOM Digital Imaging and Communications in Medicine
#pragma MIME application/dicom
#pragma endian little

165
patterns/dmc3_hd_mod.hexpat Normal file
View File

@@ -0,0 +1,165 @@
#pragma description Devil May Cry 3 HD .mod 3D model file
#pragma MIME 3d-model/capcom.dmc3-hd-mod
// author = haru233, many thanks to AxCut
// ImHex Hex Pattern File for Capcom's Devil May Cry 3 HD .mod files
import std.core;
struct ModelHeader {
char ID[4];
float Version;
padding[8];
u8 objectCount;
u8 boneCount;
u8 numberTextures;
u8;
u32;
u64;
u64 skeletonOffset;
padding[24];
};
struct ObjectInfo {
u8 meshCount;
u8;
u16 numberVertices;
padding[4];
u64 meshOffset;
u32 flags;
padding[28];
float X, Y, Z;
float radius;
};
struct Positions {
float positions[3];
};
struct Normals {
float normal[3];
};
struct UVs {
s16 uv[2];
};
struct BoneIndices {
u8 boneindex[4];
};
struct Weights {
u16 weight[1];
};
struct MeshSCM {
u16 numberVertices;
u16 textureIndex;
padding[12];
u64 VerticesPositionsOffset;
u64 NormalsPositionsOffset;
u64 UVsPositionsOffset;
padding[16];
u64 unknownOffset;
u64;
padding[8];
Positions positions[numberVertices] @VerticesPositionsOffset;
Normals normals[numberVertices] @NormalsPositionsOffset;
UVs uvs[numberVertices] @UVsPositionsOffset;
};
struct Mesh {
u16 numberVertices;
u16 textureIndex;
padding[12];
u64 VerticesPositionsOffset;
u64 NormalsPositionsOffset;
u64 UVsPositionsOffset;
u64 BoneIndicesOffset;
u64 WeightsOffset;
padding[8];
u64;
padding[8];
Positions positions[numberVertices] @VerticesPositionsOffset;
Normals normals[numberVertices] @NormalsPositionsOffset;
UVs uvs[numberVertices] @UVsPositionsOffset;
BoneIndices b_index[numberVertices] @BoneIndicesOffset;
Weights weights[numberVertices] @WeightsOffset;
};
struct Hierarchy {
u8 hierarchy;
};
struct HierarchyOrder {
u8 hierarchyorder;
};
struct Unknown {
u8;
};
struct Transform {
float x;
float y;
float z;
float length; // sqrt(x*x + y*y + z*z)
padding[16];
};
struct Skeleton{
u32 hierarchyOffset;
u32 hierarchyOrderOffset;
u32 unknownOffset;
u32 transformsOffset;
};
ModelHeader modelheader @ 0x00;
ObjectInfo objects_info[modelheader.objectCount] @ 0x40;
u32 objectOffset;
struct Object {
u64 i = std::core::array_index();
if (modelheader.ID == "SCM ") {
objectOffset = objects_info[0].meshOffset;
MeshSCM meshscm[objects_info[i].meshCount] @ objects_info[i].meshOffset;
} else {
objectOffset = objects_info[0].meshOffset;
Mesh mesh[objects_info[i].meshCount] @ objects_info[i].meshOffset;
}
};
Object objects[modelheader.objectCount] @objectOffset;
Skeleton skeleton @modelheader.skeletonOffset;
Hierarchy hierarchy[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.hierarchyOffset);
HierarchyOrder hierarchyorder[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.hierarchyOrderOffset);
Unknown unknown[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.unknownOffset);
Transform transform[modelheader.boneCount] @(modelheader.skeletonOffset + skeleton.transformsOffset);

View File

@@ -1,4 +1,5 @@
#pragma description Apple Disk Image Trailer (DMG)
#pragma magic [ 6B 6F 6C 79 ] @ -512
#pragma endian big
@@ -11,41 +12,41 @@ import std.mem;
//
// UDIFResourceFile starts at size(file) - 512
struct UDIFResourceFile {
type::Magic<"koly"> Signature; // Magic ('koly')
u32 Version; // Current version is 4
type::Size<u32> HeaderSize; // sizeof(this), always 512
type::Magic<"koly"> Signature; // Magic ('koly')
u32 Version; // Current version is 4
type::Size<u32> HeaderSize; // sizeof(this), always 512
u32 Flags;
u64 RunningDataForkOffset; //
u64 DataForkOffset; // Data fork offset (usually 0, beginning of file)
type::Size<u64> DataForkLength; // Size of data fork (usually up to the XMLOffset, below)
u64 RsrcForkOffset; // Resource fork offset, if any
type::Size<u64> RsrcForkLength; // Resource fork length, if any
u32 SegmentNumber; // Usually 1, may be 0
u32 SegmentCount; // Usually 1, may be 0
type::GUID SegmentID; // 128-bit GUID identifier of segment (if SegmentNumber !=0)
u64 RunningDataForkOffset; //
u64 DataForkOffset; // Data fork offset (usually 0, beginning of file)
type::Size<u64> DataForkLength; // Size of data fork (usually up to the XMLOffset, below)
u64 RsrcForkOffset; // Resource fork offset, if any
type::Size<u64> RsrcForkLength; // Resource fork length, if any
u32 SegmentNumber; // Usually 1, may be 0
u32 SegmentCount; // Usually 1, may be 0
u32 DataChecksumType; // Data fork
type::GUID SegmentID; // 128-bit GUID identifier of segment (if SegmentNumber !=0)
u32 DataChecksumType; // Data fork
type::Size<u32> DataChecksumSize; // Checksum Information
u32 DataChecksum[DataChecksumSize]; // Up to 128-bytes (32 x 4) of checksum
u32 DataChecksum[32]; // Up to 128-bytes (32 x 4) of checksum
u64 XMLOffset; // Offset of property list in DMG, from beginning
type::Size<u64> XMLLength; // Length of property list
u8 Reserved1[120]; // 120 reserved bytes - zeroed
u64 XMLOffset; // Offset of property list in DMG, from beginning
type::Size<u64> XMLLength; // Length of property list
u8 Reserved1[120]; // 120 reserved bytes - zeroed
u32 ChecksumType; // Master
type::Size<u32> ChecksumSize; // Checksum information
u32 Checksum[ChecksumSize]; // Up to 128-bytes (32 x 4) of checksum
u32 ChecksumType; // Master
type::Size<u32> ChecksumSize; // Checksum information
u32 Checksum[32]; // Up to 128-bytes (32 x 4) of checksum
u32 ImageVariant; // Commonly 1
u64 SectorCount; // Size of DMG when expanded, in sectors
u32 ImageVariant; // Commonly 1
u64 SectorCount; // Size of DMG when expanded, in sectors
u32 reserved2; // 0
u32 reserved3; // 0
u32 reserved4; // 0
u32 reserved2; // 0
u32 reserved3; // 0
u32 reserved4; // 0
};
UDIFResourceFile trailer @ std::mem::size() - 512;
char metadata_plist[trailer.XMLLength] @ trailer.XMLOffset;
char metadata_plist[trailer.XMLLength] @ trailer.XMLOffset;

102
patterns/dmp64.hexpat Normal file
View File

@@ -0,0 +1,102 @@
#pragma magic [ 50 41 47 45 ] @ 0x00 // PAGE
#pragma author "5h4rrK"
#pragma description "KERNEL DUMP"
import std.core;
import std.io;
import std.array;
#define COMMENT_SIZE 0x80
fn format_values(auto val){
return std::format("{:#x}", val);
};
fn format_size_values(auto val){
return std::format(
"{:#x} ({}) ",
val,
std::format("{:#x}",val * 0x1000)
);
};
union DUMP_FILE_ATTRIBUTES {
u32 bitfields[[name("BitFields")]];
u32 attributes[[name("Attributes")]];
};
enum DUMP_TYPE : u32 {
FULL_DUMP = 0x01,
BITMAP_DUMP = 0x05
};
struct EXCEPTION_RECORD64
{
u32 exception_code[[name("ExceptionCode"), format("format_values")]];
u32 exception_flags[[name("ExceptionFlags"), format("format_values")]];
u64 exception_record[[name("ExceptionRecord"), format("format_values")]];
u64 exception_address[[name("ExceptionAddress"), format("format_values")]];
u32 number_parameters[[name("NumberParameters"), format("format_values")]];
u32 unused_alignment[[name("Alignment"), format("format_values")]];
u64 exception_information[15][[name("ExceptionInformation")]];
};
struct PHYSICAL_MEMORY_RUN64 {
u64 base_page [[ name("BasePage"), format("format_size_values"), comment("StartOffset = BasePage * PageSize")]];
u64 page_count[[ name("PageCount"),format("format_size_values"), comment("Length = PageCount * PageSize")]];
}[[name("PHYSICAL_MEMORY_RUN_ENTRY")]];
struct PHYSICAL_MEMORY_DESCRIPTOR64 {
u32 no_of_runs [[name("NumberOfRuns")]];
char description[4][[name("Description")]];
u64 no_of_pages[[name("NumberOfPages"),format("format_values")]];
// PHYSICAL_MEMORY_RUN64 pmr64[no_of_runs] [[name("PHYSICAL_MEMORY_RUN64")]];
std::Array<PHYSICAL_MEMORY_RUN64, no_of_runs> pmrObjs[[name("PHYSICAL_MEMORY_RUN64")]];
};
struct DUMP_HEADER64 {
char signature[4][[name("Signature")]];
char validdump[4][[name("ValidDump")]];
u32 major_version[[name("MajorVersion")]];
u32 minor_version[[name("MinorVersion")]];
u64 dtb [[name("DirectoryBaseTable"),format("format_values")]];
u64 pfn [[name("PfnDataBase"), format("format_values")]];
u64 ploadedmodulelist [[name("PsLoadedModuleList"), format("format_values")]];
u64 pactiveprocesshead [[name("PsActiveProcessHead"), format("format_values")]];
u32 machine_type [[name("MachineImageType"), format("format_values")]];
u32 processor_counts [[name("ProcessorsCount")]];
u32 bug_check [[name("BugCheckCode"), format("format_values")]];
u32 bug_check_code_desc[[name("BugCheckCodeDescription"), format("format_values")]];
u64 bug_check_param1[[name("BugCheckCodeParameter1"), format("format_values")]];
u64 bug_check_param2[[name("BugCheckCodeParameter2"), format("format_values")]];
u64 bug_check_param3[[name("BugCheckCodeParameter3"), format("format_values")]];
u64 bug_check_param4[[name("BugCheckCodeParameter4"), format("format_values")]];
char version_user[0x20][[name("VersionUser")]];
u64 kdbg[[name("KdDebuggerDataBlock"), format("format_values")]];
PHYSICAL_MEMORY_DESCRIPTOR64 phys_mem_desc[[name("PHYSICAL_MEMORY_DESCRIPTOR64")]];
char mem_block_buffer[0x260][[name("PhysicalMemoryBlockBuffer")]];
char context_record[0xbb8][[name("ContextRecord")]];
EXCEPTION_RECORD64 excr[[name("EXCEPTION_RECORD64")]];
DUMP_TYPE dmp_type[[name("DumpType")]];
char desc1[4][[name("Description")]];
u64 req_dump_space[[name("RequiredDumpSpace"), format("format_values")]];
u64 sys_time[[name("SystemTime"), format("format_values")]];
char comment[COMMENT_SIZE][[name("Comment")]];
u64 sys_up_time[[name("SystemUpTime"), format("format_values")]];
u32 min_dmp_fields[[name("MiniDumpFields"), format("format_values")]];
u32 sec_data_state[[name("SecondaryDataState"), format("format_values")]];
u32 product_type[[name("ProductType"), format("format_values")]];
u32 suite_mask[[name("SuiteMask"), format("format_values")]];
u32 writer_status[[name("WriterStatus"), format("format_values")]];
char unused1[[name("Unused1")]];
char secondary_version[[name("KdSecondaryVersion")]];
char unused2[2][[name("Unused2")]];
DUMP_FILE_ATTRIBUTES dfa[[name("DUMP_FILE_ATTRIBUTES")]];
u32 boot_id[[name("BootId")]];
char reserved[0xfa8][[name("Reserved")]];
};
DUMP_HEADER64 dmp @ 0x00 [[name("DumpHeader")]];

242
patterns/dos.hexpat Normal file
View File

@@ -0,0 +1,242 @@
#pragma author Stephen Hewitt
#pragma description MSDOS executable file
#pragma MIME application/x-dosexec
#pragma MIME application/x-msdownload
#pragma MIME application/x-dosexecapplication/zip
#pragma MIME application/vnd.microsoft.portable-executable
import type.magic;
import std.io;
import std.mem;
import std.math;
import std.string;
/*
* A DOS EXE file, at a high level, consists of three regions:
*
* Header
* As it's name suggests. Contains info the loader uses.
*
* Load module
* Contains the program data that is loaded into memory.
*
* Extra data
* Data appended to the file that isn't loaded into memory.
*
* We'll call the combined header and load module the
* "program image". It's what the DOS loader cares about.
*/
/*
* Wikipedia: The New Executable (NE or NewEXE) is a 16-bit executable
* file format, a successor to the DOS MZ executable format. It was used
* in Windows 1.03.x, Windows 9x, multitasking MS-DOS 4.0,[1] OS/2 1.x,
* and the OS/2 subset of Windows NT up to version 5.0 (Windows 2000).
*
* Since it was used in DOS we'll support it.
*
* We'll make it optional since some programs increased
* 'headerSizeInParagraphs' and stashed all kind of stuff there.
*/
bool EnableNEHeaderExt in;
/*
* DOS file offsets/sizes. DOS uses INT 21h for file I/O. File positions and
* lengths are tracked using 32-bit signed integers. DOS INT 21h functions
* treat the offset as signed, so the highest positive offset is 0x7FFFFFFF.
* Attempting to seek beyond that or read/write beyond that will fail.
* We'll use a u32.
*/
u32 g_loadModule;
u32 g_loadModuleSize;
u32 g_programImageSize;
fn formatNumber(u32 num, str msg="") {
if (std::string::length(msg)==0)
return std::format("0x{:x} ({})", num, num);
else
return std::format("{} 0x{:x} ({})", msg, num, num);
};
fn inLoadModule(u32 off, u32 sz) {
return off>=g_loadModule && off+sz<=g_loadModule+g_loadModuleSize;
};
struct Relocation {
u16 offset [[color("9AE630")]];
u16 segment [[color("FE9A37")]];
};
struct RelocationAnnotated : Relocation {
u32 fileOffset = g_loadModule+offset+segment*16;
if (inLoadModule(fileOffset, 2)) {
u16 __goto__target @ fileOffset [[highlight_hidden]];
}
else {
str __goto__target = formatNumber(fileOffset, "Not in load module") [[export, highlight_hidden]];
}
};
struct Relocations {
if (parent.dosHeader.relocations>0) {
Relocation __goto__firstReloc @ $ [[highlight_hidden]];
Relocation __goto__lastReloc @ $+(parent.dosHeader.relocations-1)*sizeof(Relocation) [[highlight_hidden]];
}
RelocationAnnotated data[parent.dosHeader.relocations] [[inline]];
};
struct DOSHeader {
type::Magic<"MZ"> signature [[hex::spec_name("e_magic")]];
u16 extraPageSize [[hex::spec_name("e_cblp")]];
u16 numberOfPages [[hex::spec_name("e_cp")]];
g_programImageSize = (extraPageSize==0) ?
(numberOfPages*512) :
(numberOfPages-1)*512 + extraPageSize;
str __programImageSize = formatNumber(g_programImageSize) [[export, highlight_hidden]];
u8 __goto__lastByteInProgramImage @ g_programImageSize-1 [[highlight_hidden]];
u16 relocations [[name("stubRelocations"), hex::spec_name("e_crlc")]];
u16 headerSizeInParagraphs [[hex::spec_name("e_cparhdr")]];
u32 headerSize = headerSizeInParagraphs*16;
g_loadModule = headerSizeInParagraphs*16;
g_loadModuleSize = g_programImageSize - headerSize;
str __headerSize = formatNumber(headerSize) [[export, highlight_hidden]];
u8 __goto__lastByteInHeader @ headerSize-1 [[highlight_hidden]];
u16 minimumAllocatedParagraphs [[hex::spec_name("e_minalloc")]];
u16 maximumAllocatedParagraphs [[hex::spec_name("e_maxalloc")]];
u16 initialSSValue [[hex::spec_name("e_ss")]];
u16 initialRelativeSPValue [[hex::spec_name("e_sp")]];
u16 checksum [[name("stubChecksum"), hex::spec_name("e_csum")]];
u16 initialRelativeIPValue [[hex::spec_name("e_ip")]];
u16 initialCSValue [[hex::spec_name("e_cs")]];
u32 csAddrFirst = initialCSValue<<4;
u32 csAddrLast = (csAddrFirst+0xffff) & ((1<<20)-1);
u32 csEndGap = 0;
if (csAddrFirst <= csAddrLast) {
u32 csOffsetFirst = headerSize+csAddrFirst;
u32 csOffsetLast = csOffsetFirst+std::math::min(0x10000, g_loadModuleSize)-1;
}
else {
u32 csOffsetFirst = headerSize;
csEndGap = (1<<20)-csAddrFirst;
u32 csOffsetLast = headerSize+(0x10000-csEndGap-1);
std::warning("EXE has 'initialCSValue' set such that 20-bit address wraps.");
std::warning(" My guess would be to get the PSP into the CS.");
}
/*
* Adding `csEndGap` to the `initialIP` calculation below is required because the
* program is started by transferring execution to CS:IP. If `csEndGap` is non-zero
* CS and the start of the load-module value do not align; theres some extra data
* the CPU can see before the data in the EXE. What confused me for a bit was why
* its not required in the relocation target locations I make. The reason, I think,
* is that when the loader loads the load-module into memory and then proceeds to
* apply the relocations, the offsets are relative to the segment the code is loaded
* in and not the execution environment (the CS register from `initialCSValue`).
*/
u32 initialIP = csOffsetFirst+initialRelativeIPValue-csEndGap;
if (inLoadModule(initialIP, 1))
u8 __goto__initiaIP @ initialIP [[highlight_hidden]];
else
str __goto__initiaIP = formatNumber(initialIP, "Not in load module!") [[export, highlight_hidden]];
u32 csSize = csOffsetLast-csOffsetFirst+1;
if (inLoadModule(csOffsetFirst, csSize)) {
std::mem::Bytes<csSize> __select__InitialCS @ csOffsetFirst [[highlight_hidden]];
u8 __goto__InitialCS_first @ csOffsetFirst [[highlight_hidden]];
u8 __goto__InitialCS_last @ csOffsetFirst+csSize-1 [[highlight_hidden]];
}
else {
str __select__CS = formatNumber(csOffsetFirst, "Not in image!") [[export, highlight_hidden]];
}
u16 relocationsTablePointer [[hex::spec_name("e_lfarlc")]];
u32 sizeofRelocations = relocations*sizeof(Relocation);
if (relocations>0 && relocationsTablePointer+sizeofRelocations<g_programImageSize) {
std::mem::Bytes<sizeofRelocations> __select__relocationsTable
@ relocationsTablePointer [[highlight_hidden]];
}
else {
str __select__relocationsTable =
"Not in image or zero length" [[export, highlight_hidden]];
}
u16 overlayNumber [[hex::spec_name("e_ovno")]];
};
struct NEDOSHeaderExt {
u16 reservedWords[4] [[hex::spec_name("e_res")]];
u16 oemIdentifier [[hex::spec_name("e_oemid")]];
u16 oemInformation [[hex::spec_name("e_oeminfo")]];
u16 otherReservedWords[10] [[hex::spec_name("e_res2")]];
u32 newHeaderPointer [[hex::spec_name("e_lfanew")]];
};
struct NEDOSHeaderExtAnnotated : NEDOSHeaderExt {
if (newHeaderPointer < std::mem::size())
u8 __goto__newHeader @ newHeaderPointer [[highlight_hidden]];
else
str __goto__newHeader
= formatNumber(newHeaderPointer, "Not in image!") [[export, highlight_hidden]];
};
/*
* The header of a DOS EXE file consists of three regions.
*
* DOSHeader
* Present in all DOS EXEs. Used by the loader.
*
* NEDOSHeaderExt
* An extension to the header. Optional.
*
* Relocations
* An array of segment relocations to the apply to the load module. Optional.
*
* The header is followed by the load module. There can be gaps between
* DOSHeader (or NEDOSHeaderExt if present) and Relocations, and between the
* Relocations and the load module. It is not uncommon for EXEs to stash candy
* in these gaps.
*/
struct Header {
DOSHeader dosHeader;
if (EnableNEHeaderExt) {
if (dosHeader.relocationsTablePointer < $+sizeof(NEDOSHeaderExt)) {
std::warning("NEHeaderExt and Relocations overlap. Disabling NEHeaderExt.");
}
else {
NEDOSHeaderExtAnnotated extHeader;
}
}
if (dosHeader.relocations > 0) {
if (dosHeader.relocationsTablePointer < $) {
std::warning("Relocation table overlaps previous header members");
}
if (dosHeader.relocationsTablePointer+dosHeader.relocations*sizeof(Relocation) > g_loadModule) {
std::warning("Relocation table ends past header.");
}
}
if (dosHeader.relocationsTablePointer > $) {
u8 header_reloc_gap[dosHeader.relocationsTablePointer-$] [[highlight_hidden]];
}
Relocations relocations;
if (g_loadModule > $) {
u8 reloc_loadModule_gap[g_loadModule-$] [[highlight_hidden]];
}
};
struct LoadModule {
u8 __goto__first @ $ [[highlight_hidden]];
u8 __goto__last @ $+g_loadModuleSize-1 [[highlight_hidden]];
u8 data[g_loadModuleSize];
} [[color("7393B3")]];
Header header @0;
LoadModule loadModule @g_loadModule;;

View File

@@ -0,0 +1,921 @@
/*
References:
.NET BinaryFormatter Specification "MS-NRBF":
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nrbf/75b9fe09-be15-475f-85b8-ae7b7558cfe5
.NET runtime:
https://github.com/dotnet/runtime/blob/v8.0.17/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryParser.cs
.NET Library for Parsing MS-NRBF streams:
https://github.com/bbowyersmyth/BinaryFormatDataStructure
*/
#pragma author ODeux
#pragma description .NET BinaryFormatter (System.Runtime.Serialization.Formatters.Binary, obsolete)
#pragma endian little
import std.core;
import std.sys;
import std.mem;
import std.ptr;
fn offsetOf(ref auto value, ref auto value_field){
return addressof(value_field) - addressof(value);
};
struct NullableArrayPtr<T, pointerSize, auto size>{
pointerSize pointerValue [[no_unique_address, hidden]];
if(pointerValue != 0)
T *data[size]: pointerSize;
else
padding[sizeof(pointerSize)];
};
using _Ptr<T, PointerSize> = std::ptr::NullablePtr<T, PointerSize>;
using _ArrayPtr<T, PointerSize, auto size> = NullableArrayPtr<T, PointerSize, size>;
fn append_value_to_section(ref auto value, std::mem::Section section){
u128 old_section_size = std::mem::get_section_size(section);
std::mem::copy_value_to_section(value, section, old_section_size);
return old_section_size;
};
fn todo(auto message){
std::error(std::format("@0x{:08X} TODO: " + message, $));
};
using _Trackers;
std::mem::Section _TrackersSection = std::mem::create_section("_TrackersSection");
_Trackers _trackers @ 0x0 in _TrackersSection;
bool NeedUpdateTrackers = false;
bool IsUpdatingTrackers = false;
enum _ObjEnum: u64{
Empty = 0,
SerializedStreamHeader = 1,
ClassWithId = 2, Object = _ObjEnum::ClassWithId,
SystemClassWithMembers = 3, ObjectWithMap = _ObjEnum::SystemClassWithMembers,
ClassWithMembers = 4, ObjectWithMapAssemId = _ObjEnum::ClassWithMembers,
SystemClassWithMembersAndTypes = 5, ObjectWithMapTyped = _ObjEnum::SystemClassWithMembersAndTypes,
ClassWithMembersAndTypes = 6, ObjectWithMapTypedAssemId = _ObjEnum::ClassWithMembersAndTypes,
BinaryObjectString = 7, ObjectString = _ObjEnum::BinaryObjectString,
BinaryArray = 8, Array = _ObjEnum::BinaryArray,
MemberPrimitiveTyped = 9,
MemberReference = 10,
BinaryLibrary = 11, Assembly = _ObjEnum::BinaryLibrary,
ObjectNullMultiple256 = 12,
ObjectNullMultiple = 13,
ArraySinglePrimitive = 14,
ArraySingleObject = 15,
ArraySingleString = 16,
CrossAppDomainMap = 17,
CrossAppDomainString = 18,
CrossAppDomainAssembly = 19,
MethodCall = 20,
MethodReturn = 21
};
fn zeroedCurrObjTrackers(){
_trackers.currentObj.TypeName.pointerValue = 0;
_trackers.currentObj.AssemblyName.pointerValue = 0;
_trackers.currentObj.objEnum = _ObjEnum::Empty;
_trackers.currentObj.RawPtr = 0;
};
fn copyCurrObjAtIdTrackers(auto id){
NeedUpdateTrackers = true;
_trackers.objs[id].TypeName.pointerValue = _trackers.currentObj.TypeName.pointerValue;
_trackers.objs[id].AssemblyName.pointerValue = _trackers.currentObj.AssemblyName.pointerValue;
/* ! Enum does not get copied if we don't use a cast here for some reason ! */
_trackers.objs[id].objEnum = u64(_trackers.currentObj.objEnum);
_trackers.objs[id].RawPtr = _trackers.currentObj.RawPtr;
};
using BitfieldOrder = std::core::BitfieldOrder;
using TimeSpan = s64;
enum PrimitiveTypeEnum: u8{
Invalid = 0,
Boolean = 1,
Byte = 2,
Char = 3,
Currency = 4, /* Not Used in this protocol */
Decimal = 5,
Double = 6,
Int16 = 7,
Int32 = 8,
Int64 = 9,
SByte = 10,
Single = 11,
TimeSpan = 12,
DateTime = 13,
UInt16 = 14,
UInt32 = 15,
UInt64 = 16,
Null = 17,
String = 18
};
struct PrimitiveTypeEnumT<auto _primitiveTypeEnumT>{
PrimitiveTypeEnum primitiveTypeEnumT = _primitiveTypeEnumT;
PrimitiveTypeEnum primitiveTypeEnum;
if(_primitiveTypeEnumT > 0)
std::assert(primitiveTypeEnum == primitiveTypeEnumT, std::format("Expected {} but got {}", primitiveTypeEnumT, primitiveTypeEnum));
};
enum BinaryTypeEnum: u8{
Primitive = 0,
String = 1,
Object = 2,
SystemClass = 3, ObjectUrt = BinaryTypeEnum::SystemClass,
Class = 4, ObjectUser = BinaryTypeEnum::Class,
ObjectArray = 5,
StringArray = 6,
PrimitiveArray = 7
};
enum BinaryArrayTypeEnum: u8{
Single = 0,
Jagged = 1,
Rectangular = 2,
SingleOffset = 3,
JaggedOffset = 4,
RectangularOffset = 5
};
enum RecordTypeEnum: u8{
SerializedStreamHeader = 0,
ClassWithId = 1, Object = RecordTypeEnum::ClassWithId,
SystemClassWithMembers = 2, ObjectWithMap = RecordTypeEnum::SystemClassWithMembers,
ClassWithMembers = 3, ObjectWithMapAssemId = RecordTypeEnum::ClassWithMembers,
SystemClassWithMembersAndTypes = 4, ObjectWithMapTyped = RecordTypeEnum::SystemClassWithMembersAndTypes,
ClassWithMembersAndTypes = 5, ObjectWithMapTypedAssemId = RecordTypeEnum::ClassWithMembersAndTypes,
BinaryObjectString = 6, ObjectString = RecordTypeEnum::BinaryObjectString,
BinaryArray = 7, Array = RecordTypeEnum::BinaryArray,
MemberPrimitiveTyped = 8,
MemberReference = 9,
ObjectNull = 10,
MessageEnd = 11,
BinaryLibrary = 12, Assembly = RecordTypeEnum::BinaryLibrary,
ObjectNullMultiple256 = 13,
ObjectNullMultiple = 14,
ArraySinglePrimitive = 15,
ArraySingleObject = 16,
ArraySingleString = 17,
CrossAppDomainMap = 18,
CrossAppDomainString = 19,
CrossAppDomainAssembly = 20,
MethodCall = 21,
MethodReturn = 22
};
using BinaryHeaderEnum = RecordTypeEnum;
struct RecordTypeEnumT<auto _recordTypeEnumT>{
RecordTypeEnum recordTypeEnumT = _recordTypeEnumT;
RecordTypeEnum recordTypeEnum;
if(_recordTypeEnumT > 0)
std::assert(recordTypeEnum == recordTypeEnumT, std::format("Expected {} but got {}", recordTypeEnumT, recordTypeEnum));
};
bitfield MessageFlags{
bool NoArgs: 1; /* Arg Category */
bool ArgsInline: 1; /* Arg Category */
bool ArgsIsArray: 1; /* Arg Category */
bool ArgsInArray: 1; /* Arg Category */
bool NoContext: 1; /* Context Category */
bool ContextInline: 1; /* Context Category */
bool ContextInArray: 1; /* Context Category */
bool MethodSignatureInArray: 1; /* Signature Category */
bool PropertiesInArray: 1; /* Property Category */
bool NoReturnValue: 1; /* Return Category */
bool ReturnValueVoid: 1; /* Return Category */
bool ReturnValueInline: 1; /* Return Category */
bool ReturnValueInArray: 1; /* Return Category */
bool ExceptionInArray: 1; /* Exception Category */
bool GenericMethod: 1; /* Generic Category */
unsigned unused: 17;
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 32)]];
fn validate_MessageFlags(MessageFlags flags){
u8 arg_cnt = flags.NoArgs + flags.ArgsInline + flags.ArgsIsArray + flags.ArgsInArray;
u8 ctx_cnt = flags.NoContext + flags.ContextInline + flags.ContextInArray;
u8 sig_cnt = flags.MethodSignatureInArray;
u8 ret_cnt = flags.NoReturnValue + flags.ReturnValueVoid + flags.ReturnValueInline + flags.ReturnValueInArray;
u8 excep_cnt = flags.ExceptionInArray;
u8 prop_cnt = flags.PropertiesInArray;
u8 gen_cnt = flags.GenericMethod;
if(arg_cnt > 1 || ctx_cnt > 1 || sig_cnt > 1 || ret_cnt > 1 || excep_cnt > 1 || prop_cnt > 1 || gen_cnt > 1)
return -1;
if(arg_cnt != 0 && excep_cnt != 0) return -1;
if(ret_cnt != 0 && excep_cnt != 0) return -1;
if(ret_cnt != 0 && sig_cnt != 0) return -1;
if(excep_cnt != 0 && sig_cnt != 0) return -1;
return 1;
};
enum DateTimeKind: u8{
NOT_SPECIFIED = 0,
UTC = 1,
Local = 2
};
bitfield DateTime{
s64 Ticks: 62;
DateTimeKind kind: 2;
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 64)]];
struct vLength{
/*
Can't use that, it breaks when struct get re-parsed in _TrackersSection
u8 data[while(std::mem::read_unsigned($, 1) & 0x80)];
u8 last;
*/
u64 bytes [[no_unique_address, hidden]];
u8 cnt = 0;
if(bytes & 0x80){
if(bytes & 0x8000){
if(bytes & 0x800000){
if(bytes & 0x80000000){
if(bytes & 0x8000000000){
/* exceeding vLength 5 bytes, caller should crash */
cnt = 5;
}else cnt = 4;
}else cnt = 3;
}else cnt = 2;
}else cnt = 1;
}else cnt = 0;
u8 data[cnt];
u8 last;
} [[sealed, transform("LPS_Length_decode"), format("LPS_Length_decode")]];
fn LPS_Length_decode(auto Length){
u64 length = 0;
u8 i = 0;
for(i = 0, i < sizeof(Length.data), i += 1)
length |= u64(Length.data[i] & 0x7F) << i * 7;
length |= u64(Length.last) << i * 7;
return length;
};
struct LengthPrefixedString{
vLength Length;
std::assert(sizeof(Length) <= 5, "LengthPrefixedString.Length must be at most 5 bytes long");
char String[Length];
};
using Decimal = LengthPrefixedString;
struct ClassTypeInfo{
LengthPrefixedString TypeName;
s32 LibraryId;
};
struct ValueWithCode{
PrimitiveTypeEnum PrimitiveType;
match(PrimitiveType){
(PrimitiveTypeEnum::Boolean): bool Value;
(PrimitiveTypeEnum::Byte): u8 Value;
(PrimitiveTypeEnum::Char): char Value;
(PrimitiveTypeEnum::Currency): std::error("Primitive currency not used in this protocol");
(PrimitiveTypeEnum::Decimal): Decimal Value;
(PrimitiveTypeEnum::Double): double Value;
(PrimitiveTypeEnum::Int16): s16 Value;
(PrimitiveTypeEnum::Int32): s32 Value;
(PrimitiveTypeEnum::Int64): s64 Value;
(PrimitiveTypeEnum::SByte): s8 Value;
(PrimitiveTypeEnum::Single): float Value;
(PrimitiveTypeEnum::TimeSpan): TimeSpan Value;
(PrimitiveTypeEnum::DateTime): DateTime Value;
(PrimitiveTypeEnum::UInt16): u16 Value;
(PrimitiveTypeEnum::UInt32): u32 Value;
(PrimitiveTypeEnum::UInt64): u64 Value;
(PrimitiveTypeEnum::Null): {}
(PrimitiveTypeEnum::String): LengthPrefixedString Value;
(_): std::error(std::format("Unexpected {}", PrimitiveType));
}
};
struct StringValueWithCode: PrimitiveTypeEnumT<PrimitiveTypeEnum::String>{
LengthPrefixedString StringValue;
};
struct ArrayOfValueWithCode{
s32 Length;
ValueWithCode ListOfValueWithCode[Length];
};
struct ArrayInfo{
s32 ObjectId;
s32 Length;
};
struct ClassInfo{
s32 ObjectId;
LengthPrefixedString Name;
s32 MemberCount;
LengthPrefixedString MemberNames[MemberCount];
};
struct AdditionalInfo<auto _binaryTypeEnum>{
BinaryTypeEnum binaryTypeEnum = _binaryTypeEnum;
match(binaryTypeEnum){
(BinaryTypeEnum::SystemClass): /* ObjectUrt */
LengthPrefixedString String;
(BinaryTypeEnum::Class): /* ObjectUser */
ClassTypeInfo classTypeInfo;
(BinaryTypeEnum::Primitive | BinaryTypeEnum::PrimitiveArray): {
PrimitiveTypeEnum primitiveType;
std::assert(primitiveType != PrimitiveTypeEnum::Null &&
primitiveType != PrimitiveTypeEnum::String, "Must not be Null or String");
}
(BinaryTypeEnum::String | BinaryTypeEnum::Object |
BinaryTypeEnum::ObjectArray | BinaryTypeEnum::StringArray):
{/* not using continue here, need to keep array index matching */}
(_): std::error(std::format("Unrecognized {}", binaryTypeEnum));
}
};
struct MemberTypeInfo<auto MemberCount>{
BinaryTypeEnum binaryTypeEnums[MemberCount];
AdditionalInfo<binaryTypeEnums[std::core::array_index()]> additionalInfo[MemberCount];
};
struct UntypedMember<auto _className, auto classInfo>{
str className = _className;
u64 MemberCount = classInfo.MemberCount;
if(className == "System.Guid" && MemberCount == 11){
match(std::core::array_index()){
(0): s32 _a;
(1): s16 _b;
(2): s16 _c;
(3): u8 _d;
(4): u8 _e;
(5): u8 _f;
(6): u8 _g;
(7): u8 _h;
(8): u8 _i;
(9): u8 _j;
(10): u8 _k;
(_): std::error("unreachable");
}
}else if(MemberCount == 1 && classInfo.MemberNames[0].String == "value__"){
str Name = classInfo.MemberNames[0].String;
s32 member [name(Name)];
}else
std::error(std::format("Unsupported untyped member: {}", className));
};
using Record;
struct Members<auto _Name, auto memberTypeInfo>{
u64 i = std::core::array_index();
str Name = _Name;
BinaryTypeEnum binaryTypeEnum = memberTypeInfo.binaryTypeEnums[i];
if(binaryTypeEnum == BinaryTypeEnum::Primitive){
PrimitiveTypeEnum primitiveTypeEnum = memberTypeInfo.additionalInfo[i].primitiveType;
match(primitiveTypeEnum){
(PrimitiveTypeEnum::Boolean): bool Value [[name(Name)]];
(PrimitiveTypeEnum::Byte): u8 Value [[name(Name)]];
(PrimitiveTypeEnum::Char): char Value [[name(Name)]];
(PrimitiveTypeEnum::Currency): std::error("Primitive currency not used in this protocol");
(PrimitiveTypeEnum::Decimal): Decimal Value [[name(Name)]];
(PrimitiveTypeEnum::Double): double Value [[name(Name)]];
(PrimitiveTypeEnum::Int16): s16 Value [[name(Name)]];
(PrimitiveTypeEnum::Int32): s32 Value [[name(Name)]];
(PrimitiveTypeEnum::Int64): s64 Value [[name(Name)]];
(PrimitiveTypeEnum::SByte): s8 Value [[name(Name)]];
(PrimitiveTypeEnum::Single): float Value [[name(Name)]];
(PrimitiveTypeEnum::TimeSpan): TimeSpan Value [[name(Name)]];
(PrimitiveTypeEnum::DateTime): DateTime Value [[name(Name)]];
(PrimitiveTypeEnum::UInt16): u16 Value [[name(Name)]];
(PrimitiveTypeEnum::UInt32): u32 Value [[name(Name)]];
(PrimitiveTypeEnum::UInt64): u64 Value [[name(Name)]];
(PrimitiveTypeEnum::Null): {}
(PrimitiveTypeEnum::String): LengthPrefixedString Value [[name(Name)]];
(_): std::error(std::format("Unexpected {}", primitiveTypeEnum));
}
}else{
Record record [[name(Name)]];
}
};
struct ClassWithMembersAndTypes: RecordTypeEnumT<RecordTypeEnum::ClassWithMembersAndTypes>{
ClassInfo classInfo;
MemberTypeInfo<classInfo.MemberCount> memberTypeInfo;
s32 LibraryId;
Members<classInfo.MemberNames[std::core::array_index()].String, memberTypeInfo> members[classInfo.MemberCount];
};
struct ClassWithMembers: RecordTypeEnumT<RecordTypeEnum::ClassWithMembers>{
ClassInfo classInfo;
s32 LibraryId;
UntypedMember<classInfo.Name.String, classInfo> members[classInfo.MemberCount];
};
struct SystemClassWithMembersAndTypes: RecordTypeEnumT<RecordTypeEnum::SystemClassWithMembersAndTypes>{
ClassInfo classInfo;
MemberTypeInfo<classInfo.MemberCount> memberTypeInfo;
Members<classInfo.MemberNames[std::core::array_index()].String, memberTypeInfo> members[classInfo.MemberCount];
};
struct SystemClassWithMembers: RecordTypeEnumT<RecordTypeEnum::SystemClassWithMembers>{
ClassInfo classInfo;
UntypedMember<classInfo.Name.String, classInfo> members[classInfo.MemberCount];
};
struct ClassWithId: RecordTypeEnumT<RecordTypeEnum::ClassWithId>{
s32 ObjectId;
s32 MetadataId;
if(!IsUpdatingTrackers && NeedUpdateTrackers){
IsUpdatingTrackers = true;
_Trackers _trackers @ 0x0 in _TrackersSection;
IsUpdatingTrackers = false;
NeedUpdateTrackers = false;
}
match(_trackers.objs[MetadataId].objEnum){
(_ObjEnum::ClassWithMembersAndTypes): {
u32 MemberCount = _trackers.objs[MetadataId].classWithMembersAndTypes.data.classInfo.MemberCount;
Members<_trackers.objs[MetadataId].classWithMembersAndTypes.data.classInfo.MemberNames[std::core::array_index()].String, _trackers.objs[MetadataId].classWithMembersAndTypes.data.memberTypeInfo> members[MemberCount];
}
(_ObjEnum::SystemClassWithMembersAndTypes): {
u32 MemberCount = _trackers.objs[MetadataId].systemClassWithMemberAndTypes.data.classInfo.MemberCount;
Members<_trackers.objs[MetadataId].systemClassWithMemberAndTypes.data.classInfo.MemberNames[std::core::array_index()].String, _trackers.objs[MetadataId].systemClassWithMemberAndTypes.data.memberTypeInfo> members[MemberCount];
}
(_ObjEnum::SystemClassWithMembers): {
str className = _trackers.objs[MetadataId].TypeName.data.String;
u32 MemberCount = _trackers.objs[MetadataId].systemClassWithMembers.data.classInfo.MemberCount;
UntypedMember<className, _trackers.objs[MetadataId].systemClassWithMembers.data.classInfo> members[MemberCount];
}
(_ObjEnum::ClassWithMembers): {
str className = _trackers.objs[MetadataId].TypeName.data.String;
u32 MemberCount = _trackers.objs[MetadataId].classWithMembers.data.classInfo.MemberCount;
UntypedMember<className, _trackers.objs[MetadataId].classWithMembers.data.classInfo> members[MemberCount];
}
(_): std::error(std::format("Unexpected {}", _trackers.objs[MetadataId].objEnum));
}
};
struct BinaryArray: RecordTypeEnumT<RecordTypeEnum::BinaryArray>{
s32 ObjectId;
BinaryArrayTypeEnum binaryArrayTypeEnum;
s32 Rank;
s32 Length[Rank];
if(binaryArrayTypeEnum == BinaryArrayTypeEnum::SingleOffset ||
binaryArrayTypeEnum == BinaryArrayTypeEnum::JaggedOffset ||
binaryArrayTypeEnum == BinaryArrayTypeEnum::RectangularOffset)
s32 LowerBounds[Rank];
BinaryTypeEnum TypeEnum;
AdditionalInfo<TypeEnum> additionalInfo;
};
struct ArraySinglePrimitive: RecordTypeEnumT<RecordTypeEnum::ArraySinglePrimitive>{
ArrayInfo arrayInfo;
PrimitiveTypeEnum primitiveTypeEnum;
std::assert(primitiveTypeEnum != PrimitiveTypeEnum::Null &&
primitiveTypeEnum != PrimitiveTypeEnum::String, "Can't be one of those");
match(primitiveTypeEnum){
(PrimitiveTypeEnum::Boolean): bool Values[arrayInfo.Length];
(PrimitiveTypeEnum::Byte): u8 Value[arrayInfo.Length];
(PrimitiveTypeEnum::Char): char Value[arrayInfo.Length];
(PrimitiveTypeEnum::Currency): std::error("Primitive currency not used in this protocol");
(PrimitiveTypeEnum::Decimal): Decimal Value[arrayInfo.Length];
(PrimitiveTypeEnum::Double): double Value[arrayInfo.Length];
(PrimitiveTypeEnum::Int16): s16 Value[arrayInfo.Length];
(PrimitiveTypeEnum::Int32): s32 Value[arrayInfo.Length];
(PrimitiveTypeEnum::Int64): s64 Value[arrayInfo.Length];
(PrimitiveTypeEnum::SByte): s8 Value[arrayInfo.Length];
(PrimitiveTypeEnum::Single): float Value[arrayInfo.Length];
(PrimitiveTypeEnum::TimeSpan): TimeSpan Value[arrayInfo.Length];
(PrimitiveTypeEnum::DateTime): DateTime Value[arrayInfo.Length];
(PrimitiveTypeEnum::UInt16): u16 Value[arrayInfo.Length];
(PrimitiveTypeEnum::UInt32): u32 Value[arrayInfo.Length];
(PrimitiveTypeEnum::UInt64): u64 Value[arrayInfo.Length];
(PrimitiveTypeEnum::Null): {}
(PrimitiveTypeEnum::String): LengthPrefixedString Value[arrayInfo.Length];
(_): std::error(std::format("Unexpected {}", primitiveTypeEnum));
}
};
u64 ArraySinglElementSkipCount = 0;
struct ArraySingleElement<auto _recordTypeEnum>{
RecordTypeEnum recordTypeEnum = _recordTypeEnum;
if(ArraySinglElementSkipCount > 0)
ArraySinglElementSkipCount -= 1;
else{
if(recordTypeEnum == RecordTypeEnum::ArraySingleString){
Record record [[inline]];
match(record.recordTypeEnum){
(RecordTypeEnum::ObjectNullMultiple):
ArraySinglElementSkipCount = record.objectNullMultiple.NullCount;
(RecordTypeEnum::ObjectNullMultiple256):
ArraySinglElementSkipCount = record.objectNullMultiple256.NullCount;
(_): {}
}
}else{
Record record [[inline]];
if(record.recordTypeEnum == RecordTypeEnum::BinaryLibrary){
Record record2 [[inline]];
match(record2.recordTypeEnum){
(RecordTypeEnum::ObjectNullMultiple):
ArraySinglElementSkipCount = record2.objectNullMultiple.NullCount;
(RecordTypeEnum::ObjectNullMultiple256):
ArraySinglElementSkipCount = record2.objectNullMultiple256.NullCount;
(_): {}
}
}else{
match(record.recordTypeEnum){
(RecordTypeEnum::ObjectNullMultiple):
ArraySinglElementSkipCount = record.objectNullMultiple.NullCount;
(RecordTypeEnum::ObjectNullMultiple256):
ArraySinglElementSkipCount = record.objectNullMultiple256.NullCount;
(_): {}
}
}
}
}
};
struct ArraySingleObject: RecordTypeEnumT<RecordTypeEnum::ArraySingleObject>{
ArrayInfo arrayInfo;
ArraySinglElementSkipCount = 0;
ArraySingleElement<RecordTypeEnum::ArraySingleObject> records[arrayInfo.Length];
};
struct ArraySingleString: RecordTypeEnumT<RecordTypeEnum::ArraySingleString>{
ArrayInfo arrayInfo;
ArraySinglElementSkipCount = 0;
ArraySingleElement<RecordTypeEnum::ArraySingleString> records[arrayInfo.Length];
};
struct MethodReturnCallArray{
if(parent.MessageEnum.ReturnValueInArray)
ArraySingleObject ReturnValue;
if(parent.MessageEnum.ArgsInArray)
ArraySingleObject OutputArguments;
if(parent.MessageEnum.ExceptionInArray)
ArraySingleObject Exception;
if(parent.MessageEnum.ContextInArray)
ArraySingleObject CallContext;
if(parent.MessageEnum.PropertiesInArray)
ArraySingleObject MessageProperties;
};
struct MethodCallArray{
if(parent.MessageEnum.ArgsInArray)
ArraySingleObject InputArguments;
if(parent.MessageEnum.GenericMethod)
ArraySingleObject GenericTypeArguments;
if(parent.MessageEnum.MethodSignatureInArray)
ArraySingleObject MethodSignature;
if(parent.MessageEnum.ContextInArray)
ArraySingleObject CallContext;
if(parent.MessageEnum.PropertiesInArray)
ArraySingleObject MessageProperties;
};
struct BinaryMethodReturn: RecordTypeEnumT<RecordTypeEnum::MethodReturn>{
MessageFlags MessageEnum;
std::assert(validate_MessageFlags(MessageEnum) >= 0, "Validation Failed");
std::assert(!MessageEnum.MethodSignatureInArray && !MessageEnum.GenericMethod, "Can't be one of those");
if(MessageEnum.ReturnValueInline)
ValueWithCode ReturnValue;
if(MessageEnum.ContextInline)
StringValueWithCode CallContext;
if(MessageEnum.ArgsInline)
ArrayOfValueWithCode Args;
MethodReturnCallArray ReturnCallArray;
};
struct BinaryMethodCall: RecordTypeEnumT<RecordTypeEnum::MethodCall>{
MessageFlags MessageEnum;
std::assert(validate_MessageFlags(MessageEnum) >= 0, "Validation Failed");
std::assert(!MessageEnum.NoReturnValue && !MessageEnum.ReturnValueVoid &&
!MessageEnum.ReturnValueInline && !MessageEnum.ReturnValueInArray &&
!MessageEnum.ExceptionInArray, "Can't be one of those");
StringValueWithCode MethodName;
StringValueWithCode TypeName;
if(MessageEnum.ContextInline)
StringValueWithCode CallContext;
if(MessageEnum.ArgsInline)
ArrayOfValueWithCode Args;
MethodCallArray CallArray;
};
struct MemberPrimitiveTyped: RecordTypeEnumT<RecordTypeEnum::MemberPrimitiveTyped>{
PrimitiveTypeEnum primitiveTypeEnum;
std::assert(primitiveTypeEnum != PrimitiveTypeEnum::Null &&
primitiveTypeEnum != PrimitiveTypeEnum::String, "Can't be one of those");
match(primitiveTypeEnum){
(PrimitiveTypeEnum::Boolean): bool Value;
(PrimitiveTypeEnum::Byte): u8 Value;
(PrimitiveTypeEnum::Char): char Value;
(PrimitiveTypeEnum::Currency): std::error("Primitive currency not used in this protocol");
(PrimitiveTypeEnum::Decimal): Decimal Value;
(PrimitiveTypeEnum::Double): double Value;
(PrimitiveTypeEnum::Int16): s16 Value;
(PrimitiveTypeEnum::Int32): s32 Value;
(PrimitiveTypeEnum::Int64): s64 Value;
(PrimitiveTypeEnum::SByte): s8 Value;
(PrimitiveTypeEnum::Single): float Value;
(PrimitiveTypeEnum::TimeSpan): TimeSpan Value;
(PrimitiveTypeEnum::DateTime): DateTime Value;
(PrimitiveTypeEnum::UInt16): u16 Value;
(PrimitiveTypeEnum::UInt32): u32 Value;
(PrimitiveTypeEnum::UInt64): u64 Value;
(_): std::error(std::format("Unexpected {}", primitiveTypeEnum));
}
};
struct MemberPrimitiveUnTyped<auto PrimitiveType>{
match(PrimitiveType){
(PrimitiveTypeEnum::Boolean): bool Value;
(PrimitiveTypeEnum::Byte): u8 Value;
(PrimitiveTypeEnum::Char): char Value;
(PrimitiveTypeEnum::Currency): std::error("Primitive currency not used in this protocol");
(PrimitiveTypeEnum::Decimal): Decimal Value;
(PrimitiveTypeEnum::Double): double Value;
(PrimitiveTypeEnum::Int16): s16 Value;
(PrimitiveTypeEnum::Int32): s32 Value;
(PrimitiveTypeEnum::Int64): s64 Value;
(PrimitiveTypeEnum::SByte): s8 Value;
(PrimitiveTypeEnum::Single): float Value;
(PrimitiveTypeEnum::TimeSpan): TimeSpan Value;
(PrimitiveTypeEnum::DateTime): DateTime Value;
(PrimitiveTypeEnum::UInt16): u16 Value;
(PrimitiveTypeEnum::UInt32): u32 Value;
(PrimitiveTypeEnum::UInt64): u64 Value;
(PrimitiveTypeEnum::Null): {}
(PrimitiveTypeEnum::String):std::error("Can't be String");
(_): std::error(std::format("Unexpected {}", PrimitiveType));
}
};
struct MemberReference: RecordTypeEnumT<RecordTypeEnum::MemberReference>{
s32 IdRef;
};
struct ObjectNull: RecordTypeEnumT<RecordTypeEnum::ObjectNull>{
};
struct ObjectNullMultiple: RecordTypeEnumT<RecordTypeEnum::ObjectNullMultiple>{
s32 NullCount;
};
struct ObjectNullMultiple256: RecordTypeEnumT<RecordTypeEnum::ObjectNullMultiple256>{
u8 NullCount;
};
struct BinaryObjectString: RecordTypeEnumT<RecordTypeEnum::BinaryObjectString>{
s32 ObjectId;
LengthPrefixedString Value;
};
struct SerializationHeaderRecord: RecordTypeEnumT<RecordTypeEnum::SerializedStreamHeader>{
s32 RootId;
s32 HeaderId;
s32 MajorVersion;
std::assert_warn(MajorVersion == 1, "MajorVersion should be 1");
s32 MinorVersion;
std::assert_warn(MinorVersion == 0, "MinorVersion should be 0");
};
struct BinaryLibrary: RecordTypeEnumT<RecordTypeEnum::BinaryLibrary>{
s32 LibraryId;
LengthPrefixedString LibraryName;
};
struct MessageEnd: RecordTypeEnumT<RecordTypeEnum::MessageEnd>{
};
struct CrossAppDomainMap: RecordTypeEnumT<RecordTypeEnum::CrossAppDomainMap>{
s32 crossAppDomainArrayIndex;
};
struct CrossAppDomainString: RecordTypeEnumT<RecordTypeEnum::CrossAppDomainString>{
s32 ObjectId;
s32 Value;
};
struct CrossAppDomainAssembly: RecordTypeEnumT<RecordTypeEnum::CrossAppDomainAssembly>{
s32 LibraryId;
s32 LibraryIndex;
};
struct Record{
RecordTypeEnum recordTypeEnum [[no_unique_address, hidden]];
match(recordTypeEnum){
(RecordTypeEnum::SerializedStreamHeader):
std::error("SerializationStreamHeader can only appear at the top of the document");
(RecordTypeEnum::ClassWithId): { /* RecordTypeEnum::Object */
ClassWithId classWithId;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::ClassWithId;
_trackers.currentObj.RawPtr = append_value_to_section(classWithId, _TrackersSection);
_trackers.currentObj.TypeName.pointerValue = _trackers.objs[classWithId.MetadataId].TypeName.pointerValue;
_trackers.currentObj.AssemblyName.pointerValue =_trackers.objs[classWithId.MetadataId].AssemblyName.pointerValue ;
if(classWithId.ObjectId != 0)
copyCurrObjAtIdTrackers(classWithId.ObjectId);
}
}
(RecordTypeEnum::SystemClassWithMembers): { /* RecordTypeEnum::ObjectWithMap */
SystemClassWithMembers systemClassWithMembers;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::SystemClassWithMembers;
_trackers.currentObj.RawPtr = append_value_to_section(systemClassWithMembers, _TrackersSection);
_trackers.currentObj.TypeName.pointerValue = _trackers.currentObj.RawPtr + offsetOf(systemClassWithMembers, systemClassWithMembers.classInfo.Name);
if(systemClassWithMembers.classInfo.ObjectId != 0)
copyCurrObjAtIdTrackers(systemClassWithMembers.classInfo.ObjectId);
}
}
(RecordTypeEnum::ClassWithMembers): { /* RecordTypeEnum::ObjectWithMapAssemId */
ClassWithMembers classWithMembers;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::ClassWithMembers;
_trackers.currentObj.RawPtr = append_value_to_section(classWithMembers, _TrackersSection);
_trackers.currentObj.TypeName.pointerValue = _trackers.currentObj.RawPtr + offsetOf(classWithMembers, classWithMembers.classInfo.Name);
_trackers.currentObj.AssemblyName.pointerValue = _trackers.libs[classWithMembers.LibraryId].pointerValue;
if(classWithMembers.classInfo.ObjectId != 0)
copyCurrObjAtIdTrackers(classWithMembers.classInfo.ObjectId);
}
}
(RecordTypeEnum::SystemClassWithMembersAndTypes): { /* RecordTypeEnum::ObjectWithMapTyped */
SystemClassWithMembersAndTypes systemClassWithMembersAndTypes;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::SystemClassWithMembersAndTypes;
_trackers.currentObj.RawPtr = append_value_to_section(systemClassWithMembersAndTypes, _TrackersSection);
_trackers.currentObj.TypeName.pointerValue = _trackers.currentObj.RawPtr + offsetOf(systemClassWithMembersAndTypes, systemClassWithMembersAndTypes.classInfo.Name);
if(systemClassWithMembersAndTypes.classInfo.ObjectId != 0)
copyCurrObjAtIdTrackers(systemClassWithMembersAndTypes.classInfo.ObjectId);
}
}
(RecordTypeEnum::ClassWithMembersAndTypes): { /* RecordTypeEnum::ObjectWithMapTypedAssemId */
ClassWithMembersAndTypes classWithMembersAndTypes;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::ClassWithMembersAndTypes;
_trackers.currentObj.RawPtr = append_value_to_section(classWithMembersAndTypes, _TrackersSection);
_trackers.currentObj.TypeName.pointerValue = _trackers.currentObj.RawPtr + offsetOf(classWithMembersAndTypes, classWithMembersAndTypes.classInfo.Name);
_trackers.currentObj.AssemblyName.pointerValue = _trackers.libs[classWithMembersAndTypes.LibraryId].pointerValue;
if(classWithMembersAndTypes.classInfo.ObjectId != 0)
copyCurrObjAtIdTrackers(classWithMembersAndTypes.classInfo.ObjectId);
}
}
(RecordTypeEnum::BinaryObjectString): { /* RecordTypeEnum::ObjectString */
BinaryObjectString binaryObjectString;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::BinaryObjectString;
_trackers.currentObj.RawPtr = append_value_to_section(binaryObjectString, _TrackersSection);
if(binaryObjectString.ObjectId != 0)
copyCurrObjAtIdTrackers(binaryObjectString.ObjectId);
}
}
(RecordTypeEnum::BinaryArray): { /* RecordTypeEnum::Array */
BinaryArray binaryArray;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::BinaryArray;
_trackers.currentObj.RawPtr = append_value_to_section(binaryArray, _TrackersSection);
if(binaryArray.ObjectId != 0)
copyCurrObjAtIdTrackers(binaryArray.ObjectId);
}
}
(RecordTypeEnum::MemberPrimitiveTyped): {
MemberPrimitiveTyped memberPrimitiveTyped;
}
(RecordTypeEnum::MemberReference): {
MemberReference memberReference;
}
(RecordTypeEnum::ObjectNull): {}
(RecordTypeEnum::MessageEnd): break;
(RecordTypeEnum::BinaryLibrary): { /* RecordTypeEnum::Assembly */
BinaryLibrary library;
if(!IsUpdatingTrackers)
_trackers.libs[library.LibraryId].pointerValue = append_value_to_section(library.LibraryName, _TrackersSection);
}
(RecordTypeEnum::ObjectNullMultiple256): {
ObjectNullMultiple256 objectNullMultiple256;
}
(RecordTypeEnum::ObjectNullMultiple): {
ObjectNullMultiple objectNullMultiple;
}
(RecordTypeEnum::ArraySinglePrimitive): {
ArraySinglePrimitive arraySinglePrimitive;
if(!IsUpdatingTrackers){
zeroedCurrObjTrackers();
_trackers.currentObj.objEnum = _ObjEnum::ArraySinglePrimitive;
_trackers.currentObj.RawPtr = append_value_to_section(arraySinglePrimitive, _TrackersSection);
if(arraySinglePrimitive.arrayInfo.ObjectId != 0)
copyCurrObjAtIdTrackers(arraySinglePrimitive.arrayInfo.ObjectId);
}
}
(RecordTypeEnum::ArraySingleObject): {
ArraySingleObject arraySingleObject;
}
(RecordTypeEnum::ArraySingleString): {
ArraySingleString arraySingleString;
}
(RecordTypeEnum::CrossAppDomainMap):
CrossAppDomainMap crossAppDomainMap;
(RecordTypeEnum::CrossAppDomainString):
CrossAppDomainString crossAppDomainString;
(RecordTypeEnum::CrossAppDomainAssembly):
CrossAppDomainAssembly crossAppDomainAssembly;
(RecordTypeEnum::MethodCall): {
BinaryMethodCall binaryMethodCall;
}
(RecordTypeEnum::MethodReturn): {
BinaryMethodReturn binaryMethodReturn;
}
(_): std::error(std::format("Unrecognized {}", recordTypeEnum));
}
};
struct DotNetBinnaryFormatter{
SerializationHeaderRecord Header;
Record records[while(std::mem::read_unsigned($, 1) != RecordTypeEnum::MessageEnd)];
MessageEnd End;
if(!IsUpdatingTrackers && NeedUpdateTrackers){
IsUpdatingTrackers = true;
_Trackers _trackers @ 0x0 in _TrackersSection;
IsUpdatingTrackers = false;
NeedUpdateTrackers = false;
}
};
struct _ObjTracker{
_Ptr<LengthPrefixedString, u64> TypeName;
_Ptr<LengthPrefixedString, u64> AssemblyName;
_ObjEnum objEnum;
u64 RawPtr [[no_unique_address]];
/* Only enable the one we actually use to avoid significant slow down */
match(objEnum){
(_ObjEnum::Empty):
u64 ptr;
/*
(_ObjEnum::ClassWithId): // _ObjEnum::Object
_Ptr<ClassWithId, u64> classWithId;
*/
(_ObjEnum::SystemClassWithMembers): // _ObjEnum::ObjectWithMap
_Ptr<SystemClassWithMembers, u64> systemClassWithMembers;
(_ObjEnum::ClassWithMembers): // _ObjEnum::ObjectWithMapAssemId
_Ptr<ClassWithMembers, u64> classWithMembers;
(_ObjEnum::SystemClassWithMembersAndTypes): // _ObjEnum::ObjectWithMapTyped
_Ptr<SystemClassWithMembersAndTypes, u64> systemClassWithMemberAndTypes;
(_ObjEnum::ClassWithMembersAndTypes): // _ObjEnum::ObjectWithMapTypedAssemId
_Ptr<ClassWithMembersAndTypes, u64> classWithMembersAndTypes;
/*
(_ObjEnum::BinaryObjectString): // _ObjEnum::ObjectString
_Ptr<BinaryObjectString, u64> binaryObjectString;
(_ObjEnum::BinaryArray): // _ObjEnum::Array
_Ptr<BinaryArray, u64> binaryArray;
(_ObjEnum::MemberPrimitiveTyped):
_Ptr<MemberPrimitiveTyped, u64> memberPrimitiveTyped;
(_ObjEnum::MemberReference):
_Ptr<MemberReference, u64> memberReference;
(_ObjEnum::BinaryLibrary): // _ObjEnum::Assembly
_Ptr<BinaryLibrary, u64> library;
(_ObjEnum::ObjectNullMultiple256):
_Ptr<ObjectNullMultiple256, u64> objectNullMultiple256;
(_ObjEnum::ObjectNullMultiple):
_Ptr<ObjectNullMultiple, u64> objectNullMultiple;
(_ObjEnum::ArraySinglePrimitive):
_Ptr<ArraySinglePrimitive, u64> arraySinglePrimitive;
(_ObjEnum::ArraySingleObject):
_Ptr<ArraySingleObject, u64> arraySingleObject;
(_ObjEnum::ArraySingleString):
_Ptr<ArraySingleString, u64> arraySingleString;
(_ObjEnum::CrossAppDomainMap):
_Ptr<CrossAppDomainMap, u64> crossAppDomainMap;
(_ObjEnum::CrossAppDomainString):
_Ptr<CrossAppDomainString, u64> crossAppDomainString;
(_ObjEnum::CrossAppDomainAssembly):
_Ptr<CrossAppDomainAssembly, u64> crossAppDomainAssembly;
(_ObjEnum::MethodCall):
_Ptr<BinaryMethodCall, u64> binaryMethodCall;
(_ObjEnum::MethodReturn):
_Ptr<BinaryMethodReturn, u64> binaryMethodReturn;
*/
(_): u64 ptr; //std::error(std::format("Unexpected {}", objEnum));
}
};
/* Should be an In variable with default non zero value in the future until we use a hash map */
#define _OBJECTS_TRACKER_CNT 232
#define _LIBRARIES_CNT 8
struct _Trackers{
_ObjTracker currentObj;
/* TODO: this should really be an hash map, the algorithm that generated is unspecified */
_ObjTracker objs[_OBJECTS_TRACKER_CNT];
_Ptr<LengthPrefixedString, u64> libs[_LIBRARIES_CNT];
};
std::mem::set_section_size(_TrackersSection, sizeof(_trackers));
DotNetBinnaryFormatter dotNetBinnaryFormatter @ 0x0;

73
patterns/dpapiblob.hexpat Normal file
View File

@@ -0,0 +1,73 @@
#pragma description "DPAPI Blob"
import type.guid;
import std.mem;
enum ALG_ID : u32 {
CALG_DH_EPHEM = 0x0000aa02,
CALG_DH_SF = 0x0000aa01,
CALG_DSS_SIGN = 0x00002200,
CALG_ECDH = 0x0000aa05,
CALG_ECDH_EPHEM = 0x0000ae06,
CALG_ECDSA = 0x00002203,
CALG_ECMQV = 0x0000a001,
CALG_HASH_REPLACE_OWF = 0x0000800b,
CALG_HUGHES_MD5 = 0x0000a003,
CALG_HMAC = 0x00008009,
CALG_KEA_KEYX = 0x0000aa04,
CALG_MAC = 0x00008005,
CALG_MD2 = 0x00008001,
CALG_MD4 = 0x00008002,
CALG_MD5 = 0x00008003,
CALG_NO_SIGN = 0x00002000,
CALG_OID_INFO_CNG_ONLY = 0xffffffff,
CALG_OID_INFO_PARAMETERS = 0xfffffffe,
CALG_PCT1_MASTER = 0x00004c04,
CALG_RC2 = 0x00006602,
CALG_RC4 = 0x00006801,
CALG_RC5 = 0x0000660d,
CALG_RSA_KEYX = 0x0000a400,
CALG_RSA_SIGN = 0x00002400,
CALG_SCHANNEL_ENC_KEY = 0x00004c07,
CALG_SCHANNEL_MAC_KEY = 0x00004c03,
CALG_SCHANNEL_MASTER_HASH = 0x00004c02,
CALG_SEAL = 0x00006802,
CALG_SHA = 0x00008004,
CALG_SHA1 = 0x00008004,
CALG_SHA_256 = 0x0000800c,
CALG_SHA_384 = 0x0000800d,
CALG_SHA_512 = 0x0000800e,
CALG_SKIPJACK = 0x0000660a,
CALG_SSL2_MASTER = 0x00004c05,
CALG_SSL3_MASTER = 0x00004c01,
CALG_SSL3_SHAMD5 = 0x00008008,
CALG_TEK = 0x0000660b,
CALG_TLS1_MASTER = 0x00004c06,
CALG_TLS1PRF = 0x0000800a
};
struct DPAPI_BLOB{
u32 version[[name("Version")]];
type::GUID providerguid[[name("ProviderGUID")]];
u32 masterguid[[name("MasterKeyVersion")]];
type::GUID guid[[name("MasterKeyGUID")]];
u32 flags[[name("Flags")]];
u32 desclen [[name("DescriptionLen")]];
char16 desc[desclen / 0x02 ] [[name("Description")]];
ALG_ID cryptid [[name("AlgCryptId")]];
u32 algcryptlen[[name("AlgCryptLen")]];
u32 saltlen [[name("SaltLen")]];
char salt[saltlen][[name("Salt")]];
u32 hmackeylen[[name("HMACKeyLen")]];
char hmackey[hmackeylen][[name("HMACKey")]];
ALG_ID algid[[name("AlgHashId")]];
u32 alghashkeylen[[name("AlgHashKeyLen")]];
u32 hmac2keylen[[name("HMAC2keylen")]];
char hmac2[hmac2keylen][[name("HMAC2Key")]];
u32 datalen[[name("DataLen")]];
char data[datalen][[name("Data")]];
u32 signlen[[name("signlen")]];
char signhash[signlen][[name("SignHash")]];
};
DPAPI_BLOB dpapiblob @0x00 [[name("DPAPIBlob")]];

View File

@@ -0,0 +1,124 @@
#pragma description "DPAPIMasterKey"
/*
FilePath: C:\Users\<USER>\AppData\Roaming\Microsoft\Protect\<SID>
This files are hidden.
To unhide it,
1. Open Command Prompt (cmd.exe).
2. Run the following command:
- attrib -h -s
*/
import type.guid;
// https://learn.microsoft.com/en-us/windows/win32/seccrypto/alg-id
enum ALG_ID : u32 {
CALG_DH_EPHEM = 0x0000aa02,
CALG_DH_SF = 0x0000aa01,
CALG_DSS_SIGN = 0x00002200,
CALG_ECDH = 0x0000aa05,
CALG_ECDH_EPHEM = 0x0000ae06,
CALG_ECDSA = 0x00002203,
CALG_ECMQV = 0x0000a001,
CALG_HASH_REPLACE_OWF = 0x0000800b,
CALG_HUGHES_MD5 = 0x0000a003,
CALG_HMAC = 0x00008009,
CALG_KEA_KEYX = 0x0000aa04,
CALG_MAC = 0x00008005,
CALG_MD2 = 0x00008001,
CALG_MD4 = 0x00008002,
CALG_MD5 = 0x00008003,
CALG_NO_SIGN = 0x00002000,
CALG_OID_INFO_CNG_ONLY = 0xffffffff,
CALG_OID_INFO_PARAMETERS = 0xfffffffe,
CALG_PCT1_MASTER = 0x00004c04,
CALG_RC2 = 0x00006602,
CALG_RC4 = 0x00006801,
CALG_RC5 = 0x0000660d,
CALG_RSA_KEYX = 0x0000a400,
CALG_RSA_SIGN = 0x00002400,
CALG_SCHANNEL_ENC_KEY = 0x00004c07,
CALG_SCHANNEL_MAC_KEY = 0x00004c03,
CALG_SCHANNEL_MASTER_HASH = 0x00004c02,
CALG_SEAL = 0x00006802,
CALG_SHA = 0x00008004,
CALG_SHA1 = 0x00008004,
CALG_SHA_256 = 0x0000800c,
CALG_SHA_384 = 0x0000800d,
CALG_SHA_512 = 0x0000800e,
CALG_SKIPJACK = 0x0000660a,
CALG_SSL2_MASTER = 0x00004c05,
CALG_SSL3_MASTER = 0x00004c01,
CALG_SSL3_SHAMD5 = 0x00008008,
CALG_TEK = 0x0000660b,
CALG_TLS1_MASTER = 0x00004c06,
CALG_TLS1PRF = 0x0000800a
};
struct CREDHIST_MASTERKEY {
u32 version[[name("Version")]];
type::GUID guid[[name("GUID")]];
};
struct DOMAINKEY_MASTERKEY {
u32 version[[name("Version")]];
u32 seclen[[name("SecretLen")]];
u32 accesschklen[[name("AccessCheckLen")]];
type::GUID backupguid_[[name("BackupKeyGUID")]];
char blob[seclen][[name("Secret")]];
char accesschk[accesschklen][[name("AccessCheck")]];
};
struct BACKUP_MASTERKEY {
u32 start = $;
u32 version[[name("Version")]];
char salt[16][[name("Salt")]];
u32 rounds [[name("PBKDF2IterationCount")]];
ALG_ID alghashid[[name("HMACAlgId")]];
ALG_ID algcryptid[[name("CryptAlgId")]];
u32 meta = $ - start;
char key[parent.backupkeylen - meta][[name("Key")]];
};
struct PASSWORD_MASTERKEY {
u32 start = $;
u32 version[[name("Version")]];
char salt[16][[name("Salt")]];
u32 rounds [[name("PBKDF2IterationCount")]];
ALG_ID alghashid[[name("HMACAlgId")]];
ALG_ID algcryptid[[name("CryptAlgId")]];
u32 meta = $ - start;
char key[parent.masterkeylen - meta][[name("Key")]];
};
struct DPAPIMasterKey {
u32 version[[name("Version")]];
u32 unk1[[name("Unknown1")]];
u32 unk2[[name("Unknown2")]];
char16 guid[0x24][[name("GUID"), comment("This GUID is the fileName itself")]];
u32 unk3[[name("Unknown3")]];
u32 unk4[[name("Unknown4")]];
u32 policy[[name("Policy")]];
u64 masterkeylen [[name("MasterKeyLen")]];
u64 backupkeylen [[name("BackupKeyLen")]];
u64 credhistlen [[name("CredHistoryLen")]];
u64 domainkeylen [[name("DomainKeyLen")]];
if (masterkeylen > 0){
PASSWORD_MASTERKEY masterkey[[name("MasterKey")]];
}
if (backupkeylen > 0){
BACKUP_MASTERKEY backupkey[[name("BackupKey")]];
}
if (credhistlen > 0){
CREDHIST_MASTERKEY credhistkey[[name("CredHistoryKey")]];
}
if (domainkeylen > 0){
DOMAINKEY_MASTERKEY domainkey[[name("DomainKey")]];
}
};
DPAPIMasterKey masterkey @0x00[[name("DPAPIMasterKey")]];

View File

@@ -1,4 +1,5 @@
#pragma description .DS_Store file format
#pragma description macOS .DS_Store
#pragma magic [ 42 75 64 31 ] @ 0x04
// Apple macOS .DS_Store format
#pragma endian big
@@ -7,11 +8,11 @@ import std.io;
struct RecordEntry {
u32 length;
char16 filename[length];
char id[4];
// either blob or length
char type[4];
if (type == "blob") {
u32 blobCount;
u8 blobData[blobCount];
@@ -67,15 +68,15 @@ struct BuddyBlock {
u8 reserved[4];
// padding for next multiple of 256 entries (1024 bytes)
u32 addresses[blockCount];
// u8 padding[paddingCount];
u32 directoryCount;
// directory entries
u8 count;
u8 name[count];
u32 blockNumber;
// free lists
// 32 free lists
BuddyRootBlockOffsets off[32];
@@ -96,7 +97,7 @@ struct BuddyAllocator {
u32 offsetBookkeeping2;
u32 offsetData;
u8 reserved[12];
BuddyRootBlock root @ offsetBookkeeping + 4;
std::print("TOC {} address 0x{:08x}",
@@ -104,7 +105,7 @@ struct BuddyAllocator {
root.offsets.addresses[root.toc.toc[0].value] >> 0x5 << 0x5);
BlocksList blocks @ (root.offsets.addresses[root.toc.toc[0].value] >> 0x5 << 0x5) + 4;
std::print("Blocks start at address 0x{:08x}, size 0x{:04x}",
root.offsets.addresses[blocks.blockId] >> 0x5 << 0x5,
1 << (root.offsets.addresses[blocks.blockId] & 0x1f));

View File

@@ -1,17 +1,19 @@
#pragma description Digital Terrain Elevation Data
#pragma endian big
#pragma magic [ 4C 48 55 ] @ 0x00
import std.core;
import std.io;
import std.mem;
import std.string;
enum Magic:u24 {
enum Magic:u24 {
UHL = 0x55484C,
DSI = 0x445349,
ACC = 0x414343,
};
};
struct UHL {
Magic magic;
@@ -95,7 +97,7 @@ struct ACC {
ACCSub subs[9];
char reserved4[18];
char reserved5[69];
};
struct DataRecords {

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description ELF header in elf binaries
#pragma description Executable and Linkable Format executable (ELF)
#pragma MIME application/x-executable
#pragma MIME application/x-elf
@@ -10,6 +10,7 @@
import std.core;
import std.io;
import std.mem;
import type.magic;
using BitfieldOrder = std::core::BitfieldOrder;
@@ -496,14 +497,15 @@ bitfield SHF {
};
bitfield ELF32_R_INFO {
SYM : 8;
TYPE : 8;
} [[bitfield_order(BitfieldOrder::MostToLeastSignificant, 16)]];
TYPE : 8;
SYM : 8;
padding : 16;
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 32)]];
bitfield ELF64_R_INFO {
SYM : 32;
TYPE : 32;
} [[bitfield_order(BitfieldOrder::MostToLeastSignificant, 64)]];
SYM : 32;
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 64)]];
bitfield PF {
X : 1;
@@ -515,7 +517,7 @@ bitfield PF {
};
struct E_IDENT {
char EI_MAG[4];
type::Magic<"\x7fELF"> EI_MAG;
EI_CLASS EI_CLASS;
EI_DATA EI_DATA;
EI_VERSION EI_VERSION;
@@ -565,7 +567,7 @@ struct Elf32_Phdr {
Elf32_Word p_memsz;
PF p_flags;
Elf32_Word 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 [[sealed]];
};
@@ -579,7 +581,7 @@ struct Elf64_Phdr {
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 [[sealed]];
};
@@ -636,22 +638,25 @@ struct Elf32_Shdr {
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::SYMTAB || sh_type == SHT::DYNSYM) {
Elf32_Sym symbolTable[sh_size / sh_entsize] @ sh_offset;
} else if (sh_type == SHT::REL) {
Elf32_Rel relTable[sh_size / sh_entsize] @ sh_offset;
} else if (sh_type == SHT::RELA) {
Elf32_Rela relaTable[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 [[sealed]];
}
}
} [[format("format_section_header")]];;
} [[format("format_section_header")]];
struct Elf64_Chdr {
u32 ch_type;
@@ -696,15 +701,18 @@ struct Elf64_Shdr {
Elf64_Word sh_info;
Elf64_Xword sh_addralign;
Elf64_Xword 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::SYMTAB || sh_type == SHT::DYNSYM) {
Elf64_Sym symbolTable[sh_size / sh_entsize] @ sh_offset;
} else if (sh_type == SHT::REL) {
Elf64_Rel relTable[sh_size / sh_entsize] @ sh_offset;
} else if (sh_type == SHT::RELA) {
Elf64_Rela relaTable[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 {
@@ -715,7 +723,7 @@ struct Elf64_Shdr {
fn format_section_header(auto shdr) {
u32 i = 0;
u32 nameAddress = addressof(elf.shdr[stringTableIndex].stringTable) + shdr.sh_name;
String string @ nameAddress;
@@ -725,25 +733,32 @@ fn format_section_header(auto shdr) {
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 ehdr;
stringTableIndex = ehdr.e_shstrndx;
Elf32_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff;
Elf32_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff;
} else if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS64) {
Elf64_Ehdr ehdr;
stringTableIndex = ehdr.e_shstrndx;
Elf64_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff;
Elf64_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff;
}
};
ELF elf @ 0x00;
EI_DATA endian @ 0x05 [[hidden]];
match (endian) {
(EI_DATA::ELFDATA2LSB): std::core::set_endian(std::mem::Endian::Little);
(EI_DATA::ELFDATA2MSB): std::core::set_endian(std::mem::Endian::Big);
(_): std::core::set_endian(std::mem::Endian::Native);
}
fn gen_shdr_disp_name(ref auto pattern, str member_name, u8 member_index) {
return std::format(

119
patterns/esp32_image.hexpat Normal file
View File

@@ -0,0 +1,119 @@
#pragma author timschneeb
#pragma description ESP32 Firmware Image Format
#pragma endian little
// Reference: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html
import std.mem;
enum esp_chip_id_t : u16 {
ESP_CHIP_ID_ESP32 = 0x0000,
ESP_CHIP_ID_ESP32S2 = 0x0002,
ESP_CHIP_ID_ESP32C3 = 0x0005,
ESP_CHIP_ID_ESP32S3 = 0x0009,
ESP_CHIP_ID_ESP32C2 = 0x000C,
ESP_CHIP_ID_ESP32C6 = 0x000D,
ESP_CHIP_ID_ESP32H2 = 0x0010,
ESP_CHIP_ID_ESP32P4 = 0x0012,
ESP_CHIP_ID_ESP32C5 = 0x0017,
ESP_CHIP_ID_ESP32C61 = 0x0014,
ESP_CHIP_ID_ESP32H21 = 0x0019,
ESP_CHIP_ID_ESP32H4 = 0x001C,
ESP_CHIP_ID_INVALID = 0xFFFF
};
enum esp_image_spi_mode_t : u8 {
QIO,
QOUT,
DIO,
DOUT,
FAST_READ,
SLOW_READ
};
enum esp_image_spi_freq_t : u8 {
DIV_2,
DIV_3,
DIV_4,
DIV_1 = 0xF
};
enum esp_image_flash_size_t : u8 {
FLASH_1MB,
FLASH_2MB,
FLASH_4MB,
FLASH_8MB,
FLASH_16MB,
FLASH_32MB,
FLASH_64MB,
FLASH_128MB,
FLASH_MAX
};
bitfield spi_config_t {
esp_image_spi_freq_t spi_speed : 4;
esp_image_flash_size_t spi_size : 4;
};
const u32 ESP_APP_DESC_MAGIC_WORD = 0xABCD5432;
struct esp_app_desc_t {
u32 magic_word; // ESP_APP_DESC_MAGIC_WORD
u32 secure_version;
u32 reserv1[2];
char version[32];
char project_name[32];
char compile_time[16];
char compile_date[16];
char idf_ver[32];
u8 app_elf_sha256[32];
u16 min_efuse_blk_rev_full;
u16 max_efuse_blk_rev_full;
u8 mmu_page_size; // in log2 format
u8 reserv3[3];
u32 reserv2[18];
};
struct esp_image_header_t {
u8 magic; // 0xE9
u8 segment_count;
esp_image_spi_mode_t spi_mode;
spi_config_t spi_cfg;
u32 entry_addr;
u8 wp_pin [[comment("Write protect pin")]];
u8 spi_pin_drv[3] [[comment("Drive settings for the SPI flash pins")]];
esp_chip_id_t chip_id;
u8 min_chip_rev [[comment("Deprecated, replaced by min_chip_rev_full")]];
u16 min_chip_rev_full [[comment("Minimal revision (major*100+minor)")]];
u16 max_chip_rev_full [[comment("Maximal revision (major*100+minor)")]];
u8 reserved[4];
u8 hash_appended [[comment("If 1, a SHA256 digest 'simple hash' (of the entire image) is appended after the checksum")]];
};
struct esp_image_segment_header_t {
u32 load_addr;
u32 data_len;
};
union esp_image_segment_data_t {
u8 data[parent.header.data_len] [[hidden]];
// Application segment
if (std::mem::read_unsigned(addressof(data), 4) == ESP_APP_DESC_MAGIC_WORD) {
esp_app_desc_t app_descriptor;
}
};
struct esp_image_segment_t {
esp_image_segment_header_t header;
esp_image_segment_data_t data;
};
struct esp_image_t {
esp_image_header_t header;
esp_image_segment_t segments[header.segment_count];
};
esp_image_t image @ 0x0;

View File

@@ -1,5 +1,5 @@
#pragma description MS Windows Vista Event Log
#pragma MIME application/x-ms-evtx
#pragma endian little
struct Header {

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