diff --git a/outdb b/outdb index 4b484ca..ebc049e 100644 Binary files a/outdb and b/outdb differ diff --git a/src/deserializer.rs b/src/deserializer.rs index 6a94aed..ca8f8d3 100644 --- a/src/deserializer.rs +++ b/src/deserializer.rs @@ -89,15 +89,13 @@ pub fn parse_bytes(data: &[u8]) -> XDatabase { let entry: StringEntry = bincode::deserialize(&data[i..i+28]).unwrap(); info!("val: {:?}", &entry); let mut bytes = Vec::new(); - + let mut h = i+header_offset; while h < i+str_end { - if data[h] != 0 { - bytes.push(data[h]); - } - h+=1; + bytes.push(u16::from_le_bytes(data[h..h+2].try_into().unwrap())); + h+=2; } - let g = String::from_utf8(bytes).unwrap(); + let g = String::from_utf16(&bytes).unwrap(); info!("str: {}", g); match &mut xdb.find_dataset(last_type).child { XSomeList::AlbumList(albums) => { diff --git a/src/main.rs b/src/main.rs index 7dc4894..402c957 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn main() { .init(); // /Users/michael/Documents/ipod/iTunes/iTunesDB - let mut f = File::open("/Users/michael/Documents/ipod/iTunes/iTunesDB").unwrap(); // D:\\Documents\\iTunes\\iTunesDB + let mut f = File::open("D:\\Documents\\iTunes\\iTunesDB").unwrap(); // D:\\Documents\\iTunes\\iTunesDB let mut buf = Vec::new(); match f.read_to_end(&mut buf) { Ok(n) => { @@ -30,7 +30,12 @@ fn main() { let mut xdb = deserializer::parse_bytes(data); //info!("XDB: {:#?}", xdb); - let unique_id = rand::thread_rng().gen_range(10..99); + + let json = serde_json::to_string_pretty(&xdb).unwrap(); + let mut f1 = File::create("output.json").unwrap(); + f1.write(json.as_bytes()); + + /* let unique_id = rand::thread_rng().gen_range(10..99); if let XSomeList::TrackList(tracks) = &mut xdb.find_dataset(1).child { /*let mut item = (*tracks.last().unwrap()).clone(); @@ -46,7 +51,7 @@ fn main() { tracks.push(item);*/ let mut item = tracks.last_mut().unwrap(); item.args.first_mut().unwrap().val = String::from("Goy next door"); - } + } */ /*if let XSomeList::Playlists(playlists) = &mut xdb.find_dataset(3).child { let playlist = playlists.last_mut().unwrap(); diff --git a/src/serializer.rs b/src/serializer.rs index 74a4f29..0da8f06 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -3,8 +3,8 @@ use log::info; use crate::{objects::{ChunkHeader, ChunkType, PlaylistItem, StringEntry}, xobjects::{XArgument, XDatabase, XLetterJump, XPlArgument, XPlaylistIndexEntry, XSomeList}}; -fn string_to_ipod16(str: &String) -> Vec { - str.as_bytes().iter().map(|b| [*b, 0x0]).flatten().collect() +fn string_to_ipod16(str: &str) -> Vec { + str.encode_utf16().map(|f| [f as u8, (f >> 8) as u8]).flatten().collect() } fn x_args_to_bytes(args: &Vec) -> Vec {