Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindiff: 8-unstable-2024-11-11, binexport: 12-unstable-2024-11-01 #355232

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkgs/by-name/bi/bindiff/allow-compilation-without-ida.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/cmake/BinDiffDeps.cmake b/cmake/BinDiffDeps.cmake
index 057b978..3db6749 100644
--- a/cmake/BinDiffDeps.cmake
+++ b/cmake/BinDiffDeps.cmake
@@ -29,6 +29,8 @@ if(NOT sqlite_POPULATED)
endif()

# Setup IDA SDK. Uses FindIdaSdk.cmake from BinExport
+if(BINEXPORT_ENABLE_IDAPRO)
find_package(IdaSdk)
+endif()

find_package(Protobuf 3.14 REQUIRED) # Make protobuf_generate_cpp available
94 changes: 94 additions & 0 deletions pkgs/by-name/bi/bindiff/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
lib,
stdenv,
fetchFromGitHub,
fetchzip,

cmake,
ninja,
git,

binexport,
boost183,

nix-update-script,

enableIDA ? false,
}:
let
binexport' = binexport.override { inherit enableIDA; };

# needs a fixed version:
# https://github.com/google/bindiff/blob/c8972f08a3438049f2f5e81439a70ee56f95c549/cmake/BinDiffDeps.cmake#L16-L19
sqlite = fetchzip {
url = "https://sqlite.org/2024/sqlite-amalgamation-3450100.zip";
hash = "sha256-bJoMjirsBjm2Qk9KPiy3yV3+8b/POlYe76/FQbciHro=";
};
pluiedev marked this conversation as resolved.
Show resolved Hide resolved

inherit (stdenv.hostPlatform.extensions) sharedLibrary;
in
stdenv.mkDerivation (finalAttrs: {
pname = "bindiff";
version = "8-unstable-2024-11-11";

src = fetchFromGitHub {
owner = "google";
repo = "bindiff";
rev = "c8972f08a3438049f2f5e81439a70ee56f95c549";
hash = "sha256-5EVlrQqtzPPrjmoCJ/SlvSo2bRklvwveslPfeq8CN6A=";
};

patches = [ ./allow-compilation-without-ida.patch ];

nativeBuildInputs = [
cmake
ninja
git
];

buildInputs = [
boost183
];

cmakeFlags = [
(lib.cmakeFeature "BINDIFF_BINEXPORT_DIR" "${binexport'.src}")
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_SQLITE" "${sqlite}")
] ++ binexport'.cmakeFlags;

postInstall =
''
mkdir -p $out/bin
mv $out/bindiff-prefix/bindiff{,_config_setup} $out/bin
''
+ lib.optionalString enableIDA ''
mkdir -p $out/lib
mv $out/bindiff-prefix/bindiff*_ida*${sharedLibrary} $out/lib
''
+ ''
rmdir $out/bindiff-prefix
Copy link
Contributor

@wolfgangwalther wolfgangwalther Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on darwin:

rmdir: failed to remove '/nix/store/vgac29rqh53yrxz6jagvnx3qs7y61yah-bindiff-8-unstable-2024-11-11/bindiff-prefix': Directory not empty

Edit:

The lines before that might be relevant:

-- Install configuration: "Release"
-- Installing: /nix/store/vgac29rqh53yrxz6jagvnx3qs7y61yah-bindiff-8-unstable-2024-11-11/bindiff-prefix/bindiff
-- Installing: /nix/store/vgac29rqh53yrxz6jagvnx3qs7y61yah-bindiff-8-unstable-2024-11-11/bindiff-prefix/bindiff_config_setup
-- Installing: /nix/store/vgac29rqh53yrxz6jagvnx3qs7y61yah-bindiff-8-unstable-2024-11-11/bindiff-prefix/bindiff_launcher_macos

'';

passthru.updateScript = nix-update-script { };

meta = {
description = "Quickly find differences and similarities in disassembled code";
longDescription = ''
BinDiff doesn't compile the IDA plugin by default as it requires a copy
of the proprietary IDA SDK.
If you use IDA, you can override this package with `enableIDA` set to true:
```nix
bindiff.override { enableIDA = true; }
```
Note that this would render the entire package unfree and non-redistributable
due to the closed-source, proprietary nature of IDA and its SDK.
'';
homepage = "https://zynamics.com/bindiff.html";
license = with lib.licenses; [ asl20 ];
pluiedev marked this conversation as resolved.
Show resolved Hide resolved
platforms = with lib.platforms; lib.intersectLists x86 (unix ++ windows);
maintainers = with lib.maintainers; [
pluiedev
BonusPlay
];
};
})
105 changes: 105 additions & 0 deletions pkgs/by-name/bi/binexport/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
lib,
stdenv,
fetchFromGitHub,
cmake,
ninja,
git,

boost183,
abseil-cpp,
gtest,
protobuf,
ida-sdk_8,

enableBinaryNinja ? true,
enableIDA ? false,
}:
let
# Use what's specified in cmake/BinExportDeps.cmake
binaryninjaapi = fetchFromGitHub {
owner = "Vector35";
repo = "binaryninja-api";
rev = "59e569906828e91e4884670c2bba448702f5a31d";
hash = "sha256-XSVxQiLbTyrHyTubZWa0sIgL15/SXk2bl6ObLcGUj5w=";
fetchSubmodules = true;
};

inherit (stdenv.hostPlatform.extensions) sharedLibrary;
in
stdenv.mkDerivation (finalAttrs: {
pname = "binexport";
version = "12-unstable-2024-11-01";

src = fetchFromGitHub {
owner = "google";
repo = "binexport";
rev = "23619ba62d88b3b93615d28fe3033489d12b38ac";
hash = "sha256-hXb/g5BuEawUjJZPRwjKFkqZTDXDGzHSRJLYqdenMlU=";
};

nativeBuildInputs = [
cmake
ninja
git
];

buildInputs = [
boost183
];

cmakeFlags =
[
(lib.cmakeBool "BINEXPORT_ENABLE_IDAPRO" enableIDA)
(lib.cmakeBool "BINEXPORT_ENABLE_BINARYNINJA" enableBinaryNinja)

# Dependencies
(lib.cmakeBool "FETCHCONTENT_FULLY_DISCONNECTED" true)
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_ABSL" "${abseil-cpp.src}")
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_GOOGLETEST" "${gtest.src}")
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_PROTOBUF" "${protobuf.src}")
]
++ lib.optional enableBinaryNinja (
lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_BINARYNINJAAPI" "${binaryninjaapi}"
)
++ lib.optional enableIDA (lib.cmakeFeature "IdaSdk_ROOT_DIR" "${ida-sdk_8}");

postInstall =
''
mkdir -p $out/bin
mv $out/binexport-prefix/{bxp,binexport2dump} $out/bin

mkdir -p $out/lib
''
+ lib.optionalString enableBinaryNinja ''
mv $out/binexport-prefix/binexport*_binaryninja${sharedLibrary} $out/lib
''
+ lib.optionalString enableIDA ''
mv $out/binexport-prefix/binexport*_ida*${sharedLibrary} $out/lib
''
+ ''
rmdir $out/binexport-prefix
'';

meta = {
description = "Export disassemblies into Protocol Buffers";
longDescription = ''
BinExport doesn't compile the IDA plugin by default as it requires a copy
of the proprietary IDA SDK.

If you use IDA, you can override this package with `enableIDA` set to true:
```nix
binexport.override { enableIDA = true; }
```
Note that this would render the entire package unfree and non-redistributable
due to the closed-source, proprietary nature of IDA and its SDK.
'';
homepage = "https://github.com/google/binexport";
license = with lib.licenses; [ asl20 ];
pluiedev marked this conversation as resolved.
Show resolved Hide resolved
platforms = with lib.platforms; lib.intersectLists x86 (unix ++ windows);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with architectures only contrains ida-pro. I believe binexport and bindiff and binaryninja-api can be compiled on all platforms (linux, windows, macos).
Other than that, I'd be happy to approve this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I wonder then should we just set the platforms for ida-sdk_8 to be x86(-64)-only, and have it automatically fail if evaluated on a non-x86 platform?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure if this PR is hung up on anything else, but fwiw I think setting ida-sdk_8 to x86(-64)-only and only failing for it seems reasonable to me. Looking forward to this and eventual ghidra extension support making it's way in!

maintainers = with lib.maintainers; [
pluiedev
BonusPlay
];
};
})
62 changes: 62 additions & 0 deletions pkgs/by-name/id/ida-sdk_8/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
lib,
stdenvNoCC,
requireFile,
libarchive,
}:
stdenvNoCC.mkDerivation (
finalAttrs:
let
sdkName = "idasdk_pro${builtins.replaceStrings [ "." ] [ "" ] finalAttrs.version}.zip";
in
{
pname = "ida-sdk_8";
version = "8.4";

src = requireFile {
name = sdkName;
hash = "sha256-NQqrsoFzxceAGYZ6xskJL9TueP1Jn/x54UqTnLnmHiE=";
message = ''
Unfortunately, you need to first obtain a copy of the IDA SDK v${finalAttrs.version} from Hex-Rays,
as we cannot download it for you automatically.

Please first head to <https://my.hex-rays.com> and log in with or register your IDA account.

If you do not yet have an IDA license, click on the "Shop" tab, press "+ Add item",
select "IDA Free Plan" under "Product offering", then fill in your billing information.

Once you have acquired your license or if you have a pre-existing license,
click on the "Download center" tab, select version "${finalAttrs.version}"
and download "SDK Pro" under the section "SDK and Utilities".

Once your SDK has been downloaded, you can add it to your Nix store by running either
nix-store --add-fixed sha256 ${sdkName}
or
nix-prefetch-url --type sha256 file:///path/to/${sdkName}
'';
};

nativeBuildInputs = [ libarchive ];

unpackCmd = "bsdtar -xf $curSrc";

dontBuild = true;

installPhase = ''
runHook preInstall

mkdir -p $out
cp -r . $out

runHook postInstall
'';

meta = {
description = "SDK for the IDA decompiler and disassembler";
homepage = "https://hex-rays.com";
license = with lib.licenses; [ unfree ];
platforms = with lib.platforms; linux ++ darwin ++ windows;
pluiedev marked this conversation as resolved.
Show resolved Hide resolved
maintainers = with lib.maintainers; [ pluiedev ];
};
}
)
Loading