|
|
@ -43,11 +43,17 @@ pub fn recv_packet<T: Read>(socket: &mut T, cipher: &mut dyn PSOCipher) -> Resul |
|
|
|
}
|
|
|
|
|
|
|
|
let mut dec_size_buf = cipher.decrypt(&size_buf)?;
|
|
|
|
let size = u16::from_le_bytes([dec_size_buf[0], dec_size_buf[1]]) as usize;
|
|
|
|
let pkt_size = u16::from_le_bytes([dec_size_buf[0], dec_size_buf[1]]) as usize;
|
|
|
|
|
|
|
|
let mut data_buf = vec![0u8; size - cipher.header_size()];
|
|
|
|
let mut buf_size = pkt_size;
|
|
|
|
while buf_size % cipher.block_size() != 0 {
|
|
|
|
buf_size += 1;
|
|
|
|
}
|
|
|
|
buf_size -= cipher.header_size();
|
|
|
|
|
|
|
|
let mut data_buf = vec![0u8; buf_size];
|
|
|
|
let mut offset = 0;
|
|
|
|
while offset < size - cipher.header_size() {
|
|
|
|
while offset < buf_size {
|
|
|
|
let diff = socket.read(&mut data_buf[offset..])?;
|
|
|
|
if diff == 0 {
|
|
|
|
return Err(PacketNetworkError::ClientDisconnected);
|
|
|
@ -55,21 +61,14 @@ pub fn recv_packet<T: Read>(socket: &mut T, cipher: &mut dyn PSOCipher) -> Resul |
|
|
|
offset += diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut null_data_count = 0;
|
|
|
|
while data_buf.len() % cipher.header_size() != 0 {
|
|
|
|
data_buf.push(0);
|
|
|
|
null_data_count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//println!("[encbuf]: {:X?}", data_buf);
|
|
|
|
let mut dec_data_buf = cipher.decrypt(&data_buf.to_vec())?;
|
|
|
|
|
|
|
|
for _ in 0..null_data_count {
|
|
|
|
dec_data_buf.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut full_buf = Vec::new();
|
|
|
|
full_buf.append(&mut dec_size_buf);
|
|
|
|
full_buf.append(&mut dec_data_buf);
|
|
|
|
full_buf = full_buf[..pkt_size].to_vec();
|
|
|
|
|
|
|
|
//println!("[recv]: {:X?}", full_buf);
|
|
|
|
Ok(full_buf)
|
|
|
|
}
|