Skip to content

Commit

Permalink
Merge branch 'JonathanSalwan:master' into aarch64/fp_operand_support
Browse files Browse the repository at this point in the history
  • Loading branch information
psi-func authored Sep 2, 2024
2 parents 33c15fd + 0648bb9 commit 7b5ba58
Show file tree
Hide file tree
Showing 56 changed files with 10,736 additions and 230 deletions.
119 changes: 0 additions & 119 deletions .appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .build_number
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1591
1595
31 changes: 9 additions & 22 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ jobs:
os:
- macOS-latest
- ubuntu-20.04
# FIXME
#- windows-2022
- windows-2022
include:
#- os: windows-2022
# platform: windows
# vcpkg-triplet: x64-windows-static-release-md
# cmake-preset: windows-x64
# capstone-library: capstone.lib
# python-executable: python
- os: windows-2022
platform: windows
vcpkg-triplet: x64-windows-static-release-md
cmake-preset: windows-x64
python-executable: python
- os: ubuntu-20.04
platform: linux
vcpkg-triplet: x64-linux-release
cmake-preset: linux-x64
capstone-library: libcapstone.a
python-executable: python3
- os: macOS-latest
platform: macos
vcpkg-triplet: x64-osx-release
cmake-preset: macos-x64
capstone-library: libcapstone.a
python-executable: python3

steps:
Expand All @@ -42,15 +38,14 @@ jobs:
name: Get vcpkg
with:
repository: 'microsoft/vcpkg'
ref: '2022.04.12'
ref: '2024.05.24'
path: '${{ github.workspace }}/_vcpkg'
fetch-depth: 0

- uses: lukka/get-cmake@latest
name: Get CMake

- name: Set up Python 3.11
if: ${{ matrix.platform == 'macos' }}
uses: actions/setup-python@v4
with:
python-version: '3.11'
Expand All @@ -66,9 +61,6 @@ jobs:
run: |
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}\vcpkg\triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
env:
# capstone 4.0.2 does not produce a CMake Config, hence the need to point directly to include directories and libraries
CAPSTONE_INCLUDE_DIRS: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/include
CAPSTONE_LIBRARIES: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/lib/${{ matrix.capstone-library }}
VCPKG_ROOT: ${{ github.workspace }}/_vcpkg
VCPKG_FEATURE_FLAGS: manifests,versions,binarycaching,registries

Expand All @@ -78,9 +70,6 @@ jobs:
python -m pip install importlib-resources
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}/vcpkg/triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
env:
# capstone 4.0.2 does not produce a CMake Config, hence the need to point directly to include directories and libraries
CAPSTONE_INCLUDE_DIRS: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/include
CAPSTONE_LIBRARIES: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/lib/${{ matrix.capstone-library }}
VCPKG_ROOT: ${{ github.workspace }}/_vcpkg
VCPKG_FEATURE_FLAGS: manifests,versions,binarycaching,registries

Expand All @@ -89,11 +78,9 @@ jobs:
cmake --build --preset build-${{ matrix.cmake-preset }} --config Release
- name: Test
# Test disabled on Windows `pip install lief` fails as there is no ready to use .whl and compilation fails
# Test disabled on macOS `pip install lief` fails as there is no ready to use .whl and compilation fails
if: ${{ (matrix.platform != 'windows') && (matrix.platform != 'macos') }}
run: |
${{ matrix.python-executable }} -m pip install lief==0.10.1 unicorn==2.0.0 z3-solver
${{ matrix.python-executable }} --version
${{ matrix.python-executable }} -m pip install lief==0.15.1 unicorn==2.0.1.post1 z3-solver
ctest --preset test-${{ matrix.cmake-preset }} -C Release --output-on-failure
- name: Install
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ option(GCOV "Enable code coverage"
option(LLVM_INTERFACE "Use LLVM for lifting" OFF)
option(MSVC_STATIC "Use statically-linked runtime library" OFF)
option(Z3_INTERFACE "Use Z3 as SMT solver" ON)
option(BOOST_INTERFACE "Use Boost as multiprecision library" ON)
option(BOOST_INTERFACE "Use Boost as multiprecision library" OFF)
option(PYTHON_BINDINGS_AUTOCOMPLETE "Generate an autocomplete stub file" OFF)

# Define cmake dependent options
Expand All @@ -48,11 +48,18 @@ if(PYTHON_BINDINGS)
message(STATUS "Compiling with Python bindings")

if(NOT PYTHON_VERSION AND NOT PYTHON_EXECUTABLE)
# On Windows, python3 points to the Windows Store version of Python.
# Installations from the Python website do not contain python3.exe
if(WIN32)
set(PYTHON_NAMES python python3)
else()
set(PYTHON_NAMES python3 python)
endif()
# Find the python version the user has in the PATH
# This prevents an issue where an unexpected python version is used
# (eg the system/homebrew python in a virtual environment)
find_program(PYTHON_EXECUTABLE
NAMES python3 python
NAMES ${PYTHON_NAMES}
NO_PACKAGE_ROOT_PATH
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ COPY . /Triton
# cmake >= 3.20
RUN apt update && apt upgrade -y && apt install -y build-essential clang curl git libboost-all-dev libgmp-dev libpython3-dev libpython3-stdlib llvm-12 llvm-12-dev python3-pip tar ninja-build pkg-config && apt-get clean && pip install --upgrade pip && pip3 install Cython lief cmake meson

# libcapstone >= 4.0.x
# libcapstone >= 5.0.x
RUN cd /tmp && \
curl -o cap.tgz -L https://github.com/aquynh/capstone/archive/5.0.1.tar.gz && \
tar xvf cap.tgz && cd capstone-5.0.1/ && ./make.sh && make install && rm -rf /tmp/cap* \
tar xvf cap.tgz && cd capstone-5.0.1/ && CAPSTONE_ARCHS="arm aarch64 riscv x86" ./make.sh && \
make install && rm -rf /tmp/cap* \
&& ln -s /usr/lib/libcapstone.so.5 /usr/lib/x86_64-linux-gnu/libcapstone.so

# libbitwuzla >= 0.4.0
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ automate reverse engineering, perform software verification or just emulate code

* Dynamic **symbolic** execution
* Dynamic **taint** analysis
* AST representation of the **x86**, **x86-64**, **ARM32** and **AArch64** ISA semantic
* AST representation of the **x86**, **x86-64**, **ARM32**, **AArch64** and **RISC-V 32/64** ISA semantic
* Expressions **synthesis**
* SMT **simplification** passes
* **Lifting** to **LLVM** as well as **Z3** and back
Expand All @@ -30,8 +30,8 @@ As **Triton** is a kind of a part-time project, please, **don't blame us** if it
<img src="https://img.shields.io/github/actions/workflow/status/JonathanSalwan/Triton/osx.yml?branch=master&label=OSX&logo=apple">
</a>
&nbsp;
<a href="https://ci.appveyor.com/project/JonathanSalwan/triton">
<img src="https://img.shields.io/appveyor/ci/JonathanSalwan/triton/master.svg?label=Windows&logo=windows">
<a href="https://github.com/JonathanSalwan/Triton/actions/workflows/vcpkg.yml/">
<img src="https://img.shields.io/github/actions/workflow/status/JonathanSalwan/Triton/vcpkg.yml?branch=master&label=Windows&logo=windows&logoColor=white">
</a>
&nbsp;
<a href="https://codecov.io/gh/JonathanSalwan/Triton">
Expand Down Expand Up @@ -97,7 +97,7 @@ from triton import *
Triton relies on the following dependencies:

```
* libcapstone >= 4.0.x https://github.com/capstone-engine/capstone
* libcapstone >= 5.0.x https://github.com/capstone-engine/capstone
* libboost (optional) >= 1.68
* libpython (optional) >= 3.6
* libz3 (optional) >= 4.6.0 https://github.com/Z3Prover/z3
Expand Down Expand Up @@ -164,8 +164,8 @@ You can use cmake to generate the .sln file of libTriton.
-DPYTHON_LIBRARIES="C:/Python36/libs/python36.lib" \
-DZ3_INCLUDE_DIRS="C:/Users/jonathan/Works/Tools/z3-4.6.0-x64-win/include" \
-DZ3_LIBRARIES="C:/Users/jonathan/Works/Tools/z3-4.6.0-x64-win/bin/libz3.lib" \
-DCAPSTONE_INCLUDE_DIRS="C:/Users/jonathan/Works/Tools/capstone-4.0.2-win64/include" \
-DCAPSTONE_LIBRARIES="C:/Users/jonathan/Works/Tools/capstone-4.0.2-win64/capstone.lib" ..
-DCAPSTONE_INCLUDE_DIRS="C:/Users/jonathan/Works/Tools/capstone-5.0.1-win64/include" \
-DCAPSTONE_LIBRARIES="C:/Users/jonathan/Works/Tools/capstone-5.0.1-win64/capstone.lib" ..
```

However, if you prefer to directly download the precompiled library, check out our AppVeyor's [artefacts](https://ci.appveyor.com/project/JonathanSalwan/triton/history).
Expand Down
16 changes: 16 additions & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,25 @@ add_custom_target(gen_arm32_doc_from_spec
DEPENDS ${TRITON_ROOT}/src/libtriton/includes/triton/arm32.spec
)

add_custom_target(gen_rv64_doc_from_spec
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/extract_doc.py ${TRITON_ROOT}/src/libtriton/includes/triton/riscv64.spec "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/extract_doc.py
DEPENDS ${TRITON_ROOT}/src/libtriton/includes/triton/riscv64.spec
)

add_custom_target(gen_rv32_doc_from_spec
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/extract_doc.py ${TRITON_ROOT}/src/libtriton/includes/triton/riscv32.spec "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/extract_doc.py
DEPENDS ${TRITON_ROOT}/src/libtriton/includes/triton/riscv32.spec
)

add_custom_target(doc
COMMAND doxygen ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
DEPENDS gen_x86_doc_from_spec
DEPENDS gen_aarch64_doc_from_spec
DEPENDS gen_arm32_doc_from_spec
DEPENDS gen_rv64_doc_from_spec
DEPENDS gen_rv32_doc_from_spec
)

if(PYTHON_BINDINGS_AUTOCOMPLETE)
Expand All @@ -37,6 +51,8 @@ if(PYTHON_BINDINGS_AUTOCOMPLETE)
DEPENDS gen_x86_doc_from_spec
DEPENDS gen_aarch64_doc_from_spec
DEPENDS gen_arm32_doc_from_spec
DEPENDS gen_rv64_doc_from_spec
DEPENDS gen_rv32_doc_from_spec
)
if (NOT DEFINED PYTHON_SITE_PACKAGES)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from sysconfig import get_path; print(get_path('platlib'))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down
32 changes: 32 additions & 0 deletions doc/extract_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
x86_regs = list()
aarch64_regs = list()
arm32_regs = list()
rv64_regs = list()
rv32_regs = list()

##############################################################################

Expand Down Expand Up @@ -58,3 +60,33 @@
for name in arm32_regs:
out.write("<li><b>REG.ARM32.{}</b></li>\n".format(name))
out.write('</ul>\n')

##############################################################################

elif SPEC.find('riscv64') >= 0:
with open(SPEC, "r") as f:
for line in f.readlines():
if line.startswith("REG_SPEC") or line.startswith("SYS_REG_SPEC"):
args = line[line.find("(") + 1: line.find(")")].split(", ")
rv64_regs.append(args[1])

with open(os.path.join(BUILD_DIR, "rv64_reg"), "w") as out:
out.write('<ul>\n')
for name in rv64_regs:
out.write("<li><b>REG.RISCV64.{}</b></li>\n".format(name))
out.write('</ul>\n')

##############################################################################

elif SPEC.find('riscv32') >= 0:
with open(SPEC, "r") as f:
for line in f.readlines():
if line.startswith("REG_SPEC") or line.startswith("SYS_REG_SPEC"):
args = line[line.find("(") + 1: line.find(")")].split(", ")
rv32_regs.append(args[1])

with open(os.path.join(BUILD_DIR, "rv32_reg"), "w") as out:
out.write('<ul>\n')
for name in rv32_regs:
out.write("<li><b>REG.RISCV32.{}</b></li>\n".format(name))
out.write('</ul>\n')
Binary file not shown.
Loading

0 comments on commit 7b5ba58

Please sign in to comment.