git: Fixed line endings of all files

This commit is contained in:
WerWolv
2022-07-26 08:48:01 +02:00
committed by GitHub
parent 1a5d89c133
commit 9e4a1d1d96
17 changed files with 19976 additions and 27090 deletions

13
.gitattributes vendored
View File

@@ -1,3 +1,10 @@
*.pat linguist-language=Rust *.pat linguist-language=Rust
*.hexpat linguist-language=Rust *.hexpat linguist-language=Rust
* text eol=lf 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

View File

@@ -1,255 +1,255 @@
*0D0A *0D0A
00 00
01 01
02 02
03 03
04 04
05 05
06 06
07 07
0B 0B
0C 0C
0E 0E
0F 0F
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
1A 1A
1B 1B
1C 1C
1D 1D
1E 1E
1F 1F
7E 7E
7F 7F
80 80
81 81
82 82
83 83
84 84
85 85
86 86
87 87
88 88
89 89
8A 8A
8B 8B
8C 8C
8D 8D
8E 8E
8F 8F
90 90
93 93
94 94
95 95
96 96
97 97
98 98
99 99
9A 9A
9B 9B
9C 9C
9D 9D
9E 9E
B7 B7
08=BackSpace 08=BackSpace
09=\t 09=\t
20= 20=
21=! 21=!
22=" 22="
23=# 23=#
24=$ 24=$
25=% 25=%
26=& 26=&
27=' 27='
28=( 28=(
29=) 29=)
2A=* 2A=*
2B=+ 2B=+
2C=, 2C=,
2D=- 2D=-
2E=. 2E=.
2F=/ 2F=/
30=0 30=0
31=1 31=1
32=2 32=2
33=3 33=3
34=4 34=4
35=5 35=5
36=6 36=6
37=7 37=7
38=8 38=8
39=9 39=9
3A=: 3A=:
3B=; 3B=;
3C=< 3C=<
3D== 3D==
3E=> 3E=>
3F=? 3F=?
40=@ 40=@
41=A 41=A
42=B 42=B
43=C 43=C
44=D 44=D
45=E 45=E
46=F 46=F
47=G 47=G
48=H 48=H
49=I 49=I
4A=J 4A=J
4B=K 4B=K
4C=L 4C=L
4D=M 4D=M
4E=N 4E=N
4F=O 4F=O
50=P 50=P
51=Q 51=Q
52=R 52=R
53=S 53=S
54=T 54=T
55=U 55=U
56=V 56=V
57=W 57=W
58=X 58=X
59=Y 59=Y
5A=Z 5A=Z
5B=[ 5B=[
5C=\ 5C=\
5D=] 5D=]
5E=^ 5E=^
5F=_ 5F=_
60=` 60=`
61=a 61=a
62=b 62=b
63=c 63=c
64=d 64=d
65=e 65=e
66=f 66=f
67=g 67=g
68=h 68=h
69=i 69=i
6A=j 6A=j
6B=k 6B=k
6C=l 6C=l
6D=m 6D=m
6E=n 6E=n
6F=o 6F=o
70=p 70=p
71=q 71=q
72=r 72=r
73=s 73=s
74=t 74=t
75=u 75=u
76=v 76=v
77=w 77=w
78=x 78=x
79=y 79=y
7A=z 7A=z
7B={ 7B={
7C=| 7C=|
7D=} 7D=}
91=' 91='
92=' 92='
9F==<3D> 9F==<3D>
A0= A0=
A1=<3D> A1=<3D>
A2=<3D> A2=<3D>
A3=<3D> A3=<3D>
A4=<3D> A4=<3D>
A5=<3D> A5=<3D>
A6=<3D> A6=<3D>
A7=<3D> A7=<3D>
A8=<3D> A8=<3D>
A9=<3D> A9=<3D>
AA=<3D> AA=<3D>
AB=<3D> AB=<3D>
AC=<3D> AC=<3D>
AD=<3D> AD=<3D>
AE=<3D> AE=<3D>
AF=<3D> AF=<3D>
B0=<3D> B0=<3D>
B1=<3D> B1=<3D>
B2=<3D> B2=<3D>
B3=<3D> B3=<3D>
B4=<3D> B4=<3D>
B5=<3D> B5=<3D>
B6=<3D> B6=<3D>
B8=<3D> B8=<3D>
B9=<3D> B9=<3D>
BA=<3D> BA=<3D>
BB=<3D> BB=<3D>
BC=<3D> BC=<3D>
BD=<3D> BD=<3D>
BE=<3D> BE=<3D>
BF=<3D> BF=<3D>
C0=A C0=A
C1=<3D> C1=<3D>
C2=<3D> C2=<3D>
C3=<3D> C3=<3D>
C4=<3D> C4=<3D>
C5=<3D> C5=<3D>
C6=<3D> C6=<3D>
C7=<3D> C7=<3D>
C8=<3D> C8=<3D>
C9=<3D> C9=<3D>
CA=<3D> CA=<3D>
CB=<3D> CB=<3D>
CC=<3D> CC=<3D>
CD=<3D> CD=<3D>
CE=<3D> CE=<3D>
CF=<3D> CF=<3D>
D0=<3D> D0=<3D>
D1=<3D> D1=<3D>
D2=<3D> D2=<3D>
D3=<3D> D3=<3D>
D4=<3D> D4=<3D>
D5=<3D> D5=<3D>
D6=<3D> D6=<3D>
D7=<3D> D7=<3D>
D8=<3D> D8=<3D>
D9=<3D> D9=<3D>
DA=<3D> DA=<3D>
DB=<3D> DB=<3D>
DC=<3D> DC=<3D>
DD=<3D> DD=<3D>
DE=<3D> DE=<3D>
DF=<3D> DF=<3D>
E0=<3D> E0=<3D>
E1=<3D> E1=<3D>
E2=<3D> E2=<3D>
E3=<3D> E3=<3D>
E4=<3D> E4=<3D>
E5=<3D> E5=<3D>
E6=<3D> E6=<3D>
E7=<3D> E7=<3D>
E8=<3D> E8=<3D>
E9=<3D> E9=<3D>
EA=<3D> EA=<3D>
EB=<3D> EB=<3D>
EC=<3D> EC=<3D>
ED=<3D> ED=<3D>
EE=<3D> EE=<3D>
EF=<3D> EF=<3D>
F0=<3D> F0=<3D>
F1=<3D> F1=<3D>
F2=<3D> F2=<3D>
F3=<3D> F3=<3D>
F4=<3D> F4=<3D>
F5=<3D> F5=<3D>
F6=<3D> F6=<3D>
F7=<3D> F7=<3D>
F8=<3D> F8=<3D>
F9=<3D> F9=<3D>
FA=<3D> FA=<3D>
FB=<3D> FB=<3D>
FC=<3D> FC=<3D>
FD=<3D> FD=<3D>
FE=<3D> FE=<3D>
FF=<3D> FF=<3D>

View File

@@ -1,128 +1,128 @@
00=NUL 00=NUL
01=SOH 01=SOH
02=STX 02=STX
03=ETX 03=ETX
04=EOT 04=EOT
05=ENQ 05=ENQ
06=ACK 06=ACK
07=BEL 07=BEL
08=BS 08=BS
09=HT 09=HT
0A=LF 0A=LF
0B=VT 0B=VT
0C=FF 0C=FF
0D=CR 0D=CR
0E=SO 0E=SO
0F=SI 0F=SI
10=DLE 10=DLE
11=DC1 11=DC1
12=DC2 12=DC2
13=DC3 13=DC3
14=DC4 14=DC4
15=NAK 15=NAK
16=SYN 16=SYN
17=ETB 17=ETB
18=CAN 18=CAN
19=EM 19=EM
1A=SUB 1A=SUB
1B=ESC 1B=ESC
1C=FS 1C=FS
1D=GS 1D=GS
1E=RS 1E=RS
1F=US 1F=US
20=SP 20=SP
21=! 21=!
22=" 22="
23= 23=
24= 24=
25=% 25=%
26=& 26=&
27=' 27='
28=( 28=(
29=) 29=)
2A=* 2A=*
2B=+ 2B=+
2C=, 2C=,
2D=- 2D=-
2E=. 2E=.
2F=/ 2F=/
30=0 30=0
31=1 31=1
32=2 32=2
33=3 33=3
34=4 34=4
35=5 35=5
36=6 36=6
37=7 37=7
38=8 38=8
39=9 39=9
3A=: 3A=:
3B=; 3B=;
3C=< 3C=<
3D== 3D==
3E=> 3E=>
3F=? 3F=?
40= 40=
41=A 41=A
42=B 42=B
43=C 43=C
44=D 44=D
45=E 45=E
46=F 46=F
47=G 47=G
48=H 48=H
49=I 49=I
4A=J 4A=J
4B=K 4B=K
4C=L 4C=L
4D=M 4D=M
4E=N 4E=N
4F=O 4F=O
50=P 50=P
51=Q 51=Q
52=R 52=R
53=S 53=S
54=T 54=T
55=U 55=U
56=V 56=V
57=W 57=W
58=X 58=X
59=Y 59=Y
5A=Z 5A=Z
5B= 5B=
5C= 5C=
5D= 5D=
5E= 5E=
5F=_ 5F=_
60= 60=
61=a 61=a
62=b 62=b
63=c 63=c
64=d 64=d
65=e 65=e
66=f 66=f
67=g 67=g
68=h 68=h
69=i 69=i
6A=j 6A=j
6B=k 6B=k
6C=l 6C=l
6D=m 6D=m
6E=n 6E=n
6F=o 6F=o
70=p 70=p
71=q 71=q
72=r 72=r
73=s 73=s
74=t 74=t
75=u 75=u
76=v 76=v
77=w 77=w
78=x 78=x
79=y 79=y
7A=z 7A=z
7B= 7B=
7C= 7C=
7D= 7D=
7E= 7E=
7F=DEL 7F=DEL

View File

@@ -1,158 +1,158 @@
20= 20=
21=! 21=!
22=" 22="
23=# 23=#
24=$ 24=$
25=% 25=%
26=& 26=&
27=' 27='
28=( 28=(
29=) 29=)
2A=* 2A=*
2B=+ 2B=+
2C=, 2C=,
2D=- 2D=-
2E=. 2E=.
2F=/ 2F=/
30=0 30=0
31=1 31=1
32=2 32=2
33=3 33=3
34=4 34=4
35=5 35=5
36=6 36=6
37=7 37=7
38=8 38=8
39=9 39=9
3A=: 3A=:
3B=; 3B=;
3C=< 3C=<
3D== 3D==
3E=> 3E=>
3F=? 3F=?
40=@ 40=@
41=A 41=A
42=B 42=B
43=C 43=C
44=D 44=D
45=E 45=E
46=F 46=F
47=G 47=G
48=H 48=H
49=I 49=I
4A=J 4A=J
4B=K 4B=K
4C=L 4C=L
4D=M 4D=M
4E=N 4E=N
4F=O 4F=O
50=P 50=P
51=Q 51=Q
52=R 52=R
53=S 53=S
54=T 54=T
55=U 55=U
56=V 56=V
57=W 57=W
58=X 58=X
59=Y 59=Y
5A=Z 5A=Z
5B=[ 5B=[
5C=¥ 5C=¥
5D=] 5D=]
5E=^ 5E=^
5F=_ 5F=_
60=` 60=`
61=a 61=a
62=b 62=b
63=c 63=c
64=d 64=d
65=e 65=e
66=f 66=f
67=g 67=g
68=h 68=h
69=i 69=i
6A=j 6A=j
6B=k 6B=k
6C=l 6C=l
6D=m 6D=m
6E=n 6E=n
6F=o 6F=o
70=p 70=p
71=q 71=q
72=r 72=r
73=s 73=s
74=t 74=t
75=u 75=u
76=v 76=v
77=w 77=w
78=x 78=x
79=y 79=y
7A=z 7A=z
7B={ 7B={
7C=| 7C=|
7D=} 7D=}
7E=‾ 7E=‾
A1=。 A1=。
A2=「 A2=「
A3=」 A3=」
A4=、 A4=、
A5=・ A5=・
A6=ヲ A6=ヲ
A7=ァ A7=ァ
A8=ィ A8=ィ
A9=ゥ A9=ゥ
AA=ェ AA=ェ
AB=ォ AB=ォ
AC=ャ AC=ャ
AD=ュ AD=ュ
AE=ョ AE=ョ
AF=ッ AF=ッ
B0=ー B0=ー
B1=ア B1=ア
B2=イ B2=イ
B3=ウ B3=ウ
B4=エ B4=エ
B5=オ B5=オ
B6=カ B6=カ
B7=キ B7=キ
B8=ク B8=ク
B9=ケ B9=ケ
BA=コ BA=コ
BB=サ BB=サ
BC=シ BC=シ
BD=ス BD=ス
BE=セ BE=セ
BF=ソ BF=ソ
C0=タ C0=タ
C1=チ C1=チ
C2=ツ C2=ツ
C3=テ C3=テ
C4=ト C4=ト
C5=ナ C5=ナ
C6=ニ C6=ニ
C7=ヌ C7=ヌ
C8=ネ C8=ネ
C9=ノ C9=ノ
CA=ハ CA=ハ
CB=ヒ CB=ヒ
CC=フ CC=フ
CD=ヘ CD=ヘ
CE=ホ CE=ホ
CF=マ CF=マ
D0=ミ D0=ミ
D1=ム D1=ム
D2=メ D2=メ
D3=モ D3=モ
D4=ヤ D4=ヤ
D5=ユ D5=ユ
D6=ヨ D6=ヨ
D7=ラ D7=ラ
D8=リ D8=リ
D9=ル D9=ル
DA=レ DA=レ
DB=ロ DB=ロ
DC=ワ DC=ワ
DD=ン DD=ン
DE=゙ DE=゙
DF=゚ DF=゚

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,57 +1,57 @@
#pragma endian little #pragma endian little
#include <std/io.pat> #include <std/io.pat>
#include <std/mem.pat> #include <std/mem.pat>
#define VTOR 0x00000000 #define VTOR 0x00000000
#define EXTERNAL_INTERRUPT_COUNT 64 #define EXTERNAL_INTERRUPT_COUNT 64
using Address = u32; using Address = u32;
struct Exceptions { struct Exceptions {
Address reset [[name("Reset Handler")]]; Address reset [[name("Reset Handler")]];
Address nmi [[name("Non-maskable Interrupt Handler")]]; Address nmi [[name("Non-maskable Interrupt Handler")]];
Address hard_fault [[name("HardFault Handler")]]; Address hard_fault [[name("HardFault Handler")]];
Address mem_manage [[name("Memory Protection Error Handler")]]; Address mem_manage [[name("Memory Protection Error Handler")]];
Address bus_fault [[name("Bus Fault Handler")]]; Address bus_fault [[name("Bus Fault Handler")]];
Address usage_fault [[name("UsageFault (Instruction Execution fault) Handler")]]; Address usage_fault [[name("UsageFault (Instruction Execution fault) Handler")]];
Address reserved_1[4] [[hidden]]; Address reserved_1[4] [[hidden]];
Address sv_call [[name("Synchronous Supervisor Call (SVC Instruction) Handler")]]; Address sv_call [[name("Synchronous Supervisor Call (SVC Instruction) Handler")]];
Address debug_monitor [[name("Synchronous Debug Event Handler")]]; Address debug_monitor [[name("Synchronous Debug Event Handler")]];
Address reserved_2[1] [[hidden]]; Address reserved_2[1] [[hidden]];
Address pend_sv [[name("Asynchronous Supervisor Call Handler")]]; Address pend_sv [[name("Asynchronous Supervisor Call Handler")]];
Address sys_tick [[name("System Timer Tick Handler")]]; Address sys_tick [[name("System Timer Tick Handler")]];
}; };
struct ExternalInterrupts { struct ExternalInterrupts {
Address external_interrupt[EXTERNAL_INTERRUPT_COUNT] [[inline]]; Address external_interrupt[EXTERNAL_INTERRUPT_COUNT] [[inline]];
}; };
struct VectorTable { struct VectorTable {
Address initial_sp [[name("Initial Stack Pointer Value")]]; Address initial_sp [[name("Initial Stack Pointer Value")]];
Exceptions exceptions [[inline, name("Exceptions")]]; Exceptions exceptions [[inline, name("Exceptions")]];
ExternalInterrupts external_interrupts [[name("External Interrupts")]]; ExternalInterrupts external_interrupts [[name("External Interrupts")]];
}; };
VectorTable vector_table @ VTOR; VectorTable vector_table @ VTOR;
fn main() { fn main() {
u32 table_size = sizeof(vector_table); u32 table_size = sizeof(vector_table);
u32 default_handler_address = 0x00; u32 default_handler_address = 0x00;
for (u32 i = 4, i < table_size, i = i + 4) { for (u32 i = 4, i < table_size, i = i + 4) {
u32 occurrences = 0; u32 occurrences = 0;
for (u32 j = 4, j < table_size, j = j + 4) { for (u32 j = 4, j < table_size, j = j + 4) {
if (std::mem::read_unsigned(i, 4) == std::mem::read_unsigned(j, 4)) { if (std::mem::read_unsigned(i, 4) == std::mem::read_unsigned(j, 4)) {
occurrences = occurrences + 1; occurrences = occurrences + 1;
if (occurrences > 1) if (occurrences > 1)
default_handler_address = std::mem::read_unsigned(i, 4); default_handler_address = std::mem::read_unsigned(i, 4);
} }
} }
} }
if (default_handler_address != 0x00) if (default_handler_address != 0x00)
std::print("Default Handler implementation at 0x{:08X}", default_handler_address); std::print("Default Handler implementation at 0x{:08X}", default_handler_address);
}; };

View File

@@ -1,47 +1,47 @@
#pragma endian little #pragma endian little
#include <std/sys.pat> #include <std/sys.pat>
#pragma MIME image/vnd.microsoft.icon #pragma MIME image/vnd.microsoft.icon
#pragma MIME image/x-icon #pragma MIME image/x-icon
#pragma MIME image/icon #pragma MIME image/icon
#pragma MIME image/ico #pragma MIME image/ico
#pragma MIME text/ico #pragma MIME text/ico
#pragma MIME application/ico #pragma MIME application/ico
enum ImageType : u16 { enum ImageType : u16 {
Icon = 1, Icon = 1,
Cursor = 2 Cursor = 2
}; };
struct ICONDIR { struct ICONDIR {
u16 reserved [[hidden]]; u16 reserved [[hidden]];
ImageType type; ImageType type;
u16 num_images; u16 num_images;
}; };
struct ImageData { struct ImageData {
u8 data[parent.image_data_size] [[inline]]; u8 data[parent.image_data_size] [[inline]];
}; };
struct ICONDIRENTRY { struct ICONDIRENTRY {
u8 width, height; u8 width, height;
u8 num_colors; u8 num_colors;
u8 reserved [[hidden]]; u8 reserved [[hidden]];
if (header.type == ImageType::Icon) { if (header.type == ImageType::Icon) {
u16 color_planes; u16 color_planes;
u16 bits_per_pixel; u16 bits_per_pixel;
} else if (header.type == ImageType::Cursor) { } else if (header.type == ImageType::Cursor) {
u16 horizontal_hotspot_coordinate; u16 horizontal_hotspot_coordinate;
u16 vertical_hotspot_coordinate; u16 vertical_hotspot_coordinate;
} }
u32 image_data_size; u32 image_data_size;
ImageData *image_data : u32; ImageData *image_data : u32;
}; };
ICONDIR header @ 0x00; ICONDIR header @ 0x00;
ICONDIRENTRY images[header.num_images] @ $; ICONDIRENTRY images[header.num_images] @ $;
std::assert(header.reserved == 0x00, "Invalid ICO header"); std::assert(header.reserved == 0x00, "Invalid ICO header");

View File

@@ -1,270 +1,270 @@
#pragma endian big #pragma endian big
#pragma bitfield_order left_to_right #pragma bitfield_order left_to_right
#include <std/sys.pat> #include <std/sys.pat>
#include <std/io.pat> #include <std/io.pat>
struct MAC { struct MAC {
u8 octets[6]; u8 octets[6];
} [[format("mac_formatter")]]; } [[format("mac_formatter")]];
fn mac_formatter(MAC mac) { fn mac_formatter(MAC mac) {
return std::format("{0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}", return std::format("{0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}",
mac.octets[0], mac.octets[0],
mac.octets[1], mac.octets[1],
mac.octets[2], mac.octets[2],
mac.octets[3], mac.octets[3],
mac.octets[4], mac.octets[4],
mac.octets[5]); mac.octets[5]);
}; };
enum EtherType : u16 { enum EtherType : u16 {
IPv4 = 0x0800, IPv4 = 0x0800,
ARP = 0x0806, ARP = 0x0806,
WakeOnLAN = 0x0842, WakeOnLAN = 0x0842,
AVTP = 0x22F0, AVTP = 0x22F0,
IETF_TRILL = 0x22F3, IETF_TRILL = 0x22F3,
SRP = 0x22EA, SRP = 0x22EA,
DEC_MOP_RC = 0x6002, DEC_MOP_RC = 0x6002,
DECnet = 0x6003, DECnet = 0x6003,
DEC_LAT = 0x6004, DEC_LAT = 0x6004,
RARP = 0x8035, RARP = 0x8035,
AppleTalk = 0x809B, AppleTalk = 0x809B,
AppleTalk_AARP = 0x80F3, AppleTalk_AARP = 0x80F3,
VLANTaggedFrame = 0x8100, VLANTaggedFrame = 0x8100,
SLPP = 0x8102, SLPP = 0x8102,
VLACP = 0x8103, VLACP = 0x8103,
IPX = 0x8137, IPX = 0x8137,
QNX_Qnet = 0x8204, QNX_Qnet = 0x8204,
IPv6 = 0x860D, IPv6 = 0x860D,
EthernetFlowControl = 0x8808, EthernetFlowControl = 0x8808,
EthernetSlowProtocols = 0x8809, EthernetSlowProtocols = 0x8809,
CobraNet = 0x8819, CobraNet = 0x8819,
MPLS_Unicast = 0x8847, MPLS_Unicast = 0x8847,
MPLS_Multicast = 0x8848, MPLS_Multicast = 0x8848,
PPPoE_Discovery = 0x8863, PPPoE_Discovery = 0x8863,
PPPoE_Session = 0x8864, PPPoE_Session = 0x8864,
HomePlug = 0x887B, HomePlug = 0x887B,
EAPOverLAN = 0x888E, EAPOverLAN = 0x888E,
PROFINET = 0x8892, PROFINET = 0x8892,
HyperSCSI = 0x889A, HyperSCSI = 0x889A,
ATAOverEthernet = 0x88A2, ATAOverEthernet = 0x88A2,
EtherCAT = 0x88A4, EtherCAT = 0x88A4,
ServiceVLANTagIdentifier = 0x88A8, ServiceVLANTagIdentifier = 0x88A8,
EthernetPowerlink = 0x88AB, EthernetPowerlink = 0x88AB,
GOOSE = 0x88B8, GOOSE = 0x88B8,
GSE = 0x88B9, GSE = 0x88B9,
SV = 0x88BA, SV = 0x88BA,
MikroTik_RoMON = 0x88BF, MikroTik_RoMON = 0x88BF,
LLDP = 0x88CC, LLDP = 0x88CC,
SERCOS_III = 0x88CD, SERCOS_III = 0x88CD,
HomePlugGreenPHY = 0x88E1, HomePlugGreenPHY = 0x88E1,
MRP = 0x88E3, MRP = 0x88E3,
IEEE802_1AE = 0x88E5, IEEE802_1AE = 0x88E5,
PBB = 0x88E7, PBB = 0x88E7,
PTP = 0x88F7, PTP = 0x88F7,
NC_SI = 0x88F8, NC_SI = 0x88F8,
PRP = 0x88FB, PRP = 0x88FB,
CFM = 0x8902, CFM = 0x8902,
FCoE = 0x8906, FCoE = 0x8906,
FCoEIP = 0x8914, FCoEIP = 0x8914,
RoCE = 0x8915, RoCE = 0x8915,
TTE = 0x891D, TTE = 0x891D,
IEEE_1905_1 = 0x893A, IEEE_1905_1 = 0x893A,
HSR = 0x892F, HSR = 0x892F,
ECTP = 0x9000, ECTP = 0x9000,
RedundancyTag = 0xF1C1 RedundancyTag = 0xF1C1
}; };
namespace ip { namespace ip {
enum Protocol : u8 { enum Protocol : u8 {
ICMP = 1, ICMP = 1,
IGMP = 2, IGMP = 2,
TCP = 6, TCP = 6,
UDP = 17, UDP = 17,
ENCAP = 41, ENCAP = 41,
OSPF = 89, OSPF = 89,
SCTP = 132 SCTP = 132
}; };
namespace udp { namespace udp {
struct Packet { struct Packet {
u16 source_port; u16 source_port;
u16 destination_port; u16 destination_port;
u16 length; u16 length;
std::assert(length >= 8, "UDP Packet has invalid length"); std::assert(length >= 8, "UDP Packet has invalid length");
u16 checksum; u16 checksum;
u8 data[length - 8]; u8 data[length - 8];
}; };
} }
namespace tcp { namespace tcp {
bitfield Flags { bitfield Flags {
data_offset : 4; data_offset : 4;
padding : 3; padding : 3;
ns : 1; ns : 1;
cwr : 1; cwr : 1;
ece : 1; ece : 1;
urg : 1; urg : 1;
ack : 1; ack : 1;
psh : 1; psh : 1;
rst : 1; rst : 1;
syn : 1; syn : 1;
fin : 1; fin : 1;
}; };
struct Packet { struct Packet {
u16 source_port; u16 source_port;
u16 destination_port; u16 destination_port;
u32 sequence_number; u32 sequence_number;
u32 ack_number; u32 ack_number;
Flags flags [[inline]]; Flags flags [[inline]];
u16 window_size; u16 window_size;
u16 checksum; u16 checksum;
u16 urgent_pointer; u16 urgent_pointer;
if (flags.data_offset > 5) if (flags.data_offset > 5)
u8 options[(flags.data_offset - 5) * sizeof(u32)]; u8 options[(flags.data_offset - 5) * sizeof(u32)];
u8 data[parent.parent.header.total_length - 40]; u8 data[parent.parent.header.total_length - 40];
}; };
} }
struct Payload { struct Payload {
if (parent.protocol == ip::Protocol::UDP) if (parent.protocol == ip::Protocol::UDP)
udp::Packet packet [[inline]]; udp::Packet packet [[inline]];
else if (parent.protocol == ip::Protocol::TCP) else if (parent.protocol == ip::Protocol::TCP)
tcp::Packet packet [[inline]]; tcp::Packet packet [[inline]];
else else
std::error(std::format("Unknown protocol: {}", parent.protocol)); std::error(std::format("Unknown protocol: {}", parent.protocol));
}; };
} }
namespace ipv4 { namespace ipv4 {
struct Address { struct Address {
u8 octets[4]; u8 octets[4];
} [[format("ipv4::address_formatter")]]; } [[format("ipv4::address_formatter")]];
fn address_formatter(Address addr) { fn address_formatter(Address addr) {
return std::format("{0}.{1}.{2}.{3}", return std::format("{0}.{1}.{2}.{3}",
addr.octets[0], addr.octets[0],
addr.octets[1], addr.octets[1],
addr.octets[2], addr.octets[2],
addr.octets[3]); addr.octets[3]);
}; };
bitfield Header { bitfield Header {
version : 4; version : 4;
ihl : 4; ihl : 4;
tos : 8; tos : 8;
total_length : 16; total_length : 16;
}; };
bitfield Flags { bitfield Flags {
reserved : 1; reserved : 1;
df : 1; df : 1;
mf : 1; mf : 1;
fragment_offset : 13; fragment_offset : 13;
}; };
struct Packet { struct Packet {
Header header [[inline]]; Header header [[inline]];
u16 identification; u16 identification;
Flags flags [[inline]]; Flags flags [[inline]];
u8 time_to_live; u8 time_to_live;
ip::Protocol protocol; ip::Protocol protocol;
u16 header_checksum; u16 header_checksum;
Address source_ip_address; Address source_ip_address;
Address destination_ip_address; Address destination_ip_address;
if (header.ihl > 5) if (header.ihl > 5)
u8 options[(header.ihl - 5) * sizeof(u32)]; u8 options[(header.ihl - 5) * sizeof(u32)];
ip::Payload payload; ip::Payload payload;
}; };
} }
namespace ipv6 { namespace ipv6 {
struct Address { struct Address {
u16 segments[8]; u16 segments[8];
} [[format("ipv6::address_formatter")]]; } [[format("ipv6::address_formatter")]];
fn address_formatter(Address addr) { fn address_formatter(Address addr) {
return std::format("{0:04X}:{1:04X}:{2:04X}:{3:04X}:{4:04X}:{5:04X}:{6:04X}:{7:04X}", return std::format("{0:04X}:{1:04X}:{2:04X}:{3:04X}:{4:04X}:{5:04X}:{6:04X}:{7:04X}",
addr.segments[0], addr.segments[0],
addr.segments[1], addr.segments[1],
addr.segments[2], addr.segments[2],
addr.segments[3], addr.segments[3],
addr.segments[4], addr.segments[4],
addr.segments[5], addr.segments[5],
addr.segments[6], addr.segments[6],
addr.segments[7]); addr.segments[7]);
}; };
bitfield Header { bitfield Header {
version : 4; version : 4;
ds : 6; ds : 6;
ecn : 2; ecn : 2;
flow_label : 20; flow_label : 20;
}; };
struct Packet { struct Packet {
Header header [[inline]]; Header header [[inline]];
u16 payload_length; u16 payload_length;
ip::Protocol next_header; ip::Protocol next_header;
u8 hop_limit; u8 hop_limit;
Address source_address; Address source_address;
Address destination_address; Address destination_address;
ip::Payload payload; ip::Payload payload;
}; };
} }
struct Payload { struct Payload {
if (parent.type == EtherType::IPv4) if (parent.type == EtherType::IPv4)
ipv4::Packet packet [[inline]]; ipv4::Packet packet [[inline]];
else else
std::error(std::format("Unknown payload type: 0x{:04X}", parent.type)); std::error(std::format("Unknown payload type: 0x{:04X}", parent.type));
}; };
bitfield TCI { bitfield TCI {
pcp : 3; pcp : 3;
dei : 1; dei : 1;
vid : 12; vid : 12;
}; };
struct EthernetIIFrame { struct EthernetIIFrame {
MAC destination_address; MAC destination_address;
MAC source_address; MAC source_address;
u16 possible_tpid [[no_unique_address, hidden]]; u16 possible_tpid [[no_unique_address, hidden]];
if (possible_tpid == EtherType::VLANTaggedFrame) { if (possible_tpid == EtherType::VLANTaggedFrame) {
u16 tpid; u16 tpid;
TCI tci [[inline]]; TCI tci [[inline]];
} }
EtherType type; EtherType type;
Payload payload; Payload payload;
std::assert(sizeof(payload) >= 40 && sizeof(payload) <= 1500, std::format("Payload size out of range: {}", sizeof(payload))); std::assert(sizeof(payload) >= 40 && sizeof(payload) <= 1500, std::format("Payload size out of range: {}", sizeof(payload)));
u32 frame_check_sequence; u32 frame_check_sequence;
}; };
EthernetIIFrame frame @ 0x00; EthernetIIFrame frame @ 0x00;

View File

@@ -1,342 +1,342 @@
#pragma endian big #pragma endian big
#pragma MIME application/x-java-applet #pragma MIME application/x-java-applet
#include <std/io.pat> #include <std/io.pat>
#include <std/sys.pat> #include <std/sys.pat>
// The Java documentations use the number of bytes instead of the number of bits for its type names // The Java documentations use the number of bytes instead of the number of bits for its type names
using u1 = u8; using u1 = u8;
using u2 = u16; using u2 = u16;
using u4 = u32; using u4 = u32;
using f4 = float; using f4 = float;
using f8 = double; using f8 = double;
enum cp_tag : u8 { enum cp_tag : u8 {
CONSTANT_Utf8 = 1, CONSTANT_Utf8 = 1,
CONSTANT_Integer = 3, CONSTANT_Integer = 3,
CONSTANT_Float = 4, CONSTANT_Float = 4,
CONSTANT_Long = 5, CONSTANT_Long = 5,
CONSTANT_Double = 6, CONSTANT_Double = 6,
CONSTANT_Class = 7, CONSTANT_Class = 7,
CONSTANT_String = 8, CONSTANT_String = 8,
CONSTANT_Fieldref = 9, CONSTANT_Fieldref = 9,
CONSTANT_Methodref = 10, CONSTANT_Methodref = 10,
CONSTANT_InterfaceMethodref = 11, CONSTANT_InterfaceMethodref = 11,
CONSTANT_NameAndType = 12, CONSTANT_NameAndType = 12,
CONSTANT_MethodHandle = 15, CONSTANT_MethodHandle = 15,
CONSTANT_MethodType = 16, CONSTANT_MethodType = 16,
CONSTANT_InvokeDynamic = 18 CONSTANT_InvokeDynamic = 18
}; };
enum major_version : u2 { enum major_version : u2 {
JDK_1_1 = 45, JDK_1_1 = 45,
JDK_1_2 = 46, JDK_1_2 = 46,
JDK_1_3 = 47, JDK_1_3 = 47,
JDK_1_4 = 48, JDK_1_4 = 48,
Java_SE_5_0 = 49, Java_SE_5_0 = 49,
Java_SE_6_0 = 50, Java_SE_6_0 = 50,
Java_SE_7 = 51, Java_SE_7 = 51,
Java_SE_8 = 52, Java_SE_8 = 52,
Java_SE_9 = 53, Java_SE_9 = 53,
Java_SE_10 = 54, Java_SE_10 = 54,
Java_SE_11 = 55, Java_SE_11 = 55,
Java_SE_12 = 56, Java_SE_12 = 56,
Java_SE_13 = 57, Java_SE_13 = 57,
Java_SE_14 = 58, Java_SE_14 = 58,
Java_SE_15 = 59, Java_SE_15 = 59,
Java_SE_16 = 60, Java_SE_16 = 60,
Java_SE_17 = 61, Java_SE_17 = 61,
}; };
// Tag == CONSTANT_Utf8 // Tag == CONSTANT_Utf8
struct CONSTANT_Utf8_info { struct CONSTANT_Utf8_info {
u2 length; u2 length;
char bytes[length]; // u1 in documentation. Changed to char to improve readability char bytes[length]; // u1 in documentation. Changed to char to improve readability
}; };
// Tag == CONSTANT_Integer // Tag == CONSTANT_Integer
struct CONSTANT_Integer_info { struct CONSTANT_Integer_info {
u4 bytes; u4 bytes;
}; };
// Tag == CONSTANT_Float // Tag == CONSTANT_Float
struct CONSTANT_Float_info { struct CONSTANT_Float_info {
f4 bytes; // u4 in documentation. Changed to f4 to improve readablilty f4 bytes; // u4 in documentation. Changed to f4 to improve readablilty
}; };
// Tag == CONSTANT_Long // Tag == CONSTANT_Long
struct CONSTANT_Long_info { struct CONSTANT_Long_info {
u4 high_bytes; u4 high_bytes;
u4 low_bytes; u4 low_bytes;
}; };
// Tag == CONSTANT_Double // Tag == CONSTANT_Double
struct CONSTANT_Double_info { struct CONSTANT_Double_info {
u4 high_bytes; u4 high_bytes;
u4 low_bytes; u4 low_bytes;
}; };
// Tag == CONSTANT_Class // Tag == CONSTANT_Class
struct CONSTANT_Class_info { struct CONSTANT_Class_info {
u2 name_index; u2 name_index;
}; };
// Tag == CONSTANT_String // Tag == CONSTANT_String
struct CONSTANT_String_info { struct CONSTANT_String_info {
u2 string_index; u2 string_index;
}; };
// Tag == CONSTANT_Fieldref // Tag == CONSTANT_Fieldref
struct CONSTANT_Fieldref_info { struct CONSTANT_Fieldref_info {
u2 class_index; u2 class_index;
u2 name_and_type_index; u2 name_and_type_index;
}; };
// Tag == CONSTANT_Methodref // Tag == CONSTANT_Methodref
struct CONSTANT_Methodref_info { struct CONSTANT_Methodref_info {
u2 class_index; u2 class_index;
u2 name_and_type_index; u2 name_and_type_index;
}; };
// Tag == CONSTANT_InterfaceMethodref // Tag == CONSTANT_InterfaceMethodref
struct CONSTANT_InterfaceMethodref_info { struct CONSTANT_InterfaceMethodref_info {
u2 class_index; u2 class_index;
u2 name_and_type_index; u2 name_and_type_index;
}; };
// Tag == CONSTANT_NameAndType // Tag == CONSTANT_NameAndType
struct CONSTANT_NameAndType_info { struct CONSTANT_NameAndType_info {
u2 name_index; u2 name_index;
u2 descriptor_index; u2 descriptor_index;
}; };
// Tag == CONSTANT_MethodHandle // Tag == CONSTANT_MethodHandle
struct CONSTANT_MethodHandle_info { struct CONSTANT_MethodHandle_info {
u1 reference_kind; u1 reference_kind;
u2 reference_index; u2 reference_index;
}; };
// Tag == CONSTANT_MethodType // Tag == CONSTANT_MethodType
struct CONSTANT_MethodType_info { struct CONSTANT_MethodType_info {
u2 descriptor_index; u2 descriptor_index;
}; };
// Tag == CONSTANT_InvokeDynamic // Tag == CONSTANT_InvokeDynamic
struct CONSTANT_InvokeDynamic_info { struct CONSTANT_InvokeDynamic_info {
u2 bootstrap_method_attr_index; u2 bootstrap_method_attr_index;
u2 name_and_type_index; u2 name_and_type_index;
}; };
struct cp_info { struct cp_info {
cp_tag tag; cp_tag tag;
if (tag == cp_tag::CONSTANT_Utf8) if (tag == cp_tag::CONSTANT_Utf8)
CONSTANT_Utf8_info info [[inline]]; CONSTANT_Utf8_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Integer) else if (tag == cp_tag::CONSTANT_Integer)
CONSTANT_Integer_info info [[inline]]; CONSTANT_Integer_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Float) else if (tag == cp_tag::CONSTANT_Float)
CONSTANT_Float_info info [[inline]]; CONSTANT_Float_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Long) else if (tag == cp_tag::CONSTANT_Long)
CONSTANT_Long_info info [[inline]]; CONSTANT_Long_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Double) else if (tag == cp_tag::CONSTANT_Double)
CONSTANT_Double_info info [[inline]]; CONSTANT_Double_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Class) else if (tag == cp_tag::CONSTANT_Class)
CONSTANT_Class_info info [[inline]]; CONSTANT_Class_info info [[inline]];
else if (tag == cp_tag::CONSTANT_String) else if (tag == cp_tag::CONSTANT_String)
CONSTANT_String_info info [[inline]]; CONSTANT_String_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Fieldref) else if (tag == cp_tag::CONSTANT_Fieldref)
CONSTANT_Fieldref_info info [[inline]]; CONSTANT_Fieldref_info info [[inline]];
else if (tag == cp_tag::CONSTANT_Methodref) else if (tag == cp_tag::CONSTANT_Methodref)
CONSTANT_Methodref_info info [[inline]]; CONSTANT_Methodref_info info [[inline]];
else if (tag == cp_tag::CONSTANT_InterfaceMethodref) else if (tag == cp_tag::CONSTANT_InterfaceMethodref)
CONSTANT_InterfaceMethodref_info info [[inline]]; CONSTANT_InterfaceMethodref_info info [[inline]];
else if (tag == cp_tag::CONSTANT_NameAndType) else if (tag == cp_tag::CONSTANT_NameAndType)
CONSTANT_NameAndType_info info [[inline]]; CONSTANT_NameAndType_info info [[inline]];
else if (tag == cp_tag::CONSTANT_MethodHandle) else if (tag == cp_tag::CONSTANT_MethodHandle)
CONSTANT_MethodHandle_info info [[inline]]; CONSTANT_MethodHandle_info info [[inline]];
else if (tag == cp_tag::CONSTANT_MethodType) else if (tag == cp_tag::CONSTANT_MethodType)
CONSTANT_MethodType_info info [[inline]]; CONSTANT_MethodType_info info [[inline]];
else if (tag == cp_tag::CONSTANT_InvokeDynamic) else if (tag == cp_tag::CONSTANT_InvokeDynamic)
CONSTANT_InvokeDynamic_info info [[inline]]; CONSTANT_InvokeDynamic_info info [[inline]];
}; };
bitfield access_flags_method { bitfield access_flags_method {
ACC_PUBLIC : 1; // 0x0001 ACC_PUBLIC : 1; // 0x0001
ACC_PRIVATE : 1; // 0x0002 ACC_PRIVATE : 1; // 0x0002
ACC_PROTECTED : 1; // 0x0004 ACC_PROTECTED : 1; // 0x0004
ACC_STATIC : 1; // 0x0008 ACC_STATIC : 1; // 0x0008
ACC_FINAL : 1; // 0x0010 ACC_FINAL : 1; // 0x0010
ACC_SYNCHRONIZED: 1; // 0x0020 ACC_SYNCHRONIZED: 1; // 0x0020
ACC_BRIDGE : 1; // 0x0040 ACC_BRIDGE : 1; // 0x0040
ACC_VARARGS : 1; // 0x0080 ACC_VARARGS : 1; // 0x0080
ACC_NATIVE : 1; // 0x0100 ACC_NATIVE : 1; // 0x0100
padding : 1; // 0x0200 padding : 1; // 0x0200
ACC_ABSTRACT : 1; // 0x0400 ACC_ABSTRACT : 1; // 0x0400
ACC_STRICT : 1; // 0x0800 ACC_STRICT : 1; // 0x0800
ACC_SYNTHETIC : 1; // 0x1000 ACC_SYNTHETIC : 1; // 0x1000
padding : 1; // 0x2000 padding : 1; // 0x2000
padding : 1; // 0x4000 padding : 1; // 0x4000
padding : 1; // 0x8000 padding : 1; // 0x8000
}; };
bitfield access_flags_field { bitfield access_flags_field {
ACC_PUBLIC : 1; // 0x0001 ACC_PUBLIC : 1; // 0x0001
ACC_PRIVATE : 1; // 0x0002 ACC_PRIVATE : 1; // 0x0002
ACC_PROTECTED : 1; // 0x0004 ACC_PROTECTED : 1; // 0x0004
ACC_STATIC : 1; // 0x0008 ACC_STATIC : 1; // 0x0008
ACC_FINAL : 1; // 0x0010 ACC_FINAL : 1; // 0x0010
padding : 1; // 0x0020 padding : 1; // 0x0020
ACC_VOLATILE : 1; // 0x0040 ACC_VOLATILE : 1; // 0x0040
ACC_TRANSIENT : 1; // 0x0080 ACC_TRANSIENT : 1; // 0x0080
padding : 1; // 0x0100 padding : 1; // 0x0100
padding : 1; // 0x0200 padding : 1; // 0x0200
padding : 1; // 0x0400 padding : 1; // 0x0400
padding : 1; // 0x0800 padding : 1; // 0x0800
ACC_SYNTHETIC : 1; // 0x1000 ACC_SYNTHETIC : 1; // 0x1000
padding : 1; // 0x2000 padding : 1; // 0x2000
ACC_ENUM : 1; // 0x4000 ACC_ENUM : 1; // 0x4000
padding : 1; // 0x8000 padding : 1; // 0x8000
}; };
bitfield access_flags_class { bitfield access_flags_class {
ACC_PUBLIC : 1; // 0x0001 ACC_PUBLIC : 1; // 0x0001
padding : 1; // 0x0002 padding : 1; // 0x0002
padding : 1; // 0x0004 padding : 1; // 0x0004
padding : 1; // 0x0008 padding : 1; // 0x0008
ACC_FINAL : 1; // 0x0010 ACC_FINAL : 1; // 0x0010
ACC_SUPER : 1; // 0x0020 ACC_SUPER : 1; // 0x0020
padding : 1; // 0x0040 padding : 1; // 0x0040
padding : 1; // 0x0080 padding : 1; // 0x0080
padding : 1; // 0x0100 padding : 1; // 0x0100
ACC_INTERFACE : 1; // 0x0200 ACC_INTERFACE : 1; // 0x0200
ACC_ABSTRACT : 1; // 0x0400 ACC_ABSTRACT : 1; // 0x0400
padding : 1; // 0x0800 padding : 1; // 0x0800
ACC_SYNTHETIC : 1; // 0x1000 ACC_SYNTHETIC : 1; // 0x1000
ACC_ANNOTATION : 1; // 0x2000 ACC_ANNOTATION : 1; // 0x2000
ACC_ENUM : 1; // 0x4000 ACC_ENUM : 1; // 0x4000
padding : 1; // 0x8000 padding : 1; // 0x8000
}; };
struct attribute_info { struct attribute_info {
u2 attribute_name_info; u2 attribute_name_info;
u4 attribute_length; u4 attribute_length;
u1 info[attribute_length]; u1 info[attribute_length];
}; };
struct field_info { struct field_info {
access_flags_field access_flags; access_flags_field access_flags;
u2 name_index; u2 name_index;
u2 descriptor_index; u2 descriptor_index;
u2 attribute_count; u2 attribute_count;
attribute_info attributes[attribute_count]; attribute_info attributes[attribute_count];
}; };
struct method_info { struct method_info {
access_flags_method access_flags; access_flags_method access_flags;
u2 name_index; u2 name_index;
u2 descriptor_index; u2 descriptor_index;
u2 attributes_count; u2 attributes_count;
attribute_info attributes[attributes_count]; attribute_info attributes[attributes_count];
}; };
struct ClassFile { struct ClassFile {
u4 magic; u4 magic;
u2 minor_version; u2 minor_version;
major_version major_version; major_version major_version;
u2 constant_pool_count; u2 constant_pool_count;
cp_info constant_pool[constant_pool_count - 1]; cp_info constant_pool[constant_pool_count - 1];
access_flags_class access_flags; access_flags_class access_flags;
u2 this_class; u2 this_class;
u2 super_class; u2 super_class;
u2 interfaces_count; u2 interfaces_count;
u2 interfaces[interfaces_count]; u2 interfaces[interfaces_count];
u2 fields_count; u2 fields_count;
field_info fields[fields_count]; field_info fields[fields_count];
u2 methods_count; u2 methods_count;
method_info methods[methods_count]; method_info methods[methods_count];
u2 attribute_count; u2 attribute_count;
attribute_info attributes[attribute_count]; attribute_info attributes[attribute_count];
}; };
ClassFile class_file @ 0x00; ClassFile class_file @ 0x00;
fn main() { fn main() {
std::assert(class_file.magic == 0xCAFEBABE, "File is not a valid Java Class file! Invalid header magic"); std::assert(class_file.magic == 0xCAFEBABE, "File is not a valid Java Class file! Invalid header magic");
std::print("Fields:"); std::print("Fields:");
for (le u16 i = 0, i < class_file.fields_count, i = i + 1) { for (le u16 i = 0, i < class_file.fields_count, i = i + 1) {
str method_string = " "; str method_string = " ";
if (class_file.fields[i].access_flags.ACC_PUBLIC) if (class_file.fields[i].access_flags.ACC_PUBLIC)
method_string = method_string + "public "; method_string = method_string + "public ";
if (class_file.fields[i].access_flags.ACC_PRIVATE) if (class_file.fields[i].access_flags.ACC_PRIVATE)
method_string = method_string + "private "; method_string = method_string + "private ";
if (class_file.fields[i].access_flags.ACC_PROTECTED) if (class_file.fields[i].access_flags.ACC_PROTECTED)
method_string = method_string + "protected "; method_string = method_string + "protected ";
if (class_file.fields[i].access_flags.ACC_STATIC) if (class_file.fields[i].access_flags.ACC_STATIC)
method_string = method_string + "static "; method_string = method_string + "static ";
if (class_file.fields[i].access_flags.ACC_FINAL) if (class_file.fields[i].access_flags.ACC_FINAL)
method_string = method_string + "final "; method_string = method_string + "final ";
if (class_file.fields[i].access_flags.ACC_VOLATILE) if (class_file.fields[i].access_flags.ACC_VOLATILE)
method_string = method_string + "volatile "; method_string = method_string + "volatile ";
if (class_file.fields[i].access_flags.ACC_NATIVE) if (class_file.fields[i].access_flags.ACC_NATIVE)
method_string = method_string + "native "; method_string = method_string + "native ";
if (class_file.fields[i].access_flags.ACC_TRANSIENT) if (class_file.fields[i].access_flags.ACC_TRANSIENT)
method_string = method_string + "transient "; method_string = method_string + "transient ";
if (class_file.fields[i].access_flags.ACC_ENUM) if (class_file.fields[i].access_flags.ACC_ENUM)
method_string = method_string + "enum "; method_string = method_string + "enum ";
method_string = method_string + class_file.constant_pool[class_file.fields[i].name_index - 1].info.bytes; method_string = method_string + class_file.constant_pool[class_file.fields[i].name_index - 1].info.bytes;
method_string = method_string + " [ " + class_file.constant_pool[class_file.fields[i].descriptor_index - 1].info.bytes + " ]"; method_string = method_string + " [ " + class_file.constant_pool[class_file.fields[i].descriptor_index - 1].info.bytes + " ]";
std::print("{}", method_string); std::print("{}", method_string);
} }
std::print("Methods:"); std::print("Methods:");
for (le u16 i = 0, i < class_file.methods_count, i = i + 1) { for (le u16 i = 0, i < class_file.methods_count, i = i + 1) {
str method_string = " "; str method_string = " ";
if (class_file.methods[i].access_flags.ACC_PUBLIC) if (class_file.methods[i].access_flags.ACC_PUBLIC)
method_string = method_string + "public "; method_string = method_string + "public ";
if (class_file.methods[i].access_flags.ACC_PRIVATE) if (class_file.methods[i].access_flags.ACC_PRIVATE)
method_string = method_string + "private "; method_string = method_string + "private ";
if (class_file.methods[i].access_flags.ACC_PROTECTED) if (class_file.methods[i].access_flags.ACC_PROTECTED)
method_string = method_string + "protected "; method_string = method_string + "protected ";
if (class_file.methods[i].access_flags.ACC_STATIC) if (class_file.methods[i].access_flags.ACC_STATIC)
method_string = method_string + "static "; method_string = method_string + "static ";
if (class_file.methods[i].access_flags.ACC_FINAL) if (class_file.methods[i].access_flags.ACC_FINAL)
method_string = method_string + "final "; method_string = method_string + "final ";
if (class_file.methods[i].access_flags.ACC_SYNCHRONIZED) if (class_file.methods[i].access_flags.ACC_SYNCHRONIZED)
method_string = method_string + "synchronized "; method_string = method_string + "synchronized ";
if (class_file.methods[i].access_flags.ACC_NATIVE) if (class_file.methods[i].access_flags.ACC_NATIVE)
method_string = method_string + "native "; method_string = method_string + "native ";
if (class_file.methods[i].access_flags.ACC_ABSTRACT) if (class_file.methods[i].access_flags.ACC_ABSTRACT)
method_string = method_string + "abstract "; method_string = method_string + "abstract ";
if (class_file.methods[i].access_flags.ACC_STRICT) if (class_file.methods[i].access_flags.ACC_STRICT)
method_string = method_string + "strictfp "; method_string = method_string + "strictfp ";
method_string = method_string + class_file.constant_pool[class_file.methods[i].name_index - 1].info.bytes; method_string = method_string + class_file.constant_pool[class_file.methods[i].name_index - 1].info.bytes;
method_string = method_string + " [ " + class_file.constant_pool[class_file.methods[i].descriptor_index - 1].info.bytes + " ]"; method_string = method_string + " [ " + class_file.constant_pool[class_file.methods[i].descriptor_index - 1].info.bytes + " ]";
std::print("{}", method_string); std::print("{}", method_string);
} }
std::print("Class Attributes:"); std::print("Class Attributes:");
for (le u16 i = 0, i < class_file.attribute_count, i = i + 1) { for (le u16 i = 0, i < class_file.attribute_count, i = i + 1) {
std::print(" {}", class_file.constant_pool[class_file.attributes[i].attribute_name_info - 1].info.bytes); std::print(" {}", class_file.constant_pool[class_file.attributes[i].attribute_name_info - 1].info.bytes);
} }
}; };

View File

@@ -1,205 +1,205 @@
enum Model : u16 { enum Model : u16 {
NX = 1 NX = 1
}; };
struct WlanCountryCode { struct WlanCountryCode {
char code[3]; char code[3];
} [[static]]; } [[static]];
struct Cert { struct Cert {
u8 DeviceKey[0x30]; u8 DeviceKey[0x30];
padding[0x10]; padding[0x10];
u8 DeviceCertificate[0x180]; u8 DeviceCertificate[0x180];
padding[0x10]; padding[0x10];
} [[static]]; } [[static]];
enum RegionCode : u32 { enum RegionCode : u32 {
JPN = 0, JPN = 0,
USA = 1, USA = 1,
EUR = 2, EUR = 2,
AUS = 3, AUS = 3,
CHN = 4, CHN = 4,
KOR = 5, KOR = 5,
HKG = 6 HKG = 6
}; };
enum ProductModel : u32 { enum ProductModel : u32 {
Invalid = 0, Invalid = 0,
NX = 1, NX = 1,
Copper = 2, Copper = 2,
Iowa = 3, Iowa = 3,
Hoag = 4, Hoag = 4,
Calcio = 5, Calcio = 5,
Aula = 6 Aula = 6
}; };
struct PRODINFO { struct PRODINFO {
char MagicNumber[4]; char MagicNumber[4];
u32 Version; u32 Version;
u32 BodySize; u32 BodySize;
Model Model; Model Model;
u16 UpdateCount; u16 UpdateCount;
padding[0x10]; padding[0x10];
u8 BodyHash[0x20]; u8 BodyHash[0x20];
char ConfigurationId1[0x1E]; char ConfigurationId1[0x1E];
padding[0x02]; padding[0x02];
padding[0x20]; padding[0x20];
u32 WlanCountryCodesNum; u32 WlanCountryCodesNum;
u32 WlanCountryCodesLastIndex; u32 WlanCountryCodesLastIndex;
WlanCountryCode WlanCountryCodes[WlanCountryCodesNum]; WlanCountryCode WlanCountryCodes[WlanCountryCodesNum];
padding[0x180 - sizeof(WlanCountryCodes)]; padding[0x180 - sizeof(WlanCountryCodes)];
padding[0x08]; padding[0x08];
u8 WlanMacAddress[6]; u8 WlanMacAddress[6];
padding[0x10 - 6]; padding[0x10 - 6];
u8 BdAddress[6]; u8 BdAddress[6];
padding[0x10 - 6]; padding[0x10 - 6];
u8 AccelerometerOffset[6]; u8 AccelerometerOffset[6];
padding[2]; padding[2];
u8 AccelerometerScale[6]; u8 AccelerometerScale[6];
padding[2]; padding[2];
u8 GyroscopeOffset[6]; u8 GyroscopeOffset[6];
padding[2]; padding[2];
u8 GyroscopeScale[6]; u8 GyroscopeScale[6];
padding[2]; padding[2];
char SerialNumber[0x18]; char SerialNumber[0x18];
padding[8]; padding[8];
Cert EccP256Certificate; Cert EccP256Certificate;
Cert EccB233Certificate; Cert EccB233Certificate;
Cert Ecc256ETicket; Cert Ecc256ETicket;
Cert Ecc233ETicket; Cert Ecc233ETicket;
u8 SslKey[0x110]; u8 SslKey[0x110];
padding[0x10]; padding[0x10];
u32 SslCertificateSize; u32 SslCertificateSize;
padding[0x0C]; padding[0x0C];
u8 SslCertificate[0x800]; u8 SslCertificate[0x800];
u8 SslCertificateHash[0x20]; u8 SslCertificateHash[0x20];
u8 RandomNumber[0x1000]; u8 RandomNumber[0x1000];
u8 RandomNumberHash[0x20]; u8 RandomNumberHash[0x20];
u8 GameCardKey[0x110]; u8 GameCardKey[0x110];
u8 GameCardCertificate[0x400]; u8 GameCardCertificate[0x400];
padding[0x10]; padding[0x10];
u8 GameCardCertificateHash[0x20]; u8 GameCardCertificateHash[0x20];
u8 Rsa2048ETicketKey[0x220]; u8 Rsa2048ETicketKey[0x220];
padding[0x10]; padding[0x10];
u8 Rsa2048ETicketCertificate[0x240]; u8 Rsa2048ETicketCertificate[0x240];
padding[0x10]; padding[0x10];
char BatteryLot[0x18]; char BatteryLot[0x18];
padding[0x08]; padding[0x08];
u8 SpeakerCalibrationValue[0x800]; u8 SpeakerCalibrationValue[0x800];
padding[0x10]; padding[0x10];
RegionCode RegionCode; RegionCode RegionCode;
padding[0x0C]; padding[0x0C];
u8 AmiiboKey[0x50]; u8 AmiiboKey[0x50];
padding[0x10]; padding[0x10];
u8 AmiiboEcqvCertificate[0x14]; u8 AmiiboEcqvCertificate[0x14];
padding[0x0C]; padding[0x0C];
u8 AmiiboEcdsaCertificate[0x70]; u8 AmiiboEcdsaCertificate[0x70];
padding[0x10]; padding[0x10];
u8 AmiiboEcqvBlsKey[0x40]; u8 AmiiboEcqvBlsKey[0x40];
padding[0x10]; padding[0x10];
u8 AmiiboEcqvBlsCertificate[0x20]; u8 AmiiboEcqvBlsCertificate[0x20];
padding[0x10]; padding[0x10];
u8 AmiiboEcqvBlsRootCertificate[0x90]; u8 AmiiboEcqvBlsRootCertificate[0x90];
padding[0x10]; padding[0x10];
ProductModel ProductModel; ProductModel ProductModel;
padding[0x0C]; padding[0x0C];
u8 ColorVariation[6]; u8 ColorVariation[6];
padding[0x0A]; padding[0x0A];
u8 LcdBacklightBrightnessMapping[0x0C]; u8 LcdBacklightBrightnessMapping[0x0C];
padding[0x04]; padding[0x04];
u8 ExtendedEccB233DeviceKey[0x50]; u8 ExtendedEccB233DeviceKey[0x50];
padding[0x10]; padding[0x10];
u8 ExtendedEccP256ETicketKey[0x50]; u8 ExtendedEccP256ETicketKey[0x50];
padding[0x10]; padding[0x10];
u8 ExtendedEccB233ETicketKey[0x50]; u8 ExtendedEccB233ETicketKey[0x50];
padding[0x10]; padding[0x10];
u8 ExtendedRsa2048ETicketKey[0x240]; u8 ExtendedRsa2048ETicketKey[0x240];
padding[0x10]; padding[0x10];
u8 ExtendedSslKey[0x130]; u8 ExtendedSslKey[0x130];
padding[0x10]; padding[0x10];
u8 ExtendedGameCardKey[0x130]; u8 ExtendedGameCardKey[0x130];
padding[0x10]; padding[0x10];
u32 LcdVendorId; u32 LcdVendorId;
padding[0x0C]; padding[0x0C];
u8 ExtendedRsa2048DeviceKey[0x240]; u8 ExtendedRsa2048DeviceKey[0x240];
padding[0x10]; padding[0x10];
u8 Rsa2048DeviceCertificate[0x240]; u8 Rsa2048DeviceCertificate[0x240];
padding[0x10]; padding[0x10];
u8 UsbTypeCPowerSourceCircuitVersion; u8 UsbTypeCPowerSourceCircuitVersion;
padding[0x0F]; padding[0x0F];
u32 HousingSubColor; u32 HousingSubColor;
padding[0x0C]; padding[0x0C];
u32 HousingBezelColor; u32 HousingBezelColor;
padding[0x0C]; padding[0x0C];
u32 HousingMainColor1; u32 HousingMainColor1;
padding[0x0C]; padding[0x0C];
u32 HousingMainColor2; u32 HousingMainColor2;
padding[0x0C]; padding[0x0C];
u32 HousingMainColor3; u32 HousingMainColor3;
padding[0x0C]; padding[0x0C];
u8 AnalogStickModuleTypeL; u8 AnalogStickModuleTypeL;
padding[0x0F]; padding[0x0F];
u8 AnalogStickModelParameterL[0x12]; u8 AnalogStickModelParameterL[0x12];
padding[0x0E]; padding[0x0E];
u8 AnalogStickFactoryCalibrationL[0x09]; u8 AnalogStickFactoryCalibrationL[0x09];
padding[0x07]; padding[0x07];
u8 AnalogStickModuleTypeR; u8 AnalogStickModuleTypeR;
padding[0x0F]; padding[0x0F];
u8 AnalogStickModelParameterR[0x12]; u8 AnalogStickModelParameterR[0x12];
padding[0x0E]; padding[0x0E];
u8 AnalogStickFactoryCalibrationR[0x09]; u8 AnalogStickFactoryCalibrationR[0x09];
padding[0x07]; padding[0x07];
u8 ConsoleSixAxisSensorModuleType; u8 ConsoleSixAxisSensorModuleType;
padding[0x0F]; padding[0x0F];
u8 ConsoleSixAxisSensorHorizontalOffset[6]; u8 ConsoleSixAxisSensorHorizontalOffset[6];
padding[0x0A]; padding[0x0A];
u8 BatteryVersion; u8 BatteryVersion;
padding[0x0F]; padding[0x0F];
u8 TouchIcVendorId; u8 TouchIcVendorId;
padding[0x0F]; padding[0x0F];
u32 ColorModel; u32 ColorModel;
padding[0x0C]; padding[0x0C];
u8 ConsoleSixAxisSensorMountType; u8 ConsoleSixAxisSensorMountType;
}; };
PRODINFO PRODINFO @ 0x00; PRODINFO PRODINFO @ 0x00;

View File

@@ -1,98 +1,98 @@
#include <std/sys.pat> #include <std/sys.pat>
#include <std/mem.pat> #include <std/mem.pat>
#pragma MIME application/microformats+json #pragma MIME application/microformats+json
#pragma MIME application/microformats2+json #pragma MIME application/microformats2+json
#pragma MIME application/mf2+json #pragma MIME application/mf2+json
#pragma MIME application/uf2+json #pragma MIME application/uf2+json
#pragma pattern_limit 100000 #pragma pattern_limit 100000
bitfield UF2_Flags { bitfield UF2_Flags {
NotMainFlash : 1; NotMainFlash : 1;
padding : 11; padding : 11;
FileContainer : 1; FileContainer : 1;
FamilyIDPresent : 1; FamilyIDPresent : 1;
MD5ChecksumPresent : 1; MD5ChecksumPresent : 1;
ExtensionTagsPresent : 1; ExtensionTagsPresent : 1;
padding : 16; padding : 16;
}; };
struct UF2_Hash { struct UF2_Hash {
u32 startAddress; u32 startAddress;
u32 size; u32 size;
u8 md5Checksum[16]; u8 md5Checksum[16];
} [[static]]; } [[static]];
struct UF2_TagType { struct UF2_TagType {
u8 bytes[3]; u8 bytes[3];
} [[format("formatTagType")]]; } [[format("formatTagType")]];
enum UF2_TagTypeEnum : u32 { enum UF2_TagTypeEnum : u32 {
FirmwareFileVersion = 0x9FC7BC, FirmwareFileVersion = 0x9FC7BC,
DeviceDescription = 0x650D9D, DeviceDescription = 0x650D9D,
TargetPageSize = 0x0BE9F7, TargetPageSize = 0x0BE9F7,
SHA1Checksum = 0xB46DB0, SHA1Checksum = 0xB46DB0,
DeviceTypeIdentifier = 0xC8A729 DeviceTypeIdentifier = 0xC8A729
}; };
fn formatTagType(UF2_TagType type) { fn formatTagType(UF2_TagType type) {
u32 value = (type.bytes[0] << 16) | (type.bytes[1] << 8) | (type.bytes[2]); u32 value = (type.bytes[0] << 16) | (type.bytes[1] << 8) | (type.bytes[2]);
if (value == UF2_TagTypeEnum::FirmwareFileVersion) if (value == UF2_TagTypeEnum::FirmwareFileVersion)
return "Firmware File Version"; return "Firmware File Version";
else if (value == UF2_TagTypeEnum::DeviceDescription) else if (value == UF2_TagTypeEnum::DeviceDescription)
return "Device Description"; return "Device Description";
else if (value == UF2_TagTypeEnum::TargetPageSize) else if (value == UF2_TagTypeEnum::TargetPageSize)
return "Target Page Size"; return "Target Page Size";
else if (value == UF2_TagTypeEnum::SHA1Checksum) else if (value == UF2_TagTypeEnum::SHA1Checksum)
return "SHA1 Checksum"; return "SHA1 Checksum";
else if (value == UF2_TagTypeEnum::DeviceTypeIdentifier) else if (value == UF2_TagTypeEnum::DeviceTypeIdentifier)
return "Device Type Identifier"; return "Device Type Identifier";
else else
return "Custom Type"; return "Custom Type";
}; };
struct UF2_ExtensionTag { struct UF2_ExtensionTag {
u8 size; u8 size;
UF2_TagType type; UF2_TagType type;
u8 data[size - 4]; u8 data[size - 4];
if (size == 0 && type.bytes[0] == 0x00 && type.bytes[1] == 0x00 && type.bytes[2] == 0x00) if (size == 0 && type.bytes[0] == 0x00 && type.bytes[1] == 0x00 && type.bytes[2] == 0x00)
break; break;
}; };
struct UF2_Block { struct UF2_Block {
char magicStart0[4]; char magicStart0[4];
u32 magicStart1; u32 magicStart1;
UF2_Flags flags; UF2_Flags flags;
u32 targetAddr; u32 targetAddr;
u32 payloadSize; u32 payloadSize;
u32 blockNo; u32 blockNo;
u32 numBlocks; u32 numBlocks;
if (flags.FamilyIDPresent) if (flags.FamilyIDPresent)
u32 familyId; u32 familyId;
else else
u32 fileSize; u32 fileSize;
if (flags.MD5ChecksumPresent) { if (flags.MD5ChecksumPresent) {
u8 data[452]; u8 data[452];
UF2_Hash hash; UF2_Hash hash;
} }
else { else {
u8 data[476]; u8 data[476];
} }
if (flags.ExtensionTagsPresent) { if (flags.ExtensionTagsPresent) {
UF2_ExtensionTag extensionTags[0xFF]; UF2_ExtensionTag extensionTags[0xFF];
} }
u32 magicEnd; u32 magicEnd;
std::assert(magicStart0 == "UF2\n", "Invalid magicStart0 value!"); std::assert(magicStart0 == "UF2\n", "Invalid magicStart0 value!");
std::assert(magicStart1 == 0x9E5D5157, "Invalid magicStart1 value!"); std::assert(magicStart1 == 0x9E5D5157, "Invalid magicStart1 value!");
std::assert(magicEnd == 0x0AB16F30, "Invalid magicEnd value!"); std::assert(magicEnd == 0x0AB16F30, "Invalid magicEnd value!");
}; };
UF2_Block block[while(!std::mem::eof())] @ 0; UF2_Block block[while(!std::mem::eof())] @ 0;

View File

@@ -1,36 +1,36 @@
#pragma eval_depth 0x10000 #pragma eval_depth 0x10000
#include <std/mem.pat> #include <std/mem.pat>
#include <std/sys.pat> #include <std/sys.pat>
enum Type : u8 { enum Type : u8 {
Set = 0x00, Set = 0x00,
String = 0x01, String = 0x01,
Integer = 0x02, Integer = 0x02,
EndSet = 0x08 EndSet = 0x08
}; };
struct Entry { struct Entry {
Type type; Type type;
char name[]; char name[];
if (type == Type::Set) { if (type == Type::Set) {
Entry entries[while (std::mem::read_unsigned($, 1) != Type::EndSet)]; Entry entries[while (std::mem::read_unsigned($, 1) != Type::EndSet)];
Type endSet [[hidden]]; Type endSet [[hidden]];
std::assert(endSet == Type::EndSet, "Invalid end of set byte!"); std::assert(endSet == Type::EndSet, "Invalid end of set byte!");
} }
else if (type == Type::Integer) else if (type == Type::Integer)
u32 value; u32 value;
else if (type == Type::String) { else if (type == Type::String) {
char value[]; char value[];
} }
}; };
struct Set { struct Set {
Entry entry [[inline]]; Entry entry [[inline]];
Type endSet [[hidden]]; Type endSet [[hidden]];
std::assert(endSet == Type::EndSet, "Invalid end of set byte!"); std::assert(endSet == Type::EndSet, "Invalid end of set byte!");
}; };
Set set[while (std::mem::read_unsigned($ - 1, 1) != Type::EndSet)] @ 0x00; Set set[while (std::mem::read_unsigned($ - 1, 1) != Type::EndSet)] @ 0x00;

View File

@@ -1,10 +1,10 @@
{ {
"name" : "ImHex", "name" : "ImHex",
"tips" : [ "tips" : [
"Try pressing CTRL + Shift + P to open the command palette!", "Try pressing CTRL + Shift + P to open the command palette!",
"The data processor allows pre-processing of the binary input data before it's displayed without modifying the original data.", "The data processor allows pre-processing of the binary input data before it's displayed without modifying the original data.",
"Take a closer look at the Splash screen :)", "Take a closer look at the Splash screen :)",
"Check out the WerWolv/ImHex-Patterns repository for pre-made patterns and more!", "Check out the WerWolv/ImHex-Patterns repository for pre-made patterns and more!",
"ImHex can be easily extended with plugins through its API." "ImHex can be easily extended with plugins through its API."
] ]
} }

View File

@@ -1,11 +1,11 @@
{ {
"name" : "Reverse Engineering", "name" : "Reverse Engineering",
"tips" : [ "tips" : [
"Reverse Engineering a foreign file format becomes a lot easier if you know some values that should be stored in there.", "Reverse Engineering a foreign file format becomes a lot easier if you know some values that should be stored in there.",
"Ghidra, binwalk, Unicorn, x86dbg, DetectItEasy, Dependencies and CheatEngine are other fantastic and free reverse engineering tools!", "Ghidra, binwalk, Unicorn, x86dbg, DetectItEasy, Dependencies and CheatEngine are other fantastic and free reverse engineering tools!",
"ALWAYS read the documentation if there is one. It will save you a lot of time.", "ALWAYS read the documentation if there is one. It will save you a lot of time.",
"Tools are what you make of them, practice makes perfect.", "Tools are what you make of them, practice makes perfect.",
"Looking for patterns and repeating structures in binary data is always a good start.", "Looking for patterns and repeating structures in binary data is always a good start.",
"The entropy graph is an easy way to quickly figure out where interesting data is stored and if the data is encrypted or compressed." "The entropy graph is an easy way to quickly figure out where interesting data is stored and if the data is encrypted or compressed."
] ]
} }