mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-12-14 15:46:18 +00:00
Semi-working REL analysis & splitting
This commit is contained in:
@@ -151,8 +151,9 @@ impl AnalysisPass for FindRelCtorsDtors {
|
||||
let possible_sections = obj
|
||||
.sections
|
||||
.iter()
|
||||
.filter(|&(_, section)| {
|
||||
.filter(|&(index, section)| {
|
||||
if section.section_known
|
||||
|| state.known_sections.contains_key(&index)
|
||||
|| !matches!(section.kind, ObjSectionKind::Data | ObjSectionKind::ReadOnlyData)
|
||||
|| section.size < 4
|
||||
{
|
||||
@@ -283,3 +284,40 @@ impl AnalysisPass for FindRelCtorsDtors {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FindRelRodataData {}
|
||||
|
||||
impl AnalysisPass for FindRelRodataData {
|
||||
fn execute(state: &mut AnalyzerState, obj: &ObjInfo) -> Result<()> {
|
||||
ensure!(obj.kind == ObjKind::Relocatable);
|
||||
|
||||
match (obj.sections.by_name(".rodata")?, obj.sections.by_name(".data")?) {
|
||||
(None, None) => {}
|
||||
_ => return Ok(()),
|
||||
}
|
||||
|
||||
let possible_sections = obj
|
||||
.sections
|
||||
.iter()
|
||||
.filter(|&(index, section)| {
|
||||
!section.section_known
|
||||
&& !state.known_sections.contains_key(&index)
|
||||
&& matches!(section.kind, ObjSectionKind::Data | ObjSectionKind::ReadOnlyData)
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
if possible_sections.len() != 2 {
|
||||
log::warn!("Failed to find .rodata and .data");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::debug!("Found .rodata and .data: {:?}", possible_sections);
|
||||
let rodata_section_index = possible_sections[0].0;
|
||||
state.known_sections.insert(rodata_section_index, ".rodata".to_string());
|
||||
|
||||
let data_section_index = possible_sections[1].0;
|
||||
state.known_sections.insert(data_section_index, ".data".to_string());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user