Merge branch 'detections-yara-compilation' into detections-improv

This commit is contained in:
Michal Bandzi 2018-02-05 16:18:41 +01:00
commit 9ef393b30a
40 changed files with 724 additions and 5258 deletions

56
.appveyor.yml Normal file
View File

@ -0,0 +1,56 @@
version: '{build}'
environment:
WINFLEXBISON_ARCHIVE: win_flex_bison-2.5.14.zip
matrix:
- CMAKE_GENERATOR: Visual Studio 14 2015 Win64
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
matrix:
fast_finish: true
install:
- appveyor DownloadFile "https://downloads.sourceforge.net/project/winflexbison/%WINFLEXBISON_ARCHIVE%"
- 7z x -y -owinflexbison\ "%WINFLEXBISON_ARCHIVE%" > nul
- set Path=%CD%\winflexbison;%Path%
before_build:
- cmd: mkdir build
- cmd: cd build
- cmd: cmake -DCMAKE_CXX_FLAGS_RELEASE="/Od -DNDEBUG" -G"%CMAKE_GENERATOR%" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="install" -DRETDEC_TESTS=ON -DRETDEC_DEV_TOOLS=ON ..
build_script:
- cmd: cmake --build . --config Release -- /m
# Get wget, etc. needed for install step. If we do this earlier, build step fails.
# Otherwise, we could use `cmake --build . --config Release --target install -- -m` and save a few seconds.
- set Path=C:\msys64\usr\bin;C:\msys64\mingw64\bin;%Path%
- cmd: cmake --build . --config Release --target install
test_script:
# Test that install is movable and that it does not need build directory.
- cmd: mv install ../retdec-install
- cmd: cd ..
# Run unit tests.
- cmd: C:\msys64\usr\bin\bash.exe retdec-install\bin\retdec-tests-runner.sh
# Run decompilation script.
- cmd: C:\msys64\usr\bin\bash.exe retdec-install\bin\retdec-decompiler.sh --help
# Run simple decompilation.
- cmd: C:\msys64\usr\bin\echo.exe -e "#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\n printf(\"hello world\\\n\");\n return 0;\n}\n" > hello-orig.c
- cmd: cat hello-orig.c
# Make sure 32-bit gcc will be used.
- set Path=C:\MinGW\bin;%Path%
- cmd: gcc.exe -o hello.exe hello-orig.c
# Prefer msys64 after we used 32-bit compiler.
- set Path=C:\msys64\usr\bin;C:\msys64\mingw64\bin;%Path%
- cmd: hello.exe
- cmd: C:\msys64\usr\bin\bash.exe retdec-install\bin\retdec-decompiler.sh hello.exe
- cmd: cat hello.c
- cmd: grep "int main(int argc, char \*\* argv)" hello.c
notifications:
- provider: Email
to:
- '{{commitAuthorEmail}}'
on_build_success: false
on_build_failure: true
on_build_status_changed: true

107
.travis.yml Normal file
View File

@ -0,0 +1,107 @@
language: cpp
cache: ccache
matrix:
fast_finish: true
include:
- os: linux
dist: trusty
compiler: gcc-4.9
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- build-essential
- gcc-4.8-multilib
- gcc-4.9
- g++-4.9
- cmake
- perl
- python3
- flex
- bison
- autoconf
- automake
- libtool
- pkg-config
- m4
- coreutils
- zlib1g-dev
- libtinfo-dev
- wget
- bc
- upx
- openssl
env:
- MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9 && NPROC=$(nproc)"
# We need this so that ccache does not cause compilation errors.
# e.g. retdec/tests/utils/string_tests.cpp:276:2: error: stray '\' in program
- CCACHE_CPP2=true
- os: osx
osx_image: xcode8.3
env:
- MATRIX_EVAL="NPROC=$(sysctl -n hw.physicalcpu)"
- CCACHE_CPP2=true
install:
# We need to install newer versions of Flex and Bison on MacOS X.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install flex bison; fi
# ccache is not installed on OS X.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install ccache; fi
# gnu-getopt
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install gnu-getopt; fi
# bash 4
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install bash; fi
before_script:
- eval "${MATRIX_EVAL}"
# We need to use newer versions of Flex and Bison on MacOS X (the ones from Homebrew).
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export CMAKE_INCLUDE_PATH="/usr/local/opt/flex/include"; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export CMAKE_LIBRARY_PATH="/usr/local/opt/flex/lib;/usr/local/opt/bison/lib"; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH="/usr/local/opt/flex/bin:/usr/local/opt/bison/bin:$PATH"; fi
# Coreutils.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ln -s /usr/local/bin/greadlink /usr/local/bin/readlink; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"; fi
# We need to add ccache before everything else in PATH.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
script:
- mkdir build && cd build
# We use "-O0" to speed-up build.
# "-O0" causes segfaults in LLVM if we do not use "-DNDEBUG" as well.
- cmake -DCMAKE_CXX_FLAGS_RELEASE="-O0 -DNDEBUG" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/install" -DRETDEC_TESTS=ON -DRETDEC_DEV_TOOLS=ON ..
- time make install -j $NPROC
# Test that install is movable and that it does not need build directory.
- mv install ../retdec-install
- cd ..
- rm -rf build
# Run unit tests.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then /usr/local/bin/bash retdec-install/bin/retdec-tests-runner.sh; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then ./retdec-install/bin/retdec-tests-runner.sh; fi
# Run decompilation script.
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then /usr/local/bin/bash retdec-install/bin/retdec-decompiler.sh --help; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then ./retdec-install/bin/retdec-decompiler.sh --help; fi
# Run simple decompilation.
- echo -e '#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\n printf("hello world\\n");\n return 0;\n}\n' > hello-orig.c
- cat hello-orig.c
- gcc -m32 -o hello hello-orig.c
- ./hello
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then /usr/local/bin/bash retdec-install/bin/retdec-decompiler.sh hello; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then ./retdec-install/bin/retdec-decompiler.sh hello; fi
- cat hello.c
- grep "int main(int argc, char \*\* argv)" hello.c
branches:
only:
# Pushes and PRs to the master branch.
- master
# Version tags.
- /^v?\d+\.\d+.*$/
notifications:
email:
on_success: never

View File

@ -2,10 +2,12 @@
# dev
* Enhancement: Speeded up build by skipping compilation of unnecessary dependencies (e.g. unused LLVM libraries, tools, and examples).
* Enhancement: OpenSSL is now automatically built only if it is not found in your system.
* Enhancement: Added support for a system-wide installation ([#94](https://github.com/avast-tl/retdec/issues/94)).
* Enhancement: Prefixed all the installed binaries and scripts with `retdec-` ([#70](https://github.com/avast-tl/retdec/issues/70)). Also, some tools were renamed to make their names more uniform.
* Enhancement: Got rid of all git submodules ([#92](https://github.com/avast-tl/retdec/issues/92), [#93](https://github.com/avast-tl/retdec/issues/93)). Moved sources of all RetDec-related repositories to this main repository. Third-party dependencies are downloaded and built via CMake's external projects. This allows us to have e.g. only a single copy of LLVM ([#14](https://github.com/avast-tl/retdec/issues/14)) and not require a recursive clone ([#48](https://github.com/avast-tl/retdec/issues/48), [#68](https://github.com/avast-tl/retdec/issues/68), [#72](https://github.com/avast-tl/retdec/issues/72)).
* Enhancement: Set a proper `rpath` during installation on Linux and macOS ([#77](https://github.com/avast-tl/retdec/issues/77)). This allows us to move the installation directory after the installation into another location.
* Enhancement: Set a proper `rpath` during installation on Linux and macOS ([#77](https://github.com/avast-tl/retdec/issues/77), [#100](https://github.com/avast-tl/retdec/issues/100)). This allows us to move the installation directory after the installation into another location.
* Enhancement: Added community support for building and running RetDec inside Docker ([#60](https://github.com/avast-tl/retdec/pull/60)).
* Enhancement: Decrease the default timeout when downloading the support package during installation ([#6](https://github.com/avast-tl/retdec/pull/6)).
* Enhancement: Any shell can be used to install the decompiler, not just Bash.
@ -22,6 +24,7 @@
* Fix: When installing the decompiler, do not remove the entire `share` directory ([#12](https://github.com/avast-tl/retdec/issues/12)).
* Fix: Improve OS type detection when installing the decompiler.
* Fix: Remove useless OS type detection when running decompilations ([#10](https://github.com/avast-tl/retdec/issues/10)).
* Fix: Filesystem path in utils now returns correct information when it is appended with another path.
# v3.0 (2017-12-13)

View File

@ -38,7 +38,34 @@ endif()
set(EP_PREFIX "${PROJECT_BINARY_DIR}/external")
set_directory_properties(PROPERTIES EP_PREFIX "${EP_PREFIX}")
set(DEPS_TESTS ${RETDEC_TESTS})
# Compilation warnings.
if(MSVC)
# For the moment, suppress all warnings when building with MSVC on Windows
# because there are too many warnings that clutter the build output (#106).
# We should investigate the warnings, fix them, and then enable their
# emission (e.g. by replacing /W0 with /W3 in the code below).
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Enable standard warnings.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# Enable additional warnings that are not included in -Wall and -Wextra.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wswitch-default")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
# Disable warnings that produce more headaches than use.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/install-external.cmake)
add_subdirectory(deps)

View File

@ -1,5 +1,8 @@
# RetDec
[![Travis CI build status](https://travis-ci.org/avast-tl/retdec.svg?branch=master)](https://travis-ci.org/avast-tl/retdec)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/avast-tl/retdec?branch=master&svg=true)](https://ci.appveyor.com/project/avast-tl/retdec)
[RetDec](https://retdec.com/) is a retargetable machine-code decompiler based on [LLVM](https://llvm.org/).
The decompiler is not limited to any particular target architecture, operating system, or executable file format:

View File

@ -1,13 +1,42 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(capstone-project
URL https://github.com/avast-tl/capstone/archive/27c713fe4f6eaf9721785932d850b6291a6073fe.zip
URL_HASH SHA256=4d8d0461d7d5737893253698cd0b6d0d64545c1a74b166e8b1d823156a3109cb
DOWNLOAD_NAME capstone.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
-DCAPSTONE_BUILD_STATIC=ON
-DCAPSTONE_BUILD_SHARED=OFF
-DCAPSTONE_BUILD_STATIC_RUNTIME=OFF
-DCAPSTONE_BUILD_TESTS=OFF
-DCAPSTONE_X86_ATT_DISABLE=OFF
# Enabled architectures.
-DCAPSTONE_ARM_SUPPORT=ON
-DCAPSTONE_MIPS_SUPPORT=ON
-DCAPSTONE_PPC_SUPPORT=ON
-DCAPSTONE_X86_SUPPORT=ON
# Disabled architectures.
-DCAPSTONE_ARM64_SUPPORT=OFF
-DCAPSTONE_M68K_SUPPORT=OFF
-DCAPSTONE_SPARC_SUPPORT=OFF
-DCAPSTONE_SYSZ_SUPPORT=OFF
-DCAPSTONE_XCORE_SUPPORT=OFF
-DCAPSTONE_TMS320C64X_SUPPORT=OFF
-DCAPSTONE_M680X_SUPPORT=OFF
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.

View File

@ -1,11 +1,26 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(elfio-project
URL https://github.com/avast-tl/elfio/archive/1677a88d902d0fa6a5a7a31dc4da45748bba0bde.zip
URL_HASH SHA256=a446b2751b177bde6c5bff5a3716a978918daba6f4953aeef3850036cb43fde7
DOWNLOAD_NAME elfio.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the configure step - header only.
CONFIGURE_COMMAND ""
# Disable the build step.
BUILD_COMMAND ""
# Disable the update step.

View File

@ -10,8 +10,9 @@ if(CMAKE_CXX_COMPILER)
endif()
ExternalProject_Add(googletest
URL https://github.com/google/googletest/archive/5490beb0602eab560fa3969a4410e11d94bf12af.zip
URL_HASH SHA256=fb94ea2c653f239fb57e423afef372ebb5e019418af58f8bb2ce946679a6187b
URL https://github.com/google/googletest/archive/83fa0cb17dad47a1d905526dcdddb5b96ed189d2.zip
URL_HASH SHA256=3b7cf6bfd1fdec3204933b4c0419c010e89b2409dcd8cbc1ac6a78aab058e2b0
DOWNLOAD_NAME googletest.zip
CMAKE_ARGS
# This does not work on MSVC, but is useful on Linux.
-DCMAKE_BUILD_TYPE=Release
@ -44,28 +45,32 @@ ExternalProject_Get_Property(googletest binary_dir)
if(MSVC)
set(DEBUG_DIR "Debug/")
set(RELEASE_DIR "Release/")
set(DEBUG_LIB_SUFFIX "d")
endif()
add_library(gtest INTERFACE)
target_link_libraries(gtest INTERFACE debug ${binary_dir}/googlemock/gtest/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gtest INTERFACE debug ${binary_dir}/googlemock/gtest/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gtest INTERFACE optimized ${binary_dir}/googlemock/gtest/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(gtest SYSTEM INTERFACE ${GTEST_INCLUDE_DIR})
add_dependencies(gtest googletest)
add_library(gtest_main INTERFACE)
target_link_libraries(gtest_main INTERFACE debug ${binary_dir}/googlemock/gtest/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gtest_main INTERFACE debug ${binary_dir}/googlemock/gtest/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gtest_main INTERFACE optimized ${binary_dir}/googlemock/gtest/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gtest_main INTERFACE gtest)
target_include_directories(gtest_main SYSTEM INTERFACE ${GTEST_INCLUDE_DIR})
add_dependencies(gtest_main googletest)
add_library(gmock INTERFACE)
target_link_libraries(gmock INTERFACE debug ${binary_dir}/googlemock/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock INTERFACE debug ${binary_dir}/googlemock/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock INTERFACE optimized ${binary_dir}/googlemock/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock INTERFACE gtest)
target_include_directories(gmock SYSTEM INTERFACE ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR})
add_dependencies(gmock googletest)
add_library(gmock_main INTERFACE)
target_link_libraries(gmock_main INTERFACE debug ${binary_dir}/googlemock/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock_main INTERFACE debug ${binary_dir}/googlemock/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock_main INTERFACE optimized ${binary_dir}/googlemock/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(gmock_main INTERFACE gmock)
target_include_directories(gmock_main SYSTEM INTERFACE ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR})
add_dependencies(gmock_main googletest)

View File

@ -10,6 +10,7 @@ endif()
ExternalProject_Add(jsoncpp-project
URL https://github.com/open-source-parsers/jsoncpp/archive/1.8.4.zip
URL_HASH SHA256=2979436dbd4c48a3284dca9fa8f212298425ba3920ed6bacdda8905a94b111a8
DOWNLOAD_NAME jsoncpp.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
@ -18,6 +19,11 @@ ExternalProject_Add(jsoncpp-project
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable unused options.
-DJSONCPP_WITH_TESTS=OFF
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
-DBUILD_SHARED_LIBS=OFF
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.

View File

@ -1,5 +1,12 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
# Keystone requires python3, so we first check whether python3 is installed as
# "python3", and if not, we suppose that `python` runs python3.
# Python is used to generate LLVMBuild.cmake file. Python2 generates this file
@ -12,12 +19,18 @@ endif()
ExternalProject_Add(keystone-project
URL https://github.com/avast-tl/keystone/archive/4722974f58dbe878c805ce2b7c0a41cf6153903c.zip
URL_HASH SHA256=145c8bb836d2f06f845b5015b3eab350ae59d35a54052f00f5d26445172415fd
DOWNLOAD_NAME keystone.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Force python version set in this cmake file.
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DKEYSTONE_BUILD_STATIC_RUNTIME=OFF
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.

View File

@ -1,15 +1,28 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
set(LIBDWARF_INSTALL_DIR "${PROJECT_BINARY_DIR}/external/src/libdwarf-project-install")
ExternalProject_Add(libdwarf-project
URL https://github.com/avast-tl/libdwarf/archive/bb920ecb8b6172359b4d57955a2670194d1f1f43.zip
URL_HASH SHA256=b28a6f9fc854d7e1dce84c892b522b9ae98b2d600f82d9f1cc10e470f926ab98
URL https://github.com/avast-tl/libdwarf/archive/85465d5e235cc2d2f90d04016d6aca1a452d0e73.zip
URL_HASH SHA256=2864aa7b46529778476190e90359669eb35799ad273233c4df2203bec7db0738
DOWNLOAD_NAME libdwarf.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${LIBDWARF_INSTALL_DIR}
-DLIBDWARF_INSTALL_TO_UNITTESTS=${RETDEC_TESTS}
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
LOG_DOWNLOAD ON

View File

@ -3,6 +3,13 @@ if(UNIX)
find_package(ZLIB REQUIRED)
endif()
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
# Set the default build type to 'Release'
if (NOT CMAKE_BUILD_TYPE)
set(default_build_type "Release")
@ -28,8 +35,9 @@ if(NOT PYTHON_EXECUTABLE)
endif()
ExternalProject_Add(llvm-project
URL https://github.com/avast-tl/llvm/archive/e7431aa1980227e15caf296bd1a8da85aa5706f4.zip
URL_HASH SHA256=d30752a7cd23597cf54513b6ea69fa8c1311c631bd7bbfc816737249664443e9
URL https://github.com/avast-tl/llvm/archive/257248365d034351e164aae04060f0d8f4c5b1f1.zip
URL_HASH SHA256=0088e715fd92d9670398514791563f1efc727d5a81b5cac8830c7e746ab26c06
DOWNLOAD_NAME llvm.zip
CMAKE_ARGS
# Force a release build (we don't need to debug LLVM).
# This has no effect on Windows with MSVC, but is useful on Linux.
@ -66,6 +74,17 @@ ExternalProject_Add(llvm-project
# need to also link the tinfo library.
-DLLVM_ENABLE_TERMINFO=YES
# Disable build of unnecessary LLVM parts.
-DLLVM_BUILD_TOOLS=OFF
-DLLVM_BUILD_UTILS=OFF
-DLLVM_BUILD_RUNTIME=OFF
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the installation right after build (we want to install the
# needed libraries and tools manually).
INSTALL_COMMAND ""
@ -97,47 +116,24 @@ add_library(llvm INTERFACE)
add_dependencies(llvm llvm-project)
set(LLVM_LIB_LIST
LLVMInterpreter
LLVMMCJIT
LLVMRuntimeDyld
LLVMOrcJIT
LLVMExecutionEngine
LLVMRuntimeDyld
LLVMX86CodeGen
LLVMX86AsmParser
LLVMX86Disassembler
LLVMBitWriter
LLVMIRReader
LLVMInstrumentation
LLVMObject
LLVMInstCombine
LLVMSupport
LLVMipo
LLVMAsmPrinter
LLVMSelectionDAG
LLVMX86Desc
LLVMAsmParser
LLVMBitReader
LLVMVectorize
LLVMMCParser
LLVMCodeGen
LLVMX86AsmPrinter
LLVMX86Info
LLVMObjCARCOpts
LLVMScalarOpts
LLVMX86Utils
LLVMTransformUtils
LLVMAnalysis
LLVMTarget
LLVMCore
LLVMMC
LLVMObject
LLVMMCDisassembler
LLVMProfileData
LLVMDebugInfoCodeView
LLVMPasses
LLVMLinker
LLVMInstCombine
LLVMSupport
)
if(MSVC)

View File

@ -1,3 +1,12 @@
find_package(OpenSSL 1.0.1)
if(OPENSSL_FOUND)
add_library(openssl-crypto INTERFACE)
target_link_libraries(openssl-crypto INTERFACE OpenSSL::Crypto)
return()
endif()
message(STATUS " --> OpenSSL will be built as an external project")
find_package(Perl REQUIRED)
include(ExternalProject)
@ -82,6 +91,7 @@ set(OPENSSL_INSTALL_DIR "${OPENSSL_PREFIX}/src/openssl-install")
set(OPENSSL_VERSION "1.1.0f")
set(OPENSSL_URL "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz")
set(OPENSSL_ARCHIVE_SHA256 "12f746f3f2493b2f39da7ecf63d7ee19c6ac9ec6a4fcd8c229da8a522cb12765")
set(OPENSSL_DOWNLOAD_NAME "openssl.tar.gz")
set(OPENSSL_CONFIGURE_OPTIONS
no-shared
@ -96,6 +106,7 @@ if (NOT TARGET openssl)
PREFIX ${OPENSSL_PREFIX}
URL ${OPENSSL_URL}
URL_HASH SHA256=${OPENSSL_ARCHIVE_SHA256}
DOWNLOAD_NAME ${OPENSSL_DOWNLOAD_NAME}
CONFIGURE_COMMAND
${PERL_EXECUTABLE}
${OPENSSL_SRC_DIR}/Configure
@ -105,7 +116,9 @@ if (NOT TARGET openssl)
BUILD_COMMAND
${OPENSSL_MAKE}
INSTALL_COMMAND
${OPENSSL_MAKE} install
# Install only the software parts (libraries and includes), not
# e.g. documentation and manual pages.
${OPENSSL_MAKE} install_sw
LOG_DOWNLOAD 1
LOG_BUILD 1
LOG_CONFIGURE 1

View File

@ -1,11 +1,24 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(pelib-project
URL https://github.com/avast-tl/pelib/archive/e93eaa7c150f4608a5d02a67f5edc9e54456fe24.zip
URL_HASH SHA256=2ffd7e89451c980a1af6d24d4f6dfbb69a660b06ad5de44c481f6431e21de394
DOWNLOAD_NAME pelib.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.

View File

@ -1,14 +1,27 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(rapidjson-project
URL https://github.com/Tencent/rapidjson/archive/v1.1.0.zip
URL_HASH SHA256=8e00c38829d6785a2dfb951bb87c6974fa07dfe488aa5b25deec4b8bc0f6a3ab
DOWNLOAD_NAME rapidjson.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
-DRAPIDJSON_BUILD_DOC=OFF
-DRAPIDJSON_BUILD_EXAMPLES=OFF
-DRAPIDJSON_BUILD_TESTS=OFF
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the build step.
BUILD_COMMAND ""
# Disable the update step.

View File

@ -1,2 +1,53 @@
add_library(tinyxml2 STATIC tinyxml2.cpp)
target_include_directories(tinyxml2 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(tinyxml2-project
URL https://github.com/leethomason/tinyxml2/archive/cc1745b552dd12bb1297a99f82044f83b06729e0.zip
URL_HASH SHA256=de255ce39ba1efe20cbffdebd3eea2d08f1269d03440a4fd60e142b0481c3f00
DOWNLOAD_NAME tinyxml2.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Build only static library.
-DBUILD_STATIC_LIBS:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
# Do not build tests.
-DBUILD_TESTS:BOOL=OFF
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
)
# Set include directories.
ExternalProject_Get_Property(tinyxml2-project source_dir)
set(TINYXML2_INCLUDE_DIR ${source_dir})
# Add libraries.
ExternalProject_Get_Property(tinyxml2-project binary_dir)
if(MSVC)
set(DEBUG_DIR "Debug/")
set(RELEASE_DIR "Release/")
set(DEBUG_LIB_SUFFIX "d")
endif()
add_library(tinyxml2 INTERFACE)
target_link_libraries(tinyxml2 INTERFACE debug ${binary_dir}/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}tinyxml2${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
target_link_libraries(tinyxml2 INTERFACE optimized ${binary_dir}/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}tinyxml2${CMAKE_STATIC_LIBRARY_SUFFIX})
target_include_directories(tinyxml2 SYSTEM INTERFACE ${TINYXML2_INCLUDE_DIR})
add_dependencies(tinyxml2 tinyxml2-project)

File diff suppressed because it is too large Load Diff

2264
deps/tinyxml2/tinyxml2.h vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,24 @@
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(yaracpp-project
URL https://github.com/avast-tl/yaracpp/archive/a284ab17ab04d91f1725f579a8670a12ef1afd76.zip
URL_HASH SHA256=ff5e5996e90a56f2752c69ac7a12009075f7f355da5bff37e562239ae9749e44
URL https://github.com/avast-tl/yaracpp/archive/v1.0.1.zip
URL_HASH SHA256=2252ba7cfd9b190d3e260a741bbd2abc0fbd7c0422eb13d878278a89016c4fda
DOWNLOAD_NAME yaracpp.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.
@ -25,16 +38,32 @@ set(YARA_LIBRARY_NAME "libyara")
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(YARA_LIBRARY_NAME "${YARA_LIBRARY_NAME}64")
set(YARAC_NAME "yarac64.exe" CACHE STRING "Yarac binary name" FORCE)
else()
set(YARA_LIBRARY_NAME "${YARA_LIBRARY_NAME}32")
set(YARAC_NAME "yarac32.exe" CACHE STRING "Yarac binary name" FORCE)
endif()
set(YARA_WIN_DIR ${YARA_DIR}/windows/vs2015)
set(YARA_LIBRARY_DIR ${YARA_WIN_DIR}/libyara/$<CONFIGURATION>)
set(YARAC_PATH ${YARA_WIN_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${YARAC_NAME})
else()
set(YARA_LIBRARY_DIR ${YARA_DIR}/libyara/.libs)
set(YARAC_PATH ${YARA_DIR}/yarac)
endif()
# Compile YARA rules for tools detection.
set(YARA_COMPILE_SH ${CMAKE_SOURCE_DIR}/support/yara_patterns/tools/compile-yara.sh)
install(CODE "
execute_process(
COMMAND sh \"${YARA_COMPILE_SH}\" \"${YARAC_PATH}\" \"${CMAKE_SOURCE_DIR}\" \"${CMAKE_INSTALL_PREFIX}\"
RESULT_VARIABLE COMPILE_YARA_RES
)
if(COMPILE_YARA_RES)
message(FATAL_ERROR \"YARA tool signatures compilation FAILED\")
endif()
")
# Add libraries.
add_library(yaracpp INTERFACE)
add_dependencies(yaracpp yaracpp-project)

View File

@ -4,12 +4,25 @@ find_package(BISON REQUIRED)
include(ExternalProject)
if(CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER_OPTION "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
endif()
if(CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
endif()
ExternalProject_Add(yaramod-project
URL https://github.com/avast-tl/yaramod/archive/122610928203f4606276e1cb2552f04f6dd33c32.zip
URL_HASH SHA256=7fac768ccc8699fc44c1bac1e9ebea8ab57654f34a53ff772b025e50fa66c760
URL https://github.com/avast-tl/yaramod/archive/v1.0.1.zip
URL_HASH SHA256=20793f99bd1a22e9b743400653d54790a48457ef0ae1cf8f089a1bf3bf38f339
DOWNLOAD_NAME yaramod.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
-DCMAKE_BUILD_TYPE=Release
# Force the use of the same compiler as used to build the top-level
# project. Otherwise, the external project may pick up a different
# compiler, which may result in link errors.
"${CMAKE_C_COMPILER_OPTION}"
"${CMAKE_CXX_COMPILER_OPTION}"
# Disable the update step.
UPDATE_COMMAND ""
# Disable the install step.

View File

@ -8,11 +8,11 @@
#define RETDEC_UTILS_OS_H
// Obtain the used operating system. Currently, we only distinguish between
// Windows and Linux.
// Windows and UNIX.
#if defined(__WIN) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#define OS_WINDOWS
#else
#define OS_LINUX
#define OS_UNIX
#endif
#endif

View File

@ -8,10 +8,10 @@
# - the `timeout` command
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_UTILS" ]; then
DECOMPILER_UTILS="$SCRIPTPATH/retdec-utils.sh"
DECOMPILER_UTILS="$SCRIPT_DIR/retdec-utils.sh"
fi
. "$DECOMPILER_UTILS"

View File

@ -3,14 +3,14 @@
# Decompiler's configuration. This file should be included in every decompilation script.
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
##
## Paths (everything has to be without the ending slash '/').
##
# Paths relative from script path.
INSTALL_BIN_DIR="$SCRIPTPATH"
INSTALL_BIN_DIR="$SCRIPT_DIR"
UNIT_TESTS_DIR="$INSTALL_BIN_DIR"
INSTALL_SHARE_DIR="$INSTALL_BIN_DIR/../share/retdec"
INSTALL_SUPPORT_DIR="$INSTALL_SHARE_DIR/support"

View File

@ -3,10 +3,10 @@
# The script decompiles the given file into the selected target high-level language.
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_UTILS" ]; then
DECOMPILER_UTILS="$SCRIPTPATH/retdec-utils.sh"
DECOMPILER_UTILS="$SCRIPT_DIR/retdec-utils.sh"
fi
. "$DECOMPILER_UTILS"
@ -162,10 +162,10 @@ check_arguments()
fi
# Convert to absolute paths.
IN="$(readlink -f "$IN")"
OUT="$(readlink -f "$OUT")"
IN="$(get_realpath "$IN")"
OUT="$(get_realpath "$OUT")"
if [ -e "$PDB_FILE" ]; then
PDB_FILE="$(readlink -f "$PDB_FILE")"
PDB_FILE="$(get_realpath "$PDB_FILE")"
fi
# Check that selected ranges are valid.
@ -245,8 +245,7 @@ PARSED_OPTIONS=$(getopt -o "$GETOPT_SHORTOPT" -l "$GETOPT_LONGOPT" -n "$SCRIPT_N
eval set -- "$PARSED_OPTIONS"
while true ;
do
while true; do
case "$1" in
-a|--arch) # Target architecture.
[ "$ARCH" ] && print_error_and_die "Duplicate option: -a|--arch"
@ -497,10 +496,7 @@ done
check_arguments
if [ "$MODE" = "raw" ]; then
##
## Default values and initialization.
##
# Default values and initialization.
OUT_RAW_EXECUTABLE="$IN"
# Entry point for THUMB must be odd.
@ -513,7 +509,6 @@ fi
# Check for archives.
if [ "$MODE" = "bin" ]; then
# Check for archives packed in Mach-O Universal Binaries.
echo "##### Checking if file is a Mach-O Universal static library..."
echo "RUN: $EXTRACT --list $IN"
@ -937,9 +932,7 @@ if [ "$BACKEND_EMIT_CFG" ]; then
[ "$BACKEND_CFG_TEST" ] && LLVMIR2HLL_PARAMS+=(--backend-cfg-test)
fi
##
## Decompile the optimized IR code.
##
# Decompile the optimized IR code.
echo ""
echo "##### Decompiling $OUT_BACKEND_BC into $OUT..."
echo "RUN: $LLVMIR2HLL ${LLVMIR2HLL_PARAMS[@]}"
@ -957,9 +950,8 @@ check_whether_decompilation_should_be_forcefully_stopped "llvmir2hll"
GRAPH_FORMAT=${GRAPH_FORMAT:=png}
BACKEND_CG_CONVERSION=${BACKEND_CG_CONVERSION:=auto}
BACKEND_CFG_CONVERSION=${BACKEND_CFG_CONVERSION:=auto}
##
## Convert .dot graphs to desired format.
##
# Convert .dot graphs to desired format.
if [[ ( "$BACKEND_EMIT_CG" && "$BACKEND_CG_CONVERSION" = "auto" ) ||
( "$BACKEND_EMIT_CFG" && "$BACKEND_CFG_CONVERSION" = "auto" ) ]]; then
echo ""
@ -982,9 +974,7 @@ fi
sed -i 's/[ \t]*$//' "$OUT"
sed -i '$ { /^$/ d}' "$OUT"
##
## Colorize output file.
##
# Colorize output file.
if [ "$COLOR_IDA" ]; then
"$IDA_COLORIZER" "$OUT" "$CONFIG"
fi

View File

@ -6,10 +6,10 @@
# - is able to analyze archives (.a/.lib files).
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_UTILS" ]; then
DECOMPILER_UTILS="$SCRIPTPATH/retdec-utils.sh"
DECOMPILER_UTILS="$SCRIPT_DIR/retdec-utils.sh"
fi
. "$DECOMPILER_UTILS"

View File

@ -1,9 +1,9 @@
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_UTILS" ]; then
DECOMPILER_UTILS="$SCRIPTPATH/retdec-utils.sh"
DECOMPILER_UTILS="$SCRIPT_DIR/retdec-utils.sh"
fi
. "$DECOMPILER_UTILS"
@ -97,7 +97,7 @@ if [ -z "$OUT_PATH" ]; then
die_with_error_and_cleanup "option -o|--output is compulsory"
else
FILE_PATH="$OUT_PATH"
DIR="$(dirname "$(readlink -f "$FILE_PATH")")"
DIR="$(dirname "$(get_realpath "$FILE_PATH")")"
DIR_PATH=$(mktemp -d "$DIR/XXXXXXXXX")
fi

View File

@ -3,13 +3,20 @@
# Runs all the installed unit tests.
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_CONFIG" ]; then
DECOMPILER_CONFIG="$SCRIPTPATH/retdec-config.sh"
DECOMPILER_CONFIG="$SCRIPT_DIR/retdec-config.sh"
fi
. "$DECOMPILER_CONFIG"
#
# First argument can be verbose.
#
if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]; then
VERBOSE=1
fi
#
# Emits a colored version of the given message to the standard output (without
# a new line).
@ -58,8 +65,12 @@ run_unit_tests_in_dir() {
unit_test_name="$(sed 's/^.*\/bin\///' <<< "$unit_test")"
echo_colored "$unit_test_name" "yellow"
echo ""
if [ "$VERBOSE" ]; then
$unit_test --gtest_color=yes
else
$unit_test --gtest_color=yes | grep -v "RUN\|OK\|----------\|==========" |\
grep -v "^$" | grep -v "Running main() from gmock_main.cc"
fi
RC=${PIPESTATUS[0]}
if [ "$RC" != "0" ]; then
TESTS_FAILED="1"

View File

@ -26,10 +26,10 @@ RET_UNPACKER_FAILED=4
# 10 other errors
#RET_OTHER_ERRORS=10
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_UTILS" ]; then
DECOMPILER_UTILS="$SCRIPTPATH/retdec-utils.sh"
DECOMPILER_UTILS="$SCRIPT_DIR/retdec-utils.sh"
fi
. "$DECOMPILER_UTILS"
@ -64,8 +64,8 @@ check_arguments()
OUT=${OUT:="$IN"-unpacked}
# Convert to absolute paths.
IN="$(readlink -f "$IN")"
OUT="$(readlink -f "$OUT")"
IN="$(get_realpath "$IN")"
OUT="$(get_realpath "$OUT")"
}
#

View File

@ -3,14 +3,34 @@
# Compilation and decompilation utility functions.
#
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
if [ -z "$DECOMPILER_CONFIG" ]; then
DECOMPILER_CONFIG="$SCRIPTPATH/retdec-config.sh"
DECOMPILER_CONFIG="$SCRIPT_DIR/retdec-config.sh"
fi
. "$DECOMPILER_CONFIG"
#
# Prints the real, physical location of a directory or file, relative or
# absolute.
# 1 argument is needed
#
get_realpath()
{
local input_path="$1"
# Use cygpath.exe on cygwin, due to cygwins virtual folder mountpoints
# (i.e., "/cygdrive/c/foo/bar" becomes "c:/foo/bar").
# cygpath args:
# -m -- mixed mode, that is, forward slashes, instead of backward slashes
# -a -- absolute path (regardless if input is relative or not)
if [[ "$(uname -s)" == *CYGWIN* ]]; then
cygpath -ma "$input_path"
else
readlink -f "$input_path"
fi
}
#
# Print error message to stderr and die.
# 1 argument is needed

View File

@ -70,7 +70,7 @@ FILES_FILTER=${FILES_FILTER:${#SEP}}
#
# Paths.
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
SCRIPT_NAME="$(basename "$SCRIPT_NAME")"
EXTRACTOR="$SCRIPT_DIR/extract_types.py"
MERGER="$SCRIPT_DIR/merge_jsons.py"

View File

@ -6,7 +6,7 @@
#
# Paths.
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
SCRIPT_NAME="$(basename "$SCRIPT_NAME")"
EXTRACTOR="$SCRIPT_DIR/extract_types.py"
MERGER="$SCRIPT_DIR/merge_jsons.py"

View File

@ -228,7 +228,7 @@ bool ArchiveWrapper::getJsonList(
Value object(kObjectType);
object.AddMember("name", Value(outName.c_str(), allocator).Move(), allocator);
if (numbers) {
object.AddMember("index", (uint64_t) counter++, allocator);
object.AddMember("index", static_cast<uint64_t>(counter++), allocator);
}
objects.PushBack(object, allocator);
}

View File

@ -35,7 +35,6 @@
#include <llvm/IRReader/IRReader.h>
#include <llvm/InitializePasses.h>
#include <llvm/LinkAllIR.h>
#include <llvm/LinkAllPasses.h>
#include <llvm/MC/SubtargetFeature.h>
#include <llvm/Support/Debug.h>
#include <llvm/Support/FileSystem.h>
@ -272,34 +271,15 @@ static inline void addPassWithoutVerification(
*/
void initializeLlvmPasses()
{
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
// Initialize passes
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeCore(Registry);
initializeScalarOpts(Registry);
initializeObjCARCOpts(Registry);
initializeVectorization(Registry);
initializeIPO(Registry);
initializeAnalysis(Registry);
initializeTransformUtils(Registry);
initializeInstCombine(Registry);
initializeInstrumentation(Registry);
initializeTarget(Registry);
// For codegen passes, only passes that do IR to IR transformation are
// supported.
initializeCodeGenPreparePass(Registry);
initializeAtomicExpandPass(Registry);
initializeRewriteSymbolsPass(Registry);
initializeWinEHPreparePass(Registry);
initializeDwarfEHPreparePass(Registry);
initializeSafeStackPass(Registry);
initializeSjLjEHPreparePass(Registry);
initializePreISelIntrinsicLoweringLegacyPassPass(Registry);
initializeGlobalMergePass(Registry);
initializeInterleavedAccessPass(Registry);
initializeUnreachableBlockElimLegacyPassPass(Registry);
}
/**

View File

@ -6,18 +6,6 @@
#include <iostream>
#include <llvm/ADT/StringExtras.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/CodeGen/LinkAllCodegenComponents.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
#include <llvm/ExecutionEngine/JITEventListener.h>
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/ObjectCache.h>
#include <llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h>
#include <llvm/ExecutionEngine/OrcMCJITReplacement.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/IR/CallSite.h>
#include <llvm/IR/GetElementPtrTypeIterator.h>
#include <llvm/IR/IRBuilder.h>
@ -26,9 +14,6 @@
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/TypeBuilder.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/Object/Archive.h>
#include <llvm/Object/ObjectFile.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/Debug.h>
#include <llvm/Support/DynamicLibrary.h>
@ -46,7 +31,6 @@
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Transforms/Instrumentation.h>
#include "retdec/llvmir-emul/llvmir_emul.h"
@ -3071,10 +3055,9 @@ void LlvmIrEmulator::visitCallInst(llvm::CallInst& I)
if (cf && cf->isDeclaration() && cf->isIntrinsic() &&
cf->getIntrinsicID() != Intrinsic::fabs) // can not lower fabs
{
auto iId = cf->getIntrinsicID();
assert(iId != Intrinsic::vastart
&& iId != Intrinsic::vaend
&& iId != Intrinsic::vacopy);
assert(cf->getIntrinsicID() != Intrinsic::vastart
&& cf->getIntrinsicID() != Intrinsic::vaend
&& cf->getIntrinsicID() != Intrinsic::vacopy);
BasicBlock::iterator me(&I);
BasicBlock *Parent = I.getParent();

View File

@ -82,7 +82,7 @@ DynamicBuffer::~DynamicBuffer()
*
* @param rhs Right hand side of the operator.
*
* @return The new DynamicBuffer opbject.
* @return The new DynamicBuffer object.
*/
DynamicBuffer& DynamicBuffer::operator =(DynamicBuffer rhs)
{

View File

@ -5,9 +5,11 @@
*/
#include <string>
#include <iterator>
#include "retdec/utils/filesystem_path.h"
#include "retdec/utils/os.h"
#include "retdec/utils/scope_exit.h"
#include "retdec/utils/string.h"
#include "retdec/utils/value.h"
@ -27,27 +29,14 @@ namespace utils {
class FilesystemPathImpl
{
public:
FilesystemPathImpl(const std::string& path)
: _path(), _parentPath(), _subpaths(), _exists(), _isFile(), _isDirectory(), _isAbsolute()
FilesystemPathImpl(const std::string& path) : _path()
{
changePath(path);
}
FilesystemPathImpl(const FilesystemPathImpl& rhs)
: _path(rhs._path), _parentPath(rhs._parentPath), _subpaths(rhs._subpaths), _exists(rhs._exists),
_isFile(rhs._isFile), _isDirectory(rhs._isDirectory), _isAbsolute(rhs._isAbsolute) {}
FilesystemPathImpl(const FilesystemPathImpl& rhs) : _path(rhs._path) {}
virtual ~FilesystemPathImpl() = default;
void reset()
{
_parentPath = {};
_subpaths = {};
_exists = {};
_isFile = {};
_isDirectory = {};
_isAbsolute = {};
}
/**
* Returns the path.
*
@ -67,7 +56,6 @@ public:
*/
void changePath(std::string path)
{
reset();
std::replace(path.begin(), path.end(), '/', pathSeparator);
_path = endsWith(path, pathSeparator) ? path.substr(0, path.length() - 1) : path;
}
@ -84,9 +72,6 @@ public:
protected:
std::string _path;
Maybe<std::string> _absolutePath, _parentPath;
Maybe<std::vector<std::string>> _subpaths;
Maybe<bool> _exists, _isFile, _isDirectory, _isAbsolute;
};
#ifdef OS_WINDOWS
@ -100,42 +85,27 @@ public:
virtual std::string getAbsolutePath() override
{
if (_absolutePath.isDefined())
return _absolutePath;
char absolutePath[MAX_PATH] = { '\0' };
if (GetFullPathName(_path.c_str(), MAX_PATH, absolutePath, nullptr) == 0)
return {};
_absolutePath = std::string(absolutePath);
return _absolutePath;
return absolutePath;
}
virtual std::string getParentPath() override
{
if (_parentPath.isDefined())
return _parentPath;
// PathRemoveFileSpec() supports only MAX_PATH long paths and modify its parameter
char parentPathStr[MAX_PATH] = { '\0' };
strncpy(parentPathStr, _path.c_str(), MAX_PATH - 1);
PathRemoveFileSpec(parentPathStr);
_parentPath = std::string(parentPathStr);
return _parentPath;
return parentPathStr;
}
virtual bool subpathsInDirectory(std::vector<std::string>& subpaths) override
{
using namespace std::string_literals;
if (_subpaths.isDefined())
{
subpaths = _subpaths.getValue();
return true;
}
WIN32_FIND_DATA ffd;
// We need to add wildcard to examine the content of the directory
@ -145,10 +115,7 @@ public:
subpaths.clear();
HANDLE hFnd = FindFirstFile(examineDir.c_str(), &ffd);
if (hFnd == reinterpret_cast<HANDLE>(-1))
{
_subpaths = std::vector<std::string>{};
return false;
}
do
{
@ -164,55 +131,31 @@ public:
subpaths.emplace_back(newPath);
} while (FindNextFile(hFnd, &ffd));
_subpaths = subpaths;
return true;
}
virtual bool exists() override
{
if (_exists.isDefined())
return _exists;
_exists = PathFileExists(_path.c_str());
return _exists;
return PathFileExists(_path.c_str());
}
virtual bool isFile() override
{
if (_isFile.isDefined())
return _isFile;
isDirectory();
return _isFile;
return !isDirectory();
}
virtual bool isDirectory() override
{
if (_isDirectory.isDefined())
return _isDirectory;
WIN32_FIND_DATA ffd;
if (FindFirstFile(_path.c_str(), &ffd) == reinterpret_cast<HANDLE>(-1))
{
_exists = false;
_isDirectory = false;
_isFile = false;
return false;
}
_exists = true;
_isDirectory = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
_isFile = !_isDirectory;
return _isDirectory;
return ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
}
virtual bool isAbsolute() override
{
if (_isAbsolute.isDefined())
return _isAbsolute;
_isAbsolute = !PathIsRelative(_path.c_str());
return _isAbsolute;
return !PathIsRelative(_path.c_str());
}
};
#else
@ -226,43 +169,36 @@ public:
virtual std::string getAbsolutePath() override
{
if (_absolutePath.isDefined())
return _absolutePath;
#ifdef PATH_MAX
char absolutePath[PATH_MAX] = { '\0' };
if (realpath(_path.c_str(), absolutePath) == nullptr)
return {};
#else
char* absolutePathStr = realpath(_path.c_str(), nullptr);
SCOPE_EXIT {
free(absolutePathStr);
};
std::string absolutePath = absolutePathStr;
#endif
_absolutePath = std::string(absolutePath);
return _absolutePath;
return absolutePath;
}
virtual std::string getParentPath() override
{
if (_parentPath.isDefined())
return _parentPath;
// dirname() can modify the path provided in parameter, so we need to make copy
char* copyPathStr = new char[_path.length() + 1];
SCOPE_EXIT {
delete[] copyPathStr;
};
strcpy(copyPathStr, _path.c_str());
// get the parent directory by calling dirname()
char* parentPathStr = dirname(copyPathStr);
// copy the parent path into the string, so we can free the memory
_parentPath = std::string(parentPathStr);
delete[] copyPathStr;
return _parentPath;
return dirname(copyPathStr);
}
virtual bool subpathsInDirectory(std::vector<std::string>& subpaths) override
{
if (_subpaths.isDefined())
{
subpaths = _subpaths.getValue();
return true;
}
subpaths.clear();
DIR* dir = opendir(_path.c_str());
if (dir == nullptr)
@ -284,46 +220,27 @@ public:
}
closedir(dir);
_subpaths = subpaths;
return true;
}
virtual bool exists() override
{
if (_exists.isDefined())
return _exists;
isDirectory();
return _exists;
struct stat st;
return stat(_path.c_str(), &st) != 0;
}
virtual bool isFile() override
{
if (_isFile.isDefined())
return _isFile;
isDirectory();
return _isFile;
return !isDirectory();
}
virtual bool isDirectory() override
{
if (_isDirectory.isDefined())
return _isDirectory;
struct stat st;
if (stat(_path.c_str(), &st) != 0)
{
_exists = false;
_isDirectory = false;
_isFile = false;
return false;
}
_exists = true;
_isDirectory = S_ISDIR(st.st_mode);
_isFile = S_ISREG(st.st_mode);
return _isDirectory;
return S_ISDIR(st.st_mode);
}
virtual bool isAbsolute() override
@ -528,11 +445,10 @@ void FilesystemPath::loadSubpaths() const
if (!_impl->subpathsInDirectory(subpaths))
return;
for (const auto& subpath : subpaths)
{
auto fsSubpath = std::make_unique<FilesystemPath>(subpath);
_subpaths.push_back(std::move(fsSubpath));
}
std::transform(subpaths.begin(), subpaths.end(), std::back_inserter(_subpaths),
[](const auto& subpath) {
return std::make_unique<FilesystemPath>(subpath);
});
_subpathsLoaded = true;
}

View File

@ -85,20 +85,17 @@ std::string getCurrentYear() {
* @brief Returns date in human readable form.
* @param tm Timestamp for conversion.
*/
std::string timestampToDate(std::tm *tm)
{
if(!tm) {
std::string timestampToDate(std::tm *tm) {
if (!tm) {
return "";
}
const auto conDate = getDate(tm);
const auto conTime = getTime(tm);
if (conDate.empty() && conTime.empty()) {
return "";
}
else if (conDate.empty()) {
} else if (conDate.empty()) {
return conTime;
}
else if (conTime.empty()) {
} else if (conTime.empty()) {
return conDate;
}

1
support/README Normal file
View File

@ -0,0 +1 @@
Compilation and installation of YARA rules is done in deps/yaracpp.

View File

@ -0,0 +1,112 @@
#!/bin/sh
#
# Compile and install tool signatures.
# Usage: compile-yara.sh yarac-path source-path install-path
#
###############################################################################
# Print error and exit with non-zero value.
# $1 - error message.
printErrorAndDie()
{
if ! [ -z "$1" ]; then
echo "Error: $1."
fi
exit 1
}
# Compile yara signatures.
# $1 - input folder
# $2 - output file
compileFiles()
{
ERR_OUT="$("$CC" -w "$1"/*.yara "$2" 2>&1)"
if [ $? -ne 0 ]; then
printErrorAndDie "yarac failed during compilation of file $1"
fi
# Check for errors in output - yarac returns 0 when it should not.
case "$ERR_OUT" in
*error*)
printErrorAndDie "yarac failed during compilation of file $1"
;;
esac
}
###############################################################################
CC="$1"
if [ -z "$CC" ]; then
printErrorAndDie "missing path to yarac"
fi
SRC="$2"
if [ -z "$SRC" ]; then
printErrorAndDie "missing path to rules folder"
fi
OUT="$3"
if [ -z "$OUT" ]; then
printErrorAndDie "missing path to install folder"
fi
###############################################################################
# Convert from Windows to Unix path on Windows.
case "$(uname -s)" in
*Windows*|*CYGWIN*|*MINGW*|*MSYS*)
CC="$(echo "/$CC" | sed -e 's/\\/\//g' -e 's/://')"
SRC="$(echo "/$SRC" | sed -e 's/\\/\//g' -e 's/://')"
OUT="$(echo "/$OUT" | sed -e 's/\\/\//g' -e 's/://')"
;;
esac
# Directory paths.
SRC="$SRC/support/yara_patterns/tools"
OUT="$OUT/share/retdec/support/generic/yara_patterns/tools"
###############################################################################
# Remove old files if present.
rm -rf "$OUT"
# Prepare directory structure.
mkdir -p "$OUT/pe"
mkdir -p "$OUT/elf"
mkdir -p "$OUT/macho"
###############################################################################
echo "compiling yara signatures..."
## Compile PE32 signatures.
compileFiles "$SRC/pe/x86" "$OUT/pe/x86.yarac"
compileFiles "$SRC/pe/arm" "$OUT/pe/arm.yarac"
## Compile PE32+ signatures.
compileFiles "$SRC/pe/x64" "$OUT/pe/x64.yarac"
## Compile ELF signatures.
compileFiles "$SRC/elf/x86" "$OUT/elf/x86.yarac"
compileFiles "$SRC/elf/arm" "$OUT/elf/arm.yarac"
compileFiles "$SRC/elf/ppc" "$OUT/elf/ppc.yarac"
compileFiles "$SRC/elf/mips" "$OUT/elf/mips.yarac"
## Compile ELF64 signatures.
compileFiles "$SRC/elf/x64" "$OUT/elf/x64.yarac"
compileFiles "$SRC/elf/arm64" "$OUT/elf/arm64.yarac"
compileFiles "$SRC/elf/ppc64" "$OUT/elf/ppc64.yarac"
compileFiles "$SRC/elf/mips64" "$OUT/elf/mips64.yarac"
## Compile Mach-O signatures.
compileFiles "$SRC/macho/x86" "$OUT/macho/x86.yarac"
compileFiles "$SRC/macho/arm" "$OUT/macho/arm.yarac"
compileFiles "$SRC/macho/ppc" "$OUT/macho/ppc.yarac"
## Compile 64-bit Mach-O signatures.
compileFiles "$SRC/macho/x64" "$OUT/macho/x64.yarac"
compileFiles "$SRC/macho/ppc64" "$OUT/macho/ppc64.yarac"
echo "signatures compiled successfully"
exit

View File

@ -4,8 +4,13 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/
#include <cstdlib>
#include <ctime>
#include <string>
#include <gtest/gtest.h>
#include "retdec/utils/os.h"
#include "retdec/utils/time.h"
using namespace ::testing;
@ -17,7 +22,58 @@ namespace tests {
/**
* @brief Tests for the @c time module.
*/
class TimeTests: public Test {};
class TimeTests: public Test {
protected:
virtual void SetUp() override {
// We have to force a specific timezone to make the tests
// deterministic (#90).
changeTimezoneToUTC();
}
virtual void TearDown() override {
changeTimezoneBackToOriginalValue();
}
void changeTimezoneToUTC() {
// Store the original timezone so we can set it back in
// changeTimezoneBackToOriginalValue().
// Both Windows and POSIX use the same variable.
const auto TZ = std::getenv("TZ");
if (TZ) {
originalTZ = TZ;
}
#ifdef OS_WINDOWS
_putenv("TZ=UTC");
_tzset();
#else
setenv("TZ", "UTC", /*overwrite=*/1);
tzset();
#endif
}
void changeTimezoneBackToOriginalValue() {
#ifdef OS_WINDOWS
// Calling _putenv() specifying "VAR=" as a parameter (i.e. without
// the value) deletes the environment variable, which is what we
// want if originalTZ is empty.
const auto TZ_ENV = "TZ=" + originalTZ;
_putenv(TZ_ENV.c_str());
_tzset();
#else
if (originalTZ.empty()) {
unsetenv("TZ");
} else {
setenv("TZ", originalTZ.c_str(), /*overwrite=*/1);
}
tzset();
#endif
}
private:
// Originally set timezone.
std::string originalTZ;
};
//
// timestampToDate()
@ -25,7 +81,7 @@ class TimeTests: public Test {};
TEST_F(TimeTests,
CorrectTimestampToDateConversion) {
EXPECT_EQ("2015-08-05 16:25:19", timestampToDate(std::time_t(1438784719)));
EXPECT_EQ("2015-08-05 14:25:19", timestampToDate(std::time_t(1438784719)));
}
} // namespace tests