From 3360c7e7ccb4c3a311a70b1eecea8be5d036f26e Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 8 Mar 2025 09:47:24 +0100 Subject: [PATCH 1/3] unicorn-angr: init at 2.0.1.post1 angr requires a specific version of unicorn. --- pkgs/by-name/un/unicorn-angr/package.nix | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pkgs/by-name/un/unicorn-angr/package.nix diff --git a/pkgs/by-name/un/unicorn-angr/package.nix b/pkgs/by-name/un/unicorn-angr/package.nix new file mode 100644 index 000000000000..18711fc7c8a4 --- /dev/null +++ b/pkgs/by-name/un/unicorn-angr/package.nix @@ -0,0 +1,43 @@ +{ + lib, + stdenv, + cmake, + fetchFromGitHub, + pkg-config, +}: + +stdenv.mkDerivation rec { + pname = "unicorn-angr"; + # Version must follow what angr requires + version = "2.0.1.post1"; + + src = fetchFromGitHub { + owner = "unicorn-engine"; + repo = "unicorn"; + tag = version; + hash = "sha256-Jz5C35rwnDz0CXcfcvWjkwScGNQO1uijF7JrtZhM7mI="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + # Ensure the linker is using atomic when compiling for RISC-V, otherwise fails + NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic"; + + cmakeFlags = lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ + # Some x86 tests are interrupted by signal 10 + "-DCMAKE_CTEST_ARGUMENTS=--exclude-regex;test_x86" + ]; + + doCheck = true; + + meta = with lib; { + description = "Lightweight multi-platform CPU emulator library"; + homepage = "https://www.unicorn-engine.org"; + license = licenses.gpl2Only; + maintainers = with maintainers; [ fab ]; + platforms = platforms.unix; + }; +} From fb788b3954be24870b312620af84efc5cedd023d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 8 Mar 2025 09:55:38 +0100 Subject: [PATCH 2/3] python313Packages.unicorn-angr: init at 2.0.1.post1 --- .../python-modules/unicorn-angr/default.nix | 59 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 4 ++ 2 files changed, 63 insertions(+) create mode 100644 pkgs/development/python-modules/unicorn-angr/default.nix diff --git a/pkgs/development/python-modules/unicorn-angr/default.nix b/pkgs/development/python-modules/unicorn-angr/default.nix new file mode 100644 index 000000000000..350360d8d3dc --- /dev/null +++ b/pkgs/development/python-modules/unicorn-angr/default.nix @@ -0,0 +1,59 @@ +{ + lib, + stdenv, + buildPythonPackage, + distutils, + setuptools, + unicorn-angr, +}: + +buildPythonPackage rec { + pname = "unicorn-angr"; + version = lib.getVersion unicorn-angr; + pyproject = true; + + src = unicorn-angr.src; + + sourceRoot = "${src.name}/bindings/python"; + + prePatch = '' + ln -s ${unicorn-angr}/lib/libunicorn.* prebuilt/ + ''; + + # Needed on non-x86 linux + setupPyBuildFlags = + lib.optionals stdenv.hostPlatform.isLinux [ + "--plat-name" + "linux" + ] + # aarch64 only available from MacOS SDK 11 onwards, so fix the version tag. + # otherwise, bdist_wheel may detect "macosx_10_6_arm64" which doesn't make sense. + ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ + "--plat-name" + "macosx_11_0" + ]; + + build-system = [ + distutils + setuptools + ]; + + checkPhase = '' + runHook preCheck + + mv unicorn unicorn.hidden + patchShebangs sample_*.py shellcode.py + sh -e sample_all.sh + + runHook postCheck + ''; + + pythonImportsCheck = [ "unicorn" ]; + + meta = with lib; { + description = "Python bindings for Unicorn CPU emulator engine"; + homepage = "https://www.unicorn-engine.org/"; + license = licenses.gpl2Plus; + maintainers = with maintainers; [ fab ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index d07af8fb5894..18224dea9193 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -17970,6 +17970,10 @@ self: super: with self; { inherit (pkgs) unicorn; }; + unicorn-angr = callPackage ../development/python-modules/unicorn-angr { + inherit (pkgs) unicorn-angr; + }; + unicurses = callPackage ../development/python-modules/unicurses { }; unicrypto = callPackage ../development/python-modules/unicrypto { }; From 700623e350b72b8a712a474d42dbf0bb70defce5 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 8 Mar 2025 23:20:25 +0100 Subject: [PATCH 3/3] python312Packages.angr: migrate to unicorn-angr --- .../development/python-modules/angr/default.nix | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/pkgs/development/python-modules/angr/default.nix b/pkgs/development/python-modules/angr/default.nix index 78827310fb12..79cc13bf26f0 100644 --- a/pkgs/development/python-modules/angr/default.nix +++ b/pkgs/development/python-modules/angr/default.nix @@ -30,7 +30,7 @@ sortedcontainers, sqlalchemy, sympy, - unicorn, + unicorn-angr, unique-log-filter, }: @@ -48,16 +48,7 @@ buildPythonPackage rec { hash = "sha256-rrJTYe3o/Ra8+EKAA7t0M02tWVN4Ul5ueUar7lpUvMg="; }; - postPatch = '' - # unicorn is also part of build-system - substituteInPlace pyproject.toml \ - --replace-fail "unicorn==2.0.1.post1" "unicorn" - ''; - - pythonRelaxDeps = [ - "capstone" - "unicorn" - ]; + pythonRelaxDeps = [ "capstone" ]; build-system = [ setuptools ]; @@ -87,7 +78,7 @@ buildPythonPackage rec { sortedcontainers sqlalchemy sympy - unicorn + unicorn-angr unique-log-filter ]; @@ -117,7 +108,5 @@ buildPythonPackage rec { homepage = "https://angr.io/"; license = with licenses; [ bsd2 ]; maintainers = with maintainers; [ fab ]; - # angr is pining unicorn - broken = versionAtLeast unicorn.version "2.0.1.post1"; }; }