From b1e1c530eea5bc6b8178159eedd86b4cf4920308 Mon Sep 17 00:00:00 2001 From: Jean-Marie 'Histausse' Mineau Date: Sat, 27 Jan 2024 01:07:53 +0100 Subject: [PATCH] implement Debug for dexstring manually to show text when possible --- androscalpel/src/dex_string.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/androscalpel/src/dex_string.rs b/androscalpel/src/dex_string.rs index adf3cf8..7115fb9 100644 --- a/androscalpel/src/dex_string.rs +++ b/androscalpel/src/dex_string.rs @@ -10,9 +10,36 @@ use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; #[pyclass] -#[derive(Clone, PartialEq, Eq, Debug, Ord, PartialOrd)] +#[derive(Clone, PartialEq, Eq, Ord, PartialOrd)] pub struct DexString(pub androscalpel_serializer::StringDataItem); +impl std::fmt::Debug for DexString { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + if let Ok(string) = TryInto::::try_into(self) { + f.write_str(&format!( + "DexString({}, {:#x})", + string, self.0.utf16_size.0 + )) + /* + f.debug_tuple("DexString") + .field(&string) + .field(&self.0.utf16_size.0) + .finish() + */ + } else { + f.write_str(&format!( + "DexString({:?}, {:#x})", + self.0.data, self.0.utf16_size.0 + )) + /*f.debug_tuple("DexString") + .field(&self.0.data) + .field(&self.0.utf16_size.0) + .finish() + */ + } + } +} + impl Serialize for DexString { fn serialize(&self, serializer: S) -> Result where @@ -41,7 +68,7 @@ enum SerdeDexString { impl From<&DexString> for SerdeDexString { fn from(DexString(string): &DexString) -> Self { if let Ok(string) = string.try_into() { - SerdeDexString::String(string) + SerdeDexString::String(string) // TODO: utf16_size is remove, is this ok? } else { let androscalpel_serializer::StringDataItem { data,