summaryrefslogtreecommitdiff
path: root/examples/breakpoint/src
diff options
context:
space:
mode:
authorbambu <bambu@revengsec.com>2016-06-05 21:14:13 -0400
committerbambu <bambu@revengsec.com>2016-06-05 21:18:52 -0400
commit5abb8218e5cd2be9b4cefb16eebdee6caf8108c6 (patch)
treec5db708e7eff7b874991c2493c2d4d609c45ea4b /examples/breakpoint/src
parent0c3c4285a38d70bafb089b85e6764d0f4153ff9c (diff)
Makefile for building binaryninja-api and example c++ plugin
Diffstat (limited to 'examples/breakpoint/src')
-rw-r--r--examples/breakpoint/src/breakpoint.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/breakpoint/src/breakpoint.cpp b/examples/breakpoint/src/breakpoint.cpp
new file mode 100644
index 00000000..41476411
--- /dev/null
+++ b/examples/breakpoint/src/breakpoint.cpp
@@ -0,0 +1,36 @@
+#include <inttypes.h>
+#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<Architecture> 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;
+ }
+}