implement Debug for dexstring manually to show text when possible

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2024-01-27 01:07:53 +01:00
parent 0f87b75e8a
commit b1e1c530ee
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2

View file

@ -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::<String>::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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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,