From e5b416ec63e6251c4d5efb51c066198a3ce5b7b5 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Fri, 18 Jul 2025 16:31:40 -0600 Subject: [PATCH] Correctly encode dict/array XPCObject --- idevice/src/xpc/format.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/idevice/src/xpc/format.rs b/idevice/src/xpc/format.rs index 7ae053c..12a301a 100644 --- a/idevice/src/xpc/format.rs +++ b/idevice/src/xpc/format.rs @@ -163,23 +163,27 @@ impl XPCObject { } XPCObject::Dictionary(dict) => { buf.extend_from_slice(&(XPCType::Dictionary as u32).to_le_bytes()); - buf.extend_from_slice(&0_u32.to_le_bytes()); // represents l, no idea what this is. - buf.extend_from_slice(&(dict.len() as u32).to_le_bytes()); + let mut content_buf = Vec::new(); + content_buf.extend_from_slice(&(dict.len() as u32).to_le_bytes()); for (k, v) in dict { let padding = Self::calculate_padding(k.len() + 1); - buf.extend_from_slice(k.as_bytes()); - buf.push(0); - buf.extend_from_slice(&[0].repeat(padding)); - v.encode_object(buf)?; + content_buf.extend_from_slice(k.as_bytes()); + content_buf.push(0); + content_buf.extend_from_slice(&[0].repeat(padding)); + v.encode_object(&mut content_buf)?; } + buf.extend_from_slice(&(content_buf.len() as u32).to_le_bytes()); + buf.extend_from_slice(&content_buf); } XPCObject::Array(items) => { buf.extend_from_slice(&(XPCType::Array as u32).to_le_bytes()); - buf.extend_from_slice(&0_u32.to_le_bytes()); // represents l, no idea what this is. - buf.extend_from_slice(&(items.len() as u32).to_le_bytes()); + let mut content_buf = Vec::new(); + content_buf.extend_from_slice(&(items.len() as u32).to_le_bytes()); for item in items { - item.encode_object(buf)?; + item.encode_object(&mut content_buf)?; } + buf.extend_from_slice(&(content_buf.len() as u32).to_le_bytes()); + buf.extend_from_slice(&content_buf); } XPCObject::Int64(num) => {