From 8d52c0f0c6f94afc767ed37cd63796732996f8a1 Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 12:49:42 -0300 Subject: [PATCH 1/9] Update diff.rs --- objdiff-gui/src/views/diff.rs | 75 ++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 11 deletions(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 3e52021..4bf999c 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -4,7 +4,7 @@ use objdiff_core::{ diff::{ DiffObjConfig, ObjectDiff, SymbolDiff, data::BYTES_PER_ROW, - display::{ContextItem, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind}, + display::{ContextItem, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind, display_row}, }, obj::{Object, Symbol}, }; @@ -64,6 +64,26 @@ impl<'a> DiffColumnContext<'a> { pub fn id(&self) -> Option<&str> { self.symbol.map(|(symbol, _, _)| symbol.name.as_str()) } } +/// Obtains the assembly text for a given symbol diff, suitable for copying to clipboard. +fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_config: &DiffObjConfig) -> String { + let mut asm_text = String::new(); + + for ins_row in &symbol_diff.instruction_rows { + let mut line = String::new(); + let result = display_row(obj, symbol_idx, ins_row, diff_config, |segment| { + line.push_str(&segment.text); + Ok(()) + }); + + if result.is_ok() { + asm_text.push_str(&line); + asm_text.push('\n'); + } + } + + asm_text +} + #[must_use] pub fn diff_view_ui( ui: &mut Ui, @@ -208,16 +228,35 @@ pub fn diff_view_ui( // Third row if left_ctx.has_symbol() && right_ctx.has_symbol() { - if (state.current_view == View::FunctionDiff - && ui - .button("Change target") - .on_hover_text_at_pointer("Choose a different symbol to use as the target") - .clicked() - || hotkeys::consume_change_target_shortcut(ui.ctx())) - && let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() - { - ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); - } + ui.horizontal(|ui| { + if state.current_view == View::FunctionDiff + && ui + .button("Change target") + .on_hover_text_at_pointer("Choose a different symbol to use as the target") + .clicked() + || hotkeys::consume_change_target_shortcut(ui.ctx()) + { + if let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() { + ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); + } + } + + // Copy target ASM button. + if state.current_view == View::FunctionDiff { + if let Some((_, symbol_diff, symbol_idx)) = left_ctx.symbol { + if let Some((obj, _)) = left_ctx.obj { + if ui + .button("Copy ASM") + .on_hover_text_at_pointer("Copy assembly to clipboard") + .clicked() + { + let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + ui.ctx().copy_text(asm_text); + } + } + } + } + }); } else if left_ctx.status.success && !left_ctx.has_symbol() { ui.horizontal(|ui| { let mut search = state.search.clone(); @@ -374,6 +413,20 @@ pub fn diff_view_ui( { ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone())); } + + /// Copy base ASM button. + if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol { + if let Some((obj, _)) = right_ctx.obj { + if ui + .button("Copy ASM") + .on_hover_text_at_pointer("Copy assembly to clipboard") + .clicked() + { + let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + ui.ctx().copy_text(asm_text); + } + } + } } } else if right_ctx.status.success && !right_ctx.has_symbol() { let mut search = state.search.clone(); From 0a6f8e866c9ba9c394912b168404313126a5e956 Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 12:54:39 -0300 Subject: [PATCH 2/9] Fixes --- objdiff-gui/src/views/diff.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 4bf999c..799ece7 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -71,7 +71,7 @@ fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_ for ins_row in &symbol_diff.instruction_rows { let mut line = String::new(); let result = display_row(obj, symbol_idx, ins_row, diff_config, |segment| { - line.push_str(&segment.text); + line.push_str(&segment.text.to_string()); Ok(()) }); @@ -414,7 +414,7 @@ pub fn diff_view_ui( ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone())); } - /// Copy base ASM button. + // Copy base ASM button. if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol { if let Some((obj, _)) = right_ctx.obj { if ui From 09595bc4419e6d41615a6562f7c47fb66e69f503 Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 13:01:26 -0300 Subject: [PATCH 3/9] More fixes --- objdiff-gui/src/views/diff.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 799ece7..de97c93 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -1,12 +1,15 @@ +use std::cmp::Ordering; + use egui::{Id, Layout, RichText, ScrollArea, TextEdit, Ui, Widget, text::LayoutJob}; use objdiff_core::{ build::BuildStatus, diff::{ DiffObjConfig, ObjectDiff, SymbolDiff, data::BYTES_PER_ROW, - display::{ContextItem, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind, display_row}, + display::{ContextItem, DiffText, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind, display_row}, }, - obj::{Object, Symbol}, + obj::{InstructionArgValue, Object, Symbol}, + util::ReallySigned, }; use time::format_description; @@ -71,7 +74,27 @@ fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_ for ins_row in &symbol_diff.instruction_rows { let mut line = String::new(); let result = display_row(obj, symbol_idx, ins_row, diff_config, |segment| { - line.push_str(&segment.text.to_string()); + let text = match segment.text { + DiffText::Basic(text) => text.to_string(), + DiffText::Line(num) => format!("{num} "), + DiffText::Address(addr) => format!("{addr:x}:"), + DiffText::Opcode(mnemonic, _op) => format!("{mnemonic} "), + DiffText::Argument(arg) => match arg { + InstructionArgValue::Signed(v) => format!("{:#x}", ReallySigned(v)), + InstructionArgValue::Unsigned(v) => format!("{v:#x}"), + InstructionArgValue::Opaque(v) => v.into_owned(), + }, + DiffText::BranchDest(addr) => format!("{addr:x}"), + DiffText::Symbol(sym) => sym.demangled_name.as_ref().unwrap_or(&sym.name).clone(), + DiffText::Addend(addend) => match addend.cmp(&0i64) { + Ordering::Greater => format!("+{addend:#x}"), + Ordering::Less => format!("-{:#x}", -addend), + _ => String::new(), + }, + DiffText::Spacing(n) => " ".repeat(n), + DiffText::Eol => "\n".to_string(), + }; + line.push_str(&text); Ok(()) }); From 2d5f2b865caefbec1e6cd0a0a8608b69eb755323 Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 13:05:47 -0300 Subject: [PATCH 4/9] More fixes... --- objdiff-gui/src/views/diff.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index de97c93..ba7dd04 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -91,7 +91,7 @@ fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_ Ordering::Less => format!("-{:#x}", -addend), _ => String::new(), }, - DiffText::Spacing(n) => " ".repeat(n), + DiffText::Spacing(n) => " ".repeat(n.into()), DiffText::Eol => "\n".to_string(), }; line.push_str(&text); From 35e2b35d409f4cb35d278e0b616b63e9815914b4 Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 13:19:00 -0300 Subject: [PATCH 5/9] Cargo fmt --- objdiff-gui/src/app.rs | 13 +++++---- objdiff-gui/src/app_config.rs | 12 ++++++-- objdiff-gui/src/argp_version.rs | 10 +++++-- objdiff-gui/src/hotkeys.rs | 20 +++++++++---- objdiff-gui/src/jobs.rs | 23 ++++++++++----- objdiff-gui/src/views/appearance.rs | 19 ++++++------ objdiff-gui/src/views/diff.rs | 40 ++++++++++++++++++-------- objdiff-gui/src/views/frame_history.rs | 8 ++++-- 8 files changed, 100 insertions(+), 45 deletions(-) diff --git a/objdiff-gui/src/app.rs b/objdiff-gui/src/app.rs index 71bdaa2..b356ac2 100644 --- a/objdiff-gui/src/app.rs +++ b/objdiff-gui/src/app.rs @@ -147,7 +147,9 @@ impl ObjectConfig { } #[inline] -fn bool_true() -> bool { true } +fn bool_true() -> bool { + true +} pub struct AppState { pub config: AppConfig, @@ -442,10 +444,11 @@ impl AppState { let mut job = LayoutJob::default(); job.append(context, 0.0, Default::default()); job.append("\n", 0.0, Default::default()); - job.append(&format!("{e:#}"), 0.0, egui::TextFormat { - color: egui::Color32::LIGHT_RED, - ..Default::default() - }); + job.append( + &format!("{e:#}"), + 0.0, + egui::TextFormat { color: egui::Color32::LIGHT_RED, ..Default::default() }, + ); self.top_left_toasts.error(job).closable(true).duration(None); } } diff --git a/objdiff-gui/src/app_config.rs b/objdiff-gui/src/app_config.rs index 0bbde3b..2ae20c9 100644 --- a/objdiff-gui/src/app_config.rs +++ b/objdiff-gui/src/app_config.rs @@ -19,7 +19,9 @@ pub struct AppConfigVersion { } impl Default for AppConfigVersion { - fn default() -> Self { Self { version: 3 } } + fn default() -> Self { + Self { version: 3 } + } } /// Deserialize the AppConfig from storage, handling upgrades from older versions. @@ -44,7 +46,9 @@ pub fn deserialize_config(storage: &dyn Storage) -> Option { } fn from_str(str: &str) -> Option -where T: serde::de::DeserializeOwned { +where + T: serde::de::DeserializeOwned, +{ match ron::from_str(str) { Ok(config) => Some(config), Err(err) => { @@ -292,7 +296,9 @@ impl DiffObjConfigV1 { } #[inline] -fn bool_true() -> bool { true } +fn bool_true() -> bool { + true +} #[derive(serde::Deserialize, serde::Serialize)] pub struct AppConfigV1 { diff --git a/objdiff-gui/src/argp_version.rs b/objdiff-gui/src/argp_version.rs index d9dae71..aa5d8fa 100644 --- a/objdiff-gui/src/argp_version.rs +++ b/objdiff-gui/src/argp_version.rs @@ -7,12 +7,14 @@ use std::ffi::OsStr; use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) -where T: FromArgs; +where + T: FromArgs; impl TopLevelCommand for ArgsOrVersion where T: FromArgs {} impl FromArgs for ArgsOrVersion -where T: FromArgs +where + T: FromArgs, { fn _from_args( command_name: &[&str], @@ -58,6 +60,8 @@ where T: FromArgs /// This function will exit early from the current process if argument parsing was unsuccessful or if information like `--help` was requested. /// Error messages will be printed to stderr, and `--help` output to stdout. pub fn from_env() -> T -where T: TopLevelCommand { +where + T: TopLevelCommand, +{ argp::parse_args_or_exit::>(argp::DEFAULT).0 } diff --git a/objdiff-gui/src/hotkeys.rs b/objdiff-gui/src/hotkeys.rs index 80d8d5d..ea68caa 100644 --- a/objdiff-gui/src/hotkeys.rs +++ b/objdiff-gui/src/hotkeys.rs @@ -2,7 +2,9 @@ use egui::{ Context, Key, KeyboardShortcut, Modifiers, PointerButton, style::ScrollAnimation, vec2, }; -fn any_widget_focused(ctx: &Context) -> bool { ctx.memory(|mem| mem.focused().is_some()) } +fn any_widget_focused(ctx: &Context) -> bool { + ctx.memory(|mem| mem.focused().is_some()) +} pub fn enter_pressed(ctx: &Context) -> bool { if any_widget_focused(ctx) { @@ -40,13 +42,21 @@ pub fn down_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::ArrowDown) || i.key_pressed(Key::S)) } -pub fn page_up_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageUp)) } +pub fn page_up_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| i.key_pressed(Key::PageUp)) +} -pub fn page_down_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageDown)) } +pub fn page_down_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| i.key_pressed(Key::PageDown)) +} -pub fn home_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::Home)) } +pub fn home_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| i.key_pressed(Key::Home)) +} -pub fn end_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::End)) } +pub fn end_pressed(ctx: &Context) -> bool { + ctx.input_mut(|i| i.key_pressed(Key::End)) +} pub fn check_scroll_hotkeys(ui: &mut egui::Ui, include_small_increments: bool) { let ui_height = ui.available_rect_before_wrap().height(); diff --git a/objdiff-gui/src/jobs.rs b/objdiff-gui/src/jobs.rs index acce176..1499cca 100644 --- a/objdiff-gui/src/jobs.rs +++ b/objdiff-gui/src/jobs.rs @@ -20,12 +20,18 @@ use crate::{ struct EguiWaker(egui::Context); impl Wake for EguiWaker { - fn wake(self: Arc) { self.0.request_repaint(); } + fn wake(self: Arc) { + self.0.request_repaint(); + } - fn wake_by_ref(self: &Arc) { self.0.request_repaint(); } + fn wake_by_ref(self: &Arc) { + self.0.request_repaint(); + } } -pub fn egui_waker(ctx: &egui::Context) -> Waker { Waker::from(Arc::new(EguiWaker(ctx.clone()))) } +pub fn egui_waker(ctx: &egui::Context) -> Waker { + Waker::from(Arc::new(EguiWaker(ctx.clone()))) +} pub fn is_create_scratch_available(config: &AppConfig) -> bool { let Some(selected_obj) = &config.selected_obj else { @@ -127,10 +133,13 @@ pub fn start_build(ctx: &egui::Context, jobs: &mut JobQueue, config: objdiff::Ob pub fn start_check_update(ctx: &egui::Context, jobs: &mut JobQueue) { jobs.push_once(Job::Update, || { - jobs::check_update::start_check_update(egui_waker(ctx), CheckUpdateConfig { - build_updater, - bin_names: vec![BIN_NAME_NEW.to_string(), BIN_NAME_OLD.to_string()], - }) + jobs::check_update::start_check_update( + egui_waker(ctx), + CheckUpdateConfig { + build_updater, + bin_names: vec![BIN_NAME_NEW.to_string(), BIN_NAME_OLD.to_string()], + }, + ) }); } diff --git a/objdiff-gui/src/views/appearance.rs b/objdiff-gui/src/views/appearance.rs index 3eb0932..e6b00b1 100644 --- a/objdiff-gui/src/views/appearance.rs +++ b/objdiff-gui/src/views/appearance.rs @@ -91,16 +91,19 @@ impl Default for FontState { impl Appearance { pub fn pre_update(&mut self, ctx: &egui::Context) { let mut style = ctx.style().as_ref().clone(); - style.text_styles.insert(TextStyle::Body, FontId { - size: (self.ui_font.size * 0.75).floor(), - family: self.ui_font.family.clone(), - }); + style.text_styles.insert( + TextStyle::Body, + FontId { + size: (self.ui_font.size * 0.75).floor(), + family: self.ui_font.family.clone(), + }, + ); style.text_styles.insert(TextStyle::Body, self.ui_font.clone()); style.text_styles.insert(TextStyle::Button, self.ui_font.clone()); - style.text_styles.insert(TextStyle::Heading, FontId { - size: (self.ui_font.size * 1.5).floor(), - family: self.ui_font.family.clone(), - }); + style.text_styles.insert( + TextStyle::Heading, + FontId { size: (self.ui_font.size * 1.5).floor(), family: self.ui_font.family.clone() }, + ); style.text_styles.insert(TextStyle::Monospace, self.code_font.clone()); match self.theme { egui::Theme::Dark => { diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index ba7dd04..4157f65 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -6,7 +6,10 @@ use objdiff_core::{ diff::{ DiffObjConfig, ObjectDiff, SymbolDiff, data::BYTES_PER_ROW, - display::{ContextItem, DiffText, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind, display_row}, + display::{ + ContextItem, DiffText, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind, + display_row, + }, }, obj::{InstructionArgValue, Object, Symbol}, util::ReallySigned, @@ -61,16 +64,25 @@ impl<'a> DiffColumnContext<'a> { } #[inline] - pub fn has_symbol(&self) -> bool { self.symbol.is_some() } + pub fn has_symbol(&self) -> bool { + self.symbol.is_some() + } #[inline] - pub fn id(&self) -> Option<&str> { self.symbol.map(|(symbol, _, _)| symbol.name.as_str()) } + pub fn id(&self) -> Option<&str> { + self.symbol.map(|(symbol, _, _)| symbol.name.as_str()) + } } /// Obtains the assembly text for a given symbol diff, suitable for copying to clipboard. -fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_config: &DiffObjConfig) -> String { +fn get_asm_text( + obj: &Object, + symbol_diff: &SymbolDiff, + symbol_idx: usize, + diff_config: &DiffObjConfig, +) -> String { let mut asm_text = String::new(); - + for ins_row in &symbol_diff.instruction_rows { let mut line = String::new(); let result = display_row(obj, symbol_idx, ins_row, diff_config, |segment| { @@ -97,13 +109,13 @@ fn get_asm_text(obj: &Object, symbol_diff: &SymbolDiff, symbol_idx: usize, diff_ line.push_str(&text); Ok(()) }); - + if result.is_ok() { asm_text.push_str(&line); asm_text.push('\n'); } } - + asm_text } @@ -255,7 +267,9 @@ pub fn diff_view_ui( if state.current_view == View::FunctionDiff && ui .button("Change target") - .on_hover_text_at_pointer("Choose a different symbol to use as the target") + .on_hover_text_at_pointer( + "Choose a different symbol to use as the target", + ) .clicked() || hotkeys::consume_change_target_shortcut(ui.ctx()) { @@ -263,7 +277,7 @@ pub fn diff_view_ui( ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); } } - + // Copy target ASM button. if state.current_view == View::FunctionDiff { if let Some((_, symbol_diff, symbol_idx)) = left_ctx.symbol { @@ -273,7 +287,8 @@ pub fn diff_view_ui( .on_hover_text_at_pointer("Copy assembly to clipboard") .clicked() { - let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + let asm_text = + get_asm_text(obj, symbol_diff, symbol_idx, diff_config); ui.ctx().copy_text(asm_text); } } @@ -436,7 +451,7 @@ pub fn diff_view_ui( { ret = Some(DiffViewAction::SelectingRight(symbol_ref.clone())); } - + // Copy base ASM button. if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol { if let Some((obj, _)) = right_ctx.obj { @@ -445,7 +460,8 @@ pub fn diff_view_ui( .on_hover_text_at_pointer("Copy assembly to clipboard") .clicked() { - let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + let asm_text = + get_asm_text(obj, symbol_diff, symbol_idx, diff_config); ui.ctx().copy_text(asm_text); } } diff --git a/objdiff-gui/src/views/frame_history.rs b/objdiff-gui/src/views/frame_history.rs index 523c384..762ec34 100644 --- a/objdiff-gui/src/views/frame_history.rs +++ b/objdiff-gui/src/views/frame_history.rs @@ -49,9 +49,13 @@ impl FrameHistory { self.frame_times.add(now, previous_frame_time); // projected } - pub fn mean_frame_time(&self) -> f32 { self.frame_times.average().unwrap_or_default() } + pub fn mean_frame_time(&self) -> f32 { + self.frame_times.average().unwrap_or_default() + } - pub fn fps(&self) -> f32 { 1.0 / self.frame_times.mean_time_interval().unwrap_or_default() } + pub fn fps(&self) -> f32 { + 1.0 / self.frame_times.mean_time_interval().unwrap_or_default() + } pub fn ui(&mut self, ui: &mut egui::Ui) { ui.label(format!("Mean CPU usage: {:.2} ms / frame", 1e3 * self.mean_frame_time())) From 1ca1c041b19d3a2adbac2bd01521ec03b2b6751d Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 13:22:58 -0300 Subject: [PATCH 6/9] fmt --- objdiff-cli/src/argp_version.rs | 10 +- objdiff-cli/src/cmd/diff.rs | 8 +- objdiff-core/src/arch/arm.rs | 11 +- objdiff-core/src/arch/arm64.rs | 48 +++++-- objdiff-core/src/arch/mod.rs | 46 +++++-- objdiff-core/src/arch/ppc/flow_analysis.rs | 16 ++- objdiff-core/src/arch/ppc/mod.rs | 26 ++-- objdiff-core/src/arch/superh/mod.rs | 4 +- objdiff-core/src/arch/x86.rs | 145 ++++++++++++--------- objdiff-core/src/bindings/report.rs | 27 ++-- objdiff-core/src/config/mod.rs | 8 +- objdiff-core/src/config/path.rs | 16 ++- objdiff-core/src/diff/demangler.rs | 4 +- objdiff-core/src/diff/display.rs | 36 +++-- objdiff-core/src/diff/mod.rs | 16 ++- objdiff-core/src/jobs/mod.rs | 12 +- objdiff-core/src/obj/mod.rs | 8 +- objdiff-core/src/obj/split_meta.rs | 14 +- objdiff-core/src/util.rs | 32 +++-- objdiff-wasm/src/api.rs | 48 +++++-- objdiff-wasm/src/logging.rs | 4 +- 21 files changed, 365 insertions(+), 174 deletions(-) diff --git a/objdiff-cli/src/argp_version.rs b/objdiff-cli/src/argp_version.rs index d9dae71..aa5d8fa 100644 --- a/objdiff-cli/src/argp_version.rs +++ b/objdiff-cli/src/argp_version.rs @@ -7,12 +7,14 @@ use std::ffi::OsStr; use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) -where T: FromArgs; +where + T: FromArgs; impl TopLevelCommand for ArgsOrVersion where T: FromArgs {} impl FromArgs for ArgsOrVersion -where T: FromArgs +where + T: FromArgs, { fn _from_args( command_name: &[&str], @@ -58,6 +60,8 @@ where T: FromArgs /// This function will exit early from the current process if argument parsing was unsuccessful or if information like `--help` was requested. /// Error messages will be printed to stderr, and `--help` output to stdout. pub fn from_env() -> T -where T: TopLevelCommand { +where + T: TopLevelCommand, +{ argp::parse_args_or_exit::>(argp::DEFAULT).0 } diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 177fd40..93b17e6 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -322,9 +322,13 @@ impl AppState { pub struct TermWaker(pub AtomicBool); impl Wake for TermWaker { - fn wake(self: Arc) { self.0.store(true, Ordering::Relaxed); } + fn wake(self: Arc) { + self.0.store(true, Ordering::Relaxed); + } - fn wake_by_ref(self: &Arc) { self.0.store(true, Ordering::Relaxed); } + fn wake_by_ref(self: &Arc) { + self.0.store(true, Ordering::Relaxed); + } } fn run_interactive( diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index a6bc271..33942bc 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -43,10 +43,13 @@ impl ArchArm { && s.name() == Ok(".ARM.attributes") }) { let attr_data = arm_attrs.uncompressed_data()?; - let build_attrs = BuildAttrs::new(&attr_data, match file.endianness() { - object::Endianness::Little => arm_attr::Endian::Little, - object::Endianness::Big => arm_attr::Endian::Big, - })?; + let build_attrs = BuildAttrs::new( + &attr_data, + match file.endianness() { + object::Endianness::Little => arm_attr::Endian::Little, + object::Endianness::Big => arm_attr::Endian::Big, + }, + )?; for subsection in build_attrs.subsections() { let subsection = subsection?; if !subsection.is_aeabi() { diff --git a/objdiff-core/src/arch/arm64.rs b/objdiff-core/src/arch/arm64.rs index 891a105..8450e7b 100644 --- a/objdiff-core/src/arch/arm64.rs +++ b/objdiff-core/src/arch/arm64.rs @@ -21,7 +21,9 @@ use crate::{ pub struct ArchArm64 {} impl ArchArm64 { - pub fn new(_file: &object::File) -> Result { Ok(Self {}) } + pub fn new(_file: &object::File) -> Result { + Ok(Self {}) + } } impl Arch for ArchArm64 { @@ -186,7 +188,9 @@ struct DisplayCtx<'a> { // Reworked for more structured output. The library only gives us a Display impl, and no way to // capture any of this information, so it needs to be reimplemented here. fn display_instruction(args: &mut Cb, ins: &Instruction, ctx: &mut DisplayCtx) -> &'static str -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ let mnemonic = match ins.opcode { Opcode::Invalid => return "", Opcode::UDF => "udf", @@ -2001,13 +2005,17 @@ fn condition_code(cond: u8) -> &'static str { #[inline] fn push_register(args: &mut Cb, size: SizeCode, reg: u16, sp: bool) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ push_opaque(args, reg_name(size, reg, sp)); } #[inline] fn push_shift(args: &mut Cb, style: ShiftStyle, amount: u8) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ push_opaque(args, shift_style(style)); if amount != 0 { push_plain(args, " "); @@ -2017,12 +2025,16 @@ where Cb: FnMut(InstructionPart<'static>) { #[inline] fn push_condition_code(args: &mut Cb, cond: u8) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ push_opaque(args, condition_code(cond)); } fn push_barrier(args: &mut Cb, option: u8) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ match option { 0b0001 => push_opaque(args, "oshld"), 0b0010 => push_opaque(args, "oshst"), @@ -2042,32 +2054,42 @@ where Cb: FnMut(InstructionPart<'static>) { #[inline] fn push_opaque<'a, Cb>(args: &mut Cb, text: &'a str) -where Cb: FnMut(InstructionPart<'a>) { +where + Cb: FnMut(InstructionPart<'a>), +{ args(InstructionPart::opaque(text)); } #[inline] fn push_plain(args: &mut Cb, text: &'static str) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ args(InstructionPart::basic(text)); } #[inline] fn push_separator(args: &mut Cb) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ args(InstructionPart::separator()); } #[inline] fn push_unsigned(args: &mut Cb, v: u64) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ push_plain(args, "#"); args(InstructionPart::unsigned(v)); } #[inline] fn push_signed(args: &mut Cb, v: i64) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ push_plain(args, "#"); args(InstructionPart::signed(v)); } @@ -2107,7 +2129,9 @@ fn is_reg_index_reloc(resolved: Option) -> bool { } fn push_operand(args: &mut Cb, o: &Operand, ctx: &mut DisplayCtx) -where Cb: FnMut(InstructionPart<'static>) { +where + Cb: FnMut(InstructionPart<'static>), +{ match o { Operand::Nothing => unreachable!(), Operand::PCOffset(off) => { diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 601847d..7869ddf 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -143,20 +143,26 @@ impl DataType { DataType::Float => { let bytes: [u8; 4] = bytes.try_into().unwrap(); strs.push(( - format!("{:?}f", match endian { - object::Endianness::Little => f32::from_le_bytes(bytes), - object::Endianness::Big => f32::from_be_bytes(bytes), - }), + format!( + "{:?}f", + match endian { + object::Endianness::Little => f32::from_le_bytes(bytes), + object::Endianness::Big => f32::from_be_bytes(bytes), + } + ), None, )); } DataType::Double => { let bytes: [u8; 8] = bytes.try_into().unwrap(); strs.push(( - format!("{:?}", match endian { - object::Endianness::Little => f64::from_le_bytes(bytes), - object::Endianness::Big => f64::from_be_bytes(bytes), - }), + format!( + "{:?}", + match endian { + object::Endianness::Little => f64::from_le_bytes(bytes), + object::Endianness::Big => f64::from_be_bytes(bytes), + } + ), None, )); } @@ -371,11 +377,15 @@ pub trait Arch: Any + Debug + Send + Sync { Ok(None) } - fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { None } + fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { + None + } fn data_reloc_size(&self, flags: RelocationFlags) -> usize; - fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 { address } + fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 { + address + } fn extra_symbol_flags(&self, _symbol: &object::Symbol) -> SymbolFlagSet { SymbolFlagSet::default() @@ -389,9 +399,13 @@ pub trait Arch: Any + Debug + Send + Sync { None } - fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec { Vec::new() } + fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec { + Vec::new() + } - fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec { Vec::new() } + fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec { + Vec::new() + } fn instruction_hover( &self, @@ -449,7 +463,9 @@ pub fn new_arch(object: &object::File, diff_side: DiffSide) -> Result Box { Box::new(Self {}) } + pub fn new() -> Box { + Box::new(Self {}) + } } impl Arch for ArchDummy { @@ -473,7 +489,9 @@ impl Arch for ArchDummy { Ok(()) } - fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { 0 } + fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { + 0 + } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/objdiff-core/src/arch/ppc/flow_analysis.rs b/objdiff-core/src/arch/ppc/flow_analysis.rs index 13f7273..767866d 100644 --- a/objdiff-core/src/arch/ppc/flow_analysis.rs +++ b/objdiff-core/src/arch/ppc/flow_analysis.rs @@ -175,7 +175,9 @@ impl RegisterState { impl Index for RegisterState { type Output = RegisterContent; - fn index(&self, gpr: powerpc::GPR) -> &Self::Output { &self.gpr[gpr.0 as usize] } + fn index(&self, gpr: powerpc::GPR) -> &Self::Output { + &self.gpr[gpr.0 as usize] + } } impl IndexMut for RegisterState { fn index_mut(&mut self, gpr: powerpc::GPR) -> &mut Self::Output { @@ -186,7 +188,9 @@ impl IndexMut for RegisterState { impl Index for RegisterState { type Output = RegisterContent; - fn index(&self, fpr: powerpc::FPR) -> &Self::Output { &self.fpr[fpr.0 as usize] } + fn index(&self, fpr: powerpc::FPR) -> &Self::Output { + &self.fpr[fpr.0 as usize] + } } impl IndexMut for RegisterState { fn index_mut(&mut self, fpr: powerpc::FPR) -> &mut Self::Output { @@ -296,7 +300,9 @@ impl PPCFlowAnalysisResult { self.argument_contents.insert((address, argument), value); } - fn new() -> Self { PPCFlowAnalysisResult { argument_contents: Default::default() } } + fn new() -> Self { + PPCFlowAnalysisResult { argument_contents: Default::default() } + } } impl FlowAnalysisResult for PPCFlowAnalysisResult { @@ -377,7 +383,9 @@ fn fill_registers_from_relocation( // See: https://github.com/encounter/decomp-toolkit/blob/main/src/analysis/pass.rs const SLEDS: [&str; 6] = ["_savefpr_", "_restfpr_", "_savegpr_", "_restgpr_", "_savev", "_restv"]; -fn is_sled_function(name: &str) -> bool { SLEDS.iter().any(|sled| name.starts_with(sled)) } +fn is_sled_function(name: &str) -> bool { + SLEDS.iter().any(|sled| name.starts_with(sled)) +} pub fn ppc_data_flow_analysis( obj: &Object, diff --git a/objdiff-core/src/arch/ppc/mod.rs b/objdiff-core/src/arch/ppc/mod.rs index 24f01eb..0c9cd78 100644 --- a/objdiff-core/src/arch/ppc/mod.rs +++ b/objdiff-core/src/arch/ppc/mod.rs @@ -45,7 +45,9 @@ fn is_rel_abs_arg(arg: &powerpc::Argument) -> bool { ) } -fn is_offset_arg(arg: &powerpc::Argument) -> bool { matches!(arg, powerpc::Argument::Offset(_)) } +fn is_offset_arg(arg: &powerpc::Argument) -> bool { + matches!(arg, powerpc::Argument::Offset(_)) +} #[derive(Debug)] pub struct ArchPpc { @@ -228,9 +230,10 @@ impl Arch for ArchPpc { .skip_while(|&(a, _)| a < address) .take_while(|&(a, _)| a == address) .find(|(_, reloc)| { - matches!(reloc.flags(), object::RelocationFlags::Coff { - typ: pe::IMAGE_REL_PPC_PAIR - }) + matches!( + reloc.flags(), + object::RelocationFlags::Coff { typ: pe::IMAGE_REL_PPC_PAIR } + ) }) .map_or( Ok(Some(RelocationOverride { @@ -624,12 +627,15 @@ fn decode_exception_info( }; //Add the new entry to the list - result.insert(extab_func.index().0 - 1, ExceptionInfo { - eti_symbol: make_symbol_ref(&extabindex)?, - etb_symbol: make_symbol_ref(&extab)?, - data, - dtors, - }); + result.insert( + extab_func.index().0 - 1, + ExceptionInfo { + eti_symbol: make_symbol_ref(&extabindex)?, + etb_symbol: make_symbol_ref(&extab)?, + data, + dtors, + }, + ); } Ok(Some(result)) diff --git a/objdiff-core/src/arch/superh/mod.rs b/objdiff-core/src/arch/superh/mod.rs index fe5ba9c..5bc4708 100644 --- a/objdiff-core/src/arch/superh/mod.rs +++ b/objdiff-core/src/arch/superh/mod.rs @@ -15,7 +15,9 @@ pub mod disasm; pub struct ArchSuperH {} impl ArchSuperH { - pub fn new(_file: &object::File) -> Result { Ok(Self {}) } + pub fn new(_file: &object::File) -> Result { + Ok(Self {}) + } } struct DataInfo { diff --git a/objdiff-core/src/arch/x86.rs b/objdiff-core/src/arch/x86.rs index 0e4bee1..f6604be 100644 --- a/objdiff-core/src/arch/x86.rs +++ b/objdiff-core/src/arch/x86.rs @@ -569,21 +569,24 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("dword"), - InstructionPart::basic(" "), - InstructionPart::opaque("ptr"), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("ebp"), - InstructionPart::opaque("-"), - InstructionPart::signed(152i64), - InstructionPart::basic("]"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::unsigned(0u64), - ]); + assert_eq!( + parts, + &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("dword"), + InstructionPart::basic(" "), + InstructionPart::opaque("ptr"), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("ebp"), + InstructionPart::opaque("-"), + InstructionPart::signed(152i64), + InstructionPart::basic("]"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::unsigned(0u64), + ] + ); } #[test] @@ -614,21 +617,24 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("dword"), - InstructionPart::basic(" "), - InstructionPart::opaque("ptr"), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("ebp"), - InstructionPart::opaque("-"), - InstructionPart::signed(152i64), - InstructionPart::basic("]"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::reloc(), - ]); + assert_eq!( + parts, + &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("dword"), + InstructionPart::basic(" "), + InstructionPart::opaque("ptr"), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("ebp"), + InstructionPart::opaque("-"), + InstructionPart::signed(152i64), + InstructionPart::basic("]"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::reloc(), + ] + ); } #[test] @@ -659,19 +665,22 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("eax"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("eax"), - InstructionPart::opaque("*"), - InstructionPart::signed(4), - InstructionPart::opaque("+"), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ]); + assert_eq!( + parts, + &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("eax"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("eax"), + InstructionPart::opaque("*"), + InstructionPart::signed(4), + InstructionPart::opaque("+"), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ] + ); } #[test] @@ -733,15 +742,18 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("edx"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ]); + assert_eq!( + parts, + &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("edx"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ] + ); } #[test] @@ -772,15 +784,18 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("rax"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ]); + assert_eq!( + parts, + &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("rax"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ] + ); } #[test] @@ -837,9 +852,9 @@ mod test { }, ) .unwrap(); - assert_eq!(parts, &[ - InstructionPart::opcode(".byte", OPCODE_DATA), - InstructionPart::unsigned(0xABu64), - ]); + assert_eq!( + parts, + &[InstructionPart::opcode(".byte", OPCODE_DATA), InstructionPart::unsigned(0xABu64),] + ); } } diff --git a/objdiff-core/src/bindings/report.rs b/objdiff-core/src/bindings/report.rs index 032252a..1265d0e 100644 --- a/objdiff-core/src/bindings/report.rs +++ b/objdiff-core/src/bindings/report.rs @@ -229,12 +229,15 @@ impl Report { .map(|c| c[category.id.len() + 1..].to_string()) .collect(); } - reports.push((category.id.clone(), Report { - measures: category.measures, - units: sub_units, - version: self.version, - categories: sub_categories, - })); + reports.push(( + category.id.clone(), + Report { + measures: category.measures, + units: sub_units, + version: self.version, + categories: sub_categories, + }, + )); } reports } @@ -305,7 +308,9 @@ impl AddAssign for Measures { /// Allows [collect](Iterator::collect) to be used on an iterator of [Measures]. impl FromIterator for Measures { fn from_iter(iter: T) -> Self - where T: IntoIterator { + where + T: IntoIterator, + { let mut measures = Measures::default(); for other in iter { measures += other; @@ -441,13 +446,17 @@ impl From for ReportItem { #[cfg(feature = "serde")] fn serialize_hex(x: &Option, s: S) -> Result -where S: serde::Serializer { +where + S: serde::Serializer, +{ if let Some(x) = x { s.serialize_str(&format!("{x:#x}")) } else { s.serialize_none() } } #[cfg(feature = "serde")] fn deserialize_hex<'de, D>(d: D) -> Result, D::Error> -where D: serde::Deserializer<'de> { +where + D: serde::Deserializer<'de>, +{ use serde::Deserialize; let s = String::deserialize(d)?; if s.is_empty() { diff --git a/objdiff-core/src/config/mod.rs b/objdiff-core/src/config/mod.rs index 5a279e7..9513808 100644 --- a/objdiff-core/src/config/mod.rs +++ b/objdiff-core/src/config/mod.rs @@ -52,7 +52,9 @@ pub struct ProjectConfig { impl ProjectConfig { #[inline] - pub fn units(&self) -> &[ProjectObject] { self.units.as_deref().unwrap_or_default() } + pub fn units(&self) -> &[ProjectObject] { + self.units.as_deref().unwrap_or_default() + } #[inline] pub fn progress_categories(&self) -> &[ProjectProgressCategory] { @@ -194,7 +196,9 @@ impl ProjectObject { self.metadata.as_ref().and_then(|m| m.auto_generated) } - pub fn options(&self) -> Option<&ProjectOptions> { self.options.as_ref() } + pub fn options(&self) -> Option<&ProjectOptions> { + self.options.as_ref() + } } #[derive(Default, Clone, Eq, PartialEq)] diff --git a/objdiff-core/src/config/path.rs b/objdiff-core/src/config/path.rs index 09e292b..b5cc8db 100644 --- a/objdiff-core/src/config/path.rs +++ b/objdiff-core/src/config/path.rs @@ -30,12 +30,16 @@ pub mod unix_path_serde_option { use typed_path::Utf8UnixPathBuf; pub fn serialize(path: &Option, s: S) -> Result - where S: Serializer { + where + S: Serializer, + { if let Some(path) = path { s.serialize_some(path.as_str()) } else { s.serialize_none() } } pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where D: Deserializer<'de> { + where + D: Deserializer<'de>, + { Ok(Option::::deserialize(deserializer)?.map(Utf8UnixPathBuf::from)) } } @@ -46,12 +50,16 @@ pub mod platform_path_serde_option { use typed_path::Utf8PlatformPathBuf; pub fn serialize(path: &Option, s: S) -> Result - where S: Serializer { + where + S: Serializer, + { if let Some(path) = path { s.serialize_some(path.as_str()) } else { s.serialize_none() } } pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where D: Deserializer<'de> { + where + D: Deserializer<'de>, + { Ok(Option::::deserialize(deserializer)?.map(Utf8PlatformPathBuf::from)) } } diff --git a/objdiff-core/src/diff/demangler.rs b/objdiff-core/src/diff/demangler.rs index 30b987f..0b1e7d3 100644 --- a/objdiff-core/src/diff/demangler.rs +++ b/objdiff-core/src/diff/demangler.rs @@ -47,5 +47,7 @@ impl Demangler { #[cfg(not(feature = "demangler"))] impl Demangler { - pub fn demangle(&self, _name: &str) -> Option { None } + pub fn demangle(&self, _name: &str) -> Option { + None + } } diff --git a/objdiff-core/src/diff/display.rs b/objdiff-core/src/diff/display.rs index 8d9a3fa..da0e3b8 100644 --- a/objdiff-core/src/diff/display.rs +++ b/objdiff-core/src/diff/display.rs @@ -103,45 +103,61 @@ pub enum InstructionPart<'a> { impl<'a> InstructionPart<'a> { #[inline(always)] pub fn basic(s: T) -> Self - where T: Into> { + where + T: Into>, + { InstructionPart::Basic(s.into()) } #[inline(always)] pub fn opcode(s: T, o: u16) -> Self - where T: Into> { + where + T: Into>, + { InstructionPart::Opcode(s.into(), o) } #[inline(always)] pub fn opaque(s: T) -> Self - where T: Into> { + where + T: Into>, + { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Opaque(s.into()))) } #[inline(always)] pub fn signed(v: T) -> InstructionPart<'static> - where T: Into { + where + T: Into, + { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Signed(v.into()))) } #[inline(always)] pub fn unsigned(v: T) -> InstructionPart<'static> - where T: Into { + where + T: Into, + { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Unsigned(v.into()))) } #[inline(always)] pub fn branch_dest(v: T) -> InstructionPart<'static> - where T: Into { + where + T: Into, + { InstructionPart::Arg(InstructionArg::BranchDest(v.into())) } #[inline(always)] - pub fn reloc() -> InstructionPart<'static> { InstructionPart::Arg(InstructionArg::Reloc) } + pub fn reloc() -> InstructionPart<'static> { + InstructionPart::Arg(InstructionArg::Reloc) + } #[inline(always)] - pub fn separator() -> InstructionPart<'static> { InstructionPart::Separator } + pub fn separator() -> InstructionPart<'static> { + InstructionPart::Separator + } pub fn into_static(self) -> InstructionPart<'static> { match self { @@ -338,7 +354,9 @@ impl PartialEq> for HighlightKind { } impl PartialEq for DiffText<'_> { - fn eq(&self, other: &HighlightKind) -> bool { other.eq(self) } + fn eq(&self, other: &HighlightKind) -> bool { + other.eq(self) + } } impl From<&DiffText<'_>> for HighlightKind { diff --git a/objdiff-core/src/diff/mod.rs b/objdiff-core/src/diff/mod.rs index efbe2c2..3a6654b 100644 --- a/objdiff-core/src/diff/mod.rs +++ b/objdiff-core/src/diff/mod.rs @@ -28,7 +28,9 @@ pub mod display; include!(concat!(env!("OUT_DIR"), "/config.gen.rs")); impl DiffObjConfig { - pub fn separator(&self) -> &'static str { if self.space_between_args { ", " } else { "," } } + pub fn separator(&self) -> &'static str { + if self.space_between_args { ", " } else { "," } + } } #[derive(Debug, Clone)] @@ -124,13 +126,19 @@ impl InstructionArgDiffIndex { } #[inline(always)] - pub fn get(&self) -> Option { self.0.map(|idx| idx.get() - 1) } + pub fn get(&self) -> Option { + self.0.map(|idx| idx.get() - 1) + } #[inline(always)] - pub fn is_some(&self) -> bool { self.0.is_some() } + pub fn is_some(&self) -> bool { + self.0.is_some() + } #[inline(always)] - pub fn is_none(&self) -> bool { self.0.is_none() } + pub fn is_none(&self) -> bool { + self.0.is_none() + } } #[derive(Debug, Clone)] diff --git a/objdiff-core/src/jobs/mod.rs b/objdiff-core/src/jobs/mod.rs index 4344044..ad29f2c 100644 --- a/objdiff-core/src/jobs/mod.rs +++ b/objdiff-core/src/jobs/mod.rs @@ -38,7 +38,9 @@ pub struct JobQueue { impl JobQueue { /// Adds a job to the queue. #[inline] - pub fn push(&mut self, state: JobState) { self.jobs.push(state); } + pub fn push(&mut self, state: JobState) { + self.jobs.push(state); + } /// Adds a job to the queue if a job of the given kind is not already running. #[inline] @@ -64,7 +66,9 @@ impl JobQueue { } /// Iterates over all jobs mutably. - pub fn iter_mut(&mut self) -> impl Iterator + '_ { self.jobs.iter_mut() } + pub fn iter_mut(&mut self) -> impl Iterator + '_ { + self.jobs.iter_mut() + } /// Iterates over all finished jobs, returning the job state and the result. pub fn iter_finished( @@ -95,7 +99,9 @@ impl JobQueue { } /// Removes a job from the queue given its ID. - pub fn remove(&mut self, id: usize) { self.jobs.retain(|job| job.id != id); } + pub fn remove(&mut self, id: usize) { + self.jobs.retain(|job| job.id != id); + } /// Collects the results of all finished jobs and handles any errors. pub fn collect_results(&mut self) { diff --git a/objdiff-core/src/obj/mod.rs b/objdiff-core/src/obj/mod.rs index cc91f03..668f4e7 100644 --- a/objdiff-core/src/obj/mod.rs +++ b/objdiff-core/src/obj/mod.rs @@ -90,7 +90,9 @@ pub struct SectionData(pub Vec); impl core::ops::Deref for SectionData { type Target = Vec; - fn deref(&self) -> &Self::Target { &self.0 } + fn deref(&self) -> &Self::Target { + &self.0 + } } impl fmt::Debug for SectionData { @@ -356,7 +358,9 @@ impl Object { self.flow_analysis_results.insert(key, result); } - pub fn has_flow_analysis_result(&self) -> bool { !self.flow_analysis_results.is_empty() } + pub fn has_flow_analysis_result(&self) -> bool { + !self.flow_analysis_results.is_empty() + } } #[derive(Debug, Clone, Eq, PartialEq, Hash)] diff --git a/objdiff-core/src/obj/split_meta.rs b/objdiff-core/src/obj/split_meta.rs index e4599fc..fc711c8 100644 --- a/objdiff-core/src/obj/split_meta.rs +++ b/objdiff-core/src/obj/split_meta.rs @@ -33,7 +33,9 @@ const NT_SPLIT_VIRTUAL_ADDRESSES: u32 = u32::from_be_bytes(*b"VIRT"); impl SplitMeta { pub fn from_section(section: object::Section, e: E, is_64: bool) -> Result - where E: Endian { + where + E: Endian, + { let mut result = SplitMeta::default(); let data = section.uncompressed_data().map_err(object_error)?; let mut iter = NoteIterator::new(data.as_ref(), section.align(), e, is_64)?; @@ -144,7 +146,9 @@ impl SplitMeta { /// Convert an object::read::Error to a String. #[inline] -fn object_error(err: object::read::Error) -> anyhow::Error { anyhow::Error::new(err) } +fn object_error(err: object::read::Error) -> anyhow::Error { + anyhow::Error::new(err) +} /// An ELF note entry. struct Note<'data> { @@ -156,14 +160,16 @@ struct Note<'data> { /// object::read::elf::NoteIterator is awkward to use generically, /// so wrap it in our own iterator. enum NoteIterator<'data, E> -where E: Endian +where + E: Endian, { B32(object::read::elf::NoteIterator<'data, object::elf::FileHeader32>), B64(object::read::elf::NoteIterator<'data, object::elf::FileHeader64>), } impl<'data, E> NoteIterator<'data, E> -where E: Endian +where + E: Endian, { fn new(data: &'data [u8], align: u64, e: E, is_64: bool) -> Result { Ok(if is_64 { diff --git a/objdiff-core/src/util.rs b/objdiff-core/src/util.rs index 6b08661..863e1c8 100644 --- a/objdiff-core/src/util.rs +++ b/objdiff-core/src/util.rs @@ -40,7 +40,9 @@ pub fn read_u16(obj_file: &object::File, reader: &mut &[u8]) -> Result { Ok(obj_file.endianness().read_u16(value)) } -pub fn align_size_to_4(size: usize) -> usize { (size + 3) & !3 } +pub fn align_size_to_4(size: usize) -> usize { + (size + 3) & !3 +} #[cfg(feature = "std")] pub fn align_data_to_4( @@ -54,7 +56,9 @@ pub fn align_data_to_4( Ok(()) } -pub fn align_u64_to(len: u64, align: u64) -> u64 { len + ((align - (len % align)) % align) } +pub fn align_u64_to(len: u64, align: u64) -> u64 { + len + ((align - (len % align)) % align) +} pub fn align_data_slice_to(data: &mut Vec, align: u64) { data.resize(align_u64_to(data.len() as u64, align) as usize, 0); @@ -65,14 +69,20 @@ pub fn align_data_slice_to(data: &mut Vec, align: u64) { #[derive(Copy, Clone, Debug)] pub struct RawFloat(pub f32); impl PartialEq for RawFloat { - fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() } + fn eq(&self, other: &Self) -> bool { + self.0.to_bits() == other.0.to_bits() + } } impl Eq for RawFloat {} impl Ord for RawFloat { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) } + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.0.to_bits().cmp(&other.0.to_bits()) + } } impl PartialOrd for RawFloat { - fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } } // Double where we specifically care about comparing the raw bits rather than @@ -80,12 +90,18 @@ impl PartialOrd for RawFloat { #[derive(Copy, Clone, Debug)] pub struct RawDouble(pub f64); impl PartialEq for RawDouble { - fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() } + fn eq(&self, other: &Self) -> bool { + self.0.to_bits() == other.0.to_bits() + } } impl Eq for RawDouble {} impl Ord for RawDouble { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) } + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.0.to_bits().cmp(&other.0.to_bits()) + } } impl PartialOrd for RawDouble { - fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } } diff --git a/objdiff-wasm/src/api.rs b/objdiff-wasm/src/api.rs index a4f7560..8bfcd67 100644 --- a/objdiff-wasm/src/api.rs +++ b/objdiff-wasm/src/api.rs @@ -40,9 +40,13 @@ use exports::objdiff::core::{ struct Component; impl Guest for Component { - fn init(level: logging::wasi_logging::Level) { logging::init(level); } + fn init(level: logging::wasi_logging::Level) { + logging::init(level); + } - fn version() -> String { env!("CARGO_PKG_VERSION").to_string() } + fn version() -> String { + env!("CARGO_PKG_VERSION").to_string() + } } struct ResourceObject(Rc, u64); @@ -425,7 +429,9 @@ impl From for DataDiffKind { } impl Default for DataDiffRow { - fn default() -> Self { Self { address: 0, segments: Vec::new(), relocations: Vec::new() } } + fn default() -> Self { + Self { address: 0, segments: Vec::new(), relocations: Vec::new() } + } } impl From<&diff::DataDiffRow> for DataDiffRow { @@ -549,7 +555,9 @@ impl From for InstructionDiffKind { } impl GuestDiffConfig for ResourceDiffConfig { - fn new() -> Self { Self(RefCell::new(diff::DiffObjConfig::default())) } + fn new() -> Self { + Self(RefCell::new(diff::DiffObjConfig::default())) + } fn set_property(&self, key: String, value: String) -> Result<(), String> { let id = diff::ConfigPropertyId::from_str(&key) @@ -573,13 +581,17 @@ struct ObjectCache(RefCell>); impl ObjectCache { #[inline] - const fn new() -> Self { Self(RefCell::new(Vec::new())) } + const fn new() -> Self { + Self(RefCell::new(Vec::new())) + } } impl core::ops::Deref for ObjectCache { type Target = RefCell>; - fn deref(&self) -> &Self::Target { &self.0 } + fn deref(&self) -> &Self::Target { + &self.0 + } } // Assume single-threaded environment @@ -624,7 +636,9 @@ impl GuestObject for ResourceObject { Ok(Object::new(ResourceObject(obj, hash))) } - fn hash(&self) -> u64 { self.1 } + fn hash(&self) -> u64 { + self.1 + } } impl GuestObjectDiff for ResourceObjectDiff { @@ -730,19 +744,27 @@ impl From for SymbolNavigationKind { } impl Default for InstructionDiffKind { - fn default() -> Self { Self::None } + fn default() -> Self { + Self::None + } } impl Default for InstructionDiffRow { - fn default() -> Self { Self { segments: Default::default(), diff_kind: Default::default() } } + fn default() -> Self { + Self { segments: Default::default(), diff_kind: Default::default() } + } } impl Default for SymbolKind { - fn default() -> Self { Self::Unknown } + fn default() -> Self { + Self::Unknown + } } impl Default for SymbolFlags { - fn default() -> Self { Self::empty() } + fn default() -> Self { + Self::empty() + } } impl Default for SymbolInfo { @@ -803,7 +825,9 @@ fn to_symbol_ref(display_symbol: diff::display::SectionDisplaySymbol) -> SymbolR } impl Default for SectionKind { - fn default() -> Self { Self::Unknown } + fn default() -> Self { + Self::Unknown + } } impl From for SectionKind { diff --git a/objdiff-wasm/src/logging.rs b/objdiff-wasm/src/logging.rs index 1c003aa..7cf441b 100644 --- a/objdiff-wasm/src/logging.rs +++ b/objdiff-wasm/src/logging.rs @@ -10,7 +10,9 @@ pub use wasi::logging::logging as wasi_logging; struct WasiLogger; impl log::Log for WasiLogger { - fn enabled(&self, metadata: &log::Metadata) -> bool { metadata.level() <= log::max_level() } + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() <= log::max_level() + } fn log(&self, record: &log::Record) { if !self.enabled(record.metadata()) { From 80806c6311df951f6e2f24865624d2b268c3e33d Mon Sep 17 00:00:00 2001 From: boludoz Date: Thu, 9 Oct 2025 13:35:17 -0300 Subject: [PATCH 7/9] Trim extra --- objdiff-gui/src/views/diff.rs | 56 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 4157f65..f13637a 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -111,7 +111,7 @@ fn get_asm_text( }); if result.is_ok() { - asm_text.push_str(&line); + asm_text.push_str(line.trim_end()); asm_text.push('\n'); } } @@ -264,35 +264,30 @@ pub fn diff_view_ui( // Third row if left_ctx.has_symbol() && right_ctx.has_symbol() { ui.horizontal(|ui| { - if state.current_view == View::FunctionDiff + if (state.current_view == View::FunctionDiff && ui .button("Change target") .on_hover_text_at_pointer( "Choose a different symbol to use as the target", ) .clicked() - || hotkeys::consume_change_target_shortcut(ui.ctx()) + || hotkeys::consume_change_target_shortcut(ui.ctx())) + && let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() { - if let Some(symbol_ref) = state.symbol_state.right_symbol.as_ref() { - ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); - } + ret = Some(DiffViewAction::SelectingLeft(symbol_ref.clone())); } // Copy target ASM button. - if state.current_view == View::FunctionDiff { - if let Some((_, symbol_diff, symbol_idx)) = left_ctx.symbol { - if let Some((obj, _)) = left_ctx.obj { - if ui - .button("Copy ASM") - .on_hover_text_at_pointer("Copy assembly to clipboard") - .clicked() - { - let asm_text = - get_asm_text(obj, symbol_diff, symbol_idx, diff_config); - ui.ctx().copy_text(asm_text); - } - } - } + if state.current_view == View::FunctionDiff + && let Some((_, symbol_diff, symbol_idx)) = left_ctx.symbol + && let Some((obj, _)) = left_ctx.obj + && ui + .button("Copy ASM") + .on_hover_text_at_pointer("Copy assembly to clipboard") + .clicked() + { + let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + ui.ctx().copy_text(asm_text); } }); } else if left_ctx.status.success && !left_ctx.has_symbol() { @@ -453,18 +448,15 @@ pub fn diff_view_ui( } // Copy base ASM button. - if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol { - if let Some((obj, _)) = right_ctx.obj { - if ui - .button("Copy ASM") - .on_hover_text_at_pointer("Copy assembly to clipboard") - .clicked() - { - let asm_text = - get_asm_text(obj, symbol_diff, symbol_idx, diff_config); - ui.ctx().copy_text(asm_text); - } - } + if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol + && let Some((obj, _)) = right_ctx.obj + && ui + .button("Copy ASM") + .on_hover_text_at_pointer("Copy assembly to clipboard") + .clicked() + { + let asm_text = get_asm_text(obj, symbol_diff, symbol_idx, diff_config); + ui.ctx().copy_text(asm_text); } } } else if right_ctx.status.success && !right_ctx.has_symbol() { From cfc5d94de6918f7544f3b31f6bf918572ddcd9af Mon Sep 17 00:00:00 2001 From: boludoz Date: Fri, 10 Oct 2025 15:20:46 -0300 Subject: [PATCH 8/9] cargo +nightly fmt --- objdiff-cli/src/argp_version.rs | 10 +- objdiff-cli/src/cmd/diff.rs | 8 +- objdiff-core/src/arch/arm.rs | 11 +- objdiff-core/src/arch/arm64.rs | 48 ++----- objdiff-core/src/arch/mod.rs | 46 ++----- objdiff-core/src/arch/ppc/flow_analysis.rs | 16 +-- objdiff-core/src/arch/ppc/mod.rs | 26 ++-- objdiff-core/src/arch/superh/mod.rs | 4 +- objdiff-core/src/arch/x86.rs | 145 +++++++++------------ objdiff-core/src/bindings/report.rs | 27 ++-- objdiff-core/src/config/mod.rs | 8 +- objdiff-core/src/config/path.rs | 16 +-- objdiff-core/src/diff/demangler.rs | 4 +- objdiff-core/src/diff/display.rs | 36 ++--- objdiff-core/src/diff/mod.rs | 16 +-- objdiff-core/src/jobs/mod.rs | 12 +- objdiff-core/src/obj/mod.rs | 8 +- objdiff-core/src/obj/split_meta.rs | 14 +- objdiff-core/src/util.rs | 32 ++--- objdiff-gui/src/app.rs | 13 +- objdiff-gui/src/app_config.rs | 12 +- objdiff-gui/src/argp_version.rs | 10 +- objdiff-gui/src/hotkeys.rs | 20 +-- objdiff-gui/src/jobs.rs | 23 +--- objdiff-gui/src/views/appearance.rs | 19 ++- objdiff-gui/src/views/diff.rs | 8 +- objdiff-gui/src/views/frame_history.rs | 8 +- objdiff-wasm/src/api.rs | 48 ++----- objdiff-wasm/src/logging.rs | 4 +- 29 files changed, 209 insertions(+), 443 deletions(-) diff --git a/objdiff-cli/src/argp_version.rs b/objdiff-cli/src/argp_version.rs index aa5d8fa..d9dae71 100644 --- a/objdiff-cli/src/argp_version.rs +++ b/objdiff-cli/src/argp_version.rs @@ -7,14 +7,12 @@ use std::ffi::OsStr; use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) -where - T: FromArgs; +where T: FromArgs; impl TopLevelCommand for ArgsOrVersion where T: FromArgs {} impl FromArgs for ArgsOrVersion -where - T: FromArgs, +where T: FromArgs { fn _from_args( command_name: &[&str], @@ -60,8 +58,6 @@ where /// This function will exit early from the current process if argument parsing was unsuccessful or if information like `--help` was requested. /// Error messages will be printed to stderr, and `--help` output to stdout. pub fn from_env() -> T -where - T: TopLevelCommand, -{ +where T: TopLevelCommand { argp::parse_args_or_exit::>(argp::DEFAULT).0 } diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 93b17e6..177fd40 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -322,13 +322,9 @@ impl AppState { pub struct TermWaker(pub AtomicBool); impl Wake for TermWaker { - fn wake(self: Arc) { - self.0.store(true, Ordering::Relaxed); - } + fn wake(self: Arc) { self.0.store(true, Ordering::Relaxed); } - fn wake_by_ref(self: &Arc) { - self.0.store(true, Ordering::Relaxed); - } + fn wake_by_ref(self: &Arc) { self.0.store(true, Ordering::Relaxed); } } fn run_interactive( diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index 33942bc..a6bc271 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -43,13 +43,10 @@ impl ArchArm { && s.name() == Ok(".ARM.attributes") }) { let attr_data = arm_attrs.uncompressed_data()?; - let build_attrs = BuildAttrs::new( - &attr_data, - match file.endianness() { - object::Endianness::Little => arm_attr::Endian::Little, - object::Endianness::Big => arm_attr::Endian::Big, - }, - )?; + let build_attrs = BuildAttrs::new(&attr_data, match file.endianness() { + object::Endianness::Little => arm_attr::Endian::Little, + object::Endianness::Big => arm_attr::Endian::Big, + })?; for subsection in build_attrs.subsections() { let subsection = subsection?; if !subsection.is_aeabi() { diff --git a/objdiff-core/src/arch/arm64.rs b/objdiff-core/src/arch/arm64.rs index 8450e7b..891a105 100644 --- a/objdiff-core/src/arch/arm64.rs +++ b/objdiff-core/src/arch/arm64.rs @@ -21,9 +21,7 @@ use crate::{ pub struct ArchArm64 {} impl ArchArm64 { - pub fn new(_file: &object::File) -> Result { - Ok(Self {}) - } + pub fn new(_file: &object::File) -> Result { Ok(Self {}) } } impl Arch for ArchArm64 { @@ -188,9 +186,7 @@ struct DisplayCtx<'a> { // Reworked for more structured output. The library only gives us a Display impl, and no way to // capture any of this information, so it needs to be reimplemented here. fn display_instruction(args: &mut Cb, ins: &Instruction, ctx: &mut DisplayCtx) -> &'static str -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { let mnemonic = match ins.opcode { Opcode::Invalid => return "", Opcode::UDF => "udf", @@ -2005,17 +2001,13 @@ fn condition_code(cond: u8) -> &'static str { #[inline] fn push_register(args: &mut Cb, size: SizeCode, reg: u16, sp: bool) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { push_opaque(args, reg_name(size, reg, sp)); } #[inline] fn push_shift(args: &mut Cb, style: ShiftStyle, amount: u8) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { push_opaque(args, shift_style(style)); if amount != 0 { push_plain(args, " "); @@ -2025,16 +2017,12 @@ where #[inline] fn push_condition_code(args: &mut Cb, cond: u8) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { push_opaque(args, condition_code(cond)); } fn push_barrier(args: &mut Cb, option: u8) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { match option { 0b0001 => push_opaque(args, "oshld"), 0b0010 => push_opaque(args, "oshst"), @@ -2054,42 +2042,32 @@ where #[inline] fn push_opaque<'a, Cb>(args: &mut Cb, text: &'a str) -where - Cb: FnMut(InstructionPart<'a>), -{ +where Cb: FnMut(InstructionPart<'a>) { args(InstructionPart::opaque(text)); } #[inline] fn push_plain(args: &mut Cb, text: &'static str) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { args(InstructionPart::basic(text)); } #[inline] fn push_separator(args: &mut Cb) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { args(InstructionPart::separator()); } #[inline] fn push_unsigned(args: &mut Cb, v: u64) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { push_plain(args, "#"); args(InstructionPart::unsigned(v)); } #[inline] fn push_signed(args: &mut Cb, v: i64) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { push_plain(args, "#"); args(InstructionPart::signed(v)); } @@ -2129,9 +2107,7 @@ fn is_reg_index_reloc(resolved: Option) -> bool { } fn push_operand(args: &mut Cb, o: &Operand, ctx: &mut DisplayCtx) -where - Cb: FnMut(InstructionPart<'static>), -{ +where Cb: FnMut(InstructionPart<'static>) { match o { Operand::Nothing => unreachable!(), Operand::PCOffset(off) => { diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 7869ddf..601847d 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -143,26 +143,20 @@ impl DataType { DataType::Float => { let bytes: [u8; 4] = bytes.try_into().unwrap(); strs.push(( - format!( - "{:?}f", - match endian { - object::Endianness::Little => f32::from_le_bytes(bytes), - object::Endianness::Big => f32::from_be_bytes(bytes), - } - ), + format!("{:?}f", match endian { + object::Endianness::Little => f32::from_le_bytes(bytes), + object::Endianness::Big => f32::from_be_bytes(bytes), + }), None, )); } DataType::Double => { let bytes: [u8; 8] = bytes.try_into().unwrap(); strs.push(( - format!( - "{:?}", - match endian { - object::Endianness::Little => f64::from_le_bytes(bytes), - object::Endianness::Big => f64::from_be_bytes(bytes), - } - ), + format!("{:?}", match endian { + object::Endianness::Little => f64::from_le_bytes(bytes), + object::Endianness::Big => f64::from_be_bytes(bytes), + }), None, )); } @@ -377,15 +371,11 @@ pub trait Arch: Any + Debug + Send + Sync { Ok(None) } - fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { - None - } + fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { None } fn data_reloc_size(&self, flags: RelocationFlags) -> usize; - fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 { - address - } + fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 { address } fn extra_symbol_flags(&self, _symbol: &object::Symbol) -> SymbolFlagSet { SymbolFlagSet::default() @@ -399,13 +389,9 @@ pub trait Arch: Any + Debug + Send + Sync { None } - fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec { - Vec::new() - } + fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec { Vec::new() } - fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec { - Vec::new() - } + fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec { Vec::new() } fn instruction_hover( &self, @@ -463,9 +449,7 @@ pub fn new_arch(object: &object::File, diff_side: DiffSide) -> Result Box { - Box::new(Self {}) - } + pub fn new() -> Box { Box::new(Self {}) } } impl Arch for ArchDummy { @@ -489,9 +473,7 @@ impl Arch for ArchDummy { Ok(()) } - fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { - 0 - } + fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { 0 } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/objdiff-core/src/arch/ppc/flow_analysis.rs b/objdiff-core/src/arch/ppc/flow_analysis.rs index 767866d..13f7273 100644 --- a/objdiff-core/src/arch/ppc/flow_analysis.rs +++ b/objdiff-core/src/arch/ppc/flow_analysis.rs @@ -175,9 +175,7 @@ impl RegisterState { impl Index for RegisterState { type Output = RegisterContent; - fn index(&self, gpr: powerpc::GPR) -> &Self::Output { - &self.gpr[gpr.0 as usize] - } + fn index(&self, gpr: powerpc::GPR) -> &Self::Output { &self.gpr[gpr.0 as usize] } } impl IndexMut for RegisterState { fn index_mut(&mut self, gpr: powerpc::GPR) -> &mut Self::Output { @@ -188,9 +186,7 @@ impl IndexMut for RegisterState { impl Index for RegisterState { type Output = RegisterContent; - fn index(&self, fpr: powerpc::FPR) -> &Self::Output { - &self.fpr[fpr.0 as usize] - } + fn index(&self, fpr: powerpc::FPR) -> &Self::Output { &self.fpr[fpr.0 as usize] } } impl IndexMut for RegisterState { fn index_mut(&mut self, fpr: powerpc::FPR) -> &mut Self::Output { @@ -300,9 +296,7 @@ impl PPCFlowAnalysisResult { self.argument_contents.insert((address, argument), value); } - fn new() -> Self { - PPCFlowAnalysisResult { argument_contents: Default::default() } - } + fn new() -> Self { PPCFlowAnalysisResult { argument_contents: Default::default() } } } impl FlowAnalysisResult for PPCFlowAnalysisResult { @@ -383,9 +377,7 @@ fn fill_registers_from_relocation( // See: https://github.com/encounter/decomp-toolkit/blob/main/src/analysis/pass.rs const SLEDS: [&str; 6] = ["_savefpr_", "_restfpr_", "_savegpr_", "_restgpr_", "_savev", "_restv"]; -fn is_sled_function(name: &str) -> bool { - SLEDS.iter().any(|sled| name.starts_with(sled)) -} +fn is_sled_function(name: &str) -> bool { SLEDS.iter().any(|sled| name.starts_with(sled)) } pub fn ppc_data_flow_analysis( obj: &Object, diff --git a/objdiff-core/src/arch/ppc/mod.rs b/objdiff-core/src/arch/ppc/mod.rs index 0c9cd78..24f01eb 100644 --- a/objdiff-core/src/arch/ppc/mod.rs +++ b/objdiff-core/src/arch/ppc/mod.rs @@ -45,9 +45,7 @@ fn is_rel_abs_arg(arg: &powerpc::Argument) -> bool { ) } -fn is_offset_arg(arg: &powerpc::Argument) -> bool { - matches!(arg, powerpc::Argument::Offset(_)) -} +fn is_offset_arg(arg: &powerpc::Argument) -> bool { matches!(arg, powerpc::Argument::Offset(_)) } #[derive(Debug)] pub struct ArchPpc { @@ -230,10 +228,9 @@ impl Arch for ArchPpc { .skip_while(|&(a, _)| a < address) .take_while(|&(a, _)| a == address) .find(|(_, reloc)| { - matches!( - reloc.flags(), - object::RelocationFlags::Coff { typ: pe::IMAGE_REL_PPC_PAIR } - ) + matches!(reloc.flags(), object::RelocationFlags::Coff { + typ: pe::IMAGE_REL_PPC_PAIR + }) }) .map_or( Ok(Some(RelocationOverride { @@ -627,15 +624,12 @@ fn decode_exception_info( }; //Add the new entry to the list - result.insert( - extab_func.index().0 - 1, - ExceptionInfo { - eti_symbol: make_symbol_ref(&extabindex)?, - etb_symbol: make_symbol_ref(&extab)?, - data, - dtors, - }, - ); + result.insert(extab_func.index().0 - 1, ExceptionInfo { + eti_symbol: make_symbol_ref(&extabindex)?, + etb_symbol: make_symbol_ref(&extab)?, + data, + dtors, + }); } Ok(Some(result)) diff --git a/objdiff-core/src/arch/superh/mod.rs b/objdiff-core/src/arch/superh/mod.rs index 5bc4708..fe5ba9c 100644 --- a/objdiff-core/src/arch/superh/mod.rs +++ b/objdiff-core/src/arch/superh/mod.rs @@ -15,9 +15,7 @@ pub mod disasm; pub struct ArchSuperH {} impl ArchSuperH { - pub fn new(_file: &object::File) -> Result { - Ok(Self {}) - } + pub fn new(_file: &object::File) -> Result { Ok(Self {}) } } struct DataInfo { diff --git a/objdiff-core/src/arch/x86.rs b/objdiff-core/src/arch/x86.rs index f6604be..0e4bee1 100644 --- a/objdiff-core/src/arch/x86.rs +++ b/objdiff-core/src/arch/x86.rs @@ -569,24 +569,21 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("dword"), - InstructionPart::basic(" "), - InstructionPart::opaque("ptr"), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("ebp"), - InstructionPart::opaque("-"), - InstructionPart::signed(152i64), - InstructionPart::basic("]"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::unsigned(0u64), - ] - ); + assert_eq!(parts, &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("dword"), + InstructionPart::basic(" "), + InstructionPart::opaque("ptr"), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("ebp"), + InstructionPart::opaque("-"), + InstructionPart::signed(152i64), + InstructionPart::basic("]"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::unsigned(0u64), + ]); } #[test] @@ -617,24 +614,21 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("dword"), - InstructionPart::basic(" "), - InstructionPart::opaque("ptr"), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("ebp"), - InstructionPart::opaque("-"), - InstructionPart::signed(152i64), - InstructionPart::basic("]"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::reloc(), - ] - ); + assert_eq!(parts, &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("dword"), + InstructionPart::basic(" "), + InstructionPart::opaque("ptr"), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("ebp"), + InstructionPart::opaque("-"), + InstructionPart::signed(152i64), + InstructionPart::basic("]"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::reloc(), + ]); } #[test] @@ -665,22 +659,19 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("eax"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::opaque("eax"), - InstructionPart::opaque("*"), - InstructionPart::signed(4), - InstructionPart::opaque("+"), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ] - ); + assert_eq!(parts, &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("eax"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::opaque("eax"), + InstructionPart::opaque("*"), + InstructionPart::signed(4), + InstructionPart::opaque("+"), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ]); } #[test] @@ -742,18 +733,15 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("edx"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ] - ); + assert_eq!(parts, &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("edx"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ]); } #[test] @@ -784,18 +772,15 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[ - InstructionPart::opcode("mov", opcode), - InstructionPart::opaque("rax"), - InstructionPart::basic(","), - InstructionPart::basic(" "), - InstructionPart::basic("["), - InstructionPart::reloc(), - InstructionPart::basic("]"), - ] - ); + assert_eq!(parts, &[ + InstructionPart::opcode("mov", opcode), + InstructionPart::opaque("rax"), + InstructionPart::basic(","), + InstructionPart::basic(" "), + InstructionPart::basic("["), + InstructionPart::reloc(), + InstructionPart::basic("]"), + ]); } #[test] @@ -852,9 +837,9 @@ mod test { }, ) .unwrap(); - assert_eq!( - parts, - &[InstructionPart::opcode(".byte", OPCODE_DATA), InstructionPart::unsigned(0xABu64),] - ); + assert_eq!(parts, &[ + InstructionPart::opcode(".byte", OPCODE_DATA), + InstructionPart::unsigned(0xABu64), + ]); } } diff --git a/objdiff-core/src/bindings/report.rs b/objdiff-core/src/bindings/report.rs index 1265d0e..032252a 100644 --- a/objdiff-core/src/bindings/report.rs +++ b/objdiff-core/src/bindings/report.rs @@ -229,15 +229,12 @@ impl Report { .map(|c| c[category.id.len() + 1..].to_string()) .collect(); } - reports.push(( - category.id.clone(), - Report { - measures: category.measures, - units: sub_units, - version: self.version, - categories: sub_categories, - }, - )); + reports.push((category.id.clone(), Report { + measures: category.measures, + units: sub_units, + version: self.version, + categories: sub_categories, + })); } reports } @@ -308,9 +305,7 @@ impl AddAssign for Measures { /// Allows [collect](Iterator::collect) to be used on an iterator of [Measures]. impl FromIterator for Measures { fn from_iter(iter: T) -> Self - where - T: IntoIterator, - { + where T: IntoIterator { let mut measures = Measures::default(); for other in iter { measures += other; @@ -446,17 +441,13 @@ impl From for ReportItem { #[cfg(feature = "serde")] fn serialize_hex(x: &Option, s: S) -> Result -where - S: serde::Serializer, -{ +where S: serde::Serializer { if let Some(x) = x { s.serialize_str(&format!("{x:#x}")) } else { s.serialize_none() } } #[cfg(feature = "serde")] fn deserialize_hex<'de, D>(d: D) -> Result, D::Error> -where - D: serde::Deserializer<'de>, -{ +where D: serde::Deserializer<'de> { use serde::Deserialize; let s = String::deserialize(d)?; if s.is_empty() { diff --git a/objdiff-core/src/config/mod.rs b/objdiff-core/src/config/mod.rs index 9513808..5a279e7 100644 --- a/objdiff-core/src/config/mod.rs +++ b/objdiff-core/src/config/mod.rs @@ -52,9 +52,7 @@ pub struct ProjectConfig { impl ProjectConfig { #[inline] - pub fn units(&self) -> &[ProjectObject] { - self.units.as_deref().unwrap_or_default() - } + pub fn units(&self) -> &[ProjectObject] { self.units.as_deref().unwrap_or_default() } #[inline] pub fn progress_categories(&self) -> &[ProjectProgressCategory] { @@ -196,9 +194,7 @@ impl ProjectObject { self.metadata.as_ref().and_then(|m| m.auto_generated) } - pub fn options(&self) -> Option<&ProjectOptions> { - self.options.as_ref() - } + pub fn options(&self) -> Option<&ProjectOptions> { self.options.as_ref() } } #[derive(Default, Clone, Eq, PartialEq)] diff --git a/objdiff-core/src/config/path.rs b/objdiff-core/src/config/path.rs index b5cc8db..09e292b 100644 --- a/objdiff-core/src/config/path.rs +++ b/objdiff-core/src/config/path.rs @@ -30,16 +30,12 @@ pub mod unix_path_serde_option { use typed_path::Utf8UnixPathBuf; pub fn serialize(path: &Option, s: S) -> Result - where - S: Serializer, - { + where S: Serializer { if let Some(path) = path { s.serialize_some(path.as_str()) } else { s.serialize_none() } } pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - { + where D: Deserializer<'de> { Ok(Option::::deserialize(deserializer)?.map(Utf8UnixPathBuf::from)) } } @@ -50,16 +46,12 @@ pub mod platform_path_serde_option { use typed_path::Utf8PlatformPathBuf; pub fn serialize(path: &Option, s: S) -> Result - where - S: Serializer, - { + where S: Serializer { if let Some(path) = path { s.serialize_some(path.as_str()) } else { s.serialize_none() } } pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, - { + where D: Deserializer<'de> { Ok(Option::::deserialize(deserializer)?.map(Utf8PlatformPathBuf::from)) } } diff --git a/objdiff-core/src/diff/demangler.rs b/objdiff-core/src/diff/demangler.rs index 0b1e7d3..30b987f 100644 --- a/objdiff-core/src/diff/demangler.rs +++ b/objdiff-core/src/diff/demangler.rs @@ -47,7 +47,5 @@ impl Demangler { #[cfg(not(feature = "demangler"))] impl Demangler { - pub fn demangle(&self, _name: &str) -> Option { - None - } + pub fn demangle(&self, _name: &str) -> Option { None } } diff --git a/objdiff-core/src/diff/display.rs b/objdiff-core/src/diff/display.rs index da0e3b8..8d9a3fa 100644 --- a/objdiff-core/src/diff/display.rs +++ b/objdiff-core/src/diff/display.rs @@ -103,61 +103,45 @@ pub enum InstructionPart<'a> { impl<'a> InstructionPart<'a> { #[inline(always)] pub fn basic(s: T) -> Self - where - T: Into>, - { + where T: Into> { InstructionPart::Basic(s.into()) } #[inline(always)] pub fn opcode(s: T, o: u16) -> Self - where - T: Into>, - { + where T: Into> { InstructionPart::Opcode(s.into(), o) } #[inline(always)] pub fn opaque(s: T) -> Self - where - T: Into>, - { + where T: Into> { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Opaque(s.into()))) } #[inline(always)] pub fn signed(v: T) -> InstructionPart<'static> - where - T: Into, - { + where T: Into { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Signed(v.into()))) } #[inline(always)] pub fn unsigned(v: T) -> InstructionPart<'static> - where - T: Into, - { + where T: Into { InstructionPart::Arg(InstructionArg::Value(InstructionArgValue::Unsigned(v.into()))) } #[inline(always)] pub fn branch_dest(v: T) -> InstructionPart<'static> - where - T: Into, - { + where T: Into { InstructionPart::Arg(InstructionArg::BranchDest(v.into())) } #[inline(always)] - pub fn reloc() -> InstructionPart<'static> { - InstructionPart::Arg(InstructionArg::Reloc) - } + pub fn reloc() -> InstructionPart<'static> { InstructionPart::Arg(InstructionArg::Reloc) } #[inline(always)] - pub fn separator() -> InstructionPart<'static> { - InstructionPart::Separator - } + pub fn separator() -> InstructionPart<'static> { InstructionPart::Separator } pub fn into_static(self) -> InstructionPart<'static> { match self { @@ -354,9 +338,7 @@ impl PartialEq> for HighlightKind { } impl PartialEq for DiffText<'_> { - fn eq(&self, other: &HighlightKind) -> bool { - other.eq(self) - } + fn eq(&self, other: &HighlightKind) -> bool { other.eq(self) } } impl From<&DiffText<'_>> for HighlightKind { diff --git a/objdiff-core/src/diff/mod.rs b/objdiff-core/src/diff/mod.rs index 3a6654b..efbe2c2 100644 --- a/objdiff-core/src/diff/mod.rs +++ b/objdiff-core/src/diff/mod.rs @@ -28,9 +28,7 @@ pub mod display; include!(concat!(env!("OUT_DIR"), "/config.gen.rs")); impl DiffObjConfig { - pub fn separator(&self) -> &'static str { - if self.space_between_args { ", " } else { "," } - } + pub fn separator(&self) -> &'static str { if self.space_between_args { ", " } else { "," } } } #[derive(Debug, Clone)] @@ -126,19 +124,13 @@ impl InstructionArgDiffIndex { } #[inline(always)] - pub fn get(&self) -> Option { - self.0.map(|idx| idx.get() - 1) - } + pub fn get(&self) -> Option { self.0.map(|idx| idx.get() - 1) } #[inline(always)] - pub fn is_some(&self) -> bool { - self.0.is_some() - } + pub fn is_some(&self) -> bool { self.0.is_some() } #[inline(always)] - pub fn is_none(&self) -> bool { - self.0.is_none() - } + pub fn is_none(&self) -> bool { self.0.is_none() } } #[derive(Debug, Clone)] diff --git a/objdiff-core/src/jobs/mod.rs b/objdiff-core/src/jobs/mod.rs index ad29f2c..4344044 100644 --- a/objdiff-core/src/jobs/mod.rs +++ b/objdiff-core/src/jobs/mod.rs @@ -38,9 +38,7 @@ pub struct JobQueue { impl JobQueue { /// Adds a job to the queue. #[inline] - pub fn push(&mut self, state: JobState) { - self.jobs.push(state); - } + pub fn push(&mut self, state: JobState) { self.jobs.push(state); } /// Adds a job to the queue if a job of the given kind is not already running. #[inline] @@ -66,9 +64,7 @@ impl JobQueue { } /// Iterates over all jobs mutably. - pub fn iter_mut(&mut self) -> impl Iterator + '_ { - self.jobs.iter_mut() - } + pub fn iter_mut(&mut self) -> impl Iterator + '_ { self.jobs.iter_mut() } /// Iterates over all finished jobs, returning the job state and the result. pub fn iter_finished( @@ -99,9 +95,7 @@ impl JobQueue { } /// Removes a job from the queue given its ID. - pub fn remove(&mut self, id: usize) { - self.jobs.retain(|job| job.id != id); - } + pub fn remove(&mut self, id: usize) { self.jobs.retain(|job| job.id != id); } /// Collects the results of all finished jobs and handles any errors. pub fn collect_results(&mut self) { diff --git a/objdiff-core/src/obj/mod.rs b/objdiff-core/src/obj/mod.rs index 668f4e7..cc91f03 100644 --- a/objdiff-core/src/obj/mod.rs +++ b/objdiff-core/src/obj/mod.rs @@ -90,9 +90,7 @@ pub struct SectionData(pub Vec); impl core::ops::Deref for SectionData { type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.0 - } + fn deref(&self) -> &Self::Target { &self.0 } } impl fmt::Debug for SectionData { @@ -358,9 +356,7 @@ impl Object { self.flow_analysis_results.insert(key, result); } - pub fn has_flow_analysis_result(&self) -> bool { - !self.flow_analysis_results.is_empty() - } + pub fn has_flow_analysis_result(&self) -> bool { !self.flow_analysis_results.is_empty() } } #[derive(Debug, Clone, Eq, PartialEq, Hash)] diff --git a/objdiff-core/src/obj/split_meta.rs b/objdiff-core/src/obj/split_meta.rs index fc711c8..e4599fc 100644 --- a/objdiff-core/src/obj/split_meta.rs +++ b/objdiff-core/src/obj/split_meta.rs @@ -33,9 +33,7 @@ const NT_SPLIT_VIRTUAL_ADDRESSES: u32 = u32::from_be_bytes(*b"VIRT"); impl SplitMeta { pub fn from_section(section: object::Section, e: E, is_64: bool) -> Result - where - E: Endian, - { + where E: Endian { let mut result = SplitMeta::default(); let data = section.uncompressed_data().map_err(object_error)?; let mut iter = NoteIterator::new(data.as_ref(), section.align(), e, is_64)?; @@ -146,9 +144,7 @@ impl SplitMeta { /// Convert an object::read::Error to a String. #[inline] -fn object_error(err: object::read::Error) -> anyhow::Error { - anyhow::Error::new(err) -} +fn object_error(err: object::read::Error) -> anyhow::Error { anyhow::Error::new(err) } /// An ELF note entry. struct Note<'data> { @@ -160,16 +156,14 @@ struct Note<'data> { /// object::read::elf::NoteIterator is awkward to use generically, /// so wrap it in our own iterator. enum NoteIterator<'data, E> -where - E: Endian, +where E: Endian { B32(object::read::elf::NoteIterator<'data, object::elf::FileHeader32>), B64(object::read::elf::NoteIterator<'data, object::elf::FileHeader64>), } impl<'data, E> NoteIterator<'data, E> -where - E: Endian, +where E: Endian { fn new(data: &'data [u8], align: u64, e: E, is_64: bool) -> Result { Ok(if is_64 { diff --git a/objdiff-core/src/util.rs b/objdiff-core/src/util.rs index 863e1c8..6b08661 100644 --- a/objdiff-core/src/util.rs +++ b/objdiff-core/src/util.rs @@ -40,9 +40,7 @@ pub fn read_u16(obj_file: &object::File, reader: &mut &[u8]) -> Result { Ok(obj_file.endianness().read_u16(value)) } -pub fn align_size_to_4(size: usize) -> usize { - (size + 3) & !3 -} +pub fn align_size_to_4(size: usize) -> usize { (size + 3) & !3 } #[cfg(feature = "std")] pub fn align_data_to_4( @@ -56,9 +54,7 @@ pub fn align_data_to_4( Ok(()) } -pub fn align_u64_to(len: u64, align: u64) -> u64 { - len + ((align - (len % align)) % align) -} +pub fn align_u64_to(len: u64, align: u64) -> u64 { len + ((align - (len % align)) % align) } pub fn align_data_slice_to(data: &mut Vec, align: u64) { data.resize(align_u64_to(data.len() as u64, align) as usize, 0); @@ -69,20 +65,14 @@ pub fn align_data_slice_to(data: &mut Vec, align: u64) { #[derive(Copy, Clone, Debug)] pub struct RawFloat(pub f32); impl PartialEq for RawFloat { - fn eq(&self, other: &Self) -> bool { - self.0.to_bits() == other.0.to_bits() - } + fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() } } impl Eq for RawFloat {} impl Ord for RawFloat { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.to_bits().cmp(&other.0.to_bits()) - } + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) } } impl PartialOrd for RawFloat { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } // Double where we specifically care about comparing the raw bits rather than @@ -90,18 +80,12 @@ impl PartialOrd for RawFloat { #[derive(Copy, Clone, Debug)] pub struct RawDouble(pub f64); impl PartialEq for RawDouble { - fn eq(&self, other: &Self) -> bool { - self.0.to_bits() == other.0.to_bits() - } + fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() } } impl Eq for RawDouble {} impl Ord for RawDouble { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.0.to_bits().cmp(&other.0.to_bits()) - } + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) } } impl PartialOrd for RawDouble { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } diff --git a/objdiff-gui/src/app.rs b/objdiff-gui/src/app.rs index b356ac2..71bdaa2 100644 --- a/objdiff-gui/src/app.rs +++ b/objdiff-gui/src/app.rs @@ -147,9 +147,7 @@ impl ObjectConfig { } #[inline] -fn bool_true() -> bool { - true -} +fn bool_true() -> bool { true } pub struct AppState { pub config: AppConfig, @@ -444,11 +442,10 @@ impl AppState { let mut job = LayoutJob::default(); job.append(context, 0.0, Default::default()); job.append("\n", 0.0, Default::default()); - job.append( - &format!("{e:#}"), - 0.0, - egui::TextFormat { color: egui::Color32::LIGHT_RED, ..Default::default() }, - ); + job.append(&format!("{e:#}"), 0.0, egui::TextFormat { + color: egui::Color32::LIGHT_RED, + ..Default::default() + }); self.top_left_toasts.error(job).closable(true).duration(None); } } diff --git a/objdiff-gui/src/app_config.rs b/objdiff-gui/src/app_config.rs index 2ae20c9..0bbde3b 100644 --- a/objdiff-gui/src/app_config.rs +++ b/objdiff-gui/src/app_config.rs @@ -19,9 +19,7 @@ pub struct AppConfigVersion { } impl Default for AppConfigVersion { - fn default() -> Self { - Self { version: 3 } - } + fn default() -> Self { Self { version: 3 } } } /// Deserialize the AppConfig from storage, handling upgrades from older versions. @@ -46,9 +44,7 @@ pub fn deserialize_config(storage: &dyn Storage) -> Option { } fn from_str(str: &str) -> Option -where - T: serde::de::DeserializeOwned, -{ +where T: serde::de::DeserializeOwned { match ron::from_str(str) { Ok(config) => Some(config), Err(err) => { @@ -296,9 +292,7 @@ impl DiffObjConfigV1 { } #[inline] -fn bool_true() -> bool { - true -} +fn bool_true() -> bool { true } #[derive(serde::Deserialize, serde::Serialize)] pub struct AppConfigV1 { diff --git a/objdiff-gui/src/argp_version.rs b/objdiff-gui/src/argp_version.rs index aa5d8fa..d9dae71 100644 --- a/objdiff-gui/src/argp_version.rs +++ b/objdiff-gui/src/argp_version.rs @@ -7,14 +7,12 @@ use std::ffi::OsStr; use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) -where - T: FromArgs; +where T: FromArgs; impl TopLevelCommand for ArgsOrVersion where T: FromArgs {} impl FromArgs for ArgsOrVersion -where - T: FromArgs, +where T: FromArgs { fn _from_args( command_name: &[&str], @@ -60,8 +58,6 @@ where /// This function will exit early from the current process if argument parsing was unsuccessful or if information like `--help` was requested. /// Error messages will be printed to stderr, and `--help` output to stdout. pub fn from_env() -> T -where - T: TopLevelCommand, -{ +where T: TopLevelCommand { argp::parse_args_or_exit::>(argp::DEFAULT).0 } diff --git a/objdiff-gui/src/hotkeys.rs b/objdiff-gui/src/hotkeys.rs index ea68caa..80d8d5d 100644 --- a/objdiff-gui/src/hotkeys.rs +++ b/objdiff-gui/src/hotkeys.rs @@ -2,9 +2,7 @@ use egui::{ Context, Key, KeyboardShortcut, Modifiers, PointerButton, style::ScrollAnimation, vec2, }; -fn any_widget_focused(ctx: &Context) -> bool { - ctx.memory(|mem| mem.focused().is_some()) -} +fn any_widget_focused(ctx: &Context) -> bool { ctx.memory(|mem| mem.focused().is_some()) } pub fn enter_pressed(ctx: &Context) -> bool { if any_widget_focused(ctx) { @@ -42,21 +40,13 @@ pub fn down_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::ArrowDown) || i.key_pressed(Key::S)) } -pub fn page_up_pressed(ctx: &Context) -> bool { - ctx.input_mut(|i| i.key_pressed(Key::PageUp)) -} +pub fn page_up_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageUp)) } -pub fn page_down_pressed(ctx: &Context) -> bool { - ctx.input_mut(|i| i.key_pressed(Key::PageDown)) -} +pub fn page_down_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageDown)) } -pub fn home_pressed(ctx: &Context) -> bool { - ctx.input_mut(|i| i.key_pressed(Key::Home)) -} +pub fn home_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::Home)) } -pub fn end_pressed(ctx: &Context) -> bool { - ctx.input_mut(|i| i.key_pressed(Key::End)) -} +pub fn end_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::End)) } pub fn check_scroll_hotkeys(ui: &mut egui::Ui, include_small_increments: bool) { let ui_height = ui.available_rect_before_wrap().height(); diff --git a/objdiff-gui/src/jobs.rs b/objdiff-gui/src/jobs.rs index 1499cca..acce176 100644 --- a/objdiff-gui/src/jobs.rs +++ b/objdiff-gui/src/jobs.rs @@ -20,18 +20,12 @@ use crate::{ struct EguiWaker(egui::Context); impl Wake for EguiWaker { - fn wake(self: Arc) { - self.0.request_repaint(); - } + fn wake(self: Arc) { self.0.request_repaint(); } - fn wake_by_ref(self: &Arc) { - self.0.request_repaint(); - } + fn wake_by_ref(self: &Arc) { self.0.request_repaint(); } } -pub fn egui_waker(ctx: &egui::Context) -> Waker { - Waker::from(Arc::new(EguiWaker(ctx.clone()))) -} +pub fn egui_waker(ctx: &egui::Context) -> Waker { Waker::from(Arc::new(EguiWaker(ctx.clone()))) } pub fn is_create_scratch_available(config: &AppConfig) -> bool { let Some(selected_obj) = &config.selected_obj else { @@ -133,13 +127,10 @@ pub fn start_build(ctx: &egui::Context, jobs: &mut JobQueue, config: objdiff::Ob pub fn start_check_update(ctx: &egui::Context, jobs: &mut JobQueue) { jobs.push_once(Job::Update, || { - jobs::check_update::start_check_update( - egui_waker(ctx), - CheckUpdateConfig { - build_updater, - bin_names: vec![BIN_NAME_NEW.to_string(), BIN_NAME_OLD.to_string()], - }, - ) + jobs::check_update::start_check_update(egui_waker(ctx), CheckUpdateConfig { + build_updater, + bin_names: vec![BIN_NAME_NEW.to_string(), BIN_NAME_OLD.to_string()], + }) }); } diff --git a/objdiff-gui/src/views/appearance.rs b/objdiff-gui/src/views/appearance.rs index e6b00b1..3eb0932 100644 --- a/objdiff-gui/src/views/appearance.rs +++ b/objdiff-gui/src/views/appearance.rs @@ -91,19 +91,16 @@ impl Default for FontState { impl Appearance { pub fn pre_update(&mut self, ctx: &egui::Context) { let mut style = ctx.style().as_ref().clone(); - style.text_styles.insert( - TextStyle::Body, - FontId { - size: (self.ui_font.size * 0.75).floor(), - family: self.ui_font.family.clone(), - }, - ); + style.text_styles.insert(TextStyle::Body, FontId { + size: (self.ui_font.size * 0.75).floor(), + family: self.ui_font.family.clone(), + }); style.text_styles.insert(TextStyle::Body, self.ui_font.clone()); style.text_styles.insert(TextStyle::Button, self.ui_font.clone()); - style.text_styles.insert( - TextStyle::Heading, - FontId { size: (self.ui_font.size * 1.5).floor(), family: self.ui_font.family.clone() }, - ); + style.text_styles.insert(TextStyle::Heading, FontId { + size: (self.ui_font.size * 1.5).floor(), + family: self.ui_font.family.clone(), + }); style.text_styles.insert(TextStyle::Monospace, self.code_font.clone()); match self.theme { egui::Theme::Dark => { diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index f13637a..9026d0d 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -64,14 +64,10 @@ impl<'a> DiffColumnContext<'a> { } #[inline] - pub fn has_symbol(&self) -> bool { - self.symbol.is_some() - } + pub fn has_symbol(&self) -> bool { self.symbol.is_some() } #[inline] - pub fn id(&self) -> Option<&str> { - self.symbol.map(|(symbol, _, _)| symbol.name.as_str()) - } + pub fn id(&self) -> Option<&str> { self.symbol.map(|(symbol, _, _)| symbol.name.as_str()) } } /// Obtains the assembly text for a given symbol diff, suitable for copying to clipboard. diff --git a/objdiff-gui/src/views/frame_history.rs b/objdiff-gui/src/views/frame_history.rs index 762ec34..523c384 100644 --- a/objdiff-gui/src/views/frame_history.rs +++ b/objdiff-gui/src/views/frame_history.rs @@ -49,13 +49,9 @@ impl FrameHistory { self.frame_times.add(now, previous_frame_time); // projected } - pub fn mean_frame_time(&self) -> f32 { - self.frame_times.average().unwrap_or_default() - } + pub fn mean_frame_time(&self) -> f32 { self.frame_times.average().unwrap_or_default() } - pub fn fps(&self) -> f32 { - 1.0 / self.frame_times.mean_time_interval().unwrap_or_default() - } + pub fn fps(&self) -> f32 { 1.0 / self.frame_times.mean_time_interval().unwrap_or_default() } pub fn ui(&mut self, ui: &mut egui::Ui) { ui.label(format!("Mean CPU usage: {:.2} ms / frame", 1e3 * self.mean_frame_time())) diff --git a/objdiff-wasm/src/api.rs b/objdiff-wasm/src/api.rs index 8bfcd67..a4f7560 100644 --- a/objdiff-wasm/src/api.rs +++ b/objdiff-wasm/src/api.rs @@ -40,13 +40,9 @@ use exports::objdiff::core::{ struct Component; impl Guest for Component { - fn init(level: logging::wasi_logging::Level) { - logging::init(level); - } + fn init(level: logging::wasi_logging::Level) { logging::init(level); } - fn version() -> String { - env!("CARGO_PKG_VERSION").to_string() - } + fn version() -> String { env!("CARGO_PKG_VERSION").to_string() } } struct ResourceObject(Rc, u64); @@ -429,9 +425,7 @@ impl From for DataDiffKind { } impl Default for DataDiffRow { - fn default() -> Self { - Self { address: 0, segments: Vec::new(), relocations: Vec::new() } - } + fn default() -> Self { Self { address: 0, segments: Vec::new(), relocations: Vec::new() } } } impl From<&diff::DataDiffRow> for DataDiffRow { @@ -555,9 +549,7 @@ impl From for InstructionDiffKind { } impl GuestDiffConfig for ResourceDiffConfig { - fn new() -> Self { - Self(RefCell::new(diff::DiffObjConfig::default())) - } + fn new() -> Self { Self(RefCell::new(diff::DiffObjConfig::default())) } fn set_property(&self, key: String, value: String) -> Result<(), String> { let id = diff::ConfigPropertyId::from_str(&key) @@ -581,17 +573,13 @@ struct ObjectCache(RefCell>); impl ObjectCache { #[inline] - const fn new() -> Self { - Self(RefCell::new(Vec::new())) - } + const fn new() -> Self { Self(RefCell::new(Vec::new())) } } impl core::ops::Deref for ObjectCache { type Target = RefCell>; - fn deref(&self) -> &Self::Target { - &self.0 - } + fn deref(&self) -> &Self::Target { &self.0 } } // Assume single-threaded environment @@ -636,9 +624,7 @@ impl GuestObject for ResourceObject { Ok(Object::new(ResourceObject(obj, hash))) } - fn hash(&self) -> u64 { - self.1 - } + fn hash(&self) -> u64 { self.1 } } impl GuestObjectDiff for ResourceObjectDiff { @@ -744,27 +730,19 @@ impl From for SymbolNavigationKind { } impl Default for InstructionDiffKind { - fn default() -> Self { - Self::None - } + fn default() -> Self { Self::None } } impl Default for InstructionDiffRow { - fn default() -> Self { - Self { segments: Default::default(), diff_kind: Default::default() } - } + fn default() -> Self { Self { segments: Default::default(), diff_kind: Default::default() } } } impl Default for SymbolKind { - fn default() -> Self { - Self::Unknown - } + fn default() -> Self { Self::Unknown } } impl Default for SymbolFlags { - fn default() -> Self { - Self::empty() - } + fn default() -> Self { Self::empty() } } impl Default for SymbolInfo { @@ -825,9 +803,7 @@ fn to_symbol_ref(display_symbol: diff::display::SectionDisplaySymbol) -> SymbolR } impl Default for SectionKind { - fn default() -> Self { - Self::Unknown - } + fn default() -> Self { Self::Unknown } } impl From for SectionKind { diff --git a/objdiff-wasm/src/logging.rs b/objdiff-wasm/src/logging.rs index 7cf441b..1c003aa 100644 --- a/objdiff-wasm/src/logging.rs +++ b/objdiff-wasm/src/logging.rs @@ -10,9 +10,7 @@ pub use wasi::logging::logging as wasi_logging; struct WasiLogger; impl log::Log for WasiLogger { - fn enabled(&self, metadata: &log::Metadata) -> bool { - metadata.level() <= log::max_level() - } + fn enabled(&self, metadata: &log::Metadata) -> bool { metadata.level() <= log::max_level() } fn log(&self, record: &log::Record) { if !self.enabled(record.metadata()) { From c6929ef2dfd9d774902fb8fbce6d37e7c24a5215 Mon Sep 17 00:00:00 2001 From: Franco M Date: Fri, 17 Oct 2025 21:13:22 -0300 Subject: [PATCH 9/9] Update 'Copy ASM' button text to include emoji --- objdiff-gui/src/views/diff.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 9026d0d..7478204 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -278,7 +278,7 @@ pub fn diff_view_ui( && let Some((_, symbol_diff, symbol_idx)) = left_ctx.symbol && let Some((obj, _)) = left_ctx.obj && ui - .button("Copy ASM") + .button("📋 Copy ASM") .on_hover_text_at_pointer("Copy assembly to clipboard") .clicked() { @@ -447,7 +447,7 @@ pub fn diff_view_ui( if let Some((_, symbol_diff, symbol_idx)) = right_ctx.symbol && let Some((obj, _)) = right_ctx.obj && ui - .button("Copy ASM") + .button("📋 Copy ASM") .on_hover_text_at_pointer("Copy assembly to clipboard") .clicked() {