Skip to content

Commit a4fdb61

Browse files
authored
Implement diffing relocations within data sections (#154)
* Data view: Show data bytes with differing relocations as a diff * Data view: Show differing relocations on hover * Symbol list view: Adjust symbol/section match %s when relocations differ * Improve data reloc diffing logic * Don't make reloc diffs cause bytes to show as red or green * Properly detect byte size of each relocation * Data view: Add context menu for copying relocation target symbols * Also show already-matching relocations on hover/right click * Change font color for nonmatching relocs on hover
1 parent 2876be3 commit a4fdb61

File tree

10 files changed

+426
-24
lines changed

10 files changed

+426
-24
lines changed

objdiff-core/src/arch/arm.rs

+13
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ impl ObjArch for ObjArchArm {
276276
fn display_reloc(&self, flags: RelocationFlags) -> Cow<'static, str> {
277277
Cow::Owned(format!("<{flags:?}>"))
278278
}
279+
280+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
281+
match flags {
282+
RelocationFlags::Elf { r_type } => match r_type {
283+
elf::R_ARM_ABS32 => 4,
284+
elf::R_ARM_REL32 => 4,
285+
elf::R_ARM_ABS16 => 2,
286+
elf::R_ARM_ABS8 => 1,
287+
_ => 1,
288+
},
289+
_ => 1,
290+
}
291+
}
279292
}
280293

281294
#[derive(Clone, Copy, Debug)]

objdiff-core/src/arch/arm64.rs

+15
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ impl ObjArch for ObjArchArm64 {
173173
_ => Cow::Owned(format!("<{flags:?}>")),
174174
}
175175
}
176+
177+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
178+
match flags {
179+
RelocationFlags::Elf { r_type } => match r_type {
180+
elf::R_AARCH64_ABS64 => 8,
181+
elf::R_AARCH64_ABS32 => 4,
182+
elf::R_AARCH64_ABS16 => 2,
183+
elf::R_AARCH64_PREL64 => 8,
184+
elf::R_AARCH64_PREL32 => 4,
185+
elf::R_AARCH64_PREL16 => 2,
186+
_ => 1,
187+
},
188+
_ => 1,
189+
}
190+
}
176191
}
177192

178193
struct DisplayCtx<'a> {

objdiff-core/src/arch/mips.rs

+11
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ impl ObjArch for ObjArchMips {
271271
_ => Cow::Owned(format!("<{flags:?}>")),
272272
}
273273
}
274+
275+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
276+
match flags {
277+
RelocationFlags::Elf { r_type } => match r_type {
278+
elf::R_MIPS_16 => 2,
279+
elf::R_MIPS_32 => 4,
280+
_ => 1,
281+
},
282+
_ => 1,
283+
}
284+
}
274285
}
275286

276287
fn push_reloc(args: &mut Vec<ObjInsArg>, reloc: &ObjReloc) -> Result<()> {

objdiff-core/src/arch/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub trait ObjArch: Send + Sync {
148148

149149
fn display_reloc(&self, flags: RelocationFlags) -> Cow<'static, str>;
150150

151+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize;
152+
151153
fn symbol_address(&self, symbol: &Symbol) -> u64 { symbol.address() }
152154

153155
fn guess_data_type(&self, _instruction: &ObjIns) -> Option<DataType> { None }

objdiff-core/src/arch/ppc.rs

+11
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ impl ObjArch for ObjArchPpc {
202202
}
203203
}
204204

205+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
206+
match flags {
207+
RelocationFlags::Elf { r_type } => match r_type {
208+
elf::R_PPC_ADDR32 => 4,
209+
elf::R_PPC_UADDR32 => 4,
210+
_ => 1,
211+
},
212+
_ => 1,
213+
}
214+
}
215+
205216
fn guess_data_type(&self, instruction: &ObjIns) -> Option<super::DataType> {
206217
if instruction.reloc.as_ref().is_some_and(|r| r.target.name.starts_with("@stringBase")) {
207218
return Some(DataType::String);

objdiff-core/src/arch/x86.rs

+13
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ impl ObjArch for ObjArchX86 {
162162
_ => Cow::Owned(format!("<{flags:?}>")),
163163
}
164164
}
165+
166+
fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
167+
match flags {
168+
RelocationFlags::Coff { typ } => match typ {
169+
pe::IMAGE_REL_I386_DIR16 => 2,
170+
pe::IMAGE_REL_I386_REL16 => 2,
171+
pe::IMAGE_REL_I386_DIR32 => 4,
172+
pe::IMAGE_REL_I386_REL32 => 4,
173+
_ => 1,
174+
},
175+
_ => 1,
176+
}
177+
}
165178
}
166179

167180
fn replace_arg(

objdiff-core/src/diff/code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn address_eq(left: &ObjReloc, right: &ObjReloc) -> bool {
196196
left.target.address as i64 + left.addend == right.target.address as i64 + right.addend
197197
}
198198

199-
fn section_name_eq(
199+
pub fn section_name_eq(
200200
left_obj: &ObjInfo,
201201
right_obj: &ObjInfo,
202202
left_orig_section_index: usize,

0 commit comments

Comments
 (0)