Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lwerdna committed Mar 16, 2017
2 parents 164c7a6 + 1f7523c commit 31d34d5
Show file tree
Hide file tree
Showing 79 changed files with 22,319 additions and 12,135 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ binaryninjacore.lib
binaryninjacore.dll
binaryninjaapi.lib
python/_binaryninjacore.py
python/enums.py
python/generator
python/generator.exe
.vs
Expand All @@ -19,12 +20,13 @@ api-docs/build/*
.env
api-docs/source/binaryninja.*
bin/

# CMake
CMakeCache.txt
CMakeFiles
CMakeScripts
Makefile
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
*.pyc
api-docs/source/python.rst
api-docs/source/index.rst
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 g++)
AR := $(shell xcrun -f ar)
CFLAGS += -stdlib=libc++
else
CC := g++
AR := ar
endif

all: $(TARGET).a

$(TARGET).a: $(OBJECTS)
@mkdir -p $(TARGETDIR)
$(AR) rcs $@ $^

%.o: %.cpp
@echo " Compiling... $@ $<"
$(CC) $(CFLAGS) $(INC) -c -o $@ $<

clean:
@echo " Cleaning...";
$(RM) -r *.o $(TARGETDIR)

.PHONY: clean
23 changes: 23 additions & 0 deletions Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CFLAGS = /EHsc /DWIN32

TARGETDIR = bin
TARGETNAME = libbinaryninjaapi.lib
TARGET = .\$(TARGETDIR)\$(TARGETNAME)

OBJS = architecture.obj backgroundtask.obj basicblock.obj binaryninjaapi.obj binaryreader.obj binaryview.obj binaryviewtype.obj binarywriter.obj callingconvention.obj databuffer.obj demangle.obj fileaccessor.obj filemetadata.obj function.obj functiongraph.obj functiongraphblock.obj functionrecognizer.obj interaction.obj log.obj lowlevelil.obj mainthread.obj platform.obj plugin.obj scriptingprovider.obj tempfile.obj transform.obj type.obj update.obj jsoncpp.obj

$(TARGET): $(OBJS)
if not exist $(TARGETDIR) mkdir $(TARGETDIR)
lib $(OBJS) /OUT:$(TARGET)

jsoncpp.obj: json\jsoncpp.cpp
cl $(CFLAGS) /I. /c json\jsoncpp.cpp

# nmake "inference rules" are gnu make "pattern rules"
.cpp.obj:
cl $(CFLAGS) /c $<

clean:
if exist *.obj del *.obj
if exist $(TARGETDIR) del /Q /S $(TARGETDIR)

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ If interested in contributing, first please read and sign the [Contribution Lice

The issue tracker for this repository tracks not only issues with the source code contained here but also the broader Binary Ninja product.

## Building

Starting mid March 2017, the C++ portion of this API can be built into a static library (.a, .lib) that binary plugins can link against. Use Makefile on MacOS, Linux, and Windows mingw environments, and Makefile.win (nmake file) for Windows Visual Studio environment (nmake -f).

The compiled API contains names and functions you can use from your plugins, but most of the implementation is missing until you link up against libbinaryninjacore.dylib or libbinaryninjacore.dll (via import file libbinaryninjacore.lib). See the ./examples.

Since BinaryNinja is a 64-bit only product, ensure that you are using a 64-bit compiling and linking environment. Errors on windows like LNK1107 might indicate that your bits don't match.

## Examples

* bin-info is a standalone executable that prints some information about a given binary to stdout
* breakpoint is a plugin that allows you to select a region within an x86 binary and use the context menu to fill it with breakpoint bytes
* print_syscalls is a standalone executable that prints the syscalls used in a given binary
3 changes: 3 additions & 0 deletions api-docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
SOURCEDIR = source

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
Expand Down Expand Up @@ -47,6 +48,8 @@ help:
.PHONY: clean
clean:
rm -rf $(BUILDDIR)/*
rm $(SOURCEDIR)/binaryninja.*.rst
rm $(SOURCEDIR)/python.rst

.PHONY: html
html:
Expand Down
72 changes: 65 additions & 7 deletions api-docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,73 @@
import os
import sys
import platform
import inspect

if (platform.system() == "Darwin"):
bnpath=os.path.join(os.path.abspath('.'), "..", "..", "..", "ui", "binaryninja.app", "Contents", "Resources", "python")
bnpath=os.path.join(os.path.abspath('.'), "..", "..", "..", "ui", "binaryninja.app", "Contents", "Resources", "python")
else:
bnpath=os.path.join(os.path.abspath('.'), "..", "..", "..", "ui", "python")
bnpath=os.path.join(os.path.abspath('.'), "..", "..", "..", "ui", "python")

sys.path.insert(0, bnpath)
import binaryninja

def modulelist(modulename):
modules = inspect.getmembers(modulename, inspect.ismodule)
return filter(lambda x: x[0] not in ("abc", "ctypes", "core", "struct", "sys", "_binaryninjacore", "traceback", "code", "enum", "json", "threading", "startup", "associateddatastore"), modules)


def classlist(module):
members = inspect.getmembers(module, inspect.isclass)
if module.__name__ != "binaryninja.enums":
members = filter(lambda x: type(x[1]) != binaryninja.enum.EnumMeta, members)
members.extend(inspect.getmembers(module, inspect.isfunction))
return map(lambda x: x[0], filter(lambda x: not x[0].startswith("_"), members))


def generaterst():
pythonrst = open("index.rst", "w")
pythonrst.write('''Binary Ninja Python API Documentation
=====================================
.. toctree::
:maxdepth: 2
''')

for modulename, module in modulelist(binaryninja):
filename = 'binaryninja.{module}-module.rst'.format(module=modulename)
pythonrst.write(' {module} <{filename}>\n'.format(module=modulename, filename=filename))
modulefile = open(filename, "w")
modulefile.write('''{module} module
=====================
.. autosummary::
:toctree:
'''.format(module=modulename))

for classname in classlist(module):
modulefile.write(" binaryninja.{module}.{classname}\n".format(module=modulename, classname=classname))

modulefile.write('''\n.. toctree::
:maxdepth: 2\n''')

modulefile.write('''\n\n.. automodule:: binaryninja.{module}
:members:
:undoc-members:
:show-inheritance:'''.format(module=modulename))
modulefile.close()

pythonrst.write('''.. automodule:: binaryninja
:members:
:undoc-members:
:show-inheritance:
''')
pythonrst.close()


generaterst()

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand All @@ -50,7 +108,7 @@
]

autosummary_generate = True
autodoc_member_order = 'groupwise'
#autodoc_member_order = 'groupwise'

breathe_projects = { "BinaryNinja": "../../xml/" }
breathe_projects_source = {
Expand All @@ -72,7 +130,7 @@
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'python'
master_doc = 'index'

# General information about the project.
project = u'Binary Ninja API'
Expand Down Expand Up @@ -121,7 +179,7 @@
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#
add_module_names = False
add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
Expand Down Expand Up @@ -211,7 +269,7 @@

# If false, no module index is generated.
#
html_domain_indices = False
html_domain_indices = True

# If false, no index is generated.
#
Expand All @@ -223,7 +281,7 @@

# If true, links to the reST sources are added to the pages.
#
html_show_sourcelink = False
html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#
Expand Down
File renamed without changes.
73 changes: 0 additions & 73 deletions api-docs/source/python.rst

This file was deleted.

Loading

0 comments on commit 31d34d5

Please sign in to comment.