-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Raleigh Littles
authored and
Raleigh Littles
committed
Nov 17, 2024
1 parent
e7409c6
commit 89d498c
Showing
7 changed files
with
224 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* File: equalizer_constants.rs | ||
* | ||
* http://www.ipodlinux.org/ITunesDB/#Equalizer_Presets_file | ||
*/ | ||
|
||
/// Container constants | ||
pub const EQUALIZER_PRESET_CONTAINER_OBJECT_KEY: &str = "mqed"; | ||
pub const EQUALIZER_NUMBER_OF_PRESETS_OFFSET: usize = 16; | ||
pub const EQUALIZER_NUMBER_OF_PRESETS_LEN: usize = 4; | ||
|
||
pub const EQUALIZER_PRESET_CHILDSIZE_OFFSET : usize = 20; | ||
pub const EQUALIZER_PRESET_CHILDSIZE_LEN : usize = 4; | ||
pub const EQUALIZER_PRESET_CHILDSIZE_VALUE : usize = 588; | ||
|
||
|
||
pub const EQUALIZER_PRESET_PRESET_OBJECT_KEY: &str = "pqed"; | ||
pub const EQUALIZER_PRESET_PRESET_NAME_LENGTH_OFFSET : usize = 4; | ||
pub const EQUALIZER_PRESET_FIELD_MAX_LENGTH : usize = 510; | ||
|
||
pub const EQUALIZER_PRESET_NAME_OFFSET : usize = 6; // 4 + 2 | ||
|
||
pub const EQUALIZER_PREAMP_OFFSET : usize = 516; // 4 + 2 + 510 | ||
pub const EQUALIZER_PREAMP_LEN : usize = 4; | ||
|
||
pub const EQUALIZER_NUM_OF_ITUNES_BANDS_OFFSET : usize = EQUALIZER_PREAMP_OFFSET + EQUALIZER_PREAMP_LEN; | ||
pub const EQUALIZER_NUM_OF_ITUNES_BANDS_EXPECTED_VALUE : usize = 10; | ||
|
||
pub const EQUALIZER_ITUNES_BAND_VALUES_OFFSET : usize = EQUALIZER_NUM_OF_ITUNES_BANDS_OFFSET + 4; | ||
pub const EQUALIZER_ITUNES_BAND_VALUES_LEN : usize = 40; | ||
|
||
pub const MAX_EQUALIZER_BAND_VALUE : i32 = 1200; | ||
pub const MIN_EQUALIZER_BAND_VALUE : i32 = -1200; | ||
|
||
pub const EQUALIZER_NUM_OF_DSP_BANDS_OFFSET : usize = EQUALIZER_ITUNES_BAND_VALUES_OFFSET + EQUALIZER_ITUNES_BAND_VALUES_LEN; | ||
pub const EQUALIZER_NUM_OF_DSP_BANDS_EXPECTED_VALUE : usize = 5; | ||
|
||
pub const EQUALIZER_DSP_BAND_VALUES_OFFSET : usize = EQUALIZER_NUM_OF_DSP_BANDS_OFFSET + 4; | ||
pub const EQUALIZER_DSP_BAND_VALUES_LEN : usize = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
|
||
use crate::constants::deviceinfo_constants; | ||
use crate::helpers::helpers; | ||
|
||
pub fn parse_device_info_file(deviceinfo_file_as_bytes: Vec<u8>) { | ||
|
||
if deviceinfo_file_as_bytes.len() != deviceinfo_constants::DEVICEINFO_FILE_SIZE { | ||
panic!("Invalid DeviceInfo file size! Expected: {} | Got: {}", deviceinfo_constants::DEVICEINFO_FILE_SIZE, deviceinfo_file_as_bytes.len()); | ||
panic!( | ||
"Invalid DeviceInfo file size! Expected: {} | Got: {}", | ||
deviceinfo_constants::DEVICEINFO_FILE_SIZE, | ||
deviceinfo_file_as_bytes.len() | ||
); | ||
} | ||
|
||
let ipod_name_length_raw = &deviceinfo_file_as_bytes[0..2]; | ||
|
||
let ipod_name_length = helpers::build_le_u16_from_bytes(ipod_name_length_raw) as usize; | ||
|
||
// The strings are formatted using UTF-16 so this byte value must be a multiple of 2 | ||
if ipod_name_length % 2 != 0 { | ||
panic!("Invalid iPod Name Length! Expected multiple of 2 | Got: {}", ipod_name_length); | ||
if ipod_name_length % 2 != 0 | ||
|| ipod_name_length > deviceinfo_constants::DEVICEINFO_MAX_STRING_LENGTH | ||
{ | ||
panic!("Invalid iPod Name length value of '{}'", ipod_name_length); | ||
} | ||
|
||
println!("iPod Name Length: {}", ipod_name_length); | ||
|
||
// factor of 2 to account for UTF-16 encoding (2 bytes per character), | ||
// and the +2 to account for the length bytes | ||
let ipod_name_raw_bytes = &deviceinfo_file_as_bytes[2 .. (ipod_name_length * 2 + 2)]; | ||
|
||
println!("iPod Name: {:?}", String::from_utf16(&helpers::return_utf16_from_utf8(ipod_name_raw_bytes)).unwrap()); | ||
|
||
|
||
} | ||
// and the +2 to account for the length bytes. | ||
// no need to use helper method here because there's no index variable | ||
let ipod_name_raw_bytes = &deviceinfo_file_as_bytes[2..(ipod_name_length * 2 + 2)]; | ||
|
||
println!( | ||
"iPod Name: {:?}", | ||
String::from_utf16(&helpers::return_utf16_from_utf8(ipod_name_raw_bytes)).unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
use crate::constants::equalizer_constants; | ||
use crate::constants::itunesdb_constants; | ||
|
||
use crate::helpers::helpers; | ||
|
||
pub fn parse_equalizer_file(equalizer_file_as_bytes: Vec<u8>) { | ||
let mut idx: usize = 0; | ||
|
||
while idx < (equalizer_file_as_bytes.len() - itunesdb_constants::DEFAULT_SUBSTRUCTURE_SIZE) { | ||
let equalizer_type_heading: &[u8] = | ||
&equalizer_file_as_bytes[idx..idx + itunesdb_constants::DEFAULT_SUBSTRUCTURE_SIZE]; | ||
|
||
if equalizer_type_heading | ||
== equalizer_constants::EQUALIZER_PRESET_CONTAINER_OBJECT_KEY.as_bytes() | ||
{ | ||
let num_presets = helpers::get_slice_as_le_u32( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_NUMBER_OF_PRESETS_OFFSET, | ||
equalizer_constants::EQUALIZER_NUMBER_OF_PRESETS_LEN, | ||
); | ||
|
||
println!("Equalizer file has {} presets", num_presets); | ||
|
||
let preset_child_size = helpers::get_slice_as_le_u32( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_PRESET_CHILDSIZE_OFFSET, | ||
equalizer_constants::EQUALIZER_PRESET_CHILDSIZE_LEN, | ||
); | ||
|
||
if preset_child_size != equalizer_constants::EQUALIZER_PRESET_CHILDSIZE_VALUE as u32 { | ||
panic!("Invalid preset child size value of '{}'", preset_child_size); | ||
} | ||
|
||
println!("=========="); | ||
} else if equalizer_type_heading | ||
== equalizer_constants::EQUALIZER_PRESET_PRESET_OBJECT_KEY.as_bytes() | ||
{ | ||
let preset_name_length = helpers::build_le_u16_from_bytes( | ||
&equalizer_file_as_bytes[idx | ||
+ equalizer_constants::EQUALIZER_PRESET_PRESET_NAME_LENGTH_OFFSET | ||
..idx + equalizer_constants::EQUALIZER_PRESET_PRESET_NAME_LENGTH_OFFSET + 2], | ||
) as usize; | ||
|
||
if preset_name_length > equalizer_constants::EQUALIZER_PRESET_FIELD_MAX_LENGTH { | ||
panic!( | ||
"Invalid preset name length value of '{}'", | ||
preset_name_length | ||
); | ||
} | ||
|
||
println!("Preset Name Length: {}", preset_name_length); | ||
|
||
// Factor of 2 to account for UTF-16 encoding (2 bytes per character) | ||
let preset_name_raw_bytes = helpers::get_slice_from_offset_with_len( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_PRESET_NAME_OFFSET, | ||
preset_name_length * 2, | ||
); | ||
|
||
println!( | ||
"Preset Name: {:?}", | ||
String::from_utf16(&helpers::return_utf16_from_utf8(&preset_name_raw_bytes)) | ||
.unwrap() | ||
); | ||
|
||
let preamp = helpers::get_slice_as_le_u32( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_PREAMP_OFFSET, | ||
equalizer_constants::EQUALIZER_PREAMP_LEN, | ||
); | ||
|
||
println!("Preamp value: {}", preamp); | ||
|
||
let num_itunes_bands = helpers::get_slice_as_le_u32( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_NUM_OF_ITUNES_BANDS_OFFSET, | ||
4, | ||
); | ||
|
||
if num_itunes_bands | ||
!= equalizer_constants::EQUALIZER_NUM_OF_ITUNES_BANDS_EXPECTED_VALUE as u32 | ||
{ | ||
panic!( | ||
"Invalid number of equalizer bands value of '{}'", | ||
num_itunes_bands | ||
); | ||
} | ||
|
||
let equalizer_itunes_band_values_bytes = helpers::get_slice_from_offset_with_len( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_ITUNES_BAND_VALUES_OFFSET, | ||
equalizer_constants::EQUALIZER_ITUNES_BAND_VALUES_LEN, | ||
); | ||
|
||
for i in (0..equalizer_itunes_band_values_bytes.len()).step_by(4) { | ||
let band_value = | ||
helpers::build_le_u32_from_bytes(&equalizer_itunes_band_values_bytes[i..i + 4]) | ||
as i32; | ||
|
||
if band_value > equalizer_constants::MAX_EQUALIZER_BAND_VALUE | ||
|| band_value < equalizer_constants::MIN_EQUALIZER_BAND_VALUE | ||
{ | ||
panic!("Invalid equalizer band value of '{}'", band_value); | ||
} | ||
|
||
println!("[iTunes] Band Value: {}", band_value); | ||
} | ||
|
||
let num_dsp_bands = helpers::get_slice_as_le_u32( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_NUM_OF_DSP_BANDS_OFFSET, | ||
4, | ||
); | ||
|
||
if num_dsp_bands | ||
!= equalizer_constants::EQUALIZER_NUM_OF_DSP_BANDS_EXPECTED_VALUE as u32 | ||
{ | ||
panic!( | ||
"Invalid number of equalizer bands value of '{}'", | ||
num_dsp_bands | ||
); | ||
} | ||
|
||
let equalizer_dsp_band_values_bytes = helpers::get_slice_from_offset_with_len( | ||
idx, | ||
&equalizer_file_as_bytes, | ||
equalizer_constants::EQUALIZER_DSP_BAND_VALUES_OFFSET, | ||
equalizer_constants::EQUALIZER_DSP_BAND_VALUES_LEN, | ||
); | ||
|
||
for i in (0..equalizer_dsp_band_values_bytes.len()).step_by(4) { | ||
let band_value = | ||
helpers::build_le_u32_from_bytes(&equalizer_itunes_band_values_bytes[i..i + 4]) | ||
as i32; | ||
|
||
if band_value > equalizer_constants::MAX_EQUALIZER_BAND_VALUE | ||
|| band_value < equalizer_constants::MIN_EQUALIZER_BAND_VALUE | ||
{ | ||
panic!("Invalid equalizer band value of '{}'", band_value); | ||
} | ||
|
||
println!("[DSP] Band Value: {}", band_value); | ||
} | ||
|
||
println!("-----------"); | ||
} | ||
|
||
idx += itunesdb_constants::DEFAULT_SUBSTRUCTURE_SIZE | ||
} | ||
} |
Binary file not shown.