initial version

This commit is contained in:
Florian Stecker 2025-08-24 18:04:11 -04:00
commit d5680f9a7f
3 changed files with 68 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "loophole_rs2"
version = "0.1.0"
edition = "2024"
[dependencies]
nusb = "0.2.0"

59
src/main.rs Normal file
View File

@ -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<dyn Error>> {
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::<Interrupt, Out>(0x01)?;
let mut ep_in = interface.endpoint::<Interrupt, In>(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(())
}