Skip to content

Commit

Permalink
Merge pull request #52 from cblichmann:v11-binja
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 315253853
Change-Id: If39034365f3e1995681f289c8957e6476c856cec
  • Loading branch information
cblichmann committed Jun 8, 2020
2 parents 054961f + 5d76f25 commit 050b22e
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set(Protobuf_USE_STATIC_LIBS TRUE)
find_package(Boost 1.55 REQUIRED)
find_package(Git)
find_package(IdaSdk REQUIRED)
find_package(BinaryNinjaApi)
find_package(OpenSSL 1.0.2 REQUIRED)
if(BINEXPORT_ENABLE_POSTGRESQL)
find_package(PostgreSQL 9.5 REQUIRED)
Expand Down Expand Up @@ -343,6 +344,11 @@ ida_install(TARGETS ${binexport_plugin_name}
RUNTIME DESTINATION binexport-prefix
LIBRARY DESTINATION binexport-prefix)

# Binary Ninja plugin (experimental)
if(BinaryNinjaApi_FOUND)
add_subdirectory(binaryninja)
endif()

# BinExport reader library
add_library(binexport_reader STATIC
reader/call_graph.cc
Expand Down
101 changes: 101 additions & 0 deletions FindBinaryNinjaApi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# FindBinaryNinjaApi
# ------------------
#
# Locates and configures the Binary Ninja API. Needs version 1.2.1921 or
# later.
#
# Use this module by invoking find_package with the form:
#
# find_package(BinaryNinjaApi
# [REQUIRED] # Stop the build if Binary Ninja API is not found
# )
#
# Defines the following variables:
#
# BinaryNinjaApi_INCLUDE_DIRS - Include directories for the Binary Ninja API.
# BinaryNinjaApi_LIBRARIES - Library files to link against
#
# This module reads hints about search locations from variables:
#
# BinaryNinjaApi_ROOT_DIR - Preferred installation prefix for the API
# ENV{BINJA_API_DIR} - Like BinaryNinjaApi_ROOT_DIR
# BinaryNinja_DIR - Installation prefix containing the Binary Ninja
# core library
# ENV{BINJA_DIR} - Like BinaryNinja_DIR
#
# Example:
#
# find_package(BinaryNinjaApi REQUIRED)
#
# # Builds targets plugin.dll
# add_library(exmaple_plugin myplugin.cc)
# target_link_libraries(exmaple_plugin PRIVATE BinaryNinja::API)

include(CMakeParseArguments)
include(FindPackageHandleStandardArgs)

find_path(BinaryNinjaApi_DIR
NAMES binaryninjaapi.h
HINTS "${BinaryNinjaApi_ROOT_DIR}" ENV BINJA_API_DIR
PATHS "${CMAKE_CURRENT_LIST_DIR}/third_party/binaryninja-api"
"$ENV{HOME}/binaryninja-api"
DOC "Location of the Binary Ninja API"
NO_DEFAULT_PATH
)
set(BinaryNinjaApi_INCLUDE_DIRS "${BinaryNinjaApi_DIR}")

find_library(BinaryNinjaApi_LIBRARY
NAMES binaryninjaapi
PATHS "${BinaryNinjaApi_DIR}/bin"
NO_DEFAULT_PATH
)

set(_binaryninjaapi_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
find_library(BinaryNinjaCore_LIBRARY
NAMES binaryninjacore
NAMES_PER_DIR
HINTS "${BinaryNinja_DIR}" ENV BINJA_DIR
"$ENV{ProgramFiles}/Vector35/BinaryNinja" # Windows
"$ENV{HOME}/binaryninja"
PATHS "/Applications/Binary Ninja.app/Contents/MacOS"
"/opt/binaryninja"
DOC "Location of Binary Ninja"
NO_DEFAULT_PATH
)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_binaryninjaapi_FIND_LIBRARY_SUFFIXES})

if(BinaryNinjaCore_LIBRARY AND BinaryNinjaApi_LIBRARY)
list(APPEND BinaryNinjaApi_LIBRARIES
"${BinaryNinjaApi_LIBRARY}"
"${BinaryNinjaCore_LIBRARY}"
)
add_library(binaryninjaapi INTERFACE IMPORTED GLOBAL)
add_library(BinaryNinja::API ALIAS binaryninjaapi)
target_include_directories(binaryninjaapi INTERFACE
${BinaryNinjaApi_INCLUDE_DIRS})
target_link_libraries(binaryninjaapi INTERFACE
${BinaryNinjaApi_LIBRARIES})
endif()

find_package_handle_standard_args(BinaryNinjaApi
FOUND_VAR BinaryNinjaApi_FOUND
REQUIRED_VARS BinaryNinjaApi_DIR
BinaryNinjaApi_INCLUDE_DIRS
BinaryNinjaApi_LIBRARIES
FAIL_MESSAGE "Binary Ninja API not found, try setting BinaryNinjaApi_ROOT_DIR and/or BinaryNinja_DIR. Note that the API itself needs to be built first."
)
3 changes: 1 addition & 2 deletions FindIdaSdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# FindIdaSdk
# ----------
#
# Locates and configures the IDA Pro SDK. Only support version 7.0 or hight.
# Locates and configures the IDA Pro SDK. Supports version 7.0 or higher.
#
# Use this module by invoking find_package with the form:
#
Expand All @@ -36,7 +36,6 @@
# Example (this assumes Windows):
#
# find_package(IdaSdk REQUIRED)
# include_directories(${IdaSdk_INCLUDE_DIRS})
#
# # Builds targets plugin.dll and plugin64.dll
# add_ida_plugin(plugin myplugin.cc)
Expand Down
26 changes: 26 additions & 0 deletions binaryninja/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019-2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_library(${binexport_plugin_name} SHARED
main_plugin.cc
main_plugin.h
log_sink.cc
log_sink.h
)
target_link_libraries(${binexport_plugin_name} PRIVATE
absl::strings
BinaryNinja::API
binexport_core
OpenSSL::SSL
)
48 changes: 48 additions & 0 deletions binaryninja/log_sink.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2019-2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "third_party/zynamics/binexport/binaryninja/log_sink.h"

// clang-format off
#include "binaryninjaapi.h" // NOLINT
// clang-format on

#include "base/logging.h"
#include "build/absl/absl/base/log_severity.h"
#include "build/absl/absl/strings/string_view.h"
#include "third_party/absl/strings/string_view.h"
#include "third_party/zynamics/binexport/util/logging.h"

namespace security::binexport {

void BinaryNinjaLogSink::Send(const not_absl::LogEntry& entry) {
BNLogLevel level;
switch (entry.log_severity()) {
case absl::LogSeverity::kInfo:
level = InfoLog;
break;
case absl::LogSeverity::kWarning:
level = WarningLog;
break;
case absl::LogSeverity::kError:
case absl::LogSeverity::kFatal:
default:
level = ErrorLog;
break;
}
absl::string_view message = entry.text_message();
BinaryNinja::Log(level, "%*s", message.size(), message.data());
}

} // namespace security::binexport
30 changes: 30 additions & 0 deletions binaryninja/log_sink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019-2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef BINARYNINJA_LOG_SINK_H_
#define BINARYNINJA_LOG_SINK_H_

#include "base/logging.h"
#include "third_party/zynamics/binexport/util/logging.h"

namespace security::binexport {

class BinaryNinjaLogSink : public not_absl::LogSink {
public:
void Send(const not_absl::LogEntry& entry) override;
};

} // namespace security::binexport

#endif // BINARYNINJA_LOG_SINK_H_
Loading

0 comments on commit 050b22e

Please sign in to comment.