diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b2ef1d1..d206936c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,10 +7,11 @@ on: pull_request: branches: - - '**' + - "**" env: LIEF_VERSION: 0.12.3 + SLEIGH_VERSION: 10.2.3 jobs: coverage: @@ -26,9 +27,18 @@ jobs: - name: Install Dependencies run: | - sudo apt-get install libgmp-dev python3-dev libz3-dev - wget -O - -c https://github.com/lief-project/LIEF/releases/download/$LIEF_VERSION/LIEF-$LIEF_VERSION-Linux-x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - wget -O - -c https://github.com/lifting-bits/sleigh/releases/download/v10.1.2-2/Linux-sleigh-10.1.2-2.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 + sudo apt-get install libgmp-dev python3-dev + # LIEF + wget -O- https://github.com/lief-project/LIEF/releases/download/$LIEF_VERSION/LIEF-$LIEF_VERSION-Linux-x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 + # Sleigh + wget -O- https://github.com/lifting-bits/sleigh/releases/download/v$SLEIGH_VERSION/Linux-sleigh-$SLEIGH_VERSION-1.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 + # Z3 Ubuntu 20.04 package doesn't play nice with sanitizers + # (also remove top-level directory from zip) + wget -O z3.zip https://github.com/Z3Prover/z3/releases/download/z3-4.8.14/z3-4.8.14-x64-glibc-2.31.zip + dest=/opt/z3; zip=./z3.zip; \ + sudo mkdir -p "${dest}" && \ + sudo unzip -d "${dest}" "${zip}" && \ + f=("${dest}"/*) && sudo mv "${dest}"/*/* "$dest" && sudo rmdir "${f[@]}" - name: Install LCov run: sudo apt-get update -q @@ -69,7 +79,7 @@ jobs: # LIEF wget -O- https://github.com/lief-project/LIEF/releases/download/$LIEF_VERSION/LIEF-$LIEF_VERSION-Linux-x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 # Sleigh - wget -O- https://github.com/lifting-bits/sleigh/releases/download/v10.1.2-2/Linux-sleigh-10.1.2-2.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 + wget -O- https://github.com/lifting-bits/sleigh/releases/download/v$SLEIGH_VERSION/Linux-sleigh-$SLEIGH_VERSION-1.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 # Z3 Ubuntu 20.04 package doesn't play nice with sanitizers # (also remove top-level directory from zip) wget -O z3.zip https://github.com/Z3Prover/z3/releases/download/z3-4.8.14/z3-4.8.14-x64-glibc-2.31.zip @@ -99,6 +109,7 @@ jobs: test: strategy: + fail-fast: false matrix: os: [ # TODO: windows, @@ -111,6 +122,8 @@ jobs: include: - { type: shared, shared: YES } - { type: static, shared: NO } + - { os: macos, triplet: x64-osx-release } + - { os: ubuntu, triplet: x64-linux-release } runs-on: ${{ matrix.os }}-latest @@ -125,25 +138,30 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" + - name: Common Dependencies + run: | + git clone https://github.com/microsoft/vcpkg + git -C vcpkg checkout 23f0707b1a46bbf7fff9fb95cde2aa0c7213c31d + echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV" + - name: Install Dependencies if: matrix.os == 'ubuntu' run: | - sudo apt-get install libgmp-dev python3-dev libz3-dev + sudo apt-get install python3-dev python3 -m pip install pytest - wget -O - -c https://github.com/lief-project/LIEF/releases/download/$LIEF_VERSION/LIEF-$LIEF_VERSION-Linux-x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - wget -O - -c https://github.com/lifting-bits/sleigh/releases/download/v10.1.2-2/Linux-sleigh-10.1.2-2.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - name: Install Dependencies if: matrix.os == 'macos' run: | - brew install gmp z3 + brew install autoconf automake libtool python3 -m pip install --user pytest - wget -O - -c https://github.com/lief-project/LIEF/releases/download/$LIEF_VERSION/LIEF-$LIEF_VERSION-Darwin-x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - wget -O - -c https://github.com/lifting-bits/sleigh/releases/download/v10.1.2-2/macOS-sleigh-10.1.2-2.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - name: Configure run: cmake --preset=ci-${{ matrix.os }} -D BUILD_SHARED_LIBS=${{ matrix.shared }} + -D VCPKG_HOST_TRIPLET=${{ matrix.triplet }} + -D VCPKG_TARGET_TRIPLET=${{ matrix.triplet }} + -D "VCPKG_INSTALLED_DIR=${{ github.workspace }}/vcpkg_installed" - name: Build run: cmake --build build --config Release -j 2 @@ -154,7 +172,13 @@ jobs: - name: Test install directory working-directory: tests/find-package run: | - cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -Dmaat_DIR=${{ github.workspace }}/prefix/share/maat + cmake -B build -S . \ + -DCMAKE_BUILD_TYPE=Release \ + -Dmaat_DIR=${{ github.workspace }}/prefix/share/maat \ + "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ + -DVCPKG_HOST_TRIPLET=${{ matrix.triplet }} \ + -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} \ + "-DVCPKG_INSTALLED_DIR=${{ github.workspace }}/vcpkg_installed" cmake --build build ./build/maat_find_package_test diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 18d35733..adb16b26 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -10,6 +10,7 @@ on: env: LIEF_VERSION: 0.12.3 + SLEIGH_VERSION: 10.2.3 jobs: @@ -125,7 +126,7 @@ jobs: cmake --build z3/build "-j$(sysctl -n hw.logicalcpu)" && cmake --install z3/build --prefix "${{ github.workspace }}/arm64-cross" # Native sleigh for running the sleigh compiler - wget -O - -c https://github.com/lifting-bits/sleigh/releases/download/v10.1.2-2/macOS-sleigh-10.1.2-2.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 + wget -O - -c https://github.com/lifting-bits/sleigh/releases/download/v$SLEIGH_VERSION/macOS-sleigh-$SLEIGH_VERSION-1.x86_64.tar.gz | sudo tar xz -C /usr/local --strip-components=1 - name: Build wheels diff --git a/.gitignore b/.gitignore index 75622aa0..1389ad49 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ cmake-build-*/ prefix/ CMakeLists.txt.user CMakeUserPresets.json +.z3-trace diff --git a/CMakeLists.txt b/CMakeLists.txt index c7be0169..3c7fc9e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,9 @@ if(maat_USE_EXTERNAL_SLEIGH) find_package(sleigh REQUIRED) else() set(sleigh_ENABLE_TESTS OFF CACHE BOOL "") + set(sleigh_BUILD_TOOLS ON CACHE BOOL "") add_subdirectory(src/third-party/sleigh/sleigh-cmake sleigh EXCLUDE_FROM_ALL) + include("${sleigh_SOURCE_DIR}/cmake/modules/sleighCompile.cmake") endif() target_link_libraries( @@ -155,15 +157,13 @@ add_custom_command( # Allow user to override sleigh compiler to support cross-compilation. Default # location is the one imported when we found the sleigh package -if(CMAKE_CROSSCOMPILING) - find_program(maat_SLEIGH_COMPILER "sleigh_opt" - DOC "Sleigh compiler executable" - ) +if(TARGET sleigh::sleigh AND NOT CMAKE_CROSSCOMPILING) + set(maat_SLEIGH_COMPILER "$" CACHE PATH "Sleigh compiler executable") +else() + find_program(maat_SLEIGH_COMPILER "sleigh" DOC "Sleigh compiler executable") if(NOT maat_SLEIGH_COMPILER) message(FATAL_ERROR "Maat needs a sleigh compiler. Specify path manually by setting 'maat_SLEIGH_COMPILER'") endif() -else() - set(maat_SLEIGH_COMPILER "$" CACHE PATH "Sleigh compiler executable") endif() macro(maat_sleigh_compile ARCH_DIR ARCH) diff --git a/CMakePresets.json b/CMakePresets.json index 4f9676f4..ee77ad34 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -17,7 +17,6 @@ "systemVars": false }, "errors": { - "dev": true, "deprecated": true } }, @@ -29,6 +28,21 @@ "maat_DEVELOPER_MODE": "ON" } }, + { + "name": "vcpkg", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + }, + { + "name": "vcpkg-win64-static", + "inherits": "vcpkg", + "hidden": true, + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md" + } + }, { "name": "cppcheck", "hidden": true, @@ -50,7 +64,8 @@ "cacheVariables": { "CMAKE_CXX_EXTENSIONS": "OFF", "CMAKE_CXX_STANDARD": "17", - "CMAKE_CXX_STANDARD_REQUIRED": "ON" + "CMAKE_CXX_STANDARD_REQUIRED": "ON", + "CMAKE_POSITION_INDEPENDENT_CODE": "ON" } }, { @@ -107,6 +122,9 @@ "name": "ci-sanitize", "binaryDir": "${sourceDir}/build/sanitize", "inherits": ["ci-unix", "dev-mode"], + "errors": { + "dev": true + }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Sanitize", "CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common", @@ -120,15 +138,15 @@ }, { "name": "ci-macos", - "inherits": ["ci-build", "ci-unix", "dev-mode"] + "inherits": ["ci-build", "ci-unix", "dev-mode", "vcpkg"] }, { "name": "ci-ubuntu", - "inherits": ["ci-build", "ci-unix", "dev-mode"] + "inherits": ["ci-build", "ci-unix", "dev-mode", "vcpkg"] }, { "name": "ci-windows", - "inherits": ["ci-build", "ci-win64", "dev-mode"] + "inherits": ["ci-build", "ci-win64", "dev-mode", "vcpkg-win64-static"] } ] } diff --git a/HACKING.md b/HACKING.md index d0031a4d..299ef30e 100644 --- a/HACKING.md +++ b/HACKING.md @@ -74,8 +74,8 @@ the project. The following is a real example of a contributor's user preset (ins "inherits": ["dev-common", "ci-sanitize"], "binaryDir": "${sourceDir}/build/sanitize", "cacheVariables": { - "CMAKE_CXX_COMPILER": "/usr/local/opt/llvm@13/bin/clang++", - "CMAKE_C_COMPILER": "/usr/local/opt/llvm@13/bin/clang" + "CMAKE_CXX_COMPILER": "/usr/local/opt/llvm/bin/clang++", + "CMAKE_C_COMPILER": "/usr/local/opt/llvm/bin/clang" } } ], diff --git a/bindings/packaging/Dockerfile b/bindings/packaging/Dockerfile index a63eb421..9c568db2 100644 --- a/bindings/packaging/Dockerfile +++ b/bindings/packaging/Dockerfile @@ -9,7 +9,7 @@ RUN yum install -y wget findutils git gmp-devel python3-devel curl # Build and install LIEF. We need to rebuild it so that it doesn't use the C++11 mangling ABI # which is incompatible with manylinux wheels -RUN wget -O lief.tar.gz https://github.com/lief-project/LIEF/archive/refs/tags/0.12.3.zip && \ +RUN wget -O lief.tar.gz https://github.com/lief-project/LIEF/releases/download/0.12.3/lief-0.12.3.tar.gz && \ mkdir -p lief/build && tar xzvf lief.tar.gz -C lief --strip-components 1 && cd lief/build && \ cmake -DCMAKE_BUILD_TYPE=Release .. && make -j4 && make install && \ cd ../.. && rm -rf lief.tar.gz lief diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 4d7bb327..a6c480d8 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -25,7 +25,7 @@ set(other_maat_targets) # Needed only if using vendored library and not building as shared library # because sleigh is always a static library if(NOT maat_USE_EXTERNAL_SLEIGH AND NOT BUILD_SHARED_LIBS) - list(APPEND other_maat_targets sla sleigh_settings) + list(APPEND other_maat_targets sleigh_sla) endif() install( diff --git a/ports/fmt/fix-format-conflict.patch b/ports/fmt/fix-format-conflict.patch new file mode 100644 index 00000000..3d97c5c9 --- /dev/null +++ b/ports/fmt/fix-format-conflict.patch @@ -0,0 +1,28 @@ +diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h +index 2c51c50..fb3eba0 100644 +--- a/include/fmt/format-inl.h ++++ b/include/fmt/format-inl.h +@@ -75,8 +75,8 @@ FMT_FUNC void format_error_code(detail::buffer& out, int error_code, + error_code_size += detail::to_unsigned(detail::count_digits(abs_value)); + auto it = buffer_appender(out); + if (message.size() <= inline_buffer_size - error_code_size) +- format_to(it, FMT_STRING("{}{}"), message, SEP); +- format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code); ++ fmt::format_to(it, FMT_STRING("{}{}"), message, SEP); ++ fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code); + FMT_ASSERT(out.size() <= inline_buffer_size, ""); + } + +diff --git a/src/os.cc b/src/os.cc +index 04b4dc5..fe2c7e4 100644 +--- a/src/os.cc ++++ b/src/os.cc +@@ -167,7 +167,7 @@ void detail::format_windows_error(detail::buffer& out, int error_code, + if (msg) { + utf16_to_utf8 utf8_message; + if (utf8_message.convert(msg) == ERROR_SUCCESS) { +- format_to(buffer_appender(out), "{}: {}", message, utf8_message); ++ fmt::format_to(buffer_appender(out), "{}: {}", message, utf8_message); + return; + } + } diff --git a/ports/fmt/fix-invalid-command.patch b/ports/fmt/fix-invalid-command.patch new file mode 100644 index 00000000..c554188b --- /dev/null +++ b/ports/fmt/fix-invalid-command.patch @@ -0,0 +1,11 @@ +diff --git a/include/fmt/locale.h b/include/fmt/locale.h +index 7571b52..0a34eb4 100644 +--- a/include/fmt/locale.h ++++ b/include/fmt/locale.h +@@ -1,2 +1,6 @@ + #include "xchar.h" ++#ifdef _WIN32 ++#pragma message ("fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead") ++#else + #warning fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead ++#endif diff --git a/ports/fmt/fix-write-batch.patch b/ports/fmt/fix-write-batch.patch new file mode 100644 index 00000000..7c17d603 --- /dev/null +++ b/ports/fmt/fix-write-batch.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f21cf45..691a632 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -157,7 +157,7 @@ if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio") + join(netfxpath + "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\" + ".NETFramework\\v4.0") +- file(WRITE run-msbuild.bat " ++ file(WRITE ${CMAKE_BINARY_DIR}/run-msbuild.bat " + ${MSBUILD_SETUP} + ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*") + endif () diff --git a/ports/fmt/portfile.cmake b/ports/fmt/portfile.cmake new file mode 100644 index 00000000..db016782 --- /dev/null +++ b/ports/fmt/portfile.cmake @@ -0,0 +1,67 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO fmtlib/fmt + REF 8.1.1 + SHA512 794a47d7cb352a2a9f2c050a60a46b002e4157e5ad23e15a5afc668e852b1e1847aeee3cda79e266c789ff79310d792060c94976ceef6352e322d60b94e23189 + HEAD_REF master + PATCHES + fix-write-batch.patch + fix-invalid-command.patch + fix-format-conflict.patch +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DFMT_CMAKE_DIR=share/fmt + -DFMT_TEST=OFF + -DFMT_DOC=OFF +) + +vcpkg_cmake_install() +file(INSTALL "${SOURCE_PATH}/LICENSE.rst" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) +if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) + if(VCPKG_TARGET_IS_WINDOWS) + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/fmtd.dll") + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/bin") + file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/fmtd.dll" "${CURRENT_PACKAGES_DIR}/debug/bin/fmtd.dll") + endif() + endif() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/fmt.dll") + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/bin") + file(RENAME "${CURRENT_PACKAGES_DIR}/lib/fmt.dll" "${CURRENT_PACKAGES_DIR}/bin/fmt.dll") + endif() + endif() + endif() + + vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/fmt/core.h + "defined(FMT_SHARED)" + "1" + ) +endif() +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +vcpkg_cmake_config_fixup() +vcpkg_fixup_pkgconfig() + +if(VCPKG_TARGET_IS_WINDOWS) + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/share/fmt/fmt-targets-debug.cmake + "lib/fmtd.dll" + "bin/fmtd.dll" + ) + endif() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/share/fmt/fmt-targets-release.cmake + "lib/fmt.dll" + "bin/fmt.dll" + ) + endif() +endif() +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") + +# Handle post-build CMake instructions +vcpkg_copy_pdbs() +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/ports/fmt/usage b/ports/fmt/usage new file mode 100644 index 00000000..e5a9d704 --- /dev/null +++ b/ports/fmt/usage @@ -0,0 +1,8 @@ +The package fmt provides CMake targets: + + find_package(fmt CONFIG REQUIRED) + target_link_libraries(main PRIVATE fmt::fmt) + + # Or use the header-only version + find_package(fmt CONFIG REQUIRED) + target_link_libraries(main PRIVATE fmt::fmt-header-only) diff --git a/ports/fmt/vcpkg.json b/ports/fmt/vcpkg.json new file mode 100644 index 00000000..28a1f11a --- /dev/null +++ b/ports/fmt/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "fmt", + "version": "8.1.1", + "port-version": 2, + "description": "Formatting library for C++. It can be used as a safe alternative to printf or as a fast alternative to IOStreams.", + "homepage": "https://github.com/fmtlib/fmt", + "license": null, + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/ports/lief/0001-Support-vcpkg.patch b/ports/lief/0001-Support-vcpkg.patch new file mode 100644 index 00000000..0bcabb70 --- /dev/null +++ b/ports/lief/0001-Support-vcpkg.patch @@ -0,0 +1,45 @@ +From 426d8167648fff0ad79832a701223b8171dad096 Mon Sep 17 00:00:00 2001 +From: Eric Kilmer +Date: Tue, 12 Apr 2022 10:42:27 -0400 +Subject: [PATCH] Support vcpkg + +Remove msvccrt choosing and fix install paths on Windows +--- + CMakeLists.txt | 7 ++----- + 1 file changed, 2 insertions(+), 5 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b89d0522..9ca50c35 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -11,9 +11,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_CROSSCOMPILING) + endif() + + +-if(WIN32 OR ${IS_WIN_CROSS_COMPILE}) +- include(ChooseMSVCCRT) +-endif() + include(CheckCXXCompilerFlag) + include(CheckCCompilerFlag) + include(ExternalProject) +@@ -667,7 +664,7 @@ endif() + # Installation + # ====================== + +-if(UNIX) ++if(1) + include(GNUInstallDirs) + set(CMAKE_INSTALL_LIBDIR "lib") + else() +@@ -688,7 +685,7 @@ install( + EXPORT LIEFExport + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + install( +-- +2.35.1 + diff --git a/ports/lief/0002-Fix-Uninitialized-CMake-var.patch b/ports/lief/0002-Fix-Uninitialized-CMake-var.patch new file mode 100644 index 00000000..7c0cc9aa --- /dev/null +++ b/ports/lief/0002-Fix-Uninitialized-CMake-var.patch @@ -0,0 +1,19 @@ +diff --git a/LIEFConfig.cmake.in b/LIEFConfig.cmake.in +index 8c35eeab..ea09099f 100644 +--- a/LIEFConfig.cmake.in ++++ b/LIEFConfig.cmake.in +@@ -165,7 +165,8 @@ set(LIEF_LIBRARIES LIEF::LIEF) + get_target_property(LIEF_INCLUDE_DIRS LIEF::LIEF INTERFACE_INCLUDE_DIRECTORIES) + + # Set the following for backwards compatibility +-if(LIEF_INCLUDE_DIR AND EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h") ++if(LIEF_INCLUDE_DIR) ++if(EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h") + file(STRINGS "${LIEF_INCLUDE_DIR}/LIEF/version.h" LIEF_H REGEX "^#define LIEF_VERSION \"[^\"]*\"$") + + string(REGEX REPLACE "^.*LIEF_VERSION \"([0-9]+).*$" "\\1" LIEF_VERSION_MAJOR "${LIEF_H}") +@@ -177,3 +178,4 @@ if(LIEF_INCLUDE_DIR AND EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h") + set(LIEF_MINOR_VERSION "${LIEF_VERSION_MINOR}") + set(LIEF_PATCH_VERSION "${LIEF_VERSION_PATCH}") + endif() ++endif() diff --git a/ports/lief/portfile.cmake b/ports/lief/portfile.cmake new file mode 100644 index 00000000..69fe5679 --- /dev/null +++ b/ports/lief/portfile.cmake @@ -0,0 +1,72 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO lief-project/LIEF + REF 0.12.3 + SHA512 3f48978af2d96e9e469aca1fc4adcfd3475576ba32273d451f881e33b0fc062b0c2b625af10c54c2a0b6a9678e5ce7666499c1c36f578250dab217352f4717e0 + HEAD_REF master + PATCHES + 0001-Support-vcpkg.patch + 0002-Fix-Uninitialized-CMake-var.patch +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS +FEATURES + "c-api" LIEF_C_API # C API + "logging" LIEF_LOGGING # Enable logging + "logging-debug" LIEF_LOGGING_DEBUG # Enable debug logging + "enable-json" LIEF_ENABLE_JSON # Enable JSON-related APIs + + "elf" LIEF_ELF # Build LIEF with ELF module + "pe" LIEF_PE # Build LIEF with PE module + "macho" LIEF_MACHO # Build LIEF with MachO module + + "oat" LIEF_OAT # Build LIEF with OAT module + "dex" LIEF_DEX # Build LIEF with DEX module + "vdex" LIEF_VDEX # Build LIEF with VDEX module + "art" LIEF_ART # Build LIEF with ART module + +INVERTED_FEATURES + "enable-frozen" LIEF_DISABLE_FROZEN # Disable Frozen even if it is supported +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + + OPTIONS + ${FEATURE_OPTIONS} + + -DLIEF_PYTHON_API=OFF + -DLIEF_USE_CCACHE=OFF + -DLIEF_TESTS=OFF + -DLIEF_EXAMPLES=OFF + + # Build with external vcpkg dependencies + -DLIEF_OPT_MBEDTLS_EXTERNAL=ON + -DLIEF_OPT_UTFCPP_EXTERNAL=ON + -DLIEF_EXTERNAL_SPDLOG=ON + -DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON + -DLIEF_OPT_FROZEN_EXTERNAL=ON + -DLIEF_OPT_EXTERNAL_LEAF=ON + "-DLIEF_EXTERNAL_LEAF_DIR=${CURRENT_INSTALLED_DIR}/include" + -DLIEF_OPT_EXTERNAL_SPAN=ON +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH share/LIEF/cmake) + +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") + +# Check if all-caps directory is empty (it won't be on case-insensitive filesystems). +# These files could have been moved during vcpkg_cmake_config_fixup +file(GLOB dir_files "${CURRENT_PACKAGES_DIR}/share/LIEF/*") +list(LENGTH dir_files dir_files_len) +if(dir_files_len EQUAL 0) + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/LIEF") +endif() + +# Handle copyright +file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/ports/lief/vcpkg.json b/ports/lief/vcpkg.json new file mode 100644 index 00000000..165adc12 --- /dev/null +++ b/ports/lief/vcpkg.json @@ -0,0 +1,86 @@ +{ + "name": "lief", + "version-semver": "0.12.3", + "description": "LIEF - Library to Instrument Executable Formats", + "homepage": "https://lief.quarkslab.com", + "license": "Apache-2.0", + "supports": "!uwp", + "dependencies": [ + "boost-leaf", + "mbedtls", + "spdlog", + "tcb-span", + "utfcpp", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "default-features": [ + "art", + "c-api", + "dex", + "elf", + "enable-frozen", + "enable-json", + "logging", + "macho", + "oat", + "pe", + "vdex" + ], + "features": { + "art": { + "description": "Build LIEF with ART module" + }, + "c-api": { + "description": "C API" + }, + "coverage": { + "description": "Perform code coverage" + }, + "dex": { + "description": "Build LIEF with DEX module" + }, + "elf": { + "description": "Build LIEF with ELF module" + }, + "enable-frozen": { + "description": "Enable Frozen", + "dependencies": [ + "frozen" + ] + }, + "enable-json": { + "description": "Enable JSON-related APIs", + "dependencies": [ + "nlohmann-json" + ] + }, + "fuzzing": { + "description": "Fuzz LIEF" + }, + "logging": { + "description": "Enable logging" + }, + "logging-debug": { + "description": "Enable debug logging" + }, + "macho": { + "description": "Build LIEF with MachO module" + }, + "oat": { + "description": "Build LIEF with OAT module" + }, + "pe": { + "description": "Build LIEF with PE module" + }, + "vdex": { + "description": "Build LIEF with VDEX module" + } + } +} diff --git a/ports/mbedtls/enable-pthread.patch b/ports/mbedtls/enable-pthread.patch new file mode 100755 index 00000000..57309ef1 --- /dev/null +++ b/ports/mbedtls/enable-pthread.patch @@ -0,0 +1,99 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0d65b57b8..d44783975 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -61,6 +61,7 @@ if(CMAKE_HOST_WIN32) + else() + option(GEN_FILES "Generate the auto-generated files as needed" OFF) + endif() ++option(ENABLE_PTHREAD "Build mbed TLS with pthread" OFF) + + option(DISABLE_PACKAGE_CONFIG_AND_INSTALL "Disable package configuration, target export and installation" ${MBEDTLS_AS_SUBPROJECT}) + +@@ -257,12 +258,25 @@ if(LIB_INSTALL_DIR) + set(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}") + endif() + ++include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/include) ++ + add_subdirectory(include) + + add_subdirectory(3rdparty) + + add_subdirectory(library) + ++if(ENABLE_PTHREAD) ++ if(WIN32) ++ find_package(pthreads_windows REQUIRED) ++ include_directories("${PThreads4W_INCLUDE_DIR}") ++ else() ++ set(CMAKE_THREAD_PREFER_PTHREAD ON) ++ find_package(Threads REQUIRED) ++ endif() ++ set(LINK_WITH_PTHREAD ON) ++endif() ++ + # + # The C files in tests/src directory contain test code shared among test suites + # and programs. This shared test code is compiled and linked to test suites and +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index e693bc17c..b7b778505 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -1,10 +1,14 @@ + option(INSTALL_MBEDTLS_HEADERS "Install mbed TLS headers." ON) + ++configure_file(mbedtls/config_threading.h.in mbedtls/config_threading.h) ++ + if(INSTALL_MBEDTLS_HEADERS) + + file(GLOB headers "mbedtls/*.h") + file(GLOB psa_headers "psa/*.h") + ++ set(headers ${headers} "${CMAKE_CURRENT_BINARY_DIR}/mbedtls/config_threading.h") ++ + install(FILES ${headers} + DESTINATION include/mbedtls + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) +diff --git a/include/mbedtls/config_threading.h.in b/include/mbedtls/config_threading.h.in +new file mode 100644 +index 000000000..f6286ed9c +--- /dev/null ++++ b/include/mbedtls/config_threading.h.in +@@ -0,0 +1,6 @@ ++#cmakedefine ENABLE_PTHREAD ++ ++#ifdef ENABLE_PTHREAD ++#define MBEDTLS_THREADING_C ++#define MBEDTLS_THREADING_PTHREAD ++#endif +diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h +index 1c60ec8e4..d41715e3e 100644 +--- a/include/mbedtls/mbedtls_config.h ++++ b/include/mbedtls/mbedtls_config.h +@@ -24,6 +24,8 @@ + * limitations under the License. + */ + ++#include ++ + /** + * This is an optional version symbol that enables compatibility handling of + * config files. +diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt +index 0884f57ae..360e9602e 100644 +--- a/library/CMakeLists.txt ++++ b/library/CMakeLists.txt +@@ -215,7 +215,11 @@ if(HAIKU) + endif(HAIKU) + + if(LINK_WITH_PTHREAD) +- set(libs ${libs} pthread) ++ if(WIN32) ++ set(libs ${libs} "${PThreads4W_LIBRARY}") ++ else() ++ set(libs ${libs} pthread) ++ endif() + endif() + + if(LINK_WITH_TRUSTED_STORAGE) diff --git a/ports/mbedtls/portfile.cmake b/ports/mbedtls/portfile.cmake new file mode 100644 index 00000000..33f5a44f --- /dev/null +++ b/ports/mbedtls/portfile.cmake @@ -0,0 +1,36 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO ARMmbed/mbedtls + REF v3.2.1 + SHA512 11e433d64a2c0474bb44f288551c1fc2c143fe9abf8a6e9df26deb8c3e6b575e1eab508a7f46d651003f41ce0ebb234e423260a3e0556d025c345faeb631d178 + HEAD_REF master + PATCHES + enable-pthread.patch +) + +vcpkg_check_features( + OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + pthreads ENABLE_PTHREAD +) + +vcpkg_find_acquire_program(PYTHON3) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + -DENABLE_TESTING=OFF + -DENABLE_PROGRAMS=OFF + -DMBEDTLS_FATAL_WARNINGS=FALSE +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH "cmake") + +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/ports/mbedtls/vcpkg.json b/ports/mbedtls/vcpkg.json new file mode 100644 index 00000000..46a02684 --- /dev/null +++ b/ports/mbedtls/vcpkg.json @@ -0,0 +1,29 @@ +{ + "name": "mbedtls", + "version": "3.2.1", + "description": "An open source, portable, easy to use, readable and flexible SSL library", + "homepage": "https://github.com/ARMmbed/mbedtls", + "license": "Apache-2.0", + "supports": "!uwp", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "pthreads": { + "description": "Multi-threading support", + "dependencies": [ + { + "name": "pthreads", + "platform": "windows" + } + ] + } + } +} diff --git a/ports/sleigh-speccompiler/portfile.cmake b/ports/sleigh-speccompiler/portfile.cmake new file mode 100644 index 00000000..8ebfd2d2 --- /dev/null +++ b/ports/sleigh-speccompiler/portfile.cmake @@ -0,0 +1,57 @@ +# NOTE: A large part of this file is the same as sleigh port +set(VCPKG_POLICY_CMAKE_HELPER_PORT enabled) + +vcpkg_minimum_required(VERSION 2022-10-12) # for ${VERSION} + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO lifting-bits/sleigh + REF "v${VERSION}" + SHA512 e5c4d30e00904807d1495d6f063fcf18c37763928d43c784905ec357c95f83e1fbffddef2536beb0d25cc5f744235b815e61d5c861304fcbc0b6b3e258b561f0 + HEAD_REF master +) + +vcpkg_from_github( + OUT_SOURCE_PATH GHIDRA_SOURCE_PATH + REPO NationalSecurityAgency/ghidra + REF "Ghidra_${VERSION}_build" + SHA512 f5dbc828e43acabe8e30f293726b7afa7f96aa29eb2d0ea1ccd4688012e9fdf2950fab2cfa7b8a2b94feaa8ec5ffba5d39017c8ec152e592818d6e3b67df3fc7 + HEAD_REF master +) + +# Apply sleigh project's patches to ghidra +z_vcpkg_apply_patches( + SOURCE_PATH "${GHIDRA_SOURCE_PATH}" + PATCHES + "${SOURCE_PATH}/src/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${SOURCE_PATH}/src/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" + "${SOURCE_PATH}/src/patches/stable/0003-Fix-UBSAN-errors-in-decompiler.patch" + "${SOURCE_PATH}/src/patches/stable/0004-Use-stroull-instead-of-stroul-to-parse-address-offse.patch" + "${SOURCE_PATH}/src/patches/stable/0005-1-4-decompiler-Add-using-namespace-std-to-all-.cc.patch" + "${SOURCE_PATH}/src/patches/stable/0006-2-4-decompiler-Remusing-automated-std-namespace-fix.patch" + "${SOURCE_PATH}/src/patches/stable/0007-3-4-decompiler-Manually-fix-std-namespace-in-generat.patch" + "${SOURCE_PATH}/src/patches/stable/0008-4-4-decompiler-Manually-fix-missed-std-variable-usag.patch" +) + +set(VCPKG_BUILD_TYPE release) # we only need release here! +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}/tools/spec-compiler" + OPTIONS + "-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=${GHIDRA_SOURCE_PATH}" +) +vcpkg_cmake_install() +vcpkg_copy_tools( + TOOL_NAMES sleigh + DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}" + AUTO_CLEAN +) + +file( + INSTALL "${SOURCE_PATH}/LICENSE" + DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" + RENAME copyright +) +file( + INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" + DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" +) diff --git a/ports/sleigh-speccompiler/vcpkg-port-config.cmake b/ports/sleigh-speccompiler/vcpkg-port-config.cmake new file mode 100644 index 00000000..4d336443 --- /dev/null +++ b/ports/sleigh-speccompiler/vcpkg-port-config.cmake @@ -0,0 +1 @@ +set(SLEIGH_SPECCOMPILER "${CMAKE_CURRENT_LIST_DIR}/../../tools/sleigh-speccompiler/sleigh${VCPKG_HOST_EXECUTABLE_SUFFIX}") diff --git a/ports/sleigh-speccompiler/vcpkg.json b/ports/sleigh-speccompiler/vcpkg.json new file mode 100644 index 00000000..cd39879f --- /dev/null +++ b/ports/sleigh-speccompiler/vcpkg.json @@ -0,0 +1,16 @@ +{ + "name": "sleigh-speccompiler", + "version": "10.2.3", + "description": "Unofficial Ghidra Sleigh specification compiler", + "homepage": "https://github.com/lifting-bits/sleigh", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/ports/sleigh/portfile.cmake b/ports/sleigh/portfile.cmake new file mode 100644 index 00000000..775b4138 --- /dev/null +++ b/ports/sleigh/portfile.cmake @@ -0,0 +1,73 @@ +# NOTE: A large part of this file is the same as sleigh-speccompiler port +vcpkg_minimum_required(VERSION 2022-10-12) # for ${VERSION} + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO lifting-bits/sleigh + REF "v${VERSION}" + SHA512 e5c4d30e00904807d1495d6f063fcf18c37763928d43c784905ec357c95f83e1fbffddef2536beb0d25cc5f744235b815e61d5c861304fcbc0b6b3e258b561f0 + HEAD_REF master +) + +vcpkg_from_github( + OUT_SOURCE_PATH GHIDRA_SOURCE_PATH + REPO NationalSecurityAgency/ghidra + REF "Ghidra_${VERSION}_build" + SHA512 f5dbc828e43acabe8e30f293726b7afa7f96aa29eb2d0ea1ccd4688012e9fdf2950fab2cfa7b8a2b94feaa8ec5ffba5d39017c8ec152e592818d6e3b67df3fc7 + HEAD_REF master +) + +# Apply sleigh project's patches to ghidra +z_vcpkg_apply_patches( + SOURCE_PATH "${GHIDRA_SOURCE_PATH}" + PATCHES + "${SOURCE_PATH}/src/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${SOURCE_PATH}/src/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" + "${SOURCE_PATH}/src/patches/stable/0003-Fix-UBSAN-errors-in-decompiler.patch" + "${SOURCE_PATH}/src/patches/stable/0004-Use-stroull-instead-of-stroul-to-parse-address-offse.patch" + "${SOURCE_PATH}/src/patches/stable/0005-1-4-decompiler-Add-using-namespace-std-to-all-.cc.patch" + "${SOURCE_PATH}/src/patches/stable/0006-2-4-decompiler-Remusing-automated-std-namespace-fix.patch" + "${SOURCE_PATH}/src/patches/stable/0007-3-4-decompiler-Manually-fix-std-namespace-in-generat.patch" + "${SOURCE_PATH}/src/patches/stable/0008-4-4-decompiler-Manually-fix-missed-std-variable-usag.patch" +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS +FEATURES + "specs" sleigh_BUILD_SLEIGHSPECS # compiled sla files + "support" sleigh_BUILD_SUPPORT # support libraries +) + +vcpkg_list(SET OPTIONS) +if("specs" IN_LIST FEATURES) + vcpkg_list(APPEND OPTIONS "-DSLEIGH_EXECUTABLE=${SLEIGH_SPECCOMPILER}") +endif() + +vcpkg_find_acquire_program(GIT) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + ${OPTIONS} + "-DGIT_EXECUTABLE=${GIT}" + "-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=${GHIDRA_SOURCE_PATH}" + -Dsleigh_BUILD_TOOLS=OFF +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/sleigh) +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static" OR NOT VCPKG_TARGET_IS_WINDOWS) + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +file( + INSTALL "${SOURCE_PATH}/LICENSE" + DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" + RENAME copyright +) diff --git a/ports/sleigh/vcpkg.json b/ports/sleigh/vcpkg.json new file mode 100644 index 00000000..e1696166 --- /dev/null +++ b/ports/sleigh/vcpkg.json @@ -0,0 +1,30 @@ +{ + "name": "sleigh", + "version": "10.2.3", + "description": "Unofficial CMake build for Ghidra Sleigh and decompiler libraries", + "homepage": "https://github.com/lifting-bits/sleigh", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "specs": { + "description": "Compile and install the upstream sleigh specs", + "dependencies": [ + { + "name": "sleigh-speccompiler", + "host": true + } + ] + }, + "support": { + "description": "Include support libraries written by ToB" + } + } +} diff --git a/src/expression/expression.cpp b/src/expression/expression.cpp index 33950c04..e94dba2b 100644 --- a/src/expression/expression.cpp +++ b/src/expression/expression.cpp @@ -2090,7 +2090,10 @@ cst_t cst_mask(size_t size) if( size == sizeof(cst_t)*8 ) return -1; else - return ((ucst_t)1< sizeof(cst_t)*8) { + printf("Break here\n"); + } + return ((ucst_t)1<= n1.size) { - if( n1.cst_ & (0x1 << (n1.size-1))) + if( n1.cst_ & ((ucst_t)0x1 << (n1.size-1))) tmp = 0xffffffffffffffff; else tmp = 0; diff --git a/src/memory/memory.cpp b/src/memory/memory.cpp index 8885e448..593d8cc1 100644 --- a/src/memory/memory.cpp +++ b/src/memory/memory.cpp @@ -2708,7 +2708,7 @@ void MemEngine::write_from_concrete_snapshot(addr_t addr, cst_t val, int nb_byte if (_endianness == Endian::LITTLE) { segment->write_from_concrete_snapshot(addr, val, bytes_to_write); - val = val >> (bytes_to_write*8); + val = val >> (bytes_to_write*8 - 1); } else { diff --git a/src/third-party/sleigh/native/sleigh_interface.cpp b/src/third-party/sleigh/native/sleigh_interface.cpp index e31b5702..ec13294c 100644 --- a/src/third-party/sleigh/native/sleigh_interface.cpp +++ b/src/third-party/sleigh/native/sleigh_interface.cpp @@ -76,7 +76,7 @@ class SimpleLoadImage : public LoadImage } } - virtual string getArchType(void) const { return "myload"; } + virtual std::string getArchType(void) const { return "myload"; } virtual void adjustVma(long adjust) { } }; @@ -247,7 +247,7 @@ class AssemblyEmitCacher : public AssemblyEmit public: std::map cache; - void dump(const Address &addr, const string &mnem, const string &body) + void dump(const Address &addr, const std::string &mnem, const std::string &body) { cache[addr.getOffset()] = mnem + " " + body; } @@ -282,20 +282,23 @@ class AssemblyEmitCacher : public AssemblyEmit class TranslationContext { public: - SimpleLoadImage m_loader; - ContextInternal m_context_internal; - DocumentStorage m_document_storage; - Document *m_document; - Element *m_tags; - unique_ptr m_sleigh; - string m_register_name_cache; - TmpCache tmp_cache; - maat::Arch::Type arch; - AssemblyEmitCacher asm_cache; + SimpleLoadImage m_loader; + ContextInternal m_context_internal; + DocumentStorage m_document_storage; + Document *m_document; + Element *m_tags; + std::unique_ptr m_sleigh; + std::string m_register_name_cache; + TmpCache tmp_cache; + maat::Arch::Type arch; + AssemblyEmitCacher asm_cache; std::unordered_map callother_mapping; TranslationContext(maat::Arch::Type a, const std::string& slafile, const std::string& pspecfile): arch(a) { + AttributeId::initialize(); + ElementId::initialize(); + if (not loadSlaFile(slafile.c_str())) { throw runtime_exception(Fmt() << "Sleigh: failed to load slafile: " << slafile >> Fmt::to_str); diff --git a/src/third-party/sleigh/processors/x86/data/languages/ia.sinc b/src/third-party/sleigh/processors/x86/data/languages/ia.sinc index 19bd4a41..12c30f39 100644 --- a/src/third-party/sleigh/processors/x86/data/languages/ia.sinc +++ b/src/third-party/sleigh/processors/x86/data/languages/ia.sinc @@ -733,7 +733,6 @@ addr64: [Base64 + Index64*ss] is mod=0 & r_m=4; Index64 & Base64 & ss addr64: [Base64] is mod=0 & r_m=4; rexXprefix=0 & index64=4 & Base64 { export Base64; } addr64: [simm32_64 + Index64*ss] is mod=0 & r_m=4; Index64 & base64=5 & ss; simm32_64 { local tmp=simm32_64+Index64*ss; export tmp; } addr64: [Index64*ss] is mod=0 & r_m=4; Index64 & base64=5 & ss; imm32=0 { local tmp=Index64*ss; export tmp; } -# MAAT: fix addr64 to use simm32_64 instead of imm32_64 addr64: [simm32_64] is mod=0 & r_m=4; rexXprefix=0 & index64=4 & base64=5; simm32_64 { export *[const]:8 simm32_64; } addr64: [Base64 + simm8_64] is mod=1 & r_m=4; rexXprefix=0 & index64=4 & Base64; simm8_64 { local tmp=simm8_64+Base64; export tmp; } addr64: [Base64 + Index64*ss + simm8_64] is mod=1 & r_m=4; Index64 & Base64 & ss; simm8_64 { local tmp=simm8_64+Base64+Index64*ss; export tmp; } @@ -1607,13 +1606,13 @@ macro fucompe(val1, val2) { [ instrPhase=1; vexMode=1; rexBprefix=~vex_b; vexMMMMM=vex_mmmmm; rexWprefix=vex_w; vexVVVV=~vex_vvvv; vexL=vex_l; prefix_f2=1; ] {} # 32-bit 2-byte VEX -:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_vvvv & vex_l & vex_pp=0; instruction +:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_x=1 & vex_vvvv & vex_l & vex_pp=0; instruction [ instrPhase=1; vexMode=1; vexVVVV=~vex_vvvv; vexL=vex_l; vexMMMMM=0x1; ] {} -:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_vvvv & vex_l & vex_pp=1; instruction +:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_x=1 & vex_vvvv & vex_l & vex_pp=1; instruction [ instrPhase=1; vexMode=1; vexVVVV=~vex_vvvv; vexL=vex_l; vexMMMMM=0x1; prefix_66=1; ] {} -:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_vvvv & vex_l & vex_pp=2; instruction +:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_x=1 & vex_vvvv & vex_l & vex_pp=2; instruction [ instrPhase=1; vexMode=1; vexVVVV=~vex_vvvv; vexL=vex_l; vexMMMMM=0x1; prefix_f3=1; ] {} -:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_vvvv & vex_l & vex_pp=3; instruction +:^instruction is $(LONGMODE_OFF) & instrPhase=0 & vexMode=0 & rexprefix=0 & mandover=0 & byte=0xC5; vex_r=1 & vex_x=1 & vex_vvvv & vex_l & vex_pp=3; instruction [ instrPhase=1; vexMode=1; vexVVVV=~vex_vvvv; vexL=vex_l; vexMMMMM=0x1; prefix_f2=1; ] {} @@ -2790,7 +2789,6 @@ enterFrames: low5 is low5 { tmp:1 = low5; export tmp; } :INT1 is vexMode=0 & byte=0xf1 { tmp:1 = 0x1; intloc:$(SIZE) = swi(tmp); return [0:1]; } :INT3 is vexMode=0 & byte=0xcc { tmp:1 = 0x3; intloc:$(SIZE) = swi(tmp); return [0:1]; } :INT imm8 is vexMode=0 & byte=0xcd; imm8 { tmp:1 = imm8; intloc:$(SIZE) = swi(tmp); } - :INTO is vexMode=0 & byte=0xce & bit64=0 { tmp:1 = 0x4; @@ -3204,11 +3202,8 @@ define pcodeop swap_bytes; :NEG rm64 is $(LONGMODE_ON) & vexMode=0 & opsize=2 & byte=0xf7; rm64 & reg_opcode=3 ... { negflags(rm64); rm64 = -rm64; resultflags(rm64); } @endif -# MAAT: For simple NOPs rexprefix=0 is necessary to avoid the XCHG R8D, EAX and -# XCHG R8W, AX instructions to be wrongly interpreted as REX-prefixed NOPs :NOP is vexMode=0 & opsize=0 & byte=0x90 & rexprefix=0 { } :NOP is vexMode=0 & opsize=1 & byte=0x90 & rexprefix=0 { } - :NOP rm16 is vexMode=0 & mandover & opsize=0 & byte=0x0f; high5=3; rm16 ... { } :NOP rm32 is vexMode=0 & mandover & opsize=1 & byte=0x0f; high5=3; rm32 ... { } :NOP^"/reserved" rm16 is vexMode=0 & mandover & opsize=0 & byte=0x0f; byte=0x18; rm16 & reg_opcode_hb=1 ... { } @@ -5910,7 +5905,6 @@ define pcodeop movmskps; XmmReg1 = XmmReg2; } - :MOVUPS m128, XmmReg is vexMode=0 & mandover=0 & byte=0x0F; byte=0x11; m128 & XmmReg ... { m128 = XmmReg; @@ -6990,7 +6984,7 @@ define pcodeop pminub; Reg32 = zext(byte_mask); build check_Reg32_dest; } - + define pcodeop pmulhrsw; :PMULHRSW mmxreg, m64 is vexMode=0 & mandover=0 & byte=0x0F; byte=0x38; byte=0x0B; mmxreg ... & m64 { mmxreg=pmulhrsw(mmxreg,m64); } :PMULHRSW mmxreg1, mmxreg2 is vexMode=0 & mandover=0 & byte=0x0F; byte=0x38; byte=0x0B; mmxmod = 3 & mmxreg1 & mmxreg2 { mmxreg1=pmulhrsw(mmxreg1,mmxreg2); } @@ -7100,42 +7094,39 @@ define pcodeop pshufb; :PSHUFB XmmReg1, XmmReg2 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x38; byte=0x00; xmmmod = 3 & XmmReg1 & XmmReg2 { XmmReg1=pshufb(XmmReg1,XmmReg2); } # determine the total shift required by the bit fields in a shuffle opcode -Order0: order0 is imm8 [ order0 = (( imm8 & 0x3) << 5); ] { export *[const]:1 order0; } -Order1: order1 is imm8 [ order1 = (((imm8 >> 2) & 0x3) << 5); ] { export *[const]:1 order1; } -Order2: order2 is imm8 [ order2 = (((imm8 >> 4) & 0x3) << 5); ] { export *[const]:1 order2; } -Order3: order3 is imm8 [ order3 = (((imm8 >> 6) & 0x3) << 5); ] { export *[const]:1 order3; } +Order0: order0 is imm8 [ order0 = ( imm8 & 0x3); ] { export *[const]:1 order0; } +Order1: order1 is imm8 [ order1 = ((imm8 >> 2) & 0x3); ] { export *[const]:1 order1; } +Order2: order2 is imm8 [ order2 = ((imm8 >> 4) & 0x3); ] { export *[const]:1 order2; } +Order3: order3 is imm8 [ order3 = ((imm8 >> 6) & 0x3); ] { export *[const]:1 order3; } + +macro shuffle_4(dest,ord,c0,c1,c2,c3){ + dest = zext(ord == 0) * c0 + zext(ord == 1) * c1 + zext(ord == 2) * c2 + zext(ord == 3) * c3; +} :PSHUFD XmmReg1, m128, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x70; (m128 & XmmReg1 ...); imm8 & Order0 & Order1 & Order2 & Order3 { - shifted:16 = m128 >> Order0; - XmmReg1[0,32] = shifted:4; - - shifted = m128 >> Order1; - XmmReg1[32,32] = shifted:4; - - shifted = m128 >> Order2; - XmmReg1[64,32] = shifted:4; + local c0 = m128[0,32]; + local c1 = m128[32,32]; + local c2 = m128[64,32]; + local c3 = m128[96,32]; - shifted = m128 >> Order3; - XmmReg1[96,32] = shifted:4; + shuffle_4(XmmReg1[0,32],Order0,c0,c1,c2,c3); + shuffle_4(XmmReg1[32,32],Order1,c0,c1,c2,c3); + shuffle_4(XmmReg1[64,32],Order2,c0,c1,c2,c3); + shuffle_4(XmmReg1[96,32],Order3,c0,c1,c2,c3); } :PSHUFD XmmReg1, XmmReg2, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x70; xmmmod=3 & XmmReg1 & XmmReg2 ; imm8 & Order0 & Order1 & Order2 & Order3 { - #in case XmmReg1 and XmmReg2 are the same register - local original_XmmReg2:16 = XmmReg2; - - shifted:16 = original_XmmReg2 >> Order0; - XmmReg1[0,32] = shifted:4; - - shifted = original_XmmReg2 >> Order1; - XmmReg1[32,32] = shifted:4; - - shifted = original_XmmReg2 >> Order2; - XmmReg1[64,32] = shifted:4; + local c0 = XmmReg2[0,32]; + local c1 = XmmReg2[32,32]; + local c2 = XmmReg2[64,32]; + local c3 = XmmReg2[96,32]; - shifted = original_XmmReg2 >> Order3; - XmmReg1[96,32] = shifted:4; + shuffle_4(XmmReg1[0,32],Order0,c0,c1,c2,c3); + shuffle_4(XmmReg1[32,32],Order1,c0,c1,c2,c3); + shuffle_4(XmmReg1[64,32],Order2,c0,c1,c2,c3); + shuffle_4(XmmReg1[96,32],Order3,c0,c1,c2,c3); } define pcodeop pshufhw; @@ -7168,7 +7159,6 @@ define pcodeop psignd; :PSIGND XmmReg, m128 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x38; byte=0x0a; XmmReg ... & m128 { XmmReg=psignd(XmmReg,m128); } :PSIGND XmmReg1, XmmReg2 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x38; byte=0x0a; xmmmod = 3 & XmmReg1 & XmmReg2 { XmmReg1=psignd(XmmReg1,XmmReg2); } - # MAAT: simplify PSLLDQ semantics for XMM regs (Ghidra semantics commented below) :PSLLDQ XmmReg2, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0x73; xmmmod = 3 & reg_opcode=7 & XmmReg2; imm8 { @@ -7969,7 +7959,7 @@ define pcodeop rsqrtss; :RSQRTSS XmmReg, m32 is vexMode=0 & $(PRE_F3) & byte=0x0F; byte=0x52; XmmReg ... & m32 { XmmReg = rsqrtss(XmmReg, m32); } :RSQRTSS XmmReg1, XmmReg2 is vexMode=0 & $(PRE_F3) & byte=0x0F; byte=0x52; xmmmod = 3 & XmmReg1 & XmmReg2 { XmmReg1 = rsqrtss(XmmReg1, XmmReg2); } -# MAAT: add SHUFPD spec +# MAAT: add SHUFPD spec (upstream implementation commented below) :SHUFPD XmmReg, m128, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0xC6; XmmReg ... & m128; imm8 { shifted:16 = XmmReg >> ((imm8 & 0x1)*64); @@ -7994,44 +7984,44 @@ define pcodeop rsqrtss; XmmReg1[64, 64] = tempB; } +#define pcodeop shufpd; +#:SHUFPD XmmReg, m128, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0xC6; XmmReg ... & m128; imm8 { XmmReg = shufpd(XmmReg, m128, imm8:8); } +#:SHUFPD XmmReg1, XmmReg2, imm8 is vexMode=0 & $(PRE_66) & byte=0x0F; byte=0xC6; xmmmod=3 & XmmReg1 & XmmReg2; imm8 { XmmReg1 = shufpd(XmmReg1, XmmReg2, imm8:8); } + :SHUFPS XmmReg, m128, imm8 is vexMode=0 & mandover=0 & byte=0x0F; byte=0xC6; (m128 & XmmReg ...); imm8 & Order0 & Order1 & Order2 & Order3 { - shifted:16 = XmmReg >> Order0; - tempA:4 = shifted:4; - - shifted = XmmReg >> Order1; - tempB:4 = shifted:4; - - shifted = m128 >> Order2; - tempC:4 = shifted:4; + local m128_c0 = m128[0,32]; + local m128_c1 = m128[32,32]; + local m128_c2 = m128[64,32]; + local m128_c3 = m128[96,32]; - shifted = m128 >> Order3; - tempD:4 = shifted:4; + local xmm_c0 = XmmReg[0,32]; + local xmm_c1 = XmmReg[32,32]; + local xmm_c2 = XmmReg[64,32]; + local xmm_c3 = XmmReg[96,32]; - XmmReg[0,32] = tempA; - XmmReg[32,32] = tempB; - XmmReg[64,32] = tempC; - XmmReg[96,32] = tempD; + shuffle_4(XmmReg[0,32],Order0,xmm_c0,xmm_c1,xmm_c2,xmm_c3); + shuffle_4(XmmReg[32,32],Order1,xmm_c0,xmm_c1,xmm_c2,xmm_c3); + shuffle_4(XmmReg[64,32],Order2,m128_c0,m128_c1,m128_c2,m128_c3); + shuffle_4(XmmReg[96,32],Order3,m128_c0,m128_c1,m128_c2,m128_c3); } :SHUFPS XmmReg1, XmmReg2, imm8 is vexMode=0 & mandover=0 & byte=0x0F; byte=0xC6; xmmmod=3 & XmmReg1 & XmmReg2; imm8 & Order0 & Order1 & Order2 & Order3 { - shifted:16 = XmmReg1 >> Order0; - tempA:4 = shifted:4; - - shifted = XmmReg1 >> Order1; - tempB:4 = shifted:4; + local xmm1_c0 = XmmReg1[0,32]; + local xmm1_c1 = XmmReg1[32,32]; + local xmm1_c2 = XmmReg1[64,32]; + local xmm1_c3 = XmmReg1[96,32]; - shifted = XmmReg2 >> Order2; - tempC:4 = shifted:4; + local xmm2_c0 = XmmReg2[0,32]; + local xmm2_c1 = XmmReg2[32,32]; + local xmm2_c2 = XmmReg2[64,32]; + local xmm2_c3 = XmmReg2[96,32]; - shifted = XmmReg2 >> Order3; - tempD:4 = shifted:4; - - XmmReg1[0,32] = tempA; - XmmReg1[32,32] = tempB; - XmmReg1[64,32] = tempC; - XmmReg1[96,32] = tempD; + shuffle_4(XmmReg1[0,32],Order0,xmm1_c0,xmm1_c1,xmm1_c2,xmm1_c3); + shuffle_4(XmmReg1[32,32],Order1,xmm1_c0,xmm1_c1,xmm1_c2,xmm1_c3); + shuffle_4(XmmReg1[64,32],Order2,xmm2_c0,xmm2_c1,xmm2_c2,xmm2_c3); + shuffle_4(XmmReg1[96,32],Order3,xmm2_c0,xmm2_c1,xmm2_c2,xmm2_c3); } define pcodeop sqrtpd; diff --git a/src/third-party/sleigh/processors/x86/data/languages/x86-64.slaspec b/src/third-party/sleigh/processors/x86/data/languages/x86-64.slaspec index 4b1ccf97..9a04c5bd 100644 --- a/src/third-party/sleigh/processors/x86/data/languages/x86-64.slaspec +++ b/src/third-party/sleigh/processors/x86/data/languages/x86-64.slaspec @@ -17,3 +17,4 @@ @include "smx.sinc" @include "cet.sinc" @include "fma.sinc" + diff --git a/src/third-party/sleigh/processors/x86/data/languages/x86.ldefs b/src/third-party/sleigh/processors/x86/data/languages/x86.ldefs index 5e5dbc84..2556a1f2 100644 --- a/src/third-party/sleigh/processors/x86/data/languages/x86.ldefs +++ b/src/third-party/sleigh/processors/x86/data/languages/x86.ldefs @@ -91,6 +91,7 @@ + diff --git a/src/third-party/sleigh/processors/x86/data/languages/x86.slaspec b/src/third-party/sleigh/processors/x86/data/languages/x86.slaspec index 8a4bbee1..65183e39 100644 --- a/src/third-party/sleigh/processors/x86/data/languages/x86.slaspec +++ b/src/third-party/sleigh/processors/x86/data/languages/x86.slaspec @@ -14,3 +14,4 @@ @include "smx.sinc" @include "cet.sinc" @include "rdrand.sinc" + diff --git a/src/third-party/sleigh/processors/x86/data/patterns/prepatternconstraints.xml b/src/third-party/sleigh/processors/x86/data/patterns/prepatternconstraints.xml new file mode 100644 index 00000000..ea92c2ab --- /dev/null +++ b/src/third-party/sleigh/processors/x86/data/patterns/prepatternconstraints.xml @@ -0,0 +1,12 @@ + + + + + x86win_prepatterns.xml + + + x86win_prepatterns.xml + + + + diff --git a/src/third-party/sleigh/processors/x86/data/patterns/x86-64gcc_patterns.xml b/src/third-party/sleigh/processors/x86/data/patterns/x86-64gcc_patterns.xml index 98ff3ad6..2daa852e 100644 --- a/src/third-party/sleigh/processors/x86/data/patterns/x86-64gcc_patterns.xml +++ b/src/third-party/sleigh/processors/x86/data/patterns/x86-64gcc_patterns.xml @@ -11,11 +11,8 @@ 0xeb..90 0x5d 0xc3 0x5b 0xc3 - 0x415f 0xc3 - 0x415c 0xc3 + 0x41 010111.. 0xc3 0x31c0 0xc3 - 0x415d 0xc3 - 0x415e 0xc3 0x4883c4 ....1000 0xc3 0x666690 0x0f1f00 @@ -36,37 +33,114 @@ 0x534889fb 0x554889fd 0x534889fb + 0x53 0x48 0x83 0xec 0....000 + 0x53 0x48 0x81 0xec .....000 00...... 0x00 - 0x55 0x48 0x89 0xe5 0x48 0x83 0xec 0...0000 + 0x55 0x48 0x89 0xe5 0x48 100000.1 0xec .....000 0x554889e553 0x554889fd53 0x554889e548897df8 0x53 0x48 0x89 0xfb 0xe8 ........ ........ 0xff 0xff + 0x4154 0x55 0100100. 0x89 11...... + 0x4154 0x55 0x53 0100100. 0x89 11...... + 0x415741564155 - 0x41544989fc55 + 0x41564155 + 0x41554154 + 0x41 010101.. 0100100. 0x89 11...... 0x55 + 0x41 010101.. 0x41 010101.. 0100100. 0x89 11...... 0x5589e5 - + + + + + 0x55 0x53 0100100. 0x89 11...... + + + + + 0x4154 0x55 0100100. 0x89 11...... + + + + + 0x4154 0x55 0x53 0100100. 0x89 11...... + + + + + 0x53 0x48 0x83 0xec 0....000 + + + + + 0x48 0x83 0xec .....000 + + + + + 0x48 0x81 0xec .....000 00...... 0x00 + + + + + 0x55 0x53 0x48 0x83 100000.1 0xec .....000 + 0x554889e5 - + - 0x55 0x48 0x89 0xe5 0x48 0x83 0xec 0...0000 - + 0x55 0x48 0x89 0xe5 0x48 100000.1 0xec .....000 + 0x554889e553 - + - + + 0x4157 0x4156 0x4155 + + + + + 0x4157 0x4156 + + + + + 0x4156 0x4155 + + + + + 0x41554154 + + + + + 0x41 010101.. 0100100. 0x89 11...... 0x55 + + + + + 0x41 010101.. 0x41 010101.. 0100100. 0x89 11...... + + + + + 0x41 010101.. 0x41 010101.. 0100100. 0x89 11...... + + + diff --git a/src/third-party/sleigh/processors/x86/data/patterns/x86gcc_patterns.xml b/src/third-party/sleigh/processors/x86/data/patterns/x86gcc_patterns.xml index a8f1e034..89885e5a 100644 --- a/src/third-party/sleigh/processors/x86/data/patterns/x86gcc_patterns.xml +++ b/src/third-party/sleigh/processors/x86/data/patterns/x86gcc_patterns.xml @@ -30,7 +30,41 @@ + + 0x83 0xec 0.....00 100010.1 01...100 ..100100 0.....00 + + + + + 0x81 0xec ......00 0000.... 0x00 0x00 100010.1 01...100 ..100100 0.....00 + + + + + 0x5. 0x83 0xec 0.....00 100010.1 01...100 ..100100 0.....00 + + + + + 0x5. 0x81 0xec ......00 0000.... 0x00 0x00 + + + + + 0x5. 0x5. 100000.1 0xec ......00 + + + + + 0x5. 0x5. 0x5. 100000.1 0xec ......00 + + + + 0x5. 0x5. 0x5. 0x5. 100000.1 0xec ......00 + + + 0x8b 0x04 0x24 0xc3 diff --git a/src/third-party/sleigh/processors/x86/data/patterns/x86win_patterns.xml b/src/third-party/sleigh/processors/x86/data/patterns/x86win_patterns.xml index dbb07c06..4c4b59e7 100644 --- a/src/third-party/sleigh/processors/x86/data/patterns/x86win_patterns.xml +++ b/src/third-party/sleigh/processors/x86/data/patterns/x86win_patterns.xml @@ -103,41 +103,7 @@ 0x518d4c24082bc883e10703c11bc90bc159e9........ - - - - 0x8bff - 0x55 - 0x8bec - 0x83ec20 - 0x8b4508 - 0x56 - 0x57 - 0x6a08 - 0x59 - 0xbe........ - 0x8d7de0 - 0xf3a5 - 0x8945f8 - 0x8b450c - 0x5f - 0x8945fc - 0x5e - 0x85c0 - 0x740c - 0xf60008 - 0x7407 - 0xc745f4........ - 0x8d45f4 - 0x50 - 0xff75f0 - 0xff75e4 - 0xff75e0 - 0xff15........ - 0xc9 - 0xc20800 - - + diff --git a/src/third-party/sleigh/processors/x86/data/patterns/x86win_prepatterns.xml b/src/third-party/sleigh/processors/x86/data/patterns/x86win_prepatterns.xml new file mode 100644 index 00000000..7e3ecbaf --- /dev/null +++ b/src/third-party/sleigh/processors/x86/data/patterns/x86win_prepatterns.xml @@ -0,0 +1,38 @@ + + + + + 0x8bff + 0x55 + 0x8bec + 0x83ec20 + 0x8b4508 + 0x56 + 0x57 + 0x6a08 + 0x59 + 0xbe........ + 0x8d7de0 + 0xf3a5 + 0x8945f8 + 0x8b450c + 0x5f + 0x8945fc + 0x5e + 0x85c0 + 0x740c + 0xf60008 + 0x7407 + 0xc745f4........ + 0x8d45f4 + 0x50 + 0xff75f0 + 0xff75e4 + 0xff75e0 + 0xff15........ + 0xc9 + 0xc20800 + + + + diff --git a/src/third-party/sleigh/sleigh-cmake b/src/third-party/sleigh/sleigh-cmake index 759fe7ff..c3564b1e 160000 --- a/src/third-party/sleigh/sleigh-cmake +++ b/src/third-party/sleigh/sleigh-cmake @@ -1 +1 @@ -Subproject commit 759fe7ff76fcd3fbafa0a7ce38a824c19ae80aca +Subproject commit c3564b1e3e3e5ab37dc318f812b5412b15af8205 diff --git a/tests/python-tests/.gitignore b/tests/python-tests/.gitignore new file mode 100644 index 00000000..ebff9993 --- /dev/null +++ b/tests/python-tests/.gitignore @@ -0,0 +1,2 @@ +/.z3-trace +/maat_state_* diff --git a/tests/unit-tests/test_archX86.cpp b/tests/unit-tests/test_archX86.cpp index 41514a6e..478b9a46 100644 --- a/tests/unit-tests/test_archX86.cpp +++ b/tests/unit-tests/test_archX86.cpp @@ -6388,7 +6388,7 @@ namespace test sym.cpu.ctx().set(X86::EAX, exprcst(32, 0x1900)); sym.mem->write(0x1900, 0xab001200abababab, 8); sym.run_from(0x1050, 1); - nb += _assert( sym.cpu.ctx().get(X86::MM0).as_uint() == 0xababababdeadbeef, "ArchX86: failed to disassembly and/or execute PUNPCKHDQ"); + nb += _assert( sym.cpu.ctx().get(X86::MM0).as_uint() == 0xab001200deadbeef, "ArchX86: failed to disassembly and/or execute PUNPCKHDQ"); return nb; } @@ -9223,7 +9223,7 @@ void test_archX86(){ total += disass_pcmpgtd(engine); // total += disass_pextrb(engine); total += disass_pminub(engine); - // total += disass_pmovmskb(engine); + total += disass_pmovmskb(engine); total += disass_pop(engine); total += disass_popad(engine); total += disass_por(engine); @@ -9233,7 +9233,7 @@ void test_archX86(){ // TODO - ghidra bug: total += disass_psllq(engine); total += disass_psubb(engine); total += disass_punpckhdq(engine); - // TODO - ghidra bug: total += disass_punpckhqdq(engine); + total += disass_punpckhqdq(engine); total += disass_punpcklbw(engine); total += disass_punpckldq(engine); total += disass_punpcklqdq(engine); diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..dea52dc7 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,15 @@ +{ + "dependencies": [ + "gmp", + "lief", + "sleigh", + "z3", + { + "name": "sleigh-speccompiler", + "host": true + } + ], + "vcpkg-configuration": { + "overlay-ports": [ "./ports" ] + } +}