From 156ad4bb6d7c789c4f4a1c7daf635eb7d3a92400 Mon Sep 17 00:00:00 2001 From: Brick <6098371+0x1F9F1@users.noreply.github.com> Date: Fri, 15 Feb 2019 17:23:04 +0000 Subject: Greatly improved CMake builds + Fixed tests compilation --- examples/print_syscalls/CMakeLists.txt | 18 +++++++++++++++++ examples/print_syscalls/src/arm-syscall.cpp | 30 +++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 examples/print_syscalls/CMakeLists.txt (limited to 'examples/print_syscalls') diff --git a/examples/print_syscalls/CMakeLists.txt b/examples/print_syscalls/CMakeLists.txt new file mode 100644 index 00000000..d8495b3c --- /dev/null +++ b/examples/print_syscalls/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +project(print_syscalls CXX) + +add_executable(${PROJECT_NAME} + src/arm-syscall.cpp) + +target_link_libraries(${PROJECT_NAME} + binaryninjaapi) + +if (NOT WIN32) + target_link_libraries(${PROJECT_NAME} + dl) +endif() + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../bin) diff --git a/examples/print_syscalls/src/arm-syscall.cpp b/examples/print_syscalls/src/arm-syscall.cpp index 3424619b..2eb5e402 100644 --- a/examples/print_syscalls/src/arm-syscall.cpp +++ b/examples/print_syscalls/src/arm-syscall.cpp @@ -9,11 +9,12 @@ #include "binaryninjacore.h" #include "binaryninjaapi.h" +#include "lowlevelilinstruction.h" using namespace BinaryNinja; using namespace std; -#ifndef __WIN32__ +#ifndef _WIN32 #include #include string get_plugins_directory() @@ -29,7 +30,7 @@ string get_plugins_directory() #else string get_plugins_directory() { - return "C:\\Program Files\\Vector35\\Binary Ninja\\plugins\\"; + return "C:\\Program Files\\Vector35\\BinaryNinja\\plugins\\"; } #endif @@ -63,23 +64,24 @@ int main(int argc, char *argv[]) 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); + Ref bd = new BinaryData(new FileMetadata(), argv[1]); + Ref bv; + for (auto type : BinaryViewType::GetViewTypes()) + { + if (type->IsTypeValidForData(bd) && 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); + if (!bv || bv->GetTypeName() == "Raw") + { + fprintf(stderr, "Input file does not appear to be an exectuable\n"); + return -1; } - bv->UpdateAnalysis(); - while (bv->GetAnalysisProgress().state != IdleState); + bv->UpdateAnalysisAndWait(); auto arch = bv->GetDefaultArchitecture(); auto platform = bv->GetDefaultPlatform(); @@ -100,7 +102,7 @@ int main(int argc, char *argv[]) auto instr = (*il_func)[il_func->GetIndexForInstruction(i)]; if (instr.operation == LLIL_SYSCALL) { - auto reg_value = func->GetRegisterValueAtLowLevelILInstruction(i, reg); + auto reg_value = il_func->GetRegisterValueAtInstruction(reg, i); cout << "System call address: 0x" << hex << instr.address -- cgit v1.3.1