Crates.io | usbhidusage |
lib.rs | usbhidusage |
version | 0.1.3 |
source | src |
created_at | 2024-10-28 23:20:11.029042 |
updated_at | 2024-11-06 09:27:33.098142 |
description | A general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB) v1.5 |
homepage | |
repository | https://github.com/Cry-Tokyo/usbhidusage |
max_upload_size | |
id | 1426173 |
size | 563,828 |
A general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB) v1.5
Usbhidusage is a general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB). It currently follows the HID Usage Tables for usb v1.5
Usbhidusage currently provides workable enums that tie Usage Names to their specified Usage ID, while also allowing you to retain the origanl value for those without a specified usage.
A usb PCAP reader using usbhidusage.
Make sure you state usbhidusage as a dependency on Cargo.toml:
[dependencies]
usbhidusage = "0.1.0"
pcap = "2.2.0"
pnet = "0.35.0"
Then, import the project in your main.rs:
use pcap::Capture;
use pnet::packet::{usbpcap::MutableUsbPcapPacket, Packet};
use usbhidusage::keyboard::KeyboardUsage;
fn main() {
let mut file = Capture::from_file("tests/usb.pcap").unwrap();
let mut c = 1;
fn key(code: u8) -> bool {
let code = KeyboardUsage::from(code);
match code == KeyboardUsage::Reserved00_00 || code == KeyboardUsage::KeyboardLeftAlt || code == KeyboardUsage::KeyboardLeftGUI || code == KeyboardUsage::KeyboardLeftShift || code == KeyboardUsage::KeyboardLeftControl || code == KeyboardUsage::KeyboardRightAlt || code == KeyboardUsage::KeyboardRightGUI || code == KeyboardUsage::KeyboardRightShift || code == KeyboardUsage::KeyboardRightControl {
true => true,
false => false
}
}
while let Ok(packet) = file.next_packet() {
let data = MutableUsbPcapPacket::owned(packet.to_vec());
if let Some(array) = data {
match array.get_data_length() == 8 && key(array.payload()[0]) && array.payload()[1] == 0
{
true => println!("{}", HIDData::from(array.payload())),
false => println!("{}", HIDData::NOEVENT),
}
}
c += 1
}
}
This and other examples can be found here.
https://www.usb.org/sites/default/files/hut1_5.pdf
https://www.igsa.org/en/standards/gds-gaming-device-standards
https://www.unicode.org/versions/Unicode16.0.0/
Feel free to leave any changes or suggestions, the goal would be to follow the spec as closely as possible and follow up with any revisions or updates as well.
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, shall be licensed as MIT, without any additional terms or conditions.