From 736c4611ac24724ff88be03c34b3d6636fd8219f Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Fri, 25 Aug 2023 11:30:09 +0200 Subject: [PATCH] add check sort --- androscalpel_serializer/src/annotation.rs | 12 ++++++++++++ androscalpel_serializer/src/array.rs | 2 ++ androscalpel_serializer/src/value.rs | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/androscalpel_serializer/src/annotation.rs b/androscalpel_serializer/src/annotation.rs index 74208da..b37303f 100644 --- a/androscalpel_serializer/src/annotation.rs +++ b/androscalpel_serializer/src/annotation.rs @@ -56,6 +56,18 @@ impl Serializable for EncodedAnnotation { for _ in 0..size { elements.push(AnnotationElement::deserialize(input)?); } + if !elements.is_empty() { + let mut idx_0 = elements[0].name_idx; + for idx_1 in elements.iter().map(|elt| elt.name_idx).skip(1) { + if idx_0 > idx_1 { + // TODO: use proper logging + println!( + "Waring while deserializing EncodedAnnotation: element must be sorted in increasing order by string_id index, found {idx_0:?} before {idx_1:?}" + ); + } + idx_0 = idx_1; + } + } Ok(Self { type_idx, elements }) } diff --git a/androscalpel_serializer/src/array.rs b/androscalpel_serializer/src/array.rs index 44b7222..52582f8 100644 --- a/androscalpel_serializer/src/array.rs +++ b/androscalpel_serializer/src/array.rs @@ -41,3 +41,5 @@ impl Serializable for EncodedArray { self.size_field().size() + self.values.iter().map(|val| val.size()).sum::() } } + +// TODO: add tests diff --git a/androscalpel_serializer/src/value.rs b/androscalpel_serializer/src/value.rs index 0baeca6..c76a59a 100644 --- a/androscalpel_serializer/src/value.rs +++ b/androscalpel_serializer/src/value.rs @@ -3,7 +3,6 @@ use crate::{EncodedAnnotation, EncodedArray, Error, ReadSeek, Result, Serializable}; use std::io::Write; -// TODO: TESTS!!! /// An encoded value of arbitrary hierachically structured data: /// https://source.android.com/docs/core/runtime/dex-format#encoding #[derive(Debug, Clone)] @@ -669,3 +668,5 @@ impl Serializable for Idx { } } } + +// TODO: TESTS!!!