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') 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 From 164c7a680697be72d7f42af28b89012e5c6dd53b Mon Sep 17 00:00:00 2001 From: John Hurlman Date: Tue, 6 Dec 2016 02:14:56 +0000 Subject: CMake files for binaryninjaapi and breakpoint --- .gitignore | 10 +++++++++ CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++ examples/breakpoint/CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 examples/breakpoint/CMakeLists.txt (limited to 'examples') diff --git a/.gitignore b/.gitignore index 08190698..dad2e692 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,13 @@ site/* api-docs/build/* .env api-docs/source/binaryninja.* +bin/ + +# CMake +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..9b835d75 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +add_library(binaryninjaapi STATIC + architecture.cpp + backgroundtask.cpp + basicblock.cpp + binaryninjaapi.cpp + binaryreader.cpp + binaryview.cpp + binaryviewtype.cpp + binarywriter.cpp + callingconvention.cpp + databuffer.cpp + demangle.cpp + fileaccessor.cpp + filemetadata.cpp + function.cpp + functiongraph.cpp + functiongraphblock.cpp + functionrecognizer.cpp + interaction.cpp + jsoncpp.cpp + log.cpp + lowlevelil.cpp + mainthread.cpp + platform.cpp + plugin.cpp + scriptingprovider.cpp + tempfile.cpp + transform.cpp + type.cpp + update.cpp + ) + +set_target_properties(binaryninjaapi PROPERTIES + CXX_STANDARD 11 + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin + ) diff --git a/examples/breakpoint/CMakeLists.txt b/examples/breakpoint/CMakeLists.txt new file mode 100644 index 00000000..916778c8 --- /dev/null +++ b/examples/breakpoint/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +project(breakpoint CXX) + +add_library(${PROJECT_NAME} SHARED + src/breakpoint.cpp) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..) + +if(WIN32) + set(BINJA_DIR "C:\\Program Files\\Vector35\\Binary Ninja" + CACHE PATH "Binary Ninja installation directory") + set(BINJA_BIN_DIR "${BINJA_DIR}") + set(BINJA_PLUGINS_DIR "$ENV{APPDATA}/Binary Ninja/plugins" + CACHE PATH "Binary Ninja user plugins directory") +elseif(APPLE) + set(BINJA_DIR "/Applications/Binary Ninja.app" + CACHE PATH "Binary Ninja installation directory") + set(BINJA_BIN_DIR "${BINJA_DIR}/Contents/MacOS") + set(BINJA_PLUGINS_DIR "$ENV{HOME}/Library/Application Support/Binary Ninja/plugins" + CACHE PATH "Binary Ninja user plugins directory") +else() + set(BINJA_DIR "$ENV{HOME}/binaryninja" + CACHE PATH "Binary Ninja installation directory") + set(BINJA_BIN_DIR "${BINJA_DIR}") + set(BINJA_PLUGINS_DIR "$ENV{HOME}/.binaryninja/plugins" + CACHE PATH "Binary Ninja user plugins directory") +endif() + +find_library(BINJA_API_LIBRARY binaryninjaapi + HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../../bin) +find_library(BINJA_CORE_LIBRARY binaryninjacore + HINTS ${BINJA_BIN_DIR}) + +target_link_libraries(${PROJECT_NAME} + ${BINJA_API_LIBRARY} + ${BINJA_CORE_LIBRARY} + ) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../bin + ) + +install(TARGETS ${PROJECT_NAME} DESTINATION ${BINJA_PLUGINS_DIR}) -- cgit v1.3.1