Unverified Commit 0e04c4d4 authored by Moritz Sanft's avatar Moritz Sanft Committed by GitHub
Browse files

ida-free: add binary patch support (#504159)

parents 82456e15 a456c000
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
  libxkbcommon,
  makeWrapper,
  openssl,
  perl,
  stdenv,
  libxcb-wm,
  libxcb-render-util,
@@ -31,7 +32,24 @@
  libice,
  libxcb,
  zlib,
  hexPatches ? [ ],
  # hexPatches: hex patterns to substitute in specified files immediately after
  # install. Can be used, for example, to replace the embedded SSL certificates
  # for compatibility with a self-hosted Lumina server.
  # Since IDA is distributed as a binary, such patching is the only recourse
  # available to us for interoperability purposes.
}:
let
  patchScript = lib.concatMapStringsSep "\n" (
    p:
    let
      forcecntDecl = lib.optionalString (p ? assertCount) "my $forcecnt = ${toString p.assertCount};";
    in
    ''
      perl -0777 -pi -e '${forcecntDecl} my $cnt = (s/\Q''${\pack("H*","${p.from}")}\E/''${\pack("H*","${p.to}")}/g) || 0; die "Expected $forcecnt substitutions, did $cnt\n" if defined $forcecnt && $cnt != $forcecnt' "$IDADIR/${p.filename}"
    ''
  ) hexPatches;
in
stdenv.mkDerivation (finalAttrs: {
  pname = "ida-free";
  version = "9.3";
@@ -45,6 +63,7 @@ stdenv.mkDerivation (finalAttrs: {
  nativeBuildInputs = [
    makeWrapper
    autoPatchelfHook
    perl
  ];

  # We just get a runfile in $src, so no need to unpack it.
@@ -111,6 +130,8 @@ stdenv.mkDerivation (finalAttrs: {
    $(cat $NIX_CC/nix-support/dynamic-linker) $src \
      --mode unattended --prefix $IDADIR

    ${patchScript}

    # Copy the exported libraries to the output.
    cp $IDADIR/libida.so $out/lib