diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index 0d2fb3b..4e9b46a 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -2328,6 +2328,24 @@ impl DexWriter { } } + /// Link the offsets of annotations_directory_item in class_def_items. + /// + /// # Warning + /// + /// Linking can only occur once all sections are entirelly generated. + fn link_annotation_directories(&mut self) { + debug!("Link the annotations_directory_item entries in class_def_items"); + for class_def in self.class_defs_list.iter_mut() { + // prelink value is set to offset in the section + 1 (to distinguish with 0) + if class_def.annotations_off != 0 { + class_def.annotations_off += self + .section_manager + .get_offset(Section::AnnotationsDirectoryItem) + - 1; + } + } + } + /// Link the offsets of static_values_off in class_def_items. /// /// # Warning @@ -2464,6 +2482,7 @@ impl DexWriter { self.link_call_site_ids(); self.link_type_list_occurences()?; self.link_class_data_occurences(); + self.link_annotation_directories(); self.link_static_values(); self.link_debug_info(); self.link_annotations(); diff --git a/androscalpel_serializer/src/file_reader.rs b/androscalpel_serializer/src/file_reader.rs index ad1a3cb..06e94a3 100644 --- a/androscalpel_serializer/src/file_reader.rs +++ b/androscalpel_serializer/src/file_reader.rs @@ -8,6 +8,7 @@ use crate::{ use log::{error, info, warn}; use std::io::{Cursor, Seek, SeekFrom}; +#[derive(Debug)] pub struct DexFileReader<'a> { data: &'a [u8], header: HeaderItem,