|
1 | 1 | use alloc::{boxed::Box, format, string::String, vec::Vec};
|
| 2 | +use core::cmp::Ordering; |
2 | 3 |
|
3 | 4 | use anyhow::{Context, Result, anyhow, bail};
|
4 | 5 | use iced_x86::{
|
@@ -100,28 +101,30 @@ impl Arch for ArchX86 {
|
100 | 101 | 'outer: while decoder.can_decode() {
|
101 | 102 | let address = decoder.ip();
|
102 | 103 | while let Some(reloc) = reloc_iter.peek() {
|
103 |
| - if reloc.address < address { |
104 |
| - reloc_iter.next(); |
105 |
| - } else if reloc.address == address { |
106 |
| - // If the instruction starts at a relocation, it's inline data |
107 |
| - let size = self.reloc_size(reloc.flags).with_context(|| { |
108 |
| - format!("Unsupported inline x86 relocation {:?}", reloc.flags) |
109 |
| - })?; |
110 |
| - if decoder.set_position(decoder.position() + size).is_ok() { |
111 |
| - decoder.set_ip(address + size as u64); |
112 |
| - out.push(ScannedInstruction { |
113 |
| - ins_ref: InstructionRef { |
114 |
| - address, |
115 |
| - size: size as u8, |
116 |
| - opcode: DATA_OPCODE, |
117 |
| - }, |
118 |
| - branch_dest: None, |
119 |
| - }); |
| 104 | + match reloc.address.cmp(&address) { |
| 105 | + Ordering::Less => { |
120 | 106 | reloc_iter.next();
|
121 |
| - continue 'outer; |
122 | 107 | }
|
123 |
| - } else { |
124 |
| - break; |
| 108 | + Ordering::Equal => { |
| 109 | + // If the instruction starts at a relocation, it's inline data |
| 110 | + let size = self.reloc_size(reloc.flags).with_context(|| { |
| 111 | + format!("Unsupported inline x86 relocation {:?}", reloc.flags) |
| 112 | + })?; |
| 113 | + if decoder.set_position(decoder.position() + size).is_ok() { |
| 114 | + decoder.set_ip(address + size as u64); |
| 115 | + out.push(ScannedInstruction { |
| 116 | + ins_ref: InstructionRef { |
| 117 | + address, |
| 118 | + size: size as u8, |
| 119 | + opcode: DATA_OPCODE, |
| 120 | + }, |
| 121 | + branch_dest: None, |
| 122 | + }); |
| 123 | + reloc_iter.next(); |
| 124 | + continue 'outer; |
| 125 | + } |
| 126 | + } |
| 127 | + Ordering::Greater => break, |
125 | 128 | }
|
126 | 129 | }
|
127 | 130 | decoder.decode_out(&mut instruction);
|
|
0 commit comments