From 5abb8218e5cd2be9b4cefb16eebdee6caf8108c6 Mon Sep 17 00:00:00 2001 From: bambu Date: Sun, 5 Jun 2016 21:14:13 -0400 Subject: Makefile for building binaryninja-api and example c++ plugin --- Makefile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c1e159d3 --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + LIB := -L/Applications/Binary\ Ninja.app/Contents/MacOS/ -lbinaryninjacore +else + LIB := -L$(HOME)/binaryninja/ -lbinaryninjacore +endif + + +TARGETDIR := bin +TARGETNAME := libbinaryninjaapi +TARGET := $(TARGETDIR)/$(TARGETNAME) + +SRCEXT = .cpp +SOURCES = $(wildcard *$(SRCEXT)) +OBJECTS = $(SOURCES:.cpp=.o) + + +CFLAGS := -c -fPIC -O2 -pipe -std=gnu++11 -Wall -W +ifeq ($(UNAME_S),Darwin) + CC := $(shell xcrun -f clang++) + AR := $(shell xcrun -f ar) + CFLAGS += -stdlib=libc++ +all: $(TARGET).a $(TARGET).dylib +else + CC := g++ + AR := ar +all: $(TARGET).a $(TARGET).so +endif + +$(TARGET).a: $(OBJECTS) + @mkdir -p $(TARGETDIR) + $(AR) rcs $@ $^ + +$(TARGET).so: $(OBJECTS) + @mkdir -p $(TARGETDIR) + $(CC) -shared $(LIB) $(JSONCPP) $^ -o $@ + +$(TARGET).dylib: $(OBJECTS) + $(CC) -dynamiclib $(LIB) $(JSONCPP) $^ -o $@ + install_name_tool -id @loader_path/$(TARGETNAME).dylib -add_rpath @loader_path/.. $@ + +%.o: %.cpp + @echo " Compiling... $@ $<" + $(CC) $(CFLAGS) $(INC) -c -o $@ $< + +clean: + @echo " Cleaning..."; + $(RM) -r *.o $(TARGETDIR) + +.PHONY: clean -- cgit v1.3.1 From 5a42aec73a77a3a54baf054cde9047533709be31 Mon Sep 17 00:00:00 2001 From: Bambu Date: Thu, 25 Aug 2016 22:04:12 -0400 Subject: Removed dynamic linking. Added c++ version of arm-syscall python plugin. Renamed it since it works for more than just arm --- Makefile | 14 +--- examples/print_syscalls/Makefile | 54 +++++++++++++ examples/print_syscalls/src/arm-syscall.cpp | 115 ++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 examples/print_syscalls/Makefile create mode 100644 examples/print_syscalls/src/arm-syscall.cpp (limited to 'Makefile') diff --git a/Makefile b/Makefile index c1e159d3..9eb2d52a 100644 --- a/Makefile +++ b/Makefile @@ -17,28 +17,20 @@ OBJECTS = $(SOURCES:.cpp=.o) CFLAGS := -c -fPIC -O2 -pipe -std=gnu++11 -Wall -W ifeq ($(UNAME_S),Darwin) - CC := $(shell xcrun -f clang++) + CC := $(shell xcrun -f g++) AR := $(shell xcrun -f ar) CFLAGS += -stdlib=libc++ -all: $(TARGET).a $(TARGET).dylib else CC := g++ AR := ar -all: $(TARGET).a $(TARGET).so endif +all: $(TARGET).a + $(TARGET).a: $(OBJECTS) @mkdir -p $(TARGETDIR) $(AR) rcs $@ $^ -$(TARGET).so: $(OBJECTS) - @mkdir -p $(TARGETDIR) - $(CC) -shared $(LIB) $(JSONCPP) $^ -o $@ - -$(TARGET).dylib: $(OBJECTS) - $(CC) -dynamiclib $(LIB) $(JSONCPP) $^ -o $@ - install_name_tool -id @loader_path/$(TARGETNAME).dylib -add_rpath @loader_path/.. $@ - %.o: %.cpp @echo " Compiling... $@ $<" $(CC) $(CFLAGS) $(INC) -c -o $@ $< diff --git a/examples/print_syscalls/Makefile b/examples/print_syscalls/Makefile new file mode 100644 index 00000000..54fd1237 --- /dev/null +++ b/examples/print_syscalls/Makefile @@ -0,0 +1,54 @@ +# 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/ + CC := g++ +else + BINJAPATH := /Applications/Binary\ Ninja.app/Contents/MacOS + CC := $(shell xcrun -f clang++) +endif + +SRCDIR := src +BUILDDIR := build +TARGETDIR := bin + +TARGETNAME := print_syscalls +TARGET := $(TARGETDIR)/$(TARGETNAME) + +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 -ggdb +ifeq ($(UNAME_S),Darwin) + CFLAGS += -arch x86_64 -pipe -stdlib=libc++ +endif + +all: $(TARGET) + +ifeq ($(UNAME_S),Linux) +$(TARGET): $(OBJECTS) + @mkdir -p $(TARGETDIR) + $(CC) $^ $(BINJA_API_A) $(LIBS) -Wl,-rpath=$(BINJAPATH) -ldl -o $@ +else +$(TARGET): $(OBJECTS) + @mkdir -p $(TARGETDIR) + $(CC) $^ $(BINJA_API_A) $(LIBS) -o $@ + install_name_tool -change @rpath/libbinaryninjacore.dylib $(BINJAPATH)/libbinaryninjacore.dylib $@ +endif + +$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) + @mkdir -p $(BUILDDIR) + $(CC) $(CFLAGS) $(INC) -c -o $@ $< + +clean: + $(RM) -r $(BUILDDIR) $(TARGETDIR) + +.PHONY: clean diff --git a/examples/print_syscalls/src/arm-syscall.cpp b/examples/print_syscalls/src/arm-syscall.cpp new file mode 100644 index 00000000..3424619b --- /dev/null +++ b/examples/print_syscalls/src/arm-syscall.cpp @@ -0,0 +1,115 @@ +/* + * Outputs the syscall numbers called by a binary. + */ + +#include + +#include +#include + +#include "binaryninjacore.h" +#include "binaryninjaapi.h" + +using namespace BinaryNinja; +using namespace std; + +#ifndef __WIN32__ +#include +#include +string get_plugins_directory() +{ + Dl_info info; + if (!dladdr((void *)BNGetBundledPluginDirectory, &info)) + return NULL; + + stringstream ss; + ss << dirname((char *)info.dli_fname) << "/plugins/"; + return ss.str(); +} +#else +string get_plugins_directory() +{ + return "C:\\Program Files\\Vector35\\Binary Ninja\\plugins\\"; +} +#endif + +bool is_file(char *fname) +{ + struct stat buf; + if (stat(fname, &buf) == 0 && (buf.st_mode & S_IFREG) == S_IFREG) + return true; + + return false; +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + cerr << "USAGE: " << argv[0] << " " << endl; + exit(-1); + } + + char *fname = argv[1]; + if (!is_file(fname)) { + cerr << "Error: " << fname << " is not a regular file" << endl; + exit(-1); + } + + /* In order to initiate the bundled plugins properly, the location + * of where bundled plugins directory is must be set. Since + * libbinaryninjacore is in the path get the path to it and use it to + * determine the plugins directory */ + SetBundledPluginDirectory(get_plugins_directory()); + InitCorePlugins(); + InitUserPlugins(); + + auto bd = BinaryData(new FileMetadata(), fname); + BinaryView *bv = 0; + + for (auto type : BinaryViewType::GetViewTypesForData(&bd)) { + if (type->GetName() != "Raw") { + bv = type->Create(&bd); + break; + } + } + + if (!bv || bv->GetTypeName() == "Raw"){ + cerr << "Error: Unable to get any other view type besides Raw"; + exit(-1); + } + + bv->UpdateAnalysis(); + while (bv->GetAnalysisProgress().state != IdleState); + + auto arch = bv->GetDefaultArchitecture(); + auto platform = bv->GetDefaultPlatform(); + + auto cc = platform->GetSystemCallConvention(); + if (!cc) { + cerr << "Error: No system call conventions found for " + << platform->GetName() << endl; + exit(-1); + } + + auto reg = cc->GetIntegerArgumentRegisters()[0]; + + for (Function *func : bv->GetAnalysisFunctionList()) { + auto il_func = func->GetLowLevelIL(); + + for (size_t i = 0; i < il_func->GetInstructionCount(); i++) { + auto instr = (*il_func)[il_func->GetIndexForInstruction(i)]; + + if (instr.operation == LLIL_SYSCALL) { + auto reg_value = func->GetRegisterValueAtLowLevelILInstruction(i, reg); + + cout << "System call address: 0x" + << hex << instr.address + << " - " + << dec << reg_value.value + << endl; + } + } + } + + return 0; +} -- cgit v1.3.1 From 15bbf9f7b2f9067159469c9c9bdb4183b25bc9c6 Mon Sep 17 00:00:00 2001 From: Andrew Lamoureux Date: Wed, 15 Mar 2017 23:38:36 -0400 Subject: root CMakeLists.txt references json properly --- CMakeLists.txt | 8 +++++++- Makefile | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'Makefile') diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b835d75..a635c9f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) +project(binaryninja-api) + add_library(binaryninjaapi STATIC architecture.cpp backgroundtask.cpp @@ -19,7 +21,7 @@ add_library(binaryninjaapi STATIC functiongraphblock.cpp functionrecognizer.cpp interaction.cpp - jsoncpp.cpp + json/jsoncpp.cpp log.cpp lowlevelil.cpp mainthread.cpp @@ -32,6 +34,10 @@ add_library(binaryninjaapi STATIC update.cpp ) +set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) + +include_directories(${PROJECT_SOURCE_DIR}) + set_target_properties(binaryninjaapi PROPERTIES CXX_STANDARD 11 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin diff --git a/Makefile b/Makefile index 9eb2d52a..0b18c061 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin) - LIB := -L/Applications/Binary\ Ninja.app/Contents/MacOS/ -lbinaryninjacore -else - LIB := -L$(HOME)/binaryninja/ -lbinaryninjacore -endif +#UNAME_S := $(shell uname -s) +#ifeq ($(UNAME_S),Darwin) +# LIB := -L/Applications/Binary\ Ninja.app/Contents/MacOS/ -lbinaryninjacore +#else +# LIB := -L$(HOME)/binaryninja/ -lbinaryninjacore +#endif TARGETDIR := bin -- cgit v1.3.1 From c4f968cad46c51a307396ee4f21f60aa51393fe4 Mon Sep 17 00:00:00 2001 From: Andrew Lamoureux Date: Fri, 24 Mar 2017 16:32:50 -0400 Subject: ensure jsoncpp is in libbinaryninjaapi.lib for make (this was already the case for cmake builds) --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 0b18c061..23414c45 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ TARGET := $(TARGETDIR)/$(TARGETNAME) SRCEXT = .cpp SOURCES = $(wildcard *$(SRCEXT)) -OBJECTS = $(SOURCES:.cpp=.o) +OBJECTS = $(SOURCES:.cpp=.o) json.o CFLAGS := -c -fPIC -O2 -pipe -std=gnu++11 -Wall -W @@ -35,6 +35,9 @@ $(TARGET).a: $(OBJECTS) @echo " Compiling... $@ $<" $(CC) $(CFLAGS) $(INC) -c -o $@ $< +json.o: ./json/jsoncpp.cpp ./json/json.h ./json/json-forwards.h + $(CC) $(CFLAGS) -I. -c -o $@ $< + clean: @echo " Cleaning..."; $(RM) -r *.o $(TARGETDIR) -- cgit v1.3.1