mirror of
https://github.com/lcdr/lu_packets.git
synced 2026-01-07 00:49:30 -06:00
Add a script for testing parsing on captures
This commit is contained in:
133
Cargo.lock
generated
133
Cargo.lock
generated
@@ -1,5 +1,47 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bzip2-sys 0.1.9+1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.9+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "endio"
|
||||
version = "0.2.0"
|
||||
@@ -23,6 +65,22 @@ dependencies = [
|
||||
"syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"miniz_oxide 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lu_packets"
|
||||
version = "0.1.0"
|
||||
@@ -30,6 +88,7 @@ dependencies = [
|
||||
"endio 0.2.0 (git+https://github.com/lcdr/endio?rev=7ce17a01a9bf05cd777d5e6d34887a60e810cb85)",
|
||||
"endio_bit 0.1.0 (git+https://github.com/lcdr/endio_bit?rev=46b1b0eda359dd85b5eabf9714e839c3728c75af)",
|
||||
"lu_packets_derive 0.1.0",
|
||||
"zip 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -41,6 +100,24 @@ dependencies = [
|
||||
"syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"adler 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "podio"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.18"
|
||||
@@ -67,16 +144,72 @@ dependencies = [
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum adler 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10"
|
||||
"checksum bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b"
|
||||
"checksum bzip2-sys 0.1.9+1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e"
|
||||
"checksum cc 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
|
||||
"checksum endio 0.2.0 (git+https://github.com/lcdr/endio?rev=7ce17a01a9bf05cd777d5e6d34887a60e810cb85)" = "<none>"
|
||||
"checksum endio_bit 0.1.0 (git+https://github.com/lcdr/endio_bit?rev=46b1b0eda359dd85b5eabf9714e839c3728c75af)" = "<none>"
|
||||
"checksum endio_derive 0.2.0 (git+https://github.com/lcdr/endio?rev=7ce17a01a9bf05cd777d5e6d34887a60e810cb85)" = "<none>"
|
||||
"checksum flate2 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e"
|
||||
"checksum libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
||||
"checksum miniz_oxide 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f"
|
||||
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
||||
"checksum podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19"
|
||||
"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
"checksum quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea"
|
||||
"checksum syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2"
|
||||
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum zip 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58287c28d78507f5f91f2a4cf1e8310e2c76fd4c6932f93ac60fd1ceb402db7d"
|
||||
|
||||
@@ -10,3 +10,6 @@ repository = "https://github.com/lcdr/lu_packets/"
|
||||
endio = { git = "https://github.com/lcdr/endio", rev = "7ce17a01a9bf05cd777d5e6d34887a60e810cb85" }
|
||||
endio_bit = { git = "https://github.com/lcdr/endio_bit", rev = "46b1b0eda359dd85b5eabf9714e839c3728c75af" }
|
||||
lu_packets_derive = { path = "lu_packets_derive" }
|
||||
|
||||
[dev-dependencies]
|
||||
zip = "0.5.6"
|
||||
|
||||
173
examples/capture_parser.rs
Normal file
173
examples/capture_parser.rs
Normal file
@@ -0,0 +1,173 @@
|
||||
use std::env;
|
||||
use std::io::{BufReader, Result as Res};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
use endio::LERead;
|
||||
use lu_packets::{
|
||||
auth::server::Message as AuthServerMessage,
|
||||
world::server::Message as WorldServerMessage,
|
||||
world::client::Message as WorldClientMessage,
|
||||
};
|
||||
|
||||
static mut PRINT_PACKETS: bool = false;
|
||||
|
||||
fn visit_dirs(dir: &Path) -> Res<usize> {
|
||||
let mut packet_count = 0;
|
||||
if dir.is_dir() {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
packet_count += if path.is_dir() { visit_dirs(&path) } else { parse(&path) }?;
|
||||
dbg!(packet_count);
|
||||
}
|
||||
}
|
||||
Ok(packet_count)
|
||||
}
|
||||
|
||||
fn parse(path: &Path) -> Res<usize> {
|
||||
if path.extension().unwrap() != "zip" { return Ok(0); }
|
||||
|
||||
let src = BufReader::new(File::open(path).unwrap());
|
||||
let mut zip = zip::ZipArchive::new(src).unwrap();
|
||||
let mut i = 0;
|
||||
let mut packet_count = 0;
|
||||
while i < zip.len() {
|
||||
let mut file = zip.by_index(i).unwrap();
|
||||
if file.name().contains("[53-01-") {
|
||||
let msg: AuthServerMessage = file.read().expect(&format!("Zip: {}, Filename: {}, {} bytes", path.to_str().unwrap(), file.name(), file.size()));
|
||||
if unsafe { PRINT_PACKETS } {
|
||||
dbg!(msg);
|
||||
}
|
||||
packet_count += 1
|
||||
} else if file.name().contains("[53-04-")
|
||||
&& !file.name().contains("[53-04-00-16]")
|
||||
&& !file.name().contains("[53-04-00-17]")
|
||||
&& !file.name().contains("[30-00]")
|
||||
&& !file.name().contains("[77-00]")
|
||||
&& !file.name().contains("[e6-00]")
|
||||
&& !file.name().contains("[6b-03]")
|
||||
&& !file.name().contains("[16-04]")
|
||||
&& !file.name().contains("[49-04]")
|
||||
&& !file.name().contains("[ad-04]")
|
||||
&& !file.name().contains("[1c-05]")
|
||||
&& !file.name().contains("[48]")
|
||||
&& !file.name().contains("[119]")
|
||||
&& !file.name().contains("[230]")
|
||||
&& !file.name().contains("[875]")
|
||||
&& !file.name().contains("[1046]")
|
||||
&& !file.name().contains("[1097]")
|
||||
&& !file.name().contains("[1197]")
|
||||
&& !file.name().contains("[1308]")
|
||||
{
|
||||
let msg: WorldServerMessage = file.read().expect(&format!("Zip: {}, Filename: {}, {} bytes", path.to_str().unwrap(), file.name(), file.size()));
|
||||
if unsafe { PRINT_PACKETS } {
|
||||
dbg!(msg);
|
||||
};
|
||||
packet_count += 1;
|
||||
} else if file.name().contains("[53-05-00-0c")
|
||||
&& !file.name().contains("[53-05-00-00]")
|
||||
&& !file.name().contains("[53-05-00-04]")
|
||||
&& !file.name().contains("[53-05-00-06]")
|
||||
&& !file.name().contains("[53-05-00-15]")
|
||||
&& !file.name().contains("[53-05-00-1c]")
|
||||
&& !file.name().contains("[53-05-00-1e]")
|
||||
&& !file.name().contains("[53-05-00-1f]")
|
||||
&& !file.name().contains("[53-05-00-22]")
|
||||
&& !file.name().contains("[53-05-00-31]")
|
||||
&& !file.name().contains("[53-05-00-3b]")
|
||||
&& !file.name().contains("[2a-00]")
|
||||
&& !file.name().contains("[76-00]")
|
||||
&& !file.name().contains("[7f-00]")
|
||||
&& !file.name().contains("[80-00]")
|
||||
&& !file.name().contains("[e3-00]")
|
||||
&& !file.name().contains("[e6-00]")
|
||||
&& !file.name().contains("[ff-00]")
|
||||
&& !file.name().contains("[a1-01]")
|
||||
&& !file.name().contains("[39-02]")
|
||||
&& !file.name().contains("[7f-02]")
|
||||
&& !file.name().contains("[89-02]")
|
||||
&& !file.name().contains("[a3-02]")
|
||||
&& !file.name().contains("[cc-02]")
|
||||
&& !file.name().contains("[0d-03]")
|
||||
&& !file.name().contains("[35-03]")
|
||||
&& !file.name().contains("[36-03]")
|
||||
&& !file.name().contains("[4d-03]")
|
||||
&& !file.name().contains("[5a-03]")
|
||||
&& !file.name().contains("[6d-03]")
|
||||
&& !file.name().contains("[91-03]")
|
||||
&& !file.name().contains("[a0-04]")
|
||||
&& !file.name().contains("[1a-05]")
|
||||
&& !file.name().contains("[1e-05]")
|
||||
&& !file.name().contains("[e6-05]")
|
||||
&& !file.name().contains("[16-06]")
|
||||
&& !file.name().contains("[1c-06]")
|
||||
&& !file.name().contains("[6f-06]")
|
||||
&& !file.name().contains("[70-06]")
|
||||
&& !file.name().contains("[42]")
|
||||
&& !file.name().contains("[118]")
|
||||
&& !file.name().contains("[127]")
|
||||
&& !file.name().contains("[128]")
|
||||
&& !file.name().contains("[227]")
|
||||
&& !file.name().contains("[230]")
|
||||
&& !file.name().contains("[255]")
|
||||
&& !file.name().contains("[417]")
|
||||
&& !file.name().contains("[569]")
|
||||
&& !file.name().contains("[639]")
|
||||
&& !file.name().contains("[675]")
|
||||
&& !file.name().contains("[649]")
|
||||
&& !file.name().contains("[716]")
|
||||
&& !file.name().contains("[781]")
|
||||
&& !file.name().contains("[821]")
|
||||
&& !file.name().contains("[822]")
|
||||
&& !file.name().contains("[845]")
|
||||
&& !file.name().contains("[858]")
|
||||
&& !file.name().contains("[877]")
|
||||
&& !file.name().contains("[913]")
|
||||
&& !file.name().contains("[1184]")
|
||||
&& !file.name().contains("[1306]")
|
||||
&& !file.name().contains("[1310]")
|
||||
&& !file.name().contains("[1510]")
|
||||
&& !file.name().contains("[1558]")
|
||||
&& !file.name().contains("[1564]")
|
||||
&& !file.name().contains("[1647]")
|
||||
&& !file.name().contains("[1648]")
|
||||
{
|
||||
let msg: WorldClientMessage = file.read().expect(&format!("Zip: {}, Filename: {}, {} bytes", path.to_str().unwrap(), file.name(), file.size()));
|
||||
if unsafe { PRINT_PACKETS } {
|
||||
dbg!(msg);
|
||||
}
|
||||
packet_count += 1;
|
||||
} else { i += 1; continue }
|
||||
// assert fully read
|
||||
let mut rest = vec![];
|
||||
std::io::Read::read_to_end(&mut file, &mut rest).unwrap();
|
||||
assert_eq!(rest, vec![], "{}", path.to_str().unwrap());
|
||||
i += 1;
|
||||
}
|
||||
Ok(packet_count)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let capture = match args.get(1) {
|
||||
Some(x) => x,
|
||||
None => {
|
||||
println!("Usage: capture_parser capture_path --print_packets");
|
||||
return;
|
||||
}
|
||||
};
|
||||
unsafe { PRINT_PACKETS = args.get(2).is_some(); }
|
||||
|
||||
let start = Instant::now();
|
||||
let packet_count = if capture.ends_with(".zip") {
|
||||
parse(Path::new(capture))
|
||||
} else {
|
||||
visit_dirs(Path::new(capture))
|
||||
}.unwrap();
|
||||
println!();
|
||||
println!("Number of parsed packets: {}", packet_count);
|
||||
println!("Time taken: {:?}", start.elapsed());
|
||||
}
|
||||
Reference in New Issue
Block a user