From 8cfc7e90e3c138603fef2aadaabaa38bd826fc60 Mon Sep 17 00:00:00 2001 From: Ende! Date: Mon, 17 Nov 2014 20:54:30 +0100 Subject: [PATCH] added CMakeLists.txt for cross-platform builds minor code changes to be standard-conform --- CMakeLists.txt | 64 +++++++++++++++++++ Examples/CustomDataSource/Main.cpp | 3 +- Examples/PerformanceTest/Main.cpp | 3 +- Examples/SimpleDemo/Main.cpp | 5 +- Examples/SymbolResolver/Main.cpp | 7 +- .../VXInstructionFormatter.cpp | 3 +- 6 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d424d6f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 2.8.12) + +project(VerteronDisassemblerEngine) + +option(BUILD_EXAMPLES "Build examples" TRUE) + +if (NOT CONFIGURED_ONCE) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(compiler_specific "-std=c++0x -Werror") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(compiler_specific "/WX /D_CRT_SECURE_NO_WARNINGS") + endif () + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${compiler_specific}" + CACHE STRING "Flags used by the compiler during all build types." FORCE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_specific}" + CACHE STRING "Flags used by the compiler during all build types." FORCE) +endif () + +# Library +set(vde_headers + "VerteronDisassemblerEngine/VXDisassembler.h" + "VerteronDisassemblerEngine/VXDisassemblerTypes.h" + "VerteronDisassemblerEngine/VXDisassemblerUtils.h" + "VerteronDisassemblerEngine/VXInstructionDecoder.h" + "VerteronDisassemblerEngine/VXInstructionFormatter.h" + "VerteronDisassemblerEngine/VXOpcodeTable.h") +set(vde_sources + "VerteronDisassemblerEngine/VXDisassemblerUtils.cpp" + "VerteronDisassemblerEngine/VXInstructionFormatter.cpp" + "VerteronDisassemblerEngine/VXOpcodeTable.cpp" + "VerteronDisassemblerEngine/VXInstructionDecoder.cpp") + +add_library("VerteronDisassemblerEngine" + ${vde_headers} + ${vde_sources}) + +# Examples +if (BUILD_EXAMPLES) + include_directories("VerteronDisassemblerEngine") + + add_executable("CustomDataSource" + "Examples/CustomDataSource/Main.cpp") + target_link_libraries("CustomDataSource" "VerteronDisassemblerEngine") + + add_executable("PerformanceTest" + "Examples/PerformanceTest/Main.cpp") + target_link_libraries("PerformanceTest" "VerteronDisassemblerEngine") + + add_executable("SimpleDemo" + "Examples/SimpleDemo/Main.cpp") + target_link_libraries("SimpleDemo" "VerteronDisassemblerEngine") + + if (WIN32) + add_executable("SymbolResolver" + "Examples/SymbolResolver/Main.cpp") + target_link_libraries("SymbolResolver" "VerteronDisassemblerEngine") + else () + message(STATUS "Example 'SymbolResolver' not compatible with platform, ignoring.") + endif () +endif () + +set(CONFIGURED_ONCE TRUE CACHE INTERNAL "CMake has configured at least once.") \ No newline at end of file diff --git a/Examples/CustomDataSource/Main.cpp b/Examples/CustomDataSource/Main.cpp index afe5a5f..a08a382 100644 --- a/Examples/CustomDataSource/Main.cpp +++ b/Examples/CustomDataSource/Main.cpp @@ -29,9 +29,8 @@ * SOFTWARE. **************************************************************************************************/ -#include -int _tmain(int argc, _TCHAR* argv[]) +int main(int argc, char* argv[]) { // TODO: return 0; diff --git a/Examples/PerformanceTest/Main.cpp b/Examples/PerformanceTest/Main.cpp index afe5a5f..a08a382 100644 --- a/Examples/PerformanceTest/Main.cpp +++ b/Examples/PerformanceTest/Main.cpp @@ -29,9 +29,8 @@ * SOFTWARE. **************************************************************************************************/ -#include -int _tmain(int argc, _TCHAR* argv[]) +int main(int argc, char* argv[]) { // TODO: return 0; diff --git a/Examples/SimpleDemo/Main.cpp b/Examples/SimpleDemo/Main.cpp index 3a60d40..cdc582d 100644 --- a/Examples/SimpleDemo/Main.cpp +++ b/Examples/SimpleDemo/Main.cpp @@ -29,15 +29,14 @@ * SOFTWARE. **************************************************************************************************/ -#include #include #include #include -#include "VXDisassembler.h" +#include using namespace Verteron; -int _tmain(int argc, _TCHAR* argv[]) +int main(int argc, char* argv[]) { uint8_t data32[] = { diff --git a/Examples/SymbolResolver/Main.cpp b/Examples/SymbolResolver/Main.cpp index ee8e299..8e7cdc3 100644 --- a/Examples/SymbolResolver/Main.cpp +++ b/Examples/SymbolResolver/Main.cpp @@ -29,19 +29,18 @@ * SOFTWARE. **************************************************************************************************/ -#include #include #include #include -#include "VXDisassembler.h" +#include #include using namespace Verteron; -int _tmain(int argc, _TCHAR* argv[]) +int main(int argc, char* argv[]) { // Find module base in memory - void *moduleBase = GetModuleHandle(L"kernel32.dll"); + void *moduleBase = GetModuleHandle("kernel32.dll"); uintptr_t baseAddress = reinterpret_cast(moduleBase); // Parse PE headers PIMAGE_DOS_HEADER dosHeader = static_cast(moduleBase); diff --git a/VerteronDisassemblerEngine/VXInstructionFormatter.cpp b/VerteronDisassemblerEngine/VXInstructionFormatter.cpp index 94df4ec..c139d59 100644 --- a/VerteronDisassemblerEngine/VXInstructionFormatter.cpp +++ b/VerteronDisassemblerEngine/VXInstructionFormatter.cpp @@ -33,6 +33,7 @@ #include "VXDisassemblerUtils.h" #include #include +#include namespace Verteron { @@ -215,7 +216,7 @@ char const* VXBaseInstructionFormatter::outputString() // Write the formatted text to the output buffer assert((bufLen - offset) > 0); strLen = - vsnprintf_s(&m_outputBuffer[offset], bufLen - offset, _TRUNCATE, format, arguments); + std::vsnprintf(&m_outputBuffer[offset], bufLen - offset, format, arguments); } while (strLen < 0); // Increase the string length m_outputStringLen = offset + strLen + 1;