From 67979ced9de5585ba9eeda61384e57446f7683d0 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 14:15:09 +0100 Subject: [PATCH 1/2] Rename LUNA backend to Cynthion. --- src/backend/{luna.rs => cynthion.rs} | 42 ++++++++++++++-------------- src/backend/mod.rs | 2 +- src/main.rs | 4 +-- src/ui.rs | 30 ++++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) rename src/backend/{luna.rs => cynthion.rs} (92%) diff --git a/src/backend/luna.rs b/src/backend/cynthion.rs similarity index 92% rename from src/backend/luna.rs rename to src/backend/cynthion.rs index 9a97b109..76801c63 100644 --- a/src/backend/luna.rs +++ b/src/backend/cynthion.rs @@ -80,30 +80,30 @@ impl State { } } -/// A Luna device attached to the system. -pub struct LunaDevice { +/// A Cynthion device attached to the system. +pub struct CynthionDevice { device_info: DeviceInfo, pub description: String, pub speeds: Vec, } -/// A handle to an open Luna device. -pub struct LunaHandle { +/// A handle to an open Cynthion device. +pub struct CynthionHandle { interface: Interface, } -pub struct LunaStream { +pub struct CynthionStream { receiver: mpsc::Receiver>, buffer: VecDeque, } -pub struct LunaStop { +pub struct CynthionStop { stop_request: oneshot::Sender<()>, worker: JoinHandle::<()>, } -impl LunaDevice { - pub fn scan() -> Result, Error> { +impl CynthionDevice { + pub fn scan() -> Result, Error> { let mut result = Vec::new(); for device_info in nusb::list_devices()? { if device_info.vendor_id() == VID && @@ -120,9 +120,9 @@ impl LunaDevice { .product_string() .unwrap_or("Device"); let description = format!("{} {}", manufacturer, product); - let handle = LunaHandle::new(&device_info)?; + let handle = CynthionHandle::new(&device_info)?; let speeds = handle.speeds()?; - result.push(LunaDevice{ + result.push(CynthionDevice{ device_info, description, speeds, @@ -132,16 +132,16 @@ impl LunaDevice { Ok(result) } - pub fn open(&self) -> Result { - LunaHandle::new(&self.device_info) + pub fn open(&self) -> Result { + CynthionHandle::new(&self.device_info) } } -impl LunaHandle { - fn new(device_info: &DeviceInfo) -> Result { +impl CynthionHandle { + fn new(device_info: &DeviceInfo) -> Result { let device = device_info.open()?; let interface = device.claim_interface(0)?; - Ok(LunaHandle { interface }) + Ok(CynthionHandle { interface }) } pub fn speeds(&self) -> Result, Error> { @@ -171,7 +171,7 @@ impl LunaHandle { } pub fn start(mut self, speed: Speed, result_handler: F) - -> Result<(LunaStream, LunaStop), Error> + -> Result<(CynthionStream, CynthionStop), Error> where F: FnOnce(Result<(), Error>) + Send + 'static { // Channel to pass captured data to the decoder thread. @@ -241,11 +241,11 @@ impl LunaHandle { }; let worker = spawn(move || result_handler(run_capture())); Ok(( - LunaStream { + CynthionStream { receiver: rx, buffer: VecDeque::new(), }, - LunaStop { + CynthionStop { stop_request: stop_tx, worker, } @@ -269,7 +269,7 @@ impl LunaHandle { } } -impl Iterator for LunaStream { +impl Iterator for CynthionStream { type Item = Vec; fn next(&mut self) -> Option> { @@ -290,7 +290,7 @@ impl Iterator for LunaStream { } } -impl LunaStream { +impl CynthionStream { fn next_buffered_packet(&mut self) -> Option> { // Do we have the length header for the next packet? let buffer_len = self.buffer.len(); @@ -313,7 +313,7 @@ impl LunaStream { } } -impl LunaStop { +impl CynthionStop { pub fn stop(self) -> Result<(), Error> { println!("Requesting capture stop"); self.stop_request.send(()) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 75802885..efbbfef1 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1 +1 @@ -pub mod luna; \ No newline at end of file +pub mod cynthion; diff --git a/src/main.rs b/src/main.rs index f7cf06bb..abe98bcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use gtk::gio::ApplicationFlags; use packetry::ui::{ activate, display_error, - stop_luna + stop_cynthion }; fn main() { @@ -14,5 +14,5 @@ fn main() { ); application.connect_activate(|app| display_error(activate(app))); application.run_with_args::<&str>(&[]); - display_error(stop_luna()); + display_error(stop_cynthion()); } diff --git a/src/ui.rs b/src/ui.rs index e1c22bcd..adb033dd 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -47,7 +47,7 @@ use pcap_file::{ pcap::{PcapReader, PcapWriter, PcapHeader, RawPcapPacket}, }; -use crate::backend::luna::{LunaDevice, LunaHandle, LunaStop, Speed}; +use crate::backend::cynthion::{CynthionDevice, CynthionHandle, CynthionStop, Speed}; use crate::capture::{ create_capture, CaptureReader, @@ -93,7 +93,7 @@ enum FileAction { } struct DeviceSelector { - devices: Vec, + devices: Vec, dev_strings: Vec, dev_speeds: Vec>, dev_dropdown: DropDown, @@ -140,7 +140,7 @@ impl DeviceSelector { } fn scan(&mut self) -> Result { - self.devices = LunaDevice::scan()?; + self.devices = CynthionDevice::scan()?; self.dev_strings = Vec::with_capacity(self.devices.len()); self.dev_speeds = Vec::with_capacity(self.devices.len()); for device in self.devices.iter() { @@ -158,13 +158,13 @@ impl DeviceSelector { Ok(available) } - fn open(&self) -> Result<(LunaHandle, Speed), Error> { + fn open(&self) -> Result<(CynthionHandle, Speed), Error> { let device_id = self.dev_dropdown.selected(); let device = &self.devices[device_id as usize]; let speed_id = self.speed_dropdown.selected() as usize; let speed = device.speeds[speed_id]; - let luna = device.open()?; - Ok((luna, speed)) + let cynthion = device.open()?; + Ok((cynthion, speed)) } fn replace_dropdown>( @@ -187,7 +187,7 @@ pub struct UserInterface { pub capture: CaptureReader, selector: DeviceSelector, file_name: Option, - stop_handle: Option, + stop_handle: Option, traffic_window: ScrolledWindow, device_window: ScrolledWindow, pub traffic_model: Option, @@ -328,7 +328,7 @@ pub fn activate(application: &Application) -> Result<(), Error> { window.set_child(Some(&vbox)); scan_button.connect_clicked(|_| display_error(detect_hardware())); - capture_button.connect_clicked(|_| display_error(start_luna())); + capture_button.connect_clicked(|_| display_error(start_cynthion())); open_button.connect_clicked(|_| display_error(choose_file(Load))); save_button.connect_clicked(|_| display_error(choose_file(Save))); @@ -779,12 +779,12 @@ fn detect_hardware() -> Result<(), Error> { }) } -pub fn start_luna() -> Result<(), Error> { +pub fn start_cynthion() -> Result<(), Error> { let writer = reset_capture()?; with_ui(|ui| { - let (luna, speed) = ui.selector.open()?; + let (cynthion, speed) = ui.selector.open()?; let (stream_handle, stop_handle) = - luna.start(speed, display_error)?; + cynthion.start(speed, display_error)?; ui.stop_handle.replace(stop_handle); ui.open_button.set_sensitive(false); ui.scan_button.set_sensitive(false); @@ -792,8 +792,8 @@ pub fn start_luna() -> Result<(), Error> { ui.capture_button.set_sensitive(false); ui.stop_button.set_sensitive(true); let signal_id = ui.stop_button.connect_clicked(|_| - display_error(stop_luna())); - let read_luna = move || { + display_error(stop_cynthion())); + let read_cynthion = move || { let mut decoder = Decoder::new(writer)?; for packet in stream_handle { decoder.handle_raw_packet(&packet)?; @@ -802,7 +802,7 @@ pub fn start_luna() -> Result<(), Error> { Ok(()) }; std::thread::spawn(move || { - display_error(read_luna()); + display_error(read_cynthion()); gtk::glib::idle_add_once(|| { display_error( with_ui(|ui| { @@ -824,7 +824,7 @@ pub fn start_luna() -> Result<(), Error> { }) } -pub fn stop_luna() -> Result<(), Error> { +pub fn stop_cynthion() -> Result<(), Error> { with_ui(|ui| { if let Some(stop_handle) = ui.stop_handle.take() { stop_handle.stop()?; From 06510899bac194c55e2411aa714446c32641785e Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 14:26:57 +0100 Subject: [PATCH 2/2] Update documentation. --- README.md | 4 +--- docs/source/introToPacketry.rst | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14734cf7..e1813117 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Packetry -A fast, intuitive USB 2.0 protocol analysis application for use with [LUNA](https://github.com/greatscottgadgets/luna). +A fast, intuitive USB 2.0 protocol analysis application for use with [Cynthion](https://greatscottgadgets.com/cynthion/). Packetry is currently in active development and not yet ready for initial release. @@ -20,8 +20,6 @@ To build, run `cargo build` after installing the necessary prerequisites (see be If you pass a capture filename as an argument, Packetry will attempt to load it. The current supported file format is a `.pcap` file with the `LINKTYPE_USB_2_0` link layer header type. -If no filename is provided, Packetry will attempt to start live capture from an attached device running the [LUNA](https://github.com/greatscottgadgets/luna) USB analyzer applet. - ### Installing prerequisites #### Linux diff --git a/docs/source/introToPacketry.rst b/docs/source/introToPacketry.rst index ecbc8e3a..e52ddad0 100644 --- a/docs/source/introToPacketry.rst +++ b/docs/source/introToPacketry.rst @@ -2,4 +2,4 @@ Packetry ======== -A fast, intuitive USB 2.0 protocol analysis application for use with LUNA. \ No newline at end of file +A fast, intuitive USB 2.0 protocol analysis application for use with Cynthion.