Skip to content

Commit

Permalink
Add highlight render layer to WARP
Browse files Browse the repository at this point in the history
Highlights all variant instructions and blacklisted instructions

Variant instructions are highlighted red, blacklisted will be orange.
  • Loading branch information
emesare committed Feb 3, 2025
1 parent 1a45f7a commit 7816a61
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/warp/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::cache::register_cache_destructor;

use crate::matcher::MatcherSettings;
use crate::plugin::render_layer::HighlightRenderLayer;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::logger::Logger;
use binaryninja::rc::Ref;
Expand All @@ -14,6 +15,7 @@ mod debug;
mod ffi;
mod find;
mod load;
mod render_layer;
mod types;
mod workflow;

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

// Register our highlight render layer.
HighlightRenderLayer::register();

workflow::insert_workflow();

binaryninja::command::register_command(
Expand Down
56 changes: 56 additions & 0 deletions plugins/warp/src/plugin/render_layer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{is_blacklisted_instruction, is_variant_instruction, relocatable_regions};
use binaryninja::basic_block::BasicBlock;
use binaryninja::disassembly::DisassemblyTextLine;
use binaryninja::function::{HighlightColor, HighlightStandardColor, NativeBlock};
use binaryninja::low_level_il::instruction::LowLevelInstructionIndex;
use binaryninja::render_layer::{register_render_layer, RenderLayer};

pub struct HighlightRenderLayer {}

impl HighlightRenderLayer {
pub fn register() {
register_render_layer(
"WARP Highlight Layer",
HighlightRenderLayer {},
Default::default(),
);
}
}

impl RenderLayer for HighlightRenderLayer {
fn apply_to_llil_block(
&self,
block: &BasicBlock<NativeBlock>,
mut lines: Vec<DisassemblyTextLine>,
) -> Vec<DisassemblyTextLine> {
// Highlight any LLIL instruction that will be masked by WARP.
let function = block.function();
// TODO: We might need to make relocatable regions configurable.
let relocatable_regions = relocatable_regions(&function.view());
let Ok(llil) = function.low_level_il() else {
// Don't even think this is possible but _shrug_.
return lines;
};

for line in &mut lines {
let llil_instr_idx = LowLevelInstructionIndex(line.instruction_index);
if let Some(llil_instr) = llil.instruction_from_index(llil_instr_idx) {
if is_blacklisted_instruction(&llil_instr) {
// We have a blacklisted instruction, highlight it as orange!
line.highlight = HighlightColor::StandardHighlightColor {
color: HighlightStandardColor::OrangeHighlightColor,
alpha: 155,
};
} else if is_variant_instruction(&relocatable_regions, &llil_instr) {
// We have a variant instruction, highlight it as red!
line.highlight = HighlightColor::StandardHighlightColor {
color: HighlightStandardColor::RedHighlightColor,
alpha: 155,
};
}
}
}

lines
}
}

0 comments on commit 7816a61

Please sign in to comment.