From patchwork Sun Jun 7 20:19:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Maja_K=C4=85dzio=C5=82ka?= X-Patchwork-Id: 22598 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E126727BBE1; Sun, 7 Jun 2020 21:20:08 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 245F027BBE3 for ; Sun, 7 Jun 2020 21:20:08 +0100 (BST) Received: from localhost ([::1]:34828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ji1m3-0006PE-Nb for patchwork@mira.cbaines.net; Sun, 07 Jun 2020 16:20:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ji1ly-0006Oz-Bh for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:43481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ji1ly-0002Zw-2U for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ji1lx-00044v-Ux for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40267] [PATCH v2 1/2] gnu: Add unicorn. References: <20200328005052.22846-1-kuba@kadziolka.net> In-Reply-To: <20200328005052.22846-1-kuba@kadziolka.net> Resent-From: Jakub =?utf-8?b?S8SFZHppb8WCa2E=?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 07 Jun 2020 20:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40267 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40267@debbugs.gnu.org Cc: leo@famulari.name Received: via spool by 40267-submit@debbugs.gnu.org id=B40267.159156119015641 (code B ref 40267); Sun, 07 Jun 2020 20:20:01 +0000 Received: (at 40267) by debbugs.gnu.org; 7 Jun 2020 20:19:50 +0000 Received: from localhost ([127.0.0.1]:55025 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ji1ll-00044D-OC for submit@debbugs.gnu.org; Sun, 07 Jun 2020 16:19:50 -0400 Received: from pat.zlotemysli.pl ([37.59.186.212]:55150) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ji1lk-000443-7e for 40267@debbugs.gnu.org; Sun, 07 Jun 2020 16:19:48 -0400 Received: (qmail 15304 invoked by uid 1009); 7 Jun 2020 22:19:46 +0200 Received: from 188.123.215.55 (kuba@kadziolka.net@188.123.215.55) by pat.zlotemysli.pl (envelope-from , uid 1002) with qmail-scanner-2.08st (clamdscan: 0.98.6/25835. spamassassin: 3.4.0. perlscan: 2.08st. Clear:RC:1(188.123.215.55):. Processed in 0.071735 secs); 07 Jun 2020 20:19:46 -0000 Received: from unknown (HELO localhost.localdomain) (kuba@kadziolka.net@188.123.215.55) by pat.zlotemysli.pl with AES256-SHA encrypted SMTP; 7 Jun 2020 22:19:46 +0200 From: Jakub =?utf-8?b?S8SFZHppb8WCa2E=?= Date: Sun, 7 Jun 2020 22:19:40 +0200 Message-Id: <20200607201941.5044-1-kuba@kadziolka.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Qmailux-2.08st: added fake Content-Type header X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/emulators.scm (unicorn): New variable. --- Changes from v1: packaged a new -rc, which makes tests pass on ARM. Add an input for cross-binutils, and use it while running tests. Also, the new -rc doesn't need Python for build orchestration, so the python-2 input got dropped. The python-build-system phases hack got prefixed with a comment referencing the core-updates patch. gnu/packages/emulators.scm | 117 ++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/gnu/packages/emulators.scm b/gnu/packages/emulators.scm index 9798ac370e..a82df6e9b6 100644 --- a/gnu/packages/emulators.scm +++ b/gnu/packages/emulators.scm @@ -44,7 +44,9 @@ #:use-module (gnu packages boost) #:use-module (gnu packages backup) #:use-module (gnu packages cdrom) + #:use-module (gnu packages check) #:use-module (gnu packages compression) + #:use-module (gnu packages cross-base) #:use-module (gnu packages curl) #:use-module (gnu packages elf) #:use-module (gnu packages fonts) @@ -88,7 +90,8 @@ #:use-module (gnu packages web) #:use-module (guix build-system cmake) #:use-module (guix build-system glib-or-gtk) - #:use-module (guix build-system gnu)) + #:use-module (guix build-system gnu) + #:use-module (guix build-system python)) (define-public desmume (package @@ -1622,3 +1625,115 @@ derived from Gens. Project goals include clean source code, combined features from various forks of Gens, and improved platform portability.") (supported-systems '("i686-linux" "x86_64-linux")) (license license:gpl2+))) + +;; python-pwntools requires a -rc release of unicorn +(define-public unicorn + (let ((unless-x86 + (lambda (code) + (if (member (%current-system) '("x86_64-linux" "i686-linux")) + '() + code)))) + (package + (name "unicorn") + (version "1.0.2-rc4") + ;; NOTE: unicorn ships a bundled QEMU, but with a lot of custom modifications. + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/unicorn-engine/unicorn") + (commit version))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "17nyccgk7hpc4hab24yn57f1xnmr7kq4px98zbp2bkwcrxny8gwy")))) + (outputs '("out" "python")) + ;; The main library is not written in Python, but the build process has + ;; little in common with any defined build system, so we might as well + ;; build on top of python-build-system and make use of all + ;; the Python-specific phases that can be reused. + (build-system python-build-system) + (arguments + `(#:modules ((srfi srfi-26) + (guix build python-build-system) + (guix build utils)) + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'install-bindings-to-python-output + (lambda* (#:key outputs #:allow-other-keys) + ;; python-build-system will build the bindings and install them to + ;; the "out" output, so change the build-internal names of the + ;; outputs. + ;; + ;; TODO: remove this once #40469 lands, through the core-updates + ;; holding zone, on master. + (set-car! (assoc "out" outputs) "lib") + (set-car! (assoc "python" outputs) "out") + #t)) + (add-before 'build 'build-library + (lambda* (#:key inputs #:allow-other-keys) + (invoke "make" + "-j" (number->string (parallel-job-count)) + "UNICORN_STATIC=no" + "CC=gcc"))) + (add-after 'build-library 'install-library + (lambda* (#:key outputs #:allow-other-keys) + (invoke "make" "install" + "UNICORN_STATIC=no" + (string-append + "PREFIX=" + (assoc-ref outputs "lib"))))) + (add-before 'build 'prepare-bindings + (lambda* (#:key outputs #:allow-other-keys) + (chdir "bindings/python") + ;; Set this environment variable so that the Python bindings + ;; don't build their own copy of the shared object, but use + ;; a dummy value such that the bindings test suite uses the + ;; same mechanism for loading the library as any other user. + (setenv "LIBUNICORN_PATH" "1") + (substitute* "unicorn/unicorn.py" + (("_path_list = \\[.*") + (string-append + "_path_list = [\"" + (assoc-ref outputs "lib") + ;; eat the rest of the list + "/lib\"] + 0*["))) + #t)) + (add-before 'check 'check-library + (lambda* (#:key outputs #:allow-other-keys) + (for-each + (lambda (suite) + (with-directory-excursion + (string-append "../../tests/" suite) + (invoke "make" "test" "CC=gcc" + ,@(unless-x86 + '("AS=i686-unknown-linux-gnu-as" + "OBJCOPY=i686-unknown-linux-gnu-objcopy"))))) + '("unit" "regress")) + #t)) + (add-after 'install 'install-samples + (lambda* (#:key outputs #:allow-other-keys) + (let* ((python-samples (find-files "." "sample_.*")) + (c-samples (find-files "../../samples" ".*\\.c")) + (python-docdir + (string-append (assoc-ref outputs "out") + "/share/doc/unicorn/samples")) + (c-docdir + (string-append (assoc-ref outputs "lib") + "/share/doc/unicorn/samples"))) + (for-each (cut install-file <> c-docdir) c-samples) + (for-each (cut install-file <> python-docdir) python-samples) + #t)))))) + (native-inputs + ;; NOTE: cross-binutils needs to be wrapped with unless-x86, as otherwise + ;; the linker provided by the package will be used, circumventing the ld-wrapper. + `(,@(unless-x86 + `(("assembler-for-tests" ,(cross-binutils "i686-unknown-linux-gnu")))) + ("cmocka" ,cmocka) + ("hexdump-for-tests" ,util-linux))) + (home-page "http://www.unicorn-engine.org") + (synopsis "Unicorn CPU emulator framework") + (description + "Unicorn is a lightweight, multi-platform, multi-architecture CPU emulator +framework based on QEMU.") + (license license:gpl2+)))) From patchwork Sun Jun 7 20:19:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Maja_K=C4=85dzio=C5=82ka?= X-Patchwork-Id: 22599 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A4C4B27BBE3; Sun, 7 Jun 2020 21:20:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 045FE27BBE1 for ; Sun, 7 Jun 2020 21:20:15 +0100 (BST) Received: from localhost ([::1]:35036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ji1mA-0006Uu-JW for patchwork@mira.cbaines.net; Sun, 07 Jun 2020 16:20:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ji1ly-0006P5-P8 for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:43482) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ji1ly-0002a6-F6 for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ji1ly-000452-B0 for guix-patches@gnu.org; Sun, 07 Jun 2020 16:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40267] [WIP PATCH v2 2/2] gnu: Add python-pwntools. Resent-From: Jakub =?utf-8?b?S8SFZHppb8WCa2E=?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 07 Jun 2020 20:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40267 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40267@debbugs.gnu.org Cc: leo@famulari.name Received: via spool by 40267-submit@debbugs.gnu.org id=B40267.159156119815661 (code B ref 40267); Sun, 07 Jun 2020 20:20:02 +0000 Received: (at 40267) by debbugs.gnu.org; 7 Jun 2020 20:19:58 +0000 Received: from localhost ([127.0.0.1]:55027 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ji1lq-00044T-45 for submit@debbugs.gnu.org; Sun, 07 Jun 2020 16:19:58 -0400 Received: from pat.zlotemysli.pl ([37.59.186.212]:55152) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ji1lk-000444-8S for 40267@debbugs.gnu.org; Sun, 07 Jun 2020 16:19:52 -0400 Received: (qmail 15314 invoked by uid 1009); 7 Jun 2020 22:19:46 +0200 Received: from 188.123.215.55 (kuba@kadziolka.net@188.123.215.55) by pat.zlotemysli.pl (envelope-from , uid 1002) with qmail-scanner-2.08st (clamdscan: 0.98.6/25835. spamassassin: 3.4.0. perlscan: 2.08st. Clear:RC:1(188.123.215.55):. Processed in 0.067067 secs); 07 Jun 2020 20:19:46 -0000 Received: from unknown (HELO localhost.localdomain) (kuba@kadziolka.net@188.123.215.55) by pat.zlotemysli.pl with AES256-SHA encrypted SMTP; 7 Jun 2020 22:19:46 +0200 From: Jakub =?utf-8?b?S8SFZHppb8WCa2E=?= Date: Sun, 7 Jun 2020 22:19:41 +0200 Message-Id: <20200607201941.5044-2-kuba@kadziolka.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200607201941.5044-1-kuba@kadziolka.net> References: <20200607201941.5044-1-kuba@kadziolka.net> MIME-Version: 1.0 X-Qmailux-2.08st: added fake Content-Type header X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/cybersecurity.scm (python-pwntools): New variable. --- Changes from v1: added a patch to fix the installed commands' behavior when wrapped by Guix - exec doesn't fool Python's sys.argv[0]. Resolved the optional dependency on binutils for various architectures. Some unresolved questions here mentioned in the comments. I tried moving python-intervaltree out of bioinformatics.scm, but I couldn't find a good place for intervaltree (the C library) to go with it. python-xyz.scm feels wrong, since it's not in Python, and leaving it in bioinformatics.scm creates a cycle. gnu/local.mk | 1 + gnu/packages/cybersecurity.scm | 83 ++++++++++++++++++- .../python-pwntools-guix-wrappers.patch | 14 ++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/python-pwntools-guix-wrappers.patch diff --git a/gnu/local.mk b/gnu/local.mk index ae8a2275f7..4384ad952d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1431,6 +1431,7 @@ dist_patch_DATA = \ %D%/packages/patches/python-packaging-test-arch.patch \ %D%/packages/patches/python2-parameterized-docstring-test.patch \ %D%/packages/patches/python-paste-remove-timing-test.patch \ + %D%/packages/patches/python-pwntools-guix-wrappers.patch \ %D%/packages/patches/python-pycrypto-CVE-2013-7459.patch \ %D%/packages/patches/python-pycrypto-time-clock.patch \ %D%/packages/patches/python2-pygobject-2-gi-info-type-error-domain.patch \ diff --git a/gnu/packages/cybersecurity.scm b/gnu/packages/cybersecurity.scm index 8ded081c50..d45618e617 100644 --- a/gnu/packages/cybersecurity.scm +++ b/gnu/packages/cybersecurity.scm @@ -18,10 +18,20 @@ (define-module (gnu packages cybersecurity) #:use-module (guix download) + #:use-module (guix git-download) #:use-module (guix packages) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix build-system python) - #:use-module (gnu packages engineering)) + #:use-module (gnu packages) + #:use-module (gnu packages avr) + #:use-module (gnu packages bioinformatics) + #:use-module (gnu packages cross-base) + #:use-module (gnu packages emulators) + #:use-module (gnu packages engineering) + #:use-module (gnu packages python-crypto) + #:use-module (gnu packages python-web) + #:use-module (gnu packages python-xyz) + #:use-module (gnu packages time)) (define-public ropgadget (package @@ -43,3 +53,74 @@ gadgets in binaries. Some facilities are included for automatically generating chains of gadgets to execute system calls.") (license license:bsd-3))) + +(define-public python-pwntools + (package + (name "python-pwntools") + (version "4.1.1") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/Gallopsled/pwntools") + (commit version))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "101whqdfj415h0f4b9hz2jrwny44b0jdd9jmbh6rzz5w1yp41d5v")) + (patches (search-patches "python-pwntools-guix-wrappers.patch")))) + (build-system python-build-system) + (arguments + `(#:tests? #f)) ; Tests require networking and custom sshd configuration + (propagated-inputs + `(("paramiko" ,python-paramiko) + ("mako" ,python-mako) + ("pyelftools" ,python-pyelftools) + ("capstone" ,python-capstone) + ("ropgadget" ,ropgadget) + ("pyserial" ,python-pyserial) + ("requests" ,python-requests) + ("pygments" ,python-pygments) + ("pysocks" ,python-pysocks) + ("dateutil" ,python-dateutil) + ("packaging" ,python-packaging) + ("psutil" ,python-psutil) + ("intervaltree" ,python-intervaltree) + ("sortedcontainers" ,python-sortedcontainers) + ("unicorn" ,unicorn "python") + + ;; See https://docs.pwntools.com/en/stable/install/binutils.html + ;; All architectures recognized by pwntools are included. + ("binutils:aarch64" ,(cross-binutils "aarch64-linux-gnu")) + ("binutils:alpha" ,(cross-binutils "alpha-linux-gnu")) + ("binutils:arm" ,(cross-binutils "arm-linux-gnueabihf")) + ;; TODO: AVR binutils aren't detected, + ;; see https://github.com/Gallopsled/pwntools/pull/1536 + ("binutils:avr" ,avr-binutils) + ("binutils:cris" ,(cross-binutils "cris-linux-gnu")) + ("binutils:i686" ,(cross-binutils "i686-linux-gnu")) + ("binutils:ia64" ,(cross-binutils "ia64-linux-gnu")) + ("binutils:m68k" ,(cross-binutils "m68k-linux-gnu")) + ("binutils:mips" ,(cross-binutils "mipsel-linux-gnu")) + ("binutils:mips64" ,(cross-binutils "mips64el-linux-gnu")) + ;; TODO: MSP430 doesn't work for the same reason as AVR. + ("binutils:msp430" ,(cross-binutils "msp430")) + ("binutils:powerpc" ,(cross-binutils "powerpc-linux-gnu")) + ("binutils:powerpc64" ,(cross-binutils "powerpc64-linux-gnu")) + ;; TODO: Attempting to assemble code for arch='s390' complains + ;; about bfdname + ("binutils:s390" ,(cross-binutils "s390-linux-gnu")) + ("binutils:sparc" ,(cross-binutils "sparc-linux-gnu")) + ("binutils:sparc64" ,(cross-binutils "sparc64-linux-gnu")) + ;; TODO: Should VAX use a -linux-gnu target, or just "vax"? + ("binutils:vax" ,(cross-binutils "vax-linux-gnu")) + ("binutils:x86_64" ,(cross-binutils "x86_64-linux-gnu")))) + (native-inputs + `(("tox" ,python-tox))) + (home-page "https://github.com/Gallopsled/pwntools") + (synopsis "CTF framework and exploit development library") + (description "Pwntools is a CTF framework and exploit development library. +Written in Python, it is designed for rapid prototyping and development, and +intended to make exploit writing as simple as possible.") + ;; See LICENSE-pwntools.txt in the source distribution. + (license (list license:expat license:bsd-2 license:gpl2+)))) diff --git a/gnu/packages/patches/python-pwntools-guix-wrappers.patch b/gnu/packages/patches/python-pwntools-guix-wrappers.patch new file mode 100644 index 0000000000..b79a22320d --- /dev/null +++ b/gnu/packages/patches/python-pwntools-guix-wrappers.patch @@ -0,0 +1,14 @@ +Parse argv properly when the programs are wrapped by Guix. +======================================================================== +diff --git a/pwnlib/commandline/common.py b/pwnlib/commandline/common.py +index 75edfdcb..5249b6e6 100644 +--- a/pwnlib/commandline/common.py ++++ b/pwnlib/commandline/common.py +@@ -28,5 +28,7 @@ parser_commands = parser.add_subparsers(dest='command') + def main(file=sys.argv[0]): + import pwnlib.commandline.main + name = os.path.splitext(os.path.basename(file))[0] ++ if name.startswith('.') and name.endswith('-real'): ++ name = name[1:-5] + sys.argv.insert(1, name) + pwnlib.commandline.main.main()