From 8f1d0eaf9e263f351bbc5aafe055481e23ad399b Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Fri, 18 Jul 2025 16:31:54 -0600 Subject: [PATCH] Implement custom debug for flags --- idevice/src/xpc/format.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/idevice/src/xpc/format.rs b/idevice/src/xpc/format.rs index 12a301a..c713d7c 100644 --- a/idevice/src/xpc/format.rs +++ b/idevice/src/xpc/format.rs @@ -390,7 +390,6 @@ impl From for XPCObject { } } -#[derive(Debug)] pub struct XPCMessage { pub flags: u32, pub message: Option, @@ -469,3 +468,37 @@ impl XPCMessage { Ok(out) } } + +impl std::fmt::Debug for XPCMessage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut parts = Vec::new(); + + if self.flags & 0x00000001 != 0 { + parts.push("AlwaysSet".to_string()); + } + if self.flags & 0x00000100 != 0 { + parts.push("DataFlag".to_string()); + } + if self.flags & 0x00010000 != 0 { + parts.push("WantingReply".to_string()); + } + if self.flags & 0x00400000 != 0 { + parts.push("InitHandshake".to_string()); + } + + // Check for any unknown bits (not covered by known flags) + let known_mask = 0x00000001 | 0x00000100 | 0x00010000 | 0x00400000; + let custom_bits = self.flags & !known_mask; + if custom_bits != 0 { + parts.push(format!("Custom(0x{:08X})", custom_bits)); + } + + write!( + f, + "XPCMessage {{ flags: [{}], message_id: {:?}, message: {:?} }}", + parts.join(" | "), + self.message_id, + self.message + ) + } +}