From d5680f9a7f559c5c44ffb5c61435f649187569a3 Mon Sep 17 00:00:00 2001 From: Florian Stecker Date: Sun, 24 Aug 2025 18:04:11 -0400 Subject: [PATCH] initial version --- .gitignore | 2 ++ Cargo.toml | 7 +++++++ src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4c6cd23 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "loophole_rs2" +version = "0.1.0" +edition = "2024" + +[dependencies] +nusb = "0.2.0" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b17660b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,59 @@ +use nusb::{self, Interface, Device, MaybeFuture}; +use nusb::transfer::{Interrupt, In, Out, Buffer}; +use std::time::Duration; +use std::error::Error; + +fn main() -> Result<(), Box> { + let devid: (u16, u16) = (0x0da4, 0x0008); + + let dev: Device = nusb::list_devices().wait()? + .filter(|di| di.vendor_id() == devid.0 && di.product_id() == devid.1) + .next().ok_or(format!("Couldn't find device {:04x}:{:04x}", devid.0, devid.1))? + .open().wait()?; + + let interface_number = dev + .active_configuration()? + .interface_alt_settings() + .next().ok_or(format!("Device has no interfaces"))? + .interface_number(); + + let interface: Interface = dev + .detach_and_claim_interface(interface_number) + .wait()?; + + let mut ep_out = interface.endpoint::(0x01)?; + let mut ep_in = interface.endpoint::(0x81)?; + + // just check if there's any data waiting already + let buf_in = Buffer::new(64); + ep_in.submit(buf_in); + ep_in.wait_next_complete(Duration::new(0,10_000_000)); + + for i in 0.. { + println!("Attempt {i}"); + + let req: &[u8] = &[8, 0, 18, 1, 47]; + let mut buf_out = Buffer::new(64); + buf_out.extend_fill(64, 0); + buf_out[5..req.len()+5].copy_from_slice(req); + buf_out[0] = 1; // id + buf_out[1] = (req.len() as u8 + 4) << 2; + buf_out[3] = req.len() as u8; + ep_out.submit(buf_out); + + ep_out.wait_next_complete(Duration::new(1,0)) + .ok_or(format!("Write timed out"))? + .into_result()?; + + ep_in.submit(Buffer::new(64)); + if let Some(response_buf_in) = + ep_in.wait_next_complete(Duration::new(0,100_000_000)) { + println!("{response_buf_in:?}"); + break; + } + } + +// println!("{response_buf_out:?}"); + + Ok(()) +}