mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-20 14:47:45 +00:00
Begin parsing the packet header
This commit is contained in:
parent
5f0d6cc425
commit
66ef395afc
3 changed files with 115 additions and 7 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -17,6 +17,12 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "array-init"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.80"
|
||||
|
@ -25,7 +31,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.62",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -99,6 +105,30 @@ version = "0.21.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "binrw"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d4bca59c20d6f40c2cc0802afbe1e788b89096f61bdf7aeea6bf00f10c2909b"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"binrw_derive",
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "binrw_derive"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8ba42866ce5bced2645bfa15e97eef2c62d2bdb530510538de8dd3d04efff3c"
|
||||
dependencies = [
|
||||
"either",
|
||||
"owo-colors",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
|
@ -114,6 +144,12 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.6.0"
|
||||
|
@ -161,6 +197,12 @@ dependencies = [
|
|||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
|
@ -334,6 +376,7 @@ name = "kawari"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"binrw",
|
||||
"minijinja",
|
||||
"rand",
|
||||
"serde",
|
||||
|
@ -427,6 +470,12 @@ version = "1.19.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
|
@ -450,7 +499,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.62",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -554,7 +603,7 @@ checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.62",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -620,6 +669,17 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.62"
|
||||
|
@ -672,7 +732,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.62",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -34,3 +34,4 @@ serde = { version = "1.0", features = ["derive"], default-features = false }
|
|||
tracing-subscriber = { version = "0.3", features = ["fmt"], default-features = false }
|
||||
rand = "0.8"
|
||||
minijinja = "2.0"
|
||||
binrw = { version = "0.14" }
|
||||
|
|
|
@ -1,6 +1,53 @@
|
|||
use std::fs::write;
|
||||
use std::{fs::write, io::Cursor};
|
||||
|
||||
use binrw::{binrw, BinRead};
|
||||
|
||||
pub(crate) fn read_bool_from<T: std::convert::From<u8> + std::cmp::PartialEq>(x: T) -> bool {
|
||||
x == T::from(1u8)
|
||||
}
|
||||
|
||||
pub(crate) fn write_bool_as<T: std::convert::From<u8>>(x: &bool) -> T {
|
||||
if *x { T::from(1u8) } else { T::from(0u8) }
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
#[brw(repr = u16)]
|
||||
#[derive(Debug)]
|
||||
enum ConnectionType {
|
||||
Lobby = 0x3,
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
#[derive(Debug)]
|
||||
struct PacketHeader {
|
||||
unk1: u64,
|
||||
unk2: u64,
|
||||
timestamp: u64,
|
||||
size: u32,
|
||||
connection_type: ConnectionType,
|
||||
count: u16,
|
||||
unk3: u8,
|
||||
#[br(map = read_bool_from::<u8>)]
|
||||
#[bw(map = write_bool_as::<u8>)]
|
||||
compressed: bool,
|
||||
unk4: u32,
|
||||
}
|
||||
|
||||
fn dump(msg: &str, data: &[u8]) {
|
||||
write("packet.bin", data);
|
||||
panic!("{msg} Dumped to packet.bin.");
|
||||
}
|
||||
|
||||
pub fn parse_packet(data: &[u8]) {
|
||||
write("packet.bin", data);
|
||||
panic!("Unknown packet! Dumping to packet.bin.");
|
||||
let mut cursor = Cursor::new(data);
|
||||
|
||||
if let Ok(packet) = PacketHeader::read_le(&mut cursor) {
|
||||
println!("{:#?}", packet);
|
||||
|
||||
if packet.size as usize != data.len() {
|
||||
dump("Packet size mismatch between what we're given and the header!", data);
|
||||
}
|
||||
} else {
|
||||
dump("Failed to parse packet!", data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue