diff --git a/soundcore-lib/Cargo.toml b/soundcore-lib/Cargo.toml index 3974d33..1ccad4a 100644 --- a/soundcore-lib/Cargo.toml +++ b/soundcore-lib/Cargo.toml @@ -23,4 +23,5 @@ dialoguer = { version = "0.10.4", features = ["fuzzy-select"] } derive_more = { version = "0.99", features = ["from"] } [dev-dependencies] -test_data = { path = "../test_data/" } \ No newline at end of file +test_data = { path = "../test_data/" } +cargo-fuzz = "0.11.2" \ No newline at end of file diff --git a/soundcore-lib/fuzz/.gitignore b/soundcore-lib/fuzz/.gitignore new file mode 100644 index 0000000..1a45eee --- /dev/null +++ b/soundcore-lib/fuzz/.gitignore @@ -0,0 +1,4 @@ +target +corpus +artifacts +coverage diff --git a/soundcore-lib/fuzz/Cargo.toml b/soundcore-lib/fuzz/Cargo.toml new file mode 100644 index 0000000..5f3d88f --- /dev/null +++ b/soundcore-lib/fuzz/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "soundcore-lib-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.soundcore-lib] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[profile.release] +debug = 1 + +[[bin]] +name = "fuzz_target_1" +path = "fuzz_targets/fuzz_target_1.rs" +test = false +doc = false + +[[bin]] +name = "a3951" +path = "fuzz_targets/a3951.rs" +test = false +doc = false diff --git a/soundcore-lib/fuzz/fuzz_targets/a3951.rs b/soundcore-lib/fuzz/fuzz_targets/a3951.rs new file mode 100644 index 0000000..409cbab --- /dev/null +++ b/soundcore-lib/fuzz/fuzz_targets/a3951.rs @@ -0,0 +1,7 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use soundcore_lib::packets::ResponsePacket; + +fuzz_target!(|data: &[u8]| { + let _ = ResponsePacket::from_bytes(data); +}); \ No newline at end of file diff --git a/soundcore-lib/src/models/misc.rs b/soundcore-lib/src/models/misc.rs index 17f18a9..f90c76c 100644 --- a/soundcore-lib/src/models/misc.rs +++ b/soundcore-lib/src/models/misc.rs @@ -55,13 +55,11 @@ pub struct TwsStatus(pub bool); )] pub struct WearDetection(pub bool); - #[derive( Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From, )] pub struct TouchTone(pub bool); - #[derive( Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From, )] diff --git a/soundcore-lib/src/packets/response/state/a3040.rs b/soundcore-lib/src/packets/response/state/a3040.rs index 9d3f2b3..97bed57 100644 --- a/soundcore-lib/src/packets/response/state/a3040.rs +++ b/soundcore-lib/src/packets/response/state/a3040.rs @@ -1,6 +1,6 @@ use serde::{Serialize, Deserialize}; -use crate::models::{SingleBattery, FirmwareVer, SerialNumber}; +use crate::models::{SingleBattery, FirmwareVer, SerialNumber, TouchTone, WearDetection, ThreeDimensionalEffect, BassUp, LDAC, SupportTwoCnn, InEarBeep, DeviceColor, AutoPowerOff, HearingProtect, AmbientSoundNotice, PowerOnBatteryNotice}; #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] @@ -8,5 +8,18 @@ pub struct A3040StateResponse { pub battery: SingleBattery, pub fw: FirmwareVer, pub sn: SerialNumber, - + pub touch_tone: TouchTone, + pub wear_detection: WearDetection, + pub three_dimensional_effect: ThreeDimensionalEffect, + pub charging_case_battery: u8, // TODO: Extract type? + pub bass_up: BassUp, + pub device_color: DeviceColor, + pub ldac: LDAC, + pub support_two_cnn: SupportTwoCnn, + pub in_ear_beep: InEarBeep, + pub prompt_language: u8, // TODO: Extract type? If == 0, then English. If == 1, then Chinese. + pub auto_power_off: AutoPowerOff, + pub hearing_protect: HearingProtect, + pub ambient_sound_notice: AmbientSoundNotice, + pub power_on_battery_notice: PowerOnBatteryNotice, } \ No newline at end of file