commit:     412eaec7e9d11870fb4b831213d93f422b6b613c
Author:     John Helmert III <ajak <AT> gentoo <DOT> org>
AuthorDate: Tue Oct  5 20:35:25 2021 +0000
Commit:     John Helmert III <ajak <AT> gentoo <DOT> org>
CommitDate: Tue Oct  5 20:40:06 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=412eaec7

dev-util/rizin: add 0.3.0

Note that tests are restricted due to uncertainty about the licenses
of the test binaries.

Bug: https://bugs.gentoo.org/792357
Bug: https://bugs.gentoo.org/807067

Signed-off-by: John Helmert III <ajak <AT> gentoo.org>

 dev-util/rizin/Manifest                            |   1 +
 dev-util/rizin/files/rizin-0.3.0-md4-openssl.patch | 100 ++++++++++++++++
 .../rizin/files/rizin-0.3.0-typedb-prefix.patch    | 132 +++++++++++++++++++++
 dev-util/rizin/rizin-0.3.0.ebuild                  | 103 ++++++++++++++++
 4 files changed, 336 insertions(+)

diff --git a/dev-util/rizin/Manifest b/dev-util/rizin/Manifest
index 1327734a460..1b95d38c2f3 100644
--- a/dev-util/rizin/Manifest
+++ b/dev-util/rizin/Manifest
@@ -1,2 +1,3 @@
 DIST rizin-src-v0.2.1.tar.xz 51439132 BLAKE2B 
3ce048c5e93afa43b33bb7c36e7f7a96734886a44a67339c18b36de84b6e3dd015aa49fd048815bc7cb26a39bd3c44ebd00227fdb0c3dc9d9f07ff2ff1f1948d
 SHA512 
4d0a68971a8fe1de3860f8ee18197606f59c22d4c24f3fcce691c73b45c8fe8c356a9b411604e9c3d4e5bb01f695b6ead32cdc217134eb4ddfec76867c16c327
+DIST rizin-src-v0.3.0.tar.xz 64097204 BLAKE2B 
308037ce60ec6523f337580221ea265c912ff92032fc5e1c2ab37430eae5a16cc2e8efa74447a79735c7814a35d3b08e5fc2f548612a1553c5edc2f314d22df5
 SHA512 
68f71e612bd4df90c79ebd4cb26c3e09bb370ccd9e51f574f2687f940b3934d9bf417108f3f7e678cabc6ddba7402e0420aab569c24316e07b2b56ed33153ed3
 DIST rizin-testbins-a80fd0d56d538d07a05ef01e29c8cb430a4f9d72.tar.gz 119214206 
BLAKE2B 
33916d466d77aaa0aeb6b221529a570a2bd2ad07b59b45967d75a84e3efbbc8ca3b8fff9cd88d61598b4e785ead2f8bc58eb7c1cb31007c27e497d80f36e4d2d
 SHA512 
9b01a63ff281ac19b427e715d669e6080c4afdfd777ae762c30537c59bd2cdc2865adc1b34ccb61430b172e54995375b48bb35fd88f098b6a9839e9f3669fde4

diff --git a/dev-util/rizin/files/rizin-0.3.0-md4-openssl.patch 
b/dev-util/rizin/files/rizin-0.3.0-md4-openssl.patch
new file mode 100644
index 00000000000..d2c3135d1c7
--- /dev/null
+++ b/dev-util/rizin/files/rizin-0.3.0-md4-openssl.patch
@@ -0,0 +1,100 @@
+From 6a1edf5fb6967d57d1dcc8cf21ea3a6bbdf8a5b8 Mon Sep 17 00:00:00 2001
+From: wargio <[email protected]>
+Date: Sat, 2 Oct 2021 22:36:32 +0200
+Subject: [PATCH 1/2] Fix nullptr due missing small_block method when openssl
+ is used.
+
+---
+ librz/hash/algorithms/openssl_common.h | 42 ++++++++++++++++++++++++++
+ 1 file changed, 42 insertions(+)
+
+diff --git a/librz/hash/algorithms/openssl_common.h 
b/librz/hash/algorithms/openssl_common.h
+index b29a1ae1221..e2399cff68d 100644
+--- a/librz/hash/algorithms/openssl_common.h
++++ b/librz/hash/algorithms/openssl_common.h
+@@ -76,6 +76,46 @@ EVP_sha512
+               return true; \
+       }
+ 
++#define rz_openssl_plugin_small_block(pluginname, evpmd) \
++      static bool openssl_plugin_##pluginname##_small_block(const ut8 *data, 
ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) { \
++              rz_return_val_if_fail(data &&digest, false); \
++              const EVP_MD *evp_md = evpmd(); \
++              if (!evp_md) { \
++                      return false; \
++              } \
++              RzMsgDigestSize dgst_size = EVP_MD_size(evp_md); \
++              ut8 *dgst = malloc(dgst_size); \
++              if (!dgst) { \
++                      return false; \
++              } \
++              EVP_MD_CTX *context = EVP_MD_CTX_new(); \
++              if (!context) { \
++                      free(dgst); \
++                      return false; \
++              } \
++              if (EVP_DigestInit_ex(context, evp_md, NULL) != 1) { \
++                      EVP_MD_CTX_free(context); \
++                      free(dgst); \
++                      return false; \
++              } \
++              if (EVP_DigestUpdate(context, data, size) != 1) { \
++                      EVP_MD_CTX_free(context); \
++                      free(dgst); \
++                      return false; \
++              } \
++              if (EVP_DigestFinal_ex(context, dgst, NULL) != 1) { \
++                      EVP_MD_CTX_free(context); \
++                      free(dgst); \
++                      return false; \
++              } \
++              *digest = dgst; \
++              if (digest_size) { \
++                      *digest_size = dgst_size; \
++              } \
++              EVP_MD_CTX_free(context); \
++              return true; \
++      }
++
+ #define rz_openssl_plugin_define_msg_digest(pluginname, evpmd, canhmac) \
+       rz_openssl_plugin_context_new(pluginname); \
+       rz_openssl_plugin_context_free(pluginname); \
+@@ -84,6 +124,7 @@ EVP_sha512
+       rz_openssl_plugin_init(pluginname, evpmd); \
+       rz_openssl_plugin_update(pluginname); \
+       rz_openssl_plugin_final(pluginname); \
++      rz_openssl_plugin_small_block(pluginname, evpmd); \
+       RzMsgDigestPlugin rz_msg_digest_plugin_##pluginname = { \
+               .name = #pluginname, \
+               .license = "Apache 2.0", \
+@@ -96,6 +137,7 @@ EVP_sha512
+               .init = openssl_plugin_##pluginname##_init, \
+               .update = openssl_plugin_##pluginname##_update, \
+               .final = openssl_plugin_##pluginname##_final, \
++              .small_block = openssl_plugin_##pluginname##_small_block, \
+       }
+ 
+ #endif /* RZ_OPENSSL_COMMON_H */
+
+From f4a8e2c86be861f33327c2a8f1d181b42232069e Mon Sep 17 00:00:00 2001
+From: wargio <[email protected]>
+Date: Sat, 2 Oct 2021 23:07:54 +0200
+Subject: [PATCH 2/2] Fix style
+
+---
+ librz/hash/algorithms/openssl_common.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/librz/hash/algorithms/openssl_common.h 
b/librz/hash/algorithms/openssl_common.h
+index e2399cff68d..0091fef2fa3 100644
+--- a/librz/hash/algorithms/openssl_common.h
++++ b/librz/hash/algorithms/openssl_common.h
+@@ -78,7 +78,7 @@ EVP_sha512
+ 
+ #define rz_openssl_plugin_small_block(pluginname, evpmd) \
+       static bool openssl_plugin_##pluginname##_small_block(const ut8 *data, 
ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) { \
+-              rz_return_val_if_fail(data &&digest, false); \
++              rz_return_val_if_fail((data) && (digest), false); \
+               const EVP_MD *evp_md = evpmd(); \
+               if (!evp_md) { \
+                       return false; \

diff --git a/dev-util/rizin/files/rizin-0.3.0-typedb-prefix.patch 
b/dev-util/rizin/files/rizin-0.3.0-typedb-prefix.patch
new file mode 100644
index 00000000000..dfb86447df7
--- /dev/null
+++ b/dev-util/rizin/files/rizin-0.3.0-typedb-prefix.patch
@@ -0,0 +1,132 @@
+https://github.com/rizinorg/rizin/issues/1789
+
+Signed-off-by: Florian Märkl <[email protected]>
+
+diff --git a/test/unit/test_serialize_analysis.c 
b/test/unit/test_serialize_analysis.c
+index 51092c067..0d714ba90 100644
+--- a/test/unit/test_serialize_analysis.c
++++ b/test/unit/test_serialize_analysis.c
+@@ -546,7 +546,10 @@ Sdb *vars_ref_db() {
+ }
+ 
+ bool test_analysis_var_save() {
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       RzAnalysis *analysis = rz_analysis_new();
+       rz_analysis_use(analysis, "x86");
+       rz_analysis_set_bits(analysis, 64);
+diff --git a/test/unit/test_type.c b/test/unit/test_type.c
+index d8a3d9c5f..3956a800b 100644
+--- a/test/unit/test_type.c
++++ b/test/unit/test_type.c
+@@ -379,7 +379,10 @@ static bool test_enum_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -417,7 +420,10 @@ static bool test_const_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -469,7 +475,10 @@ static bool test_type_as_string(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -516,7 +525,10 @@ static bool test_array_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -569,7 +581,10 @@ static bool test_struct_func_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -659,7 +674,10 @@ static bool test_struct_array_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -707,7 +725,10 @@ static bool 
test_struct_identifier_without_specifier(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -735,7 +756,10 @@ static bool test_union_identifier_without_specifier(void) 
{
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;
+@@ -767,7 +791,10 @@ static bool test_edit_types(void) {
+       RzTypeDB *typedb = rz_type_db_new();
+       mu_assert_notnull(typedb, "Couldn't create new RzTypeDB");
+       mu_assert_notnull(typedb->types, "Couldn't create new types hashtable");
+-      const char *dir_prefix = rz_sys_prefix(NULL);
++      const char *dir_prefix = getenv("RZ_PREFIX");
++      if (!dir_prefix) {
++              dir_prefix = rz_sys_prefix(NULL);
++      }
+       rz_type_db_init(typedb, dir_prefix, "x86", 64, "linux");
+ 
+       char *error_msg = NULL;

diff --git a/dev-util/rizin/rizin-0.3.0.ebuild 
b/dev-util/rizin/rizin-0.3.0.ebuild
new file mode 100644
index 00000000000..0ac6575d67e
--- /dev/null
+++ b/dev-util/rizin/rizin-0.3.0.ebuild
@@ -0,0 +1,103 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+PYTHON_COMPAT=(python3_{8,9,10})
+
+# This is the commit that the CI for the release commit used
+BINS_COMMIT="d4cee85f3e94f1151dc9ff1681555ebcff7931f0"
+
+inherit meson python-any-r1
+
+DESCRIPTION="reverse engineering framework for binary analysis"
+HOMEPAGE="https://rizin.re/";
+
+SRC_URI="https://github.com/rizinorg/rizin/releases/download/v${PV}/rizin-src-v${PV}.tar.xz";
+       #test? ( 
https://github.com/rizinorg/rizin-testbins/archive/${BINS_COMMIT}.tar.gz -> 
rizin-testbins-${BINS_COMMIT}.tar.gz )"
+KEYWORDS="~amd64 ~arm64 ~x86"
+
+LICENSE="Apache-2.0 BSD LGPL-3 MIT"
+SLOT="0"
+IUSE="test"
+
+# Need to audit licenses of the binaries used for testing
+RESTRICT="test"
+
+RDEPEND="
+       sys-apps/file
+       app-arch/lz4:0=
+       dev-libs/capstone:0=
+       dev-libs/libuv:0=
+       dev-libs/libzip:0=
+       dev-libs/openssl:0=
+       >=dev-libs/tree-sitter-0.19.0
+       dev-libs/xxhash
+       sys-libs/zlib:0=
+"
+DEPEND="${RDEPEND}"
+BDEPEND="${PYTHON_DEPS}"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-${PV}-typedb-prefix.patch"
+       "${FILESDIR}/${PN}-${PV}-md4-openssl.patch"
+)
+
+S="${WORKDIR}/${PN}-v${PV}"
+
+src_prepare() {
+       default
+
+       local py_to_mangle=(
+               librz/core/cmd_descs/cmd_descs_generate.py
+               
subprojects/lz4-1.9.3/contrib/meson/meson/GetLz4LibraryVersion.py
+               subprojects/lz4-1.9.3/contrib/meson/meson/InstallSymlink.py
+               subprojects/lz4-1.9.3/tests/test-lz4-list.py
+               subprojects/lz4-1.9.3/tests/test-lz4-speed.py
+               subprojects/lz4-1.9.3/tests/test-lz4-versions.py
+               sys/clang-format.py
+               test/fuzz/scripts/fuzz_rz_asm.py
+               test/scripts/gdbserver.py
+       )
+
+       python_fix_shebang "${py_to_mangle[@]}"
+
+       if use test; then
+               cp -r "${WORKDIR}/rizin-testbins-${BINS_COMMIT}" 
"${S}/test/bins" || die
+               cp -r "${WORKDIR}/rizin-testbins-${BINS_COMMIT}" "${S}" || die
+       fi
+}
+
+src_configure() {
+       local emesonargs=(
+               -Dcli=enabled
+               -Duse_sys_capstone=enabled
+               -Duse_sys_magic=enabled
+               -Duse_sys_libzip=enabled
+               -Duse_sys_zlib=enabled
+               -Duse_sys_lz4=enabled
+               -Duse_sys_xxhash=enabled
+               -Duse_sys_openssl=enabled
+               -Duse_sys_tree_sitter=enabled
+
+               $(meson_use test enable_tests)
+               $(meson_use test enable_rz_test)
+       )
+       meson_src_configure
+}
+
+src_test() {
+       # Rizin uses data files that it expects to be installed on the
+       # system. To hack around this, we create a tree of what it expects
+       # in ${T}, and patch the tests to support a prefix from the
+       # environment. https://github.com/rizinorg/rizin/issues/1789
+       mkdir -p "${T}/usr/share/${PN}/${PV}" || die
+       ln -sf "${BUILD_DIR}/librz/analysis/d" 
"${T}/usr/share/${PN}/${PV}/types" || die
+       ln -sf "${BUILD_DIR}/librz/syscall/d" 
"${T}/usr/share/${PN}/${PV}/syscall" || die
+       ln -sf "${BUILD_DIR}/librz/asm/d" "${T}/usr/share/${PN}/${PV}/opcodes" 
|| die
+       # https://github.com/rizinorg/rizin/issues/1797
+       ln -sf "${BUILD_DIR}/librz/flag/d" "${T}/usr/share/${PN}/${PV}/flag" || 
die
+       export RZ_PREFIX="${T}/usr"
+
+       meson_src_test
+}

Reply via email to