Skip to content

Commit 7816a61

Browse files
committed
Add highlight render layer to WARP
Highlights all variant instructions and blacklisted instructions Variant instructions are highlighted red, blacklisted will be orange.
1 parent 1a45f7a commit 7816a61

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

plugins/warp/src/plugin.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::cache::register_cache_destructor;
22

33
use crate::matcher::MatcherSettings;
4+
use crate::plugin::render_layer::HighlightRenderLayer;
45
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
56
use binaryninja::logger::Logger;
67
use binaryninja::rc::Ref;
@@ -14,6 +15,7 @@ mod debug;
1415
mod ffi;
1516
mod find;
1617
mod load;
18+
mod render_layer;
1719
mod types;
1820
mod workflow;
1921

@@ -37,6 +39,9 @@ pub extern "C" fn CorePluginInit() -> bool {
3739
// Make sure caches are flushed when the views get destructed.
3840
register_cache_destructor();
3941

42+
// Register our highlight render layer.
43+
HighlightRenderLayer::register();
44+
4045
workflow::insert_workflow();
4146

4247
binaryninja::command::register_command(
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::{is_blacklisted_instruction, is_variant_instruction, relocatable_regions};
2+
use binaryninja::basic_block::BasicBlock;
3+
use binaryninja::disassembly::DisassemblyTextLine;
4+
use binaryninja::function::{HighlightColor, HighlightStandardColor, NativeBlock};
5+
use binaryninja::low_level_il::instruction::LowLevelInstructionIndex;
6+
use binaryninja::render_layer::{register_render_layer, RenderLayer};
7+
8+
pub struct HighlightRenderLayer {}
9+
10+
impl HighlightRenderLayer {
11+
pub fn register() {
12+
register_render_layer(
13+
"WARP Highlight Layer",
14+
HighlightRenderLayer {},
15+
Default::default(),
16+
);
17+
}
18+
}
19+
20+
impl RenderLayer for HighlightRenderLayer {
21+
fn apply_to_llil_block(
22+
&self,
23+
block: &BasicBlock<NativeBlock>,
24+
mut lines: Vec<DisassemblyTextLine>,
25+
) -> Vec<DisassemblyTextLine> {
26+
// Highlight any LLIL instruction that will be masked by WARP.
27+
let function = block.function();
28+
// TODO: We might need to make relocatable regions configurable.
29+
let relocatable_regions = relocatable_regions(&function.view());
30+
let Ok(llil) = function.low_level_il() else {
31+
// Don't even think this is possible but _shrug_.
32+
return lines;
33+
};
34+
35+
for line in &mut lines {
36+
let llil_instr_idx = LowLevelInstructionIndex(line.instruction_index);
37+
if let Some(llil_instr) = llil.instruction_from_index(llil_instr_idx) {
38+
if is_blacklisted_instruction(&llil_instr) {
39+
// We have a blacklisted instruction, highlight it as orange!
40+
line.highlight = HighlightColor::StandardHighlightColor {
41+
color: HighlightStandardColor::OrangeHighlightColor,
42+
alpha: 155,
43+
};
44+
} else if is_variant_instruction(&relocatable_regions, &llil_instr) {
45+
// We have a variant instruction, highlight it as red!
46+
line.highlight = HighlightColor::StandardHighlightColor {
47+
color: HighlightStandardColor::RedHighlightColor,
48+
alpha: 155,
49+
};
50+
}
51+
}
52+
}
53+
54+
lines
55+
}
56+
}

0 commit comments

Comments
 (0)