git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #48180 from timokau/retdec-update

retdec: 3.0 -> 3.2

commitf84cfdf02a495dc4bd326050cc8cc012357c4e1d authorWill Dietz <github@wdtz.org> dateThu 11 Oct 2018, 17:36 (8 years ago) parent9d293dba33dec8
2 files changed+220−74
pkgs/development/tools/analysis/retdec/default.nix+171−74 pkgs/development/tools/analysis/retdec/yaracpp.nix+49
pkgs/development/tools/analysis/retdec/default.nix+171−74
@@ -1,121 +1,218 @@
1−{ stdenv, fetchFromGitHub, fetchurl, fetchzip,
2−# Native build inputs
3−cmake,
4−autoconf, automake, libtool,
5−pkgconfig,
6−bison, flex,
7−groff,
8−perl,
9−python,
10−# Runtime tools
11−time,
12−upx,
13−# Build inputs
14−ncurses,
15−libffi,
16−libxml2,
17−zlib,
18−# PE (Windows) data, huge space savings if not needed
19−withPEPatterns ? false,
1+{ stdenv
2+, fetchFromGitHub
3+, fetchzip
4+, lib
5+, callPackage
6+, openssl
7+, cmake
8+, autoconf
9+, automake
10+, libtool
11+, pkgconfig
12+, bison
13+, flex
14+, groff
15+, perl
16+, python3
17+, time
18+, upx
19+, ncurses
20+, libffi
21+, libxml2
22+, zlib
23+, withPEPatterns ? false
2024}:
2125
2226let
23− release = "3.0";
24−
27+ capstone = fetchFromGitHub {
28+ owner = "avast-tl";
29+ repo = "capstone";
30+ rev = "27c713fe4f6eaf9721785932d850b6291a6073fe";
31+ sha256 = "105z1g9q7s6n15qpln9vzhlij7vj6cyc5dqdr05n7wzjvlagwgxc";
32+ };
33+ elfio = fetchFromGitHub {
34+ owner = "avast-tl";
35+ repo = "elfio";
36+ rev = "998374baace397ea98f3b1d768e81c978b4fba41";
37+ sha256 = "09n34rdp0wpm8zy30zx40wkkc4gbv2k3cv181y6c1260rllwk5d1";
38+ };
39+ keystone = fetchFromGitHub { # only for tests
40+ owner = "keystone-engine";
41+ repo = "keystone";
42+ rev = "d7ba8e378e5284e6384fc9ecd660ed5f6532e922";
43+ sha256 = "1yzw3v8xvxh1rysh97y0i8y9svzbglx2zbsqjhrfx18vngh0x58f";
44+ };
45+ libdwarf = fetchFromGitHub {
46+ owner = "avast-tl";
47+ repo = "libdwarf";
48+ rev = "85465d5e235cc2d2f90d04016d6aca1a452d0e73";
49+ sha256 = "11y62r65py8yp57i57a4cymxispimn62by9z4j2g19hngrpsgbki";
50+ };
51+ llvm = fetchFromGitHub {
52+ owner = "avast-tl";
53+ repo = "llvm";
54+ rev = "725d0cee133c6ab9b95c493f05de3b08016f5c3c";
55+ sha256 = "0dzvafmn4qs62w1y9vh0a11clpj6q3hb41aym4izpcyybjndf9bq";
56+ };
57+ pelib = fetchFromGitHub {
58+ owner = "avast-tl";
59+ repo = "pelib";
60+ rev = "a7004b2e80e4f6dc984f78b821e7b585a586050d";
61+ sha256 = "0nyrb3g749lxgcymz1j584xbb1x6rvy1mc700lyn0brznvqsm81n";
62+ };
2563 rapidjson = fetchFromGitHub {
2664 owner = "Tencent";
2765 repo = "rapidjson";
2866 rev = "v1.1.0";
2967 sha256 = "1jixgb8w97l9gdh3inihz7avz7i770gy2j2irvvlyrq3wi41f5ab";
3068 };
69+ yaracpp = callPackage ./yaracpp.nix {}; # is its own package because it needs a patch
70+ yaramod = fetchFromGitHub {
71+ owner = "avast-tl";
72+ repo = "yaramod";
73+ rev = "v2.1.2";
74+ sha256 = "1rpyqzkrqvk721hf75wb7aasw5mzp9wz4j89p0x1l9p5x1b3maz3";
75+ };
3176 jsoncpp = fetchFromGitHub {
3277 owner = "open-source-parsers";
3378 repo = "jsoncpp";
34− rev = "1.8.3";
35− sha256 = "05gkmg6r94q8a0qdymarcjlnlvmy9s365m9jhz3ysvi71cr31lkz";
79+ rev = "1.8.4";
80+ sha256 = "1z0gj7a6jypkijmpknis04qybs1hkd04d1arr3gy89lnxmp6qzlm";
3681 };
37− googletest = fetchFromGitHub {
82+ googletest = fetchFromGitHub { # only for tests
3883 owner = "google";
3984 repo = "googletest";
40− rev = "release-1.8.0";
41− sha256 = "0bjlljmbf8glnd9qjabx73w6pd7ibv43yiyngqvmvgxsabzr8399";
85+ rev = "83fa0cb17dad47a1d905526dcdddb5b96ed189d2";
86+ sha256 = "1c2r0p9v7vz2vasy8bknfb448l6wsvzw35s8hmc5z013z5502mpk";
4287 };
4388 tinyxml2 = fetchFromGitHub {
4489 owner = "leethomason";
4590 repo = "tinyxml2";
46− rev = "5.0.1";
91+ rev = "cc1745b552dd12bb1297a99f82044f83b06729e0";
4792 sha256 = "015g8520a0c55gwmv7pfdsgfz2rpdmh3d1nq5n9bd65n35492s3q";
4893 };
49− yara = fetchurl {
50− url = "https://github.com/avast-tl/yara/archive/v1.0-retdec.zip";
51− sha256 = "1bjrkgp1sgld2y7gvwrlrz5fs16521ink6xyq72v7yxj3vfa9gps";
52− };
53− openssl = fetchurl {
54− url = "https://www.openssl.org/source/openssl-1.1.0f.tar.gz";
55− sha256 = "0r97n4n552ns571diz54qsgarihrxvbn7kvyv8wjyfs9ybrldxqj";
56− };
5794
58− retdec-support = fetchzip {
59− url = "https://github.com/avast-tl/retdec-support/releases/download/2017-12-12/retdec-support_2017-12-12.tar.xz";
60− sha256 = if withPEPatterns then "0pchl7hb42dm0sdbmpr8d3c6xc0lm6cs4p6g6kdb2cr9c99gjzn3"
61− else "1hcyq6bf4wk739kb53ic2bs71gsbx6zd07pc07lzfnxf8k497mhv";
95+ retdec-support = let
96+ version = "2018-02-08"; # make sure to adjust both hashes (once with withPEPatterns=true and once withPEPatterns=false)
97+ in fetchzip {
98+ url = "https://github.com/avast-tl/retdec-support/releases/download/${version}/retdec-support_${version}.tar.xz";
99+ sha256 = if withPEPatterns then "148i8flbyj1y4kfdyzsz7jsj38k4h97npjxj18h6v4wksd4m4jm7"
100+ else "0ixv9qyqq40pzyqy6v9jf5rxrvivjb0z0zn260nbmb9gk765bacy";
101+ stripRoot = false;
62102 # Removing PE signatures reduces this from 3.8GB -> 642MB (uncompressed)
63− extraPostFetch = stdenv.lib.optionalString (!withPEPatterns) ''
64− rm -rf $out/generic/yara_patterns/static-code/pe
103+ extraPostFetch = lib.optionalString (!withPEPatterns) ''
104+ rm -r "$out/generic/yara_patterns/static-code/pe"
65105 '';
106+ } // {
107+ inherit version; # necessary to check the version against the expected version
66108 };
109+
110+ # patch CMakeLists.txt for a dependency and compare the versions to the ones expected by upstream
111+ # this has to be applied for every dependency (which it is in postPatch)
112+ patchDep = dep: ''
113+ # check if our version of dep is the same version that upstream expects
114+ echo "Checking version of ${dep.dep_name}"
115+ expected_rev="$( sed -n -e 's|.*URL https://github.com/.*/archive/\(.*\)\.zip.*|\1|p' "deps/${dep.dep_name}/CMakeLists.txt" )"
116+ if [ "$expected_rev" != '${dep.rev}' ]; then
117+ echo "The ${dep.dep_name} dependency has the wrong version: ${dep.rev} while $expected_rev is expected."
118+ exit 1
119+ fi
120+
121+ # patch the CMakeLists.txt file to use our local copy of the dependency instead of fetching it at build time
122+ sed -i -e 's|URL .*|URL ${dep}|' "deps/${dep.dep_name}/CMakeLists.txt"
123+ '';
124+
67125in stdenv.mkDerivation rec {
68126 name = "retdec-${version}";
69− version = "${release}.0";
127+
128+ # If you update this you will also need to adjust the versions of the updated dependencies. You can do this by first just updating retdec
129+ # itself and trying to build it. The build should fail and tell you which dependencies you have to upgrade to which versions.
130+ # I've notified upstream about this problem here:
131+ # https://github.com/avast-tl/retdec/issues/412
132+ version = "3.2";
70133
71134 src = fetchFromGitHub {
72135 owner = "avast-tl";
73136 repo = "retdec";
74− name = "retdec-${release}";
75− rev = "refs/tags/v${release}";
76− sha256 = "0cpc5lxg8qphdzl3gg9dx992ar35r8ik8wyysr91l2qvfhx93wks";
77− fetchSubmodules = true;
137+ name = "retdec-${version}";
138+ rev = "refs/tags/v${version}";
139+ sha256 = "0chky656lsddn20bnm3pmz6ix20y4a0y8swwr42hrhi01vkhmzrp";
78140 };
79141
80− nativeBuildInputs = [ cmake autoconf automake libtool pkgconfig bison flex groff perl python ];
142+ nativeBuildInputs = [
143+ cmake
144+ autoconf
145+ automake
146+ libtool
147+ pkgconfig
148+ bison
149+ flex
150+ groff
151+ perl
152+ python3
153+ ];
81154
82− buildInputs = [ ncurses libffi libxml2 zlib ];
155+ buildInputs = [
156+ openssl
157+ ncurses
158+ libffi
159+ libxml2
160+ zlib
161+ ];
83162
84− prePatch = ''
85− find . -wholename "*/deps/rapidjson/CMakeLists.txt" -print0 | \
86− xargs -0 sed -i -e 's|GIT_REPOSITORY.*|URL ${rapidjson}|'
87− find . -wholename "*/deps/jsoncpp/CMakeLists.txt" -print0 | \
88− xargs -0 sed -i -e 's|GIT_REPOSITORY.*|URL ${jsoncpp}|'
89− find . -wholename "*/deps/googletest/CMakeLists.txt" -print0 | \
90− xargs -0 sed -i -e 's|GIT_REPOSITORY.*|URL ${googletest}|'
91− find . -wholename "*/deps/tinyxml2/CMakeLists.txt" -print0 | \
92− xargs -0 sed -i -e 's|GIT_REPOSITORY.*|URL ${tinyxml2}|'
163+ cmakeFlags = [
164+ "-DRETDEC_TESTS=ON" # build tests
165+ ];
93166
94− find . -wholename "*/yaracpp/deps/CMakeLists.txt" -print0 | \
95− xargs -0 sed -i -e 's|URL .*|URL ${yara}|'
167+ # all dependencies that are normally fetched during build time (the subdirectories of `deps`)
168+ # all of these need to be fetched through nix and the CMakeLists files need to be patched not to fetch them themselves
169+ external_deps = [
170+ (capstone // { dep_name = "capstone"; })
171+ (elfio // { dep_name = "elfio"; })
172+ (googletest // { dep_name = "googletest"; })
173+ (jsoncpp // { dep_name = "jsoncpp"; })
174+ (keystone // { dep_name = "keystone"; })
175+ (libdwarf // { dep_name = "libdwarf"; })
176+ (llvm // { dep_name = "llvm"; })
177+ (pelib // { dep_name = "pelib"; })
178+ (rapidjson // { dep_name = "rapidjson"; })
179+ (tinyxml2 // { dep_name = "tinyxml2"; })
180+ (yaracpp // { dep_name = "yaracpp"; })
181+ (yaramod // { dep_name = "yaramod"; })
182+ ];
96183
97− find . -wholename "*/deps/openssl/CMakeLists.txt" -print0 | \
98− xargs -0 sed -i -e 's|OPENSSL_URL .*)|OPENSSL_URL ${openssl})|'
184+ postPatch = (lib.concatMapStrings patchDep external_deps) + ''
185+ # install retdec-support
186+ echo "Checking version of retdec-support"
187+ expected_version="$( sed -n -e "s|^version = '\(.*\)'$|\1|p" 'cmake/install-share.py' )"
188+ if [ "$expected_version" != '${retdec-support.version}' ]; then
189+ echo "The retdec-support dependency has the wrong version: ${retdec-support.version} while $expected_version is expected."
190+ exit 1
191+ fi
192+ mkdir -p "$out/share/retdec"
193+ cp -r ${retdec-support} "$out/share/retdec/support" # write permission needed during install
194+ chmod -R u+w "$out/share/retdec/support"
195+ # python file originally responsible for fetching the retdec-support archive to $out/share/retdec
196+ # that is not necessary anymore, so empty the file
197+ echo > cmake/install-share.py
99198
100− cat > cmake/install-share.sh <<EOF
101− #!/bin/sh
102− mkdir -p $out/share/retdec/
103− ln -s ${retdec-support} $out/share/retdec/support
104− EOF
105− chmod +x cmake/*.sh
106− patchShebangs cmake/*.sh
107−
108− substituteInPlace scripts/unpack.sh --replace ' upx -d' ' ${upx}/bin/upx -d'
109− substituteInPlace scripts/config.sh --replace /usr/bin/time ${time}/bin/time
199+ # call correct `time` and `upx` programs
200+ substituteInPlace scripts/retdec-config.py --replace /usr/bin/time ${time}/bin/time
201+ substituteInPlace scripts/retdec-unpacker.py --replace "'upx'" "'${upx}/bin/upx'"
110202 '';
111203
112204 enableParallelBuilding = true;
113205
114− meta = with stdenv.lib; {
206+ doInstallCheck = true;
207+ installCheckPhase = ''
208+ ${python3.interpreter} "$out/bin/retdec-tests-runner.py"
209+ '';
210+
211+ meta = with lib; {
115212 description = "A retargetable machine-code decompiler based on LLVM";
116213 homepage = https://retdec.com;
117214 license = licenses.mit;
118− maintainers = with maintainers; [ dtzWill ];
119− broken = withPEPatterns; # retdec-full is broken, 2018-04-11
215+ maintainers = with maintainers; [ dtzWill timokau ];
216+ platforms = ["x86_64-linux" "i686-linux"];
120217 };
121218}
pkgs/development/tools/analysis/retdec/yaracpp.nixnew file+49
@@ -0,0 +1,49 @@
1+{ stdenv
2+, fetchFromGitHub
3+, coreutils
4+}:
5+
6+let
7+ yara = fetchFromGitHub {
8+ owner = "avast-tl";
9+ repo = "yara";
10+ rev = "ea101c5856941f39cad2db3012f2660d1d5c8b65";
11+ sha256 = "033ssx2hql5k4pv9si043s3mjq2b748ymjzif8pg6rdwh260faky";
12+ };
13+in stdenv.mkDerivation rec {
14+ # only fetches the yaracpp source patched to work with a local yara clone,
15+ # does not build anything
16+ name = "yaracpp-src-${version}";
17+ version = "2018-10-09";
18+ rev = "b92bde0e59e3b75bc445227e04b71105771dee8b"; # as specified in retdec/deps/yaracpp/CMakeLists.txt
19+
20+ src = fetchFromGitHub {
21+ inherit rev;
22+ owner = "avast-tl";
23+ repo = "yaracpp";
24+ sha256 = "0fan7q79j7s3bjmhsd2nw6sqyi14xgikn7mr2p4nj87lick5l4a2";
25+ };
26+
27+ postPatch = ''
28+ # check if our version of yara is the same version that upstream expects
29+ echo "Checking version of yara"
30+ expected_rev="$( sed -n -e 's|.*URL https://github.com/.*/archive/\(.*\)\.zip.*|\1|p' "deps/CMakeLists.txt" )"
31+ if [ "$expected_rev" != '${yara.rev}' ]; then
32+ echo "The yara dependency has the wrong version: ${yara.rev} while $expected_rev is expected."
33+ exit 1
34+ fi
35+
36+ # patch the CMakeLists.txt file to use our local copy of the dependency instead of fetching it at build time
37+ sed -i -e "s|URL .*|URL ${yara}|" "deps/CMakeLists.txt"
38+
39+ # abuse the CONFIGURE_COMMAND to make the source writeable after copying it to the build locatoin (necessary for the build)
40+ sed -i -e 's|CONFIGURE_COMMAND ""|CONFIGURE_COMMAND COMMAND ${coreutils}/bin/chmod -R u+w .|' "deps/CMakeLists.txt"
41+ '';
42+
43+ buildPhase = "# do nothing";
44+ configurePhase = "# do nothing";
45+ installPhase = ''
46+ mkdir -p "$out"
47+ cp -r * "$out"
48+ '';
49+}