summaryrefslogtreecommitdiff
path: root/examples/breakpoint
diff options
context:
space:
mode:
authorAndrew Lamoureux <lwerdna@users.noreply.github.com>2017-03-15 20:33:55 -0400
committerGitHub <noreply@github.com>2017-03-15 20:33:55 -0400
commit31d34d5d067ed4c5fe071eb8637b10ed50607555 (patch)
tree9347ba4e5e6a2b26baf620f59e56db7965bb47b5 /examples/breakpoint
parent164c7a680697be72d7f42af28b89012e5c6dd53b (diff)
parent1f7523ce2b1edac1014d781fc771d5b82568e2f1 (diff)
Merge branch 'dev' into dev
Diffstat (limited to 'examples/breakpoint')
-rw-r--r--examples/breakpoint/Makefile57
-rw-r--r--examples/breakpoint/Makefile.win16
-rw-r--r--examples/breakpoint/src/breakpoint.cpp14
3 files changed, 80 insertions, 7 deletions
diff --git a/examples/breakpoint/Makefile b/examples/breakpoint/Makefile
new file mode 100644
index 00000000..d85b63e5
--- /dev/null
+++ b/examples/breakpoint/Makefile
@@ -0,0 +1,57 @@
+# Path to prebuilt libbinaryninjaapi.a
+BINJA_API_A := ../../bin/libbinaryninjaapi.a
+
+# Path to binaryninjaapi.h and json
+INC := -I../../
+
+UNAME_S := $(shell uname -s)
+ifeq ($(UNAME_S),Linux)
+ # Path to binaryninja install
+ BINJAPATH := $(HOME)/binaryninja
+else
+ BINJAPATH := /Applications/Binary\ Ninja.app/Contents/MacOS
+endif
+
+SRCDIR := src
+BUILDDIR := build
+TARGETDIR := bin
+
+TARGETNAME := breakpoint
+TARGET := $(TARGETDIR)/$(TARGETNAME)
+INSTALLBINDIR := $(BINJAPATH)/plugins/
+
+SRCEXT := cpp
+SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
+OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
+
+LIBS := -L $(BINJAPATH) -lbinaryninjacore
+CFLAGS := -c -std=gnu++11 -O2 -Wall -W -fPIC -pipe
+ifeq ($(UNAME_S),Linux)
+ CC := g++
+all: $(TARGET).so
+else
+ CC := $(shell xcrun -f clang++)
+ CFLAGS += -arch x86_64 -pipe -stdlib=libc++ -mmacosx-version-min=10.7
+all: $(TARGET).dylib
+endif
+
+$(TARGET).so: $(OBJECTS)
+ @mkdir -p $(TARGETDIR)
+ $(CC) -shared $^ $(BINJA_API_A) $(LIBS) -o $@
+
+$(TARGET).dylib: $(OBJECTS)
+ @mkdir -p $(TARGETDIR)
+ $(CC) -dynamiclib $^ $(BINJA_API_A) $(LIBS) -o $@
+ install_name_tool -id @loader_path/$(TARGETNAME).dylib -add_rpath @loader_path/.. $@
+
+$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
+ @mkdir -p $(BUILDDIR)
+ $(CC) $(CFLAGS) $(INC) -c -o $@ $<
+
+clean:
+ $(RM) -r $(BUILDDIR) $(TARGETDIR)
+
+install:
+ cp $(TARGET) $(INSTALLBINDIR)
+
+.PHONY: clean
diff --git a/examples/breakpoint/Makefile.win b/examples/breakpoint/Makefile.win
new file mode 100644
index 00000000..00cbbfa1
--- /dev/null
+++ b/examples/breakpoint/Makefile.win
@@ -0,0 +1,16 @@
+BINJA_API_INC_PATH = ..\..\
+BINJA_API_LIB = ..\..\bin\libbinaryninjaapi.lib
+BINJA_CORE_LIB = "c:\Program Files\Vector35\BinaryNinja\binaryninjacore.lib"
+
+FLAGS = /DWIN32 /D__WIN32__ /EHsc /I$(BINJA_API_INC_PATH) /link $(BINJA_API_LIB) $(BINJA_CORE_LIB)
+
+bininfo.dll: ./src/breakpoint.cpp
+ if not exist bin mkdir bin
+ cl ./src/breakpoint.cpp /LD $(FLAGS) /OUT:.\bin\breakpoint.dll
+
+clean:
+ if exist *.obj del *.obj
+ if exist *.exp del *.exp
+ if exist *.lib del *.lib
+ if exist *.dll del *.dll
+ if exist .\bin del /S /Q bin
diff --git a/examples/breakpoint/src/breakpoint.cpp b/examples/breakpoint/src/breakpoint.cpp
index 99d9b169..4fac98ac 100644
--- a/examples/breakpoint/src/breakpoint.cpp
+++ b/examples/breakpoint/src/breakpoint.cpp
@@ -7,10 +7,10 @@ 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
+ // Also possible:
+ // register
+ // register_for_address
+ // register_for_function
Ref<Architecture> arch = view->GetDefaultArchitecture();
string arch_name = arch->GetName();
@@ -18,9 +18,9 @@ void write_breakpoint(BinaryNinja::BinaryView *view, uint64_t start, uint64_t le
if (arch_name.compare(0, 3, "x86") == 0) {
string int3s = string(length, '\xcc');
view->Write(start, int3s.c_str(), length);
- } else {
+ } else {
LogError("No support for breakpoint on %s", arch_name.c_str());
- }
+ }
}
extern "C"
@@ -33,4 +33,4 @@ extern "C"
&write_breakpoint);
return true;
}
-}
+} \ No newline at end of file