From a34d106338e8fcda553b3bcb8242418f07dd5620 Mon Sep 17 00:00:00 2001 From: Jex Amro Date: Wed, 19 Nov 2025 15:51:23 -0500 Subject: [PATCH 01/15] Fix AST optimizations incorrectly eliminating symbolic expressions Three optimizations (A^A=0, A|A=A, A-A=0) were using equalTo() to detect identical operands. However, equalTo() compares concrete values rather than AST structure, causing different symbolic expressions with the same concrete value to be incorrectly identified as equal. This caused the optimizer to eliminate symbolic information: - bvxor: A^A=0 replaced symbolic XOR with concrete 0 - bvsub: A-A=0 replaced symbolic SUB with concrete 0 - bvor: A|A=A returned one operand, losing the other's dependency Example: In AArch64 cfSub_s(), the carry flag computation would lose symbolic status when symbolic operands evaluated to 0, breaking conditional branch symbolization (e.g., b.lo not recognized as symbolic). The fix adds isSymbolized() checks to ensure these optimizations only apply when both operands are concrete, preserving symbolic information. Note: bvand already had the correct check; this fix makes bvor, bvsub, and bvxor consistent with that pattern. --- src/libtriton/ast/astContext.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libtriton/ast/astContext.cpp b/src/libtriton/ast/astContext.cpp index 9915cecc..3e889799 100644 --- a/src/libtriton/ast/astContext.cpp +++ b/src/libtriton/ast/astContext.cpp @@ -353,7 +353,9 @@ namespace triton { return this->bv(expr2->getBitvectorMask(), expr2->getBitvectorSize()); /* Optimization: A | A = A */ - if (expr1->equalTo(expr2)) + /* Only apply when both operands are concrete. Two different symbolic expressions + * may evaluate to the same value but represent distinct computations. */ + if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2)) return expr1; } @@ -603,7 +605,9 @@ namespace triton { return this->bvneg(expr2); /* Optimization: A - A = 0 */ - if (expr1->equalTo(expr2)) + /* Only apply when both operands are concrete to preserve symbolic information. + * Different symbolic expressions may evaluate equal but must remain distinct. */ + if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2)) return this->bv(0, expr1->getBitvectorSize()); } @@ -732,7 +736,10 @@ namespace triton { return expr2; /* Optimization: A ^ A = 0 */ - if (expr1->equalTo(expr2)) + /* Only apply when both operands are concrete to avoid losing symbolic information. + * Two different symbolic expressions may have the same concrete value temporarily, + * but they represent different symbolic computations that must be preserved. */ + if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2)) return this->bv(0, expr1->getBitvectorSize()); } From ede0580d704bb02aa20b418b72c2ee05119f5449 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 12:57:42 +0000 Subject: [PATCH 02/15] Add Windows build method --- setup.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 1694b351..5e17f74c 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,9 @@ VERSION_PATCH = 0 RELEASE_CANDIDATE = 4 +BUILDTOOLS = "vs2022" # clang or clang_cl or vs2022 +CMAKE_BUILD_TYPE = "Release" # release or debug + VERSION = f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}' + \ f'rc{RELEASE_CANDIDATE}' if RELEASE_CANDIDATE else '' @@ -59,7 +62,7 @@ class CMakeBuild(build_ext): cmake_args = [ # General arguments. '-DPYTHON_EXECUTABLE=' + sys.executable, - '-DCMAKE_BUILD_TYPE=Release', + '-DCMAKE_BUILD_TYPE='+ CMAKE_BUILD_TYPE, ] # Interfaces can be defined using environment variables. @@ -89,11 +92,27 @@ class CMakeBuild(build_ext): build_args += ['--', '-j4'] elif platform.system() == "Windows": - cmake_args += [ - '-G Visual Studio 17 2022', - ] - build_args += ['--', '/m:4'] - + if BUILDTOOLS == "vs2022": + cmake_args += [ + "-G Visual Studio 17 2022", + ] + build_args += ["--", "/m:4"] + else: + assert os.getenv('COMPILER_DIR'), "COMPILER_DIR(clang or clang_cl) env not found" + if BUILDTOOLS == "clang": + cmake_args += [ + "-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "clang.exe", + "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "clang++.exe", + "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "llvm-rc.exe", + "-G Ninja", + ] + if BUILDTOOLS == "clang_cl": + cmake_args += [ + "-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "clang-cl.exe", + "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "clang-cl.exe", + "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "llvm-rc.exe", + "-G Ninja", + ] else: raise Exception(f'Platform not supported: {platform.system()}') @@ -155,11 +174,11 @@ class CMakeBuild(build_ext): os.makedirs(self.build_lib) subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) - subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python-triton'] + build_args, cwd=self.build_temp) + subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python-triton'] + build_args, cwd=self.build_temp) # The autocomplete file has to be built separately. if (is_cmake_true(python_autocomplete_value)): - subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python_autocomplete'], cwd=self.build_temp) + subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python_autocomplete'], cwd=self.build_temp) def copy_extension_to_source(self, ext): fullname = self.get_ext_fullname(ext.name) @@ -172,7 +191,7 @@ class CMakeBuild(build_ext): src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) elif platform.system() == "Windows": - src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\Release', 'triton.pyd') + src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\'+ CMAKE_BUILD_TYPE, 'triton.pyd') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) else: raise Exception(f'Platform not supported: {platform.system()}') From 6020e8e6eea90928da30355f4e77a542a9776862 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 13:38:37 +0000 Subject: [PATCH 03/15] add deps --- .github/workflows/codecov.yml | 2 +- .github/workflows/linux.yml | 2 +- Dockerfile | 3 ++- src/scripts/docker/Dockerfile | 10 +++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 1eeb76a2..74e68313 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -23,7 +23,7 @@ jobs: - name: Install dependencies run: | - sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev + sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev libmpfr-dev - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v2 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index ed39c95e..7b430403 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | - sudo apt-get install python3-setuptools libboost-dev libgmp-dev + sudo apt-get install python3-setuptools libboost-dev libgmp-dev libmpfr-dev - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v2 diff --git a/Dockerfile b/Dockerfile index fb16e2f0..80cc7375 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,8 @@ RUN DEBIAN_FRONTEND="noninteractive" \ pkg-config \ python3-pip \ python3-venv \ - tar && \ + tar \ + libmpfr-dev && \ apt clean ENV VIRTUAL_ENV=/Triton-venv diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index f71ea8d8..ac3da797 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -9,7 +9,7 @@ RUN yum install -y \ less \ ninja-build \ sudo \ - wget + wget \ # LLVM dependencies. RUN yum install -y \ @@ -25,6 +25,14 @@ ENV SOURCE_DIR=/src # Create directory for dependencies. RUN mkdir -p $DEPENDENCIES_DIR +# Download, build and install GMP. +RUN curl -LO https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz && \ + tar xf gmp-6.3.0.tar.xz && \ + cd gmp-6.3.0 && \ + ./configure --prefix=/usr/local/gmp --disable-assembly && \ + make -j$(nproc) && \ + make install + # Download, build and install Bitwuzla. RUN echo "[+] Download, build and install Bitwuzla" && \ cd $DEPENDENCIES_DIR && \ From 1ffbeb7440311838c3b8460b6b6bfa12d2b184ff Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 13:52:50 +0000 Subject: [PATCH 04/15] delete \ --- src/scripts/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index ac3da797..c2319548 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -9,7 +9,7 @@ RUN yum install -y \ less \ ninja-build \ sudo \ - wget \ + wget # LLVM dependencies. RUN yum install -y \ From fbc1b3e32e7e3e58d4481e53b879b834e3993bb5 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 13:55:35 +0000 Subject: [PATCH 05/15] update dockerfile with quay.io/pypa/manylinux_2_34_x86_64 --- src/scripts/docker/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index c2319548..6c34d8b0 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -26,7 +26,9 @@ ENV SOURCE_DIR=/src RUN mkdir -p $DEPENDENCIES_DIR # Download, build and install GMP. -RUN curl -LO https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz && \ +RUN echo "[+] Download, build and install GMP" && \ + cd $DEPENDENCIES_DIR && \ + curl -LO https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz && \ tar xf gmp-6.3.0.tar.xz && \ cd gmp-6.3.0 && \ ./configure --prefix=/usr/local/gmp --disable-assembly && \ From afa0945993366e540aa93a49381573c2285c3cea Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 14:04:40 +0000 Subject: [PATCH 06/15] update dockerfile --- src/scripts/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index 6c34d8b0..be95c68b 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -28,7 +28,7 @@ RUN mkdir -p $DEPENDENCIES_DIR # Download, build and install GMP. RUN echo "[+] Download, build and install GMP" && \ cd $DEPENDENCIES_DIR && \ - curl -LO https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz && \ + curl -LO https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz && \ tar xf gmp-6.3.0.tar.xz && \ cd gmp-6.3.0 && \ ./configure --prefix=/usr/local/gmp --disable-assembly && \ From 697c7acbd11b66c7c5b0e954e6d4ac2e13f7efd4 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Sun, 30 Nov 2025 15:03:48 +0000 Subject: [PATCH 07/15] mpfr --- src/scripts/docker/Dockerfile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index be95c68b..000ba989 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -17,6 +17,13 @@ RUN yum install -y \ libzstd-devel \ ncurses-devel +ENV VIRTUAL_ENV=/Triton-venv +RUN python3.10 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +RUN . $VIRTUAL_ENV/bin/activate && \ + pip install --upgrade pip + RUN python3.10 -m pip install meson ENV DEPENDENCIES_DIR=/tmp/triton-dependencies @@ -31,10 +38,21 @@ RUN echo "[+] Download, build and install GMP" && \ curl -LO https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz && \ tar xf gmp-6.3.0.tar.xz && \ cd gmp-6.3.0 && \ - ./configure --prefix=/usr/local/gmp --disable-assembly && \ + ./configure --prefix=/usr/local/gmp --disable-assembly --enable-cxx && \ make -j$(nproc) && \ make install + +RUN echo "[+] Download, build and install mpfr" && \ + cd $DEPENDENCIES_DIR && \ + curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz \ + && tar xf mpfr-4.2.1.tar.xz \ + && cd mpfr-4.2.1 \ + && ./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp \ + && make -j$(nproc) && make install + +ENV PKG_CONFIG_PATH=/usr/local/gmp/lib/pkgconfig:/usr/local/mpfr/lib/pkgconfig:$PKG_CONFIG_PATH + # Download, build and install Bitwuzla. RUN echo "[+] Download, build and install Bitwuzla" && \ cd $DEPENDENCIES_DIR && \ From 93e1f96f32975d742c3b729872cc118d64d1a71d Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 01:30:20 +0000 Subject: [PATCH 08/15] update dockerfile --- src/scripts/docker/Dockerfile | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/scripts/docker/Dockerfile b/src/scripts/docker/Dockerfile index 000ba989..7c9711dd 100644 --- a/src/scripts/docker/Dockerfile +++ b/src/scripts/docker/Dockerfile @@ -38,21 +38,19 @@ RUN echo "[+] Download, build and install GMP" && \ curl -LO https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz && \ tar xf gmp-6.3.0.tar.xz && \ cd gmp-6.3.0 && \ - ./configure --prefix=/usr/local/gmp --disable-assembly --enable-cxx && \ + ./configure --disable-assembly --enable-cxx && \ make -j$(nproc) && \ make install RUN echo "[+] Download, build and install mpfr" && \ cd $DEPENDENCIES_DIR && \ - curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz \ - && tar xf mpfr-4.2.1.tar.xz \ - && cd mpfr-4.2.1 \ - && ./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp \ - && make -j$(nproc) && make install - -ENV PKG_CONFIG_PATH=/usr/local/gmp/lib/pkgconfig:/usr/local/mpfr/lib/pkgconfig:$PKG_CONFIG_PATH - + curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz && \ + tar xf mpfr-4.2.1.tar.xz && \ + cd mpfr-4.2.1 && \ + ./configure && \ + make -j$(nproc) && make install + # Download, build and install Bitwuzla. RUN echo "[+] Download, build and install Bitwuzla" && \ cd $DEPENDENCIES_DIR && \ From 1787f69129bb48f5a25d72d3d1f9f60879e3ad0f Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 02:04:01 +0000 Subject: [PATCH 09/15] update setup.py --- setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.py b/setup.py index 5e17f74c..7b6fd0df 100644 --- a/setup.py +++ b/setup.py @@ -130,6 +130,9 @@ class CMakeBuild(build_ext): cmake_args += ['-DPYTHON_VERSION=' + os.getenv('PYTHON_VERSION')] # Custom Z3 paths. + if os.getenv('Z3_DIR'): + cmake_args += ['-DZ3_DIR=' + os.getenv('Z3_DIR')] + if os.getenv('Z3_LIBRARIES'): cmake_args += ['-DZ3_LIBRARIES=' + os.getenv('Z3_LIBRARIES')] @@ -144,6 +147,9 @@ class CMakeBuild(build_ext): cmake_args += ['-DBITWUZLA_INCLUDE_DIRS=' + os.getenv('BITWUZLA_INCLUDE_DIRS')] # Custom Capstone paths. + if os.getenv('CAPSTONE_DIR'): + cmake_args += ['-DCAPSTONE_DIR=' + os.getenv('CAPSTONE_DIR')] + if os.getenv('CAPSTONE_LIBRARIES'): cmake_args += ['-DCAPSTONE_LIBRARIES=' + os.getenv('CAPSTONE_LIBRARIES')] @@ -151,6 +157,9 @@ class CMakeBuild(build_ext): cmake_args += ['-DCAPSTONE_INCLUDE_DIRS=' + os.getenv('CAPSTONE_INCLUDE_DIRS')] # Custom LLVM paths. + if os.getenv('LLVM_DIR'): + cmake_args += ['-DLLVM_DIR='+ os.getenv('LLVM_DIR')] + if os.getenv('LLVM_LIBRARIES'): cmake_args += ['-DLLVM_LIBRARIES=' + os.getenv('LLVM_LIBRARIES')] From bdfa33f9760983aeee8c217e99dc8b9e08f3484a Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 02:51:13 +0000 Subject: [PATCH 10/15] update setup.py --- CMakeLists.txt | 4 ++-- setup.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4625c5c..6f925b72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,12 +149,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif() # Custom cmake search -list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/") +#list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/") # Find Z3 if(Z3_INTERFACE) message(STATUS "Compiling with Z3 SMT solver") - find_package(Z3 REQUIRED) + find_package(Z3 CONFIG REQUIRED) message(STATUS "Z3 version: ${Z3_VERSION}") if(TARGET z3::libz3) link_libraries(z3::libz3) diff --git a/setup.py b/setup.py index 7b6fd0df..d69baa06 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ VERSION_PATCH = 0 RELEASE_CANDIDATE = 4 BUILDTOOLS = "vs2022" # clang or clang_cl or vs2022 -CMAKE_BUILD_TYPE = "Release" # release or debug +CMAKE_BUILD_TYPE = "Release" # Release or Debug VERSION = f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}' + \ f'rc{RELEASE_CANDIDATE}' if RELEASE_CANDIDATE else '' @@ -101,16 +101,16 @@ class CMakeBuild(build_ext): assert os.getenv('COMPILER_DIR'), "COMPILER_DIR(clang or clang_cl) env not found" if BUILDTOOLS == "clang": cmake_args += [ - "-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "clang.exe", - "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "clang++.exe", - "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "llvm-rc.exe", + "-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang.exe", + "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang++.exe", + "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe", "-G Ninja", ] if BUILDTOOLS == "clang_cl": cmake_args += [ - "-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "clang-cl.exe", - "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "clang-cl.exe", - "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "llvm-rc.exe", + "-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "/clang-cl.exe", + "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang-cl.exe", + "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe", "-G Ninja", ] else: @@ -149,7 +149,7 @@ class CMakeBuild(build_ext): # Custom Capstone paths. if os.getenv('CAPSTONE_DIR'): cmake_args += ['-DCAPSTONE_DIR=' + os.getenv('CAPSTONE_DIR')] - + if os.getenv('CAPSTONE_LIBRARIES'): cmake_args += ['-DCAPSTONE_LIBRARIES=' + os.getenv('CAPSTONE_LIBRARIES')] @@ -200,7 +200,7 @@ class CMakeBuild(build_ext): src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) elif platform.system() == "Windows": - src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\'+ CMAKE_BUILD_TYPE, 'triton.pyd') + src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\', 'triton.pyd') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) else: raise Exception(f'Platform not supported: {platform.system()}') From 09a4bbb4ecce4813c6511d8afa1ba7e66416e9e9 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 03:10:07 +0000 Subject: [PATCH 11/15] update cmakelists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f925b72..66ff2552 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,7 +149,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif() # Custom cmake search -#list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/") +list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/") # Find Z3 if(Z3_INTERFACE) @@ -199,7 +199,7 @@ endif() # Find Capstone message(STATUS "Compiling with Capstone") -find_package(CAPSTONE 5 REQUIRED) +find_package(CAPSTONE 5 CONFIG REQUIRED) message(STATUS "CAPSTONE version: ${CAPSTONE_VERSION}") if(TARGET capstone::capstone) link_libraries(capstone::capstone) From 2b1d0ad8fcd6bfb7d865cada5e0d9c8c4963627d Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 07:53:18 +0000 Subject: [PATCH 12/15] update setup.py --- CMakeLists.txt | 4 ++-- README.md | 12 ++++++++++++ setup.py | 30 ++++++++++++++++-------------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66ff2552..c4625c5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,7 @@ list(APPEND CMAKE_MODULE_PATH "${TRITON_ROOT}/CMakeModules/") # Find Z3 if(Z3_INTERFACE) message(STATUS "Compiling with Z3 SMT solver") - find_package(Z3 CONFIG REQUIRED) + find_package(Z3 REQUIRED) message(STATUS "Z3 version: ${Z3_VERSION}") if(TARGET z3::libz3) link_libraries(z3::libz3) @@ -199,7 +199,7 @@ endif() # Find Capstone message(STATUS "Compiling with Capstone") -find_package(CAPSTONE 5 CONFIG REQUIRED) +find_package(CAPSTONE 5 REQUIRED) message(STATUS "CAPSTONE version: ${CAPSTONE_VERSION}") if(TARGET capstone::capstone) link_libraries(capstone::capstone) diff --git a/README.md b/README.md index 719df6f0..35e5cc28 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,18 @@ You can use cmake to generate the .sln file of libTriton. -DCAPSTONE_LIBRARIES="C:/Users/jonathan/Works/Tools/capstone-5.0.1-win64/capstone.lib" .. ``` +You can use setup.py to generate the debug version of triton.pyd on Windows. + +```console +> git clone https://github.com/JonathanSalwan/Triton.git +> cd Triton +> $env:COMPILER_DIR="C:/deps/llvm/llvm2116r/bin" +> $env:CMAKE_PREFIX_PATH="C:/deps/llvm/llvm-project-21.1.6.src/install/lib/cmake/llvm;C:/code/cxx-common-cmake/build/install" +> python_d -m build --wheel +> python_d -m pip install (Get-ChildItem .\dist\triton_library*) + +``` + However, if you prefer to directly download the precompiled library, check out our AppVeyor's [artefacts](https://ci.appveyor.com/project/JonathanSalwan/triton/history). Note that if you use AppVeyor's artefacts, you probably have to install the [Visual C++ Redistributable](https://www.microsoft.com/en-US/download/details.aspx?id=30679) packages for Visual Studio 2012. diff --git a/setup.py b/setup.py index d69baa06..87f34d44 100644 --- a/setup.py +++ b/setup.py @@ -20,11 +20,23 @@ from setuptools.command.build_ext import build_ext VERSION_MAJOR = 1 VERSION_MINOR = 0 VERSION_PATCH = 0 +ON = "ON" +OFF = "OFF" + +clang = "clang" +clang_cl = "clang_cl" +vs2022 = "vs2022" +Release = "Release" +Debug = "Debug" RELEASE_CANDIDATE = 4 +Z3_INTERFACE = ON +LLVM_INTERFACE = OFF +BITWUZLA_INTERFACE = OFF +BOOST_INTERFACE = OFF -BUILDTOOLS = "vs2022" # clang or clang_cl or vs2022 -CMAKE_BUILD_TYPE = "Release" # Release or Debug +BUILDTOOLS = vs2022 # clang or clang_cl or vs2022 +CMAKE_BUILD_TYPE = Release # Release or Debug VERSION = f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}' + \ f'rc{RELEASE_CANDIDATE}' if RELEASE_CANDIDATE else '' @@ -73,7 +85,7 @@ class CMakeBuild(build_ext): # BITWUZLA_INTERFACE=Off # BOOST_INTERFACE=Off # - for arg, value in [('Z3_INTERFACE', 'On'), ('LLVM_INTERFACE', 'Off'), ('BITWUZLA_INTERFACE', 'Off'), ('BOOST_INTERFACE', 'Off')]: + for arg, value in [('Z3_INTERFACE', Z3_INTERFACE), ('LLVM_INTERFACE', LLVM_INTERFACE), ('BITWUZLA_INTERFACE', BITWUZLA_INTERFACE), ('BOOST_INTERFACE', BOOST_INTERFACE)]: if os.getenv(arg): cmake_args += [f'-D{arg}=' + os.getenv(arg)] else: @@ -130,9 +142,6 @@ class CMakeBuild(build_ext): cmake_args += ['-DPYTHON_VERSION=' + os.getenv('PYTHON_VERSION')] # Custom Z3 paths. - if os.getenv('Z3_DIR'): - cmake_args += ['-DZ3_DIR=' + os.getenv('Z3_DIR')] - if os.getenv('Z3_LIBRARIES'): cmake_args += ['-DZ3_LIBRARIES=' + os.getenv('Z3_LIBRARIES')] @@ -145,11 +154,7 @@ class CMakeBuild(build_ext): if os.getenv('BITWUZLA_INCLUDE_DIRS'): cmake_args += ['-DBITWUZLA_INCLUDE_DIRS=' + os.getenv('BITWUZLA_INCLUDE_DIRS')] - # Custom Capstone paths. - if os.getenv('CAPSTONE_DIR'): - cmake_args += ['-DCAPSTONE_DIR=' + os.getenv('CAPSTONE_DIR')] - if os.getenv('CAPSTONE_LIBRARIES'): cmake_args += ['-DCAPSTONE_LIBRARIES=' + os.getenv('CAPSTONE_LIBRARIES')] @@ -157,9 +162,6 @@ class CMakeBuild(build_ext): cmake_args += ['-DCAPSTONE_INCLUDE_DIRS=' + os.getenv('CAPSTONE_INCLUDE_DIRS')] # Custom LLVM paths. - if os.getenv('LLVM_DIR'): - cmake_args += ['-DLLVM_DIR='+ os.getenv('LLVM_DIR')] - if os.getenv('LLVM_LIBRARIES'): cmake_args += ['-DLLVM_LIBRARIES=' + os.getenv('LLVM_LIBRARIES')] @@ -200,7 +202,7 @@ class CMakeBuild(build_ext): src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) elif platform.system() == "Windows": - src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\', 'triton.pyd') + src_filename = os.path.join(self.build_temp + '/src/libtriton', 'triton.pyd') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) else: raise Exception(f'Platform not supported: {platform.system()}') From ccb586e527132915402ee080414972afeb9a18aa Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 16:10:40 +0800 Subject: [PATCH 13/15] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 87f34d44..2c59ae88 100644 --- a/setup.py +++ b/setup.py @@ -202,7 +202,7 @@ class CMakeBuild(build_ext): src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) elif platform.system() == "Windows": - src_filename = os.path.join(self.build_temp + '/src/libtriton', 'triton.pyd') + src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\', 'triton.pyd') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) else: raise Exception(f'Platform not supported: {platform.system()}') From 5a02087e2f569d324fe7d0c13a3cf38ba9adf999 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Mon, 1 Dec 2025 20:24:56 +0800 Subject: [PATCH 14/15] Update setup.py --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c59ae88..cc332daf 100644 --- a/setup.py +++ b/setup.py @@ -202,7 +202,10 @@ class CMakeBuild(build_ext): src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) elif platform.system() == "Windows": - src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\', 'triton.pyd') + if BUILDTOOLS == vs2022: + src_filename = os.path.join(self.build_temp + '/src/libtriton/' + CMAKE_BUILD_TYPE, 'triton.pyd') + else: + src_filename = os.path.join(self.build_temp + '/src/libtriton', 'triton.pyd') dst_filename = os.path.join(self.build_lib, os.path.basename(filename)) else: raise Exception(f'Platform not supported: {platform.system()}') From 1dcf63cc261b0e0b812954e19e5d60c3b6c74850 Mon Sep 17 00:00:00 2001 From: cctv130 Date: Tue, 2 Dec 2025 04:49:13 +0800 Subject: [PATCH 15/15] Update setup.py --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index cc332daf..b43a01ac 100644 --- a/setup.py +++ b/setup.py @@ -104,21 +104,21 @@ class CMakeBuild(build_ext): build_args += ['--', '-j4'] elif platform.system() == "Windows": - if BUILDTOOLS == "vs2022": + if BUILDTOOLS == vs2022: cmake_args += [ "-G Visual Studio 17 2022", ] build_args += ["--", "/m:4"] else: assert os.getenv('COMPILER_DIR'), "COMPILER_DIR(clang or clang_cl) env not found" - if BUILDTOOLS == "clang": + if BUILDTOOLS == clang: cmake_args += [ "-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang.exe", "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang++.exe", "-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe", "-G Ninja", ] - if BUILDTOOLS == "clang_cl": + if BUILDTOOLS == clang_cl: cmake_args += [ "-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "/clang-cl.exe", "-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang-cl.exe",