Compare commits

...

40 Commits

Author SHA1 Message Date
Brandon Maier
6f7988e96e patterns: Added Xilinx boot images (#210)
* Adds pattern for Xilinx's Zynq UltraScale+ Boot Image format.
* Boot images are generated by Xilinx's `bootgen` tool.
* Spec: Xilinx UG1283 https://docs.xilinx.com/r/en-US/ug1283-bootgen-user-guide/Zynq-UltraScale-MPSoC-Boot-and-Configuration
* Add test file generated as follows
  - Build bootgen tool from https://github.com/Xilinx/bootgen
  - Create dummy data with `dd if=/dev/zero of=image.bin count=1`
  - Create bif with `echo "img: {image.bin}" >image.bif`
  - Create test bin with
    `./bootgen -arch zynqmp -image image.bif -o xilinx_bootgen.hexpat.bin`
2023-12-28 18:32:13 +01:00
g4ngli0s
0a631f0c1f patterns/pe: Fix BaseRelocationBlock count inside BaseRelocationTable (#212) 2023-12-28 18:31:53 +01:00
EvelynTSMG
5942897c29 patterns/ffx: Pull in latest updates (#209)
* Add Final Fantasy X patterns

* Update README

* Fix: github dum

* Add Bastion patterns

* git: update submodules

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2023-12-22 14:02:37 +01:00
utkumaden
a7e6209791 patterns: Added gITF pattern(#205)
* Create gltf.hexpat

Added glTF binary file pattern.

* Add a test file for the glTF pattern.

* Renamed the test file to fit the pattern file name.

* Fixed typo in documentation.
2023-12-07 17:09:25 +01:00
EvelynTSMG
294f69fa36 patterns: Add Bastion patterns (#207)
* Add Final Fantasy X patterns

* Update README

* Fix: github dum

* Add Bastion patterns

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2023-12-07 16:38:32 +01:00
gmestanley
1ea12cd4bd patterns/pe: Bringing over the massively improved version of pe.hexpat (#204)
* Add files via upload

* Update README.md

Added nes.hexpat to list of hex patterns

* Fix indenting of hex patterns list

Moved nes.hexpat below NE.hexpat

* Update README.md

Fixed indenting of PP pattern file's description being wrong

* Added x-msdownload MIME type to PE description

* Made indenting & code of ips.hexpat better

* Improvements to gb.hexpat

* Urgent fix to ips.hexpat

* Urgent fix to gb.hexpat

* Massive pe.hexpat improvement

* Replaced virtualDifference with relativeVirtualDifference

* Fixing unnecessary pattern_limit
2023-12-07 16:36:50 +01:00
Surasia
8129504dcb patterns/hinf_luas: Added pattern for reading HavokScript 5.1 Bytecode from Halo Infinite (#203)
* patterns/hinf_luas: Added pattern for reading HavokScript 5.1 Bytecode from Halo Infinite

* Parses Header and Structures of the parent tag
* Reads Bytecode types and arguments
* Reads Constants and Debug Info
* Reads Referenced Tags in the File

* readme: fix relative link
2023-12-07 16:36:27 +01:00
klirktag
22e30cfef9 patterns/mp4: Add STBL-box children (#202)
add STBL-box children
2023-12-07 16:36:07 +01:00
EvelynTSMG
9b819cf392 patterns: Add Final Fantasy X patterns (#197)
* Add Final Fantasy X patterns

* Update README

* Fix: github dum
2023-11-20 11:54:56 +01:00
klirktag
3277821153 patterns/mp4: Support mp4a and avc1 codec boxes (#195)
add support for mp4a and avc1 codec boxes, and sample-time-to-sample box
2023-11-15 22:26:10 +01:00
paxcut
f23dbbb565 includes/std: Fixed std::string::replace not replacing sequences correctly (#198)
fix:  [Bug] std::string::replace("aa", "aa", "") returns "a" #1408
2023-11-15 22:25:34 +01:00
Surasia
52f7d9e77a patterns/hinf_bitmap: Added pattern for parsing Halo Infinite bitmap files (#194)
* patterns/hinf_bitmap: Added pattern for parsing Halo Infinite bitmap files

* Parses the header of all Halo Infinite files which includes related "dependencies", datablocks, structure references
* Read bitmap sequence data, including bitmap index, complete index, sprite info
* Find the width/height and DDS Format of the raw texture, which can then be parsed into usable DDS textures
* Locates raw DDS block info

* Nulled out the DDS section of the bitmap
2023-11-14 00:20:32 +01:00
klirktag
99df77baf2 patterns/mp4: Add childbox support for STBL boxes (#192)
* find childboxes in stbl

* add implementation for SampleDescriptionBox
2023-11-14 00:06:50 +01:00
klirktag
d7b0819ff0 patterns/mp4: Make handler_type into a char[4], which reflects how it is used (#193)
make handler_type into a char[4], which reflects how it is used
2023-11-14 00:06:31 +01:00
Nik
70f491d2fa includes/type: Fixed formatting of time_t values in big endian patterns 2023-11-12 22:18:46 +01:00
Hugo
08680a6544 patterns/bplist: Added pattern file for Apple’s binary property list format (bplist) (#190)
* Added pattern file for Apple’s binary property list format (bplist)

* renamed some stuff and improved error messages

* added error handling for object size special case (0x0F)
2023-11-12 01:02:50 +01:00
Ange Albertini
23bc36c4bd patterns/selinux: Detailed SELinux config bitfield (#188) 2023-11-06 16:30:53 +01:00
Ange Albertini
8ae778944d patterns/se: Increased array limit (#187)
Increased array limit
2023-11-01 20:19:10 +01:00
klirktag
7e6a5d3bfa patterns/mp4: Added stbl box (#185) 2023-10-29 19:54:23 +01:00
Hugo
27e55d2e6d patterns/zip: Added parsing of extra field (#182)
* zip pattern: Improved fallback method for finding eocd. Added test data to cover this edge case

* zip pattern: added parsing of extra field
2023-10-29 19:47:11 +01:00
Benjamin Gilbert
e0a602c10a patterns/jpeg: Small improvements (#184)
* patterns/jpeg: exclude EOI marker from SOS image data

* patterns/jpeg: use type::Magic for magic numbers

* patterns/jpeg: add RGB component IDs

* patterns/jpeg: add struct for APP14 marker

* patterns/jpeg: add definition for COM marker

* patterns/jpeg: add some format_read() for better legibility
2023-10-29 19:46:51 +01:00
AdventureT
8748646016 patterns/CrashLvl: Update Crash Back in Time level format (#186)
* Working on new Version

* Needs testing

* Updated CrashLvl script to support version 0.94c

* Update README.md

* Added TestData and author to script

* Delete tests/patterns/test_data/CrashLvl.hexpat.bin
2023-10-29 19:46:28 +01:00
iTrooz
4a52ee4cf8 patterns: add UEFI Boot Entry pattern (#183)
add uefi_boot_entry pattern
2023-10-24 23:04:49 +02:00
iTrooz
e517e3534b patterns: fix description pragmas (#181) 2023-10-24 17:25:43 +02:00
DmitriLeon2000
edd0aa9a2f patterns: Add .fas and .was pattern files (Oska DeskMates) (#176)
* 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
2023-10-24 07:35:38 +02:00
Hugo
a992d1ba92 patterns/zip: Improved fallback method for finding eocd (#177)
zip pattern: Improved fallback method for finding eocd. Added test data to cover this edge case
2023-10-24 07:35:02 +02:00
leen
6fbdcac556 patterns/ip: Fix payload size when ip header or tcp header has options in ip.hexpat (#178) 2023-10-24 07:34:35 +02:00
itsmeow
47fce1628f patterns: Add ARIA2 Control format (#179) 2023-10-24 07:33:56 +02:00
Nik
9b152ae560 includes/std: Fixed doc comment of std::math::atan2 2023-10-22 21:25:14 +02:00
Nik
6b136b7fc6 includes/std: Fixed std::math::atan2 not taking correct arguments 2023-10-22 21:23:51 +02:00
gmestanley
93494a19a4 patterns: Better code + credit given for ips.hexpat & better readme (#174)
* Add files via upload

* Update README.md

Added nes.hexpat to list of hex patterns

* Fix indenting of hex patterns list

Moved nes.hexpat below NE.hexpat

* Update README.md

Fixed indenting of PP pattern file's description being wrong

* Added x-msdownload MIME type to PE description

* Made indenting & code of ips.hexpat better

* Improvements to gb.hexpat

* Urgent fix to ips.hexpat

* Urgent fix to gb.hexpat
2023-10-15 21:21:19 +02:00
H0L0
4fd710e23e patterns/flac: Fix SEEKTABLE metadata block (#173)
Add SEEKTABLE to blocktype check
2023-10-15 21:19:34 +02:00
Nik
44842dc44b includes/std: Added std::mem::set_section_size (#175) 2023-10-15 21:15:12 +02:00
HalfInner
056035c540 patterns/zip: Add parsing local file header with minor adjustment (#172)
patterns/zip: add parsing local file header, and another adjustmenst

Add missing parsing for local file headers
Add compression method
Minor adjustments: removed black colors, marked magic ids
2023-10-06 12:20:30 +02:00
Diego
5ad8e15afc patterns/shp: Added ESRI patterns (#170)
* add .shp and .shx patterns

* add tests
2023-10-06 12:20:11 +02:00
Nik
39c4d11404 patterns/uefi: Remove invalid MIME pragma 2023-10-05 08:54:59 +02:00
Benjamin Gilbert
815bd5f7f3 git: Minor readme fixes (#168) 2023-09-26 16:51:31 +02:00
Benjamin Gilbert
917b05a9f2 patterns: Add DICOM (#162)
DICOM files specify a "transfer syntax" which defines the image
compression format, the encoding rules for the entire file, and any
special-case encoding rules for particular fields.  Many transfer syntaxes
have common design features, but a transfer syntax is allowed to use
completely custom encoding rules, and need not be publicly documented.

Explicitly reject transfer syntaxes we know we don't support: implicit VR
(uncommon), explicit VR big-endian (deprecated), deflate-compressed.
In all other cases, follow some general rules and hope it works out.

The large lookup functions were generated by a script, but I haven't
included the code here, since its input is hand-massaged data copied from
HTML tables.

Add a JPEG WSI test case from the WG26 2021 hackathon (CC0 license) and a
synthetic LE Explicit VLP case produced with img2dcm.
2023-09-26 16:51:02 +02:00
brliron
46a2cef993 patterns: Added Android VBMeta image pattern (#169) 2023-09-26 14:03:24 +02:00
Nik
bca25b1a78 includes/hex: Fixed duplicate variable name in hex::core::get_selection() function
Fixes #167
2023-09-25 07:22:06 +02:00
52 changed files with 9546 additions and 987 deletions

8
.gitmodules vendored
View File

@@ -1,4 +1,10 @@
[submodule "rules"]
path = yara/official_rules
url = https://github.com/Yara-Rules/rules
branch = master
branch = master
[submodule "patterns/ffx"]
path = patterns/ffx
url = https://gitlab.com/EvelynTSMG/imhex-ffx-pats.git
[submodule "patterns/bastion"]
path = patterns/bastion
url = https://gitlab.com/EvelynTSMG/imhex-bastion-pats.git

View File

@@ -26,11 +26,14 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| 7Z | | [`patterns/7z.hexpat`](patterns/7z.hexpat) | 7z File Format |
| AFE2 | | [`patterns/afe2.hexpat`](patterns/afe2.hexpat) | Nintendo Switch Atmosphère CFW Fatal Error log |
| AR | `application/x-archive` | [`patterns/ar.hexpat`](patterns/ar.hexpat) | Static library archive files |
| 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 |
| Bastion | | [`patterns/bastion/*`](https://gitlab.com/EvelynTSMG/imhex-bastion-pats) | Various [Bastion](https://en.wikipedia.org/wiki/Bastion_(video_game)) files |
| Bencode | `application/x-bittorrent` | [`patterns/bencode.hexpat`](patterns/bencode.hexpat) | Bencode encoding, used by Torrent files |
| BMP | `image/bmp` | [`patterns/bmp.hexpat`](patterns/bmp.hexpat) | OS2/Windows Bitmap files |
| BIN | | [`patterns/selinux.hexpat`](patterns/selinux.pat) | SE Linux modules |
| 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) |
| BSP | | [`patterns/bsp_goldsrc.hexpat`](patterns/bsp_goldsrc.hexpat) | GoldSrc engine maps format (used in Half-Life 1) |
| CCHVA | | [`patterns/cchva.hexpat`](patterns/cchva.hexpat) | Command and Conquer Voxel Animation |
| CCVXL | | [`patterns/ccvxl.hexpat`](patterns/ccvxl.hexpat) | Command and Conquer Voxel Model |
@@ -39,20 +42,24 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| CHM | | [`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 flashback tapes level format |
| CrashLvl | | [`patterns/Crashlvl.hexpat`](patterns/Crashlvl.hexpat) | Crash Bandicoot - Back in Time (fan game) User created level format |
| DDS | `image/vnd-ms.dds` | [`patterns/dds.hexpat`](patterns/dds.hexpat) | DirectDraw Surface |
| DEX | | [`patterns/dex.hexpat`](patterns/dex.hexpat) | Dalvik EXecutable Format |
| DMG | | [`patterns/dmg.hexpat`](patterns/dmg.hexpat) | Apple Disk Image Trailer (DMG) |
| DS_Store | `application/octet-stream` | [`patterns/dsstore.hexpat`](patterns/dsstore.hexpat) | .DS_Store file format |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| GIF | `image/gif` | [`patterns/gif.hexpat`](patterns/gif.hexpat) | GIF image files |
| GZIP | `application/gzip` | [`patterns/gzip.hexpat`](patterns/gzip.hexpat) | GZip compressed data format |
| Halo Bitmap || [`patterns/hinf_bitmap.hexpat`](patterns/hinf_bitmap.hexpat) | Halo Infinite Bitmap tag files |
| Halo HavokScript || [`patterns/hinf_luas.hexpat`](patterns/hinf_luas.hexpat) | Halo Infinite HavokScript 5.1 Bytecode |
| 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 |
| Intel HEX | | [`patterns/intel_hex.hexpat`](patterns/intel_hex.hexpat) | [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX") |
@@ -76,8 +83,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| OGG | `audio/ogg` | [`patterns/ogg.hexpat`](patterns/ogg.hexpat) | OGG Audio format |
| PCAP | `application/vnd.tcpdump.pcap` | [`patterns/pcap.hexpat`](patterns/pcap.hexpat) | pcap header and packets |
| PCX | `application/x-pcx` | [`patterns/pcx.hexpat`](patterns/pcx.hexpat) | PCX Image format |
| PE | `application/x-dosexec` | [`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 |
| PP | | [`patterns/selinuxpp.hexpat`](patterns/selinuxpp.pat) | SE Linux package |
| PFS0 | | [`patterns/pfs0.hexpat`](patterns/pfs0.hexpat) | Nintendo Switch PFS0 archive (NSP files) |
| PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format |
| PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files |
@@ -88,6 +95,8 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| QBCL | | [`patterns/qbcl.hexpat`](patterns/qbcl.hexpat) | Qubicle voxel scene project file |
| QOI | `image/qoi` | [`patterns/qoi.hexpat`](patterns/qoi.hexpat) | QOI image files |
| 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 |
| shx | | [`patterns/shx.hexpat`](patterns/shx.hexpat) | ESRI index file |
| SPIRV | | [`patterns/spirv.hexpat`](patterns/spirv.hexpat) | SPIR-V header and instructions |
| 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 |
@@ -97,13 +106,16 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| Ubiquiti | | [`patterns/ubiquiti.hexpat`](patterns/ubiquiti.hexpat) | Ubiquiti Firmware (update) image |
| UEFI | | [`patterns/uefi.hexpat`](patterns/uefi.hexpat)` | UEFI structs for parsing efivars |
| UF2 | | [`patterns/uf2.hexpat`](patterns/uf2.hexpat) | [USB Flashing Format](https://github.com/microsoft/uf2) |
| VBMeta | | [`patterns/vbmeta.hexpat`](patterns/vbmeta.hexpat) | Android VBMeta image |
| VDF | | [`patterns/vdf.hexpat`](patterns/vdf.hexpat) | Binary Value Data Format (.vdf) files |
| VHDX | | [`patterns/vhdx.hexpat`](patterns/vhdx.hexpat) | Microsoft Hyper-V Virtual Hard Disk 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
| WAD | | [`patterns/wad.hexpat`](patterns/wad.hexpat) | DOOM WAD Archive |
| XBEH | `audio/x-xbox-executable` | [`patterns/xbeh.hexpat`](patterns/xbeh.hexpat) | Xbox executable |
| XCI | | [`patterns/xci.hexpat`](patterns/xci.hexpat) | Nintendo Switch XCI cardridge ROM |
| 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 |
| 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 |
@@ -119,9 +131,9 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
| Name | Path | Description |
|------|------|-------------|
| libstd | [`includes/std/*`](includes/std) | Pattern Language Standard Libaray |
| libtype | [`includes/type/*`](includes/type) | Various custom types with special formatters |
| libhex | [`includes/hex/*`](includes/hex) | Functions to interact with ImHex |
| libstd | [`includes/std/*`](includes/std) | Pattern Language Standard Library |
| libtype | [`includes/type/*`](includes/type) | Various custom types with special formatters |
### Yara rules

View File

@@ -21,20 +21,20 @@ namespace hex::core {
@return The current selection
*/
fn get_selection() {
u128 result = builtin::hex::core::get_selection();
u128 selection = builtin::hex::core::get_selection();
Selection result;
if (result == u128(-1)) {
if (selection == u128(-1)) {
result.valid = false;
result.address = 0x00;
result.size = 0x00;
} else {
result.valid = true;
result.address = result >> 64;
result.size = result & u64(-1);
result.address = selection >> 64;
result.size = selection & u64(-1);
}
return result;
};
}
}

View File

@@ -262,10 +262,11 @@ namespace std::math {
/**
Calculates the arc tangent of `value`.
@param value Value
@param y Value representing the proportion of the y-coordinate
@param x Value representing the proportion of the x-coordinate.
@return Arc tangent of `value` in radians between `-pi` and `pi`
*/
fn atan2(auto value) { return builtin::std::math::atan2(value); };
fn atan2(auto y, auto x) { return builtin::std::math::atan2(y, x); };
/**
Calculates the hyperbolic sine of `value`.

View File

@@ -180,6 +180,15 @@ namespace std::mem {
return builtin::std::mem::get_section_size(section);
};
/**
Changes the size of a custom section
@param section The handle to the section
@param size The new size of the section
*/
fn set_section_size(Section section, u128 size) {
builtin::std::mem::set_section_size(section, size);
};
/**
Copies a range of bytes from one section into another
@param from_section The section to copy from

View File

@@ -209,31 +209,27 @@ namespace std::string {
@param replace The substring to replace with.
@return The string with the replacements.
*/
fn replace(str string, str pattern, str replace) {
u32 string_len, pattern_len, replace_len;
string_len = std::string::length(string);
pattern_len = std::string::length(pattern);
replace_len = std::string::length(replace);
if (pattern_len > string_len)
return string;
fn replace(str string, str pattern, str replace) {
s32 string_len = std::string::length(string);
s32 pattern_len = std::string::length(pattern);
if (pattern_len > string_len || pattern_len * string_len == 0 )
return string;
str result;
u32 i;
while (i <= (string_len - pattern_len)) {
if (std::string::substr(string, i, pattern_len) == pattern) {
result = result + replace;
i = i + pattern_len;
} else {
result = result + std::string::at(string, i);
i = i + 1;
s32 string_index;
s32 remaining_len = string_len;
while (pattern_len <= remaining_len) {
if (std::string::substr(string, string_index, pattern_len) == pattern) {
result += replace;
string_index += pattern_len;
} else {
result += std::string::at(string, string_index);
string_index += 1;
}
remaining_len = string_len - string_index;
}
result = result + std::string::substr(string,string_len-pattern_len+1,pattern_len);
result += std::string::substr(string, string_index, remaining_len );
return result;
};
}

View File

@@ -34,7 +34,7 @@ namespace std::time {
/**
A type to represent a time in seconds since the epoch.
*/
using EpochTime = u128;
using EpochTime = u32;
/**
A type to represent a time zone.
@@ -91,7 +91,7 @@ namespace std::time {
@return The local time.
*/
fn to_local(EpochTime epoch_time) {
TimeConverter converter;
le TimeConverter converter;
converter.value = builtin::std::time::to_local(epoch_time);
@@ -104,7 +104,7 @@ namespace std::time {
@return The UTC time.
*/
fn to_utc(EpochTime epoch_time) {
TimeConverter converter;
le TimeConverter converter;
converter.value = builtin::std::time::to_utc(epoch_time);
@@ -117,7 +117,7 @@ namespace std::time {
@return The current time in the specified time zone.
*/
fn now(TimeZone time_zone = TimeZone::Local) {
TimeConverter converter;
le TimeConverter converter;
if (time_zone == TimeZone::Local)
converter.value = builtin::std::time::to_local(std::time::epoch());
@@ -135,7 +135,7 @@ namespace std::time {
@return The DOS date.
*/
fn to_dos_date(u16 value) {
impl::DOSDateConverter converter;
le impl::DOSDateConverter converter;
converter.value = value;
@@ -148,13 +148,22 @@ namespace std::time {
@return The DOS time.
*/
fn to_dos_time(u16 value) {
impl::DOSTimeConverter converter;
le impl::DOSTimeConverter converter;
converter.value = value;
return converter.time;
};
/**
Converts a FILETIME to unix time.
@param value The value to convert.
@return Timestamp formatted as unix time.
*/
fn filetime_to_unix(u64 value) {
return value / 10000000 - 11644473600;
};
/**
Formats a time according to the specified format string.
@param time The time to format.
@@ -162,7 +171,7 @@ namespace std::time {
@return The formatted time.
*/
fn format(Time time, str format_string = "%c") {
TimeConverter converter;
le TimeConverter converter;
converter.time = time;
return builtin::std::time::format(format_string, converter.value);

View File

@@ -34,6 +34,11 @@ namespace type {
*/
using DOSTime = u16 [[format("type::impl::format_dostime")]];
/**
A 64bit FILETIME value
*/
using FILETIME = u64 [[format("type::impl::format_filetime_as_unix")]];
namespace impl {
fn format_time_t(u128 value) {
@@ -48,6 +53,10 @@ namespace type {
return std::time::format_dos_time(std::time::to_dos_time(value));
};
fn format_filetime_as_unix(u64 value) {
return std::time::filetime_to_unix(value);
};
}
}

View File

@@ -1,20 +1,26 @@
#pragma description Crash Bandicoot - Back in Time (fan game) User created flashback tapes level format
#pragma author AdventureT
#pragma description Crash Bandicoot - Back in Time (fan game) User created level format
// Supports all versions till 0.94c, newer versions might be compatible!
#include <type/magic.pat>
#include <std/string.pat>
#include <std/array.pat>
// Crash Bandicoot - Back in Time (fan game) user created tapes
// author AdventureT
struct Header {
type::Magic<"CRASHLVL"> magic;
u8 version;
if (version >= 4) {
std::string::SizedString<u8> gameVersion;
}
std::string::SizedString<u8> levelName;
std::string::SizedString<u8> author;
};
enum Music : u32 {
Header header @ 0x0;
// Background Music
enum BGM : u32 {
None,
BonusBGM,
CrashCreatorBGM,
@@ -30,39 +36,199 @@ enum Music : u32 {
NBrioBGM
};
enum BGMV2 : u32 {
None,
N_TropyBGM,
CrashCreatorBGM,
MainMenuBGM,
WarpRoomBGM,
Jungle01BGM,
SnowBGM,
RiverBGM,
FutureBGM,
LabBGM,
SewerBGM,
EgyptBGM,
NBrioBGM,
AdventureBGM,
SpyBGM,
ChaseBGM,
TrialsBGM,
SpaceBGM,
Jungle02BGM,
RipperBGM,
TheGreatWallBGM,
RoadToSomewhereBGM,
LavaKoalaBGM,
CortexBGM,
CyberCortexBGM,
ArabicBGM,
N_Tropy2BGM,
JazzBGM,
Space2BGM,
TawnaBonusBGM,
CortexPowerBGM,
ArabicBonusBGM,
EgyptBonusBGM,
FutureBonusBGM,
LostCityBGM,
PolarBGM,
RiverBonusBGM,
RuinsBonusBGM,
SewerBonusBGM,
SnowBonusBGM,
RoadToRuinBGM,
NGinBGM,
Arabia01BGM,
Arabia02BGM,
BashBGM,
Cortex02BGM,
};
enum Type : u32 {
Unset,
Flashback,
Trial
Trial,
};
enum Time : u32 {
enum TypeV2 : u32 {
Practice,
Flashback,
Trial,
Adventure
};
enum Skybox : u32 {
Night,
Day,
Storm,
Dawn
};
enum Terrain : u32 {
enum SkyboxV2 : u32 {
Default = 1,
Briolab,
Fort,
Moon,
Toxic,
AboutRight,
Crash1Island,
Arabia,
RoadToRuin,
Black
};
enum Scenery : u32 {
None,
Machines,
Trees,
FutureTense,
Forest,
Waterfall,
Snow,
Fortress,
};
enum SceneryV2 : u32 {
None,
FutureTense,
Forest,
Waterfall,
None2,
Fortress,
None3,
Lava,
TheGreatGate,
Mountain,
KoalaKong,
SunsetVista,
HangemHigh,
Sphynxinator,
Tunnel,
Pipes
};
enum SceneryV4 : u32 {
None,
FutureTense,
Forest,
Waterfall,
Snow,
Fortress,
None2,
Lava,
TheGreatGate,
Mountain,
KoalaKong,
SunsetVista,
HangemHigh,
Sphynxinator,
Tunnel,
Pipes
};
enum Weather : u32 {
Default,
Snow,
Rain
};
struct Options {
Type type;
Time time;
Terrain terrain;
Music music;
if (header.version > 1)
TypeV2 type;
else
Type type;
if (header.version > 1)
SkyboxV2 skybox;
else
Skybox skybox;
if (header.version == 1)
Scenery scenery;
else if (header.version > 1 && header.version < 4)
SceneryV2 scenery;
else
SceneryV4 scenery;
if (header.version > 2)
{
Weather weather;
}
if (header.version > 1)
BGMV2 bgm;
else
BGM bgm;
if (type == Type::Trial)
{
u32 timeTrialTicksBronze;
u32 timeTrialTicksSilver;
u32 timeTrialTicksGold;
}
};
struct Object {
std::string::SizedString<u8> objName;
u32 x;
u32 y;
if (header.version > 1)
{
u16 x;
u16 y;
bool hasMetafields;
if (hasMetafields)
{
u16 numOfMetafields;
u8 metafields[numOfMetafields];
}
}
else
{
u32 x;
u32 y;
}
};
struct Objects{
@@ -70,6 +236,9 @@ struct Objects{
std::Array<Object, objCount> objArray;
};
Header header @ 0x0;
Options options @ $;
Objects objects @ $;
Objects objects @ $;

36
patterns/aria2.hexpat Normal file
View File

@@ -0,0 +1,36 @@
#pragma author itsmeow
#pragma description aria2 Control File
#pragma endian big
/*
Format sourced from:
https://aria2.github.io/manual/en/html/technical-notes.html#control-file-aria2-format
Version 0 files are not supported by default
However parsing one is as simple as changing to #pragma endian ittle
and resolving any errors resulting from that by adding be prefixes to struct fields.
*/
struct AriaInFlight {
u32 index;
u32 length;
u32 bitfield_piece_length;
u8 bitfield_p[bitfield_piece_length];
};
struct AriaHeader {
u16 version;
u32 extension;
u32 infohash_length;
u8 infohash[infohash_length];
u32 piece_length;
u64 total_length;
u64 upload_length;
u32 bitfield_length;
u8 bitfield_d[bitfield_length];
u32 inflight_count;
AriaInFlight inflights[inflight_count];
};
AriaHeader aria_header @ 0x00;

1
patterns/bastion Submodule

Submodule patterns/bastion added at e6deed433c

271
patterns/bplist.hexpat Normal file
View File

@@ -0,0 +1,271 @@
#include <std/math.pat>
#include <std/core.pat>
#include <type/magic.pat>
#include <type/time.pat>
using CFBinaryPlistObject;
enum Marker : u8 {
Null = 0x00,
False = 0x08,
True = 0x09,
Fill = 0x0F,
Int = 0x10,
Real = 0x20,
Date = 0x30,
Data = 0x40,
ASCIIString = 0x50,
Unicode16String = 0x60,
UNK_0x70 = 0x70,
UID = 0x80,
UNK_0x90 = 0x90,
Array = 0xA0,
UNK_0xB0 = 0xB0,
Set = 0xC0,
Dict = 0xD0,
UNK_0xE0 = 0xE0,
UNK_0xF0 = 0xF0
};
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
return "Fill";
}else if (marker & 0xF0 == Marker::Int){ //int 0001 nnnn ... // # of bytes is 2^nnnn, big-endian bytes
return "Int";
}else if (marker & 0xF0 == Marker:: Real){ //real 0010 nnnn ... // # of bytes is 2^nnnn, big-endian bytes
return "Real";
}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";
}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
return "Unicode16String";
}else if (marker & 0xF0 == Marker::UNK_0x70){ //0111 xxxx // unused
return "UNK_0x70";
}else if (marker & 0xF0 == Marker::UID){ //uid 1000 nnnn ... // nnnn+1 is # of bytes
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
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
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) {
return std::format("{}", get_marker(marker));
};
fn coredata_to_date (double val){
return type::impl::format_time_t(978307200 + val);
};
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 {
CFBinaryPlistObject value @ offsetTable[parent.objReference.value_refs[std::core::array_index()]].offset;
};
struct ObjectReference{
match(trailer.objectRefSize){
(1): {
be u8 key_refs[parent.ObjectLen.size];
be u8 value_refs[parent.ObjectLen.size];
}
(2): {
be u16 key_refs[parent.ObjectLen.size];
be u16 value_refs[parent.ObjectLen.size];
}
(4): {
be u32 key_refs[parent.ObjectLen.size];
be u32 value_refs[parent.ObjectLen.size];
}
(8): {
be u64 key_refs[parent.ObjectLen.size];
be u64 value_refs[parent.ObjectLen.size];
}
}
};
struct ObjectReferenceArray{
match(trailer.objectRefSize){
(1): be u8 value_refs[parent.ObjectLen.size];
(2): be u16 value_refs[parent.ObjectLen.size];
(4): be u32 value_refs[parent.ObjectLen.size];
(8): be u64 value_refs[parent.ObjectLen.size];
}
};
struct ObjectLen{
if (parent.marker_lsb != 0x0F){
u8 size = parent.marker_lsb [[export]];
}else{
CFBinaryPlistObject obj;
if (obj.marker & 0xF0 != Marker::Int){
std::error(std::format("Expects a 'Int' marker. Got 0x{:x} marker, with value {}", obj.marker, obj.value));
}
u128 size = obj.value [[export]];
}
};
struct CFBinaryPlistOffset{
match (trailer.offsetIntSize){
(1): be u8 offset;
(2): be u16 offset;
(4): be u32 offset;
(8): be u64 offset;
}
};
struct CFBinaryPlistObject{
u8 marker [[format("get_marker_name")]];
u8 marker_msb = marker & 0xF0;
u8 marker_lsb = marker & 0x0F;
match (marker_msb){
(0x0): {
match (marker_lsb){
(Marker::Null): {
u8 value = 0x00 [[export]];
}
(Marker::False): {
bool value = false [[export]];
}
(Marker::True): {
bool value = true [[export]];
}
(Marker::Fill): {
//I think the correct implementation is to do nothing here. The marker will be used as padding (Fill) ???
}
(_): {
std::error("Detected unknown marker {}.", marker_msb);
}
}
}
(Marker::Int): {
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'
// integers are not required to be in the most compact possible representation, but only the last 64 bits are significant currently
// Source: https://opensource.apple.com/source/CF/CF-550/CFBinaryPList.c
match (size) {
(1): be u8 value;
(2): be u16 value;
(4): be u32 value;
(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);
match (size){
(4): be float value;
(8): be double value;
(_): std::error(std::format("Invalid size detected for 'Real' marker. Got size: {}.", size));
}
}
(Marker::Date): {
be double value [[format("coredata_to_date")]];
}
(Marker::Data): {
ObjectLen ObjectLen;
u8 value[ObjectLen.size];
}
(Marker::ASCIIString): {
ObjectLen ObjectLen;
char value[ObjectLen.size];
}
(Marker::Unicode16String): {
ObjectLen ObjectLen;
be char16 value[ObjectLen.size];
}
(Marker::UID): {
//Not 100% sure if this is correct for UID. Need more testing
u8 size = marker_lsb+1;
match (size) {
(1): be u8 value;
(2): be u16 value;
(4): be u32 value;
(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;
ObjectReferenceArray objReference;
ArrayElement value[ObjectLen.size];
}
(Marker::Dict): {
ObjectLen ObjectLen;
ObjectReference objReference;
DictElement value[ObjectLen.size];
}
(Marker::UNK_0x70 | Marker::UNK_0x90 | Marker::UNK_0xB0 | Marker::UNK_0xE0 | Marker::UNK_0xF0): {
std::error(std::format("Got unused marker 0x{:x}", marker));
}
(_): {
std::error(std::format("Got unknown marker 0x{:x}", marker));
}
}
};
struct CFBinaryPlistHeader{
type::Magic<"bplist"> magic;
u16 version;
if (version != 0x3030){
std::error("Unsupported version detected. Only version 00 is supported (bplist00).");
}
};
struct CFBinaryPlistTrailer {
u8 unused[5];
u8 sortVersion;
be u8 offsetIntSize;
match (offsetIntSize){
(1|2|4|8): {}
(_): {std::error("Invalid offsetIntSize.");}
}
be u8 objectRefSize;
match (objectRefSize){
(1|2|4|8): {}
(_): {std::error("Invalid objectRefSize.");}
}
be u64 numObjects;
be u64 topObject;
be u64 offsetTableOffset;
};
CFBinaryPlistHeader header @ 0x00;
CFBinaryPlistTrailer trailer @ std::mem::size()-32;
CFBinaryPlistOffset offsetTable[trailer.numObjects] @ trailer.offsetTableOffset;
CFBinaryPlistObject objectTable @ offsetTable[trailer.topObject].offset;

5594
patterns/dicom.hexpat Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
#pragma author DmitriLeon2000
#pragma description Oska Software DeskMates FAS (Frames and Sequences) file
#pragma endian little
enum Compression : u32 {
BI_RGB,
BI_RLE8,
BI_RLE4,
BI_BITFIELDS,
BI_JPEG,
BI_PNG,
BI_ALPHABITFIELDS,
BI_CMYK,
BI_CMYKRLE8,
BI_CMYKRLE4,
};
struct Colors {
u8 blue;
u8 green;
u8 red;
u8 reserved;
};
struct FASHeader {
char name[50]; // name of the pack, may include garbage data
u16 version; // Format version number
s16 frameIDFirst; // assigned ID of the first frame
s16 frameIDLast; // assigned ID of the last frame
s32 width; // width of the animation (in pixels)
s32 height; // height of the animation (in pixels)
u16 frameSize; // size of the animation ((frameWidth * BPP + 31) // 32 * 4 * frameHeight)
u16 DblHeaderCount; // amount of BitmapInfoHeader pairs (one for color, one for masking)
};
struct BitmapInfoHeader { // bog-standard BitmapInfoHeaderV1
u32 biSize;
s32 biWidth;
s32 biHeight;
u16 biPlanes;
u16 biBitCount;
Compression compression;
u32 biSizeImage;
s32 biXPelsPerMeter;
s32 biYPelsPerMeter;
u32 biClrUsed;
u32 biClrImportant;
};
struct BitmapInfo {
BitmapInfoHeader header;
Colors colorMap[header.biClrUsed == 0 ?
1 << header.biBitCount : header.biClrUsed];
};
struct ExtraSprite {
char name[];
};
struct AnimSequence {
char name[];
char sequence[];
};
struct SeqHeader {
le u32 size;
le u32 count;
le u32 strPointers[count*2];
};
struct Bitmap {
u8 byte[fas.fasHeader.version >= 3 ? fas.fasHeader.frameSize + (fas.frameSizeHigh << 16) : fas.fasHeader.frameSize];
};
struct FramesHeader {
le u32 count;
le s16 frameID[count];
u8 frameDblHdrID[count];
};
struct FAS {
FASHeader fasHeader;
BitmapInfo dibHeaders[fasHeader.DblHeaderCount * 2];
if (fasHeader.version >= 1)
u8 charID;
if (fasHeader.version >= 2)
{
u32 extraEndOffset;
u16 extraSpritesCount;
if (extraSpritesCount)
// char extraSpriteList[touchOffset - 6];
ExtraSprite extraSprites[extraSpritesCount];
}
if (fasHeader.version >= 3)
le u16 frameSizeHigh;
le u16 touchColors;
if (touchColors)
{
u32 touchColorMap[touchColors];
u16 touchWidth;
u8 touchBitmap[this.touchWidth * fasHeader.height];
}
SeqHeader seqHeader;
if (fasHeader.version >= 1)
u8 filenameChecksum; // a checksum for a filename in ASCII
AnimSequence sequences[seqHeader.count];
FramesHeader framesHeader;
};
FAS fas @ 0x00;
Bitmap framesBitmap[fas.framesHeader.count] @ $;

View File

@@ -0,0 +1,87 @@
#pragma author DmitriLeon2000
#pragma description Oska Software DeskMates FAS (Frames and Sequences) file (Oska DeskMate versions 1.3 and 2.06)
#pragma endian little
enum Compression : u32 {
BI_RGB,
BI_RLE8,
BI_RLE4,
BI_BITFIELDS,
BI_JPEG,
BI_PNG,
BI_ALPHABITFIELDS,
BI_CMYK,
BI_CMYKRLE8,
BI_CMYKRLE4,
};
struct Colors {
u8 blue;
u8 green;
u8 red;
u8 reserved;
};
struct FASHeader {
s32 width; // width of the animation (in pixels)
s32 height; // height of the animation (in pixels)
u16 reserved1;
u16 reserved2;
u16 frameSizeCombined; // a sum of frameSizeColor and frameSizeMask
u16 frameSizeColor; // size of the animation ((frameWidth * 4 + 31) // 32 * 4 * frameHeight)
u16 frameSizeMask; // size of the animation's mask ((frameWidth * 1 + 31) // 32 * 4 * frameHeight)
u16 headerCount; // amount of DIB headers
};
struct BitmapInfoHeader { // bog-standard BitmapInfoHeaderV1
u32 biSize;
s32 biWidth;
s32 biHeight;
u16 biPlanes;
u16 biBitCount;
Compression compression;
u32 biSizeImage;
s32 biXPelsPerMeter;
s32 biYPelsPerMeter;
u32 biClrUsed;
u32 biClrImportant;
};
struct BitmapInfo {
BitmapInfoHeader header;
le u32 colorMap[header.biClrUsed == 0 ?
1 << header.biBitCount : header.biClrUsed];
};
struct AnimSequence {
char name[];
char sequence[];
};
struct SeqHeader {
le u32 size;
le u32 count;
le u32 strPointers[count*2];
};
struct Frame {
u8 colorBitmap[fas.fasHeader.frameSizeColor];
u8 maskBitmap[fas.fasHeader.frameSizeMask];
};
struct FramesHeader {
le u32 count;
le s16 frameID[count];
};
struct FAS {
FASHeader fasHeader;
BitmapInfo dibHeaders[fasHeader.headerCount];
SeqHeader seqHeader;
AnimSequence sequences[seqHeader.count];
FramesHeader framesHeader;
};
FAS fas @ 0x00;
Frame frames[fas.framesHeader.count] @ $;

1
patterns/ffx Submodule

Submodule patterns/ffx added at ad18b0259f

View File

@@ -307,6 +307,8 @@ struct METADATA_BLOCK {
METADATA_BLOCK_PADDING data;
else if (header.blockType == BLOCK_TYPE::APPLICATION)
METADATA_BLOCK_APPLICATION data;
else if (header.blockType == BLOCK_TYPE::SEEKTABLE)
METADATA_BLOCK_SEEKTABLE data;
else if (header.blockType == BLOCK_TYPE::VORBIS_COMMENT)
METADATA_BLOCK_VORBIS_COMMENT data;
else if (header.blockType == BLOCK_TYPE::CUESHEET)
@@ -323,4 +325,4 @@ struct STREAM {
//FRAME frames[while(!std::mem::eof())];
};
STREAM stream @ 0x00;
STREAM stream @ 0x00;

View File

@@ -1,340 +1,361 @@
#pragma author WerWolv
#pragma description Gameboy ROM
#include <type/size.pat>
#include <std/io.pat>
#include <std/string.pat>
#pragma MIME application/x-gameboy-rom
#include <type/size.pat>
#include <std/string.pat>
#include <std/mem.pat>
bool uppercaseROMFeatures in;
bool brandedROMFeatures in;
bitfield CGB {
padding : 2;
PGB_MODE : 2;
padding : 2;
CGB_ONLY : 1 [[comment("gbcOnly")]];
CGB_SUPPORT : 1 [[comment("supportsGBC")]];
} [[comment("GBCFlags")]];
namespace format {
fn rom_type(u8 romType) {
u32 romSize = 32768 * (1 << romType);
u16 romBanks = 2 * (1 << romType);
if(romType == 0x52) {
romSize = 1153434;
romBanks = 72;
}
if(romType == 0x53) {
romSize = 1258291;
romBanks = 80;
}
return std::format("size: {}, banks: {}", type::impl::size_formatter(romSize), romBanks);
};
fn ram_type(u8 ramType) {
u16 ramSize;
u16 ramBanks;
if(ramType == 2) {
ramSize = 8192;
ramBanks = 1;
}
if(ramType == 3) {
ramSize = 32768;
ramBanks = 4;
}
if(ramType == 4) {
ramSize = 131072;
ramBanks = 16;
}
if(ramType == 5) {
ramSize = 65536;
ramBanks = 8;
}
return std::format("size: {}, banks: {}", type::impl::size_formatter(ramSize), ramBanks);
};
fn rom_features(u8 type) {
str result = "( ";
match(type) {
(0x00): result += "no_mbc ";
(0x01): result += "mbc1 ";
(0x02): result += "mbc1 | ram ";
(0x03): result += "mbc1 | ram | battery ";
(0x05): result += "mbc2 ";
(0x06): result += "mbc2 | battery ";
(0x08): result += "no_mbc | ram ";
(0x09): result += "no_mbc | ram | battery ";
(0x0B): result += "mmm01 ";
(0x0C): result += "mmm01 | ram ";
(0x0D): result += "mmm01 | ram | battery ";
(0x0F): result += "mbc3 | timer | battery ";
(0x10): result += "mbc3 | timer | ram | battery ";
(0x11): result += "mbc3 ";
(0x12): result += "mbc3 | ram ";
(0x13): result += "mbc3 | ram | battery ";
(0x19): result += "mbc5 ";
(0x1A): result += "mbc5 | ram ";
(0x1B): result += "mbc5 | ram | battery ";
(0x1C): result += "mbc5 | rumble ";
(0x1D): result += "mbc5 | rumble | ram ";
(0x1E): result += "mbc5 | rumble | ram | battery ";
(0x20): result += "mbc6 ";
(0x22): result += "mbc7 | sensor | rumble ";
(0xFC): result += "camera ";
(0xFD): result += "tama5 ";
(0xFE): result += "huc3 ";
(0xFF): result += "huc1 | ram | battery ";
}
return result + ")";
};
fn licensee_code(u8 code) {
match(code) {
(0x00): return "None";
(0x01 | 0x31): return "Nintendo";
(0x08 | 0x38): return "Capcom";
(0x09): return "Hot-B";
(0x0A | 0xE0): return "Jaleco";
(0x0B): return "Coconuts Japan";
(0x0C | 0x6E): return "Elite Systems";
(0x13 | 0x69): return "EA (Electronic Arts)";
(0x18): return "Hudsonsoft";
(0x19): return "ITC Entertainment";
(0x1A): return "Yanoman";
(0x1D): return "Japan Clary";
(0x1F | 0x4A | 0x61): return "Virgin Interactive";
(0x24): return "PCM Complete";
(0x25): return "San-X";
(0x28): return "Kotobuki Systems";
(0x29): return "Seta";
(0x30 | 0x70): return "Infogrames";
(0x32 | 0xA2 | 0xB2 | 0xC4): return "Bandai";
(0x33): return "See new licensee";
(0x34 | 0xA4): return "Konami";
(0x35): return "HectorSoft";
(0x39 | 0x9D): return "Banpresto";
(0x3C): return ".Entertainment i";
(0x3E): return "Gremlin";
(0x41): return "Ubisoft";
(0x42 | 0xEB): return "Atlus";
(0x44 | 0x4D): return "Malibu";
(0x46 | 0xCF): return "Angel";
(0x47): return "Spectrum Holoby";
(0x49): return "Irem";
(0x50): return "Absolute";
(0x51 | 0xB0): return "Acclaim";
(0x52): return "Activision";
(0x53): return "American Sammy";
(0x54): return "GameTek";
(0x55): return "Park Place";
(0x56 | 0xDB | 0xFF): return "LJN";
(0x57): return "Matchbox";
(0x59): return "Milton Bradley";
(0x5A): return "Mindscape";
(0x5B): return "Romstar";
(0x5C | 0xD6): return "Naxat Soft";
(0x5D): return "Tradewest";
(0x60): return "Titus";
(0x67): return "Ocean Interactive";
(0x6F): return "Electro Brain";
(0x71): return "Interplay";
(0x72 | 0xAA): return "Broderbund";
(0x73): return "Sculptered Soft";
(0x75): return "The Sales Curve";
(0x78): return "t.hq";
(0x79): return "Accolade";
(0x7A): return "Triffix Entertainment";
(0x7C): return "Microprose";
(0x7F | 0xC2): return "Kemco";
(0x80): return "Misawa Entertainment";
(0x83): return "Lozc";
(0x86 | 0xC4): return "Tokuma Shoten Intermedia";
(0x8B): return "Bullet-Proof Software";
(0x8C): return "Vic Tokai";
(0x8E): return "Ape";
(0x8F): return "I'Max";
(0x91): return "Chunksoft Co.";
(0x92): return "Video System";
(0x93): return "Tsubaraya Productions Co.";
(0x95): return "Varie Corporation";
(0x96): return "Yonezawa/SPal";
(0x97): return "Kaneko";
(0x99): return "Arc";
(0x9A): return "Nihon Bussan";
(0x9B): return "Tecmo";
(0x9C): return "Imagineer";
(0x9F): return "Nova";
(0xA1): return "Hori Electric";
(0xA6): return "Kawada";
(0xA7): return "Takara";
(0xA9): return "Technos Japan";
(0xAC): return "Toei Animation";
(0xAD): return "Toho";
(0xAF): return "Namco";
(0xB1): return "ASCII or Nexsoft";
(0xB4): return "Square Enix";
(0xB6): return "HAL Laboratory";
(0xB7): return "SNK";
(0xB9 | 0xCE): return "Pony Canyon";
(0xBA): return "Culture Brain";
(0xBB): return "Sunsoft";
(0xBD): return "Sony Imagesoft";
(0xBF): return "Sammy";
(0xC0 | 0xD0): return "Taito";
(0xC3): return "Squaresoft";
(0xC5): return "Data East";
(0xC6): return "Tonkinhouse";
(0xC8): return "Koei";
(0xC9): return "UFL";
(0xCA): return "Ultra";
(0xCB): return "Vap";
(0xCC): return "Use Corporation";
(0xCD): return "Meldac";
(0xD1): return "Sofel";
(0xD2): return "Quest";
(0xD3): return "Sigma Enterprises";
(0xD4): return "ASK Kodansha Co.";
(0xD7): return "Copya System";
(0xDA): return "Tomy";
(0xDD): return "NCS";
(0xDE): return "Human";
(0xDF): return "Altron";
(0xE1): return "Towa Chiki";
(0xE2): return "Yutaka";
(0xE3): return "Varie";
(0xE5): return "Epoch";
(0xE7): return "Athena";
(0xE8): return "Asmik";
(0xE9): return "Natsume";
(0xEA): return "King Records";
(0xEE): return "IGS";
(0xF0): return "A Wave";
(0xF3): return "Extreme Entertainment";
}
return "Unknown Licensee";
};
fn new_licensee_code(str a) {
if(a[0] == 0 && a[1] == 0) return "See old licensee";
match(a) {
("00"): return "None";
("01"): return "Nintendo R&D1";
("08"): return "Capcom";
("13"): return "Electronic Arts";
("18"): return "Hudson Soft";
("19"): return "b-ai";
("20"): return "kss";
("22"): return "pow";
("24"): return "PCM Complete";
("25"): return "san-x";
("28"): return "Kemco Japan";
("29"): return "seta";
("30"): return "Viacom";
("31"): return "Nintendo";
("32"): return "Bandai";
("33"): return "Ocean/Acclaim";
("34"): return "Konami";
("35"): return "Hector";
("37"): return "Taito";
("38"): return "Hudson";
("39"): return "Banpresto";
("41"): return "Ubi Soft";
("42"): return "Atlus";
("44"): return "Malibu";
("46"): return "angel";
("47"): return "Bullet-Proof";
("49"): return "irem";
("50"): return "Absolute";
("51"): return "Acclaim";
("52"): return "Activision";
("53"): return "American sammy";
("54"): return "Konami";
("55"): return "Hi tech entertainment";
("56"): return "LJN";
("57"): return "Matchbox";
("58"): return "Mattel";
("59"): return "Milton Bradley";
("60"): return "Titus";
("61"): return "Virgin";
("64"): return "LucasArts";
("67"): return "Ocean";
("69"): return "Electronic Arts";
("70"): return "Infogrames";
("71"): return "Interplay";
("72"): return "Broderbund";
("73"): return "sculptured";
("75"): return "sci";
("78"): return "THQ";
("79"): return "Accolade";
("80"): return "misawa";
("83"): return "lozc";
("86"): return "Tokuma Shoten Intermedia";
("87"): return "Tsukuda Original";
("91"): return "Chunksoft";
("92"): return "Video system";
("93"): return "Ocean/Acclaim";
("95"): return "Varie";
("96"): return "Yonezawa/spal";
("97"): return "Kaneko";
("99"): return "Pack in soft";
("A4"): return "Konami (Yu-Gi-Oh!)";
}
return "Unknown";
};
fn cart_size(u8 cartSizeType) {
u32 romSize = 32768 * (1 << cartSizeType);
u16 romBanks = 2 * (1 << cartSizeType);
if (cartSizeType == 0x52) {
romSize = 1153434;
romBanks = 72;
}
if (cartSizeType == 0x53) {
romSize = 1258291;
romBanks = 80;
}
return std::format("size: {}, banks: {}", type::impl::size_formatter(romSize), romBanks);
};
fn ram_type(u8 ramType) {
u16 ramSize;
u16 ramBanks;
if(ramType == 2) {
ramSize = 8192;
ramBanks = 1;
}
if(ramType == 3) {
ramSize = 32768;
ramBanks = 4;
}
if(ramType == 4) {
ramSize = 131072;
ramBanks = 16;
}
if(ramType == 5) {
ramSize = 65536;
ramBanks = 8;
}
return std::format("size: {}, banks: {}", type::impl::size_formatter(ramSize), ramBanks);
};
fn rom_features(u8 type) {
str result = "( ";
if (brandedROMFeatures) match(type) {
(0xFC): result += "pocket ";
(0xFD): result += "bandai ";
}
match(type) {
(0x00): result += "no_mbc";
(0x01): result += "mbc1";
(0x02): result += "mbc1 | ram";
(0x03): result += "mbc1 | ram | battery";
(0x05): result += "mbc2";
(0x06): result += "mbc2 | battery";
(0x08): result += "no_mbc | ram";
(0x09): result += "no_mbc | ram | battery";
(0x0B): result += "mmm01";
(0x0C): result += "mmm01 | ram";
(0x0D): result += "mmm01 | ram | battery";
(0x0F): result += "mbc3 | timer | battery";
(0x10): result += "mbc3 | timer | ram | battery";
(0x11): result += "mbc3";
(0x12): result += "mbc3 | ram";
(0x13): result += "mbc3 | ram | battery";
(0x19): result += "mbc5";
(0x1A): result += "mbc5 | ram";
(0x1B): result += "mbc5 | ram | battery";
(0x1C): result += "mbc5 | rumble";
(0x1D): result += "mbc5 | rumble | ram";
(0x1E): result += "mbc5 | rumble | ram | battery";
(0x20): result += "mbc6";
(0x22): result += "mbc7 | sensor | rumble";
(0xFC): result += "camera";
(0xFD): result += "tama5";
(0xFE): result += "huc3";
(0xFF): result += "huc1 | ram | battery";
}
if (uppercaseROMFeatures) result = std::string::to_upper(result);
return result + " )";
};
fn licensee_code(u8 code) {
match(code) {
(0x00): return "None";
(0x01 | 0x31): return "Nintendo";
(0x08 | 0x38): return "Capcom";
(0x09): return "Hot-B";
(0x0A | 0xE0): return "Jaleco";
(0x0B): return "Coconuts Japan";
(0x0C | 0x6E): return "Elite Systems";
(0x13 | 0x69): return "EA (Electronic Arts)";
(0x18): return "Hudsonsoft";
(0x19): return "ITC Entertainment";
(0x1A): return "Yanoman";
(0x1D): return "Japan Clary";
(0x1F | 0x4A | 0x61): return "Virgin Interactive";
(0x24): return "PCM Complete";
(0x25): return "San-X";
(0x28): return "Kotobuki Systems";
(0x29): return "Seta";
(0x30 | 0x70): return "Infogrames";
(0x32 | 0xA2 | 0xB2 | 0xC4): return "Bandai";
(0x33): return "See new licensee code";
(0x34 | 0xA4): return "Konami";
(0x35): return "HectorSoft";
(0x39 | 0x9D): return "Banpresto";
(0x3C): return ".Entertainment i";
(0x3E): return "Gremlin";
(0x41): return "Ubisoft";
(0x42 | 0xEB): return "Atlus";
(0x44 | 0x4D): return "Malibu";
(0x46 | 0xCF): return "Angel";
(0x47): return "Spectrum Holoby";
(0x49): return "Irem";
(0x50): return "Absolute";
(0x51 | 0xB0): return "Acclaim";
(0x52): return "Activision";
(0x53): return "American Sammy";
(0x54): return "GameTek";
(0x55): return "Park Place";
(0x56 | 0xDB | 0xFF): return "LJN";
(0x57): return "Matchbox";
(0x59): return "Milton Bradley";
(0x5A): return "Mindscape";
(0x5B): return "Romstar";
(0x5C | 0xD6): return "Naxat Soft";
(0x5D): return "Tradewest";
(0x60): return "Titus";
(0x67): return "Ocean Interactive";
(0x6F): return "Electro Brain";
(0x71): return "Interplay";
(0x72 | 0xAA): return "Broderbund";
(0x73): return "Sculptered Soft";
(0x75): return "The Sales Curve";
(0x78): return "t.hq";
(0x79): return "Accolade";
(0x7A): return "Triffix Entertainment";
(0x7C): return "Microprose";
(0x7F | 0xC2): return "Kemco";
(0x80): return "Misawa Entertainment";
(0x83): return "Lozc";
(0x86 | 0xC4): return "Tokuma Shoten Intermedia";
(0x8B): return "Bullet-Proof Software";
(0x8C): return "Vic Tokai";
(0x8E): return "Ape";
(0x8F): return "I'Max";
(0x91): return "Chunksoft Co.";
(0x92): return "Video System";
(0x93): return "Tsubaraya Productions Co.";
(0x95): return "Varie Corporation";
(0x96): return "Yonezawa/SPal";
(0x97): return "Kaneko";
(0x99): return "Arc";
(0x9A): return "Nihon Bussan";
(0x9B): return "Tecmo";
(0x9C): return "Imagineer";
(0x9F): return "Nova";
(0xA1): return "Hori Electric";
(0xA6): return "Kawada";
(0xA7): return "Takara";
(0xA9): return "Technos Japan";
(0xAC): return "Toei Animation";
(0xAD): return "Toho";
(0xAF): return "Namco";
(0xB1): return "ASCII or Nexsoft";
(0xB4): return "Square Enix";
(0xB6): return "HAL Laboratory";
(0xB7): return "SNK";
(0xB9 | 0xCE): return "Pony Canyon";
(0xBA): return "Culture Brain";
(0xBB): return "Sunsoft";
(0xBD): return "Sony Imagesoft";
(0xBF): return "Sammy";
(0xC0 | 0xD0): return "Taito";
(0xC3): return "Squaresoft";
(0xC5): return "Data East";
(0xC6): return "Tonkinhouse";
(0xC8): return "Koei";
(0xC9): return "UFL";
(0xCA): return "Ultra";
(0xCB): return "Vap";
(0xCC): return "Use Corporation";
(0xCD): return "Meldac";
(0xD1): return "Sofel";
(0xD2): return "Quest";
(0xD3): return "Sigma Enterprises";
(0xD4): return "ASK Kodansha Co.";
(0xD7): return "Copya System";
(0xDA): return "Tomy";
(0xDD): return "NCS";
(0xDE): return "Human";
(0xDF): return "Altron";
(0xE1): return "Towa Chiki";
(0xE2): return "Yutaka";
(0xE3): return "Varie";
(0xE5): return "Epoch";
(0xE7): return "Athena";
(0xE8): return "Asmik";
(0xE9): return "Natsume";
(0xEA): return "King Records";
(0xEE): return "IGS";
(0xF0): return "A Wave";
(0xF3): return "Extreme Entertainment";
}
return "Unknown Licensee";
};
fn new_licensee_code(str a) {
if (std::mem::read_unsigned(0x14B, 1) != 0x33) return "See old licensee code";
match(a) {
("00"): return "None";
("01"): return "Nintendo R&D1";
("08"): return "Capcom";
("13"): return "Electronic Arts";
("18"): return "Hudson Soft";
("19"): return "b-ai";
("20"): return "KSS";
("22"): return "pow";
("24"): return "PCM Complete";
("25"): return "san-x";
("28"): return "Kemco Japan";
("29"): return "seta";
("30"): return "Viacom";
("31"): return "Nintendo";
("32"): return "Bandai";
("33"): return "Ocean/Acclaim";
("34"): return "Konami";
("35"): return "Hector";
("37"): return "Taito";
("38"): return "Hudson";
("39"): return "Banpresto";
("41"): return "Ubi Soft";
("42"): return "Atlus";
("44"): return "Malibu";
("46"): return "Angel";
("47"): return "Bullet-Proof Software";
("49"): return "irem";
("50"): return "Absolute";
("51"): return "Acclaim";
("52"): return "Activision";
("53"): return "American Sammy";
("54"): return "Konami";
("55"): return "Hi tech entertainment";
("56"): return "LJN";
("57"): return "Matchbox";
("58"): return "Mattel";
("59"): return "Milton Bradley";
("60"): return "Titus";
("61"): return "Virgin";
("64"): return "LucasArts";
("67"): return "Ocean";
("69"): return "Electronic Arts";
("70"): return "Infogrames";
("71"): return "Interplay";
("72"): return "Broderbund";
("73"): return "sculptured";
("75"): return "sci";
("78"): return "THQ";
("79"): return "Accolade";
("80"): return "misawa";
("83"): return "lozc";
("86"): return "Tokuma Shoten Intermedia";
("87"): return "Tsukuda Original";
("91"): return "Chunksoft";
("92"): return "Video system";
("93"): return "Ocean/Acclaim";
("95"): return "Varie";
("96"): return "Yonezawa/spal";
("97"): return "Kaneko";
("99"): return "Pack in soft";
("A4"): return "Konami (Yu-Gi-Oh!)";
}
return "Unknown";
};
using CGB;
fn null_cgb_flags(CGB flags) {
return "NO_CGB";
};
}
enum DestinationType : u8 {
Japanese,
NonJapanese
};
enum SGBFlagType : u8 {
NoSGBFunctionality,
SGBFunctionality = 0x03
};
struct Header {
char title[16-(std::mem::read_unsigned(addressof(this)+15, 1) >= 0x80)];
if (std::mem::read_unsigned(addressof(this)+15, 1) == 0)
CGB gbcFlags @ $-1 [[format("format::null_cgb_flags")]];
else if (std::mem::read_unsigned(addressof(this)+15, 1) >= 0x80)
CGB gbcFlags;
char newLicenseeCode[2] [[format("format::new_licensee_code")]];
SGBFlagType sgbFlag;
u8 romType [[format("format::rom_features")]];
u8 cartSize [[format("format::cart_size")]];
u8 ramType [[format("format::ram_type")]];
DestinationType destination;
u8 licenseeCode [[format("format::licensee_code")]];
u8 maskROMVersionNumber;
u8 headerChecksum [[comment("Checksum for: $134-$14C")]];
u16 globalChecksum [[comment("Checksum for entire range")]];
};
bitfield pixel_packed {
p1 : 1;
p2 : 1;
p3 : 1;
p4 : 1;
p5 : 1;
p6 : 1;
p7 : 1;
p8 : 1;
p1 : 1;
p2 : 1;
p3 : 1;
p4 : 1;
p5 : 1;
p6 : 1;
p7 : 1;
p8 : 1;
};
enum CGB : u8 {
NO_CGB = 0x00 ... 0x7F,
BACKWARDS_COMPATIBLE = 0x80,
CGB_ONLY = 0xC0
};
struct Logo {
pixel_packed rawData[0x30];
struct CartridgeStart {
u8 entryCode[4];
pixel_packed logo[0x30];
Header header;
};
struct JumpVectors {
u8 rst1[8] [[comment("rst $1")]];
u8 rst2[8] [[comment("rst $2")]];
u8 rst3[8] [[comment("rst $3")]];
u8 rst4[8] [[comment("rst $4")]];
u8 rst5[8] [[comment("rst $5")]];;
u8 rst6[8] [[comment("rst $6")]];
u8 rst7[8] [[comment("rst $7")]];
u8 rst8[8] [[comment("rst $8")]];
u8 int1[8] [[comment("vblank")]];
u8 int2[8] [[comment("lcd stat")]];
u8 int3[8] [[comment("timer")]];
u8 int4[8] [[comment("serial")]];
u8 int5[8] [[comment("joypad")]];
};
struct Header {
u32 jmpInstruction;
Logo logo;
char title[0xF];
CGB cgb;
char newLicenseeCode[2] [[format("format::new_licensee_code")]];
bool sgbFlag;
u8 type [[format("format::rom_features")]];
u8 romType [[format("format::rom_type")]];
u8 ramType [[format("format::ram_type")]];
bool japanOnly;
u8 licenseeCode [[format("format::licensee_code")]];
u8 version;
u8 checksum [[comment("Checksum for: $134-$14C")]];
u16 gloalChecksum [[comment("Checksum for entire range")]];
u8 rst1[8] [[comment("rst $1")]];
u8 rst2[8] [[comment("rst $2")]];
u8 rst3[8] [[comment("rst $3")]];
u8 rst4[8] [[comment("rst $4")]];
u8 rst5[8] [[comment("rst $5")]];
u8 rst6[8] [[comment("rst $6")]];
u8 rst7[8] [[comment("rst $7")]];
u8 rst8[8] [[comment("rst $8")]];
u8 int1[8] [[comment("vblank")]];
u8 int2[8] [[comment("lcd stat")]];
u8 int3[8] [[comment("timer")]];
u8 int4[8] [[comment("serial")]];
u8 int5[8] [[comment("joypad")]];
};
struct Cartrige {
JumpVectors jumpVectors [[comment("Instructions called on interupts or rst instructions")]];
padding[0x100 - sizeof(JumpVectors)];
Header header;
};
Cartrige cart @ 0x00;
JumpVectors jumpVectors @ 0x00 [[comment("Instructions called on interrupts or RST instructions")]];
CartridgeStart cartridgeStart @ 0x100;

66
patterns/gltf.hexpat Normal file
View File

@@ -0,0 +1,66 @@
/**
* @file <gltf.pat> ImHex Pattern for glTF binary files.
*
* Copyright (c) 2023 H. Utku Maden <utkumaden@hotmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <std/mem.pat>
#include <std/io.pat>
/**
* @brief The glTF magic section.
*/
struct gltf_magic_t {
char magic[4]; /**< The magic value. Must be "glTF" */
u32 version; /**< The version. Must be 2 for glTF 2.0. */
u32 length; /**< Length of the file in bytes, including magic section. */
};
/**
* @brief Enumeration of well defined glTF chunks.
*/
enum gltf_chunk_type_t : u32 {
JSON = 1313821514 /* "JSON" */, /**< JSON chunk. */
BIN = 5130562 /* "BIN\0" */, /**< Binary data chunk. Could be an image or model data. */
};
/**
* @brief A glTF chunk.
*/
struct gltf_chunk_t {
u32 length; /**< Length of this chunk. */
gltf_chunk_type_t type [[format("gltf_format")]]; /**< Type of the chunk. JSON or BIN expected. */
u8 string[length]; /**< The chunk data. */
};
fn gltf_format(gltf_chunk_type_t x)
{
if (x == gltf_chunk_type_t::JSON) return "JSON";
else if (x == gltf_chunk_type_t::BIN) return "BIN";
return "";
};
gltf_magic_t magic @ 0x00;
gltf_chunk_t chunks[while(!std::mem::eof())] @ $;
if (magic.magic != "glTF")
std::error("This file might not be a glTF file, expected \"glTF\", got %s", magic.magic);

536
patterns/hinf_bitmap.hexpat Normal file
View File

@@ -0,0 +1,536 @@
#include <std/mem.pat>
#include <std/io.pat>
#include <std/string.pat>
struct Header {
u32 magic;
u32 version;
u64 RootStructAltGUID;
u64 AssetChecksum;
u32 DependencyCount;
s32 DataBlockCount;
s32 TagStructCount;
s32 DataReferenceCount;
s32 TagReferenceCount;
u32 StringTableSize;
u32 ZoneSetDataSize;
u32 Unk_0x34;
u32 HeaderSize;
u32 DataSize;
u32 ResourceDataSize;
u32 ActualResoureDataSize;
u8 HeaderAlignment;
u8 TagDataAlignment;
u8 ResourceDataAlignment;
u8 ActualResourceDataAlignment;
s32 IsResource;
};
enum curve_mode : u8 {
choose_best = 0x00,
force_FAST = 0x01,
force_PRETTY = 0x02,
};
enum BitmapForcedFormat : u16 {
Use_Default = 0x00,
Best_Compressed_Color_Format = 0x01,
Best_Uncompressed_Color_Format = 0x02,
Best_Compressed_Bump_Format = 0x03,
Best_Uncompressed_Bump_Format = 0x04,
Best_Compressed_Monochrome_Format = 0x05,
Best_Uncompressed_Monochrome_Format = 0x06,
Best_Compressed_Monochrome_Format_Without_Alpha = 0x07,
unused2 = 0x08,
unused3 = 0x09,
unused4 = 0x0A,
unused5 = 0x0B,
unused6 = 0x0C,
Color_And_Alpha_Formats = 0x0D,
bc1_unorm_DXT1_Compressed_Color_Key_Alpha = 0x0E,
bc2_unorm_DXT3_Compressed_Color_4bit_Alpha = 0x0F,
bc3_unorm_DXT5_Compressed_Color_Compressed_8bit_Alpha = 0x10,
Color_24bit_Alpha_8bit = 0x11,
Monochrome_8bit_Alpha_8bit = 0x12,
Channel_Mask_3bit_Color_1bit_Alpha = 0x13,
Color_30bit_Alpha_2bit = 0x14,
Color_48bit_Alpha_16bit = 0x15,
HALF_Color_Alpha = 0x16,
FLOAT_Color_Alpha = 0x17,
r8_unorm_8bit_Intensity_RGBA = 0x18,
DEPRECATED_DXT3A_4bit_Intensity_ARGB = 0x19,
bc4_unorm_rrrr_DXT5A_Compressed_Intensity_ARGB = 0x1A,
Compressed_Monochrome_Alpha = 0x1B,
b4g4r4a4_12bit_Color_4bit_Alpha = 0x1C,
Color_Only_Formats = 0x1D,
Monochrome_8bit = 0x1E,
Compressed_Color_24bit = 0x1F,
Color_32bit_R11G11B10 = 0x20,
Monochrome_16bit = 0x21,
Red_Green_Only_16bit = 0x22,
Signed_RGBA_16bit = 0x23,
HALF_Red_Only = 0x24,
FLOAT_Red_Only = 0x25,
HALF_Red_Green_Only = 0x26,
FLOAT_Red_Green_Only = 0x27,
HALF_Monochrome = 0x28,
DEPRECATED_Compressed_Monochrome_4bit = 0x29,
Compressed_Interpolated_Monochrome = 0x2A,
bc6h_uf16_HDR_RGB_Unsigned_Half_Float = 0x2B,
bc6h_sf16_HDR_RGB_Signed_Half_Float = 0x2C,
bc7_unorm_High_Quality_bc3 = 0x2D,
Alpha_Only_Formats = 0x2E,
DEPRECATED_DXT3A_4bit_Alpha = 0x2F,
bc4_unorm_000r_DXT5A_8bit_Compressed_Alpha = 0x30,
Alpha_8bit = 0x31,
unused28 = 0x32,
unused29 = 0x33,
unused30 = 0x34,
Normal_Map_Formats = 0x35,
bc5_snorm_DXN_Compressed_Normals_Better = 0x36,
DEPRECATED_CTX1_Compressed_Normals_Smaller = 0x37,
Normals_16bit = 0x38,
Normals_32bit = 0x39,
Vector_8bit_4_Channel = 0x3A,
};
enum BitmapDownsampleFilter : u8 {
point_sampled = 0x01,
box_filter = 0x02,
blackman_filter = 0x03,
lanczos_filter = 0x04,
nuttall_filter = 0x05,
blackman_harris_filter = 0x06,
blackman_nuttall_filter = 0x07,
flat_top_filter = 0x08,
extreme_filter = 0x09,
min_filter = 0x0A
};
enum BitmapType : u8 {
_2D_Texture = 0x00,
_3D_Texture = 0x01,
CubeMap = 0x02,
Array = 0x03,
};
enum BitmapColorSpace : u8 {
Automatic = 0x00,
Rec709 = 0x01,
DCI_P3 = 0x02,
Rec2020 = 0x03,
};
enum SignedDistanceFieldMethod : u8 {
Neighbors_Multithreaded = 0x00,
Neighbors = 0x01,
Cached_Euclidean_Multithreaded = 0x02,
Cached_Euclidean = 0x03,
SSEDT = 0x04,
};
enum BitmapFormat : u16 {
a8_unorm = 0x00,
r8_unorm_rrr1 = 0x01,
r8_unorm_rrrr = 0x02,
r8g8_unorm_rrrg = 0x03,
unused1 = 0x04,
unused2 = 0x05,
b5g6r5_unorm = 0x06,
unused3 = 0x07,
b5g6r5a1_unorm = 0x08,
b4g4r4a4_unorm = 0x09,
b8g8r8x8_unorm = 0x0A,
b8g8r8a8_unorm = 0x0B,
unused4 = 0x0C,
DEPRECATED_dxt5_bias_alpha = 0x0D,
bc1_unorm_dxt1 = 0x0E,
bc2_unorm_dxt3 = 0x0F,
bc3_unorm_dxt5 = 0x10,
DEPRECATED_a4r4g4b4_font = 0x11,
unused7 = 0x12,
unused8 = 0x13,
DEPRECATED_SOFTWARE_rgbfp32 = 0x14,
unused9 = 0x15,
r8g8_snorm_v8u8 = 0x16,
DEPRECATED_g8b8 = 0x17,
r32g32b32a32_float_abgrfp32 = 0x18,
r16g16b16a16_float_abgrfp16 = 0x19,
r16_float_rrr1_16f_mono = 0x1A,
r16_float_r000_16f_red = 0x1B,
r8g8b8a8_snorm_q8w8v8u8 = 0x1C,
r10g10b10a2_unorm_a2r10g10b10 = 0x1D,
r16g16b16a16_unorm_a16b16g16r16 = 0x1E,
r16g16_snorm_v16u16 = 0x1F,
r16_unorm_rrr0_L16 = 0x20,
r16g16_unorm_r16g16 = 0x21,
r16g16b16a16_snorm_signedr16g16b16a16 = 0x22,
DEPRECATED_dxt3a = 0x23,
bc4_unorm_rrrr_dxt5a = 0x24,
bc4_snorm_rrrr = 0x25,
DEPRECATED_dxt3a_1111 = 0x26,
bc5_snorm_dxn = 0x27,
DEPRECATED_ctx1 = 0x28,
DEPRECATED_dxt3a_alpha_only = 0x29,
DEPRECATED_dxt3a_monochrome_only = 0x2A,
bc4_unorm_000r_dxt5a_alpha = 0x2B,
bc4_unorm_rrr1_dxt5a_mono = 0x2C,
bc5_unorm_rrrg_dxn_mono_alpha = 0x2D,
bc5_snorm_rrrg_dxn_mono_alpha_signed = 0x2E,
bc6h_uf16 = 0x2F,
bc6h_sf16 = 0x30,
bc7_unorm = 0x31,
d24_unorm_s8_uint_depth_24 = 0x32,
r11g11b10_float = 0x33,
r16g16_float = 0x34,
};
enum BitmapCurve : u8 {
unknown = 0x00,
xRGB = 0x01,
gamma_2 = 0x02,
linear = 0x03,
offset_log = 0x04,
sRGB = 0x05,
Rec709 = 0x06,
};
enum BitmapUsageFlag : u8 {
ignore_curve_override = 0x00,
do_not_allow_size_optimization = 0x01,
swap_axes = 0x02,
pre_filter_cubemaps = 0x03,
};
enum BitmapSlicer : u8 {
automatically_determine_slicer = 0x00,
no_slicing = 0x01,
color_plate_slicer = 0x02,
cube_map_slicer = 0x03,
color_grading_slicer = 0x04,
};
enum BitmapPacker : u8 {
no_packing = 0x00,
sprite_packing = 0x01,
sprite_packing_if_needed = 0x02,
_3d_pack = 0x03,
};
enum BitmapSmallestMip : u8 {
_1_pixel = 0x00,
_2_pixel = 0x01,
_4_pixel = 0x02,
_8_pixel = 0x03,
_16_pixel = 0x04,
_32_pixel = 0x05,
_64_pixel = 0x06,
_128_pixel = 0x07,
_256_pixel = 0x08,
_512_pixel = 0x09,
_1024_pixel = 0x0A,
};
enum Swizzle : u8 {
default = 0x00,
source_red_channel = 0x01,
source_green_channel = 0x02,
source_blue_channel = 0x03,
source_alpha_channel = 0x04,
set_to_1 = 0x05,
set_to_0 = 0x06,
set_to_0_5 = 0x07,
Random = 0x08,
one_minus_source_red_channel = 0x09,
one_minus_source_green_channel = 0x0A,
one_minus_source_blue_channel = 0x0B,
one_minus_source_alpha_channel = 0x0C,
negative_source_red_channel = 0x0D,
negative_source_green_channel = 0x0E,
negative_source_blue_channel = 0x0F,
negative_source_alpha_channel = 0x10,
};
bitfield BitmapDicerFlag {
convert_plate_color_key_to_alpha_channel : 1;
rotate_cube_map_to_match_directX_format : 1;
sprites_shrink_elements_to_smallest_non_zero_alpha_region : 1;
sprites_shrink_elements_to_smallest_non_zero_color_and_alpha_region : 1;
unsigned_signed_scale_and_bias : 1;
color_grading_sRGB_correction : 1;
color_grading_Rec709_correction : 1;
};
bitfield BitmapDownsampleFlag {
sprites : 1;
pre_multiply_alpha : 1;
post_divide_alpha : 1;
height_map : 1;
detail_map : 1;
_signed : 1;
illum_map : 1;
zbump_map : 1;
cubemap : 1;
calculate_spec_power : 1;
downsample_bumps_in_angular_space : 1;
standard_orientation_of_normals_in_angular_space_and_renormalize : 1;
generate_rgb_luminance_into_alpha_channel : 1;
};
bitfield BitmapPackerFlag {
shrink_sprite_texture_pages_tightly_to_content : 1;
};
bitfield BitmapDataResourceFlags {
Contains_3D_Texture : 1;
CPU_Gameplay_Required : 1;
Single_Mip_Texture : 1;
UI_Texture : 1;
};
bitfield BitmapGroupFlags {
bitmap_is_tiled : 1;
use_less_blurry_bump_map : 1;
dither_when_compressing : 1;
generate_random_sprites : 1;
ignore_alpha_channel : 1;
alpha_channel_stores_transparency : 1;
preserve_alpha_channel_in_mipmaps : 1;
only_use_on_demand : 1;
apply_max_resolution_after_slicing :1;
pre_filter_cubemaps : 1;
has_valid_min_and_max_values : 1;
SDF_Only_Store_Inside_values : 1;
SDF_Store_Direction : 1;
SDF_Store_Initial_Values_In_Alpha_Channel : 1;
Has_CUstom_Mipmaps : 1;
Validate_Has_Custom_Mipmaps : 1;
Is_Light_Probes : 1;
pad1 : 1;
pad2 : 1;
pad3 : 1;
pad4 : 1;
pad5 : 1;
pad6 : 1;
pad7 : 1;
pad8 : 1;
};
bitfield BitmapFlags {
power_of_two_dimension : 1;
compressed : 1;
swap_axes : 1;
mutable_at_runtime : 1;
pad1 : 1;
pad2 : 1;
pad3 : 1;
pad4 : 1;
pad5 : 1;
};
struct Data_Block {
u32 Size;
u16 Padding;
u16 Section;
u64 Offset;
};
struct Tag_Def_Structure {
s64 GUID_1;
s64 GUID_2;
u16 Type;
u16 Unk_0x12;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct Tag_Dependency {
char GroupTag[4] [[format("std::string::reverse")]];
u32 NameOffset;
u64 AssetID;
u32 GlobalID;
u32 Unk_0x14;
};
struct Data_Reference {
s32 ParentStructIndex;
s32 Unk_0x04;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct TagReference {
s64 GlobalHandle;
s32 ref_id_int;
s32 ref_id_sub;
s32 ref_id_center_int;
char TagGroupRev[4] [[format("std::string::reverse")]];
s32 local_handle;
};
struct Tag_Fixup_Reference {
s32 FieldBlock;
u32 FieldOffset;
u32 NameOffset;
s32 DependencyIndex;
TagReference tagreference @ header.HeaderSize + datablocks[FieldBlock].Offset + FieldOffset;
};
struct RealARgbColor {
float A;
float R;
float G;
float B;
};
struct RealRgbColor {
float R;
float G;
float B;
};
struct Bitmap_Resource_Handle {
s32 pixels[6]; // sum of these equals pixel count.
u32 hardware_format;
s8 tileMode;
s8 format;
BitmapDataResourceFlags bitmap_data_resource_flags;
s8 Alignment_Bits;
u8 highResMipCountAndFlags;
u8 mipCountPerArraySlice;
char generated_padff1b[6];
s64 runtime_data;
char streamingData[20];
s32 generated_padb266;
};
struct BitmapBlock {
u16 width;
u16 height;
u16 depth;
BitmapType Bitmap_Type;
u8 generated_paddca;
BitmapFormat bitmap_format;
BitmapFlags bitmap_flags;
s8 mipmap_count;
BitmapCurve bitmap_curve;
u16 generated_pad8fee;
float streaming_scale;
s16 source_width;
s16 source_height;
char bitmap_resource_handle_size[12];
s32 bitmap_resource_handle_count;
Bitmap_Resource_Handle bitmap_resource_handle[bitmap_resource_handle_count];
};
struct BitmapUsage {
s32 name;
s32 editor_group;
u32 source_gamma;
BitmapCurve bitmap_curve;
BitmapUsageFlag bitmap_usage_flag;
BitmapSlicer bitmap_slicer;
BitmapDicerFlag bitmap_dicer;
BitmapPacker bitmap_packer;
BitmapPackerFlag bitmap_packer_flags;
BitmapType bitmap_type;
s8 mipmap_limit;
BitmapSmallestMip bitmap_smallest_mip;
BitmapDownsampleFilter bitmap_downsample_filter;
s8 filter_radius_bias;
char generated_pad122e[1];
BitmapDownsampleFlag bitmap_downsample_flag;
char generated_pad5ee3[2];
RealRgbColor sprite_background_color;
Swizzle swizzle_red;
Swizzle swizzle_green;
Swizzle swizzle_blue;
Swizzle swizzle_alpha;
BitmapFormat bitmap_formats;
BitmapColorSpace source_color_space;
BitmapColorSpace target_color_space;
};
struct BitmapGroupSprite {
u32 bitmap_index;
char generated_pad2095[2];
s32 left;
s32 right;
s32 top;
s32 bottom;
s64 real_point_2D;
};
struct BitmapGroupSequence {
char name[32];
u32 first_bitmap_index;
u32 bitmap_count;
char sprites[16];
s32 sprite_count;
BitmapGroupSprite Sprites[sprite_count];
};
struct Bitm {
u32 Usage;
s32 UsageID;
s32 Package;
s32 texture_group;
BitmapGroupFlags flags;
u16 sprite_spacing;
u16 mip_sample_count;
float bump_map_height;
float blur_factor;
u32 blur;
u32 mipmap_blur;
curve_mode curvemode;
s8 max_mipmap_level;
u16 max_resolution;
BitmapForcedFormat force_bitmap_format;
SignedDistanceFieldMethod sdfgeneration;
s8 target_platform;
u16 spread_factor;
u16 generated_pad8ed2;
char usage_override[16];
s32 usage_override_count;
BitmapUsage bitmap_usage[usage_override_count];
char manual_sequence[16];
s32 manual_sequences_count;
BitmapGroupSequence manual_sequences[manual_sequences_count];
char source_data[24];
char source_path[20];
u64 source_checksum;
RealARgbColor min_color;
RealARgbColor max_color;
char sequence[16];
s32 sequences_count;
BitmapGroupSequence sequences[sequences_count];
char bitmapstart[16];
s32 bitmap_block_count;
BitmapBlock bitmap_block[bitmap_block_count];
char RawDDSData[header.ActualResoureDataSize];
};
struct InternalStruct {
s64 vtablespace;
u32 global_tag_id;
char local_tag_handle[4];
};
// TAG LAYOUT
Header header @ 0x00;
Tag_Dependency Dependencies[header.DependencyCount] @ 0x50;
Data_Block datablocks[header.DataBlockCount] @ header.DependencyCount * 0x18 + 0x50;
Tag_Def_Structure tagdefstructure[header.TagStructCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10;
Data_Reference Data_References[header.DataReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20;
Tag_Fixup_Reference tagfixupreference[header.TagReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20 + header.DataReferenceCount * 0x14;
char ZoneSet[header.ZoneSetDataSize] @ header.HeaderSize - header.ZoneSetDataSize; // zonesets kinda make no sense
InternalStruct internalstruct @ header.HeaderSize;
Bitm bitmap @ header.HeaderSize + 16;

441
patterns/hinf_luas.hexpat Normal file
View File

@@ -0,0 +1,441 @@
#pragma author Surasia
#pragma description Halo Infinite HavokScript 5.1 "luas" file
#include <std/io.pat>
#include <std/mem.pat>
#include <std/core.pat>
#include <std/string.pat>
struct String32 {
s32 length;
if (length != 0) {
char s[length - 1];
u8 endbyte;
}
};
struct String64 {
s64 length;
if (length != 0) {
char s[length - 1];
u8 endbyte;
}
};
enum lua_endian : u8 {
little_endian = 1,
big_endian = 0,
};
enum lua_numbertype : u8 {
_float = 0,
_int32 = 1,
};
struct lua_enum {
s32 value;
String32 string;
};
struct LuaEnum {
s32 count;
lua_enum entries[count];
};
enum HksOpCode : s8 {
GETFIELD,
TEST,
CALL_I,
CALL_C,
EQ,
EQ_BK,
GETGLOBAL,
MOVE,
SELF,
RETURN,
GETTABLE_S,
GETTABLE_N,
GETTABLE,
LOADBOOL,
TFORLOOP,
SETFIELD,
SETTABLE_S,
SETTABLE_S_BK,
SETTABLE_N,
SETTABLE_N_BK,
SETTABLE,
SETTABLE_BK,
TAILCALL_I,
TAILCALL_C,
TAILCALL_M,
LOADK,
LOADNIL,
SETGLOBAL,
JMP,
CALL_M,
CALL,
INTRINSIC_INDEX,
INTRINSIC_NEWINDEX,
INTRINSIC_SELF,
INTRINSIC_LITERAL,
INTRINSIC_NEWINDEX_LITERAL,
INTRINSIC_SELF_LITERAL,
TAILCALL,
GETUPVAL,
SETUPVAL,
ADD,
ADD_BK,
SUB,
SUB_BK,
MUL,
MUL_BK,
DIV,
DIV_BK,
MOD,
MOD_BK,
POW,
POW_BK,
NEWTABLE,
UNM,
NOT,
LEN,
LT,
LT_BK,
LE,
LE_BK,
CONCAT,
TESTSET,
FORPREP,
FORLOOP,
SETLIST,
CLOSE,
CLOSURE,
VARARG,
TAILCALL_I_R1,
CALL_I_R1,
SETUPVAL_R1,
TEST_R1,
NOT_R1,
GETFIELD_R1,
SETFIELD_R1,
NEWSTRUCT,
DATA,
SETSLOTN,
SETSLOTI,
SETSLOT,
SETSLOTS,
SETSLOTMT,
CHECKTYPE,
CHECKTYPES,
GETSLOT,
GETSLOTMT,
SELFSLOT,
SELFSLOTMT,
GETFIELD_MM,
CHECKTYPE_D,
GETSLOT_D,
GETGLOBAL_MEM,
};
enum HksType : u8
{
TNIL,
TBOOLEAN,
TLIGHTUSERDATA,
TNUMBER,
TSTRING,
TTABLE,
TFUNCTION,
TUSERDATA,
TTHREAD,
TIFUNCTION,
TCFUNCTION,
TUI64,
TSTRUCT
};
bitfield REG_CONST_UNUSED {
argB : 17 & 0x1ffff;
argA : 8 & 0xff;
};
bitfield REG_NUM_NUM {
argC : 9 & 0x1ff;
argB : 8 & 0xff;
argA : 8 & 0xff;
};
bitfield REG_NUM_UNUSED {
argB : 8 & 0xff;
argA : 8 & 0xff;
argC : 9 & 0x1ff;
};
bitfield UNUSED_OFFSET_UNUSED {
argA : 8 & 0xff;
argB : 9 & 0x1ff;
argC : 8 & 0xff;
};
bitfield LuaBitfield {
HksOpCode OpCode : 7;
//Arguments : 25; // read on how to process them at https://raw.githubusercontent.com/soupstream/havok-script-tools/main/HavokScriptToolsCommon/HksOpCodes.cs
match(OpCode) {
(HksOpCode::LOADK) : REG_CONST_UNUSED arguments;
(HksOpCode::SETGLOBAL) : REG_CONST_UNUSED arguments;
(HksOpCode::NEWTABLE) : REG_NUM_NUM arguments;
(HksOpCode::CLOSURE) : REG_CONST_UNUSED arguments;
(HksOpCode::RETURN) : REG_NUM_UNUSED arguments;
(HksOpCode::NEWSTRUCT) : REG_NUM_NUM arguments;
(HksOpCode::DATA) : UNUSED_OFFSET_UNUSED arguments;
(_): arguments : 25;
}
};
struct LuaInstruction {
LuaBitfield OpCode;
};
struct LuaConstant {
HksType type;
if (type == HksType::TNIL) {
}
else if (type == HksType::TSTRING) {
String64 string;
}
else if (type == HksType::TNUMBER) {
float number;
}
else if (type == HksType::TBOOLEAN) {
bool boolean;
}
else if (type == HksType::TLIGHTUSERDATA) {
s64 userdata;
}
else {
s64 data;
}
};
struct HksLocal {
String64 string;
u32 start;
u32 end;
};
struct LuaFunction {
s32 upvaluecount;
s32 paramcount;
s8 isVarArg;
s32 slotCount;
s32 unk;
s32 instruction_count;
if ($ % 4 != 0) {
$ += (4 - ($ % 4));
}
LuaInstruction instructions[instruction_count];
s32 constantCount;
LuaConstant constants[constantCount];;
s32 HasDebugInfo;
if (HasDebugInfo != 0) {
u32 LineCount;
u32 LocalsCount;
u32 UpValueCount;
u32 LineBegin;
u32 LineEnd;
String64 path;
String64 functionName;
s32 Lines[LineCount];
HksLocal Locals[LocalsCount];
String64 UpValues[UpValueCount];
}
s32 function_count;
LuaFunction children[function_count];
};
struct LuaStructHeader {
String64 name;
s32 structID;
s32 pad;
s24 unk1;
HksType type;
s32 unk2;
};
struct LuaStructMember {
s32 pad;
LuaStructHeader header;
s32 index;
};
struct LuaStruct {
try {
u32 unk;
LuaStructHeader ExtendedStructHeader;
s64 ExtendedStructMemberCount;
LuaStructMember ExtendedStructMembers[ExtendedStructMemberCount];
u32 unk2;
} catch {
std::print("WARNING: this file does not support structs.");
}
try {
LuaStructHeader StructHeader;
s64 StructMemberCount;
LuaStructMember StructMembers[StructMemberCount];
} catch {
std::print("WARNING: this file does not support multiple structs.");
}
};
struct LuaHeader {
char luaheader[4];
u8 version;
u8 format;
lua_endian Endianness;
if (Endianness == lua_endian::big_endian) {
std::core::set_endian(std::mem::Endian::Big);
} else {
std::core::set_endian(std::mem::Endian::Little);
}
u8 intSize;
u8 size_tSize;
u8 instruction_size;
u8 number_size;
lua_numbertype numberType;
u8 flags;
u8 unknown;
LuaEnum enums;
LuaFunction LuaFunctions;
LuaStruct LuaStructures;
};
struct Header {
u32 magic;
u32 version;
u64 RootStructAltGUID;
u64 AssetChecksum;
u32 DependencyCount;
s32 DataBlockCount;
s32 TagStructCount;
s32 DataReferenceCount;
s32 TagReferenceCount;
u32 StringTableSize;
u32 ZoneSetDataSize;
u32 Unk_0x34;
u32 HeaderSize;
u32 DataSize;
u32 ResourceDataSize;
u32 ActualResoureDataSize;
u8 HeaderAlignment;
u8 TagDataAlignment;
u8 ResourceDataAlignment;
u8 ActualResourceDataAlignment;
s32 IsResource;
};
struct _s_tagblock {
char tagblock[16];
s32 count;
};
struct _s_resource {
char resource[12];
s32 count;
};
struct _s_data {
char data[24];
};
struct Data_Block {
u32 Size;
u16 Padding;
u16 Section;
u64 Offset;
};
struct Tag_Def_Structure {
s64 GUID_1;
s64 GUID_2;
u16 Type;
u16 Unk_0x12;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct Tag_Dependency {
char GroupTag[4] [[format("std::string::reverse")]];
u32 NameOffset;
u64 AssetID;
u32 GlobalID;
u32 Unk_0x14;
};
struct Data_Reference {
s32 ParentStructIndex;
s32 Unk_0x04;
s32 TargetIndex;
s32 FieldBlock;
u32 FieldOffset;
};
struct _s_tagref {
s64 GlobalHandle;
s32 ref_id_int;
s32 ref_id_sub;
s32 ref_id_center_int;
char TagGroupRev[4] [[format("std::string::reverse")]];
s32 local_handle;
};
struct Tag_Fixup_Reference {
s32 FieldBlock;
u32 FieldOffset;
u32 NameOffset;
s32 DependencyIndex;
_s_tagref tagreference @ header.HeaderSize + datablocks[FieldBlock].Offset + FieldOffset;
};
struct InternalStruct {
s64 vtablespace;
u32 global_tag_id;
char local_tag_handle[4];
};
struct LuaReferencedTagContainer {
_s_tagref tagReference;
};
struct LuaScriptTagDefinition {
u32 luaFileName;
_s_data luaFileData;
char luaFileNameString[256];
_s_tagblock referencedTags_count;
LuaHeader lua_header;
try {
char pad[14];
LuaReferencedTagContainer referencedTags[referencedTags_count.count];
} catch {
std::print("This file does not support referenced Tags.");
}
};
// TAG LAYOUT
Header header @ 0x00;
Tag_Dependency Dependencies[header.DependencyCount] @ 0x50;
Data_Block datablocks[header.DataBlockCount] @ header.DependencyCount * 0x18 + 0x50;
Tag_Def_Structure tagdefstructure[header.TagStructCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10;
Data_Reference Data_References[header.DataReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20;
Tag_Fixup_Reference tagfixupreference[header.TagReferenceCount] @ header.DependencyCount * 0x18 + 0x50 + header.DataBlockCount * 0x10 + header.TagStructCount * 0x20 + header.DataReferenceCount * 0x14;
char ZoneSet[header.ZoneSetDataSize] @ header.HeaderSize - header.ZoneSetDataSize;
InternalStruct internalstruct @ header.HeaderSize;
LuaScriptTagDefinition lua_script @ header.HeaderSize + 16;

View File

@@ -1,4 +1,4 @@
#pragma description [Intel hexadecimal object file format definition]("https://en.wikipedia.org/wiki/Intel_HEX")
#pragma description Intel hexadecimal object file format definition
/* If you have no delimiters between data records then remove
* the null_bytes field in the data_packet struct.

View File

@@ -132,7 +132,7 @@ namespace ip {
if (flags.data_offset > 5)
u8 options[(flags.data_offset - 5) * sizeof(u32)];
u8 data[parent.parent.header.total_length - 40];
u8 data[parent.parent.header.total_length - parent.parent.header.ihl * 4 - flags.data_offset * 4];
};
}

View File

@@ -1,16 +1,15 @@
#pragma author gmestanley
#pragma description IPS (International Patching System) files
#pragma endian big
#include <std/mem.pat>
#include <std/string.pat>
#pragma endian big
u8 eofOffset = 3;
struct Hunk {
u24 offset;
u16 length;
if (length == 0) {
if (!length) {
u16 runCount;
u8 payload;
}
@@ -21,12 +20,9 @@ struct Hunk {
struct IPS {
char signature[5];
if (std::mem::read_string(std::mem::size()-3, 3) != "EOF") {
eofOffset += 3;
}
Hunk hunks[while($ < std::mem::size()-eofOffset)];
Hunk hunks[while($ < std::mem::size() - (3 + 3 * (std::mem::read_string(std::mem::size()-3, 3) != "EOF")))];
char eof[3];
u24 truncatedSize[eofOffset>3];
u24 truncatedSize[3+(std::mem::read_string(std::mem::size()-3, 3) != "EOF")>3];
};
IPS ips @ 0x00;
IPS ips @ 0x00;

View File

@@ -1,7 +1,9 @@
#pragma author WerWolv
#pragma description JPEG Image Format
#include <std/io.pat>
#include <std/mem.pat>
#include <type/magic.pat>
#pragma endian big
#pragma MIME image/jpeg
@@ -48,6 +50,12 @@ enum DensityUnit : u8 {
PixelsPerCm = 0x02
};
enum ColorTransform : u8 {
Unknown = 0x00,
YCbCr = 0x01,
YCCK = 0x02
};
struct Pixel {
u8 r, g, b;
} [[sealed, transform("transform_pixel")]];
@@ -58,7 +66,7 @@ fn transform_pixel(Pixel pixel) {
struct APP0 {
char magic[5];
type::Magic<"JFIF\x00"> magic;
u8 versionMajor, versionMinor;
DensityUnit densityUnit;
u16 densityX, densityY;
@@ -66,18 +74,33 @@ struct APP0 {
Pixel thumbnail[thumbnailX * thumbnailY] [[sealed]];
};
struct APP14 {
type::Magic<"Adobe"> magic;
u16 version;
u16 flags0;
u16 flags1;
ColorTransform transform;
};
enum ComponentId : u8 {
Y = 1,
CB = 2,
CR = 3,
I = 4,
Q = 5
Q = 5,
B = 66,
G = 71,
R = 82
};
struct SOF0Component {
ComponentId componentId;
u8 samplingFactors;
u8 quantizationTableId;
} [[format_read("sof0_component_read")]];
fn sof0_component_read(SOF0Component c) {
return std::format("({}, {}, {})", c.componentId, c.samplingFactors, c.quantizationTableId);
};
struct SOF0 {
@@ -99,11 +122,11 @@ struct SOS {
u8 endSpectral;
u8 apprBitPos;
u8 image_data[while(!std::mem::eof())] [[sealed]];
u8 image_data[std::mem::size() - $ - 2] [[sealed]];
};
struct Segment {
u8 magic;
type::Magic<"\xff"> magic;
Marker marker;
if (marker == Marker::SOI || marker == Marker::EOI) {
@@ -112,6 +135,10 @@ struct Segment {
u16 length;
if (marker == Marker::APP0) {
APP0 data;
} else if (marker == Marker::APP14) {
APP14 data;
} else if (marker == Marker::COM) {
char data[length - sizeof(length)];
} else if (marker == Marker::SOF0) {
SOF0 data;
} else if (marker == Marker::SOS) {
@@ -120,6 +147,10 @@ struct Segment {
u8 data[length - sizeof(length)] [[sealed]];
}
}
} [[format_read("segment_read")]];
fn segment_read(Segment s) {
return std::format("{}", s.marker);
};
Segment segments[while(!std::mem::eof())] @ 0x00 [[hex::visualize("image", this)]];

View File

@@ -16,7 +16,17 @@ fn to_string(auto var) {
fn format_string(auto string) {
return string.value;
};
};
struct FixedPoint16 {
u8 integer;
u8 fraction;
};
struct FixedPoint32 {
u16 integer;
u16 fraction;
};
struct string {
char value[std::mem::find_sequence_in_range(0, $, std::mem::size(), 0x00) - $];
@@ -79,8 +89,8 @@ struct MovieHeaderBox : FullBox {
u32 timescale;
u32 duration;
}
u32 rate [[comment("Fixed point number 16.16")]];
u16 volume [[comment("Fixed point number 8.8")]];
FixedPoint32 rate;
FixedPoint16 volume;
u8 reserved[10] [[sealed]];
u32 matrix[9];
u32 preview_time;
@@ -147,7 +157,7 @@ struct DataInformationBox : BaseBox {
struct HandlerBox : FullBox {
u32 component_type;
u32 handler_type;
char handler_type[4];
u32 reserved[3];
char name[endOffset - $];
};
@@ -157,6 +167,132 @@ struct VideoMediaHeaderBox : FullBox {
u16 opcolor[3];
};
struct Avc1Box : BaseBox {
u48 reserved;
u16 data_reference_index;
u16 version;
u16 revision_level;
u32 max_packet_size;
if (this.version == 0 || this.version == 1) {
u32 temporal_quality;
u32 spatial_quality;
u16 width;
u16 height;
FixedPoint32 horizontal_resolution;
FixedPoint32 vertical_resolution;
u32 data_size;
u16 frame_count;
char compressor_name[32];
u16 depth;
s16 color_table_id;
}
u8 unk[while($ != endOffset)];
};
struct Mp4aBox : BaseBox {
u48 reserved;
u16 data_reference_index;
u16 version;
u16 revision_level;
u32 max_packet_size;
if (this.version == 0) {
u16 num_audio_channels;
u16 sample_size;
u16 compression_id;
u16 packet_size;
FixedPoint32 sample_rate;
}
u8 unk[while($ != endOffset)];
};
struct SubSampleDescriptionBox {
u32 type = std::mem::read_unsigned($ + 4, 4, std::mem::Endian::Big);
match (str(type)) {
("mp4a"): Mp4aBox box [[inline]];
("avc1"): Avc1Box box [[inline]];
(_): UnknownBox box [[inline]];
}
} [[name(std::format("SubSampleDescriptionBox({})", box.type))]];
struct SampleDescriptionBox : FullBox {
u32 entry_count;
SubSampleDescriptionBox box[while($ < endOffset)] [[inline]];
};
struct SampleTimeToSampleEntry {
u32 sample_count;
u32 sample_delta;
};
struct SampleTimeToSampleBox: FullBox {
u32 entry_count;
SampleTimeToSampleEntry entry_list[this.entry_count];
u8 unk[while($ != endOffset)];
};
struct SampleToChunkEntry {
u32 first_chunk;
u32 samples_per_chunk;
u32 sample_description_index;
};
struct SampleToChunkBox: FullBox {
u32 entry_count;
SampleToChunkEntry entry_list[this.entry_count];
u8 unk[while($ != endOffset)];
};
struct ChunkOffsetBox: FullBox {
u32 entry_count;
u32 chunk_offset[this.entry_count];
u8 unk[while($ != endOffset)];
};
struct SyncSampleBox: FullBox {
u32 entry_count;
u32 sample_number[this.entry_count];
u8 unk[while($ != endOffset)];
};
struct CompositionOffsetEntryV0 {
u32 sample_count;
u32 sample_offset;
};
struct CompositionOffsetEntryV1 {
u32 sample_count;
s32 sample_offset;
};
struct CompositionOffsetBox: FullBox {
u32 entry_count;
if(this.version == 0) {
CompositionOffsetEntryV0 entry_list[this.entry_count];
}
else if (this.version == 1) {
CompositionOffsetEntryV1 entry_list[this.entry_count];
}
};
struct SubSampleBoxTable {
u32 type = std::mem::read_unsigned($ + 4, 4, std::mem::Endian::Big);
match (str(type)) {
("stsd"): SampleDescriptionBox box [[inline]];
("stts"): SampleTimeToSampleBox box [[inline]];
("stsc"): SampleToChunkBox box [[inline]];
("stco"): ChunkOffsetBox box [[inline]];
("stss"): SyncSampleBox box [[inline]];
("ctts"): CompositionOffsetBox box [[inline]];
(_): UnknownBox box [[inline]];
}
} [[name(std::format("SubSampleBoxTable({})", box.type))]];
struct SampleBoxTable : BaseBox {
SubSampleBoxTable box[while($ < endOffset)] [[inline]];
};
struct SubMediaInformationBox {
u32 type = std::mem::read_unsigned($ + 4, 4, std::mem::Endian::Big);
@@ -164,8 +300,8 @@ struct SubMediaInformationBox {
("vmhd"): VideoMediaHeaderBox box [[inline]];
("hdlr"): HandlerBox box [[inline]];
("dinf"): DataInformationBox box [[inline]];
("stbl"): SampleBoxTable box [[inline]];
(_): UnknownBox box [[inline]];
// TODO: Add stbl
}
} [[name(std::format("MediaInformationBox({})", box.type))]];

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,9 @@
#pragma description SE Linux modules
#pragma author Ange Albertini
#include <std/sys.pat>
#pragma pattern_limit 13107200
#pragma array_limit 13107200
#pragma endian little
u32 version;
@@ -17,6 +19,13 @@ enum magics: u32 {
module = 0xf97cff8d,
};
bitfield CONFIG {
DENY_UNKNOWN: 1;
MLS: 1;
REJECT_UNKNOWN: 1;
ALLOW_UNKNOWN: 1;
padding: 4 + 3 * 8;
};
enum policy_types: u32 {
kernel = 0,
@@ -667,7 +676,7 @@ struct Header {
version = __policyvers;
boundary_feature = (type_g == policy_types::kernel && version >= 24) || (type_g != policy_types::kernel && version >= 9);
std::assert((magic == magics::kernel && 15 <= version && version <= 33) || (magic != magics::kernel && 4 <= version && version <= 21), "Non matching type_g != and type");
u32 config;
CONFIG config;
u32 symbols_count_;
symbols_count = symbols_count_;
std::assert(0 <= symbols_count && symbols_count <= 9, "Invalid 'symbols_count' value.");

201
patterns/shp.hexpat Normal file
View File

@@ -0,0 +1,201 @@
#pragma author Calcoph
#pragma description ESRI shapefile
// Spec:
// https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf
enum ShapeType: u32 {
Null = 0,
Point = 1,
PolyLine = 3,
Polygon = 5,
MultiPoint = 8,
PointZ = 11,
PolyLineZ = 13,
PolygonZ = 15,
MultiPointZ = 18,
PointM = 21,
PolyLineM = 23,
PolygonM = 25,
MultiPointM = 28,
MultiPatch = 32,
};
struct NullShape {
};
struct Point {
double x;
double y;
};
struct MultiPoint {
double box[4];
u32 num_points;
Point points[num_point];
};
struct PolyLine {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
};
struct Polygon {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
};
struct PointM {
double x;
double y;
double m;
};
struct MultiPointM {
double box[4];
u32 num_points;
Point points[num_point];
double m_range[2];
double m_array[num_points];
};
struct PolyLineM {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolygonM {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double m_range[2];
double m_array[num_points];
};
struct PointZ {
double x;
double y;
double z;
double m;
};
struct MultiPointZ {
double box[4];
u32 num_points;
Point points[num_point];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolyLineZ {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolygonZ {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
enum PartType: u32 {
TriangleStrip = 0,
TriangleFan = 1,
OuterRing = 2,
InnerRing = 3,
FirstRing = 4,
Ring = 5,
};
struct MultiPatch {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
PartType part_types[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct Header {
be u32 magic; // 9994
padding[20]; // unused
be u32 file_length; // in 16-bit words (including header)
u32 version; // 1000
ShapeType shape_type;
// Bounding box
double bb_xmin;
double bb_ymin;
double bb_xmax;
double bb_ymax;
double bb_zmin;
double bb_zmax;
double bb_mmin;
double bb_mmax;
};
struct RecordHeader {
be u32 record_number; // starting at 1
be u32 content_length; // in 16-bit words
};
struct Record {
RecordHeader;
ShapeType shape_type;
match (shape_type) {
(ShapeType::Null): NullShape;
(ShapeType::Point): Point;
(ShapeType::PolyLine): PolyLine;
(ShapeType::Polygon): Polygon;
(ShapeType::MultiPoint): MultiPoint;
(ShapeType::PointZ): PointZ;
(ShapeType::PolyLineZ): PolyLineZ;
(ShapeType::PolygonZ): PolygonZ;
(ShapeType::MultiPointZ): MultiPointZ;
(ShapeType::PointM): PointM;
(ShapeType::PolyLineM): PolyLineM;
(ShapeType::PolygonM): PolygonM;
(ShapeType::MultiPointM): MultiPointM;
(ShapeType::MultiPatch): MultiPatch;
}
};
struct ShapeFile {
Header header;
Record records[while ($ < (header.file_length * 2))];
};
ShapeFile file @ 0x00;

52
patterns/shx.hexpat Normal file
View File

@@ -0,0 +1,52 @@
#pragma author Calcoph
#pragma description ESRI shapefile indices
// Spec:
// https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf
enum ShapeType: u32 {
Null = 0,
Point = 1,
PolyLine = 3,
Polygon = 5,
MultiPoint = 8,
PointZ = 11,
PolyLineZ = 13,
PolygonZ = 15,
MultiPointZ = 18,
PointM = 21,
PolyLineM = 23,
PolygonM = 25,
MultiPointM = 28,
MultiPatch = 32,
};
struct Header {
be u32 magic; // 9994
padding[20]; // unused
be u32 file_length; // in 16-bit words (including header)
u32 version; // 1000
ShapeType shape_type;
// Bounding box
double bb_xmin;
double bb_ymin;
double bb_xmax;
double bb_ymax;
double bb_zmin;
double bb_zmax;
double bb_mmin;
double bb_mmax;
};
struct Record {
u32 offset;
u32 content_length;
};
struct IndexFile {
Header header;
Record records[while($ < header.file_length * 2)];
};
IndexFile file @ 0x00;

View File

@@ -1,7 +1,5 @@
#pragma description UEFI structs for parsing efivars
#pragma MIME data
#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
#define WIN_CERT_TYPE_EFI_PKCS115 0x0EF0
#define WIN_CERT_TYPE_EFI_GUID 0x0EF1

View File

@@ -0,0 +1,74 @@
// subsections in this pattern refer to subsections in the
// UEFI Specification Release 2.10 from Aug 29 2022
#pragma author iTrooz
#pragma description UEFI Boot Entry (Load option)
#include <std/io.pat>
#include <type/guid.pat>
// subsection 10.3.5.1
struct HARD_DRIVE {
u32 partitionNumber;
u64 partitionStart;
u64 partitionSize;
type::GUID partitionSig;
u8 format;
u8 sigType;
};
// subsection 10.3.5.4
struct FILE_PATH {
char16 path[];
};
// subsection 10.3.1
enum MEDIA_DEVICE_PATH_SUBTYPE : u8 {
HARD_DRIVE = 0x01,
FILE_PATH = 0x04,
};
enum DEVICE_PATH_TYPE : u8 {
MEDIA_DEVICE_PATH = 0x04,
};
// subsection 10.2
// EFI_DEVICE_PATH_PROTOCOL
struct DEVICE_PATH {
u8 type;
u8 subtype;
// length of this DEVICE_PATH structure
u16 length;
// the size of the data is the size of the structure minus the fields we know.
// not always used
u16 dataSize = length-1-1-2;
match (type, subtype) {
(DEVICE_PATH_TYPE::MEDIA_DEVICE_PATH, MEDIA_DEVICE_PATH_SUBTYPE::HARD_DRIVE): HARD_DRIVE data;
(DEVICE_PATH_TYPE::MEDIA_DEVICE_PATH, MEDIA_DEVICE_PATH_SUBTYPE::FILE_PATH): FILE_PATH data;
(_, _): u8 data[dataSize];
}
};
// subsections 3.1.3
// EFI_LOAD_OPTION
struct LOAD_OPTION {
u32 attributes;
// length of the filePathList data
u16 filePathLength;
char16 description[];
u64 startOffset = $;
DEVICE_PATH filePathList[while($ - startOffset < filePathLength)];
u8 optionalData;
};
// on Linux, variables are found in /sys/firmware/efi/efivars,
// and will be prefixed by their attributes
struct EFI_VAR {
u32 attributes;
LOAD_OPTION loadOption;
};
EFI_VAR data @0x0;

View File

@@ -1,5 +1,5 @@
#pragma author WerWolv
#pragma description [USB Flashing Format](https://github.com/microsoft/uf2)
#pragma description USB Flashing Format
#include <std/sys.pat>
#include <std/mem.pat>
@@ -98,4 +98,4 @@ struct UF2_Block {
std::assert(magicEnd == 0x0AB16F30, "Invalid magicEnd value!");
};
UF2_Block block[while(!std::mem::eof())] @ 0;
UF2_Block block[while(!std::mem::eof())] @ 0;

215
patterns/vbmeta.hexpat Normal file
View File

@@ -0,0 +1,215 @@
#pragma description Android VBMeta image
#pragma endian big
#include <std/core.pat>
using uint8_t = u8;
using uint32_t = u32;
using uint64_t = u64;
#define AVB_MAGIC_LEN 4
#define AVB_RELEASE_STRING_SIZE 48
enum AvbAlgorithmType : uint32_t {
AVB_ALGORITHM_TYPE_NONE,
AVB_ALGORITHM_TYPE_SHA256_RSA2048,
AVB_ALGORITHM_TYPE_SHA256_RSA4096,
AVB_ALGORITHM_TYPE_SHA256_RSA8192,
AVB_ALGORITHM_TYPE_SHA512_RSA2048,
AVB_ALGORITHM_TYPE_SHA512_RSA4096,
AVB_ALGORITHM_TYPE_SHA512_RSA8192,
_AVB_ALGORITHM_NUM_TYPES
};
struct AvbVBMetaImageHeader {
/* 0: Four bytes equal to "AVB0" (AVB_MAGIC). */
char magic[AVB_MAGIC_LEN];
/* 4: The major version of libavb required for this header. */
uint32_t required_libavb_version_major;
/* 8: The minor version of libavb required for this header. */
uint32_t required_libavb_version_minor;
/* 12: The size of the signature block. */
uint64_t authentication_data_block_size;
/* 20: The size of the auxiliary data block. */
uint64_t auxiliary_data_block_size;
/* 28: The verification algorithm used, see |AvbAlgorithmType| enum. */
AvbAlgorithmType algorithm_type;
/* 32: Offset into the "Authentication data" block of hash data. */
uint64_t hash_offset;
/* 40: Length of the hash data. */
uint64_t hash_size;
/* 48: Offset into the "Authentication data" block of signature data. */
uint64_t signature_offset;
/* 56: Length of the signature data. */
uint64_t signature_size;
/* 64: Offset into the "Auxiliary data" block of public key data. */
uint64_t public_key_offset;
/* 72: Length of the public key data. */
uint64_t public_key_size;
/* 80: Offset into the "Auxiliary data" block of public key metadata. */
uint64_t public_key_metadata_offset;
/* 88: Length of the public key metadata. Must be set to zero if there
* is no public key metadata.
*/
uint64_t public_key_metadata_size;
/* 96: Offset into the "Auxiliary data" block of descriptor data. */
uint64_t descriptors_offset;
/* 104: Length of descriptor data. */
uint64_t descriptors_size;
/* 112: The rollback index which can be used to prevent rollback to
* older versions.
*/
uint64_t rollback_index;
/* 120: Flags from the AvbVBMetaImageFlags enumeration. This must be
* set to zero if the vbmeta image is not a top-level image.
*/
uint32_t flags;
/* 124: The location of the rollback index defined in this header.
* Only valid for the main vbmeta. For chained partitions, the rollback
* index location must be specified in the AvbChainPartitionDescriptor
* and this value must be set to 0.
*/
uint32_t rollback_index_location;
/* 128: The release string from avbtool, e.g. "avbtool 1.0.0" or
* "avbtool 1.0.0 xyz_board Git-234abde89". Is guaranteed to be NUL
* terminated. Applications must not make assumptions about how this
* string is formatted.
*/
char release_string[AVB_RELEASE_STRING_SIZE];
/* 176: Padding to ensure struct is size AVB_VBMETA_IMAGE_HEADER_SIZE
* bytes. This must be set to zeroes.
*/
padding[80];
};
enum AvbDescriptorTag : uint64_t {
AVB_DESCRIPTOR_TAG_PROPERTY,
AVB_DESCRIPTOR_TAG_HASHTREE,
AVB_DESCRIPTOR_TAG_HASH,
AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE,
AVB_DESCRIPTOR_TAG_CHAIN_PARTITION,
};
struct AvbPropertyDescriptor {
uint64_t key_num_bytes;
uint64_t value_num_bytes;
char key[key_num_bytes];
padding[1];
char value[value_num_bytes];
padding[1];
} [[inline]];
bitfield AvbHashtreeDescriptorFlags {
AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB : 1;
AVB_HASHTREE_DESCRIPTOR_FLAGS_CHECK_AT_MOST_ONCE : 1;
} [[bitfield_order(std::core::BitfieldOrder::LeastToMostSignificant, 32)]];
struct AvbHashtreeDescriptor {
uint32_t dm_verity_version;
uint64_t image_size;
uint64_t tree_offset;
uint64_t tree_size;
uint32_t data_block_size;
uint32_t hash_block_size;
uint32_t fec_num_roots;
uint64_t fec_offset;
uint64_t fec_size;
char hash_algorithm[32];
uint32_t partition_name_len;
uint32_t salt_len;
uint32_t root_digest_len;
AvbHashtreeDescriptorFlags flags;
padding[60]; // reserved
char partition_name[partition_name_len];
u8 salt[salt_len];
u8 root_digest[root_digest_len];
} [[inline]];
struct AvbHashDescriptor {
uint64_t image_size;
char hash_algorithm[32];
uint32_t partition_name_len;
uint32_t salt_len;
uint32_t digest_len;
uint32_t flags;
padding[60]; // reserved
char partition_name[partition_name_len];
u8 salt[salt_len];
u8 digest[digest_len];
} [[inline]];
struct AvbKernelCmdlineDescriptor {
uint32_t flags;
uint32_t kernel_cmdline_length;
char kernel_cmdline[kernel_cmdline_length];
} [[inline]];
struct AvbChainPartitionDescriptor {
uint32_t rollback_index_location;
uint32_t partition_name_len;
uint32_t public_key_len;
padding[64]; // reserved
char partition_name[partition_name_len];
u8 public_key[public_key_len];
} [[inline]];
struct AvbDescriptor<auto end> {
AvbDescriptorTag tag;
uint64_t num_bytes_following;
u8 data[num_bytes_following] [[hidden]];
match (tag) {
(AvbDescriptorTag::AVB_DESCRIPTOR_TAG_PROPERTY) : AvbPropertyDescriptor descriptor @ addressof(data);
(AvbDescriptorTag::AVB_DESCRIPTOR_TAG_HASHTREE) : AvbHashtreeDescriptor descriptor @ addressof(data);
(AvbDescriptorTag::AVB_DESCRIPTOR_TAG_HASH) : AvbHashDescriptor descriptor @ addressof(data);
(AvbDescriptorTag::AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE) : AvbKernelCmdlineDescriptor descriptor @ addressof(data);
(AvbDescriptorTag::AVB_DESCRIPTOR_TAG_CHAIN_PARTITION): AvbChainPartitionDescriptor descriptor @ addressof(data);
}
if ($ >= end)
break;
};
struct AuthenticationData<auto authentication_data_block_size,
auto hash_offset, auto hash_size,
auto signature_offset, auto signature_size>
{
u8 authentication_data_block[authentication_data_block_size] [[hidden]];
u8 hash[hash_size] @ addressof(authentication_data_block) + hash_offset;
u8 signature[signature_size] @ addressof(authentication_data_block) + signature_offset;
};
struct AuxiliaryData<auto auxiliary_data_block_size,
auto public_key_offset, auto public_key_size,
auto public_key_metadata_offset, auto public_key_metadata_size,
auto descriptors_offset, auto descriptors_size>
{
u8 auxiliary_data_block[auxiliary_data_block_size] [[hidden]];
u8 public_key[public_key_size] @ addressof(auxiliary_data_block) + public_key_offset;
u8 public_key_metadata[public_key_metadata_size] @ addressof(auxiliary_data_block) + public_key_metadata_offset;
if (descriptors_size > 0) {
u8 descriptors_block[descriptors_size] @ addressof(auxiliary_data_block) + descriptors_offset [[hidden]];
AvbDescriptor<addressof(descriptors_block) + descriptors_size> descriptors[200] @ addressof(descriptors_block);
}
};
struct AvbVBMetaImage
{
AvbVBMetaImageHeader header;
AuthenticationData<header.authentication_data_block_size,
header.hash_offset, header.hash_size,
header.signature_offset, header.signature_size>
authentication_data;
AuxiliaryData<header.auxiliary_data_block_size,
header.public_key_offset, header.public_key_size,
header.public_key_metadata_offset, header.public_key_metadata_size,
header.descriptors_offset, header.descriptors_size>
auxiliary_data;
};
AvbVBMetaImage image @ 0;

View File

@@ -0,0 +1,24 @@
#pragma author DmitriLeon2000
#pragma description Oska Software DeskMates WAS/WA3 (WAVE/MP3 Set) file
#pragma endian little
#include <type/size.pat>
struct Sound {
char name[];
u32 length;
u8 data[length];
};
struct Header {
type::Size<u32> size;
u32 count;
u32 pointers[count * 2];
};
struct WAS {
Header header;
Sound sounds[header.count];
};
WAS was @ 0x00;

View File

@@ -0,0 +1,374 @@
#pragma endian little
#pragma description Xilinx Zynq UltraScale+ Boot Image
#pragma magic [ 58 4E 4C 58 ] @ 0x24
// Spec: Xilinx UG1283 https://docs.xilinx.com/r/en-US/ug1283-bootgen-user-guide/Zynq-UltraScale-MPSoC-Boot-and-Configuration
#include <type/magic.pat>
#include <std/io.pat>
#include <std/mem.pat>
#include <std/array.pat>
#include <std/ptr.pat>
fn format_u32_string(auto arr) {
str result = "";
for (u32 i = 0, i < sizeof(arr) / 4, i = i + 1) {
result += char((arr[i] >> 24) & 0xff);
result += char((arr[i] >> 16) & 0xff);
result += char((arr[i] >> 8) & 0xff);
result += char((arr[i] ) & 0xff);
}
return result;
};
fn pointer_word(auto offset) {
return u128(offset) * 3;
};
// Based on std::ptr::NullablePtr
// Pointer addresses 4-byte words
struct NullableWordPtr<PointeeTy, PointerTy> {
PointerTy pointerValue [[no_unique_address, hidden]];
if (pointerValue == 0x0) {
padding[sizeof(PointerTy)];
} else {
PointeeTy *data : PointerTy [[pointer_base("pointer_word"),inline]];
}
};
namespace zynqmp {
enum SpkUserEfuseSelect : u8 {
Spk = 0x01,
User = 0x10,
};
enum PpkKeySelect : u8 {
Ppk0 = 0,
Ppk1 = 1,
};
enum AcFormat : u8 {
Pkcs1v1_5 = 0,
};
enum AcVersion : u8 {
Current = 0,
};
enum PpkKeyType : u8 {
Hash = 0,
};
enum PpkKeySource : u8 {
Efuse = 0,
};
enum SpkEnable : u8 {
Disabled = 0,
Enabled = 1,
};
enum PublicStrength : u8 {
b2048 = 0,
b4096 = 1,
};
enum HashAlgo : u8 {
Sha3_384 = 1,
};
enum PublicAlgo : u8 {
Rsa = 1,
};
bitfield AuthenticationCertificationHeader {
PublicAlgo public_algorithm : 2;
HashAlgo hash_algorithm : 2;
PublicStrength public_strength : 4;
SpkEnable spk_enable : 1;
PpkKeySource ppk_key_source : 2;
PpkKeyType ppk_key_type : 1;
AcVersion authentication_certificate_version : 2;
AcFormat authentication_certificate_format : 2;
PpkKeySelect ppk_key_select : 2;
SpkUserEfuseSelect spk_user_efuse_select : 2;
padding : 12;
};
struct AuthenticationCertificates {
AuthenticationCertificationHeader authentication_header;
u32 spk_id;
u32 udf[14];
u32 ppk_mod[128];
u32 ppk_mod_ext[128];
u32 ppk_exponent;
padding[60];
u32 spk_mod[128];
u32 spk_mod_ext[128];
u32 spk_exponent;
padding[60];
u32 spk_signature[128];
u32 boot_header_signature[128];
u32 partition_signature[128];
};
enum VectorLocation : u8 {
Low = 0,
High = 1,
};
enum EarlyHandoff : u8 {
Disabled = 0,
Enabled = 1,
};
enum Endianness : u8 {
Little = 0,
Big = 1,
};
enum PartitionOwner : u8 {
Fsbl = 0,
UBoot = 1,
};
enum RsaCertPresent : u8 {
No = 0,
Yes = 1,
};
enum ChecksumType : u8 {
None = 0,
Md5 = 1,
Sha2 = 2,
Sha3 = 3,
};
enum DestCpu : u8 {
None = 0,
A53_0 = 1,
A53_1 = 2,
A53_2 = 3,
A53_3 = 4,
R5_0 = 5,
R5_1 = 6,
R5Lockstep = 7,
Pmu = 8,
};
enum EncryptionPresent : u8 {
No = 0,
Yes = 1,
};
enum DestDevice : u8 {
None = 0,
Ps = 1,
Pl = 2,
Pmu = 3,
Xip = 4,
};
enum A5xExecState : u8 {
Aarch64 = 0,
Aarch32 = 1,
};
enum ExceptionLevel : u8 {
El0 = 0,
El1 = 1,
El2 = 2,
El3 = 3,
};
enum TrustZone : u8 {
NonSecure = 0,
Secure = 1,
};
bitfield PartitionAttributeBits {
TrustZone trustzone : 1;
ExceptionLevel exception_level : 2;
A5xExecState a5x_exec_state : 1;
DestDevice destination_device : 3;
EncryptionPresent encryption_present : 1;
DestCpu destination_cpu : 4;
ChecksumType checksum_type : 3;
RsaCertPresent rsa_authentication_certificate_present : 1;
PartitionOwner partition_owner : 2;
Endianness endianness : 1;
EarlyHandoff early_handoff : 1;
padding : 3;
VectorLocation vector_location : 1;
padding : 8;
};
struct PartitionHeader {
u32 encrypted_partition_data_word_length;
u32 unencrypted_data_word_length;
u32 total_partition_word_length;
NullableWordPtr<PartitionHeader, u32> next_partition_header_offset;
u64 destination_execution_address;
u64 destination_load_address;
NullableWordPtr<std::Array<u8,parent.encrypted_partition_data_word_length*4>, u32> actual_partition_word_offset;
PartitionAttributeBits attributes;
u32 section_count;
u32 checksum_word_offset;
u32 image_header_word_offset;
NullableWordPtr<AuthenticationCertificates, u32> ac_offset;
u32 partition_number;
u32 header_checksum;
};
struct ImageHeader {
NullableWordPtr<ImageHeader, u32> image_header;
NullableWordPtr<PartitionHeader, u32> corresponding_partition_header;
padding[4];
u32 partition_count;
u32 image_name[] [[format("format_u32_string")]];
};
enum BootDevice : u32 {
Same = 0,
Qspi32 = 1,
Qspi24 = 2,
Nand = 3,
Sd0 = 4,
Sd1 = 5,
Sdls = 6,
Mmc = 7,
Usb = 8,
Ethernet = 9,
PciE = 10,
Sata = 11,
};
struct ImageHeaderTable {
u32 version;
u32 count_of_image_header;
u32 first_partition_header_offset;
NullableWordPtr<ImageHeader, u32> image_header_table_offset;
NullableWordPtr<AuthenticationCertificates, u32> header_authentication_certificate;
BootDevice secondary_boot_device;
padding[36];
u32 checksum;
};
struct RegisterInitializationTablePair {
u32 address;
u32 value;
};
struct RegisterInitializationTable {
RegisterInitializationTablePair register_initialization_pairs[256];
};
enum CpuSelect : u8 {
R5Single,
A53Single32Bit,
A53Single64Bit,
R5Dual,
};
enum HashingSelect : u8 {
NoIntegrityCheck = 0x0 ... 0x1,
Sha3IntegrityCheck = 0x3,
};
enum PufHdLocation : u8 {
Efuse = 0x0 ... 0x2,
BootHeader = 0x3,
};
enum BootHeaderRsa : u8 {
AuthDecidedByEfuse = 0x0 ... 0x2,
AuthEnabled = 0x3,
};
bitfield BootHeaderAttributeBits {
padding : 6;
PufHdLocation puf_hd : 2;
HashingSelect hashing_select : 2;
CpuSelect cpu_select : 2;
padding : 2;
BootHeaderRsa bhdr_rsa : 2;
padding : 16;
};
struct PufHelperData {
u32 data[384];
u32 chash;
u16 aux;
padding[2];
};
enum ArmVectorTable : u32 {
Cortex32Bit = 0xEAFFFFFE,
Cortex64Bit = 0x14000000,
};
enum KeySource : u32 {
Unencrypted = 0x00000000,
BlackKeyInEfuse = 0xA5C3C5A5,
ObfuscatedKeyInEfuse = 0xA5C3C5A7,
RedKeyInBbram = 0x3A5C3C5A,
EfuseRedKeyInEfuse = 0xA5C3C5A3,
ObfuscatedKeyInBootHeader = 0xA35C7CA5,
UserKeyInBootHeader = 0xA3A5C3C5,
BlackKeyInBootHeader = 0xA35C7C53,
};
struct BootHeader {
ArmVectorTable arm_vector_table[8];
u32 width_detection_word;
type::Magic<"XNLX"> header_signature;
KeySource key_source;
u32 fsbl_execution_address;
u32 source_offset;
u32 pmu_image_length;
u32 total_pmu_fw_length;
u32 fsbl_image_length;
u32 total_fsbl_length;
BootHeaderAttributeBits fsbl_image_attributes;
u32 boot_header_checksum;
u32 obfuscated_black_key_storage[8];
u32 shutter_value;
u32 user_defined_fields[10];
std::ptr::NullablePtr<ImageHeaderTable, u32> image_header_table_offset;
u32 partition_header_table_offset;
u32 secure_header_iv[3];
u32 obfuscated_black_key_iv[3];
if (fsbl_image_attributes.puf_hd == 0x3) {
PufHelperData puf_helper_data @ 0x8b8;
}
if (source_offset > 0) {
if (pmu_image_length > 0) {
u8 pmu_firmware[total_pmu_fw_length] @ source_offset;
u8 fsbl[total_fsbl_length] @ source_offset + total_pmu_fw_length;
} else {
u8 fsbl[total_fsbl_length] @ source_offset;
}
}
};
struct DeviceBootImage {
BootHeader boot_header @ 0x0;
RegisterInitializationTable register_initialization_table @ 0xB8;
};
}
zynqmp::DeviceBootImage boot_image @ 0x00;

View File

@@ -1,12 +1,13 @@
#pragma description End of Central Directory Header, Central Directory File Headers
#pragma description End of Central Directory Header, Central Directory File Headers, Local File Header
#pragma MIME application/zip
#include <std/mem.pat>
#include <std/math.pat>
#include <type/time.pat>
struct EndOfCentralDirectory {
u32 headerSignature [[color("00000000")]];
u32 headerSignature [[comment("EoCD magic"), name("EoCD PK\\5\\6")]];
u16 diskNum [[comment("Number of this disk "), name("Disk Number")]];
u16 diskStart [[comment("Disk where central directory starts "), name("Central Directory Disk Number")]];
u16 CDRCount [[comment("Number of central directory records on this disk"), name("Central Directory Entries")]];
@@ -17,6 +18,78 @@ struct EndOfCentralDirectory {
char coment[commentLength] [[name("Comment")]];
};
namespace extra {
bitfield Flags {
bool modification_time_set : 1;
bool access_time_set : 1;
bool creation_time_set : 1;
reserved: 5; //reserved for additional timestamps; not set
};
struct X5455_ExtendedTimestamp {
Flags Flags;
if (Flags.modification_time_set){
u32 ModTime;
}
if (Flags.access_time_set){
u32 AcTime;
}
if (Flags.creation_time_set){
u32 CrTime;
}
};
struct X000A_NTFS {
u32 reserved;
u16 tag;
u16 TSize;
//Timestamps are in FILETIME format. Converted to Unix for easier handling.
type::FILETIME ModTime;
type::FILETIME AcTime;
type::FILETIME CrTime;
};
struct X7875_NewUnix {
u16 tag;
u16 TSize;
u8 version;
u8 UIDSize;
u8 UID[UIDSize];
u8 GIDSize;
u8 GID[GIDSize];
};
struct X5855_InfoZipUnix {
u32 AcTime;
u32 ModTime;
if (parent.TSize > 8){
u16 UID;
}
if (parent.TSize > 10){
u16 GID;
}
};
struct ExtraField {
u16 tag;
u16 TSize;
if (tag == 0x5455){
extra::X5455_ExtendedTimestamp x5455_ExtendedTimestamp;
}else if (tag == 0x000a){
extra::X000A_NTFS x000A_NTFS;
}else if (tag == 0x7875){
extra::X7875_NewUnix x7875_NewUnix;
}else if (tag == 0x5855){
extra::X5855_InfoZipUnix x5855_InfoZipUnix;
}else{
std::print("Unsupported tag 0x{:02X}", tag);
padding[TSize];
}
};
}
fn find_eocd() {
// If there is no zip comment, which is the common case,
// the end-of-central-directory record will be 22 bytes long
@@ -25,38 +98,109 @@ fn find_eocd() {
return std::mem::size()-22;
} else {
// If it's not there, then there's probably a zip comment;
// search the last 64KB of the file for the signature.
// This is not entirely reliable, since the signature could
// randomly appear in compressed data before the actual EOCD,
// but it should be good enough...
u128 last64k = std::math::max(0, std::mem::size()-65536-22);
return std::mem::find_sequence_in_range(0, last64k, std::mem::size(), 0x50,0x4B,0x05,0x06);
// search the last 64KB of the file for the signature.
u128 offset_search_from = std::math::max(0, std::mem::size()-65536-22);
u128 prev_address;
while(1){
u128 current_address = std::mem::find_sequence_in_range(0, offset_search_from, std::mem::size(), 0x50,0x4B,0x05,0x06);
//Reached EOF and did not find valid eocd.
if (current_address == 340282366920938463463374607431768211455){
std::error("Could not find EOCD.");
}
//Potential eocd found. Create a eocd struct
EndOfCentralDirectory EOCD @ current_address;
//If central directory file header is valid, then we know the eocd offset is valid.
if (std::mem::read_unsigned(EOCD.CDOffset, 4, std::mem::Endian::Little) == 0x2014B50){
return current_address;
}
offset_search_from = current_address + 1;
prev_address = current_address;
}
}
};
EndOfCentralDirectory fileInfo @ find_eocd() [[name("End of Central Directory Record")]];
enum CompressionMethod : u16 {
None = 0, // The file is stored (no compression)
Shrunk = 1, // The file is Shrunk
Factor1 = 2, // The file is Reduced with compression factor 1
Factor2 = 3, // The file is Reduced with compression factor 2
Factor3 = 4, // The file is Reduced with compression factor 3
Factor4 = 5, // The file is Reduced with compression factor 4
Implode = 6, // The file is Imploded
// ? = 7, // Reserved for Tokenizing compression algorithm
Deflate = 8, // The file is Deflated
Deflate64 = 9, // Enhanced Deflating using Deflate64(tm)
PKWARE = 10, // PKWARE Data Compression Library Imploding (old IBM TERSE)
// ? =11, // Reserved by PKWARE
BZIP2 = 12, // File is compressed using BZIP2 algorithm
// ? = 13, // Reserved by PKWARE
LZMA = 14, // LZMA
// ? = 15, // Reserved by PKWARE
CMPSC = 16, // IBM z/OS CMPSC Compression
// ? = 17, // Reserved by PKWARE
IBMTERSE = 18, // File is compressed using IBM TERSE (new)
LZ77 = 19, // IBM LZ77 z Architecture
_ZSTD = 20, // deprecated (use method 93 for zstd)
ZSTD = 93, // Zstandard (zstd) Compression
MP3 = 94, // MP3 Compression
XZ = 95, // XZ Compression
JPEG = 96, // JPEG variant
WavPack = 97, // WavPack compressed data
PPMd = 98, // PPMd version I, Rev 1
AE_x = 99, // AE-x encryption marker (see APPENDIX E)
};
struct LocalFileHeader {
u32 headerSignature [[name("LCF PK\\3\\4")]];
u16 version [[ comment("The minimum supported ZIP specification version needed to extract the file") ]];
u16 purposeBitflag [[ comment("General purpose bit flag") ]];
CompressionMethod compressionMethod [[ comment("Compression method") ]];
u16 lastModifyTime [[ comment("File last modification time") ]];
u16 lastModifyDate [[ comment("File last modification date") ]];
u32 crc32 [[ comment("CRC-32") ]];
u32 compressedSize [[ comment("Compressed size") ]];
u32 uncompressedSize [[ comment("Uncompressed size") ]];
u16 fileNameLength [[ comment("File name length (n)") ]];
u16 extraFieldLength [[ comment("Extra field length (m)") ]];
char fileName[fileNameLength] [[ comment("File Name") ]];
u64 extraEnd = $ + extraFieldLength;
extra::ExtraField extraFields[while ($ < extraEnd)] [[comment("Extra Fields")]];
u8 data[compressedSize] [[name("File Data")]];
};
union File {
u32 fileOffset [[comment("Offset of local file header, relative to the start of the first disk on which the file occurs.")]];
LocalFileHeader *fileHeader : u32;
};
struct CentralDirectoryFileHeader {
u32 headerSignature [[color("00000000")]];
u32 headerSignature [[name("CDFH PK\\1\\2")]];
u16 versionMade [[comment("Version file made by")]];
u16 versionExtract [[comment("Minimum version needed to extract")]];
u16 generalFlag [[comment("General purpose bit flag"), color("00000000")]];
u16 compressionMethod;
u16 generalFlag [[comment("General purpose bit flag")]];
CompressionMethod compressionMethod;
u16 fileLastModifyTime [[comment("File last modification time")]];
u16 fileLastModifyDate [[comment("File last modification date")]];
u32 crc32 [[comment("CRC-32 of uncompressed data"), color("00000000")]];
u32 crc32 [[comment("CRC-32 of uncompressed data")]];
u32 compressedSize;
u32 uncompressedSize;
u16 fileNameLength [[color("00000000")]];
u16 extraFieldLength [[color("00000000")]];
u16 fileCommentLength [[color("00000000")]];
u16 fileNameLength;
u16 extraFieldLength;
u16 fileCommentLength;
u16 diskNumber [[comment("Disk number where file starts")]];
u16 internalFileAttributes;
u32 externalFileAttributes;
u32 fileOffset [[comment("Offset of local file header, relative to the start of the first disk on which the file occurs.")]];
File file;
char fileName[fileNameLength];
u8 extraField[extraFieldLength];
u64 extraEnd = $ + extraFieldLength;
extra::ExtraField extraFields[while ($ < extraEnd)] [[comment("Extra Fields")]];
char comment[fileCommentLength];
};
CentralDirectoryFileHeader centralDirHeaders[fileInfo.CDRCount] @ (fileInfo.CDOffset) [[name("Files")]];
CentralDirectoryFileHeader centralDirHeaders[fileInfo.CDRCount] @ (fileInfo.CDOffset) [[name("Files")]];

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.