diff --git a/Cargo.toml b/Cargo.toml index ed0eb7c..79b3e7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "objdiff-gui", "objdiff-wasm", ] -resolver = "2" +resolver = "3" [profile.release-lto] inherits = "release" @@ -16,7 +16,7 @@ codegen-units = 1 [workspace.package] version = "3.0.0-beta.1" authors = ["Luke Street "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/encounter/objdiff" -rust-version = "1.82" +rust-version = "1.85" diff --git a/objdiff-cli/src/argp_version.rs b/objdiff-cli/src/argp_version.rs index ee371e0..d9dae71 100644 --- a/objdiff-cli/src/argp_version.rs +++ b/objdiff-cli/src/argp_version.rs @@ -4,7 +4,7 @@ //! For now, this only adds a --version/-V option which causes early-exit. use std::ffi::OsStr; -use argp::{parser::ParseGlobalOptions, EarlyExit, FromArgs, TopLevelCommand}; +use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) where T: FromArgs; diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 175e616..05afd9c 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -3,40 +3,39 @@ use std::{ mem, str::FromStr, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, task::{Wake, Waker}, time::Duration, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use argp::FromArgs; use crossterm::{ event, event::{DisableMouseCapture, EnableMouseCapture}, terminal::{ - disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, SetTitle, + EnterAlternateScreen, LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode, }, }; use objdiff_core::{ bindings::diff::DiffResult, build::{ - watcher::{create_watcher, Watcher}, BuildConfig, + watcher::{Watcher, create_watcher}, }, config::{ - build_globset, + ProjectConfig, ProjectObject, ProjectObjectMetadata, build_globset, path::{check_path_buf, platform_path, platform_path_serde_option}, - ProjectConfig, ProjectObject, ProjectObjectMetadata, }, diff::{ self, ConfigEnum, ConfigPropertyId, ConfigPropertyKind, DiffObjConfig, MappingConfig, ObjectDiff, }, jobs::{ - objdiff::{start_build, ObjDiffConfig}, Job, JobQueue, JobResult, + objdiff::{ObjDiffConfig, start_build}, }, obj::{self, Object}, }; @@ -45,10 +44,10 @@ use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf}; use crate::{ util::{ - output::{write_output, OutputFormat}, + output::{OutputFormat, write_output}, term::crossterm_panic_handler, }, - views::{function_diff::FunctionDiffUi, EventControlFlow, EventResult, UiView}, + views::{EventControlFlow, EventResult, UiView, function_diff::FunctionDiffUi}, }; #[derive(FromArgs, PartialEq, Debug)] @@ -426,15 +425,17 @@ fn run_interactive( let mut result = EventResult { redraw: true, ..Default::default() }; 'outer: loop { if result.redraw { - terminal.draw(|f| loop { - result.redraw = false; - view.draw(&state, f, &mut result); - result.click_xy = None; - if !result.redraw { - break; + terminal.draw(|f| { + loop { + result.redraw = false; + view.draw(&state, f, &mut result); + result.click_xy = None; + if !result.redraw { + break; + } + // Clear buffer on redraw + f.buffer_mut().reset(); } - // Clear buffer on redraw - f.buffer_mut().reset(); })?; } loop { diff --git a/objdiff-cli/src/cmd/report.rs b/objdiff-cli/src/cmd/report.rs index b20c033..be82667 100644 --- a/objdiff-cli/src/cmd/report.rs +++ b/objdiff-cli/src/cmd/report.rs @@ -1,12 +1,11 @@ use std::{collections::HashSet, fs::File, io::Read, time::Instant}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use argp::FromArgs; use objdiff_core::{ bindings::report::{ - ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, Report, - ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata, - REPORT_VERSION, + ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, REPORT_VERSION, + Report, ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata, }, config::path::platform_path, diff, obj, @@ -19,7 +18,7 @@ use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf}; use crate::{ cmd::diff::ObjectConfig, - util::output::{write_output, OutputFormat}, + util::output::{OutputFormat, write_output}, }; #[derive(FromArgs, PartialEq, Debug)] @@ -206,11 +205,7 @@ fn report_object( let section_match_percent = section_diff.match_percent.unwrap_or_else(|| { // Support cases where we don't have a target object, // assume complete means 100% match - if object.complete.unwrap_or(false) { - 100.0 - } else { - 0.0 - } + if object.complete.unwrap_or(false) { 100.0 } else { 0.0 } }); sections.push(ReportItem { name: section.name.clone(), @@ -251,11 +246,7 @@ fn report_object( let match_percent = symbol_diff.match_percent.unwrap_or_else(|| { // Support cases where we don't have a target object, // assume complete means 100% match - if object.complete.unwrap_or(false) { - 100.0 - } else { - 0.0 - } + if object.complete.unwrap_or(false) { 100.0 } else { 0.0 } }); measures.fuzzy_match_percent += match_percent * symbol.size as f32; measures.total_code += symbol.size; diff --git a/objdiff-cli/src/main.rs b/objdiff-cli/src/main.rs index bcd5c24..065f80d 100644 --- a/objdiff-cli/src/main.rs +++ b/objdiff-cli/src/main.rs @@ -17,7 +17,7 @@ use anyhow::{Error, Result}; use argp::{FromArgValue, FromArgs}; use enable_ansi_support::enable_ansi_support; use supports_color::Stream; -use tracing_subscriber::{filter::LevelFilter, EnvFilter}; +use tracing_subscriber::{EnvFilter, filter::LevelFilter}; #[derive(Debug, Eq, PartialEq, Copy, Clone)] enum LogLevel { diff --git a/objdiff-cli/src/util/output.rs b/objdiff-cli/src/util/output.rs index c08eee9..bdcb40d 100644 --- a/objdiff-cli/src/util/output.rs +++ b/objdiff-cli/src/util/output.rs @@ -5,7 +5,7 @@ use std::{ path::Path, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use tracing::info; #[derive(Debug, Copy, Clone, PartialEq, Eq, Default)] diff --git a/objdiff-cli/src/util/term.rs b/objdiff-cli/src/util/term.rs index 97bf6b5..cd702cb 100644 --- a/objdiff-cli/src/util/term.rs +++ b/objdiff-cli/src/util/term.rs @@ -3,7 +3,7 @@ use std::{io::stdout, panic}; use crossterm::{ cursor::Show, event::DisableMouseCapture, - terminal::{disable_raw_mode, LeaveAlternateScreen}, + terminal::{LeaveAlternateScreen, disable_raw_mode}, }; pub fn crossterm_panic_handler() { diff --git a/objdiff-cli/src/views/function_diff.rs b/objdiff-cli/src/views/function_diff.rs index 6cbd113..b41ae1e 100644 --- a/objdiff-cli/src/views/function_diff.rs +++ b/objdiff-cli/src/views/function_diff.rs @@ -1,18 +1,18 @@ use core::cmp::Ordering; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind}; use objdiff_core::{ diff::{ - display::{display_row, DiffText, DiffTextColor, HighlightKind}, DiffObjConfig, FunctionRelocDiffs, InstructionDiffKind, ObjectDiff, SymbolDiff, + display::{DiffText, DiffTextColor, HighlightKind, display_row}, }, obj::Object, }; use ratatui::{ + Frame, prelude::*, widgets::{Block, Borders, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState}, - Frame, }; use super::{EventControlFlow, EventResult, UiView}; diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index 3a489a8..9750a68 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -5,14 +5,14 @@ use alloc::{ vec::Vec, }; -use anyhow::{bail, Result}; -use arm_attr::{enums::CpuArch, tag::Tag, BuildAttrs}; -use object::{elf, Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _}; +use anyhow::{Result, bail}; +use arm_attr::{BuildAttrs, enums::CpuArch, tag::Tag}; +use object::{Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _, elf}; use unarm::{args, arm, thumb}; use crate::{ arch::Arch, - diff::{display::InstructionPart, ArmArchVersion, ArmR9Usage, DiffObjConfig}, + diff::{ArmArchVersion, ArmR9Usage, DiffObjConfig, display::InstructionPart}, obj::{ InstructionRef, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation, ScannedInstruction, SymbolFlag, SymbolFlagSet, SymbolKind, @@ -58,11 +58,7 @@ impl ArchArm { } // Only checking first CpuArch tag. Others may exist, but that's very unlikely. let cpu_arch = subsection.into_public_tag_iter()?.find_map(|(_, tag)| { - if let Tag::CpuArch(cpu_arch) = tag { - Some(cpu_arch) - } else { - None - } + if let Tag::CpuArch(cpu_arch) = tag { Some(cpu_arch) } else { None } }); match cpu_arch { Some(CpuArch::V4T) => return Ok(Some(unarm::ArmVersion::V4T)), @@ -358,11 +354,7 @@ impl Arch for ArchArm { } fn symbol_address(&self, address: u64, kind: SymbolKind) -> u64 { - if kind == SymbolKind::Function { - address & !1 - } else { - address - } + if kind == SymbolKind::Function { address & !1 } else { address } } fn extra_symbol_flags(&self, symbol: &object::Symbol) -> SymbolFlagSet { diff --git a/objdiff-core/src/arch/arm64.rs b/objdiff-core/src/arch/arm64.rs index bc21a65..7474e49 100644 --- a/objdiff-core/src/arch/arm64.rs +++ b/objdiff-core/src/arch/arm64.rs @@ -5,7 +5,7 @@ use alloc::{ }; use core::cmp::Ordering; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use object::elf; use yaxpeax_arch::{Arch as YaxpeaxArch, Decoder, Reader, U8Reader}; use yaxpeax_arm::armv8::a64::{ @@ -15,7 +15,7 @@ use yaxpeax_arm::armv8::a64::{ use crate::{ arch::Arch, - diff::{display::InstructionPart, DiffObjConfig}, + diff::{DiffObjConfig, display::InstructionPart}, obj::{ InstructionRef, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation, ScannedInstruction, @@ -216,11 +216,7 @@ where Cb: FnMut(InstructionPart<'static>) { unreachable!("movn operand 1 is always ImmShift"); }; let imm = if let Operand::Register(size, _) = ins.operands[0] { - if size == SizeCode::W { - imm as u32 as u64 - } else { - imm - } + if size == SizeCode::W { imm as u32 as u64 } else { imm } } else { unreachable!("movn operand 0 is always Register"); }; @@ -237,11 +233,7 @@ where Cb: FnMut(InstructionPart<'static>) { unreachable!("movz operand is always ImmShift"); }; let imm = if let Operand::Register(size, _) = ins.operands[0] { - if size == SizeCode::W { - imm as u32 as u64 - } else { - imm - } + if size == SizeCode::W { imm as u32 as u64 } else { imm } } else { unreachable!("movz operand 0 is always Register"); }; @@ -574,11 +566,7 @@ where Cb: FnMut(InstructionPart<'static>) { { if immr < imms { let size = if let Operand::Register(size, _) = ins.operands[0] { - if size == SizeCode::W { - 32 - } else { - 64 - } + if size == SizeCode::W { 32 } else { 64 } } else { unreachable!("operand 0 is always a register"); }; diff --git a/objdiff-core/src/arch/mips.rs b/objdiff-core/src/arch/mips.rs index aa99090..fdf5914 100644 --- a/objdiff-core/src/arch/mips.rs +++ b/objdiff-core/src/arch/mips.rs @@ -1,18 +1,18 @@ use alloc::{collections::BTreeMap, string::ToString, vec::Vec}; use core::ops::Range; -use anyhow::{bail, Result}; -use object::{elf, Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _}; +use anyhow::{Result, bail}; +use object::{Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _, elf}; use rabbitizer::{ - abi::Abi, - operands::{ValuedOperand, IU16}, - registers_meta::Register, IsaExtension, IsaVersion, Vram, + abi::Abi, + operands::{IU16, ValuedOperand}, + registers_meta::Register, }; use crate::{ arch::Arch, - diff::{display::InstructionPart, DiffObjConfig, MipsAbi, MipsInstrCategory}, + diff::{DiffObjConfig, MipsAbi, MipsInstrCategory, display::InstructionPart}, obj::{ InstructionArg, InstructionArgValue, InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation, ScannedInstruction, diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index fb592de..f9b0d13 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -1,13 +1,13 @@ use alloc::{borrow::Cow, boxed::Box, format, string::String, vec::Vec}; use core::{ffi::CStr, fmt, fmt::Debug}; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use object::Endian as _; use crate::{ diff::{ - display::{ContextItem, HoverItem, InstructionPart}, DiffObjConfig, + display::{ContextItem, HoverItem, InstructionPart}, }, obj::{ InstructionArg, Object, ParsedInstruction, Relocation, RelocationFlags, @@ -66,7 +66,9 @@ impl DataType { pub fn display_literals(&self, endian: object::Endianness, bytes: &[u8]) -> Vec { let mut strs = Vec::new(); if self.required_len().is_some_and(|l| bytes.len() < l) { - log::warn!("Failed to display a symbol value for a symbol whose size is too small for instruction referencing it."); + log::warn!( + "Failed to display a symbol value for a symbol whose size is too small for instruction referencing it." + ); return strs; } let mut bytes = bytes; diff --git a/objdiff-core/src/arch/ppc.rs b/objdiff-core/src/arch/ppc.rs index e24a208..ee3e153 100644 --- a/objdiff-core/src/arch/ppc.rs +++ b/objdiff-core/src/arch/ppc.rs @@ -5,17 +5,17 @@ use alloc::{ vec::Vec, }; -use anyhow::{bail, ensure, Result}; -use cwextab::{decode_extab, ExceptionTableData}; +use anyhow::{Result, bail, ensure}; +use cwextab::{ExceptionTableData, decode_extab}; use flagset::Flags; -use object::{elf, Object as _, ObjectSection as _, ObjectSymbol as _}; +use object::{Object as _, ObjectSection as _, ObjectSymbol as _, elf}; use crate::{ arch::{Arch, DataType}, diff::{ + DiffObjConfig, data::resolve_relocation, display::{ContextItem, HoverItem, HoverItemColor, InstructionPart, SymbolNavigationKind}, - DiffObjConfig, }, obj::{ InstructionRef, Object, Relocation, RelocationFlags, ResolvedInstructionRef, @@ -826,8 +826,8 @@ fn generate_fake_pool_relocations_for_function( for unseen_addr in unseen_addrs { let prev_bctr_gpr_state = gpr_state_at_bctr .iter() - .filter(|(&addr, _)| addr < unseen_addr) - .min_by_key(|(&addr, _)| addr) + .filter(|&(&addr, _)| addr < unseen_addr) + .min_by_key(|&(&addr, _)| addr) .map(|(_, gpr_state)| gpr_state); if let Some(gpr_pool_relocs) = prev_bctr_gpr_state { let dest_offset_into_func = unseen_addr - func_address as u32; diff --git a/objdiff-core/src/arch/x86.rs b/objdiff-core/src/arch/x86.rs index 37ebe40..c17ab2d 100644 --- a/objdiff-core/src/arch/x86.rs +++ b/objdiff-core/src/arch/x86.rs @@ -1,15 +1,15 @@ use alloc::{boxed::Box, string::String, vec::Vec}; -use anyhow::{anyhow, bail, Result}; +use anyhow::{Result, anyhow, bail}; use iced_x86::{ Decoder, DecoderOptions, DecoratorKind, FormatterOutput, FormatterTextKind, GasFormatter, Instruction, IntelFormatter, MasmFormatter, NasmFormatter, NumberKind, OpKind, Register, }; -use object::{pe, Endian as _, Object as _, ObjectSection as _}; +use object::{Endian as _, Object as _, ObjectSection as _, pe}; use crate::{ arch::Arch, - diff::{display::InstructionPart, DiffObjConfig, X86Formatter}, + diff::{DiffObjConfig, X86Formatter, display::InstructionPart}, obj::{InstructionRef, RelocationFlags, ResolvedInstructionRef, ScannedInstruction}, }; @@ -89,7 +89,7 @@ impl Arch for ArchX86 { let mut reloc_replace = None; if let Some(reloc) = resolved.relocation { const PLACEHOLDER: u64 = 0x7BDE3E7D; // chosen by fair dice roll. - // guaranteed to be random. + // guaranteed to be random. let reloc_offset = reloc.relocation.address - resolved.ins_ref.address; let reloc_size = reloc_size(reloc.relocation.flags).unwrap_or(usize::MAX); let offsets = decoder.get_constant_offsets(&instruction); diff --git a/objdiff-core/src/bindings/report.rs b/objdiff-core/src/bindings/report.rs index 938bc45..02bf34a 100644 --- a/objdiff-core/src/bindings/report.rs +++ b/objdiff-core/src/bindings/report.rs @@ -7,7 +7,7 @@ use alloc::{ }; use core::ops::AddAssign; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use prost::Message; // Protobuf report types @@ -441,11 +441,7 @@ impl From for ReportItem { #[cfg(feature = "serde")] fn serialize_hex(x: &Option, s: S) -> Result where S: serde::Serializer { - if let Some(x) = x { - s.serialize_str(&format!("{:#x}", x)) - } else { - s.serialize_none() - } + if let Some(x) = x { s.serialize_str(&format!("{:#x}", x)) } else { s.serialize_none() } } #[cfg(feature = "serde")] diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index def6f25..65c00bb 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -2,8 +2,8 @@ use std::{ fs, path::{Path, PathBuf}, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, task::Waker, time::Duration, @@ -11,7 +11,7 @@ use std::{ use globset::GlobSet; use notify::RecursiveMode; -use notify_debouncer_full::{new_debouncer_opt, DebounceEventResult}; +use notify_debouncer_full::{DebounceEventResult, new_debouncer_opt}; pub type Watcher = notify_debouncer_full::Debouncer< notify::RecommendedWatcher, diff --git a/objdiff-core/src/config/mod.rs b/objdiff-core/src/config/mod.rs index 272f35b..d3f7986 100644 --- a/objdiff-core/src/config/mod.rs +++ b/objdiff-core/src/config/mod.rs @@ -6,7 +6,7 @@ use alloc::{ vec::Vec, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use globset::{Glob, GlobSet, GlobSetBuilder}; use path::unix_path_serde_option; use typed_path::Utf8UnixPathBuf; diff --git a/objdiff-core/src/config/path.rs b/objdiff-core/src/config/path.rs index d94d977..09e292b 100644 --- a/objdiff-core/src/config/path.rs +++ b/objdiff-core/src/config/path.rs @@ -31,11 +31,7 @@ pub mod unix_path_serde_option { pub fn serialize(path: &Option, s: S) -> Result where S: Serializer { - if let Some(path) = path { - s.serialize_some(path.as_str()) - } else { - s.serialize_none() - } + 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> @@ -51,11 +47,7 @@ pub mod platform_path_serde_option { pub fn serialize(path: &Option, s: S) -> Result where S: Serializer { - if let Some(path) = path { - s.serialize_some(path.as_str()) - } else { - s.serialize_none() - } + 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> diff --git a/objdiff-core/src/diff/code.rs b/objdiff-core/src/diff/code.rs index 7b273fc..a372166 100644 --- a/objdiff-core/src/diff/code.rs +++ b/objdiff-core/src/diff/code.rs @@ -1,16 +1,16 @@ use alloc::{ - collections::{btree_map, BTreeMap}, + collections::{BTreeMap, btree_map}, string::{String, ToString}, vec, vec::Vec, }; -use anyhow::{anyhow, ensure, Context, Result}; +use anyhow::{Context, Result, anyhow, ensure}; use super::{ - display::display_ins_data_literals, DiffObjConfig, FunctionRelocDiffs, InstructionArgDiffIndex, - InstructionBranchFrom, InstructionBranchTo, InstructionDiffKind, InstructionDiffRow, - SymbolDiff, + DiffObjConfig, FunctionRelocDiffs, InstructionArgDiffIndex, InstructionBranchFrom, + InstructionBranchTo, InstructionDiffKind, InstructionDiffRow, SymbolDiff, + display::display_ins_data_literals, }; use crate::obj::{ InstructionArg, InstructionArgValue, InstructionRef, Object, ResolvedInstructionRef, diff --git a/objdiff-core/src/diff/data.rs b/objdiff-core/src/diff/data.rs index 6275b31..eb9e4c5 100644 --- a/objdiff-core/src/diff/data.rs +++ b/objdiff-core/src/diff/data.rs @@ -1,12 +1,12 @@ use alloc::{vec, vec::Vec}; use core::{cmp::Ordering, ops::Range}; -use anyhow::{anyhow, Result}; -use similar::{capture_diff_slices, get_diff_ratio, Algorithm}; +use anyhow::{Result, anyhow}; +use similar::{Algorithm, capture_diff_slices, get_diff_ratio}; use super::{ - code::{address_eq, section_name_eq}, DataDiff, DataDiffKind, DataRelocationDiff, ObjectDiff, SectionDiff, SymbolDiff, + code::{address_eq, section_name_eq}, }; use crate::obj::{Object, Relocation, ResolvedRelocation, Symbol, SymbolFlag, SymbolKind}; @@ -431,11 +431,7 @@ pub fn diff_generic_section( .fold((0.0, 0.0), |(matched, total), (s, d)| { (matched + d.match_percent.unwrap_or(0.0) * s.size as f32, total + s.size as f32) }); - if total == 0.0 { - 100.0 - } else { - matched / total - } + if total == 0.0 { 100.0 } else { matched / total } }; Ok(( SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] }, diff --git a/objdiff-core/src/diff/mod.rs b/objdiff-core/src/diff/mod.rs index edcdac1..272c63c 100644 --- a/objdiff-core/src/diff/mod.rs +++ b/objdiff-core/src/diff/mod.rs @@ -26,13 +26,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)] diff --git a/objdiff-core/src/jobs/check_update.rs b/objdiff-core/src/jobs/check_update.rs index 3d33bf3..940e5fe 100644 --- a/objdiff-core/src/jobs/check_update.rs +++ b/objdiff-core/src/jobs/check_update.rs @@ -6,7 +6,7 @@ use self_update::{ update::{Release, ReleaseUpdate}, }; -use crate::jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}; +use crate::jobs::{Job, JobContext, JobResult, JobState, start_job, update_status}; pub struct CheckUpdateConfig { pub build_updater: fn() -> Result>, diff --git a/objdiff-core/src/jobs/create_scratch.rs b/objdiff-core/src/jobs/create_scratch.rs index ab427ee..602dda1 100644 --- a/objdiff-core/src/jobs/create_scratch.rs +++ b/objdiff-core/src/jobs/create_scratch.rs @@ -1,11 +1,11 @@ use std::{fs, sync::mpsc::Receiver, task::Waker}; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use typed_path::{Utf8PlatformPathBuf, Utf8UnixPathBuf}; use crate::{ - build::{run_make, BuildConfig, BuildStatus}, - jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}, + build::{BuildConfig, BuildStatus, run_make}, + jobs::{Job, JobContext, JobResult, JobState, start_job, update_status}, }; #[derive(Debug, Clone)] diff --git a/objdiff-core/src/jobs/mod.rs b/objdiff-core/src/jobs/mod.rs index b0543ec..06e2e1e 100644 --- a/objdiff-core/src/jobs/mod.rs +++ b/objdiff-core/src/jobs/mod.rs @@ -1,8 +1,8 @@ use std::{ sync::{ + Arc, RwLock, atomic::{AtomicUsize, Ordering}, mpsc::{Receiver, Sender, TryRecvError}, - Arc, RwLock, }, task::Waker, thread::JoinHandle, diff --git a/objdiff-core/src/jobs/objdiff.rs b/objdiff-core/src/jobs/objdiff.rs index 8d0d0d9..072a08a 100644 --- a/objdiff-core/src/jobs/objdiff.rs +++ b/objdiff-core/src/jobs/objdiff.rs @@ -1,14 +1,14 @@ use std::{sync::mpsc::Receiver, task::Waker}; -use anyhow::{bail, Error, Result}; +use anyhow::{Error, Result, bail}; use time::OffsetDateTime; use typed_path::Utf8PlatformPathBuf; use crate::{ - build::{run_make, BuildConfig, BuildStatus}, - diff::{diff_objs, DiffObjConfig, MappingConfig, ObjectDiff}, - jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}, - obj::{read, Object}, + build::{BuildConfig, BuildStatus, run_make}, + diff::{DiffObjConfig, MappingConfig, ObjectDiff, diff_objs}, + jobs::{Job, JobContext, JobResult, JobState, start_job, update_status}, + obj::{Object, read}, }; pub struct ObjDiffConfig { diff --git a/objdiff-core/src/jobs/update.rs b/objdiff-core/src/jobs/update.rs index 8fe290f..b31ec02 100644 --- a/objdiff-core/src/jobs/update.rs +++ b/objdiff-core/src/jobs/update.rs @@ -10,7 +10,7 @@ use anyhow::{Context, Result}; pub use self_update; // Re-export self_update crate use self_update::update::ReleaseUpdate; -use crate::jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}; +use crate::jobs::{Job, JobContext, JobResult, JobState, start_job, update_status}; pub struct UpdateConfig { pub build_updater: fn() -> Result>, diff --git a/objdiff-core/src/obj/mod.rs b/objdiff-core/src/obj/mod.rs index a9b2722..06459d6 100644 --- a/objdiff-core/src/obj/mod.rs +++ b/objdiff-core/src/obj/mod.rs @@ -11,7 +11,7 @@ use alloc::{ }; use core::{fmt, num::NonZeroU32}; -use flagset::{flags, FlagSet}; +use flagset::{FlagSet, flags}; use crate::{ arch::{Arch, ArchDummy}, diff --git a/objdiff-core/src/obj/read.rs b/objdiff-core/src/obj/read.rs index 968191b..dda2e06 100644 --- a/objdiff-core/src/obj/read.rs +++ b/objdiff-core/src/obj/read.rs @@ -6,16 +6,16 @@ use alloc::{ }; use core::cmp::Ordering; -use anyhow::{anyhow, bail, ensure, Context, Result}; +use anyhow::{Context, Result, anyhow, bail, ensure}; use object::{Object as _, ObjectSection as _, ObjectSymbol as _}; use crate::{ - arch::{new_arch, Arch}, + arch::{Arch, new_arch}, diff::DiffObjConfig, obj::{ - split_meta::{SplitMeta, SPLITMETA_SECTION}, Object, Relocation, RelocationFlags, Section, SectionData, SectionFlag, SectionKind, Symbol, SymbolFlag, SymbolKind, + split_meta::{SPLITMETA_SECTION, SplitMeta}, }, util::{read_u16, read_u32}, }; diff --git a/objdiff-core/src/obj/split_meta.rs b/objdiff-core/src/obj/split_meta.rs index b50a46b..8e407df 100644 --- a/objdiff-core/src/obj/split_meta.rs +++ b/objdiff-core/src/obj/split_meta.rs @@ -1,7 +1,7 @@ use alloc::{string::String, vec, vec::Vec}; -use anyhow::{anyhow, Result}; -use object::{elf::SHT_NOTE, Endian, ObjectSection}; +use anyhow::{Result, anyhow}; +use object::{Endian, ObjectSection, elf::SHT_NOTE}; pub const SPLITMETA_SECTION: &str = ".note.split"; pub const SHT_SPLITMETA: u32 = SHT_NOTE; diff --git a/objdiff-core/src/util.rs b/objdiff-core/src/util.rs index ecd60c6..ddea4ed 100644 --- a/objdiff-core/src/util.rs +++ b/objdiff-core/src/util.rs @@ -1,7 +1,7 @@ use alloc::format; use core::fmt; -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use num_traits::PrimInt; use object::{Endian, Object}; diff --git a/objdiff-core/tests/common.rs b/objdiff-core/tests/common.rs index 3e1cb0a..4c89526 100644 --- a/objdiff-core/tests/common.rs +++ b/objdiff-core/tests/common.rs @@ -1,5 +1,5 @@ use objdiff_core::{ - diff::{display::DiffTextSegment, DiffObjConfig, SymbolDiff}, + diff::{DiffObjConfig, SymbolDiff, display::DiffTextSegment}, obj::Object, }; diff --git a/objdiff-gui/src/app.rs b/objdiff-gui/src/app.rs index c6b0344..88c42e9 100644 --- a/objdiff-gui/src/app.rs +++ b/objdiff-gui/src/app.rs @@ -5,8 +5,8 @@ use std::{ path::{Path, PathBuf}, rc::Rc, sync::{ - atomic::{AtomicBool, Ordering}, Arc, Mutex, RwLock, + atomic::{AtomicBool, Ordering}, }, time::Instant, }; @@ -14,11 +14,11 @@ use std::{ use filetime::FileTime; use globset::Glob; use objdiff_core::{ - build::watcher::{create_watcher, Watcher}, + build::watcher::{Watcher, create_watcher}, config::{ + DEFAULT_WATCH_PATTERNS, ProjectConfig, ProjectConfigInfo, ProjectObject, ScratchConfig, build_globset, default_watch_patterns, path::platform_path_serde_option, - save_project_config, ProjectConfig, ProjectConfigInfo, ProjectObject, ScratchConfig, - DEFAULT_WATCH_PATTERNS, + save_project_config, }, diff::DiffObjConfig, jobs::{Job, JobQueue, JobResult}, @@ -27,22 +27,22 @@ use time::UtcOffset; use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf}; use crate::{ - app_config::{deserialize_config, AppConfigVersion}, - config::{load_project_config, ProjectObjectNode}, + app_config::{AppConfigVersion, deserialize_config}, + config::{ProjectObjectNode, load_project_config}, jobs::{create_objdiff_config, egui_waker, start_build}, views::{ - appearance::{appearance_window, Appearance}, + appearance::{Appearance, appearance_window}, config::{ - arch_config_window, config_ui, general_config_ui, project_window, ConfigViewState, - CONFIG_DISABLED_TEXT, + CONFIG_DISABLED_TEXT, ConfigViewState, arch_config_window, config_ui, + general_config_ui, project_window, }, debug::debug_window, - demangle::{demangle_window, DemangleViewState}, + demangle::{DemangleViewState, demangle_window}, diff::diff_view_ui, frame_history::FrameHistory, - graphics::{graphics_window, GraphicsConfig, GraphicsViewState}, + graphics::{GraphicsConfig, GraphicsViewState, graphics_window}, jobs::{jobs_menu_ui, jobs_window}, - rlwinm::{rlwinm_decode_window, RlwinmDecodeViewState}, + rlwinm::{RlwinmDecodeViewState, rlwinm_decode_window}, symbol_diff::{DiffViewAction, DiffViewState, ResolvedNavigation, View}, }, }; diff --git a/objdiff-gui/src/app_config.rs b/objdiff-gui/src/app_config.rs index 91d667c..3a058c2 100644 --- a/objdiff-gui/src/app_config.rs +++ b/objdiff-gui/src/app_config.rs @@ -11,7 +11,7 @@ use objdiff_core::{ }; use typed_path::{Utf8PlatformPathBuf, Utf8UnixPathBuf}; -use crate::app::{AppConfig, ObjectConfig, CONFIG_KEY}; +use crate::app::{AppConfig, CONFIG_KEY, ObjectConfig}; #[derive(Clone, serde::Deserialize, serde::Serialize)] pub struct AppConfigVersion { diff --git a/objdiff-gui/src/config.rs b/objdiff-gui/src/config.rs index 1ddda64..16583c1 100644 --- a/objdiff-gui/src/config.rs +++ b/objdiff-gui/src/config.rs @@ -1,6 +1,6 @@ use anyhow::Result; use globset::Glob; -use objdiff_core::config::{try_project_config, DEFAULT_WATCH_PATTERNS}; +use objdiff_core::config::{DEFAULT_WATCH_PATTERNS, try_project_config}; use typed_path::{Utf8UnixComponent, Utf8UnixPath}; use crate::app::{AppState, ObjectConfig}; diff --git a/objdiff-gui/src/hotkeys.rs b/objdiff-gui/src/hotkeys.rs index e68571b..80d8d5d 100644 --- a/objdiff-gui/src/hotkeys.rs +++ b/objdiff-gui/src/hotkeys.rs @@ -1,5 +1,5 @@ use egui::{ - style::ScrollAnimation, vec2, Context, Key, KeyboardShortcut, Modifiers, PointerButton, + Context, Key, KeyboardShortcut, Modifiers, PointerButton, style::ScrollAnimation, vec2, }; fn any_widget_focused(ctx: &Context) -> bool { ctx.memory(|mem| mem.focused().is_some()) } diff --git a/objdiff-gui/src/jobs.rs b/objdiff-gui/src/jobs.rs index f9dcd38..543191f 100644 --- a/objdiff-gui/src/jobs.rs +++ b/objdiff-gui/src/jobs.rs @@ -3,18 +3,18 @@ use std::{ task::{Wake, Waker}, }; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use jobs::create_scratch; use objdiff_core::{ build::BuildConfig, diff::MappingConfig, jobs, - jobs::{check_update::CheckUpdateConfig, objdiff, update::UpdateConfig, Job, JobQueue}, + jobs::{Job, JobQueue, check_update::CheckUpdateConfig, objdiff, update::UpdateConfig}, }; use crate::{ app::{AppConfig, AppState}, - update::{build_updater, BIN_NAME_NEW, BIN_NAME_OLD}, + update::{BIN_NAME_NEW, BIN_NAME_OLD, build_updater}, }; struct EguiWaker(egui::Context); diff --git a/objdiff-gui/src/main.rs b/objdiff-gui/src/main.rs index 32f73bb..2687f01 100644 --- a/objdiff-gui/src/main.rs +++ b/objdiff-gui/src/main.rs @@ -17,12 +17,12 @@ use std::{ sync::{Arc, Mutex}, }; -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use cfg_if::cfg_if; use time::UtcOffset; use tracing_subscriber::EnvFilter; -use crate::views::graphics::{load_graphics_config, GraphicsBackend, GraphicsConfig}; +use crate::views::graphics::{GraphicsBackend, GraphicsConfig, load_graphics_config}; fn load_icon() -> Result { let decoder = png::Decoder::new(include_bytes!("../assets/icon_64.png").as_ref()); @@ -86,7 +86,7 @@ fn main() -> ExitCode { } #[cfg(feature = "wgpu")] { - use eframe::egui_wgpu::{wgpu, WgpuSetup}; + use eframe::egui_wgpu::{WgpuSetup, wgpu}; if graphics_config.desired_backend.is_supported() { native_options.wgpu_options.wgpu_setup = match native_options.wgpu_options.wgpu_setup { WgpuSetup::CreateNew(mut setup) => { diff --git a/objdiff-gui/src/views/appearance.rs b/objdiff-gui/src/views/appearance.rs index a501201..805d4b9 100644 --- a/objdiff-gui/src/views/appearance.rs +++ b/objdiff-gui/src/views/appearance.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use egui::{text::LayoutJob, Color32, FontFamily, FontId, TextFormat, TextStyle, Widget}; +use egui::{Color32, FontFamily, FontId, TextFormat, TextStyle, Widget, text::LayoutJob}; use time::UtcOffset; use crate::fonts::load_font_if_needed; diff --git a/objdiff-gui/src/views/config.rs b/objdiff-gui/src/views/config.rs index baf76a7..d262062 100644 --- a/objdiff-gui/src/views/config.rs +++ b/objdiff-gui/src/views/config.rs @@ -5,17 +5,17 @@ use std::{mem::take, path::MAIN_SEPARATOR}; #[cfg(all(windows, feature = "wsl"))] use anyhow::{Context, Result}; use egui::{ - output::OpenUrl, text::LayoutJob, CollapsingHeader, FontFamily, FontId, RichText, - SelectableLabel, TextFormat, Widget, + CollapsingHeader, FontFamily, FontId, RichText, SelectableLabel, TextFormat, Widget, + output::OpenUrl, text::LayoutJob, }; use globset::Glob; use objdiff_core::{ - config::{path::check_path_buf, DEFAULT_WATCH_PATTERNS}, + config::{DEFAULT_WATCH_PATTERNS, path::check_path_buf}, diff::{ - ConfigEnum, ConfigEnumVariantInfo, ConfigPropertyId, ConfigPropertyKind, - ConfigPropertyValue, CONFIG_GROUPS, + CONFIG_GROUPS, ConfigEnum, ConfigEnumVariantInfo, ConfigPropertyId, ConfigPropertyKind, + ConfigPropertyValue, }, - jobs::{check_update::CheckUpdateResult, Job, JobQueue, JobResult}, + jobs::{Job, JobQueue, JobResult, check_update::CheckUpdateResult}, }; use typed_path::Utf8PlatformPathBuf; @@ -347,11 +347,7 @@ fn display_unit( let color = if selected { appearance.emphasized_text_color } else if let Some(complete) = object.complete { - if complete { - appearance.insert_color - } else { - appearance.delete_color - } + if complete { appearance.insert_color } else { appearance.delete_color } } else { appearance.text_color }; diff --git a/objdiff-gui/src/views/data_diff.rs b/objdiff-gui/src/views/data_diff.rs index bd0a13b..0c25e20 100644 --- a/objdiff-gui/src/views/data_diff.rs +++ b/objdiff-gui/src/views/data_diff.rs @@ -1,11 +1,11 @@ use std::{cmp::min, default::Default, mem::take}; -use egui::{text::LayoutJob, Label, Sense, Widget}; +use egui::{Label, Sense, Widget, text::LayoutJob}; use objdiff_core::{ diff::{ - data::resolve_relocation, - display::{relocation_context, relocation_hover, ContextItem, HoverItem}, DataDiff, DataDiffKind, DataRelocationDiff, + data::resolve_relocation, + display::{ContextItem, HoverItem, relocation_context, relocation_hover}, }, obj::Object, }; diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 4df91ad..16e1b46 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -1,9 +1,9 @@ -use egui::{text::LayoutJob, Id, Layout, RichText, ScrollArea, TextEdit, Ui, Widget}; +use egui::{Id, Layout, RichText, ScrollArea, TextEdit, Ui, Widget, text::LayoutJob}; use objdiff_core::{ build::BuildStatus, diff::{ - display::{ContextItem, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind}, DiffObjConfig, ObjectDiff, SectionDiff, SymbolDiff, + display::{ContextItem, HoverItem, HoverItemColor, SymbolFilter, SymbolNavigationKind}, }, obj::{Object, Section, Symbol}, }; @@ -14,13 +14,12 @@ use crate::{ views::{ appearance::Appearance, column_layout::{render_header, render_strips, render_table}, - data_diff::{data_row_ui, split_diffs, BYTES_PER_ROW}, + data_diff::{BYTES_PER_ROW, data_row_ui, split_diffs}, extab_diff::extab_ui, - function_diff::{asm_col_ui, FunctionDiffContext}, + function_diff::{FunctionDiffContext, asm_col_ui}, symbol_diff::{ - match_color_for_symbol, symbol_context_menu_ui, symbol_hover_ui, symbol_list_ui, DiffViewAction, DiffViewNavigation, DiffViewState, SymbolDiffContext, SymbolRefByName, - View, + View, match_color_for_symbol, symbol_context_menu_ui, symbol_hover_ui, symbol_list_ui, }, write_text, }, diff --git a/objdiff-gui/src/views/function_diff.rs b/objdiff-gui/src/views/function_diff.rs index 4819c38..dff2c15 100644 --- a/objdiff-gui/src/views/function_diff.rs +++ b/objdiff-gui/src/views/function_diff.rs @@ -1,14 +1,14 @@ use std::{cmp::Ordering, default::Default}; -use egui::{text::LayoutJob, Label, Response, Sense, Widget}; +use egui::{Label, Response, Sense, Widget, text::LayoutJob}; use egui_extras::TableRow; use objdiff_core::{ diff::{ - display::{ - display_row, instruction_context, instruction_hover, DiffText, DiffTextColor, - DiffTextSegment, HighlightKind, - }, DiffObjConfig, InstructionDiffKind, InstructionDiffRow, ObjectDiff, + display::{ + DiffText, DiffTextColor, DiffTextSegment, HighlightKind, display_row, + instruction_context, instruction_hover, + }, }, obj::{InstructionArgValue, InstructionRef, Object}, util::ReallySigned, diff --git a/objdiff-gui/src/views/graphics.rs b/objdiff-gui/src/views/graphics.rs index 089ce85..fcfa114 100644 --- a/objdiff-gui/src/views/graphics.rs +++ b/objdiff-gui/src/views/graphics.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::Result; -use egui::{text::LayoutJob, Context, FontId, RichText, TextFormat, TextStyle, Window}; +use egui::{Context, FontId, RichText, TextFormat, TextStyle, Window, text::LayoutJob}; use serde::{Deserialize, Serialize}; use crate::views::{appearance::Appearance, frame_history::FrameHistory}; diff --git a/objdiff-gui/src/views/mod.rs b/objdiff-gui/src/views/mod.rs index 543fead..aedabe9 100644 --- a/objdiff-gui/src/views/mod.rs +++ b/objdiff-gui/src/views/mod.rs @@ -1,4 +1,4 @@ -use egui::{text::LayoutJob, Color32, FontId, TextFormat}; +use egui::{Color32, FontId, TextFormat, text::LayoutJob}; pub(crate) mod appearance; pub(crate) mod column_layout; diff --git a/objdiff-gui/src/views/symbol_diff.rs b/objdiff-gui/src/views/symbol_diff.rs index 3977328..e19cb9f 100644 --- a/objdiff-gui/src/views/symbol_diff.rs +++ b/objdiff-gui/src/views/symbol_diff.rs @@ -1,18 +1,18 @@ use std::mem::take; use egui::{ - style::ScrollAnimation, text::LayoutJob, CollapsingHeader, Color32, Id, OpenUrl, ScrollArea, - SelectableLabel, Ui, Widget, + CollapsingHeader, Color32, Id, OpenUrl, ScrollArea, SelectableLabel, Ui, Widget, + style::ScrollAnimation, text::LayoutJob, }; use objdiff_core::{ diff::{ - display::{ - display_sections, symbol_context, symbol_hover, HighlightKind, SectionDisplay, - SymbolFilter, SymbolNavigationKind, - }, ObjectDiff, SymbolDiff, + display::{ + HighlightKind, SectionDisplay, SymbolFilter, SymbolNavigationKind, display_sections, + symbol_context, symbol_hover, + }, }, - jobs::{create_scratch::CreateScratchResult, objdiff::ObjDiffResult, Job, JobQueue, JobResult}, + jobs::{Job, JobQueue, JobResult, create_scratch::CreateScratchResult, objdiff::ObjDiffResult}, obj::{Object, Section, SectionKind, Symbol, SymbolFlag}, }; use regex::{Regex, RegexBuilder}; diff --git a/objdiff-wasm/src/cabi_realloc.rs b/objdiff-wasm/src/cabi_realloc.rs index 40107ae..da48b5c 100644 --- a/objdiff-wasm/src/cabi_realloc.rs +++ b/objdiff-wasm/src/cabi_realloc.rs @@ -20,7 +20,7 @@ //! this is defined as a "weak" symbol. This means that other definitions are //! allowed to overwrite it if they are present in a compilation. -use alloc::{alloc, Layout}; +use alloc::{Layout, alloc}; use core::ptr; #[used]