Skip to content

Commit a51a5ac

Browse files
committed
Add hack to detect strings via the addi opcode
1 parent 9b1205d commit a51a5ac

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

objdiff-core/src/arch/ppc.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,21 @@ impl ObjArch for ObjArchPpc {
204204
return Some(DataType::String);
205205
}
206206

207-
guess_data_type_from_load_store_inst_op(Opcode::from(instruction.op as u8))
207+
let op = Opcode::from(instruction.op as u8);
208+
if let Some(ty) = guess_data_type_from_load_store_inst_op(op) {
209+
Some(ty)
210+
} else if op == Opcode::Addi {
211+
// Assume that any addi instruction that references a local symbol is loading a string.
212+
// This hack is not ideal and results in tons of false positives where it will show
213+
// garbage strings (e.g. misinterpreting arrays, float literals, etc).
214+
// But there isn't much other choice as not all strings are in the @stringBase pool.
215+
// And even those that are would be missed by the target.name.starts_with("@stringBase")
216+
// hack above for fake pooled relocations, as they have an empty string placeholder for
217+
// the target symbol name.
218+
Some(DataType::String)
219+
} else {
220+
None
221+
}
208222
}
209223

210224
fn display_data_type(&self, ty: DataType, bytes: &[u8]) -> Option<String> {
@@ -422,7 +436,7 @@ fn get_offset_and_addr_gpr_for_possible_pool_reference(
422436
}
423437
} else {
424438
// If it's not a load/store instruction, there's two more possibilities we need to handle.
425-
// 1. It could be a reference to @stringBase.
439+
// 1. It could be loading a pointer to a string.
426440
// 2. It could be moving the relocation address plus an offset into a different register to
427441
// load from later.
428442
// If either of these match, we also want to return the destination register that the

0 commit comments

Comments
 (0)