WIP link offset class def

This commit is contained in:
Jean-Marie Mineau 2024-03-29 16:37:30 +01:00
parent 82c1140eae
commit a6cff22592
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
2 changed files with 46 additions and 4 deletions

View file

@ -2088,8 +2088,13 @@ impl DexFragment {
fn link_id_class_def(&mut self, string_reindex: &[u32], type_reindex: &[u32]) { fn link_id_class_def(&mut self, string_reindex: &[u32], type_reindex: &[u32]) {
self.class_def.class_idx = type_reindex[self.class_def.class_idx as usize]; self.class_def.class_idx = type_reindex[self.class_def.class_idx as usize];
if self.class_def.superclass_idx != NO_INDEX.0 {
self.class_def.superclass_idx = type_reindex[self.class_def.superclass_idx as usize]; self.class_def.superclass_idx = type_reindex[self.class_def.superclass_idx as usize];
self.class_def.source_file_idx = string_reindex[self.class_def.source_file_idx as usize]; }
if self.class_def.source_file_idx != NO_INDEX.0 {
self.class_def.source_file_idx =
string_reindex[self.class_def.source_file_idx as usize];
}
} }
fn link_id_method_handle(&mut self, field_reindex: &[u16], method_reindex: &[u16]) { fn link_id_method_handle(&mut self, field_reindex: &[u16], method_reindex: &[u16]) {
@ -2420,8 +2425,45 @@ impl DexFragment {
&self.interfaces &self.interfaces
} }
pub fn link_offsets_but_class_data(&mut self, offsets: &SectionOffsets) -> Result<()> { /// Link the offsets in the fragment except for the class_def_item.class_data_off
/// that needs the size of the linked class_data_items of the previous fragments.
pub fn link_offsets_but_class_data(
&mut self,
offsets: &SectionOffsets,
type_lists: &HashMap<Vec<IdType>, u32>,
) -> Result<()> {
self.link_state = self.link_state.start_linking_offset()?; self.link_state = self.link_state.start_linking_offset()?;
self.link_off_call_site_ids(offsets);
self.link_off_class_def(offsets, type_lists)?;
Ok(())
}
fn link_off_call_site_ids(&mut self, offsets: &SectionOffsets) {
for id in &mut self.call_site_ids {
id.call_site_off += offsets.get_offset(Section::EncodedArrayItem);
}
}
fn link_off_class_def(
&mut self,
offsets: &SectionOffsets,
type_lists: &HashMap<Vec<IdType>, u32>,
) -> Result<()> {
if self.class_def.annotations_off != 0 {
self.class_def.annotations_off +=
offsets.get_offset(Section::AnnotationsDirectoryItem) - 1;
}
if self.class_def.static_values_off != 0 {
self.class_def.static_values_off += offsets.get_offset(Section::EncodedArrayItem) - 1;
}
if !self.interfaces.is_empty() {
self.class_def.interfaces_off = offsets.get_offset(Section::TypeList)
+ type_lists.get(&self.interfaces).ok_or(anyhow!(
"Interface list {:?} not found in type list",
self.interfaces
))?;
}
// class data offset not set here
Ok(()) Ok(())
} }
} }

View file

@ -687,7 +687,7 @@ pub(crate) struct SectionOffsets {
} }
impl SectionOffsets { impl SectionOffsets {
fn get_offset(&self, section: Section) -> u32 { pub fn get_offset(&self, section: Section) -> u32 {
self.offsets[section.get_index()] self.offsets[section.get_index()]
} }