Skip to content

Commit 88eba55

Browse files
committed
[WARP] Fix possible skipped instructions when multiple IL expressions are appended for a given instruction
1 parent f8d3c5e commit 88eba55

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

plugins/warp/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
155155
instr_bytes.truncate(instr_info.length);
156156

157157
// Find variant and blacklisted instructions using lifted il.
158-
if let Some(lifted_il_instr) = lifted_il.instruction_at(instr_addr) {
158+
for lifted_il_instr in lifted_il.instructions_at(instr_addr) {
159159
// If instruction is blacklisted, don't include the bytes.
160160
if is_blacklisted_instruction(&lifted_il_instr) {
161161
continue;
@@ -164,6 +164,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
164164
if is_variant_instruction(relocatable_regions, &lifted_il_instr) {
165165
// Found a variant instruction, mask off the entire instruction.
166166
instr_bytes.fill(0);
167+
break;
167168
}
168169
}
169170

@@ -177,10 +178,11 @@ pub fn basic_block_guid<M: FunctionMutability>(
177178
// TODO: A "mapped llil" or having some simple data flow, the simple data flow is the most attractive
178179
// TODO: "solution", but it would require
179180
if let Ok(llil) = &low_level_il {
180-
if let Some(low_level_instr) = llil.instruction_at(instr_addr) {
181+
for low_level_instr in llil.instructions_at(instr_addr) {
181182
if is_computed_variant_instruction(relocatable_regions, &low_level_instr) {
182183
// Found a computed variant instruction, mask off the entire instruction.
183184
instr_bytes.fill(0);
185+
break;
184186
}
185187
}
186188
}

plugins/warp/src/plugin/render_layer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ impl HighlightRenderLayer {
5151
let relocatable_regions = relocatable_regions(&lifted_il.function().view());
5252
for line in lines {
5353
// We use address here instead of index since it's more reliable for other IL's.
54-
if let Some(lifted_il_instr) = lifted_il.instruction_at(line.address) {
54+
for lifted_il_instr in lifted_il.instructions_at(line.address) {
5555
if is_blacklisted_instruction(&lifted_il_instr) {
5656
line.highlight = self.blacklist;
5757
} else if is_variant_instruction(&relocatable_regions, &lifted_il_instr) {
5858
line.highlight = self.variant;
5959
}
6060
}
6161

62-
if let Some(llil_instr) = llil.instruction_at(line.address) {
62+
for llil_instr in llil.instructions_at(line.address) {
6363
if is_computed_variant_instruction(&relocatable_regions, &llil_instr) {
6464
line.highlight = self.computed_variant;
6565
}

rust/src/low_level_il/function.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,31 @@ where
9393
}
9494
}
9595

96+
/// Get all the contiguous instructions for a given location.
97+
///
98+
/// NOTE: This won't get you every instruction for a location, only the instructions
99+
/// that are sequential from the starting instruction.
100+
pub fn instructions_at<L: Into<Location>>(&self, loc: L) -> Vec<LowLevelILInstruction<M, F>> {
101+
let loc = loc.into();
102+
// TODO: Instructions sharing the same address are not always sequential.
103+
// Gather all of the sequential instructions with the same address and same block.
104+
self.instruction_index_at(loc)
105+
.map(|mut idx| {
106+
let mut instructions = Vec::new();
107+
let block = self.basic_block_containing_index(idx);
108+
while idx.0 < self.instruction_count() {
109+
let instr = LowLevelILInstruction::new(self, idx);
110+
if instr.address() != loc.addr || instr.basic_block() != block {
111+
break;
112+
}
113+
instructions.push(instr);
114+
idx = idx.next();
115+
}
116+
instructions
117+
})
118+
.unwrap_or_default()
119+
}
120+
96121
pub fn instruction_at<L: Into<Location>>(&self, loc: L) -> Option<LowLevelILInstruction<M, F>> {
97122
Some(LowLevelILInstruction::new(
98123
self,

0 commit comments

Comments
 (0)