@@ -0,0 +1,2304 @@
+from binaryninja.datarender import DataRenderer%0Afrom binaryninja.function import DisassemblyTextLine%0Afrom binaryninja.enums import TypeClass, HighlightStandardColor%0Afrom binaryninja.binaryview import BinaryView%0Afrom binaryninja.architecture import InstructionTextToken%0Afrom binaryninja.types import Type%0Afrom typing import List%0A%0Aimport sys%0Asys.path.append(%22/Users/peterlafosse/Qt/PySide/6.1.3/python3/site-packages/%22)%0Afrom PySide6.QtGui import QKeySequence%0Afrom binaryninjaui import UIActionHandler, UIAction, UIActionContext%0A%0Aclass CodeDataRenderer(DataRenderer):%0A%09def __init__(self):%0A%09%09DataRenderer.__init__(self)%0A%09def perform_is_valid_for_data(self, _, bv: BinaryView, addr: int, type: Type, context: List%5Bstr%5D) -%3E bool:%0A%09%09sym = bv.get_symbol_at(addr)%0A%09%09return sym is not None and sym.name.startswith(%22CODE_%22) and type.type_class == TypeClass.ArrayTypeClass%0A%09def perform_get_lines_for_data(self, _, bv: BinaryView, addr: int, type: Type, prefix: List%5BInstructionTextToken%5D, width: int, context: List%5Bstr%5D) -%3E List%5BDisassemblyTextLine%5D:%0A%09%09end = addr + len(type)%0A%09%09result: List%5BDisassemblyTextLine%5D = %5B%5D%0A%09%09for tokens, size in bv.disassembly_tokens(addr, bv.arch):%0A%09%09%09if addr + size %3E end:%0A%09%09%09%09break%0A%09%09%09result.append(DisassemblyTextLine(%5B*tokens%5D, addr, color=HighlightStandardColor.RedHighlightColor))%0A%09%09%09addr += size%0A%09%09return result%0A%09def __del__(self):%0A%09%09pass%0A%0Adef make_code(bv: BinaryView, start: int, end: int) -%3E None:%0A%09if bv.get_basic_blocks_at(start):%0A%09%09return%0A%09if end - start %3C= 1:%0A%09%09# find the next basic block, data variable, or segment/section end%0A%09%09data_var = bv.get_next_data_var_after(start)%0A%09%09if data_var is not None:%0A%09%09%09end = data_var.address%0A%09%09else:%0A%09%09%09end = bv.end%0A%09%09end = min(bv.get_next_basic_block_start_after(start), end)%0A%09%09seg = bv.get_segment_at(start)%0A%09%09if seg is not None:%0A%09%09%09end = min(seg.end, end)%0A%09%09section_ends = %5Bs.end for s in bv.get_sections_at(start)%5D%0A%09%09end = min(*section_ends, end)%0A%09bv.define_data_var(start, Type.array(Type.int(1, False), end-start), f%22CODE_%7Bstart:08x%7D%22)%0A%0Adef make_code_helper(ctx: UIActionContext):%0A%09make_code(ctx.binaryView, ctx.address, ctx.address + ctx.length)%0A%0ACodeDataRenderer().register_type_specific()%0AUIAction.registerAction(%22Make Code%22, QKeySequence(%22C%22))%0AUIActionHandler.globalActions().bindAction(%22Make Code%22, UIAction(make_code_helper))

Add make_code.py plugin to python examples