Skip to content

Commit 017127c

Browse files
committed
OPCODE_DATA too
1 parent 3b718e3 commit 017127c

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

objdiff-core/src/arch/arm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use object::{Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _, el
1111
use unarm::{args, arm, thumb};
1212

1313
use crate::{
14-
arch::{Arch, OPCODE_INVALID, RelocationOverride, RelocationOverrideTarget},
14+
arch::{Arch, OPCODE_DATA, OPCODE_INVALID, RelocationOverride, RelocationOverrideTarget},
1515
diff::{ArmArchVersion, ArmR9Usage, DiffObjConfig, display::InstructionPart},
1616
obj::{
1717
InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation,
@@ -164,7 +164,7 @@ impl ArchArm {
164164
}
165165
_ => bail!("Invalid instruction size {}", ins_ref.size),
166166
};
167-
let (ins, parsed_ins) = if ins_ref.opcode == OPCODE_INVALID {
167+
let (ins, parsed_ins) = if ins_ref.opcode == OPCODE_DATA {
168168
let mut args = args::Arguments::default();
169169
args[0] = args::Argument::UImm(code);
170170
let mnemonic = if ins_ref.size == 4 { ".word" } else { ".hword" };
@@ -238,7 +238,7 @@ impl Arch for ArchArm {
238238
ops.push(InstructionRef {
239239
address: address as u64,
240240
size: data.len() as u8,
241-
opcode: OPCODE_INVALID,
241+
opcode: OPCODE_DATA,
242242
branch_dest: None,
243243
});
244244
break;
@@ -318,7 +318,7 @@ impl Arch for ArchArm {
318318
};
319319
(opcode, branch_dest)
320320
}
321-
unarm::ParseMode::Data => (OPCODE_INVALID, None),
321+
unarm::ParseMode::Data => (OPCODE_DATA, None),
322322
};
323323

324324
ops.push(InstructionRef {

objdiff-core/src/arch/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub mod superh;
4141
#[cfg(feature = "x86")]
4242
pub mod x86;
4343

44-
pub const OPCODE_INVALID: u16 = u16::MAX - 1;
44+
pub const OPCODE_INVALID: u16 = u16::MAX;
45+
pub const OPCODE_DATA: u16 = u16::MAX - 1;
4546

4647
/// Represents the type of data associated with an instruction
4748
#[derive(PartialEq)]

objdiff-core/src/arch/x86.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use iced_x86::{
99
use object::{Endian as _, Object as _, ObjectSection as _, elf, pe};
1010

1111
use crate::{
12-
arch::{Arch, OPCODE_INVALID, RelocationOverride, RelocationOverrideTarget},
12+
arch::{Arch, OPCODE_DATA, RelocationOverride, RelocationOverrideTarget},
1313
diff::{DiffObjConfig, X86Formatter, display::InstructionPart},
1414
obj::{InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, Section, Symbol},
1515
};
@@ -119,7 +119,7 @@ impl Arch for ArchX86 {
119119
out.push(InstructionRef {
120120
address,
121121
size: size as u8,
122-
opcode: OPCODE_INVALID,
122+
opcode: OPCODE_DATA,
123123
branch_dest: None,
124124
});
125125

@@ -146,7 +146,7 @@ impl Arch for ArchX86 {
146146
out.push(InstructionRef {
147147
address: indirect_array_address + i as u64,
148148
size: 1,
149-
opcode: OPCODE_INVALID,
149+
opcode: OPCODE_DATA,
150150
branch_dest: None,
151151
});
152152
}
@@ -185,14 +185,14 @@ impl Arch for ArchX86 {
185185
diff_config: &DiffObjConfig,
186186
cb: &mut dyn FnMut(InstructionPart) -> Result<()>,
187187
) -> Result<()> {
188-
if resolved.ins_ref.opcode == OPCODE_INVALID {
188+
if resolved.ins_ref.opcode == OPCODE_DATA {
189189
let (mnemonic, imm) = match resolved.ins_ref.size {
190190
1 => (".byte", resolved.code[0] as u64),
191191
2 => (".word", self.endianness.read_u16_bytes(resolved.code.try_into()?) as u64),
192192
4 => (".dword", self.endianness.read_u32_bytes(resolved.code.try_into()?) as u64),
193193
_ => bail!("Unsupported x86 inline data size {}", resolved.ins_ref.size),
194194
};
195-
cb(InstructionPart::opcode(mnemonic, OPCODE_INVALID))?;
195+
cb(InstructionPart::opcode(mnemonic, OPCODE_DATA))?;
196196
if resolved.relocation.is_some() {
197197
cb(InstructionPart::reloc())?;
198198
} else {
@@ -834,7 +834,7 @@ mod test {
834834
ins_ref: InstructionRef {
835835
address: 0x1234,
836836
size: 1,
837-
opcode: OPCODE_INVALID,
837+
opcode: OPCODE_DATA,
838838
branch_dest: None,
839839
},
840840
code: &code,
@@ -848,7 +848,7 @@ mod test {
848848
)
849849
.unwrap();
850850
assert_eq!(parts, &[
851-
InstructionPart::opcode(".byte", OPCODE_INVALID),
851+
InstructionPart::opcode(".byte", OPCODE_DATA),
852852
InstructionPart::unsigned(0xABu64),
853853
]);
854854
}

0 commit comments

Comments
 (0)