|
| 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