nixpkgs/pkgs/tools/security/jadx/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.6 KiB
Nix
Raw Normal View History

{ lib, stdenv, fetchFromGitHub, gradle, jdk, makeWrapper, perl }:
2020-03-30 03:49:08 +00:00
let
pname = "jadx";
2023-03-16 00:42:50 +00:00
version = "1.4.6";
2020-03-30 03:49:08 +00:00
src = fetchFromGitHub {
owner = "skylot";
repo = pname;
rev = "v${version}";
2023-03-16 00:42:50 +00:00
hash = "sha256-nxEK2K6id1Rnqo85ls6YEHXrhc9ykJU17+olGqg+aGA=";
2020-03-30 03:49:08 +00:00
};
deps = stdenv.mkDerivation {
name = "${pname}-deps";
inherit src;
nativeBuildInputs = [ gradle jdk perl ];
buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
export JADX_VERSION=${version}
gradle --no-daemon jar
2021-12-02 17:49:19 +00:00
# Apparently, Gradle won't cache the `compileOnlyApi` dependency
# `org.jetbrains:annotations:22.0.0` which is defined in
# `io.github.skylot:raung-common`. To make it available in the
# output, we patch `build.gradle` and run Gradle again.
substituteInPlace build.gradle \
--replace 'org.jetbrains:annotations:23.0.0' 'org.jetbrains:annotations:22.0.0'
gradle --no-daemon jar
2020-03-30 03:49:08 +00:00
'';
# Mavenize dependency paths
# e.g. org.codehaus.groovy/groovy/2.4.0/{hash}/groovy-2.4.0.jar -> org/codehaus/groovy/groovy/2.4.0/groovy-2.4.0.jar
installPhase = ''
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
| sh
2022-10-24 07:33:28 +00:00
# Work around okio-2.10.0 bug, fixed in 3.0. Remove "-jvm" from filename.
# https://github.com/square/okio/issues/954
mv $out/com/squareup/okio/okio/2.10.0/okio{-jvm,}-2.10.0.jar
2020-03-30 03:49:08 +00:00
'';
outputHashMode = "recursive";
2023-03-16 00:42:50 +00:00
outputHash = "sha256-QebPRmfLtXy4ZlyKeGC5XNzhMTsYI0X36My+nTFvQpM=";
2020-03-30 03:49:08 +00:00
};
in stdenv.mkDerivation {
inherit pname version src;
nativeBuildInputs = [ gradle jdk makeWrapper ];
2022-10-24 13:33:42 +00:00
# Otherwise, Gradle fails with `java.net.SocketException: Operation not permitted`
__darwinAllowLocalNetworking = true;
2020-03-30 03:49:08 +00:00
buildPhase = ''
# The installDist Gradle build phase tries to copy some dependency .jar
# files multiple times into the build directory. This ends up failing when
# the dependencies are read directly from the Nix store since they are not
# marked as chmod +w. To work around this, get a local copy of the
# dependency store, and give write permissions.
depsDir=$(mktemp -d)
cp -R ${deps}/* $depsDir
chmod -R u+w $depsDir
gradleInit=$(mktemp)
cat >$gradleInit <<EOF
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
clear()
maven { url '$depsDir' }
}
}
repositories {
clear()
maven { url '$depsDir' }
}
}
}
settingsEvaluated { settings ->
settings.pluginManagement {
repositories {
maven { url '$depsDir' }
}
}
}
EOF
export GRADLE_USER_HOME=$(mktemp -d)
export JADX_VERSION=${version}
gradle --offline --no-daemon --info --init-script $gradleInit pack
'';
installPhase = ''
mkdir $out $out/bin
cp -R build/jadx/lib $out
for prog in jadx jadx-gui; do
cp build/jadx/bin/$prog $out/bin
wrapProgram $out/bin/$prog --set JAVA_HOME ${jdk.home}
done
'';
meta = with lib; {
2020-03-30 03:49:08 +00:00
description = "Dex to Java decompiler";
longDescription = ''
Command line and GUI tools for produce Java source code from Android Dex
and Apk files.
'';
sourceProvenance = with sourceTypes; [
fromSource
binaryBytecode # deps
];
2020-03-30 03:49:08 +00:00
license = licenses.asl20;
platforms = platforms.unix;
maintainers = with maintainers; [ delroth ];
};
}