-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naive incomplete chunk header packer
- Loading branch information
1 parent
7e47ba4
commit 7b4c890
Showing
8 changed files
with
158 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
pack_chunk_header: | ||
; pack_chunk_header [rax] [rdi] [rsi] | ||
; rax = flags | ||
; rdi = size | ||
; rsi = output buffer | ||
; | ||
; example: | ||
; | ||
; mov rax, 0 | ||
; set_rax_flag CHUNKFLAG_VITAL | ||
; mov rdi, 10 | ||
; mov rsi, my_chunk_buffer | ||
; call pack_chunk_header | ||
; | ||
|
||
push rax | ||
|
||
cmp rdi, 63 | ||
jg .pack_chunk_header_error_size | ||
|
||
push rax | ||
mov dword rax, [connection_sequence] | ||
cmp rax, 255 | ||
jg .pack_chunk_header_error_seq | ||
pop rax | ||
|
||
; Chunk header (vital) | ||
; +---------+---------+-----------------+--------+-----------------+ | ||
; | Flags | Size | Sequence number | Size | Sequence number | | ||
; | 2 bits | 6 bits | 2 bits | 6 bits | 8 bits | | ||
; +---------+---------+-----------------+--------+-----------------+ | ||
|
||
; flags | ||
mov [rsi], al | ||
; size (only in the 2nd byte for now) | ||
mov [rsi+1], dil | ||
|
||
; sequence only included if it is a vital chunk | ||
is_rax_flag CHUNKFLAG_VITAL | ||
jz .pack_chunk_header_end | ||
|
||
; sequence (only in the 3rd byte for now) | ||
mov byte al, [connection_sequence] | ||
mov [rsi+2], al | ||
|
||
jmp .pack_chunk_header_end | ||
|
||
.pack_chunk_header_error_seq: | ||
print s_unsupported_seq_size | ||
mov rax, [connection_sequence] | ||
call print_uint32 | ||
exit 1 | ||
|
||
.pack_chunk_header_error_size: | ||
print s_unsupported_chunk_size | ||
mov rax, rdi | ||
call print_uint32 | ||
exit 1 | ||
|
||
.pack_chunk_header_end: | ||
pop rax | ||
ret | ||
|
||
queue_chunk: | ||
; queue_chunk [rax] [rdi] [rsi] [rdx] | ||
; rax = system (1=system 0=game) | ||
; rdi = payload | ||
; rsi = payload size | ||
|
||
; resend flag is not supported yet | ||
|
||
push_registers | ||
|
||
; increment if vital | ||
; connection_sequence | ||
|
||
pop_registers | ||
ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
s_got_peer_token db "[client] got peer token: " | ||
l_s_got_peer_token equ $ - s_got_peer_token | ||
s_got_accept db "[client] got accept", 0x0a | ||
l_s_got_accept equ $ - s_got_accept | ||
s_got_ctrl_msg db "[client] got ctrl msg: " | ||
l_s_got_ctrl_msg equ $ - s_got_ctrl_msg | ||
s_unknown_ctrl_msg db "[client] unknown ctrl msg: " | ||
l_s_unknown_ctrl_msg equ $ - s_unknown_ctrl_msg | ||
s_got_packet_with_chunks db "[client] got packet with chunks: " | ||
l_s_got_packet_with_chunks equ $ - s_got_packet_with_chunks | ||
s_unhandled_packet db "[client] UNHANDLED PACKET!!" | ||
l_s_unhandled_packet equ $ - s_unhandled_packet | ||
s_unsupported_chunk_size db "[error] chunk sizes higher than 63 are not supported yet. got size: " | ||
l_s_unsupported_chunk_size equ $ - s_unsupported_chunk_size | ||
s_unsupported_seq_size db "[error] chunk sequence numbers higher than 255 are not supported yet. got sequence number: " | ||
l_s_unsupported_seq_size equ $ - s_unsupported_seq_size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
%include "tests/assert.asm" | ||
%include "src/chunks.asm" | ||
|
||
_start: | ||
mov dword [connection_sequence], 9 | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 6 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header | ||
|
||
mov al, [assert_actual_buf] | ||
assert_al_eq 0x40 | ||
mov al, [assert_actual_buf + 1] | ||
assert_al_eq 0x06 | ||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0x09 | ||
exit 0 | ||
|