From ed994792d2735b701f5284fc8e3e1444dfc3c650 Mon Sep 17 00:00:00 2001 From: John Hurlman Date: Tue, 6 Dec 2016 02:14:09 +0000 Subject: Add example C++ plugin: breakpoint --- examples/breakpoint/src/breakpoint.cpp | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/breakpoint/src/breakpoint.cpp (limited to 'examples/breakpoint/src/breakpoint.cpp') diff --git a/examples/breakpoint/src/breakpoint.cpp b/examples/breakpoint/src/breakpoint.cpp new file mode 100644 index 00000000..99d9b169 --- /dev/null +++ b/examples/breakpoint/src/breakpoint.cpp @@ -0,0 +1,36 @@ +#include +#include "binaryninjaapi.h" + +using namespace BinaryNinja; +using namespace std; + +void write_breakpoint(BinaryNinja::BinaryView *view, uint64_t start, uint64_t length) +{ + // Sample function to show registering a plugin menu item for a range of bytes. + // Also possible: + // register + // register_for_address + // register_for_function + + Ref arch = view->GetDefaultArchitecture(); + string arch_name = arch->GetName(); + + if (arch_name.compare(0, 3, "x86") == 0) { + string int3s = string(length, '\xcc'); + view->Write(start, int3s.c_str(), length); + } else { + LogError("No support for breakpoint on %s", arch_name.c_str()); + } +} + +extern "C" +{ + BINARYNINJAPLUGIN bool CorePluginInit() + { + // Register the plugin with Binary Ninja + PluginCommand::RegisterForRange("Convert to breakpoint", + "Fill region with breakpoint instructions.", + &write_breakpoint); + return true; + } +} -- cgit v1.3.1