summaryrefslogtreecommitdiff
path: root/examples/breakpoint/src/breakpoint.cpp
blob: 75156e1db8c996bb07a7d0d93276c60914d7dd5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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"
{
	BN_DECLARE_CORE_ABI_VERSION

	BINARYNINJAPLUGIN bool CorePluginInit()
	{
		// Register the plugin with Binary Ninja
		PluginCommand::RegisterForRange(
		    "Convert to breakpoint", "Fill region with breakpoint instructions.", &write_breakpoint);
		return true;
	}
}