Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions objdiff-cli/src/argp_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use std::ffi::OsStr;
use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions};

struct ArgsOrVersion<T>(T)
where T: FromArgs;
where
T: FromArgs;

impl<T> TopLevelCommand for ArgsOrVersion<T> where T: FromArgs {}

impl<T> FromArgs for ArgsOrVersion<T>
where T: FromArgs
where
T: FromArgs,
{
fn _from_args(
command_name: &[&str],
Expand Down Expand Up @@ -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>() -> T
where T: TopLevelCommand {
where
T: TopLevelCommand,
{
argp::parse_args_or_exit::<ArgsOrVersion<T>>(argp::DEFAULT).0
}
8 changes: 6 additions & 2 deletions objdiff-cli/src/cmd/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ impl AppState {
pub struct TermWaker(pub AtomicBool);

impl Wake for TermWaker {
fn wake(self: Arc<Self>) { self.0.store(true, Ordering::Relaxed); }
fn wake(self: Arc<Self>) {
self.0.store(true, Ordering::Relaxed);
}

fn wake_by_ref(self: &Arc<Self>) { self.0.store(true, Ordering::Relaxed); }
fn wake_by_ref(self: &Arc<Self>) {
self.0.store(true, Ordering::Relaxed);
}
}

fn run_interactive(
Expand Down
11 changes: 7 additions & 4 deletions objdiff-core/src/arch/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
48 changes: 36 additions & 12 deletions objdiff-core/src/arch/arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use crate::{
pub struct ArchArm64 {}

impl ArchArm64 {
pub fn new(_file: &object::File) -> Result<Self> { Ok(Self {}) }
pub fn new(_file: &object::File) -> Result<Self> {
Ok(Self {})
}
}

impl Arch for ArchArm64 {
Expand Down Expand Up @@ -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<Cb>(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 "<invalid>",
Opcode::UDF => "udf",
Expand Down Expand Up @@ -2001,13 +2005,17 @@ fn condition_code(cond: u8) -> &'static str {

#[inline]
fn push_register<Cb>(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<Cb>(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, " ");
Expand All @@ -2017,12 +2025,16 @@ where Cb: FnMut(InstructionPart<'static>) {

#[inline]
fn push_condition_code<Cb>(args: &mut Cb, cond: u8)
where Cb: FnMut(InstructionPart<'static>) {
where
Cb: FnMut(InstructionPart<'static>),
{
push_opaque(args, condition_code(cond));
}

fn push_barrier<Cb>(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"),
Expand All @@ -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<Cb>(args: &mut Cb, text: &'static str)
where Cb: FnMut(InstructionPart<'static>) {
where
Cb: FnMut(InstructionPart<'static>),
{
args(InstructionPart::basic(text));
}

#[inline]
fn push_separator<Cb>(args: &mut Cb)
where Cb: FnMut(InstructionPart<'static>) {
where
Cb: FnMut(InstructionPart<'static>),
{
args(InstructionPart::separator());
}

#[inline]
fn push_unsigned<Cb>(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<Cb>(args: &mut Cb, v: i64)
where Cb: FnMut(InstructionPart<'static>) {
where
Cb: FnMut(InstructionPart<'static>),
{
push_plain(args, "#");
args(InstructionPart::signed(v));
}
Expand Down Expand Up @@ -2107,7 +2129,9 @@ fn is_reg_index_reloc(resolved: Option<ResolvedRelocation>) -> bool {
}

fn push_operand<Cb>(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) => {
Expand Down
46 changes: 32 additions & 14 deletions objdiff-core/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
Expand Down Expand Up @@ -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()
Expand All @@ -389,9 +399,13 @@ pub trait Arch: Any + Debug + Send + Sync {
None
}

fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec<HoverItem> { Vec::new() }
fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec<HoverItem> {
Vec::new()
}

fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec<ContextItem> { Vec::new() }
fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec<ContextItem> {
Vec::new()
}

fn instruction_hover(
&self,
Expand Down Expand Up @@ -449,7 +463,9 @@ pub fn new_arch(object: &object::File, diff_side: DiffSide) -> Result<Box<dyn Ar
pub struct ArchDummy {}

impl ArchDummy {
pub fn new() -> Box<Self> { Box::new(Self {}) }
pub fn new() -> Box<Self> {
Box::new(Self {})
}
}

impl Arch for ArchDummy {
Expand All @@ -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)]
Expand Down
16 changes: 12 additions & 4 deletions objdiff-core/src/arch/ppc/flow_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ impl RegisterState {
impl Index<powerpc::GPR> 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<powerpc::GPR> for RegisterState {
fn index_mut(&mut self, gpr: powerpc::GPR) -> &mut Self::Output {
Expand All @@ -186,7 +188,9 @@ impl IndexMut<powerpc::GPR> for RegisterState {
impl Index<powerpc::FPR> 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<powerpc::FPR> for RegisterState {
fn index_mut(&mut self, fpr: powerpc::FPR) -> &mut Self::Output {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 16 additions & 10 deletions objdiff-core/src/arch/ppc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion objdiff-core/src/arch/superh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub mod disasm;
pub struct ArchSuperH {}

impl ArchSuperH {
pub fn new(_file: &object::File) -> Result<Self> { Ok(Self {}) }
pub fn new(_file: &object::File) -> Result<Self> {
Ok(Self {})
}
}

struct DataInfo {
Expand Down
Loading
Loading