mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-26 00:37:44 +00:00
Emit a better error message on packet parsing failure
This commit is contained in:
parent
3caf9d38c1
commit
2f996f0012
1 changed files with 36 additions and 32 deletions
|
@ -143,42 +143,46 @@ async fn send_packet(socket: &mut WriteHalf<TcpStream>, segments: &[PacketSegmen
|
||||||
pub async fn parse_packet(socket: &mut WriteHalf<TcpStream>, data: &[u8]) {
|
pub async fn parse_packet(socket: &mut WriteHalf<TcpStream>, data: &[u8]) {
|
||||||
let mut cursor = Cursor::new(data);
|
let mut cursor = Cursor::new(data);
|
||||||
|
|
||||||
if let Ok(packet) = Packet::read_le(&mut cursor) {
|
|
||||||
println!("{:#?}", packet);
|
|
||||||
|
|
||||||
if packet.header.size as usize != data.len() {
|
match Packet::read_le(&mut cursor) {
|
||||||
dump(
|
Ok(packet) => {
|
||||||
"Packet size mismatch between what we're given and the header!",
|
println!("{:#?}", packet);
|
||||||
data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for segment in &packet.segments {
|
if packet.header.size as usize != data.len() {
|
||||||
match &segment.segment_type {
|
dump(
|
||||||
SegmentType::InitializeEncryption { phrase, key } => {
|
"Packet size mismatch between what we're given and the header!",
|
||||||
// Generate an encryption key for this client
|
data,
|
||||||
let client_key = generate_encryption_key(key, phrase);
|
);
|
||||||
|
|
||||||
let blowfish = Blowfish::new(&client_key);
|
|
||||||
let mut data = blowfish.encrypt(&0xE0003C2Au32.to_le_bytes()).unwrap();
|
|
||||||
data.resize(0x280, 0);
|
|
||||||
|
|
||||||
let response_packet = PacketSegment {
|
|
||||||
source_actor: 0,
|
|
||||||
target_actor: 0,
|
|
||||||
segment_type: SegmentType::InitializationEncryptionResponse {
|
|
||||||
data
|
|
||||||
},
|
|
||||||
};
|
|
||||||
send_packet(socket, &[response_packet]).await;
|
|
||||||
},
|
|
||||||
SegmentType::InitializationEncryptionResponse { .. } => panic!("The server is recieving a response packet!"),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//dump("nothing", data);
|
for segment in &packet.segments {
|
||||||
} else {
|
match &segment.segment_type {
|
||||||
dump("Failed to parse packet!", data);
|
SegmentType::InitializeEncryption { phrase, key } => {
|
||||||
|
// Generate an encryption key for this client
|
||||||
|
let client_key = generate_encryption_key(key, phrase);
|
||||||
|
|
||||||
|
let blowfish = Blowfish::new(&client_key);
|
||||||
|
let mut data = blowfish.encrypt(&0xE0003C2Au32.to_le_bytes()).unwrap();
|
||||||
|
data.resize(0x280, 0);
|
||||||
|
|
||||||
|
let response_packet = PacketSegment {
|
||||||
|
source_actor: 0,
|
||||||
|
target_actor: 0,
|
||||||
|
segment_type: SegmentType::InitializationEncryptionResponse {
|
||||||
|
data
|
||||||
|
},
|
||||||
|
};
|
||||||
|
send_packet(socket, &[response_packet]).await;
|
||||||
|
},
|
||||||
|
SegmentType::InitializationEncryptionResponse { .. } => panic!("The server is recieving a response packet!"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
println!("{err}");
|
||||||
|
dump("Failed to parse packet!", data);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue