mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-31 13:25:58 -05:00
Compare commits
35 Commits
ImHex-v1.2
...
ImHex-v1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72acac1082 | ||
|
|
a9d6c882ac | ||
|
|
7ecfcd446d | ||
|
|
b094757b03 | ||
|
|
1d0b11372f | ||
|
|
f01ddec350 | ||
|
|
64136ba16c | ||
|
|
1e45938887 | ||
|
|
f32b162647 | ||
|
|
d2685aabf5 | ||
|
|
8027cda032 | ||
|
|
a178509b3c | ||
|
|
56411ae067 | ||
|
|
7ee489237d | ||
|
|
4d97e79097 | ||
|
|
9fec10000a | ||
|
|
b0d8b81861 | ||
|
|
c7fbb661ae | ||
|
|
7e19b4cb10 | ||
|
|
ff2726ce8a | ||
|
|
ed47fa65f1 | ||
|
|
f0963603bf | ||
|
|
15548b92e2 | ||
|
|
87efc6cf54 | ||
|
|
5e48adcb9d | ||
|
|
f548643933 | ||
|
|
575e4d5381 | ||
|
|
6b0fad199e | ||
|
|
ece86f1124 | ||
|
|
ce2b4d60ca | ||
|
|
7c88439681 | ||
|
|
8d3c94be8f | ||
|
|
0b15299980 | ||
|
|
eda13b2518 | ||
|
|
aa6c90fa5b |
8
.gitattributes
vendored
8
.gitattributes
vendored
@@ -1,10 +1,2 @@
|
||||
*.pat linguist-language=Rust
|
||||
*.hexpat linguist-language=Rust
|
||||
constants/* text eol=lf
|
||||
encodings/* text eol=lf
|
||||
includes/* text eol=lf
|
||||
magic/* text eol=lf
|
||||
patterns/* text eol=lf
|
||||
structs/* text eol=lf
|
||||
tips/* text eol=lf
|
||||
yara/* text eol=lf
|
||||
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -53,7 +53,7 @@ jobs:
|
||||
- name: 🧪 Perform Unit Tests
|
||||
run: |
|
||||
cd tests/build
|
||||
ctest
|
||||
ctest --output-on-failure
|
||||
- name: 📎 Validate JSON Files
|
||||
run: |
|
||||
cd constants
|
||||
|
||||
10
README.md
10
README.md
@@ -32,6 +32,14 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
|
||||
| VDF | | `patterns/vdf.hexpat` | Binary Value Data Format (.vdf) files |
|
||||
| IP | | `patterns/ip.hexpat` | Ethernet II Frames (IP Packets) |
|
||||
| UF2 | | `patterns/uf2.hexpat` | [USB Flashing Format](https://github.com/microsoft/uf2) |
|
||||
| File System | | `patterns/fs.hexpat` | Drive File System |
|
||||
| Bencode | `application/x-bittorrent` | `patterns/bencode.hexpat` | Bencode encoding, used by Torrent files |
|
||||
| Protobuf | | `patterns/protobuf.hexpat` | Google Protobuf encoding |
|
||||
| OGG | `audio/ogg` | `patterns/ogg.hexpat` | OGG Audio format |
|
||||
| STL | `model/stl` | `patterns/stl.hexpat` | STL 3D Model format |
|
||||
| VHDX | | `patterns/vhdx.hexpat` | Microsoft Hyper-V Virtual Hard Disk format |
|
||||
| NTAG | | `patterns/ntag.hexpat` | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC |
|
||||
| Shell Link | `application/x-ms-shortcut` | `patterns/lnk.hexpat` | Windows Shell Link file format |
|
||||
|
||||
### Scripts
|
||||
|
||||
@@ -88,6 +96,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
|
||||
| Eastern Europe Windows | `encodings/eastern_europe_windows.tbl` | Eastern Europe Windows encoding |
|
||||
| EBCDIC | `encodings/ebcdic.tbl` | Extended Binary Coded Decimal Interchange Code, developed by IBM for their Main Frames |
|
||||
| EUC-JP | `encodings/euc_jp.tbl` | EUC-JP encoding with NEC special and IBM extended characters |
|
||||
| EUC-KR | `encodings/euc_kr.tbl` | EUC-KR encoding |
|
||||
| Greek ISO | `encodings/greek_iso.tbl` | Greek ISO encoding |
|
||||
| Greek Windows | `encodings/greek_windows.tbl` | Greek Windows encoding |
|
||||
| Hebrew ISO | `encodings/hebrew_iso.tbl` | Hebrew ISO encoding |
|
||||
@@ -98,6 +107,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
|
||||
| JIS X 0211 | `encodings/jis_x_0211.tbl` | JIS X 0211 encoding in UTF-8 |
|
||||
| JIS 0213 | `encodings/jis_x_0213.tbl` | JIS X 0213 encoding in UTF-8 |
|
||||
| Macintosh | `encodings/macintosh.tbl` | Macintosh character encoding used by the Kermit protocol |
|
||||
| Pokémon (English, Generation 1) | `encodings/pokegen1_en.tbl` | Character encoding used by the English generation 1 Pokémon games |
|
||||
| Shift-JIS UTF-8 | `encodings/shiftjis.tbl` | Shift-JIS encoding in UTF-8 |
|
||||
| Thai | `encodings/thai.tbl` | Thai character encoding |
|
||||
| Turkish ISO | `encodings/turkish_iso.tbl` | Turkish ISO encoding |
|
||||
|
||||
256
encodings/cyrillic_cp866.tbl
Normal file
256
encodings/cyrillic_cp866.tbl
Normal file
@@ -0,0 +1,256 @@
|
||||
00=NUL
|
||||
01=☺
|
||||
02=☻
|
||||
03=♥
|
||||
04=♦
|
||||
05=♣
|
||||
06=♠
|
||||
07=•
|
||||
08=◘
|
||||
09=○
|
||||
0A=◙
|
||||
0B=♂
|
||||
0C=♀
|
||||
0D=♪
|
||||
0E=♫
|
||||
0F=☼
|
||||
10=►
|
||||
11=◄
|
||||
12=↕
|
||||
13=‼
|
||||
14=¶
|
||||
15=§
|
||||
16=▬
|
||||
17=↨
|
||||
18=↑
|
||||
19=↓
|
||||
1A=→
|
||||
1B=←
|
||||
1C=∟
|
||||
1D=↔
|
||||
1E=▲
|
||||
1F=▼
|
||||
20=
|
||||
21=!
|
||||
22="
|
||||
23=#
|
||||
24=$
|
||||
25=%
|
||||
26=&
|
||||
27='
|
||||
28=(
|
||||
29=)
|
||||
2A=*
|
||||
2B=+
|
||||
2C=,
|
||||
2D=-
|
||||
2E=.
|
||||
2F=/
|
||||
30=0
|
||||
31=1
|
||||
32=2
|
||||
33=3
|
||||
34=4
|
||||
35=5
|
||||
36=6
|
||||
37=7
|
||||
38=8
|
||||
39=9
|
||||
3A=:
|
||||
3B=;
|
||||
3C=<
|
||||
3D==
|
||||
3E=>
|
||||
3F=?
|
||||
40=@
|
||||
41=A
|
||||
42=B
|
||||
43=C
|
||||
44=D
|
||||
45=E
|
||||
46=F
|
||||
47=G
|
||||
48=H
|
||||
49=I
|
||||
4A=J
|
||||
4B=K
|
||||
4C=L
|
||||
4D=M
|
||||
4E=N
|
||||
4F=O
|
||||
50=P
|
||||
51=Q
|
||||
52=R
|
||||
53=S
|
||||
54=T
|
||||
55=U
|
||||
56=V
|
||||
57=W
|
||||
58=X
|
||||
59=Y
|
||||
5A=Z
|
||||
5B=[
|
||||
5C=\
|
||||
5D=]
|
||||
5E=^
|
||||
5F=_
|
||||
60=`
|
||||
61=a
|
||||
62=b
|
||||
63=c
|
||||
64=d
|
||||
65=e
|
||||
66=f
|
||||
67=g
|
||||
68=h
|
||||
69=i
|
||||
6A=j
|
||||
6B=k
|
||||
6C=l
|
||||
6D=m
|
||||
6E=n
|
||||
6F=o
|
||||
70=p
|
||||
71=q
|
||||
72=r
|
||||
73=s
|
||||
74=t
|
||||
75=u
|
||||
76=v
|
||||
77=w
|
||||
78=x
|
||||
79=y
|
||||
7A=z
|
||||
7B={
|
||||
7C=|
|
||||
7D=}
|
||||
7E=~
|
||||
7F=⌂
|
||||
80=А
|
||||
81=Б
|
||||
82=В
|
||||
83=Г
|
||||
84=Д
|
||||
85=Е
|
||||
86=Ж
|
||||
87=З
|
||||
88=И
|
||||
89=Й
|
||||
8A=К
|
||||
8B=Л
|
||||
8C=М
|
||||
8D=Н
|
||||
8E=О
|
||||
8F=П
|
||||
90=Р
|
||||
91=С
|
||||
92=Т
|
||||
93=У
|
||||
94=Ф
|
||||
95=Х
|
||||
96=Ц
|
||||
97=Ч
|
||||
98=Ш
|
||||
99=Щ
|
||||
9A=Ъ
|
||||
9B=Ы
|
||||
9C=Ь
|
||||
9D=Э
|
||||
9E=Ю
|
||||
9F=Я
|
||||
A0=а
|
||||
A1=б
|
||||
A2=в
|
||||
A3=г
|
||||
A4=д
|
||||
A5=е
|
||||
A6=ж
|
||||
A7=з
|
||||
A8=и
|
||||
A9=й
|
||||
AA=к
|
||||
AB=л
|
||||
AC=м
|
||||
AD=н
|
||||
AE=о
|
||||
AF=п
|
||||
B0=░
|
||||
B1=▒
|
||||
B2=▓
|
||||
B3=│
|
||||
B4=┤
|
||||
B5=╡
|
||||
B6=╢
|
||||
B7=╖
|
||||
B8=╕
|
||||
B9=╣
|
||||
BA=║
|
||||
BB=╗
|
||||
BC=╝
|
||||
BD=╜
|
||||
BE=╛
|
||||
BF=┐
|
||||
C0=└
|
||||
C1=┴
|
||||
C2=┬
|
||||
C3=├
|
||||
C4=─
|
||||
C5=┼
|
||||
C6=╞
|
||||
C7=╟
|
||||
C8=╚
|
||||
C9=╔
|
||||
CA=╩
|
||||
CB=╦
|
||||
CC=╠
|
||||
CD=═
|
||||
CE=╬
|
||||
CF=╧
|
||||
D0=╨
|
||||
D1=╤
|
||||
D2=╥
|
||||
D3=╙
|
||||
D4=╘
|
||||
D5=╒
|
||||
D6=╓
|
||||
D7=╫
|
||||
D8=╪
|
||||
D9=┘
|
||||
DA=┌
|
||||
DB=█
|
||||
DC=▄
|
||||
DD=▌
|
||||
DE=▐
|
||||
DF=▀
|
||||
E0=р
|
||||
E1=с
|
||||
E2=т
|
||||
E3=у
|
||||
E4=ф
|
||||
E5=х
|
||||
E6=ц
|
||||
E7=ч
|
||||
E8=ш
|
||||
E9=щ
|
||||
EA=ъ
|
||||
EB=ы
|
||||
EC=ь
|
||||
ED=э
|
||||
EE=ю
|
||||
EF=я
|
||||
F0=Ё
|
||||
F1=ё
|
||||
F2=Є
|
||||
F3=є
|
||||
F4=Ї
|
||||
F5=ї
|
||||
F6=Ў
|
||||
F7=ў
|
||||
F8=°
|
||||
F9=∙
|
||||
FA=·
|
||||
FB=√
|
||||
FC=№
|
||||
FD=¤
|
||||
FE=■
|
||||
FF=
|
||||
16674
encodings/euc_kr.tbl
Normal file
16674
encodings/euc_kr.tbl
Normal file
File diff suppressed because it is too large
Load Diff
255
encodings/pokegen1_en.tbl
Normal file
255
encodings/pokegen1_en.tbl
Normal file
@@ -0,0 +1,255 @@
|
||||
00=NUL
|
||||
01
|
||||
02
|
||||
03
|
||||
04
|
||||
05
|
||||
06
|
||||
07
|
||||
08
|
||||
09
|
||||
0A
|
||||
0B
|
||||
0C
|
||||
0D
|
||||
0E
|
||||
0F
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
1A
|
||||
1B
|
||||
1C
|
||||
1D
|
||||
1E
|
||||
1F
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
2A
|
||||
2B
|
||||
2C
|
||||
2D
|
||||
2E
|
||||
2F
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
3A
|
||||
3B
|
||||
3C
|
||||
3D
|
||||
3E
|
||||
3F
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49=page
|
||||
4A=PkMn
|
||||
4B=_cont
|
||||
4C=autocont
|
||||
4D
|
||||
4E=next line
|
||||
4F=bottom line
|
||||
50=end
|
||||
51=paragraph
|
||||
52=player name
|
||||
53=rival name
|
||||
54=Poké
|
||||
55=cont
|
||||
56=......
|
||||
57=done
|
||||
58=prompt
|
||||
59=target
|
||||
5A=user
|
||||
5B=PC
|
||||
5C=TM
|
||||
5D=TRAINER
|
||||
5E=ROCKET
|
||||
5F=dex
|
||||
60=A
|
||||
61=B
|
||||
62=C
|
||||
63=D
|
||||
64=E
|
||||
65=F
|
||||
66=G
|
||||
67=H
|
||||
68=I
|
||||
69=V
|
||||
6A=S
|
||||
6B=L
|
||||
6C=M
|
||||
6D=:
|
||||
6E=ぃ
|
||||
6F=ぅ
|
||||
70=‘
|
||||
71=’
|
||||
72=“
|
||||
73=”
|
||||
74=・
|
||||
75=⋯
|
||||
76=ぁ
|
||||
77=ぇ
|
||||
78=ぉ
|
||||
79
|
||||
7A
|
||||
7B
|
||||
7C
|
||||
7D
|
||||
7E
|
||||
7F
|
||||
80=A
|
||||
81=B
|
||||
82=C
|
||||
83=D
|
||||
84=E
|
||||
85=F
|
||||
86=G
|
||||
87=H
|
||||
88=I
|
||||
89=J
|
||||
8A=K
|
||||
8B=L
|
||||
8C=M
|
||||
8D=N
|
||||
8E=O
|
||||
8F=P
|
||||
90=Q
|
||||
91=R
|
||||
92=S
|
||||
93=T
|
||||
94=U
|
||||
95=V
|
||||
96=W
|
||||
97=X
|
||||
98=Y
|
||||
99=Z
|
||||
9A=(
|
||||
9B=)
|
||||
9C=
|
||||
9D=;
|
||||
9E=[
|
||||
9F=]
|
||||
A0=a
|
||||
A1=b
|
||||
A2=c
|
||||
A3=d
|
||||
A4=e
|
||||
A5=f
|
||||
A6=g
|
||||
A7=h
|
||||
A8=i
|
||||
A9=j
|
||||
AA=k
|
||||
AB=l
|
||||
AC=m
|
||||
AD=n
|
||||
AE=o
|
||||
AF=p
|
||||
B0=q
|
||||
B1=r
|
||||
B2=s
|
||||
B3=t
|
||||
B4=u
|
||||
B5=v
|
||||
B6=w
|
||||
B7=x
|
||||
B8=y
|
||||
B9=z
|
||||
BA=é
|
||||
BB='d
|
||||
BC='l
|
||||
BD='s
|
||||
BE='t
|
||||
BF='v
|
||||
C0
|
||||
C1
|
||||
C2
|
||||
C3
|
||||
C4
|
||||
C5
|
||||
C6
|
||||
C7
|
||||
C8
|
||||
C9
|
||||
CA
|
||||
CB
|
||||
CC
|
||||
CD
|
||||
CE
|
||||
CF
|
||||
D0
|
||||
D1
|
||||
D2
|
||||
D3
|
||||
D4
|
||||
D5
|
||||
D6
|
||||
D7
|
||||
D8
|
||||
D9
|
||||
DA
|
||||
DB
|
||||
DC
|
||||
DD
|
||||
DE
|
||||
DF
|
||||
E0='
|
||||
E1=Pk
|
||||
E2=Mn
|
||||
E3=-
|
||||
E4='r
|
||||
E5='m
|
||||
E6=?
|
||||
E7=!
|
||||
E8=.
|
||||
E9=ァ
|
||||
EA=ゥ
|
||||
EB=ェ
|
||||
EC=▷
|
||||
ED=▶
|
||||
EE=▼
|
||||
EF=♂
|
||||
F0=$
|
||||
F1=×
|
||||
F2=.
|
||||
F3=/
|
||||
F4=,
|
||||
F5=♀
|
||||
F6=0
|
||||
F7=1
|
||||
F8=2
|
||||
F9=3
|
||||
FA=4
|
||||
FB=5
|
||||
FC=6
|
||||
FD=7
|
||||
FE=8
|
||||
FF=9
|
||||
@@ -1,6 +1,10 @@
|
||||
00=
|
||||
090D=(R)
|
||||
0A=(BR)
|
||||
08=\b
|
||||
09=\t
|
||||
0A=\n
|
||||
0B=\v
|
||||
0C=\f
|
||||
0D=\r
|
||||
20=
|
||||
21=!
|
||||
22="
|
||||
|
||||
61
includes/std/core.pat
Normal file
61
includes/std/core.pat
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::core {
|
||||
|
||||
enum Endian : u8 {
|
||||
Native = 0,
|
||||
Big = 1,
|
||||
Little = 2
|
||||
};
|
||||
|
||||
enum BitfieldOrder : u8 {
|
||||
LeftToRight = 0,
|
||||
RightToLeft = 1
|
||||
};
|
||||
|
||||
|
||||
fn has_attribute(auto pattern, str attribute) {
|
||||
return builtin::std::core::has_attribute(pattern, attribute);
|
||||
};
|
||||
|
||||
|
||||
fn get_attribute_value(auto pattern, str attribute) {
|
||||
return builtin::std::core::get_attribute_value(pattern, attribute);
|
||||
};
|
||||
|
||||
|
||||
fn set_endian(Endian endian) {
|
||||
builtin::std::core::set_endian(endian);
|
||||
};
|
||||
|
||||
fn get_endian() {
|
||||
return builtin::std::core::get_endian();
|
||||
};
|
||||
|
||||
|
||||
fn set_bitfield_order(BitfieldOrder order) {
|
||||
builtin::std::core::set_bitfield_order(order);
|
||||
};
|
||||
|
||||
fn get_bitfield_order() {
|
||||
return builtin::std::core::get_bitfield_order();
|
||||
};
|
||||
|
||||
|
||||
fn array_index() {
|
||||
return builtin::std::core::array_index();
|
||||
};
|
||||
|
||||
fn member_count(auto pattern) {
|
||||
return builtin::std::core::member_count(pattern);
|
||||
};
|
||||
|
||||
fn has_member(auto pattern, str name) {
|
||||
return builtin::std::core::has_member(pattern, name);
|
||||
};
|
||||
|
||||
fn formatted_value(auto pattern) {
|
||||
return builtin::std::core::formatted_value(pattern);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -39,15 +39,12 @@ namespace std::string {
|
||||
};
|
||||
|
||||
fn contains(str a, str b) {
|
||||
s32 a_len, b_len;
|
||||
a_len = std::string::length(a);
|
||||
b_len = std::string::length(b);
|
||||
s32 a_len = std::string::length(a);
|
||||
s32 b_len = std::string::length(b);
|
||||
|
||||
s32 i;
|
||||
while (i < a_len - b_len) {
|
||||
for (s32 i = 0, i <= (a_len - b_len), i += 1) {
|
||||
if (std::string::substr(a, i, b_len) == b)
|
||||
return true;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
33
includes/type/leb128.pat
Normal file
33
includes/type/leb128.pat
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct LEB128 {
|
||||
u8 array[while($ == addressof(this) || std::mem::read_unsigned($-1, 1) & 0x80 != 0)] [[hidden]];
|
||||
} [[sealed, format("type::impl::format_leb128"), transform("type::impl::transform_leb128")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn transform_leb128_array(auto array) {
|
||||
u128 res = array[0] & 0x7f;
|
||||
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
|
||||
res |= u64(array[i] & 0x7f) << 7 * i;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn format_leb128(auto leb128) {
|
||||
u128 res = type::impl::transform_leb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_leb128(auto leb128) {
|
||||
return type::impl::transform_leb128_array(leb128.array);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
includes/type/path.pat
Normal file
32
includes/type/path.pat
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct UnixPathSegment {
|
||||
char string[while(std::mem::read_unsigned($, 1) != '/' && std::mem::read_unsigned($, 1) != 0x00)];
|
||||
char separator [[hidden]];
|
||||
|
||||
if (separator == 0x00) {
|
||||
$ -= 1;
|
||||
break;
|
||||
}
|
||||
} [[sealed, format("type::impl::format_unix_path_segment")]];
|
||||
|
||||
struct UnixPath {
|
||||
UnixPathSegment segments[while(true)];
|
||||
} [[format("type::impl::format_unix_path")]];
|
||||
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn format_unix_path_segment(UnixPathSegment segment) {
|
||||
return segment.string;
|
||||
};
|
||||
|
||||
fn format_unix_path(UnixPath path) {
|
||||
return std::mem::read_string($, sizeof(path));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
45
includes/type/size.pat
Normal file
45
includes/type/size.pat
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace type {
|
||||
|
||||
using Size8 = u8 [[format("type::impl::size_formatter")]];
|
||||
using Size16 = u16 [[format("type::impl::size_formatter")]];
|
||||
using Size32 = u32 [[format("type::impl::size_formatter")]];
|
||||
using Size64 = u64 [[format("type::impl::size_formatter")]];
|
||||
using Size128 = u128 [[format("type::impl::size_formatter")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn size_formatter(u128 size) {
|
||||
double sizeFloat = size;
|
||||
|
||||
u32 i = 0;
|
||||
while (sizeFloat >= 1024 && i <= 6) {
|
||||
i += 1;
|
||||
sizeFloat /= 1024;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
if (size == 1)
|
||||
return std::format("{} Byte", size);
|
||||
else
|
||||
return std::format("{} Bytes", size);
|
||||
} else {
|
||||
str result = std::format("{:.3f} ", sizeFloat);
|
||||
|
||||
if (i == 1)
|
||||
return result + "kiB";
|
||||
else if (i == 2)
|
||||
return result + "MiB";
|
||||
else if (i == 3)
|
||||
return result + "GiB";
|
||||
else if (i == 4)
|
||||
return result + "TiB";
|
||||
else if (i == 5)
|
||||
return result + "PiB";
|
||||
else
|
||||
return result + "EiB";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
73
patterns/bencode.hexpat
Normal file
73
patterns/bencode.hexpat
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma MIME application/x-bittorrent
|
||||
|
||||
#include <std/ctype.pat>
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
|
||||
namespace bencode {
|
||||
|
||||
struct ASCIIDecimal {
|
||||
char value[while(std::ctype::isdigit(std::mem::read_unsigned($, 1)))];
|
||||
} [[sealed, format("bencode::format_ascii_decimal"), transform("bencode::format_ascii_decimal")]];
|
||||
|
||||
fn format_ascii_decimal(ASCIIDecimal adsasd) {
|
||||
return std::string::parse_int(adsasd.value, 10);
|
||||
};
|
||||
|
||||
enum Type : u8 {
|
||||
Integer = 'i',
|
||||
Dictionary = 'd',
|
||||
List = 'l',
|
||||
|
||||
String0 = '0',
|
||||
String1 = '1',
|
||||
String2 = '2',
|
||||
String3 = '3',
|
||||
String4 = '4',
|
||||
String5 = '5',
|
||||
String6 = '6',
|
||||
String7 = '7',
|
||||
String8 = '8',
|
||||
String9 = '9'
|
||||
};
|
||||
|
||||
struct String {
|
||||
ASCIIDecimal length;
|
||||
char separator [[hidden]];
|
||||
char value[length];
|
||||
} [[sealed, format("bencode::format_string"), transform("bencode::format_string")]];
|
||||
|
||||
fn format_string(String string) {
|
||||
return string.value;
|
||||
};
|
||||
|
||||
using Bencode;
|
||||
using Value;
|
||||
|
||||
struct DictionaryEntry {
|
||||
String key;
|
||||
Value value;
|
||||
};
|
||||
|
||||
struct Value {
|
||||
Type type;
|
||||
|
||||
if (type == Type::Dictionary) {
|
||||
DictionaryEntry entry[while(std::mem::read_unsigned($, 1) != 'e')];
|
||||
} else if (type == Type::Integer) {
|
||||
ASCIIDecimal value;
|
||||
char end;
|
||||
} else {
|
||||
$ -= 1;
|
||||
String value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Bencode {
|
||||
Value value[while(!std::mem::eof())] [[inline]];
|
||||
char end;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bencode::Bencode bencode @ 0x00;
|
||||
@@ -158,7 +158,11 @@ namespace program {
|
||||
LOOS = 0x60000000,
|
||||
HIOS = 0x6FFFFFFF,
|
||||
LOPROC = 0x70000000,
|
||||
HIPROC = 0x7FFFFFFF
|
||||
HIPROC = 0x7FFFFFFF,
|
||||
GNU_EH_FRAME = program::Type::LOOS + 0x474E550,
|
||||
GNU_STACK = program::Type::LOOS + 0x474E551,
|
||||
GNU_RELRO = program::Type::LOOS + 0x474E552,
|
||||
GNU_PROPERTY = program::Type::LOOS + 0x474E553
|
||||
};
|
||||
|
||||
struct Header {
|
||||
@@ -181,7 +185,7 @@ namespace program {
|
||||
u64 memory_size;
|
||||
u64 alignment;
|
||||
}
|
||||
} [[static]];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -251,7 +255,7 @@ namespace section {
|
||||
u64 address_alignment;
|
||||
u64 entry_size;
|
||||
}
|
||||
} [[static]];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
168
patterns/fs.hexpat
Normal file
168
patterns/fs.hexpat
Normal file
@@ -0,0 +1,168 @@
|
||||
#include <std/io.pat>
|
||||
|
||||
struct DiskTimeStamp {
|
||||
u8 seconds, minutes, hours;
|
||||
};
|
||||
|
||||
enum DiskProtection : u16 {
|
||||
None = 0x0000,
|
||||
CopyProtected = 0x5A5A
|
||||
};
|
||||
|
||||
bitfield CHS {
|
||||
h : 8;
|
||||
s : 6;
|
||||
c : 10;
|
||||
} [[right_to_left, format("chs_formatter")]];
|
||||
|
||||
fn chs_formatter(CHS chs) {
|
||||
return std::format("({:X}, {:X}, {:X}) | 0x{:X}", chs.c, chs.h, chs.s, (chs.c * 16 + chs.h) * 63 + (chs.s - 1));
|
||||
};
|
||||
|
||||
enum PartitionStatus : u8 {
|
||||
None = 0x00,
|
||||
Active = 0x80
|
||||
};
|
||||
|
||||
enum PartitionType : u8 {
|
||||
EmptyPartitionEntry = 0x00,
|
||||
FAT32_CHS = 0x0B,
|
||||
FAT32_LBA = 0x0C
|
||||
};
|
||||
|
||||
namespace fat32 {
|
||||
|
||||
u64 bytesPerCluster;
|
||||
|
||||
struct FSInfo {
|
||||
u32 leadSignature;
|
||||
padding[480];
|
||||
u32 structSignature;
|
||||
u32 freeClusterCount;
|
||||
u32 nextFreeCluster;
|
||||
padding[12];
|
||||
u32 trailSignature;
|
||||
};
|
||||
|
||||
bitfield SequenceNumber {
|
||||
padding : 1;
|
||||
lastLogical : 1;
|
||||
padding : 1;
|
||||
number : 5;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum EntryStatus : u8 {
|
||||
Regular = 0x00,
|
||||
DotEntry = 0x2E,
|
||||
DeletedEntry = 0xE5
|
||||
};
|
||||
|
||||
union EntryStatusOrSequenceNumber {
|
||||
EntryStatus entryStatus;
|
||||
SequenceNumber sequenceNumber;
|
||||
};
|
||||
|
||||
bitfield Attributes {
|
||||
readOnly : 1;
|
||||
hidden : 1;
|
||||
systemFile : 1;
|
||||
volumeLabel : 1;
|
||||
subdirectory : 1;
|
||||
archive : 1;
|
||||
padding : 2;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DirEntry {
|
||||
char fileName[8];
|
||||
char extension[3];
|
||||
Attributes attributes;
|
||||
u8 reserved[10];
|
||||
u16 time, date;
|
||||
u16 startingCluster;
|
||||
u32 fileSize;
|
||||
|
||||
u8 data[fileSize] @ startingCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
struct VFATDirEntry {
|
||||
EntryStatusOrSequenceNumber entryStatusOrSequenceNumber;
|
||||
char16 name1[5];
|
||||
Attributes attributes;
|
||||
u8 type;
|
||||
u8 nameChecksum;
|
||||
char16 name2[6];
|
||||
u16 startingCluster;
|
||||
char16 name3[2];
|
||||
|
||||
if (entryStatusOrSequenceNumber.sequenceNumber.number > 1)
|
||||
VFATDirEntry nextLogicalEntry;
|
||||
else
|
||||
DirEntry physicalEntry;
|
||||
};
|
||||
|
||||
struct Partition {
|
||||
u8 jmpCode[3];
|
||||
char oemName[8];
|
||||
u16 bytesPerSector;
|
||||
u8 sectorsPerCluster;
|
||||
u16 reservedAreaSize;
|
||||
u8 numFats;
|
||||
u16 rootEntryCount;
|
||||
u16 numSectors;
|
||||
u8 mediaType;
|
||||
u16 fatSize;
|
||||
u16 sectorsPerTrack;
|
||||
u16 numHeads;
|
||||
u32 numHiddenSectors;
|
||||
u32 numFsSectors;
|
||||
u32 numFatSectors;
|
||||
u16 extFlags;
|
||||
u16 fsVersion;
|
||||
u32 rootCluster;
|
||||
u16 fsInfoSector;
|
||||
u16 backupBootSector;
|
||||
padding[12];
|
||||
u8 driveNumber;
|
||||
padding[1];
|
||||
u8 bootSignature;
|
||||
u32 volumeID;
|
||||
char volumeLabel[11];
|
||||
char fsType[8];
|
||||
u8 bootstrapCode[420];
|
||||
u16 signature;
|
||||
|
||||
bytesPerCluster = (sectorsPerCluster * 1024) * bytesPerSector;
|
||||
|
||||
FSInfo fsInfo @ addressof(this) + fsInfoSector * bytesPerSector;
|
||||
VFATDirEntry rootDirEntry @ addressof(this) + rootCluster * bytesPerCluster;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct PartitionEntry {
|
||||
PartitionStatus status;
|
||||
CHS chsFirstSectorAddress;
|
||||
PartitionType type;
|
||||
CHS chsLastSectorAddress;
|
||||
u32 lbaFirstSectorAddress;
|
||||
u32 numSectors;
|
||||
|
||||
if (type == PartitionType::EmptyPartitionEntry)
|
||||
continue;
|
||||
else if (type == PartitionType::FAT32_CHS || type == PartitionType::FAT32_LBA)
|
||||
fat32::Partition partition @ lbaFirstSectorAddress * 512;
|
||||
};
|
||||
|
||||
struct MasterBootRecord {
|
||||
u8 bootstrapCodeArea1[218];
|
||||
padding[2];
|
||||
u8 originalPhysicalDrive;
|
||||
DiskTimeStamp diskTimeStamp;
|
||||
u8 bootstrapCodeArea2[216];
|
||||
u32 diskSignature;
|
||||
DiskProtection diskProtection;
|
||||
PartitionEntry partitionEntries[4];
|
||||
u16 bootSignature;
|
||||
};
|
||||
|
||||
MasterBootRecord mbr @ 0x00;
|
||||
459
patterns/lnk.hexpat
Normal file
459
patterns/lnk.hexpat
Normal file
@@ -0,0 +1,459 @@
|
||||
#pragma MIME application/x-ms-shortcut
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
bitfield LinkFlags {
|
||||
HasLinkTargetIDList : 1;
|
||||
HasLinkInfo : 1;
|
||||
HasName : 1;
|
||||
HasRelativePath : 1;
|
||||
HasWorkingDir : 1;
|
||||
HasArguments : 1;
|
||||
HasIconLocation : 1;
|
||||
IsUnicode : 1;
|
||||
ForceNoLinkInfo : 1;
|
||||
HasExpString : 1;
|
||||
RunInSeparateProcess : 1;
|
||||
padding : 1;
|
||||
HasDarwinID : 1;
|
||||
RunAsUser : 1;
|
||||
HasExpIcon : 1;
|
||||
NoPidlAlias : 1;
|
||||
padding : 1;
|
||||
RunWithShimLayer : 1;
|
||||
ForceNoLinkTrack : 1;
|
||||
EnableTargetMetadata : 1;
|
||||
DisableLinkPathTracking : 1;
|
||||
DisableKnownFolderTracking : 1;
|
||||
DisableKnownFolderAlias : 1;
|
||||
AllowLinkToLink : 1;
|
||||
UnaliasOnSave : 1;
|
||||
PreferEnvironmentPath : 1;
|
||||
KeepLocalIDListForUNCTarget : 1;
|
||||
padding : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield FileAttributesFlags {
|
||||
FILE_ATTRIBUTE_READONLY : 1;
|
||||
FILE_ATTRIBUTE_HIDDEN : 1;
|
||||
FILE_ATTRIBUTE_SYSTEM : 1;
|
||||
padding : 1;
|
||||
FILE_ATTRIBUTE_DIRECTORY : 1;
|
||||
FILE_ATTRIBUTE_ARCHIVE : 1;
|
||||
padding : 1;
|
||||
FILE_ATTRIBUTE_NORMAL : 1;
|
||||
FILE_ATTRIBUTE_TEMPORARY : 1;
|
||||
FILE_ATTRIBUTE_SPARSE_FILE : 1;
|
||||
FILE_ATTRIBUTE_REPARSE_POINT : 1;
|
||||
FILE_ATTRIBUTE_COMPRESSED : 1;
|
||||
FILE_ATTRIBUTE_OFFLINE : 1;
|
||||
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : 1;
|
||||
FILE_ATTRIBUTE_ENCRYPTED : 1;
|
||||
padding : 17;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield ModifierKeys {
|
||||
HOTKEYF_SHIFT : 1;
|
||||
HOTKEYF_CONTROL : 1;
|
||||
HOTKEYF_ALT : 1;
|
||||
padding : 5;
|
||||
} [[right_to_left]];
|
||||
|
||||
enum Keys : u8 {
|
||||
KEY_NONE = 0x00,
|
||||
KEY_0 = 0x30,
|
||||
KEY_1 = 0x31,
|
||||
KEY_2 = 0x32,
|
||||
KEY_3 = 0x33,
|
||||
KEY_4 = 0x34,
|
||||
KEY_5 = 0x35,
|
||||
KEY_6 = 0x36,
|
||||
KEY_7 = 0x37,
|
||||
KEY_8 = 0x38,
|
||||
KEY_9 = 0x39,
|
||||
KEY_A = 0x41,
|
||||
KEY_B = 0x42,
|
||||
KEY_C = 0x43,
|
||||
KEY_D = 0x44,
|
||||
KEY_E = 0x45,
|
||||
KEY_F = 0x46,
|
||||
KEY_G = 0x47,
|
||||
KEY_H = 0x48,
|
||||
KEY_I = 0x49,
|
||||
KEY_J = 0x4A,
|
||||
KEY_K = 0x4B,
|
||||
KEY_L = 0x4C,
|
||||
KEY_M = 0x4D,
|
||||
KEY_N = 0x4E,
|
||||
KEY_O = 0x4F,
|
||||
KEY_P = 0x50,
|
||||
KEY_Q = 0x51,
|
||||
KEY_R = 0x52,
|
||||
KEY_S = 0x53,
|
||||
KEY_T = 0x54,
|
||||
KEY_U = 0x55,
|
||||
KEY_V = 0x56,
|
||||
KEY_W = 0x57,
|
||||
KEY_X = 0x58,
|
||||
KEY_Y = 0x59,
|
||||
KEY_Z = 0x5A,
|
||||
|
||||
VK_F1 = 0x70,
|
||||
VK_F2 = 0x71,
|
||||
VK_F3 = 0x72,
|
||||
VK_F4 = 0x73,
|
||||
VK_F5 = 0x74,
|
||||
VK_F6 = 0x75,
|
||||
VK_F7 = 0x76,
|
||||
VK_F8 = 0x77,
|
||||
VK_F9 = 0x78,
|
||||
VK_F10 = 0x79,
|
||||
VK_F11 = 0x7A,
|
||||
VK_F12 = 0x7B,
|
||||
VK_F13 = 0x7C,
|
||||
VK_F14 = 0x7D,
|
||||
VK_F15 = 0x7E,
|
||||
VK_F16 = 0x7F,
|
||||
VK_F17 = 0x80,
|
||||
VK_F18 = 0x81,
|
||||
VK_F19 = 0x82,
|
||||
VK_F20 = 0x83,
|
||||
VK_F21 = 0x84,
|
||||
VK_F22 = 0x85,
|
||||
VK_F23 = 0x86,
|
||||
VK_F24 = 0x87,
|
||||
VK_NUMLOCK = 0x90,
|
||||
VK_SCROLL = 0x91,
|
||||
};
|
||||
|
||||
struct HotKeyFlags {
|
||||
Keys Key;
|
||||
ModifierKeys ModifierKeys;
|
||||
};
|
||||
|
||||
struct FILETIME {
|
||||
u32 dwLowDateTime;
|
||||
u32 dwHighDateTime;
|
||||
};
|
||||
|
||||
enum SHOWWINDOW_FLAGS : u32 {
|
||||
SW_SHOWNORMAL = 0x00000001,
|
||||
SW_SHOWMAXIMIZED = 0x00000003,
|
||||
SW_SHOWMINNOACTIVE = 0x00000007
|
||||
};
|
||||
|
||||
struct ShellLinkHeader {
|
||||
type::Size32 HeaderSize;
|
||||
type::GUID LinkCLSID;
|
||||
LinkFlags LinkFlags;
|
||||
FileAttributesFlags FileAttributes;
|
||||
FILETIME CreationTime, AccessTime, WriteTime;
|
||||
type::Size32 FileSize;
|
||||
u32 IconIndex;
|
||||
SHOWWINDOW_FLAGS ShowCommand;
|
||||
HotKeyFlags HotKey;
|
||||
padding[2];
|
||||
padding[4];
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct ItemID {
|
||||
type::Size16 ItemIDSize;
|
||||
|
||||
if (ItemIDSize == 0x00)
|
||||
break;
|
||||
else
|
||||
u8 Data[ItemIDSize - sizeof(ItemIDSize)];
|
||||
};
|
||||
|
||||
struct IDList {
|
||||
ItemID ItemIDList[while(true)];
|
||||
};
|
||||
|
||||
struct LinkTargetIDList {
|
||||
type::Size16 IDListSize;
|
||||
IDList IDList[while($ < (addressof(IDListSize) + IDListSize))];
|
||||
};
|
||||
|
||||
bitfield LinkInfoFlags {
|
||||
VolumeIDAndLocalBasePath : 1;
|
||||
CommonNetworkRelativeLinkAndPathSuffix : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
enum DriveType : u32 {
|
||||
DRIVE_UNKNOWN = 0x00000000,
|
||||
DRIVE_NO_ROOT_DIR = 0x00000001,
|
||||
DRIVE_REMOVABLE = 0x00000002,
|
||||
DRIVE_FIXED = 0x00000003,
|
||||
DRIVE_REMOTE = 0x00000004,
|
||||
DRIVE_CDROM = 0x00000005,
|
||||
DRIVE_RAMDISK = 0x00000006
|
||||
};
|
||||
|
||||
struct VolumeID {
|
||||
type::Size32 VolumeIDSize;
|
||||
DriveType DriveType;
|
||||
u32 DriveSerialNumber;
|
||||
u32 VolumeLabelOffset;
|
||||
if (VolumeLabelOffset == 0x14)
|
||||
u32 VolumeLabelOffsetUnicode;
|
||||
char Data[VolumeIDSize - ($ - addressof(this))];
|
||||
};
|
||||
|
||||
bitfield CommonNetworkRelativeLinkFlags {
|
||||
ValidDevice : 1;
|
||||
ValidNetType : 1;
|
||||
padding : 30;
|
||||
} [[right_to_left]];
|
||||
|
||||
enum NetworkProviderType : u32 {
|
||||
WNNC_NET_AVID = 0x001A0000,
|
||||
WNNC_NET_DOCUSPACE = 0x001B0000,
|
||||
WNNC_NET_MANGOSOFT = 0x001C0000,
|
||||
WNNC_NET_SERNET = 0x001D0000,
|
||||
WNNC_NET_RIVERFRONT1 = 0x001E0000,
|
||||
WNNC_NET_RIVERFRONT2 = 0x001F0000,
|
||||
WNNC_NET_DECORB = 0x00200000,
|
||||
WNNC_NET_PROTSTOR = 0x00210000,
|
||||
WNNC_NET_FJ_REDIR = 0x00220000,
|
||||
WNNC_NET_DISTINCT = 0x00230000,
|
||||
WNNC_NET_TWINS = 0x00240000,
|
||||
WNNC_NET_RDR2SAMPLE = 0x00250000,
|
||||
WNNC_NET_CSC = 0x00260000,
|
||||
WNNC_NET_3IN1 = 0x00270000,
|
||||
WNNC_NET_EXTENDNET = 0x00290000,
|
||||
WNNC_NET_STAC = 0x002A0000,
|
||||
WNNC_NET_FOXBAT = 0x002B0000,
|
||||
WNNC_NET_YAHOO = 0x002C0000,
|
||||
WNNC_NET_EXIFS = 0x002D0000,
|
||||
WNNC_NET_DAV = 0x002E0000,
|
||||
WNNC_NET_KNOWARE = 0x002F0000,
|
||||
WNNC_NET_OBJECT_DIRE = 0x00300000,
|
||||
WNNC_NET_MASFAX = 0x00310000,
|
||||
WNNC_NET_HOB_NFS = 0x00320000,
|
||||
WNNC_NET_SHIVA = 0x00330000,
|
||||
WNNC_NET_IBMAL = 0x00340000,
|
||||
WNNC_NET_LOCK = 0x00350000,
|
||||
WNNC_NET_TERMSRV = 0x00360000,
|
||||
WNNC_NET_SRT = 0x00370000,
|
||||
WNNC_NET_QUINCY = 0x00380000,
|
||||
WNNC_NET_OPENAFS = 0x00390000,
|
||||
WNNC_NET_AVID1 = 0x003A0000,
|
||||
WNNC_NET_DFS = 0x003B0000,
|
||||
WNNC_NET_KWNP = 0x003C0000,
|
||||
WNNC_NET_ZENWORKS = 0x003D0000,
|
||||
WNNC_NET_DRIVEONWEB = 0x003E0000,
|
||||
WNNC_NET_VMWARE = 0x003F0000,
|
||||
WNNC_NET_RSFX = 0x00400000,
|
||||
WNNC_NET_MFILES = 0x00410000,
|
||||
WNNC_NET_MS_NFS = 0x00420000,
|
||||
WNNC_NET_GOOGLE = 0x00430000
|
||||
};
|
||||
|
||||
struct CommonNetworkRelativeLink {
|
||||
type::Size32 CommonNetworkRelativeLinkSize;
|
||||
CommonNetworkRelativeLinkFlags CommonNetworkRelativeLinkFlags;
|
||||
u32 NetNameOffset;
|
||||
u32 DeviceNameOffset;
|
||||
NetworkProviderType NetworkProviderType;
|
||||
|
||||
if (NetNameOffset > 0x14) {
|
||||
u32 NetNameOffsetUnicode;
|
||||
u32 DeviceNameOffsetUnicode;
|
||||
}
|
||||
|
||||
char NetName[];
|
||||
char DeviceName[];
|
||||
|
||||
if (NetNameOffset > 0x14) {
|
||||
char16 NetNameUnicode[];
|
||||
char16 DeviceNameUnicode[];
|
||||
}
|
||||
};
|
||||
|
||||
struct LinkInfo {
|
||||
type::Size32 LinkInfoSize;
|
||||
type::Size32 LinkInfoHeaderSize;
|
||||
LinkInfoFlags LinkInfoFlags;
|
||||
u32 VolumeIDOffset;
|
||||
u32 LocalBasePathOffset;
|
||||
u32 CommonNetworkRelativeLinkOffset;
|
||||
u32 CommonPathSuffixOffset;
|
||||
|
||||
if (LinkInfoHeaderSize >= 0x24) {
|
||||
u32 LocalBasePathOffsetUnicode;
|
||||
u32 CommonPathSuffixOffsetUnicode;
|
||||
}
|
||||
|
||||
if (LinkInfoFlags.VolumeIDAndLocalBasePath) {
|
||||
VolumeID VolumeID;
|
||||
char LocalBasePath[];
|
||||
}
|
||||
|
||||
if (LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix)
|
||||
CommonNetworkRelativeLink CommonNetworkRelativeLink;
|
||||
|
||||
char CommonPathSuffix[];
|
||||
|
||||
if (LinkInfoHeaderSize >= 0x24) {
|
||||
if (LinkInfoFlags.VolumeIDAndLocalBasePath)
|
||||
char16 LocalBasePathUnicode[];
|
||||
char16 CommonPathSuffixUnicode[];
|
||||
}
|
||||
};
|
||||
|
||||
struct String {
|
||||
u16 CountCharacters;
|
||||
char16 String[CountCharacters];
|
||||
};
|
||||
|
||||
struct StringData {
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasName)
|
||||
String NAME_STRING;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasRelativePath)
|
||||
String RELATIVE_PATH;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasWorkingDir)
|
||||
String WORKING_DIR;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasArguments)
|
||||
String COMMAND_LINE_ARGUMENTS;
|
||||
if (parent.ShellLinkHeader.LinkFlags.HasIconLocation)
|
||||
String ICON_LOCATION;
|
||||
};
|
||||
|
||||
bitfield FillAttributes {
|
||||
FOREGROUND_BLUE : 1;
|
||||
FOREGROUND_GREEN : 1;
|
||||
FOREGROUND_RED : 1;
|
||||
FOREGROUND_INTENSITY : 1;
|
||||
|
||||
BACKGROUND_BLUE : 1;
|
||||
BACKGROUND_GREEN : 1;
|
||||
BACKGROUND_RED : 1;
|
||||
BACKGROUND_INTENSITY : 1;
|
||||
|
||||
padding : 8;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct ConsoleDataBlock {
|
||||
FillAttributes FillAttributes;
|
||||
FillAttributes PopupFillAttributes;
|
||||
u16 ScreenBufferSizeX, ScreenBufferSizeY;
|
||||
u16 WindowSizeX, WindowSizeY;
|
||||
u16 WindowOriginX, WindowOriginY;
|
||||
padding[4];
|
||||
padding[4];
|
||||
u32 FontSize;
|
||||
u32 FontFamily;
|
||||
u32 FontWeight;
|
||||
char16 FaceName[32];
|
||||
u32 CursorSize;
|
||||
u32 FullScreen;
|
||||
u32 QuickEdit;
|
||||
u32 InsertMode;
|
||||
u32 AutoPosition;
|
||||
u32 HistoryBufferSize;
|
||||
u32 NumberOfHistoryBuffers;
|
||||
u32 HistoryNoDup;
|
||||
u32 ColorTable[16];
|
||||
};
|
||||
|
||||
struct ConsoleFEDataBlock {
|
||||
u32 CodePage;
|
||||
};
|
||||
|
||||
struct DarwinDataBlock {
|
||||
char DarwinDataAnsi[260];
|
||||
char16 DarwinDataUnicode[260];
|
||||
};
|
||||
|
||||
struct EnvironmentVariableDataBlock {
|
||||
char TargetAnsi[260];
|
||||
char16 TargetUnicode[260];
|
||||
};
|
||||
|
||||
struct IconEnvironmentDataBlock {
|
||||
char TargetAnsi[260];
|
||||
char16 TargetUnicode[260];
|
||||
};
|
||||
|
||||
struct KnownFolderDataBlock {
|
||||
type::GUID KnownFolderID;
|
||||
u32 Offset;
|
||||
};
|
||||
|
||||
struct PropertyStoreDataBlock {
|
||||
u8 Bytes[parent.BlockSize - sizeof(parent.BlockSize) - sizeof(parent.BlockSignature)];
|
||||
std::warning("PropertyStoreDataBlock is not yet implemented!");
|
||||
};
|
||||
|
||||
struct ShimDataBlock {
|
||||
char16 LayerName[(parent.BlockSize - sizeof(parent.BlockSize) - sizeof(parent.BlockSignature)) / sizeof(char16)];
|
||||
};
|
||||
|
||||
struct SpecialFolderDataBlock {
|
||||
u32 SpecialFolderID;
|
||||
u32 Offset;
|
||||
};
|
||||
|
||||
struct TrackerDataBlock {
|
||||
type::Size32 Length;
|
||||
u32 Version;
|
||||
char MachineID[16];
|
||||
type::GUID Droid[2];
|
||||
type::GUID DroidBirth[2];
|
||||
};
|
||||
|
||||
struct VistaAndAboveIDListDataBlock {
|
||||
IDList IDList;
|
||||
};
|
||||
|
||||
struct ExtraDataBlock {
|
||||
type::Size32 BlockSize;
|
||||
|
||||
if (BlockSize < 0x04)
|
||||
break;
|
||||
else {
|
||||
u32 BlockSignature;
|
||||
|
||||
if (BlockSignature == 0xA000'0002)
|
||||
ConsoleDataBlock CONSOLE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0004)
|
||||
ConsoleFEDataBlock CONSOLE_FE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0006)
|
||||
DarwinDataBlock DARWIN_PROPS;
|
||||
else if (BlockSignature == 0xA000'0001)
|
||||
EnvironmentVariableDataBlock ENVIRONMENT_PROPS;
|
||||
else if (BlockSignature == 0xA000'0007)
|
||||
IconEnvironmentDataBlock ICON_ENVIRONMENT_PROPS;
|
||||
else if (BlockSignature == 0xA000'000B)
|
||||
KnownFolderDataBlock KNOWN_FOLDER_PROPS;
|
||||
else if (BlockSignature == 0xA000'0009)
|
||||
PropertyStoreDataBlock PROPERTY_STORE_PROPS;
|
||||
else if (BlockSignature == 0xA000'0008)
|
||||
ShimDataBlock SHIM_PROPS;
|
||||
else if (BlockSignature == 0xA000'0005)
|
||||
SpecialFolderDataBlock SPECIAL_FOLDER_PROPS;
|
||||
else if (BlockSignature == 0xA000'0003)
|
||||
TrackerDataBlock TRACKER_PROPS;
|
||||
else if (BlockSignature == 0xA000'000C)
|
||||
VistaAndAboveIDListDataBlock VISTA_AND_ABOVE_IDLIST_PROPS;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExtraData {
|
||||
ExtraDataBlock ExtraDataBlock[while(true)];
|
||||
};
|
||||
|
||||
struct LNK {
|
||||
ShellLinkHeader ShellLinkHeader;
|
||||
if (ShellLinkHeader.LinkFlags.HasLinkTargetIDList)
|
||||
LinkTargetIDList LinkTargetIDList;
|
||||
if (ShellLinkHeader.LinkFlags.HasLinkInfo)
|
||||
LinkInfo LinkInfo;
|
||||
StringData StringData;
|
||||
ExtraData ExtraData;
|
||||
};
|
||||
|
||||
LNK lnk @ 0x00;
|
||||
161
patterns/ntag.hexpat
Normal file
161
patterns/ntag.hexpat
Normal file
@@ -0,0 +1,161 @@
|
||||
bitfield AccessCapability {
|
||||
Read : 4;
|
||||
Write : 4;
|
||||
} [[left_to_right]];
|
||||
|
||||
struct CapabilityContainer {
|
||||
u8 magic;
|
||||
u8 version;
|
||||
u8 memorySize;
|
||||
AccessCapability accessCapability;
|
||||
};
|
||||
|
||||
bitfield NDEFFlags {
|
||||
MB : 1;
|
||||
ME : 1;
|
||||
CF : 1;
|
||||
SR : 1;
|
||||
IL : 1;
|
||||
TNF : 3;
|
||||
} [[left_to_right]];
|
||||
|
||||
enum TNFType : u8 {
|
||||
Empty = 0x00,
|
||||
NFCForumWellKnownType = 0x01,
|
||||
MediaType = 0x02,
|
||||
AbsoluteURI = 0x03,
|
||||
NFCForumExternalType = 0x04,
|
||||
Unknown = 0x05,
|
||||
Unchanged = 0x06,
|
||||
Reserved = 0x07
|
||||
};
|
||||
|
||||
struct NDEF {
|
||||
NDEFFlags flags;
|
||||
u8 typeLength;
|
||||
|
||||
if (flags.SR)
|
||||
u8 payloadLength;
|
||||
else
|
||||
u32 payloadLength;
|
||||
|
||||
if (flags.IL)
|
||||
u8 idLength;
|
||||
|
||||
char type[typeLength];
|
||||
|
||||
if (flags.IL)
|
||||
u8 id[idLength];
|
||||
|
||||
u8 payload[payloadLength];
|
||||
|
||||
if (flags.ME)
|
||||
break;
|
||||
};
|
||||
|
||||
struct LockControl {
|
||||
u8 dynamicLockByteOffset;
|
||||
u8 numBits;
|
||||
u8 pageControlInfo;
|
||||
};
|
||||
|
||||
struct MemoryControl {
|
||||
u8 reservedBytesOffset;
|
||||
u8 numBytes;
|
||||
u8 pageSize;
|
||||
};
|
||||
|
||||
struct Length {
|
||||
u8 byte [[hidden, no_unique_address]];
|
||||
if (byte == 0xFF)
|
||||
u24 length;
|
||||
else
|
||||
u8 length;
|
||||
} [[sealed, transform("transform_length"), format("transform_length")]];
|
||||
|
||||
fn transform_length(Length length) {
|
||||
return length.length;
|
||||
};
|
||||
|
||||
enum Tag : u8 {
|
||||
NULL = 0x00,
|
||||
LockControl = 0x01,
|
||||
MemoryControl = 0x02,
|
||||
NDEFMessage = 0x03,
|
||||
Proprietary = 0xFD,
|
||||
TerminatorTLV = 0xFE
|
||||
};
|
||||
|
||||
struct TLV {
|
||||
Tag tag;
|
||||
if (tag == Tag::TerminatorTLV) {
|
||||
break;
|
||||
} else if (tag == Tag::NULL) {
|
||||
// Empty
|
||||
} else {
|
||||
Length length;
|
||||
|
||||
if (length > 0) {
|
||||
if (tag == Tag::LockControl) {
|
||||
LockControl lockControl;
|
||||
} else if (tag == Tag::MemoryControl) {
|
||||
LockControl lockControl;
|
||||
} else if (tag == Tag::NDEFMessage) {
|
||||
NDEF ndef[while(true)];
|
||||
} else {
|
||||
u8 value[length];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ManufacturerData {
|
||||
u8 serial1[3];
|
||||
u8 checkByte0;
|
||||
u8 serial2[4];
|
||||
u8 checkByte1;
|
||||
u8 internal;
|
||||
u16 lockBytes;
|
||||
};
|
||||
|
||||
struct DynamicLockBytes {
|
||||
u8 bytes[3];
|
||||
u8 RFUI;
|
||||
};
|
||||
|
||||
bitfield MIRROR {
|
||||
MIRROR_CONF : 2;
|
||||
MIRROR_BYTE : 2;
|
||||
RFUI : 1;
|
||||
STRG_MOD_EN : 1;
|
||||
RFUI : 2;
|
||||
} [[left_to_right]];
|
||||
|
||||
bitfield ACCESS {
|
||||
PROT : 1;
|
||||
CFGLCK : 1;
|
||||
RFUI : 1;
|
||||
NFC_CNT_EN : 1;
|
||||
NFC_CNT_PWD_PROT : 1;
|
||||
AUTHLIM : 3;
|
||||
};
|
||||
|
||||
struct Config {
|
||||
MIRROR MIRROR;
|
||||
u8 MIRROR_PAGE;
|
||||
u8 AUTH0;
|
||||
ACCESS ACCESS;
|
||||
u32 PWD;
|
||||
u16 PACK;
|
||||
};
|
||||
|
||||
struct NTAG {
|
||||
ManufacturerData manufacturerData;
|
||||
CapabilityContainer cc;
|
||||
TLV tlv[while(true)];
|
||||
padding[addressof(tlv) + cc.memorySize * 8 - sizeof(tlv)];
|
||||
DynamicLockBytes dynamicLockBytes;
|
||||
Config config;
|
||||
};
|
||||
|
||||
NTAG ntag @ 0x00;
|
||||
29
patterns/ogg.hexpat
Normal file
29
patterns/ogg.hexpat
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma MIME audio/ogg
|
||||
|
||||
#include <std/core.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
bitfield HeaderType {
|
||||
Continuation : 1;
|
||||
BeginOfStream : 1;
|
||||
EndOfStream : 1;
|
||||
};
|
||||
|
||||
struct SegmentData {
|
||||
u8 data[parent.segmentTable[std::core::array_index()]];
|
||||
};
|
||||
|
||||
struct Ogg {
|
||||
char capturePattern[4];
|
||||
u8 version;
|
||||
HeaderType headerType;
|
||||
u64 granulePosition;
|
||||
u32 bitstreamSerialNumber;
|
||||
u32 pageSequenceNumber;
|
||||
u32 checksum;
|
||||
u8 pageSegments;
|
||||
u8 segmentTable[pageSegments];
|
||||
SegmentData data[pageSegments];
|
||||
};
|
||||
|
||||
Ogg ogg[while(!std::mem::eof())] @ 0x00;
|
||||
@@ -1,4 +1,10 @@
|
||||
#pragma MIME application/x-dosexec
|
||||
#pragma MIME application/x-msdownload
|
||||
#pragma pattern_limit 100000
|
||||
#pragma array_limit 10000
|
||||
#include <std/mem.pat>
|
||||
#include <std/string.pat>
|
||||
#include <std/ctype.pat>
|
||||
#include <std/io.pat>
|
||||
|
||||
enum MachineType : u16 {
|
||||
Unknown = 0x00,
|
||||
@@ -7,9 +13,13 @@ enum MachineType : u16 {
|
||||
ARM = 0x1C0,
|
||||
ARM64 = 0xAA64,
|
||||
ARMNT = 0x1C4,
|
||||
DECAlphaAXP = 0x183,
|
||||
EBC = 0xEBC,
|
||||
I386 = 0x14C,
|
||||
I860 = 0x14D,
|
||||
IA64 = 0x200,
|
||||
LOONGARCH32 = 0x6232,
|
||||
LOONGARCH64 = 0x6264,
|
||||
M32R = 0x9041,
|
||||
MIPS16 = 0x266,
|
||||
MIPSFPU = 0x366,
|
||||
@@ -28,32 +38,99 @@ enum MachineType : u16 {
|
||||
WCEMIPSV2 = 0x169
|
||||
};
|
||||
|
||||
enum PEFormat : u16 {
|
||||
PE32 = 0x10B,
|
||||
PE32Plus = 0x20B
|
||||
};
|
||||
|
||||
enum SubsystemType : u16 {
|
||||
Unknown = 0x00,
|
||||
Native = 0x01,
|
||||
WindowsGUI = 0x02,
|
||||
WindowsCUI = 0x03,
|
||||
OS2CUI = 0x05,
|
||||
POSIXCUI = 0x07,
|
||||
Windows9xNative = 0x08,
|
||||
WindowsCEGUI = 0x09,
|
||||
EFIApplication = 0x0A,
|
||||
EFIBootServiceDriver = 0x0B,
|
||||
EFIRuntimeDriver = 0x0C,
|
||||
EFIROM = 0x0D,
|
||||
Xbox = 0x0E,
|
||||
WindowsBootApplication = 0x10
|
||||
};
|
||||
|
||||
bitfield Characteristics {
|
||||
stripped : 1;
|
||||
relocationsStripped : 1;
|
||||
executableImage : 1;
|
||||
lineNumsStripped : 1;
|
||||
localSymsStripped : 1;
|
||||
lineNumbersStripped : 1;
|
||||
localSymbolsStripped : 1;
|
||||
aggressiveWsTrim : 1;
|
||||
largeAddressAware : 1;
|
||||
reserved : 1;
|
||||
bytesReversedLo : 1;
|
||||
is32BitMachine : 1;
|
||||
debugStripped : 1;
|
||||
debugInfoStripped : 1;
|
||||
removableRunFromSwap : 1;
|
||||
netRunFromSwap : 1;
|
||||
system : 1;
|
||||
dll : 1;
|
||||
upSystemOnly : 1;
|
||||
uniprocessorMachineOnly : 1;
|
||||
bytesReversedHi : 1;
|
||||
};
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield DLLCharacteristics {
|
||||
reserved : 4;
|
||||
padding : 1;
|
||||
highEntropyVA : 1;
|
||||
dynamicBase : 1;
|
||||
forceIntegrity : 1;
|
||||
nxCompatible : 1;
|
||||
noIsolation : 1;
|
||||
noSEH : 1;
|
||||
doNotBind : 1;
|
||||
appContainer : 1;
|
||||
wdmDriver : 1;
|
||||
cfGuard : 1;
|
||||
terminalServerAware : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield SectionFlags {
|
||||
reserved : 3;
|
||||
doNotPad : 1;
|
||||
reserved : 1;
|
||||
containsCode : 1;
|
||||
containsInitializedData : 1;
|
||||
containsUninitializedData : 1;
|
||||
linkOther : 1;
|
||||
comments : 1;
|
||||
reserved : 1;
|
||||
remove : 1;
|
||||
comdat : 1;
|
||||
padding : 2;
|
||||
globalPointerRelocation : 1;
|
||||
purgeable : 1;
|
||||
is16Bit : 1;
|
||||
locked : 1;
|
||||
preloaded : 1;
|
||||
dataAlignment : 4;
|
||||
extendedRelocations : 1;
|
||||
discardable : 1;
|
||||
notCacheable : 1;
|
||||
notPageable : 1;
|
||||
shared : 1;
|
||||
executed : 1;
|
||||
read : 1;
|
||||
writtenTo : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct DataDirectory {
|
||||
u32 virtualAddress;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct OptionalHeader32 {
|
||||
u16 magic;
|
||||
struct OptionalHeader {
|
||||
PEFormat magic;
|
||||
u8 majorLinkerVersion;
|
||||
u8 minorLinkerVersion;
|
||||
u32 sizeOfCode;
|
||||
@@ -61,8 +138,13 @@ struct OptionalHeader32 {
|
||||
u32 sizeOfUninitializedData;
|
||||
u32 addressOfEntryPoint;
|
||||
u32 baseOfCode;
|
||||
u32 baseOfData;
|
||||
u32 imageBase;
|
||||
if (magic == PEFormat::PE32) {
|
||||
u32 baseOfData;
|
||||
u32 imageBase;
|
||||
}
|
||||
else if (magic == PEFormat::PE32Plus) {
|
||||
u64 imageBase;
|
||||
}
|
||||
u32 sectionAlignment;
|
||||
u32 fileAlignment;
|
||||
u16 majorOperatingSystemVersion;
|
||||
@@ -75,87 +157,90 @@ struct OptionalHeader32 {
|
||||
u32 sizeOfImage;
|
||||
u32 sizeOfHeaders;
|
||||
u32 checksum;
|
||||
u16 subsystem;
|
||||
u16 dllCharacteristics;
|
||||
u32 sizeOfStackReserve;
|
||||
u32 sizeOfStackCommit;
|
||||
u32 sizeOfHeapReserve;
|
||||
u32 sizeOfHeapCommit;
|
||||
SubsystemType subsystem;
|
||||
DLLCharacteristics dllCharacteristics;
|
||||
if (magic == PEFormat::PE32) {
|
||||
u32 sizeOfStackReserve;
|
||||
u32 sizeOfStackCommit;
|
||||
u32 sizeOfHeapReserve;
|
||||
u32 sizeOfHeapCommit;
|
||||
}
|
||||
else if (magic == PEFormat::PE32Plus) {
|
||||
u64 sizeOfStackReserve;
|
||||
u64 sizeOfStackCommit;
|
||||
u64 sizeOfHeapReserve;
|
||||
u64 sizeOfHeapCommit;
|
||||
}
|
||||
u32 loaderFlags;
|
||||
u32 numberOfRvaAndSizes;
|
||||
DataDirectory directories[numberOfRvaAndSizes];
|
||||
u32 numberOfRVAsAndSizes;
|
||||
DataDirectory directories[numberOfRVAsAndSizes];
|
||||
};
|
||||
|
||||
struct OptionalHeader64 {
|
||||
u16 magic;
|
||||
u8 majorLinkerVersion;
|
||||
u8 minorLinkerVersion;
|
||||
u32 sizeOfCode;
|
||||
u32 sizeOfInitializedData;
|
||||
u32 sizeOfUninitializedData;
|
||||
u32 addressOfEntryPoint;
|
||||
u32 baseOfCode;
|
||||
u64 imageBase;
|
||||
u32 sectionAlignment;
|
||||
u32 fileAlignment;
|
||||
u16 majorOperatingSystemVersion;
|
||||
u16 minorOperatingSystemVersion;
|
||||
u16 majorImageVersion;
|
||||
u16 minorImageVersion;
|
||||
u16 majorSubsystemVersion;
|
||||
u16 minorSubSystemVersion;
|
||||
u32 win32VersionValue;
|
||||
u32 sizeOfImage;
|
||||
u32 sizeOfHeaders;
|
||||
u32 checksum;
|
||||
u16 subsystem;
|
||||
u16 dllCharacteristics;
|
||||
u64 sizeOfStackReserve;
|
||||
u64 sizeOfStackCommit;
|
||||
u64 sizeOfHeapReserve;
|
||||
u64 sizeOfHeapCommit;
|
||||
u32 loaderFlags;
|
||||
u32 numberOfRvaAndSizes;
|
||||
DataDirectory directories[numberOfRvaAndSizes];
|
||||
};
|
||||
|
||||
struct COFFHeader {
|
||||
u32 signature;
|
||||
struct COFFHeader {
|
||||
char signature[4];
|
||||
MachineType machine;
|
||||
u16 numberOfSections;
|
||||
u32 timeDateStamp;
|
||||
u32 pointerToSymbolTable;
|
||||
u32 numberOfSymbolTable;
|
||||
u32 numberOfSymbols;
|
||||
u16 sizeOfOptionalHeader;
|
||||
Characteristics characteristics;
|
||||
|
||||
if (machine == MachineType::AMD64) {
|
||||
OptionalHeader64 optionalHeader;
|
||||
} else {
|
||||
OptionalHeader32 optionalHeader;
|
||||
|
||||
if (sizeOfOptionalHeader > 0x00) {
|
||||
OptionalHeader optionalHeader;
|
||||
}
|
||||
};
|
||||
|
||||
struct DOSHeader {
|
||||
u16 signature;
|
||||
u8 header[0x3A];
|
||||
COFFHeader *coffHeaderPointer : u32;
|
||||
char signature[2];
|
||||
u16 lastPageSize;
|
||||
u16 numberOfPages;
|
||||
u16 relocations;
|
||||
u16 headerSizeInParagraphs;
|
||||
u16 minimumAllocatedParagraphs;
|
||||
u16 maximumAllocatedParagraphs;
|
||||
u16 initialSSValue;
|
||||
u16 initialRelativeSPValue;
|
||||
u16 checksum;
|
||||
u16 initialRelativeIPValue;
|
||||
u16 initialCSValue;
|
||||
u16 relocationsTablePointer;
|
||||
u16 overlayNumber;
|
||||
u16 reservedWords[4];
|
||||
u16 oemIdentifier;
|
||||
u16 oemInformation;
|
||||
u16 reservedWords[10];
|
||||
u32 coffHeaderPointer;
|
||||
};
|
||||
|
||||
fn isdosmessage(char c) {
|
||||
return std::ctype::isalnum(c) || c == '.' || c == ' ';
|
||||
};
|
||||
|
||||
struct DOSStub {
|
||||
u8 code[14];
|
||||
s8 message[0x27];
|
||||
u8 data[11];
|
||||
u8 code[while(std::mem::read_string($, 4) != "This")];
|
||||
char message[while(isdosmessage(std::mem::read_unsigned($, 1)))];
|
||||
char data[while(std::mem::read_unsigned($, 1) != 0x00)];
|
||||
};
|
||||
|
||||
union SectionMisc {
|
||||
u32 physicalAddress;
|
||||
u32 virtualSize;
|
||||
struct PEHeader {
|
||||
DOSHeader dosHeader;
|
||||
if (dosHeader.headerSizeInParagraphs * 16 < std::mem::size()) {
|
||||
DOSStub dosStub @ dosHeader.headerSizeInParagraphs * 16;
|
||||
}
|
||||
};
|
||||
|
||||
struct Section {
|
||||
PEHeader peHeader @ 0x00;
|
||||
|
||||
COFFHeader coffHeader @ peHeader.dosHeader.coffHeaderPointer;
|
||||
|
||||
struct SectionHeader {
|
||||
char name[8];
|
||||
SectionMisc misc;
|
||||
if (coffHeader.characteristics.executableImage) {
|
||||
u32 virtualSize;
|
||||
} else {
|
||||
u32 physicalAddress;
|
||||
}
|
||||
u32 virtualAddress;
|
||||
u32 sizeOfRawData;
|
||||
u32 ptrRawData;
|
||||
@@ -163,15 +248,436 @@ struct Section {
|
||||
u32 ptrLineNumbers;
|
||||
u16 numberOfRelocations;
|
||||
u16 numberOfLineNumbers;
|
||||
SectionFlags characteristics;
|
||||
};
|
||||
|
||||
SectionHeader sectionTable[coffHeader.numberOfSections] @ (addressof(coffHeader.characteristics) + 2) + coffHeader.sizeOfOptionalHeader;
|
||||
|
||||
u16 currentSectionIndex;
|
||||
fn updateSectionIndex() {
|
||||
currentSectionIndex = currentSectionIndex + 1;
|
||||
};
|
||||
|
||||
struct NullTerminatedString {
|
||||
char string[while(std::mem::read_unsigned($, 1) != 0x00)];
|
||||
padding[1];
|
||||
} [[inline]];
|
||||
|
||||
// Declarations of sections and variables used by it
|
||||
// Imports + Readonly Data Section
|
||||
struct DirectoryTable {
|
||||
u32 lookupTableRVA;
|
||||
u32 timeDateStamp;
|
||||
u32 forwarderChain;
|
||||
u32 dllNameRVA;
|
||||
u32 addressTableRVA;
|
||||
};
|
||||
|
||||
struct ImportsSection {
|
||||
DirectoryTable directoryTables[while(std::mem::read_unsigned($, 16) != 0x00)];
|
||||
DirectoryTable nullDirectoryTable;
|
||||
};
|
||||
|
||||
struct ReadonlyDataSection {
|
||||
u8 readonlyDataStart[while($ < coffHeader.optionalHeader.directories[1].virtualAddress - (sectionTable[currentSectionIndex].virtualAddress - sectionTable[currentSectionIndex].ptrRawData))];
|
||||
ImportsSection importsSection;
|
||||
u8 readonlyDataEnd[while($ < sectionTable[currentSectionIndex+1].ptrRawData)];
|
||||
};
|
||||
|
||||
// Resource Section
|
||||
struct ResourceDirectoryTable {
|
||||
u32 characteristics;
|
||||
u32 timeDateStamp;
|
||||
u16 majorVersion;
|
||||
u16 minorVersion;
|
||||
u16 nameEntriesAmount;
|
||||
u16 idEntriesAmount;
|
||||
};
|
||||
|
||||
enum ResourceID : u32 {
|
||||
Bitmap = 0x02,
|
||||
Icon = 0x03,
|
||||
Menu = 0x04,
|
||||
Dialog = 0x05,
|
||||
String = 0x06,
|
||||
GroupIcon = 0x0D,
|
||||
Version = 0x10,
|
||||
Manifest = 0x18
|
||||
};
|
||||
|
||||
struct IdDirectoryEntry {
|
||||
ResourceID id;
|
||||
u32 relativeOffsetToData;
|
||||
};
|
||||
|
||||
struct ResourceDirectory {
|
||||
ResourceDirectoryTable resourceDirectoryTable;
|
||||
IdDirectoryEntry idEntries[resourceDirectoryTable.idEntriesAmount];
|
||||
};
|
||||
|
||||
struct ResourceSection {
|
||||
ResourceDirectory rootDirectory;
|
||||
};
|
||||
|
||||
// Exports Section
|
||||
struct ExportDirectoryTable {
|
||||
u32 exportFlags;
|
||||
u32 timeDateStamp;
|
||||
u16 majorVersion;
|
||||
u16 minorVersion;
|
||||
u32 nameRVA;
|
||||
u32 ordinalBase;
|
||||
u32 addressTableEntries;
|
||||
u32 numberOfNamePointers;
|
||||
u32 exportAddressTableRVA;
|
||||
u32 namePointerRVA;
|
||||
u32 ordinalTableRVA;
|
||||
};
|
||||
|
||||
struct ExportAddress {
|
||||
if (std::mem::read_unsigned($, 4) > sectionTable[currentSectionIndex].sizeOfRawData && std::mem::read_unsigned($, 4) < sectionTable[currentSectionIndex].ptrRawData) {
|
||||
u32 exportRVA;
|
||||
}
|
||||
else {
|
||||
u32 forwarderRVA;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExportsSection {
|
||||
ExportDirectoryTable exportDirectoryTable;
|
||||
ExportAddress exportAddressTable[exportDirectoryTable.addressTableEntries];
|
||||
u32 exportNamePointerTable[exportDirectoryTable.numberOfNamePointers];
|
||||
};
|
||||
|
||||
// Exception Section
|
||||
bitfield ExceptionSectionBits {
|
||||
functionLength : 22;
|
||||
instructions32Bit : 1;
|
||||
exceptionHandler : 1;
|
||||
} [[right_to_left]];
|
||||
|
||||
struct FunctionTableEntry {
|
||||
if (coffHeader.machine == MachineType::MIPSFPU) {
|
||||
u32 beginVA;
|
||||
u32 endVA;
|
||||
u32 exceptionHandlerPointer;
|
||||
u32 handlerDataPointer;
|
||||
u32 prologEndVA;
|
||||
} else if (coffHeader.machine == MachineType::ARM || MachineType::ARM64 || MachineType::ARMNT || MachineType::POWERPC || MachineType::POWERPCFP || MachineType::SH3 || MachineType::SH4) {
|
||||
u32 beginVA;
|
||||
u8 prologLength;
|
||||
ExceptionSectionBits miscellaneousBits;
|
||||
} else if (coffHeader.machine == MachineType::AMD64 || MachineType::IA64) {
|
||||
u32 beginRVA;
|
||||
u32 endRVA;
|
||||
u32 unwindInformationRVA;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExceptionSection {
|
||||
FunctionTableEntry functionTableEntries[while($ < sectionTable[currentSectionIndex].ptrRawData + sectionTable[currentSectionIndex].sizeOfRawData)];
|
||||
};
|
||||
|
||||
// TLS Section
|
||||
struct TLSSection {
|
||||
if (coffHeader.optionalHeader.magic == PEFormat::PE32) {
|
||||
u32 rawDataStartVA;
|
||||
u32 rawDataEndVA;
|
||||
u32 indexAddress;
|
||||
u32 callbacksAddress;
|
||||
}
|
||||
else if (coffHeader.optionalHeader.magic == PEFormat::PE32Plus) {
|
||||
u64 rawDataStartVA;
|
||||
u64 rawDataEndVA;
|
||||
u64 indexAddress;
|
||||
u64 callbacksAddress;
|
||||
}
|
||||
u32 zeroFillSize;
|
||||
u32 characteristics;
|
||||
};
|
||||
|
||||
struct PEHeader {
|
||||
DOSHeader dosHeader;
|
||||
DOSStub dosStub;
|
||||
// Relocations Section
|
||||
bitfield RelocationWord {
|
||||
type : 4;
|
||||
offset : 12;
|
||||
};
|
||||
|
||||
PEHeader peHeader @ 0x00;
|
||||
struct BaseRelocationBlock {
|
||||
u32 pageRVA;
|
||||
u32 blockSize;
|
||||
RelocationWord word;
|
||||
};
|
||||
|
||||
Section sectionsTable[peHeader.dosHeader.coffHeaderPointer.numberOfSections]
|
||||
@ addressof(peHeader.dosHeader.coffHeaderPointer) + sizeof(peHeader.dosHeader.coffHeaderPointer);
|
||||
struct BaseRelocationTable {
|
||||
BaseRelocationBlock baseRelocationBlocks[while(std::mem::read_unsigned($, 8) != 0x00)];
|
||||
};
|
||||
|
||||
// General Section things
|
||||
enum I386Relocations : u16 {
|
||||
Absolute = 0x00,
|
||||
Dir16 = 0x01,
|
||||
Rel16 = 0x02,
|
||||
Dir32 = 0x06
|
||||
};
|
||||
|
||||
struct Relocation {
|
||||
u32 virtualAddress;
|
||||
u32 symbolTableIndex;
|
||||
if (coffHeader.machine == MachineType::I386) {
|
||||
I386Relocations type;
|
||||
}
|
||||
else {
|
||||
u16 type;
|
||||
}
|
||||
};
|
||||
|
||||
struct LineNumber {
|
||||
u32 lineNumber @ $ + 4;
|
||||
if (lineNumber > 0x00) {
|
||||
u32 virtualAddress @ $ - 8;
|
||||
} else {
|
||||
u32 symbolTableIndex @ $ - 8;
|
||||
}
|
||||
$ += 8;
|
||||
};
|
||||
|
||||
fn importsSectionExists() {
|
||||
bool returnedValue = false;
|
||||
std::print("Checking which section is .idata for read-only data section");
|
||||
for (u16 i = 0, i < coffHeader.numberOfSections, i = i + 1) {
|
||||
std::print("Checking section " + std::string::to_string(i));
|
||||
if (sectionTable[i].name == ".idata") {
|
||||
std::print("Check successful. Section " + std::string::to_string(i) + " is .idata, so the read-only data section won't have an imports section in it");
|
||||
returnedValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!returnedValue) {
|
||||
std::print("Check failed! This means there is no separate imports section");
|
||||
}
|
||||
return returnedValue;
|
||||
};
|
||||
|
||||
struct Section {
|
||||
if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".pdata")) { // Exception section
|
||||
ExceptionSection exceptionSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".rdata")) {// Read-only data section
|
||||
if (importsSectionExists() || coffHeader.optionalHeader.directories[1].size == 0) {
|
||||
u8 readonlyDataSection[sectionTable[currentSectionIndex].sizeOfRawData];
|
||||
}
|
||||
else {
|
||||
ReadonlyDataSection readonlyDataSection;
|
||||
}
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".idata")) {// Imports section
|
||||
ImportsSection importsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".edata")) {// Exports section
|
||||
ExportsSection exportsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".rsrc")) { // Resource section
|
||||
ResourceSection resourceSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".tls")) { // Thread-local storage section
|
||||
TLSSection tlsSection;
|
||||
}
|
||||
else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".reloc")) {// Thread-local storage section
|
||||
BaseRelocationTable relocationsSection;
|
||||
}
|
||||
else {
|
||||
u8 freeformSection[sectionTable[currentSectionIndex].sizeOfRawData]; // Freeform data section
|
||||
}
|
||||
|
||||
// Additional things
|
||||
//Relocation relocations[sectionTable[currentSectionIndex].numberOfRelocations] @ sectionTable[currentSectionIndex].ptrRelocations;
|
||||
LineNumber lineNumbers[sectionTable[currentSectionIndex].numberOfLineNumbers] @ sectionTable[currentSectionIndex].ptrLineNumbers;
|
||||
|
||||
// Next section
|
||||
if (currentSectionIndex < coffHeader.numberOfSections-1) { // If it's not the last section (to avoid problems this code would have with it)
|
||||
updateSectionIndex(); // Make the current section index the next section's index
|
||||
if (sectionTable[currentSectionIndex].sizeOfRawData > 0) { // If the size of this section is bigger than 0
|
||||
$ = sectionTable[currentSectionIndex].ptrRawData; // Put the current offset at the start of the next section
|
||||
}
|
||||
}
|
||||
} [[inline]];
|
||||
|
||||
Section sections[coffHeader.numberOfSections] @ sectionTable[0].ptrRawData;
|
||||
|
||||
// Symbol & String Tables
|
||||
enum SectionNumberType : s16 {
|
||||
Undefined = 0,
|
||||
Absolute = -1,
|
||||
Debug = -2
|
||||
};
|
||||
|
||||
enum SymbolTypeMSB : u8 {
|
||||
Null = 0x00,
|
||||
Pointer = 0x10,
|
||||
Function = 0x20,
|
||||
Array = 0x30
|
||||
};
|
||||
|
||||
enum SymbolTypeLSB : u8 {
|
||||
Null = 0x00,
|
||||
Void = 0x01,
|
||||
Char = 0x02,
|
||||
Short = 0x03,
|
||||
Integer = 0x04,
|
||||
Long = 0x05,
|
||||
Float = 0x06,
|
||||
Double = 0x07,
|
||||
Struct = 0x08,
|
||||
Union = 0x09,
|
||||
Enum = 0x0A,
|
||||
MemberOfEnum = 0x0B,
|
||||
Byte = 0x0C,
|
||||
Word = 0x0D,
|
||||
UInt = 0x0E,
|
||||
DWord = 0x0F
|
||||
};
|
||||
|
||||
enum StorageClassType : s8 {
|
||||
EndOfFunction = -1,
|
||||
Null = 0,
|
||||
Automatic = 1,
|
||||
External = 2,
|
||||
Static = 3,
|
||||
Register = 4,
|
||||
DefinedExternally = 5,
|
||||
Label = 6,
|
||||
UndefinedLabel = 7,
|
||||
MemberOfStruct = 8,
|
||||
Argument = 9,
|
||||
StructTag = 10,
|
||||
MemberOfUnion = 11,
|
||||
UnionTag = 12,
|
||||
TypeDefinition = 13,
|
||||
UndefinedStatic = 14,
|
||||
EnumTag = 15,
|
||||
MemberOfEnum = 16,
|
||||
RegisterParameter = 17,
|
||||
Bitfield = 18,
|
||||
Block = 100,
|
||||
BlockFunction = 101,
|
||||
EndOfStruct = 102,
|
||||
File = 103,
|
||||
Section = 104,
|
||||
WeakExternal = 105,
|
||||
CLRToken = 107
|
||||
};
|
||||
|
||||
struct SymbolNameAddress {
|
||||
u32 zeroes;
|
||||
u32 offset;
|
||||
};
|
||||
|
||||
struct SymbolName {
|
||||
if (std::mem::read_unsigned($, 4) == 0) {
|
||||
SymbolNameAddress nameAddress;
|
||||
}
|
||||
else {
|
||||
char shortName[8];
|
||||
}
|
||||
};
|
||||
|
||||
struct SymbolType {
|
||||
SymbolTypeMSB msb;
|
||||
SymbolTypeLSB lsb;
|
||||
};
|
||||
|
||||
struct Symbol {
|
||||
SymbolName name;
|
||||
u32 value;
|
||||
SectionNumberType sectionNumber;
|
||||
SymbolType type;
|
||||
StorageClassType storageClass;
|
||||
u8 numberOfAuxSymbols;
|
||||
};
|
||||
|
||||
Symbol symbolTable[coffHeader.numberOfSymbols] @ coffHeader.pointerToSymbolTable;
|
||||
|
||||
struct StringTable {
|
||||
u32 size;
|
||||
NullTerminatedString strings[while($ < addressof(this) + size)];
|
||||
} [[inline]];
|
||||
|
||||
StringTable stringTable[coffHeader.numberOfSymbols > 0] @ addressof(symbolTable) + sizeof(symbolTable);
|
||||
|
||||
// Rich Header
|
||||
enum ProductType : u16 {
|
||||
Unmarked = 0x00 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
Imports = 0x01 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
STDLIBDLL = 0x04 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CVTRes = 0x06 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CCompiler = 0x0A ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC6CPPCompiler = 0x0B ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
OldNames = 0x0C ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
MASM613 = 0x0E ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003Assembler = 0x0F ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002Linker = 0x19 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002CCompiler = 0x1C ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2002CPPCompiler = 0x1D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003SDKIMP = 0x5D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2003CPPCompiler = 0x60 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2008SDKIMP = 0x93 ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
Linker12 = 0x9D ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
MASM10 = 0x9E ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2010CCompiler = 0xAA ^ richHeaderEnd[0].mask.maskArray[1],
|
||||
VC2010CPPCompiler = 0xAB ^ richHeaderEnd[0].mask.maskArray[1]
|
||||
};
|
||||
|
||||
union RichHeaderMask {
|
||||
u32 maskVariable;
|
||||
u16 maskArray[2];
|
||||
};
|
||||
|
||||
struct RichHeaderEnd {
|
||||
char signature[4];
|
||||
RichHeaderMask mask;
|
||||
} [[inline]];
|
||||
|
||||
u8 richHeaderAmount;
|
||||
u8 richHeaderEndPosition;
|
||||
u8 richHeaderCorpusPosition;
|
||||
fn initializeRichHeader() {
|
||||
$ = sizeof(peHeader);
|
||||
while ($ < peHeader.dosHeader.coffHeaderPointer) {
|
||||
if (std::mem::read_string($, 4) == "Rich") {
|
||||
richHeaderAmount = 1;
|
||||
richHeaderEndPosition = $;
|
||||
break;
|
||||
}
|
||||
$ += 1;
|
||||
}
|
||||
};
|
||||
initializeRichHeader();
|
||||
|
||||
RichHeaderEnd richHeaderEnd[richHeaderAmount] @ richHeaderEndPosition;
|
||||
|
||||
struct Product {
|
||||
u16 buildNumber;
|
||||
ProductType productID;
|
||||
u32 objectCount;
|
||||
};
|
||||
|
||||
struct RichHeaderCorpus {
|
||||
char maskedSignature[4];
|
||||
u32 nullPadding[3];
|
||||
Product products[while($ != richHeaderEndPosition)];
|
||||
} [[inline]];
|
||||
|
||||
fn setupRichHeader() {
|
||||
if (richHeaderAmount > 0) {
|
||||
//0x20 is the size of a Rich Header with one product
|
||||
for (u8 richCursor = $ - 0x20, richCursor > sizeof(peHeader), richCursor = richCursor - 0x01) {
|
||||
if (str(std::mem::read_unsigned(richCursor, 4) ^ richHeaderEnd[0].mask.maskVariable) == "DanS") {
|
||||
richHeaderCorpusPosition = richCursor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
setupRichHeader();
|
||||
|
||||
RichHeaderCorpus richHeaderCorpus[richHeaderAmount] @ richHeaderCorpusPosition;
|
||||
|
||||
66
patterns/protobuf.hexpat
Normal file
66
patterns/protobuf.hexpat
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <std/mem.pat>
|
||||
|
||||
#include <type/leb128.pat>
|
||||
|
||||
struct ZigZag32 {
|
||||
u32 value;
|
||||
} [[sealed, format("format_zigzag32")]];
|
||||
|
||||
fn format_zigzag32(ZigZag32 zigzag) {
|
||||
return s32((s32(zigzag.value) << 1) ^ (s32(zigzag.value) >> 31));
|
||||
};
|
||||
|
||||
struct ZigZag64 {
|
||||
u64 value;
|
||||
} [[sealed, format("format_zigzag64")]];
|
||||
|
||||
fn format_zigzag64(ZigZag64 zigzag) {
|
||||
return s64((s64(zigzag.value) << 1) ^ (s64(zigzag.value) >> 63));
|
||||
};
|
||||
|
||||
enum WireType : u8 {
|
||||
Varint = 0,
|
||||
_64Bit = 1,
|
||||
LengthDelimited = 2,
|
||||
StartGroup = 3,
|
||||
EndGroup = 4,
|
||||
_32Bit = 5
|
||||
};
|
||||
|
||||
bitfield Key {
|
||||
field_number : 5;
|
||||
wire_type : 3;
|
||||
} [[left_to_right]];
|
||||
|
||||
union _64Bit {
|
||||
u64 fixed64;
|
||||
ZigZag64 sfixed64;
|
||||
double dbl;
|
||||
};
|
||||
|
||||
union _32Bit {
|
||||
u32 fixed32;
|
||||
ZigZag32 sfixed32;
|
||||
float flt;
|
||||
};
|
||||
|
||||
struct LengthDelimited {
|
||||
type::LEB128 length;
|
||||
char data[length];
|
||||
};
|
||||
|
||||
|
||||
struct Entry {
|
||||
Key key;
|
||||
|
||||
if (key.wire_type == WireType::Varint)
|
||||
type::LEB128 value;
|
||||
else if (key.wire_type == WireType::_64Bit)
|
||||
_64Bit value;
|
||||
else if (key.wire_type == WireType::LengthDelimited)
|
||||
LengthDelimited value;
|
||||
else if (key.wire_type == WireType::_32Bit)
|
||||
_32Bit value;
|
||||
};
|
||||
|
||||
Entry entries[while(!std::mem::eof())] @ 0x00;
|
||||
38
patterns/stl.hexpat
Normal file
38
patterns/stl.hexpat
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma MIME model/stl
|
||||
#pragma MIME model/x.stl-binary
|
||||
#pragma MIME model/x.stl-ascii
|
||||
#pragma MIME application/sla
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
struct Vector3f {
|
||||
float x, y, z;
|
||||
} [[static, format("format_vector3f")]];
|
||||
|
||||
fn format_vector3f(Vector3f vec) {
|
||||
return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z);
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
Vector3f normal;
|
||||
Vector3f points[3];
|
||||
u16 flags;
|
||||
} [[static]];
|
||||
|
||||
struct BinarySTLHeader {
|
||||
char caption[];
|
||||
padding[80 - sizeof(caption)];
|
||||
u32 triangleCount;
|
||||
};
|
||||
|
||||
struct STL {
|
||||
if (std::mem::read_string(0, 6) == "solid ")
|
||||
std::warning("ASCII STL file!");
|
||||
else {
|
||||
BinarySTLHeader header;
|
||||
Triangle triangles[header.triangleCount];
|
||||
}
|
||||
};
|
||||
|
||||
STL stl @ 0x00;
|
||||
193
patterns/vhdx.hexpat
Normal file
193
patterns/vhdx.hexpat
Normal file
@@ -0,0 +1,193 @@
|
||||
#include <std/io.pat>
|
||||
#include <std/ptr.pat>
|
||||
#include <std/core.pat>
|
||||
|
||||
#include <type/guid.pat>
|
||||
#include <type/size.pat>
|
||||
|
||||
struct FileTypeIdentifier {
|
||||
char signature[8];
|
||||
char16 creator[256];
|
||||
padding[0x1'0000 - sizeof(signature) - sizeof(creator)];
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
u32 sequenceHigh;
|
||||
u8 data[4084];
|
||||
u32 sequenceLow;
|
||||
} [[static]];
|
||||
|
||||
struct ZeroDescriptor {
|
||||
padding[4];
|
||||
u64 zeroLength;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct DataDescriptor {
|
||||
u32 trailingBytes;
|
||||
u64 leadingBytes;
|
||||
DataSector *dataSector : u64;
|
||||
u64 sequenceNumber;
|
||||
} [[static]];
|
||||
|
||||
struct LogDescriptor {
|
||||
char signature[4];
|
||||
|
||||
if (signature == "zero")
|
||||
ZeroDescriptor descriptor [[inline]];
|
||||
else if (signature == "desc")
|
||||
DataDescriptor descriptor [[inline]];
|
||||
};
|
||||
|
||||
struct LogEntry {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
type::Size32 entryLength;
|
||||
u32 tail;
|
||||
u64 sequenceNumber;
|
||||
u32 descriptorCount;
|
||||
padding[4];
|
||||
type::GUID logGuid;
|
||||
u64 flushedFileOffset;
|
||||
u64 lastFileOffset;
|
||||
} [[static]];
|
||||
|
||||
bitfield BAT {
|
||||
State : 3;
|
||||
padding : 17;
|
||||
FileOffsetMB : 44;
|
||||
} [[right_to_left]];
|
||||
|
||||
bitfield MetadataEntryFlags {
|
||||
IsUser : 1;
|
||||
IsVirtualDisk : 1;
|
||||
IsRequired : 1;
|
||||
padding : 29;
|
||||
};
|
||||
|
||||
bitfield FileParameterFlags {
|
||||
LeaveBlockAllocated : 1;
|
||||
HasParent : 1;
|
||||
padding : 30;
|
||||
};
|
||||
|
||||
struct MetadataFileParameters {
|
||||
type::Size32 blockSize;
|
||||
FileParameterFlags flags;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskSize {
|
||||
type::Size64 virtualDiskSize;
|
||||
};
|
||||
|
||||
struct MetadataVirtualDiskID {
|
||||
type::GUID virtualDiskID;
|
||||
};
|
||||
|
||||
struct MetadataLogicalSectorSize {
|
||||
type::Size32 logicalSectorSize;
|
||||
};
|
||||
|
||||
struct MetadataPhysicalSectorSize {
|
||||
type::Size32 physicalSectorSize;
|
||||
};
|
||||
|
||||
struct ParentLocatorEntry {
|
||||
u32 keyOffset;
|
||||
u32 valueOffset;
|
||||
u16 keyLength;
|
||||
u16 valueLength;
|
||||
|
||||
char key[keyLength] @ addressof(parent) + keyOffset;
|
||||
char value[valueLength] @ addressof(parent) + valueOffset;
|
||||
};
|
||||
|
||||
struct MetadataParentLocator {
|
||||
type::GUID locatorType;
|
||||
padding[2];
|
||||
u16 keyValueCount;
|
||||
ParentLocatorEntry entries[keyValueCount];
|
||||
};
|
||||
|
||||
fn metadata_relative(u128 offset) {
|
||||
return addressof(parent.parent);
|
||||
};
|
||||
|
||||
struct MetadataTableEntry {
|
||||
type::GUID itemID;
|
||||
|
||||
if (std::core::formatted_value(itemID) == "{CAA16737-FA36-4D43-B3B6-33F0AA44E76B}")
|
||||
MetadataFileParameters *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}")
|
||||
MetadataVirtualDiskSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}")
|
||||
MetadataVirtualDiskID *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}")
|
||||
MetadataLogicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}")
|
||||
MetadataPhysicalSectorSize *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}")
|
||||
MetadataParentLocator *data : u32 [[pointer_base("metadata_relative")]];
|
||||
else
|
||||
u32 dataOffset;
|
||||
|
||||
type::Size32 length;
|
||||
MetadataEntryFlags flags;
|
||||
padding[4];
|
||||
};
|
||||
|
||||
struct MetadataRegion {
|
||||
char signature[8];
|
||||
padding[2];
|
||||
u16 entryCount;
|
||||
padding[20];
|
||||
MetadataTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct RegionTableEntry {
|
||||
type::GUID guid;
|
||||
|
||||
if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}")
|
||||
BAT *bat : u64;
|
||||
else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}")
|
||||
MetadataRegion *metadata : u64;
|
||||
else
|
||||
u64 fileOffset;
|
||||
|
||||
type::Size32 length;
|
||||
u32 required;
|
||||
};
|
||||
|
||||
struct RegionTable {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u32 entryCount;
|
||||
padding[4];
|
||||
|
||||
RegionTableEntry entries[entryCount];
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char signature[4];
|
||||
u32 checksum;
|
||||
u64 sequenceNumber;
|
||||
type::GUID fileWriteGuid, dataWriteGuid, logGuid;
|
||||
u16 logVersion;
|
||||
u16 version;
|
||||
type::Size32 logLength;
|
||||
LogEntry *log : u64;
|
||||
padding[4016];
|
||||
};
|
||||
|
||||
struct VHDX {
|
||||
FileTypeIdentifier fileTypeIdentifier;
|
||||
|
||||
Header header @ 0x1'0000;
|
||||
Header headerBackup @ 0x2'0000;
|
||||
|
||||
RegionTable regionTable @ 0x3'0000;
|
||||
RegionTable regionTableBackup @ 0x4'0000;
|
||||
};
|
||||
|
||||
VHDX vhdx @ 0x00;
|
||||
@@ -169,7 +169,7 @@ struct WaveListItem : WaveChunk {
|
||||
} else if (chunkId == "note") {
|
||||
WaveNote note;
|
||||
} else {
|
||||
padding[chunkSize];
|
||||
padding[(chunkSize + 1) >> 1 << 1];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,36 +181,48 @@ struct WaveList {
|
||||
WaveListItem item[while ($ < listEnd)];
|
||||
};
|
||||
|
||||
u32 paddedChunkSize;
|
||||
|
||||
struct WavData {
|
||||
WaveChunk chunk;
|
||||
paddedChunkSize = (chunk.chunkSize + 1) >> 1 << 1;
|
||||
|
||||
if (chunk.chunkId == "fmt ") {
|
||||
WaveFormat fmt;
|
||||
|
||||
if (fmt.formatTag == WaveFormatType::PCM) {
|
||||
WaveFormatPCM pcmExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(pcmExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MS_ADPCM) {
|
||||
WaveFormatMSADPCM msAdpcmExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(msAdpcmExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MPEG) {
|
||||
WaveFormatMPEG mpegExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(mpegExtraData)];
|
||||
} else if (fmt.formatTag == WaveFormatType::MPEGLAYER3) {
|
||||
WaveFormatMPEGLayer3 mpegLayer3ExtraData;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(mpegLayer3ExtraData)];
|
||||
} else {
|
||||
WaveFormatExDummy unknown;
|
||||
padding[paddedChunkSize - sizeof(fmt) - sizeof(unknown)];
|
||||
}
|
||||
} else if (chunk.chunkId == "data") {
|
||||
padding[chunk.chunkSize];
|
||||
padding[paddedChunkSize];
|
||||
} else if (chunk.chunkId == "fact") {
|
||||
WaveFact fact;
|
||||
padding[paddedChunkSize - sizeof(fact)];
|
||||
} else if (chunk.chunkId == "smpl") {
|
||||
WaveSample smpl;
|
||||
padding[paddedChunkSize - sizeof(smpl)];
|
||||
} else if (chunk.chunkId == "cue ") {
|
||||
WaveCue cue;
|
||||
padding[paddedChunkSize - sizeof(cue)];
|
||||
} else if (chunk.chunkId == "LIST") {
|
||||
listEnd = $ + chunk.chunkSize;
|
||||
WaveList list;
|
||||
padding[paddedChunkSize % 1];
|
||||
} else {
|
||||
padding[chunk.chunkSize];
|
||||
padding[paddedChunkSize];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
35
scripts/extract_legacy_hexproj.py
Normal file
35
scripts/extract_legacy_hexproj.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def extractData(projectName, jsonData, objectName, extension):
|
||||
if objectName in jsonData:
|
||||
with open(f"./{projectName}.{extension}", mode="w", encoding="utf-8") as output:
|
||||
output.write(jsonData[objectName])
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2 or not str(sys.argv[1]).endswith(".hexproj"):
|
||||
print(f"Usage: {sys.argv[0]} <filename.hexproj>")
|
||||
exit(1)
|
||||
|
||||
projectPath = sys.argv[1]
|
||||
with open(projectPath, mode="r", encoding="utf-8") as file:
|
||||
jsonData = json.loads(file.read())
|
||||
|
||||
projectName = Path(projectPath).stem
|
||||
|
||||
extractData(projectName, jsonData, "dataProcessor", "hexnode")
|
||||
extractData(projectName, jsonData, "pattern", "hexpat")
|
||||
|
||||
if "bookmarks" in jsonData:
|
||||
with open(f"./{projectName}.hexbm", mode="w", encoding="utf-8") as output:
|
||||
jsonOutput = {}
|
||||
jsonOutput["bookmarks"] = jsonData["bookmarks"]
|
||||
|
||||
output.write(json.dumps(jsonOutput, indent=4))
|
||||
|
||||
if "filePath" in jsonData:
|
||||
print(f"Project file used file {jsonData['filePath']}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,5 +1,8 @@
|
||||
#include <pl.hpp>
|
||||
#include <helpers/file.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
|
||||
#include <pl/core/errors/preprocessor_errors.hpp>
|
||||
#include <pl/core/errors/evaluator_errors.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
@@ -19,17 +22,20 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Running test {} on test file {}\n", includeName, includeFilePath.filename().string());
|
||||
|
||||
// Open pattern file
|
||||
pl::fs::File patternFile(includeFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File patternFile(includeFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!patternFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Setup Pattern Language Runtime
|
||||
pl::PatternLanguage runtime;
|
||||
{
|
||||
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){ pl::LogConsole::abortEvaluation("Include files should never use this pragma!"); return true; };
|
||||
constexpr auto DummyPragmaHandler = [](const auto&, const auto&){
|
||||
pl::core::err::M0006.throwError("Include files should never use this pragma!");
|
||||
return false;
|
||||
};
|
||||
|
||||
runtime.setDataSource([&](pl::u64 address, pl::u8 *data, size_t size) {
|
||||
pl::LogConsole::abortEvaluation("Include files should never read from memory directly!");
|
||||
pl::core::err::E0011.throwError("Include files should never read from memory directly!");
|
||||
}, 0x00, 0x100000);
|
||||
runtime.setDangerousFunctionCallHandler([]{ return true; });
|
||||
runtime.setIncludePaths({ includePath });
|
||||
@@ -47,14 +53,15 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Error during execution!\n");
|
||||
|
||||
if (const auto &hardError = runtime.getError(); hardError.has_value())
|
||||
fmt::print("Hard error: {}\n\n", hardError.value().what());
|
||||
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
|
||||
|
||||
for (const auto &[level, message] : runtime.getConsoleLog()) {
|
||||
switch (level) {
|
||||
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
|
||||
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
|
||||
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
|
||||
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
|
||||
using enum pl::core::LogConsole::Level;
|
||||
case Debug: fmt::print(" [DEBUG] "); break;
|
||||
case Info: fmt::print(" [INFO] "); break;
|
||||
case Warning: fmt::print(" [WARN] "); break;
|
||||
case Error: fmt::print(" [ERROR] "); break;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <helpers/file.hpp>
|
||||
#include <helpers/guards.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
#include <pl/helpers/guards.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <pl.hpp>
|
||||
#include <helpers/file.hpp>
|
||||
#include <pl/helpers/file.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cstdlib>
|
||||
@@ -27,12 +27,12 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Running test {} on test file {}\n", patternName, testFilePath.stem().string());
|
||||
|
||||
// Open pattern file
|
||||
pl::fs::File patternFile(patternFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File patternFile(patternFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!patternFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Open test file
|
||||
pl::fs::File testFile(testFilePath, pl::fs::File::Mode::Read);
|
||||
pl::hlp::fs::File testFile(testFilePath, pl::hlp::fs::File::Mode::Read);
|
||||
if (!testFile.isValid())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -55,14 +55,15 @@ int main(int argc, char **argv) {
|
||||
fmt::print("Error during execution!\n");
|
||||
|
||||
if (const auto &hardError = runtime.getError(); hardError.has_value())
|
||||
fmt::print("Hard error: {}\n\n", hardError.value().what());
|
||||
fmt::print("Hard error: {}:{} - {}\n\n", hardError->line, hardError->column, hardError->message);
|
||||
|
||||
for (const auto &[level, message] : runtime.getConsoleLog()) {
|
||||
switch (level) {
|
||||
case pl::LogConsole::Level::Debug: fmt::print(" [DEBUG] "); break;
|
||||
case pl::LogConsole::Level::Info: fmt::print(" [INFO] "); break;
|
||||
case pl::LogConsole::Level::Warning: fmt::print(" [WARN] "); break;
|
||||
case pl::LogConsole::Level::Error: fmt::print(" [ERROR] "); break;
|
||||
using enum pl::core::LogConsole::Level;
|
||||
case Debug: fmt::print(" [DEBUG] "); break;
|
||||
case Info: fmt::print(" [INFO] "); break;
|
||||
case Warning: fmt::print(" [WARN] "); break;
|
||||
case Error: fmt::print(" [ERROR] "); break;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", message);
|
||||
|
||||
BIN
tests/patterns/test_data/lnk.hexpat.lnk
Normal file
BIN
tests/patterns/test_data/lnk.hexpat.lnk
Normal file
Binary file not shown.
BIN
tests/patterns/test_data/ntag.hexpat.bin
Normal file
BIN
tests/patterns/test_data/ntag.hexpat.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user