diff --git a/src/app.rs b/src/app.rs index 3171a31..846b8b4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -81,7 +81,7 @@ impl Default for ViewConfig { pub struct SymbolReference { pub symbol_name: String, - pub section_index: usize, + pub section_name: String, } #[derive(serde::Deserialize, serde::Serialize)] diff --git a/src/views/data_diff.rs b/src/views/data_diff.rs index 0bd1a1e..eda971b 100644 --- a/src/views/data_diff.rs +++ b/src/views/data_diff.rs @@ -14,7 +14,9 @@ use crate::{ const BYTES_PER_ROW: usize = 16; fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSection> { - obj.sections.get(selected_symbol.section_index) + obj.sections.iter().find(|section| { + section.symbols.iter().any(|symbol| symbol.name == selected_symbol.symbol_name) + }) } fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) { diff --git a/src/views/function_diff.rs b/src/views/function_diff.rs index 87de16a..6e25142 100644 --- a/src/views/function_diff.rs +++ b/src/views/function_diff.rs @@ -241,8 +241,9 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) { } fn find_symbol<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSymbol> { - let section = obj.sections.get(selected_symbol.section_index)?; - section.symbols.iter().find(|s| s.name == selected_symbol.symbol_name) + obj.sections.iter().find_map(|section| { + section.symbols.iter().find(|symbol| symbol.name == selected_symbol.symbol_name) + }) } fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) { diff --git a/src/views/symbol_diff.rs b/src/views/symbol_diff.rs index 5643f18..3ccc015 100644 --- a/src/views/symbol_diff.rs +++ b/src/views/symbol_diff.rs @@ -56,7 +56,7 @@ fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol) { fn symbol_ui( ui: &mut Ui, symbol: &ObjSymbol, - section: Option<(usize, &ObjSection)>, + section: Option<&ObjSection>, highlighted_symbol: &mut Option, selected_symbol: &mut Option, current_view: &mut View, @@ -97,14 +97,18 @@ fn symbol_ui( .context_menu(|ui| symbol_context_menu_ui(ui, symbol)) .on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol)); if response.clicked() { - if let Some((section_index, section)) = section { + if let Some(section) = section { if section.kind == ObjSectionKind::Code { - *selected_symbol = - Some(SymbolReference { symbol_name: symbol.name.clone(), section_index }); + *selected_symbol = Some(SymbolReference { + symbol_name: symbol.name.clone(), + section_name: section.name.clone(), + }); *current_view = View::FunctionDiff; } else if section.kind == ObjSectionKind::Data { - *selected_symbol = - Some(SymbolReference { symbol_name: section.name.clone(), section_index }); + *selected_symbol = Some(SymbolReference { + symbol_name: section.name.clone(), + section_name: section.name.clone(), + }); *current_view = View::DataDiff; } } @@ -158,11 +162,11 @@ fn symbol_list_ui( }); } - for (section_index, section) in obj.sections.iter().enumerate() { + for section in &obj.sections { CollapsingHeader::new(format!("{} ({:x})", section.name, section.size)) .default_open(true) .show(ui, |ui| { - if section.name == ".text" && reverse_function_order { + if section.kind == ObjSectionKind::Code && reverse_function_order { for symbol in section.symbols.iter().rev() { if !symbol_matches_search(symbol, &lower_search) { continue; @@ -170,7 +174,7 @@ fn symbol_list_ui( symbol_ui( ui, symbol, - Some((section_index, section)), + Some(section), highlighted_symbol, selected_symbol, current_view, @@ -185,7 +189,7 @@ fn symbol_list_ui( symbol_ui( ui, symbol, - Some((section_index, section)), + Some(section), highlighted_symbol, selected_symbol, current_view,