diff -Nru afflib-3.7.7/compile afflib-3.7.16/compile --- afflib-3.7.7/compile 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/compile 1970-01-01 00:00:00.000000000 +0000 @@ -1,136 +0,0 @@ -#! /bin/sh -# Wrapper for compilers which do not understand `-c -o'. - -scriptversion=2003-11-09.00 - -# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc. -# Written by Tom Tromey . -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# This file is maintained in Automake, please report -# bugs to or send patches to -# . - -case $1 in - '') - echo "$0: No command. Try \`$0 --help' for more information." 1>&2 - exit 1; - ;; - -h | --h*) - cat <<\EOF -Usage: compile [--help] [--version] PROGRAM [ARGS] - -Wrapper for compilers which do not understand `-c -o'. -Remove `-o dest.o' from ARGS, run PROGRAM with the remaining -arguments, and rename the output as expected. - -If you are trying to build a whole package this is not the -right script to run: please start by reading the file `INSTALL'. - -Report bugs to . -EOF - exit 0 - ;; - -v | --v*) - echo "compile $scriptversion" - exit 0 - ;; -esac - - -prog=$1 -shift - -ofile= -cfile= -args= -while test $# -gt 0; do - case "$1" in - -o) - # configure might choose to run compile as `compile cc -o foo foo.c'. - # So we do something ugly here. - ofile=$2 - shift - case "$ofile" in - *.o | *.obj) - ;; - *) - args="$args -o $ofile" - ofile= - ;; - esac - ;; - *.c) - cfile=$1 - args="$args $1" - ;; - *) - args="$args $1" - ;; - esac - shift -done - -if test -z "$ofile" || test -z "$cfile"; then - # If no `-o' option was seen then we might have been invoked from a - # pattern rule where we don't need one. That is ok -- this is a - # normal compilation that the losing compiler can handle. If no - # `.c' file was seen then we are probably linking. That is also - # ok. - exec "$prog" $args -fi - -# Name of file we expect compiler to create. -cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` - -# Create the lock directory. -# Note: use `[/.-]' here to ensure that we don't use the same name -# that we are using for the .o file. Also, base the name on the expected -# object file name, since that is what matters with a parallel build. -lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d -while true; do - if mkdir $lockdir > /dev/null 2>&1; then - break - fi - sleep 1 -done -# FIXME: race condition here if user kills between mkdir and trap. -trap "rmdir $lockdir; exit 1" 1 2 15 - -# Run the compile. -"$prog" $args -status=$? - -if test -f "$cofile"; then - mv "$cofile" "$ofile" -fi - -rmdir $lockdir -exit $status - -# Local Variables: -# mode: shell-script -# sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff -Nru afflib-3.7.7/configure.ac afflib-3.7.16/configure.ac --- afflib-3.7.7/configure.ac 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/configure.ac 2017-06-24 00:57:09.000000000 +0000 @@ -4,7 +4,7 @@ # See http://autotoolset.sourceforge.net/tutorial.html # and http://www.openismus.com/documents/linux/automake/automake.shtml -AC_INIT([AFFLIB],[3.7.7],[https://github.com/sshock/AFFLIBv3]) +AC_INIT([AFFLIB],[3.7.16],[https://github.com/sshock/AFFLIBv3]) AM_INIT_AUTOMAKE AM_MAINTAINER_MODE @@ -28,17 +28,16 @@ # We are now threading m4_include([m4/acx_pthread.m4]) -m4_include([m4/acinclude.m4]) ACX_PTHREAD() if test x"${cross_compiling}" = "xno" ; then # Bring additional directories where things might be found into our # search path. I don't know why autoconf doesn't do this by default - for spfx in /usr/local /opt/local /sw ${prefix} ; do + for spfx in ${prefix} /sw /opt/local /usr/local ; do AC_MSG_NOTICE([checking ${spfx}/include]) if test -d ${spfx}/include; then - CPPFLAGS="-I${spfx}/include $CPPFLAGS" - LDFLAGS="-L${spfx}/lib $LDFLAGS" + CPPFLAGS="$CPPFLAGS -I${spfx}/include" + LDFLAGS="$LDFLAGS -L${spfx}/lib" AC_MSG_NOTICE([ *** ADDING ${spfx}/include to CPPFLAGS *** ]) AC_MSG_NOTICE([ *** ADDING ${spfx}/lib to LDFLAGS *** ]) fi @@ -81,7 +80,7 @@ # Specific headers that I plan to use -AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h dmalloc.h err.h errno.h fcntl.h getopt.h inttypes.h linux/fs.h malloc.h netinet/in.h regex.h signal.h stdint.h stdio.h stdlib.h string.h sys/cdefs.h sys/disk.h sys/file.h sys/ioctl.h sys/ioctl.h sys/param.h sys/param.h sys/socket.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/vfs.h sysexits.h term.h time.h unistd.h zlib.h _mingw.h]) +AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h dmalloc.h err.h errno.h fcntl.h getopt.h inttypes.h linux/fs.h malloc.h netinet/in.h regex.h signal.h stdint.h stdio.h stdlib.h string.h sys/cdefs.h sys/disk.h sys/file.h sys/ioctl.h sys/ioctl.h sys/param.h sys/param.h sys/socket.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/vfs.h sysexits.h time.h unistd.h zlib.h _mingw.h]) AC_CHECK_LIB([regex],[regcomp]) # see if we need -lregex @@ -113,53 +112,57 @@ ################################################################ # For AFF tools AC_CHECK_HEADERS([readline/readline.h]) -AC_CHECK_HEADERS([curses.h termcap.h]) AC_CHECK_LIB([readline],[readline],, AC_MSG_RESULT([readline not installed])) AC_CHECK_LIB([z],[uncompress],, AC_MSG_ERROR([zlib not installed; cannot continue. Try adding zlib-dev or zlib1g-dev.])) AC_CHECK_LIB([rt],[aio_error64]) -AC_SEARCH_LIBS(tgetent, termlib termcap curses) -AC_CHECK_FUNCS(putp tputs tgoto tgetstr tgetnum gotorc beep endwin setupterm printw) ################################################################ ## Expat ## Required for S3 and Digital Signatures -## -AC_ARG_WITH(expat, - AS_HELP_STRING([--with-expat=PATH], [where libexpat is compiled (if it isn't installed); required for S3 and Digital Signatures]), - [LDFLAGS="-L${with_expat} $LDFLAGS" ; - CPPFLAGS="-I${with_expat}/lib $CPPFLAGS"]) - -have_expat=yes -AC_CHECK_HEADER([expat.h]) -AC_CHECK_LIB([expat],[XML_ParserCreate],,[have_expat="no ";AC_MSG_WARN([expat not found; S3 and Digital Signatures not enabled])]) - +AC_ARG_WITH([expat], + AS_HELP_STRING([--with-expat], [build with expat; required for S3 and Digital Signatures @<:@default=check@:>@]), + [], [with_expat=check]) + +have_expat=no +AS_IF([test "x$with_expat" != xno], + [AC_CHECK_HEADER([expat.h], + [AC_CHECK_LIB([expat], [XML_ParserCreate])]) + have_expat=${ac_cv_lib_expat_XML_ParserCreate-no} + AS_IF([test "x$with_expat" != xcheck && test "x$have_expat" = xno], + [AC_MSG_FAILURE([--with-expat was given but test for expat failed])])]) ################################################################ ## LZMA (always enabled) AC_DEFINE(USE_LZMA, 1, [Enable LZMA compression]) +################################################################ +## curl +## Required for S3 +AC_ARG_WITH([curl], + AS_HELP_STRING([--with-curl], [build with curl; required for S3 @<:@default=check@:>@]), + [], [with_curl=check]) + +have_curl=no +AS_IF([test "x$with_curl" != xno], + [AC_CHECK_HEADER([curl/curl.h], + [AC_CHECK_LIB([curl], [curl_global_init],,)],) + have_curl=${ac_cv_lib_curl_curl_global_init-no} + AS_IF([test "x$with_curl" != xcheck && test "x$have_curl" = xno], + [AC_MSG_FAILURE([--with-curl was given but test for curl failed])])]) ################################################################ ## Amazon S3 ## S3 requires curl and expat; otherwise we don't need them -AC_ARG_ENABLE(s3, - AC_HELP_STRING([--enable-s3=yes], - [Support for Amazon S3 service. Requires CURL and Expat.]), - [enable_s3=$enableval], [enable_s3=no]) - -if test "x${enable_s3}" = "xyes" ; then - AC_MSG_NOTICE([S3 support requested. Looking for curl and expat...]) - AC_PATH_PROG(CURL_CONFIG,curl-config) - AC_ARG_WITH(curl, - AC_HELP_STRING([--with-curl=PATH], [where libcurl is installed; required for S3]), - [CURL_CONFIG="${with_curl}/bin/curl-config"]) - AC_CHECK_HEADER([curl/curl.h],, - AC_MSG_WARN([curl/curl.h not found; Disabling S3 Support.]) - enable_s3=no) - AC_CHECK_LIB([curl],[curl_global_init],, - AC_MSG_WARN([Curl library corrupt; Disabling S3 Support.]) - enable_s3=no) -fi +AC_ARG_ENABLE([s3], + AC_HELP_STRING([--enable-s3], [Support for Amazon S3 service. Requires CURL and Expat. @<:@default=check@:>@]), + [enable_s3=$enableval], [enable_s3=check]) + +AS_IF([test "x$enable_s3" != xno], + [AS_IF([test "x$have_expat" = xyes && test "x$have_curl" = xyes], + [enable_s3=yes], + [AS_IF([test "x$enable_s3" = xcheck], + [enable_s3=no], + [AC_MSG_FAILURE([--enable-s3 was given but required libraries are not found])])])]) S3_BIN= if test "x${enable_s3}" = "xyes" ; then @@ -198,13 +201,11 @@ ### PyAFF ################################################################ # python checks -# (requires autoconf 1.5+ and the macros in acinclude.m4) AC_ARG_ENABLE([python], AC_HELP_STRING([--enable-python=no], [Build python bindings (pyaff)]), [enable_python=$enableval], [enable_python=no]) if test "${enable_python}" = "yes" ; then - AM_PATH_PYTHON([2.5]) - AC_PYTHON_DEVEL() + AM_PATH_PYTHON() AC_DEFINE([HAVE_PYTHON],1,[Build Python bindings]) fi @@ -229,34 +230,37 @@ AC_CHECK_LIB([md],[MD5]) # if libmd is available, get it -AC_CHECK_FUNCS([MD5 SHA1 AES_encrypt RAND_pseudo_bytes des_read_pw_string EVP_read_pw_string EVP_MD_size]) +AC_CHECK_FUNCS([MD5 SHA1 AES_encrypt RAND_bytes des_read_pw_string EVP_read_pw_string EVP_MD_size]) AC_CHECK_FUNCS([PEM_read_bio_RSA_PUBKEY]) ################################################################ ## FUSE: Filesystem in Userspace AC_ARG_ENABLE(fuse, - AC_HELP_STRING([--enable-fuse=yes], - [Support for FUSE, Filesystem in Userspace. (default yes)]), - [enable_fuse=$enableval], [enable_fuse=yes]) -if test "x${enable_fuse}" = "xyes" ; then - AC_MSG_NOTICE([FUSE requested]) - CPPFLAGS="-D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26 $CPPFLAGS" - if test `uname -s` = Darwin ; then - AC_MSG_NOTICE([FUSE IS NOT SUPPORTED ON MACOS]) - enable_fuse=no - fi - AC_CHECK_HEADER([fuse.h],, - AC_MSG_NOTICE([fuse.h not found; Disabling FUSE support.]) - enable_fuse=no) - AC_SUBST(FUSE_LIBS) - AC_SUBST(FUSE_CFLAGS) -fi + AC_HELP_STRING([--enable-fuse], [Support for FUSE, Filesystem in Userspace. @<:@default=check@:>@]), + [enable_fuse=$enableval], [enable_fuse=check]) + +have_fuse=no +AS_IF([test "x$enable_fuse" != xno], + [CPPFLAGS="-D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26 $CPPFLAGS" + AC_CHECK_HEADER([fuse.h], + [AC_CHECK_LIB([fuse], [fuse_version], + [FUSE_LIBS=-lfuse + have_fuse=yes])]) + AS_IF([test `uname -s` = Darwin && test "x$have_fuse" != "xyes"], + [m4_ifdef([PKG_CHECK_MODULES], + [PKG_CHECK_MODULES([FUSE], [fuse], + [have_fuse=yes], + [:])])]) + AS_IF([test "x$enable_fuse" != xcheck && test "x$have_fuse" = xno], + [AC_MSG_FAILURE([--enable-fuse was given but test for fuse failed])])]) +enable_fuse=$have_fuse + AFFUSE_BIN= -if test "${enable_fuse}" = "yes"; then - AC_DEFINE([USE_FUSE],1,[Use FUSE to mount AFF images]) - AFFUSE_BIN='affuse$(EXEEXT)' - FUSE_LIBS=-lfuse -fi +AS_IF([test "x${enable_fuse}" = "xyes"], + [AC_SUBST(FUSE_LIBS) + AC_SUBST(FUSE_CFLAGS) + AC_DEFINE([USE_FUSE],1,[Use FUSE to mount AFF images]) + AFFUSE_BIN='affuse$(EXEEXT)']) AC_SUBST(AFFUSE_BIN) AM_PROG_CC_C_O dnl for affuse ## diff -Nru afflib-3.7.7/debian/changelog afflib-3.7.16/debian/changelog --- afflib-3.7.7/debian/changelog 2015-12-02 13:23:50.000000000 +0000 +++ afflib-3.7.16/debian/changelog 2021-05-04 20:40:25.000000000 +0000 @@ -1,3 +1,136 @@ +afflib (3.7.16-2build2~16.04.sav0) xenial; urgency=medium + + * Backport to Xenial + + -- Rob Savoury Tue, 04 May 2021 13:40:25 -0700 + +afflib (3.7.16-2build2) bionic; urgency=medium + + * No-change rebuild against libcurl4 + + -- Steve Langasek Wed, 28 Feb 2018 06:41:56 +0000 + +afflib (3.7.16-2build1) bionic; urgency=high + + * No change rebuild against openssl1.1. + + -- Dimitri John Ledkov Mon, 05 Feb 2018 16:48:32 +0000 + +afflib (3.7.16-2) unstable; urgency=medium + + * Upload to unstable. + + -- Joao Eriberto Mota Filho Wed, 19 Jul 2017 21:51:23 -0300 + +afflib (3.7.16-1) experimental; urgency=medium + + * New upstream release. + * debian/copyright: updated the upstream copyright years. + * debian/README.source: created to explain about manpages. + + -- Joao Eriberto Mota Filho Wed, 19 Jul 2017 09:45:30 -0300 + +afflib (3.7.15-2) experimental; urgency=medium + + * debian/control: + - Bumped Standards-Version to 4.0.0. + - Removed obsolete dbg binary. + * debian/libafflib0v5.symbols: fixed symbols to avoid a FTBFS. (see #853301) + * debian/rules: dropped an override about no longer needed dbg binary. + + -- Joao Eriberto Mota Filho Sat, 24 Jun 2017 18:50:33 -0300 + +afflib (3.7.15-1) unstable; urgency=medium + + * New upstream release. + * debian/copyright: + - Moved lib/{afflib.h, afflib_i.h, aftimer.h, utils.h} to include/afflib/, + because the upstream changed the source code. + - Removed rights for pyaff/pyaff.c, now generated automatically. + - Updated rights for some files. + - Updated the packaging copyright years. + + -- Joao Eriberto Mota Filho Mon, 02 Jan 2017 16:20:38 -0200 + +afflib (3.7.13-1) unstable; urgency=medium + + * New upstream release. + * debian/copyright: + - Fixed some licensing issues. + - Grouped some blocks that use the same licensing, to simplify the file. + * debian/source/options: no longer necessary. Removed. + * debian/watch: removed the unnecessary opts line. + + -- Joao Eriberto Mota Filho Mon, 28 Nov 2016 11:29:45 -0200 + +afflib (3.7.10-2) unstable; urgency=medium + + * Provided the static library in development package (requested by + upstream). To do it, enabled --enable-static in debian/rules and + changed the debian/libafflib-dev.install file. + + -- Joao Eriberto Mota Filho Thu, 24 Nov 2016 16:55:09 -0200 + +afflib (3.7.10-1) unstable; urgency=medium + + * New upstream release. (Closes: 828228) + * Migrate DH level to 10. + + -- Joao Eriberto Mota Filho Fri, 07 Oct 2016 22:21:49 -0300 + +afflib (3.7.8-1) unstable; urgency=medium + + * New upstream release. + * debian/changelog: updated the upstream copyright years. + + -- Joao Eriberto Mota Filho Tue, 23 Aug 2016 23:19:19 -0300 + +afflib (3.7.7+git20160511.4fd23a-2) unstable; urgency=medium + + * Upload to unstable. + * Reverted to default GCC provided by Debian. + + -- Joao Eriberto Mota Filho Mon, 16 May 2016 08:49:30 -0300 + +afflib (3.7.7+git20160511.4fd23a-1) experimental; urgency=medium + + * New upstream release. + * Force temporarily to build using GCC-6. + * debian/patches/: removed all patches. The upstream + fixed the source code. Thanks! + * debian/watch: added a temporary dversionmangle. + + -- Joao Eriberto Mota Filho Sat, 14 May 2016 21:58:23 -0300 + +afflib (3.7.7-5) unstable; urgency=medium + + * Upload to unstable. + + -- Joao Eriberto Mota Filho Sun, 01 May 2016 13:55:15 -0300 + +afflib (3.7.7-4) experimental; urgency=medium + + * debian/control: + - Bumped Standards-Version to 3.9.8. + - Changed from cgit to git in Vcs-Browser field. + - Fixed a spelling error in long description. + - Updated the Vcs-* fields to use https instead of http and git. + * debian/copyright: updated the packaging copyright years. + * debian/patches/: + - Added two patches to fix spelling errors. They are + 10_fix_spelling_errors_in_source_code.patch and + 20_fix_spelling_in_manpage.patch. + - 30_fix_gcc_warnings_literal-suffix.patch: added to fix some + specific GCC warnings. + - 40_fix_gcc_warnings_misleading-indentation.patch: added to fix + some specific GCC warnings. + * debian/libafflib0v5.symbols: removed some symbols to be compliant + with GCC 6. Thanks to Martin Michlmayr . + (Closes: #811966) + * debian/watch: bumped to version 4. + + -- Joao Eriberto Mota Filho Sat, 30 Apr 2016 15:08:34 -0300 + afflib (3.7.7-3) unstable; urgency=medium * Upload to unstable. (Closes: #803695) diff -Nru afflib-3.7.7/debian/compat afflib-3.7.16/debian/compat --- afflib-3.7.7/debian/compat 2014-09-29 21:38:24.000000000 +0000 +++ afflib-3.7.16/debian/compat 2016-10-08 01:21:49.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru afflib-3.7.7/debian/control afflib-3.7.16/debian/control --- afflib-3.7.7/debian/control 2015-10-11 11:35:06.000000000 +0000 +++ afflib-3.7.16/debian/control 2018-02-05 16:48:32.000000000 +0000 @@ -1,9 +1,10 @@ Source: afflib Section: libs Priority: optional -Maintainer: Debian Forensics +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Debian Forensics Uploaders: Joao Eriberto Mota Filho -Build-Depends: debhelper (>= 9), +Build-Depends: debhelper (>= 10), dh-autoreconf, chrpath, libcurl4-openssl-dev, @@ -11,10 +12,10 @@ libfuse-dev [!hurd-i386], libssl-dev, zlib1g-dev -Standards-Version: 3.9.6 +Standards-Version: 4.0.0 Homepage: https://github.com/sshock/AFFLIBv3 -Vcs-Browser: https://anonscm.debian.org/cgit/forensics/afflib.git -Vcs-Git: git://anonscm.debian.org/forensics/afflib.git +Vcs-Browser: https://anonscm.debian.org/git/forensics/afflib.git +Vcs-Git: https://anonscm.debian.org/git/forensics/afflib.git Package: libafflib0v5 Architecture: any @@ -27,7 +28,7 @@ . - AFF allows you to store both computer forensic data and associated metadata in one or more files. - - AFF allows files to be digital singed, to provide for + - AFF allows files to be digital signed, to provide for chain-of-custody and long-term file integrity. - AFF allows for forensic disk images to stored encrypted and decrypted on-the-fly for processing. This allows disk images @@ -44,7 +45,7 @@ . - AFF allows you to store both computer forensic data and associated metadata in one or more files. - - AFF allows files to be digital singed, to provide for + - AFF allows files to be digital signed, to provide for chain-of-custody and long-term file integrity. - AFF allows for forensic disk images to stored encrypted and decrypted on-the-fly for processing. This allows disk images @@ -52,28 +53,6 @@ . This package provides the development files. -Package: afflib-dbg -Section: debug -Priority: extra -Architecture: any -Depends: ${misc:Depends}, - afflib-tools (= ${binary:Version}), - libafflib0v5 (= ${binary:Version}), - libafflib-dev (= ${binary:Version}) -Description: Advanced Forensics Format Library (debug version) - The Advanced Forensic Format (AFF) is on-disk format for storing - computer forensic information. Critical features of AFF include: - . - - AFF allows you to store both computer forensic data and associated - metadata in one or more files. - - AFF allows files to be digital singed, to provide for - chain-of-custody and long-term file integrity. - - AFF allows for forensic disk images to stored encrypted and - decrypted on-the-fly for processing. This allows disk images - containing privacy sensitive material to be stored on the Internet. - . - This package provides the debugging symbols. - Package: afflib-tools Section: utils Architecture: any @@ -85,7 +64,7 @@ . - AFF allows you to store both computer forensic data and associated metadata in one or more files. - - AFF allows files to be digital singed, to provide for + - AFF allows files to be digital signed, to provide for chain-of-custody and long-term file integrity. - AFF allows for forensic disk images to stored encrypted and decrypted on-the-fly for processing. This allows disk images diff -Nru afflib-3.7.7/debian/copyright afflib-3.7.16/debian/copyright --- afflib-3.7.7/debian/copyright 2015-10-11 11:37:46.000000000 +0000 +++ afflib-3.7.16/debian/copyright 2017-07-19 12:45:30.000000000 +0000 @@ -3,34 +3,28 @@ Source: https://github.com/sshock/AFFLIBv3 Files: * -Copyright: 2012-2013 Simson L. Garfinkel - 2014-2015 Phillip Hellewell -License: Public_Domain_1 - - -Files: tools/aff_bom.cpp - tools/aff_bom.h - tools/affcrypto.cpp - tools/affdiskprint.cpp -Copyright: 2008 Simson L. Garfinkel - 2014-2015 Phillip Hellewell -License: Public_Domain_2 - +Copyright: 2005-2006 Igor Pavlov + 2008-2013 Simson L. Garfinkel + 2014-2017 Phillip Hellewell +License: public-domain Files: doc/FAQ.txt + include/afflib/afflib.h + include/afflib/afflib_i.h + include/afflib/aftimer.h + include/afflib/utils.h lib/aff_db.cpp lib/aff_db.h - lib/aff_toc.cpp lib/afflib.cpp - lib/afflib.h - lib/afflib_i.h lib/afflib_pages.cpp lib/afflib_stream.cpp lib/afflib_util.cpp + lib/aff_toc.cpp + lib/lzma_glue.cpp + lib/s3.cpp lib/s3_glue.cpp lib/s3_glue.h lib/utils.cpp - lib/utils.h lib/vnode_afd.cpp lib/vnode_afd.h lib/vnode_aff.cpp @@ -50,99 +44,77 @@ tools/affcopy.cpp tools/affinfo.cpp tools/affix.cpp -Copyright: 2005-2006 Simson L. Garfinkel - 2005-2006 Basis Technology, Inc. + tools/affuse.c +Copyright: 2005-2006 Basis Technology, Inc. + 2005-2012 Simson L. Garfinkel + 2007 Olivier Castan 2014-2015 Phillip Hellewell -License: BSD-4-clause - - -Files: lib/aftimer.h - lib/s3.cpp - lib/lzma_glue.cpp -Copyright: 2012 Simson L. Garfinkel - 2014 Phillip Hellewell -License: BSD-4-clause - +License: BSD-4-Clause Files: lzma443/* Copyright: 1999-2006 Igor Pavlov -License: LGPL-2.1+ or CPL or other - - -Files: lzma443/C/7zip/Compress/LZMA_C/LzmaStateTest.c +License: LGPL-2.1 or CPL-1.0 or special or proprietary +Comment: the lzma443/lzma.txt file says: + "LZMA SDK is available under any of the following licenses: + . + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + 3) Simplified license for unmodified code (read SPECIAL EXCEPTION) + 4) Proprietary license + . + It means that you can select one of these four options and follow + rules of that license." + +Files: lzma443/C/7zip/Compress/Branch/BranchTypes.h + lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp + lzma443/C/7zip/Compress/LZMA_C/LzmaStateTest.c lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c lzma443/C/7zip/Compress/LZMA_C/LzmaTypes.h -Copyright: 2005-2006 Igor Pavlov -License: Public_Domain_3 - - -Files: lib/qemu/block-vpc.c - lib/qemu/block-parallels.c - lib/qemu/block-bochs.c -Copyright: 2005-2007 Alex Beregszaszi -License: ISC - +Copyright: 1999-2006 Igor Pavlov +License: LGPL-2.1 or CPL-1.0 or special or proprietary or public-domain +Comment: in special license, the exption #3 says about the public-domain + for listed files. -Files: lib/qemu/block.c +Files: lib/qemu/block-bochs.c + lib/qemu/block.c + lib/qemu/block-cloop.c lib/qemu/block-cow.c + lib/qemu/block-dmg.c lib/qemu/block_int.h + lib/qemu/block-parallels.c lib/qemu/block-qcow.c lib/qemu/block-qcow2.c lib/qemu/block-raw-posix.c + lib/qemu/block-vmdk.c + lib/qemu/block-vpc.c + lib/qemu/block-vvfat.c lib/qemu/qemu-img.c Copyright: 2003-2008 Fabrice Bellard + 2004-2005 Johannes E. Schindelin + 2005 Filip Navara + 2005-2007 Alex Beregszaszi License: ISC - -Files: lib/qemu/block-dmg.c - lib/qemu/block-vvfat.c - lib/qemu/block-cloop.c -Copyright: 2004-2005 Johannes E. Schindelin -License: ISC - - -Files: lib/qemu/block-vmdk.c -Copyright: 2004 Fabrice Bellard - 2005 Filip Navara -License: ISC - - Files: lib/base64.cpp Copyright: 1995 International Business Machines, Inc. 1996-1999 Internet Software Consortium License: MIT and IBM - Files: lib/base64.h Copyright: 1996-1999 Internet Software Consortium License: MIT - Files: m4/acx_pthread.m4 Copyright: 2008 Steven G. Johnson License: GPL-3+ - -Files: pyaff/pyaff.c -Copyright: 2008 David Collett -License: LGPL-3+ - - Files: tools/affsegment.cpp tools/affstats.cpp tools/affxml.cpp -Copyright: 2005-2006 Simson L. Garfinkel - Basis Technology, Inc. +Copyright: 2005-2006 Basis Technology, Inc. + 2005-2006 Simson L. Garfinkel 2014 Phillip Hellewell -License: BSD-3-clause - - -Files: tools/affuse.c -Copyright: 2007 Olivier Castan - Simson L. Garfinkel - 2014 Phillip Hellewell -License: BSD-4-clause - +License: BSD-3-Clause Files: debian/* Copyright: 2009 Daniel Baumann @@ -151,31 +123,14 @@ 2010 Cristian Greco 2011 Luk Claes 2012 Julien Valroff - 2014-2015 Joao Eriberto Mota Filho + 2014-2017 Joao Eriberto Mota Filho 2015 Julien Cristau License: BSD-3-clause +License: public-domain + This file is in the Public domain. -License: Public_Domain_1 - This file is a work of a US government employee and as such is - in the Public domain. - - -License: Public_Domain_2 - The software provided here is released by the Naval Postgraduate - School (NPS), an agency of the US Department of the Navy, USA. The - software bears no warranty, either expressed or implied. NPS does - not assume legal liability nor responsibility for a User's use of - the software or the results of such use. Please note that within - the United States, copyright protection, under Section 105 of the - United States Code, Title 17, is not available for any work of the - United States Government and/or for any works created by United - States Government employees. User acknowledges that this software - contains work which was created by NPS employee(s) and is therefore - in the public domain and not subject to copyright. - - -License: BSD-4-clause +License: BSD-4-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -208,34 +163,284 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -License: Public_Domain_3 - This file written and distributed to public domain by Igor Pavlov. - - -License: LGPL-2.1+ or CPL or other - The LZMA SDK is quad-licensed under the GNU Library General Public - License (LGPL), the Common Public License (CPL), a custom simplified - license for unmodified code, and a proprietary license. - . - In Debian, the LZMA SDK is distributed under the LGPL. +License: LGPL-2.1 + This package is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; version + 2.1 of the License. . - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - . - This library is distributed in the hope that it will be useful, + This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. . - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . . On Debian systems, the complete text of the GNU Lesser General Public License can be found in "/usr/share/common-licenses/LGPL-2.1". +License: CPL-1.0 + Common Public License Version 1.0 + . + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC + LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM + CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + . + 1. DEFINITIONS + . + "Contribution" means: + . + a) in the case of the initial Contributor, the initial code and + documentation distributed under this Agreement, and + . + b) in the case of each subsequent Contributor: + . + i) changes to the Program, and + . + ii) additions to the Program; + . + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' from a + Contributor if it was added to the Program by such Contributor itself or + anyone acting on such Contributor's behalf. Contributions do not include + additions to the Program which: (i) are separate modules of software + distributed in conjunction with the Program under their own license + agreement, and (ii) are not derivative works of the Program. + . + "Contributor" means any person or entity that distributes the Program. + . + "Licensed Patents " mean patent claims licensable by a Contributor which are + necessarily infringed by the use or sale of its Contribution alone or when + combined with the Program. + . + "Program" means the Contributions distributed in accordance with this + Agreement. + . + "Recipient" means anyone who receives the Program under this Agreement, + including all Contributors. + . + 2. GRANT OF RIGHTS + . + a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly perform, + distribute and sublicense the Contribution of such Contributor, if any, and + such derivative works, in source code and object code form. + . + b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code and + object code form. + This patent license shall apply to the combination of the Contribution and + the Program if, at the time the Contribution is added by the Contributor, + such addition of the Contribution causes such combination to be covered by + the Licensed Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se is licensed + hereunder. + . + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances are provided by + any Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor disclaims + any liability to Recipient for claims brought by any other entity based on + infringement of intellectual property rights or otherwise. As a condition to + exercising the rights and licenses granted hereunder, each Recipient hereby + assumes sole responsibility to secure any other intellectual property rights + needed, if any. For example, if a third party patent license is required to + allow Recipient to distribute the Program, it is Recipient's responsibility + to acquire that license before distributing the Program. + . + d) Each Contributor represents that to its knowledge it has sufficient + copyright rights in its Contribution, if any, to grant the copyright license + set forth in this Agreement. + . + 3. REQUIREMENTS + . + A Contributor may choose to distribute the Program in object code form under + its own license agreement, provided that: + . + a) it complies with the terms and conditions of this Agreement; and + . + b) its license agreement: + . + i) effectively disclaims on behalf of all Contributors all warranties and + conditions, express and implied, including warranties or conditions of title + and non-infringement, and implied warranties or conditions of merchantability + and fitness for a particular purpose; + . + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and consequential + damages, such as lost profits; + . + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + . + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable manner on + or through a medium customarily used for software exchange. + . + When the Program is made available in source code form: + . + a) it must be made available under this Agreement; and + . + b) a copy of this Agreement must be included with each copy of the + Program. + . + Contributors may not remove or alter any copyright notices contained within + the Program. + . + Each Contributor must identify itself as the originator of its Contribution, + if any, in a manner that reasonably allows subsequent Recipients to identify + the originator of the Contribution. + . + 4. COMMERCIAL DISTRIBUTION + . + Commercial distributors of software may accept certain responsibilities with + respect to end users, business partners and the like. While this license is + intended to facilitate the commercial use of the Program, the Contributor who + includes the Program in a commercial product offering should do so in a + manner which does not create potential liability for other Contributors. + Therefore, if a Contributor includes the Program in a commercial product + offering, such Contributor ("Commercial Contributor") hereby agrees to defend + and indemnify every other Contributor ("Indemnified Contributor") against any + losses, damages and costs (collectively "Losses") arising from claims, + lawsuits and other legal actions brought by a third party against the + Indemnified Contributor to the extent caused by the acts or omissions of such + Commercial Contributor in connection with its distribution of the Program in + a commercial product offering. The obligations in this section do not apply + to any claims or Losses relating to any actual or alleged intellectual + property infringement. In order to qualify, an Indemnified Contributor must: + a) promptly notify the Commercial Contributor in writing of such claim, and + b) allow the Commercial Contributor to control, and cooperate with the + Commercial Contributor in, the defense and any related settlement + negotiations. The Indemnified Contributor may participate in any such claim + at its own expense. + . + For example, a Contributor might include the Program in a commercial product + offering, Product X. That Contributor is then a Commercial Contributor. If + that Commercial Contributor then makes performance claims, or offers + warranties related to Product X, those performance claims and warranties are + such Commercial Contributor's responsibility alone. Under this section, the + Commercial Contributor would have to defend claims against the other + Contributors related to those performance claims and warranties, and if a + court requires any other Contributor to pay any damages as a result, the + Commercial Contributor must pay those damages. + . + 5. NO WARRANTY + . + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON + AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER + EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR + CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A + PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the + appropriateness of using and distributing the Program and assumes all risks + associated with its exercise of rights under this Agreement, including but + not limited to the risks and costs of program errors, compliance with + applicable laws, damage to or loss of data, programs or equipment, and + unavailability or interruption of operations. + . + 6. DISCLAIMER OF LIABILITY + . + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY + CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION + LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE + EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY + OF SUCH DAMAGES. + . + 7. GENERAL + . + If any provision of this Agreement is invalid or unenforceable under + applicable law, it shall not affect the validity or enforceability of the + remainder of the terms of this Agreement, and without further action by the + parties hereto, such provision shall be reformed to the minimum extent + necessary to make such provision valid and enforceable. + . + If Recipient institutes patent litigation against a Contributor with respect + to a patent applicable to software (including a cross-claim or counterclaim + in a lawsuit), then any patent licenses granted by that Contributor to such + Recipient under this Agreement shall terminate as of the date such litigation + is filed. In addition, if Recipient institutes patent litigation against any + entity (including a cross-claim or counterclaim in a lawsuit) alleging that + the Program itself (excluding combinations of the Program with other software + or hardware) infringes such Recipient's patent(s), then such Recipient's + rights granted under Section 2(b) shall terminate as of the date such + litigation is filed. + . + All Recipient's rights under this Agreement shall terminate if it fails to + comply with any of the material terms or conditions of this Agreement and + does not cure such failure in a reasonable period of time after becoming + aware of such noncompliance. If all Recipient's rights under this Agreement + terminate, Recipient agrees to cease use and distribution of the Program as + soon as reasonably practicable. However, Recipient's obligations under this + Agreement and any licenses granted by Recipient relating to the Program shall + continue and survive. + . + Everyone is permitted to copy and distribute copies of this Agreement, but in + order to avoid inconsistency the Agreement is copyrighted and may only be + modified in the following manner. The Agreement Steward reserves the right to + publish new versions (including revisions) of this Agreement from time to + time. No one other than the Agreement Steward has the right to modify this + Agreement. IBM is the initial Agreement Steward. IBM may assign the + responsibility to serve as the Agreement Steward to a suitable separate + entity. Each new version of the Agreement will be given a distinguishing + version number. The Program (including Contributions) may always be + distributed subject to the version of the Agreement under which it was + received. In addition, after a new version of the Agreement is published, + Contributor may elect to distribute the Program (including its Contributions) + under the new version. Except as expressly stated in Sections 2(a) and 2(b) + above, Recipient receives no rights or licenses to the intellectual property + of any Contributor under this Agreement, whether expressly, by implication, + estoppel or otherwise. All rights in the Program not expressly granted under + this Agreement are reserved. + . + This Agreement is governed by the laws of the State of New York and the + intellectual property laws of the United States of America. No party to this + Agreement will bring a legal action under this Agreement more than one year + after the cause of action arose. Each party waives its rights to a jury trial + in any resulting litigation. + +License: special + SPECIAL EXCEPTION + . + Igor Pavlov, as the author of this code, expressly permits you + to statically or dynamically link your code (or bind by name) + to the files from LZMA SDK without subjecting your linked + code to the terms of the CPL or GNU LGPL. + Any modifications or additions to files from LZMA SDK, however, + are subject to the GNU LGPL or CPL terms. + . + SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, + while you keep LZMA SDK code unmodified. + . + SPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits + you to use this code under the same terms and conditions contained in the License + Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov. + . + SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version + of LZMA SDK as update for previous versions. + . + SPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits + you to use code of the following files: + BranchTypes.h, LzmaTypes.h, LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, + LzmaAlone.cs, LzmaAlone.java as public domain code. + +License: proprietary + Proprietary license + . + LZMA SDK also can be available under a proprietary license which + can include: + . + 1) Right to modify code without subjecting modified code to the + terms of the CPL or GNU LGPL + 2) Technical support for code + . + To request such proprietary license or any additional consultations, + send email message from that page: http://www.7-zip.org/support.html License: ISC Permission is hereby granted, free of charge, to any person obtaining a copy @@ -256,7 +461,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - License: MIT Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -271,7 +475,6 @@ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - License: IBM International Business Machines, Inc. (hereinafter called IBM) grants permission under its copyrights to use, copy, modify, and distribute this @@ -294,7 +497,6 @@ OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - License: GPL-3+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -312,27 +514,7 @@ On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". - -License: LGPL-3+ - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - . - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - . - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - . - On Debian systems, the complete text of the GNU Library General Public License - can be found in /usr/share/common-licenses/LGPL-3 file. - - -License: BSD-3-clause +License: BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff -Nru afflib-3.7.7/debian/libafflib0v5.symbols afflib-3.7.16/debian/libafflib0v5.symbols --- afflib-3.7.7/debian/libafflib0v5.symbols 2015-11-29 02:35:38.000000000 +0000 +++ afflib-3.7.16/debian/libafflib0v5.symbols 2017-06-24 21:50:33.000000000 +0000 @@ -56,8 +56,6 @@ _ZN10COutBuffer6CreateEj@Base 3.7.6 _ZN10COutBuffer9FlushPartEv@Base 3.7.6 _ZN10COutBuffer9SetStreamEP20ISequentialOutStream@Base 3.7.6 - _ZN10COutBufferD1Ev@Base 3.7.6 - _ZN10COutBufferD2Ev@Base 3.7.6 _ZN11CLZInWindow4FreeEv@Base 3.7.6 _ZN11CLZInWindow4InitEv@Base 3.7.6 _ZN11CLZInWindow6CreateEjjj@Base 3.7.6 @@ -82,7 +80,6 @@ _ZN13CCrcOutStreamD0Ev@Base 3.7.6 _ZN13CCrcOutStreamD1Ev@Base 3.7.6 _ZN13CCrcOutStreamD2Ev@Base 3.7.6 - _ZN13CObjectVectorI11CStringBaseIwEE3AddERKS1_@Base 3.7.6 _ZN13CObjectVectorI11CStringBaseIwEE6DeleteEii@Base 3.7.6 _ZN13CObjectVectorI11CStringBaseIwEED0Ev@Base 3.7.6 _ZN13CObjectVectorI11CStringBaseIwEED1Ev@Base 3.7.6 @@ -329,12 +326,8 @@ _ZN9NCompress5NLZMA8CEncoderD2Ev@Base 3.7.6 _ZN9NCompress5NLZMA9g_FastPosE@Base 3.7.6 _ZNK10COutBuffer16GetProcessedSizeEv@Base 3.7.6 - _ZNK11CStringBaseIwE3MidEii@Base 3.7.6 _ZNK9NCompress5NLZMA16CLiteralEncoder28GetPriceEbhh@Base 3.7.6 _ZNK9NCompress5NLZMA7NLength8CEncoder9SetPricesEjjPj@Base 3.7.6 - _ZNSt6vectorIN3aff7seginfoESaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_@Base 3.7.6 - _ZNSt6vectorIPN2s36BucketESaIS2_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS2_S4_EERKS2_@Base 3.7.6 - _ZNSt6vectorIPN2s38ContentsESaIS2_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS2_S4_EERKS2_@Base 3.7.6 _ZTI11CLZInWindow@Base 3.7.6 _ZTI12CInStreamRam@Base 3.7.6 _ZTI12IMatchFinder@Base 3.7.6 diff -Nru afflib-3.7.7/debian/libafflib-dev.install afflib-3.7.16/debian/libafflib-dev.install --- afflib-3.7.7/debian/libafflib-dev.install 2014-09-30 12:32:47.000000000 +0000 +++ afflib-3.7.16/debian/libafflib-dev.install 2016-11-24 18:55:09.000000000 +0000 @@ -1,3 +1,4 @@ usr/include/* +usr/lib/*/lib*.a usr/lib/*/lib*.so usr/lib/*/pkgconfig/*.pc diff -Nru afflib-3.7.7/debian/README.source afflib-3.7.16/debian/README.source --- afflib-3.7.7/debian/README.source 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/debian/README.source 2017-07-19 12:45:30.000000000 +0000 @@ -0,0 +1,7 @@ +afflib for Debian +----------------- + +The upstream incorporated the manpages to his source code. However, +the debian/manpage/ directory will be kept for possible future works. + + -- Joao Eriberto Mota Filho Wed, 19 Jul 2017 09:45:30 -0300 diff -Nru afflib-3.7.7/debian/rules afflib-3.7.16/debian/rules --- afflib-3.7.7/debian/rules 2015-11-29 02:41:38.000000000 +0000 +++ afflib-3.7.16/debian/rules 2017-06-24 21:50:33.000000000 +0000 @@ -1,4 +1,5 @@ #!/usr/bin/make -f +#export DH_VERBOSE=1 export DEB_BUILD_MAINT_OPTIONS = hardening=+all @@ -9,7 +10,7 @@ override_dh_auto_configure: dh_auto_configure -- LDFLAGS="$(LDFLAGS) -Wl,--as-needed,-z,defs" \ - --enable-s3=yes --enable-python=no --enable-static=no \ + --enable-s3=yes --enable-python=no --enable-static=yes \ --enable-shared=yes override_dh_auto_install: @@ -22,8 +23,5 @@ override_dh_auto_test: # do nothing -override_dh_strip: - dh_strip -a --dbg-package=afflib-dbg - override_dh_makeshlibs: dh_makeshlibs -- -v$(PVER) diff -Nru afflib-3.7.7/debian/source/options afflib-3.7.16/debian/source/options --- afflib-3.7.7/debian/source/options 2014-10-11 15:40:09.000000000 +0000 +++ afflib-3.7.16/debian/source/options 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -extend-diff-ignore = "^(INSTALL|compile|tools/Makefile.am)$" diff -Nru afflib-3.7.7/debian/watch afflib-3.7.16/debian/watch --- afflib-3.7.7/debian/watch 2014-10-11 17:23:03.000000000 +0000 +++ afflib-3.7.16/debian/watch 2016-11-28 13:29:45.000000000 +0000 @@ -1,2 +1,2 @@ -version=3 +version=4 https://github.com/sshock/AFFLIBv3/releases .*/archive/v?(\d\S+)\.tar\.(?:bz2|gz|xz) diff -Nru afflib-3.7.7/.gitignore afflib-3.7.16/.gitignore --- afflib-3.7.7/.gitignore 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/.gitignore 2017-06-24 00:57:09.000000000 +0000 @@ -105,3 +105,9 @@ *.dirstamp lib/aftest afflib-?.?.? +compile + +# Python # +########## +*.egg-info +pyaff/dist diff -Nru afflib-3.7.7/include/afflib/afflib.h afflib-3.7.16/include/afflib/afflib.h --- afflib-3.7.7/include/afflib/afflib.h 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/include/afflib/afflib.h 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,582 @@ +#ifndef _AFFLIB_H_ +#define _AFFLIB_H_ + +/* + * afflib.h: + * + * This file describes the public AFFLIB interface. + * The interface to reading AFF files and Raw files. + * + * Copyright (c) 2005-2006 + * Simson L. Garfinkel and Basis Technology, Inc. + * All rights reserved. + * + * This code is derrived from software contributed by + * Simson L. Garfinkel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Simson L. Garfinkel + * and Basis Technology Corp. + * 4. Neither the name of Simson Garfinkel, Basis Technology, or other + * contributors to this program may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY SIMSON GARFINKEL, BASIS TECHNOLOGY, + * AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SIMSON GARFINKEL, BAIS TECHNOLOGy, + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* Figure out what kind of OS we are running on */ + +/* These are both needed; no need to bother with affconfig.h #defines */ +#include +#ifdef HAVE_STDINT_H +#include +#else +#ifdef _MSC_VER +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif +#endif +#include + +#ifdef HAVE_SYS_CDEFS_H +#include +#endif + +#ifdef linux +/* Horrible lossage stuff for largefile support under Linux */ +#define _LARGEFILE_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#endif + +#ifdef HAVE_INTTYPES_H +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include +#else +#ifdef _MSC_VER +#define PRIu32 "I32u" +#endif +#endif + +/** WIN32 is defined by the NMAKE makefile for Visual C++ under Windows and by mingw **/ +#ifdef WIN32 +#include +#include // gets isatty + +/* These aren't needed for mingw */ +#if !defined(__MINGW_H) +#ifndef _UINT64_T_DECLARED +typedef unsigned __int64 uint64_t; /* 64-bit types Types */ +#define _UINT64_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64 int64_t; +#define _INT64_T_DECLARED +#endif +#endif + +#ifndef PRId64 +#define PRId64 "I64d" +#endif + +#ifndef PRIi64 +#define PRIi64 "I64i" +#endif + +#ifndef PRIu64 +#define PRIu64 "I64u" +#endif + +#endif +/** END OF WIN32 DEFINES **/ + +#define I64d PRIi64 +#define I64u PRIu64 + +/* If our types still aren't defined, give some kind of error + */ +struct affcallback_info; +struct aff_pagebuf { + int64_t pagenum; // -1 means no page loaded + unsigned char *pagebuf; // where the data is; size is image_pagesize + size_t pagebuf_bytes; // number of bytes in the pagebuf that are valid. + uint32_t pagenum_valid:1; // buffer contains data + uint32_t pagebuf_valid:1; // buffer contains data + uint32_t pagebuf_dirty:1; // data was modified + int last; // when the page was last visited +}; + +struct af_vnode_info { + uint64_t imagesize; // size of this image + int pagesize; // what is the natural page size? + uint32_t supports_compression:1; // supports writing compressed segments + uint32_t has_pages:1; // does system support page segments? + uint32_t supports_metadata:1; // does it support metadata? + uint32_t is_raw:1; // file is raw + uint32_t use_eof:1; // should we use the EOF flag? + uint32_t at_eof:1; // are we at the EOF? + uint32_t changable_pagesize:1; // pagesize can be changed at any time + uint32_t changable_sectorsize:1; // sectorsize can be changed at any time + uint32_t cannot_decrypt:1; // encrypted pages cannot be decrypted becuase passphrase is invalid + uint32_t segment_count_total; + uint32_t page_count_total; + uint32_t segment_count_signed; + uint32_t segment_count_encrypted; + uint32_t page_count_encrypted; +}; // + + +/* All of this stuff should be hidden inside a single private structure... */ +typedef struct _AFFILE AFFILE; + +/* The information that is provided in the aff callback */ +struct affcallback_info { + int info_version; // version number for this segment + AFFILE *af; // v1: the AFFILE responsibile for the callback + int phase; // v1: 1 = before compress; 2 = after compressing; + // 3 = before writing; 4 = after writing + int64_t pagenum; // v1: page number being written + int bytes_to_write; // v1: >0 if we are going to write bytes + int bytes_written; // v1: >0 if bytes were written + int compressed; // v1: >0 if bytes were/will be compressed + int compression_alg; // v1: compression algorithm + int compression_level; // v1: compression level +}; + +/* Utility Functions */ + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __never_defined__ +} +#endif + +/**************************************************************** + *** + *** Intended user AFF interface + *** + ****************************************************************/ + +const char * af_version(void); // returns AFF Version Number + +/* af_file stream functions */ +AFFILE *af_open(const char *filename,int flags,int mode); +AFFILE *af_freopen(FILE *file); // reopen a raw file as an AFFILE +AFFILE *af_popen(const char *command,const char *type); // no need to use pclose(); af_close() is fine +int af_close(AFFILE *af); +void af_set_error_reporter(AFFILE *af,void (*reporter)(const char *fmt,...)); +void af_stats(AFFILE *af,FILE *f); // print stats to f +void af_set_cachesize(AFFILE *af,int max); // how much memory can the cache use? +int af_vstat(AFFILE *af,struct af_vnode_info *vni); // does the stat +void af_perror(const char *fname); // print the error string to stderr +void af_err(int code,const char *fname,...); // like err(), but will also print AFF-specific errors + + + +/* Generic set/get option routines; this replaces individual options in previous implementations. + * af==0 to set global options. Return the previous value. + */ +int af_set_option(AFFILE *af,int option,int value); + +#define AF_OPTION_AUTO_ENCRYPT 1 // 1 = auto-encrypt +#define AF_OPTION_AUTO_DECRYPT 2 // 1 = auto-decrypt +// The following are not implemented yet +#define AF_OPTION_PIECEWISE_MD5 3 // 1 = automatically write pagen_md5 segments +#define AF_OPTION_PIECEWISE_SHA1 4 // 1 = automatically write pagen_md5 segments +#define AF_OPTION_PIECEWISE_SHA256 5 // 1 = automatically write pagen_md5 segments +#define AF_OPTION_DISABLE_RDLOCK 6 // 1 = do not read lock, but report that it should have locked. + + +/* Special AFOPEN flags for af_open_with */ +#define AF_OPEN_PRIMITIVE (1<<31) // only open primtive, not compound files +#define AF_BADBLOCK_FILL (1<<30) // fill unallocated (sparse) with BADBLOCK flag +#define AF_HALF_OPEN (1<<29) // return af before calling af->v->open; +#define AF_NO_CRYPTO (1<<28) // disable encryption layer + +/* navigating within the data segments as if they were a single file */ +#ifdef _WIN32 +SSIZE_T af_read(AFFILE *af,unsigned char *buf,SSIZE_T count); +#else +ssize_t af_read(AFFILE *af,unsigned char *buf,ssize_t count); +#endif +uint64_t af_seek(AFFILE *af,int64_t pos,int whence); // returns new position +uint64_t af_tell(AFFILE *af); +int af_eof(AFFILE *af); // is the virtual file at the end? + +/* Additional routines for writing */ +int af_set_maxsize(AFFILE *af,int64_t size); // sets maximum AFF file size +void af_set_callback(AFFILE *af, void (*cb)(struct affcallback_info *acbi)); +void af_enable_compression(AFFILE *af,int type,int level); // set/gunset compression for writing +int af_compression_type(AFFILE *af); +int af_write(AFFILE *af,unsigned char *buf,size_t count); +const unsigned char *af_badflag(AFFILE *af); // return the pattern used to identify bad sectors +int af_is_badsector(AFFILE *af,const unsigned char *buf); // 0 if not, 1 if it is, -1 if error + + +/* Misc. Functions */ +const char *af_ext(const char *filename); // return the extension of str including the dot +int af_ext_is(const char *filename,const char *ext); +const char *af_filename(AFFILE *af); // returns the filename of an open stream. +int af_identify(AFFILE *af); // returns type of AFFILE pointer + +/* AFF implementation types returned by af_identify() and af_identify_file_type() */ + +#define AF_IDENTIFY_RAW 0 // file is a raw file +#define AF_IDENTIFY_AFF 1 // file is an AFF file +#define AF_IDENTIFY_AFD 2 // file is a directory of AFF files +#define AF_IDENTIFY_EVF 3 // file is an EnCase file +#define AF_IDENTIFY_EVD 4 // file is a .E01 file when there are more files following +#define AF_IDENTIFY_SPLIT_RAW 5 // file is a split raw file +#define AF_IDENTIFY_AFM 6 // file is raw file with metadata +#define AF_IDENTIFY_EWF 7 // libewf; deprecated +#define AF_IDENTIFY_S3 8 // is an s3:/// file +#define AF_IDENTIFY_VMDK 9 // QEMU support for VMDK format +#define AF_IDENTIFY_DMG 10 // QEMU support for Apple DMG format +#define AF_IDENTIFY_SPARSEIMAGE 11 // QEMU support for Apple SPARSEIMAGE format + +#define AF_IDENTIFY_ERR -1 // error encountered on identify +#define AF_IDENTIFY_NOEXIST -2 // file does not exist + + +/* Accessor Functions */ +int64_t af_get_imagesize(AFFILE *af); // byte # of last mapped byte in image, or size of device; + // returns -1 if error +int af_get_pagesize(AFFILE *af); // returns page size, or -1 +int af_set_acquisition_date(AFFILE *af,time_t t); // sets AF_ACQUISITION_DATE + +#define af_imagesize(af) af_get_imagesize(af) // backwards compatiability +int af_get_segq(AFFILE *af,const char *name,int64_t *quad);/* Get/set 8-byte values */ +int af_update_segq(AFFILE *af,const char *name,int64_t quad); + + +/**************************************************************** + * Functions for manipulating the AFFILE as if it were a name/value database. + ****************************************************************/ + +/* get functions: + * get the named segment. + * If arg!=0, set *arg to be the segment's flag. + * if data==0, don't return it. + * if datalen && *datalen==0, return the size of the data segment. + *** Returns 0 on success, + *** -1 on end of file. (AF_ERROR_EOF) + *** -2 if *data is not large enough to hold the segment (AF_ERROR_DATASMALL) + *** -3 file is corrupt or other internal error. (AF_ERROR_CORRUPT) + */ + +int af_get_seg(AFFILE *af,const char *name,uint32_t *arg, + unsigned char *data,size_t *datalen); +int af_get_next_seg(AFFILE *af,char *segname,size_t segname_len, + uint32_t *arg, unsigned char *data, size_t *datalen); + +int af_rewind_seg(AFFILE *af); // rewind seg pointer to beginning + +/* + * af_update_seg() should be your primary routine for writing new values. + */ + +/* Writing arbitrary name/value pairs */ +int af_update_seg(AFFILE *af,const char *segname,uint32_t arg, + const unsigned char *value,uint32_t vallen); +#ifdef HAVE_OPENSSL_BIO_H +/* Write a memory bio to a segment */ +#include +int af_update_seg_frombio(AFFILE *af,const char *segname,uint32_t arg,BIO *bio); +#endif + + +/* Delete functions */ + +int af_del_seg(AFFILE *af,const char *name); // complete delete of first name + // returns 0 if success, -1 if seg not found + +/* Segname parse functions. + * af_segname_page_number: + * - Returns page number if segment name is a page #, and -1 if it is not + * af_segname_hash_page_number: + * - Returns page number if segment name is a page hash, sets hash function + * to be the function used. + */ +int64_t af_segname_page_number(const char *name); // return -1 if it is not a page number +int64_t af_segname_hash_page_number(const char *name,char *hash,int hashlen); // return -1 if it is not a hash page # + +int af_display_as_quad(const char *segname); // afflib recommends displaying this segment as an 8-byte quad +int af_display_as_hex(const char *segname); // afflib recommends displaying this segment as a hex-string + +/****************************************************************/ + +/* Crypto */ +/* AFF Base Encryption */ +int af_SHA256(const unsigned char *buf,size_t buflen,unsigned char md[32]); // return 0 if success, -1 if no cipher +int af_set_aes_key(AFFILE *af,const unsigned char *userKey,const int bits); +int af_cannot_decrypt(AFFILE *af); // encrypted pages are present which cannot be decrypted +int af_has_encrypted_segments(AFFILE *af); +int af_is_encrypted_segment(const char *segname); + +/* AFF Passphrase Encryption */ +int af_establish_aes_passphrase(AFFILE *af,const char *passphrase); +int af_change_aes_passphrase(AFFILE *af,const char *oldphrase,const char *newphrase); +int af_use_aes_passphrase(AFFILE *af,const char *passphrase); +int af_save_aes_key_with_passphrase(AFFILE *af,const char *passphrase, const unsigned char affkey[32]); +int af_get_aes_key_from_passphrase(AFFILE *af,const char *passphrase, unsigned char affkey[32]); + + +/* PKI Signing */ +int af_set_sign_files(AFFILE *af,const char *keyfile,const char *certfile); +int af_sign_seg3(AFFILE *af,const char *segname, uint32_t arg, + const unsigned char *data,uint32_t datalen,uint32_t signmode); +int af_sign_seg(AFFILE *af,const char *segname); +int af_sign_all_unsigned_segments(AFFILE *af); // +int af_sig_verify_seg(AFFILE *af,const char *segname); // see below for return codes + +int af_is_signature_segment(const char *segname); + +/* PKI sealing */ +int af_set_seal_certificates(AFFILE *af,const char *certfiles[],int numcertfiles); +int af_seal_affkey_using_certificates(AFFILE *af,const char *certfiles[],int numcertfiles, unsigned char affkey[32]);// +int af_set_unseal_keybuffer(AFFILE *af,const char *key); // take key from a buffer +int af_set_unseal_keyfile(AFFILE *af,const char *keyfile); // take key from a file +int af_get_affkey_using_keyfile(AFFILE *af, const char *private_keyfile,unsigned char affkey[32]); + + + +#ifdef HAVE_OPENSSL_EVP_H +#include +int af_sig_verify_seg2(AFFILE *af,const char *segname,EVP_PKEY *pubkey,unsigned char *sigbuf, + size_t sigbuf_len,int sigmode); +int af_hash_verify_seg2(AFFILE *af,const char *segname,unsigned char *sigbuf_,size_t sigbuf_len_,int sigmode); +#define AF_HASH_VERIFIES 0 + +#endif +#define AF_SIGNATURE_MODE0 0x0000 // signature is for segname, arg, data in segment +#define AF_SIGNATURE_MODE1 0x0001 // signature is for segname, 0 arg, uncompressed data in segment +#define AF_SIGNATURE_DELETE 0xFFFF // signature is invalid; delete segment + +/* Metadata access */ + +/* Compression amounts */ + +#define AF_COMPRESSION_MIN 1 +#define AF_COMPRESSION_DEFAULT -1 +#define AF_COMPRESSION_MAX 9 +#define AF_COMPRESSION_MIN 1 + + +/**************************************************************** + *** AF segment names that you might be interested in... + ****************************************************************/ + +#define AF_IGNORE "" // ignore segments with 0-length name +#define AF_DIRECTORY "dir" // the directory +#define AF_RAW_IMAGE_FILE_EXTENSION "raw_image_file_extension" +#define AF_PAGES_PER_RAW_IMAGE_FILE "pages_per_raw_image_file" + +#define AF_PAGESIZE "pagesize" // page data size, in bytes, stored in arg +#define AF_IMAGESIZE "imagesize" // last logical byte in image, stored as a 64-bit number +#define AF_BADSECTORS "badsectors" // number of bad sectors +#define AF_SECTORSIZE "sectorsize" // in bytes, stored in arg +#define AF_DEVICE_SECTORS "devicesectors"// stored as a 64-bit number +#define AF_BADFLAG "badflag" // data used to mark a bad sector +#define AF_PAGE "page%" I64d // segment flag indicates compression (replaces seg%d) +#define AF_PAGE_MD5 AF_PAGE"_md5" // md5 hash of page +#define AF_PAGE_SHA1 AF_PAGE"_sha1" // sha1 hash of page +#define AF_PAGE_SHA256 AF_PAGE"_sha256"// sha256 hash of page +#define AF_PARITY0 "parity0" // parity page of all bytes +#define AF_BATCH_NAME "batch_name" +#define AF_BATCH_ITEM_NAME "batch_item_name" + +#define AF_BLANKSECTORS "blanksectors" // all NULs; 8-bytes +#define AF_AFF_FILE_TYPE "aff_file_type" // contents should be "AFF", "AFM" or "AFD" + +#define AF_AFFKEY "affkey_aes256" // segment for AES256 session key encrypted with sha of the passphrase +#define AF_AFFKEY_EVP "affkey_evp%d" // segment for encrypted affkey +#define AF_AES256_SUFFIX "/aes256" // suffix for encrypted segments +#define AF_SIG256_SUFFIX "/sha256" // suffix for signature segments +#define AF_SIGN256_CERT "cert-sha256" // segment name for image creator's public key +#define AF_PARITY0_SIG "parity0/sha256" // signature for parity segment + +/* Chain of custody segments */ +#define AF_BOM_SEG "affbom%d" + +/* Deprecated terminology; pages were originally called data segments */ +#define AF_SEG_D "seg%" I64d // segment flag indicates compression (deprecated) +#define AF_SEGSIZE_D "segsize" // segment data size (deprecated) + +/* Bill of Materials */ +#define AF_XML_AFFBOM "affbom" +#define AF_XML_DATE "date" +#define AF_XML_SIGNING_CER "signingcert" +#define AF_XML_SEGMENT_HASH "segmenthash" + + +/* AFF Flags */ +/* Flags for 8-byte segments */ +#define AF_SEG_QUADWORD 0x0002 + +/* Flags for selecting compression algorithm to try */ +#define AF_COMPRESSION_ALG_NONE 0 // don't compress +#define AF_COMPRESSION_ALG_ZLIB 1 // try to compress with zlib +#define AF_COMPRESSION_ALG_LZMA 2 // try to compress with LZMA + +/* Arg Flags for data pages; this is stored in 'flag' of data segment */ +#define AF_PAGE_COMPRESSED 0x0001 +#define AF_PAGE_COMP_MAX 0x0002 // compressed at maximum; nice to know +#define AF_PAGE_COMP_ALG_MASK 0x00F0 // up to 16 compression algorithms may be used +#define AF_PAGE_COMP_ALG_ZLIB 0x0000 +#define AF_PAGE_COMP_ALG_BZIP 0x0010 // not implemented; why bother? +#define AF_PAGE_COMP_ALG_LZMA 0x0020 // high compression but pretty slow +#define AF_PAGE_COMP_ALG_ZERO 0x0030 // Data segment is a 4-byte value of # of NULLs. + +#define AF_MD5 "md5" // stores image md5 +#define AF_SHA1 "sha1" // stores image sha1 +#define AF_SHA256 "sha256" // stores image sha256 + +#define AF_CREATOR "creator" // progname of the program that created the AFF file + +/* segment names: imaging */ +#define AF_CASE_NUM "case_num" // case number +#define AF_IMAGE_GID "image_gid" // 128-bit unique number +#define AF_ACQUISITION_ISO_COUNTRY "acquisition_iso_country" // ISO country code +#define AF_ACQUISITION_COMMAND_LINE "acquisition_commandline" // actual command line used to create the image +#define AF_ACQUISITION_DATE "acquisition_date" // YYYY-MM-DD HH:MM:SS TZT +#define AF_ACQUISITION_NOTES "acquisition_notes" // notes made while imaging +#define AF_ACQUISITION_DEVICE "acquisition_device" // device used to do the imaging +#define AF_ACQUISITION_SECONDS "acquisition_seconds" // stored in arg +#define AF_ACQUISITION_TECHNICIAN "acquisition_tecnician" +#define AF_ACQUISITION_MACADDR "acquisition_macaddr" +#define AF_ACQUISITION_DMESG "acquisition_dmesg" + + +// mac addresses are store in ASCII as a list of lines that end with \n, +// for example, "00:03:93:14:c5:04\n" +// It is all the mac addresses that were on the acquisition system + +// DMESG is the output from the "dmesg" command at the time of acquisition + + +/* segment names: device hardware */ + +#define AF_AFFLIB_VERSION "afflib_version" // version of AFFLIB that made this file +#define AF_DEVICE_MANUFACTURER "device_manufacturer" +#define AF_DEVICE_MODEL "device_model" // string for ident from drive +#define AF_DEVICE_SN "device_sn" // string of drive capabilities +#define AF_DEVICE_FIRMWARE "device_firmware" // string of drive capabilities +#define AF_DEVICE_SOURCE "device_source" // string +#define AF_CYLINDERS "cylinders" // quad with # cylinders +#define AF_HEADS "heads" // quad with # heads +#define AF_SECTORS_PER_TRACK "sectors_per_track"// quad with # sectors/track +#define AF_LBA_SIZE "lbasize" +#define AF_HPA_PRESENT "hpa_present" // flag = 1 or 0 +#define AF_DCO_PRESENT "dco_present" // flag = 1 or 0 +#define AF_LOCATION_IN_COMPUTER "location_in_computer" // text, where it was found +#define AF_DEVICE_CAPABILITIES "device_capabilities" // string; human-readable + +#define AF_MAX_NAME_LEN 64 // segment names should not be larger than this + +/* AFF error codes */ +#define AF_ERROR_NO_ERROR 0 +#define AF_ERROR_EOF -1 +#define AF_ERROR_DATASMALL -2 +#define AF_ERROR_TAIL -3 // no tail, or error reading tail +#define AF_ERROR_SEGH -4 // no head, or error reading head +#define AF_ERROR_NAME -5 // segment name invalid +#define AF_ERROR_INVALID_ARG -6 // argument invalid +#define AF_ERROR_NO_AES -7 // AES support is not compiled in +#define AF_ERROR_AES_TOO_SMALL -8 // and AES-encrypted segment was too small +#define AF_ERROR_KEY_SET -9 // a key was already set +#define AF_ERROR_AFFKEY_EXISTS -10 // a key already exists in file an attempt was made to establish +#define AF_ERROR_AFFKEY_NOT_EXIST -11 // a key does not exist and an attempt was made to use it. +#define AF_ERROR_AFFKEY_WRONG_VERSION -12 +#define AF_ERROR_WRONG_PASSPHRASE -13 +#define AF_ERROR_RNG_FAIL -13 +#define AF_ERROR_HASH_FAIL -14 +#define AF_ERROR_NO_SHA256 -15 + +#define AF_SIG_GOOD 0 +#define AF_ERROR_SIG_BAD -15 +#define AF_ERROR_SIG_NO_CERT -16 +#define AF_ERROR_SIG_CANNOT_READ_PUBLIC_KEY -17 +#define AF_ERROR_SIG_DATAREAD_ERROR -18 +#define AF_ERROR_SIG_MALLOC -19 +#define AF_ERROR_SIG_READ_ERROR -20 +#define AF_ERROR_SIG_SIG_SEG -21 // can't verify the signature on a signature segment +#define AF_ERROR_SIG_NOT_COMPILED -22 // afflib compiled without signature support + + +/* AFF environment variables */ +#define AFFLIB_CACHE_STATS "AFFLIB_CACHE_STATS" // make non-zero to dump stats to STDERR at end +#define AFFLIB_CACHE_DEBUG "AFFLIB_CACHE_DEBUG" // make "1" to dump a trace of cache events to stderr +#define AFFLIB_CACHE_PAGES "AFFLIB_CACHE_PAGES" // Size of the page cache +#define AFFLIB_CACHE_PAGES_DEFAULT 32 // default number of cache pages +#define AFFLIB_BIGTMP "AFFLIB_BIGTMP" // default directory to put very big files for test programs +#define AFFLIB_TRACEFILE "AFFLIB_TRACEFILE" // If set, send a record of all activity to the location +/* passphrases for single-key cryptography */ +#define AFFLIB_PASSPHRASE "AFFLIB_PASSPHRASE" +#define AFFLIB_PASSPHRASE_FILE "AFFLIB_PASSPHRASE_FILE" +#define AFFLIB_PASSPHRASE_FD "AFFLIB_PASSPHRASE_FD" + +/* passphrases for signing keys */ +#define AFFLIB_PEM_SIGNING_PASSPHRASE "AFFLIB_PEM_SIGNING_PASSPHRASE" + +/* passphrases for sealing keys */ + +#define AFFLIB_DECRYPTING_PRIVATE_KEYFILE "AFFLIB_DECRYPTING_PRIVATE_KEYFILE" + +extern FILE *af_trace; // fd to trace to + +/**************************************************************** + *** Not AFF functions at all, but placed here for convenience. + ****************************************************************/ +const char *af_hexbuf(char *dst,int dst_len,const unsigned char *bin,int bytes,int format_flag); + +/* af_hexbuf formats: */ +#define AF_HEXBUF_NO_SPACES 0 +#define AF_HEXBUF_SPACE2 0x0001 // space every 2 characters +#define AF_HEXBUF_SPACE4 0x0002 // space every 4 characters +#define AF_HEXBUF_UPPERCASE 0x1000 // uppercase +#define AF_HEXBUF_LINEBREAK 0x2000 // break every 80 cols + + +/**************************************************************** + *** Internal implementation details below. + ****************************************************************/ + + +#ifdef __never_defined__ +{ +#endif +#ifdef __cplusplus +} +#endif +#endif + + diff -Nru afflib-3.7.7/include/afflib/afflib_i.h afflib-3.7.16/include/afflib/afflib_i.h --- afflib-3.7.7/include/afflib/afflib_i.h 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/include/afflib/afflib_i.h 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,689 @@ +/* + * afflib_i.h: + * The "master include file" of the AFF Library. + * Includes many fucntions that are not designed + * to be used by application programmers. + * + * + * Copyright (c) 2005-2006 + * Simson L. Garfinkel and Basis Technology, Inc. + * All rights reserved. + * + * This code is derrived from software contributed by + * Simson L. Garfinkel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Simson L. Garfinkel + * and Basis Technology Corp. + * 4. Neither the name of Simson Garfinkel, Basis Technology, or other + * contributors to this program may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY SIMSON GARFINKEL, BASIS TECHNOLOGY, + * AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SIMSON GARFINKEL, BAIS TECHNOLOGy, + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef AFFLIB_I_H +#define AFFLIB_I_H + +#ifdef KERNEL_LIBRARY +#ifdef __cplusplus +extern "C" { +#endif +void __cdecl AFDbgPrint (PCSTR Format,...); +#ifdef __cplusplus +} +#endif +#endif + + +/* Should we disable threading? */ +#ifdef DISABLE_PTHREAD +#undef HAVE_PTHREAD +#endif + +/* Standard includes */ +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_ZLIB_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_FCNTL_H +#include +#endif + +#ifdef HAVE_ASSERT_H +#include +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif + +#ifdef HAVE_DIRENT_H +#include +#endif + +#ifdef HAVE_ERR_H +#include +#endif + +#ifdef HAVE_ALLOCA_H +#include +#endif + +#ifdef HAVE_LIBCRYPTO +#include +#include // a standard part of OpenSSL +#include +#include +#include +#endif + +#ifdef HAVE_PTHREAD +#include +#define AF_READLOCK(af) pthread_rwlock_rdlock(&af->rwlock); +#define AF_WRLOCK(af) pthread_rwlock_wrlock(&af->rwlock); +#define AF_UNLOCK(af) pthread_rwlock_unlock(&af->rwlock); +#else +/* No threads */ +#define AF_READLOCK(af) {} +#define AF_WRLOCK(af) {} +#define AF_UNLOCK(af) {} +#endif + +#ifdef WIN32 +#if !defined(HAVE__MINGW_H) +#pragma warning(disable: 4996) /* Don't warn on Windows about using POSIX open() instead of _open() */ +#endif +#include +#include +#include // htonl() +#include +#define snprintf _snprintf +#define strcasecmp _stricmp +#define mkdir(path,mode) _mkdir(path) +#define random() rand() +#define access _access +#define strdup _strdup + +#ifndef ENOTSUP +#define ENOTSUP 65536 /* made up number */ +#endif + +#ifndef _MODE_T_ +#define _MODE_T_ +typedef unsigned short mode_t; +typedef unsigned short _mode_t; +#endif + +#ifndef S_ISDIR +#define S_ISDIR(m)(((m) & 0170000) == 0040000) +#endif + +#if !defined(HAVE__MINGW_H) +#define ftruncate(fd,size) _chsize_s(fd,size) +#define MAXPATHLEN 1024 +#endif + +#if defined(HAVE__MINGW_H) +#ifndef ftello +#define ftello ftello64 +#endif + +#ifndef fseeko +#define fseeko fseeko64 +#endif + +#else +#define ftello _ftelli64 /* replaces ftello64 in VC2008 */ +#define fseeko _fseeki64 +#endif + +#endif +/** END OF WIN32 DEFINES **/ + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_ARPA_INET_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +/* Pick an appropriate POINTER_FMT; isn't there an ANSI standard for this? */ +#ifdef __APPLE__ +#define POINTER_FMT "%p" +#endif + +#ifdef linux +#define POINTER_FMT "%p" +#endif + +#ifndef POINTER_FMT +#define POINTER_FMT "%x" // guess +#endif + +/* Handle systems that are missing some #defines */ + +#ifndef O_BINARY +#define O_BINARY 0 // for Windows compatability +#endif + +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + +#ifndef O_ACCMODE +#define O_ACCMODE 0x0003 +#endif + +/* If these functions do not exist, we need to create our own */ + +#ifndef HAVE_ERR +void err(int eval, const char *fmt, ...); +#endif + +#ifndef HAVE_ERRX +void errx(int eval, const char *fmt, ...); +#endif + +#ifndef HAVE_WARN +void warn(const char *fmt, ...); +#endif + +#ifndef HAVE_WARNX +void warnx(const char *fmt, ...); +#endif + +/* access function */ +#ifndef F_OK +#define F_OK 0 /* test for existence of file */ +#endif + +#ifndef X_OK +#define X_OK 0x01 /* test for execute or search permission */ +#endif + +#ifndef W_OK +#define W_OK 0x02 /* test for write permission */ +#endif + +#ifndef R_OK +#define R_OK 0x04 /* test for read permission */ +#endif + + +#if defined(WIN32) && !defined(HAVE__MINGW_H) +/**************************************************************** + *** Windows emulation of opendir()/readdir() + *** From php + ****************************************************************/ + +/* struct dirent - same as Unix */ + +struct dirent { + long d_ino; /* inode (always 1 in WIN32) */ + off_t d_off; /* offset to this dirent */ + int d_reclen; /* length of d_name; was unsigned short */ + char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */ +}; + + +/* typedef DIR - not the same as Unix */ +typedef struct { + long handle; /* _findfirst/_findnext handle */ + short offset; /* offset into directory */ + short finished; /* 1 if there are not more files */ + struct _finddata_t fileinfo; /* from _findfirst/_findnext */ + char *dir; /* the dir we are reading */ + struct dirent dent; /* the dirent to return */ +} DIR; + +/* Function prototypes */ + + +#ifdef __cplusplus +extern "C" { +#endif + +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +int closedir(DIR *); +int rewinddir(DIR *); + + +#ifdef __cplusplus +} +#endif +#endif + + +/**************************************************************** + *** AFFLIB internal stuff follows. + ****************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef NEVER_DEFINED +} +#endif + +#if defined(HAVE_LIBEXPAT) +#define USE_AFFSIGS +#endif + +struct _AFFILE { + int version; // 2 + void *tag; // available to callers; unused by AFFLIB + + struct af_vnode *v; // which function table to use. + struct _AFFILE *parent; // for AFF file inside an AFD + + /* For all files */ + int openflags; // how it was opened + int openmode; // how we were asked to open it; more + int exists; // did file exist before open was called? + + /* From URLs */ + char *fname; // Filename of file; be sure to free when done + char *protocol; // could be "file" or "s3" + char *username; // optionally specified in URL + char *password; // from URL; erase after use. + char *hostname; // from URL + int port; // from URL + + /* Extended Logging */ + char error_str[64]; // what went wrong + + /* Implement a stream abstraction */ + uint64_t image_size; // last mappable byte of disk image + uint64_t image_size_in_file; // see if it was changed... + uint32_t image_pagesize; // the size of image data segments in this file + uint32_t image_sectorsize; + uint64_t pos; // location in stream; should be signed because of comparisons + + /* Page buffer cache */ + struct aff_pagebuf *pb; // the current page buffer + struct aff_pagebuf *pbcache; // array of pagebufs + int num_pbufs; // number of pagebufs; default is 1 + int afftime; // for updating last + int64_t cur_page; // used by vnode_raw to fake pages must be able to go negative. + + int debug; // for debugging, of course + unsigned int badflag_set:1; // is badflag set? + unsigned char *badflag; // bad sector flag + + + /****************************************************************/ + /* Right now the instance variables for each implementation are here, + * which is ugly but easier for development... + */ + + /* For AFF Segment Files; this could be moved into private storage... */ + FILE *aseg; + struct aff_toc_mem *toc; // table of contents + int toc_count; // number of directory elements + + /****************************************************************/ + + unsigned int write_md5:1; // automatically write the MD5 for each page + unsigned int write_sha1:1; + unsigned int write_sha256:1; + + + /* These are for optimizing updates; really this should go away and we should just + * exmaine the TOC to find a hole, but currently we don't do that. + */ + unsigned int direction_changes; // how many times have we changed directions? + int last_direction; // should be 1 or -1 + unsigned int random_access:1; // are we in random access mode? + + /* additional support for writing. */ + unsigned int compression_type; // preferred compression type + int compression_level; // 0 is no compression + + + /* w_callback: + * A callback that is called before and after each segment is written. + * Called with the arguments (i,0,0) at the beginning of the write operation. + * Called with the arguments (i,j,k) at the end of the write operation. + * i = segment number + * j = segment length + * If segment is being written with compresison, k = compressed length. + * If segment is written w/o compression, k = 0 + */ + void (*w_callback)(struct affcallback_info *acbi); + // called at start and end of compression. + + uint64_t maxsize; // maximum file size of a multi-segment files, + // or 0 if this is not a multi-segment file + + /* Performance Counters */ + uint64_t bytes_memcpy; // total number of bytes memcpy'ed + uint64_t pages_written; // total number of pages written + uint64_t pages_compressed; // total number of pages compressed + uint64_t pages_decompressed; + uint64_t pages_read; // total number of pages read + uint64_t bytes_written; + uint64_t cache_hits; + uint64_t cache_misses; // total number of pages flushed from cache + + void *vnodeprivate; // private storage for the vnode + void (*error_reporter)(const char *fmt, ...); + struct af_crypto *crypto; +#ifdef HAVE_PTHREAD + pthread_rwlock_t rwlock; // automatically created and destroyed if pthread exists +#endif + struct af_vnode_info *vni_cache; // vstat cache +}; + + + +/* af_crypto: + * copy of AES encrypt and decrypt keys. + */ +void af_crypto_allocate(AFFILE *af); +void af_crypto_deallocate(AFFILE *af); + +struct af_crypto { + uint32_t sealing_key_set:1; // encryption key has been set + uint32_t auto_encrypt:1; // encrypt segments when we write + uint32_t auto_decrypt:1; // automatically decrypto when we read +#ifdef AES_BLOCK_SIZE + AES_KEY ekey; // encrypt key + AES_KEY dkey; // decrypt key +#endif +#ifdef HAVE_OPENSSL_EVP_H + EVP_PKEY *sign_privkey; // signing private key (to write signatures) + EVP_PKEY *sign_pubkey; // signing public key (to verify signatures) + X509 *sign_cert; // signing certificate (for verifying signatures) + /* Sealing is kept locally and immediately turned into a dkey & ekey */ +#endif +}; + + +/* The AFF STREAM VNODE */ +struct af_vnode { + int type; // numeric vnode type + int flag; // file system flag type + const char *name; + int (*identify)(const char *fname,int exists); // returns 1 if file system is identified by implementation; + int (*open)(AFFILE *af); + int (*close)(AFFILE *af); + int (*vstat)(AFFILE *af,struct af_vnode_info *); // returns info about the vnode image file + int (*get_seg)(AFFILE *af,const char *name,uint32_t *arg, uint8_t *data,size_t *datalen); + int (*get_next_seg)(AFFILE *af,char *segname,size_t segname_len, + uint32_t *arg, uint8_t *data, size_t *datalen); + int (*rewind_seg)(AFFILE *af); + int (*update_seg)(AFFILE *af,const char *name,uint32_t arg, + const uint8_t *value,uint32_t vallen); + int (*del_seg)(AFFILE *af,const char *name); + int (*read)(AFFILE *af,uint8_t *buf,uint64_t offset,size_t count); + int (*write)(AFFILE *af,uint8_t *buf,uint64_t offset,size_t count); +}; + +/* VNODE Flags */ +#define AF_VNODE_TYPE_PRIMITIVE 0x01 // single-file implementation +#define AF_VNODE_TYPE_COMPOUND 0x02 // multi-file implementation +#define AF_VNODE_TYPE_RELIABLE 0x04 // writes are reliable; no need to verify them. +#define AF_VNODE_MAXSIZE_MULTIPLE 0x08 // maxsize must be multiple of pagesize (for AFM and splitraw) +#define AF_VNODE_NO_SIGNING 0x10 // vnode does not support signing (like raw) +#define AF_VNODE_NO_SEALING 0x20 // vnode does not support sealing (like raw and afd) + +#define AF_SEALING_VNODE(af) (!(af->v->flag & AF_VNODE_NO_SEALING)) +#define AF_SIGNING_VNODE(af) (!(af->v->flag & AF_VNODE_NO_SIGNING)) +#define AF_SEALING(af) AF_SEALING_VNODE(af) && af->crypto && af->crypto->sealing_key_set + + +/* The header for an AFF file. All binary numbers are stored in network byte order. */ +#define AF_HEADER "AFF10\r\n\000" +struct af_head { + char header[8]; // "AFF10\r\n\000" + /* segments follow */ +}; + + +/* The header of each segment */ +#define AF_SEGHEAD "AFF\000" +struct af_segment_head { + char magic[4]; // "AFF\000" + uint32_t name_len:32; // length of segment name + uint32_t data_len:32; // length of segment data, if any + uint32_t flag:32; // argument for name; + /* name follows, then data */ +}; + +/* The tail of each segment */ +#define AF_SEGTAIL "ATT\000" +struct af_segment_tail { + char magic[4]; // "ATT\000" + uint32_t segment_len:32; // includes head, tail, name & length +}; + + +/* How 64-bit values are stored in a segment */ +#pragma pack(1) +struct aff_quad { + uint32_t low:32; + uint32_t high:32; +}; +#pragma pack() + + +/* As it is kept in memory */ +struct aff_toc_mem { + char *name; // name of this directory entry + uint64_t offset; // offset from beginning of file. + uint64_t segment_len; // includes head, tail, name & length +}; + +/* How encryption keys are stored */ +struct affkey { + uint8_t version[4]; + uint8_t affkey_aes256[32]; // AFF key encrypted with SHA-256 of passphrase + // encrypted as two codebooks in a row; no need for CBC + uint8_t zeros_aes256[16]; // all zeros encrypted with SHA-256 of passphrase +}; +#define AFFKEY_SIZE 4+32+16 + + +void af_initialize(); // initialize the AFFLIB + // automatically called by af_open() + +/* Internal identification routines */ +int af_identify_file_type(const char *filename,int exists); // returns type of a file; if exists=1, file must exist +const char *af_identify_file_name(const char *filename,int exists); // returns name of a file type; +int split_raw_increment_fname (char *fn); /* exposed for testing in aftest */ + +AFFILE *af_open_with(const char *filename,int flags,int mode, struct af_vnode *v); +extern struct af_vnode *af_vnode_array[]; // array of filesystems; last is a "0" + +int af_last_seg(AFFILE *af,char *last_segname,int last_segname_len,int64_t *pos); +int af_make_badflag(AFFILE *af); // creates a badflag and puts it +int af_make_gid(AFFILE *af); // created an AF_IMAGE_GID if it doesn't exist +extern char af_error_str[64]; + + +#define AFF_DEFAULT_PAGESIZE (1024*1024*16) + + +/* afflib_os.cpp: + * Operating-system specific code. + */ + +/* af_figure_media: + * Returns information about the media in a structure. + * Returns 0 if successful, -1 if error. + */ + +struct af_figure_media_buf { + int version; + int sector_size; + uint64_t total_sectors; + uint64_t max_read_blocks; // was previously 4-bytes; must be 8! +}; +int af_figure_media(int fd,struct af_figure_media_buf *); + +/**************************************************************** + *** Lowest-level routines for manipulating the AFF File... + ****************************************************************/ + +/* Navigating within the AFFILE */ +/* probe the next segment. + * Returns: 0 if success + * -1 if error + * -2 if segname_len was not large enough to hold segname + * - segname - the name of the next segment. + * - segsize - number of bytes the entire segment is. + * + * doesn't change af->aseg pointer if do_rewind is true, otherwise leaves stream + * positioned ready to read the data + */ + +int af_probe_next_seg(AFFILE *af,char *segname,size_t segname_len, + uint32_t *arg,size_t *datasize, size_t *segsize,int do_rewind); +int af_backspace(AFFILE *af); // back up one segment + + + +/**************************************************************** + *** Reading functions + ****************************************************************/ + + +/* Support for data pages. This is what the stream system is built upon. + * Note: pagename to string translation happens inside afflib.cpp, not inside + * the vnode driver. + */ +int af_page_size(AFFILE *af); // legacy (now is af_get_pagesize) +void af_read_sizes(AFFILE *af); // sets up values if we can get them. +int af_set_pagesize(AFFILE *af,uint32_t pagesize); // sets the pagesize; fails with -1 if imagesize >=0 +int af_set_sectorsize(AFFILE *AF,int sectorsize); // fails with -1 if imagesize>=0 +int af_get_sectorsize(AFFILE *AF); // returns sector size +int af_has_pages(AFFILE *af); // does the underlying system support pages? +int af_get_pagesize(AFFILE *af); // returns page size, or -1 +int af_get_page_raw(AFFILE *af,int64_t pagenum,uint32_t *arg,uint8_t *data,size_t *bytes); +int af_get_page(AFFILE *af,int64_t pagenum,uint8_t *data,size_t *bytes); +#define AF_SIGFLAG_NOSIG 0x0001 // do not write signatures with af_update_segf() +#define AF_SIGFLAG_NOSEAL 0x0002 // do not encrypt an af_update_segf() + +/**************************************************************** + *** Writing functions + ****************************************************************/ + +extern int af_cache_debug; // sets level of verbosity */ +int af_update_page(AFFILE *af,int64_t pagenum,uint8_t *data,int datalen); +int af_update_segf(AFFILE *af,const char *name, + uint32_t arg,const uint8_t *value,uint32_t vallen,uint32_t sigflag); + +void af_invalidate_vni_cache(AFFILE *af); +void af_cache_writethrough(AFFILE *af,int64_t pagenum, + const uint8_t *buf,int bufflen); +int af_cache_flush(AFFILE *af); // write buffers to disk +struct aff_pagebuf *af_cache_alloc(AFFILE *af,int64_t pagenum); + + +/**************************************************************** + ***/ + +/* afflib_util.cpp + */ +uint64_t af_decode_q(uint8_t buf[8]); // return buf[8] into an unsigned quad +const char *af_commas(char buf[64],int64_t val); +int af_hasmeta(const char *buf); // return 1 if buf has shell metacharacters +int af_is_filestream(const char *filename); // return 1 if file:// or filename +void af_parse_url(const char *url,char **protocol,char **hostname, + char **username,char **password,int *port,char **path); + +#ifndef HAVE_STRLCPY +size_t strlcpy(char *dest,const char *src,size_t dest_size); +#endif + +#ifndef HAVE_STRLCAT +size_t strlcat(char *dest,const char *src,size_t dest_size); +#endif + + +/**************************************************************** + *** Table of Contents + ****************************************************************/ + +/* Needs a rewrite for efficiency */ + +/* afflib_toc.cpp: + * Table of contents management routines + * Remember: all of these routines may fail, because the whole TOC may not + * fit in memory... + * + * This is all experimental right now. + */ + +int aff_segment_overhead(const char *segname); +int aff_toc_free(AFFILE *af); +void aff_toc_print(AFFILE *af); +int aff_toc_build(AFFILE *af); // build by scanning the AFFILE +struct aff_toc_mem *aff_toc(AFFILE *af,const char *segname); +int aff_toc_del(AFFILE *af,const char *segname); +void aff_toc_update(AFFILE *af,const char *segname,uint64_t offset,uint64_t datalen); + +struct aff_toc_mem *aff_toc_next_seg(AFFILE *af, uint64_t offset); +int aff_toc_find_hole(AFFILE *af, uint64_t min_size, uint64_t *offset, uint64_t *size); + +/* lzma_glue.cpp: + * For the LZMA compression engine + */ +int lzma_compress(uint8_t *dest,size_t *destLen, const uint8_t *data,size_t datalen,int level); +int lzma_uncompress(uint8_t *buf,size_t *buflen, const uint8_t *cbuf,size_t cbuf_size); + +#ifdef NEVER_DEFINED +{ +#endif +#ifdef __cplusplus +} +#endif +#endif + + diff -Nru afflib-3.7.7/include/afflib/aftimer.h afflib-3.7.16/include/afflib/aftimer.h --- afflib-3.7.7/include/afflib/aftimer.h 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/include/afflib/aftimer.h 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,184 @@ +/* + * Distributed under the Berkeley 4-part license. + * Simson L. Garfinkel, March 12, 2012 + */ + + +#ifndef __AFTIMER_H__ +#define __AFTIMER_H__ + +#ifdef __cplusplus +#ifndef WIN32 +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include +#include +#endif +#include +#include +#include + +class aftimer { + struct timeval t0; + bool running; + long total_sec; + long total_usec; + double lap_time_; // time from when we last did a "stop" +public: + aftimer():t0(),running(false),total_sec(0),total_usec(0),lap_time_(0){} + + void start(); // start the timer + void stop(); // stop the timer + + time_t tstart() { return t0.tv_sec;} // time we started + double elapsed_seconds(); // how long timer has been running, total + double lap_time(); // how long the timer is running this time + double eta(double fraction_done); // calculate ETA in seconds, given fraction + std::string hms(long t); // turn a number of seconds into h:m:s + std::string elapsed_text(); /* how long we have been running */ + std::string eta_text(double fraction_done); // h:m:s + std::string eta_time(double fraction_done); // the actual time +}; + +/* This code in part from + * http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/430449b3-f6dd-4e18-84de-eebd26a8d668 + */ + +#ifdef WIN32 +# include +# include +# ifndef DELTA_EPOCH_IN_MICROSECS +# if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +# else +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +# endif +# endif +#endif + +inline void timestamp(struct timeval *t) +{ +#ifdef WIN32 + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + unsigned __int64 tmpres = 0; + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tmpres /= 10; /*convert into microseconds*/ + t->tv_sec = (long)(tmpres / 1000000UL); + t->tv_usec = (long)(tmpres % 1000000UL); +#else + gettimeofday(t,NULL); +#endif +} + +inline void aftimer::start() +{ + timestamp(&t0); + running = 1; +} + +inline void aftimer::stop(){ + if(running){ + struct timeval t; + timestamp(&t); + total_sec += t.tv_sec - t0.tv_sec; + total_usec += t.tv_usec - t0.tv_usec; + lap_time_ = (double)(t.tv_sec - t0.tv_sec) + (double)(t.tv_usec - t0.tv_usec)/1000000.0; + running = false; + } +} + +inline double aftimer::lap_time() +{ + return lap_time_; +} + +inline double aftimer::elapsed_seconds() +{ + double ret = (double)total_sec + (double)total_usec/1000000.0; + if(running){ + struct timeval t; + timestamp(&t); + ret += t.tv_sec - t0.tv_sec; + ret += (t.tv_usec - t0.tv_usec) / 1000000.0; + } + return ret; +} + +inline std::string aftimer::hms(long t) +{ + char buf[64]; + int days = t / (60*60*24); + + t = t % (60*60*24); /* what's left */ + + int h = t / 3600; + int m = (t / 60) % 60; + int s = t % 60; + buf[0] = 0; + switch(days){ + case 0: + snprintf(buf,sizeof(buf),"%2d:%02d:%02d",h,m,s); + break; + case 1: + snprintf(buf,sizeof(buf),"%d day, %2d:%02d:%02d",days,h,m,s); + break; + default: + snprintf(buf,sizeof(buf),"%d days %2d:%02d:%02d",days,h,m,s); + } + return std::string(buf); +} + +inline std::string aftimer::elapsed_text() +{ + return hms((int)elapsed_seconds()); +} + +/** + * returns the number of seconds until the job is complete. + */ +inline double aftimer::eta(double fraction_done) +{ + double t = elapsed_seconds(); + if(t<=0) return -1; // can't figure it out + if(fraction_done<=0) return -1; // can't figure it out + return (t * 1.0/fraction_done - t); +} + +/** + * Retuns the number of hours:minutes:seconds until the job is done. + */ +inline std::string aftimer::eta_text(double fraction_done) +{ + double e = eta(fraction_done); + if(e<0) return std::string("n/a"); // can't figure it out + return hms((long)e); +} + +/** + * Returns the time when data is due. + */ +inline std::string aftimer::eta_time(double fraction_done) +{ + time_t when = time_t(eta(fraction_done)) + time(0); + struct tm tm; +#ifdef HAVE_LOCALTIME_R + localtime_r(&when,&tm); +#else + tm = *localtime(&when); +#endif + + char buf[64]; + snprintf(buf,sizeof(buf),"%02d:%02d:%02d",tm.tm_hour,tm.tm_min,tm.tm_sec); + return std::string(buf); +} + +#endif + +#endif diff -Nru afflib-3.7.7/include/afflib/utils.h afflib-3.7.16/include/afflib/utils.h --- afflib-3.7.7/include/afflib/utils.h 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/include/afflib/utils.h 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,89 @@ +/* + * utils.h: + * Some useful utilities for building AFF-aware programs. + * Distributed under the Berkeley 4-part license + */ + +#ifndef AFF_UTILS_H +#define AFF_UTILS_H + +#ifdef __cplusplus +#ifdef HAVE_STL +#include +#include +#include +#include +#include +#include +#include +#endif + +#ifdef HAVE_OPENSSL_PEM_H +#include +#include +#else +typedef void X509; +typedef void EVP_PKEY; +typedef void BIO; +#define BIO_free free +#endif + +namespace aff { + +#ifdef HAVE_STL + std::string command_line(int argc,char **argv); + bool ends_with(std::string str,std::string ending); +#endif + bool ends_with(const char *buf,const char *with); + + /* Structure for hash map */ + struct less_c_str + { + inline bool operator()( const char* x, const char* y) const + { return ( strcmp( x,y ) < 0 ); + } + }; + + struct md5blob { + unsigned char buf[16]; + }; + +#ifdef HAVE_STL + typedef std::map< const char*, struct md5blob, less_c_str > hashMapT; + + /* The seginfo stores information about a segment other than its data*/ + class seginfo { + public: + seginfo(std::string n1,size_t l1,unsigned int a1): name(n1),len(l1),arg(a1) {} + std::string name; + size_t len; + unsigned long arg; + /** pagenumber returns <0 for invalid pages, >= for a page */ + int64_t pagenumber() const {return af_segname_page_number(name.c_str());} + bool inline operator==(const class seginfo &b) const { + return name == b.name; + } + virtual ~seginfo(){}; + }; + + /* the seglist provides AFF internal functions and tools an easy way to get + * a list of all of the segments in the currently open AFF file. + * Use the seglist(af) constructor to populate it with all the segments + * when you create. Each element is populated with the name, length and arg. + */ + class seglist : public std::vector { + public: + bool contains(std::string segname); + bool has_signed_segments(); + int get_seglist(AFFILE *af); + seglist(){} + virtual ~seglist(){} + seglist(AFFILE *af){ + get_seglist(af); + } + }; +#endif +} +#endif + +#endif diff -Nru afflib-3.7.7/lib/aff_db.cpp afflib-3.7.16/lib/aff_db.cpp --- afflib-3.7.7/lib/aff_db.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/aff_db.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -50,7 +50,7 @@ uint32_t name_len = ntohl(segh.name_len); uint32_t datasize = ntohl(segh.data_len); if(name_len>AF_MAX_NAME_LEN){ - snprintf(af->error_str,sizeof(af->error_str),"afflib: name_len=%"PRIu32" (an outrageous value)",name_len); + snprintf(af->error_str,sizeof(af->error_str),"afflib: name_len=%" PRIu32 " (an outrageous value)",name_len); return AF_ERROR_NAME; } diff -Nru afflib-3.7.7/lib/afflib.cpp afflib-3.7.16/lib/afflib.cpp --- afflib-3.7.7/lib/afflib.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/afflib.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -455,7 +455,7 @@ uint64_t af_seek(AFFILE *af,int64_t pos,int whence) { AF_WRLOCK(af); - if(af_trace) fprintf(af_trace,"af_seek(%p,%"I64d",%d)\n",af,pos,whence); + if(af_trace) fprintf(af_trace,"af_seek(%p,%" I64d ",%d)\n",af,pos,whence); uint64_t new_pos=0; switch(whence){ case SEEK_SET: @@ -596,7 +596,7 @@ if(af->badflag!=0) free(af->badflag); af->badflag = (unsigned char *)malloc(af->image_sectorsize); // current sector size - RAND_pseudo_bytes(af->badflag,af->image_sectorsize); + RAND_bytes(af->badflag,af->image_sectorsize); strcpy((char *)af->badflag,"BAD SECTOR"); AF_WRLOCK(af); @@ -624,7 +624,7 @@ AF_WRLOCK(af); if(af_get_seg(af,AF_IMAGE_GID,0,0,0)!=0){ unsigned char bit128[16]; - RAND_pseudo_bytes(bit128,sizeof(bit128)); + RAND_bytes(bit128,sizeof(bit128)); int r = af_update_seg(af,AF_IMAGE_GID,0,bit128,sizeof(bit128)); if(r<0) ret = -1; else ret = 1; @@ -788,7 +788,7 @@ int af_update_segf(AFFILE *af, const char *segname, uint32_t arg,const u_char *data,uint32_t datalen,uint32_t flag) { - if(af_trace) fprintf(af_trace,"af_update_segf(%p,segname=%s,arg=%"PRIu32",datalen=%d)\n", + if(af_trace) fprintf(af_trace,"af_update_segf(%p,segname=%s,arg=%" PRIu32 ",datalen=%d)\n", af,segname,arg,datalen); AF_WRLOCK(af); if(af->v->update_seg==0){ @@ -954,13 +954,13 @@ { AF_READLOCK(af); fprintf(f,"AFSTATS for %s\n",af_filename(af)); - fprintf(f,"Pages read: %"I64u"\n",af->pages_read); - fprintf(f,"Pages written: %"I64u"\n",af->pages_written); - fprintf(f,"Pages compressed: %"I64u"\n",af->pages_compressed); - fprintf(f,"Pages decompressed: %"I64u"\n",af->pages_decompressed); - fprintf(f,"Cache hits: %"I64u"\n",af->cache_hits); - fprintf(f,"Cache misses: %"I64u"\n",af->cache_misses); - fprintf(f,"Bytes copied: %"I64u"\n",af->bytes_memcpy); + fprintf(f,"Pages read: %" I64u "\n",af->pages_read); + fprintf(f,"Pages written: %" I64u "\n",af->pages_written); + fprintf(f,"Pages compressed: %" I64u "\n",af->pages_compressed); + fprintf(f,"Pages decompressed: %" I64u "\n",af->pages_decompressed); + fprintf(f,"Cache hits: %" I64u "\n",af->cache_hits); + fprintf(f,"Cache misses: %" I64u "\n",af->cache_misses); + fprintf(f,"Bytes copied: %" I64u "\n",af->bytes_memcpy); AF_UNLOCK(af); } diff -Nru afflib-3.7.7/lib/afflib.h afflib-3.7.16/lib/afflib.h --- afflib-3.7.7/lib/afflib.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/afflib.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,582 +0,0 @@ -#ifndef _AFFLIB_H_ -#define _AFFLIB_H_ - -/* - * afflib.h: - * - * This file describes the public AFFLIB interface. - * The interface to reading AFF files and Raw files. - * - * Copyright (c) 2005-2006 - * Simson L. Garfinkel and Basis Technology, Inc. - * All rights reserved. - * - * This code is derrived from software contributed by - * Simson L. Garfinkel - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Simson L. Garfinkel - * and Basis Technology Corp. - * 4. Neither the name of Simson Garfinkel, Basis Technology, or other - * contributors to this program may be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY SIMSON GARFINKEL, BASIS TECHNOLOGY, - * AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SIMSON GARFINKEL, BAIS TECHNOLOGy, - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* Figure out what kind of OS we are running on */ - -/* These are both needed; no need to bother with affconfig.h #defines */ -#include -#ifdef HAVE_STDINT_H -#include -#else -#ifdef _MSC_VER -typedef signed char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -#endif -#endif -#include - -#ifdef HAVE_SYS_CDEFS_H -#include -#endif - -#ifdef linux -/* Horrible lossage stuff for largefile support under Linux */ -#define _LARGEFILE_SOURCE 1 -#define _FILE_OFFSET_BITS 64 -#endif - -#ifdef HAVE_INTTYPES_H -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif -#include -#else -#ifdef _MSC_VER -#define PRIu32 "I32u" -#endif -#endif - -/** WIN32 is defined by the NMAKE makefile for Visual C++ under Windows and by mingw **/ -#ifdef WIN32 -#include -#include // gets isatty - -/* These aren't needed for mingw */ -#if !defined(__MINGW_H) -#ifndef _UINT64_T_DECLARED -typedef unsigned __int64 uint64_t; /* 64-bit types Types */ -#define _UINT64_T_DECLARED -#endif - -#ifndef _INT64_T_DECLARED -typedef __int64 int64_t; -#define _INT64_T_DECLARED -#endif -#endif - -#ifndef PRId64 -#define PRId64 "I64d" -#endif - -#ifndef PRIi64 -#define PRIi64 "I64i" -#endif - -#ifndef PRIu64 -#define PRIu64 "I64u" -#endif - -#endif -/** END OF WIN32 DEFINES **/ - -#define I64d PRIi64 -#define I64u PRIu64 - -/* If our types still aren't defined, give some kind of error - */ -struct affcallback_info; -struct aff_pagebuf { - int64_t pagenum; // -1 means no page loaded - unsigned char *pagebuf; // where the data is; size is image_pagesize - size_t pagebuf_bytes; // number of bytes in the pagebuf that are valid. - uint32_t pagenum_valid:1; // buffer contains data - uint32_t pagebuf_valid:1; // buffer contains data - uint32_t pagebuf_dirty:1; // data was modified - int last; // when the page was last visited -}; - -struct af_vnode_info { - uint64_t imagesize; // size of this image - int pagesize; // what is the natural page size? - uint32_t supports_compression:1; // supports writing compressed segments - uint32_t has_pages:1; // does system support page segments? - uint32_t supports_metadata:1; // does it support metadata? - uint32_t is_raw:1; // file is raw - uint32_t use_eof:1; // should we use the EOF flag? - uint32_t at_eof:1; // are we at the EOF? - uint32_t changable_pagesize:1; // pagesize can be changed at any time - uint32_t changable_sectorsize:1; // sectorsize can be changed at any time - uint32_t cannot_decrypt:1; // encrypted pages cannot be decrypted becuase passphrase is invalid - uint32_t segment_count_total; - uint32_t page_count_total; - uint32_t segment_count_signed; - uint32_t segment_count_encrypted; - uint32_t page_count_encrypted; -}; // - - -/* All of this stuff should be hidden inside a single private structure... */ -typedef struct _AFFILE AFFILE; - -/* The information that is provided in the aff callback */ -struct affcallback_info { - int info_version; // version number for this segment - AFFILE *af; // v1: the AFFILE responsibile for the callback - int phase; // v1: 1 = before compress; 2 = after compressing; - // 3 = before writing; 4 = after writing - int64_t pagenum; // v1: page number being written - int bytes_to_write; // v1: >0 if we are going to write bytes - int bytes_written; // v1: >0 if bytes were written - int compressed; // v1: >0 if bytes were/will be compressed - int compression_alg; // v1: compression algorithm - int compression_level; // v1: compression level -}; - -/* Utility Functions */ - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef __never_defined__ -} -#endif - -/**************************************************************** - *** - *** Intended user AFF interface - *** - ****************************************************************/ - -const char * af_version(void); // returns AFF Version Number - -/* af_file stream functions */ -AFFILE *af_open(const char *filename,int flags,int mode); -AFFILE *af_freopen(FILE *file); // reopen a raw file as an AFFILE -AFFILE *af_popen(const char *command,const char *type); // no need to use pclose(); af_close() is fine -int af_close(AFFILE *af); -void af_set_error_reporter(AFFILE *af,void (*reporter)(const char *fmt,...)); -void af_stats(AFFILE *af,FILE *f); // print stats to f -void af_set_cachesize(AFFILE *af,int max); // how much memory can the cache use? -int af_vstat(AFFILE *af,struct af_vnode_info *vni); // does the stat -void af_perror(const char *fname); // print the error string to stderr -void af_err(int code,const char *fname,...); // like err(), but will also print AFF-specific errors - - - -/* Generic set/get option routines; this replaces individual options in previous implementations. - * af==0 to set global options. Return the previous value. - */ -int af_set_option(AFFILE *af,int option,int value); - -#define AF_OPTION_AUTO_ENCRYPT 1 // 1 = auto-encrypt -#define AF_OPTION_AUTO_DECRYPT 2 // 1 = auto-decrypt -// The following are not implemented yet -#define AF_OPTION_PIECEWISE_MD5 3 // 1 = automatically write pagen_md5 segments -#define AF_OPTION_PIECEWISE_SHA1 4 // 1 = automatically write pagen_md5 segments -#define AF_OPTION_PIECEWISE_SHA256 5 // 1 = automatically write pagen_md5 segments -#define AF_OPTION_DISABLE_RDLOCK 6 // 1 = do not read lock, but report that it should have locked. - - -/* Special AFOPEN flags for af_open_with */ -#define AF_OPEN_PRIMITIVE (1<<31) // only open primtive, not compound files -#define AF_BADBLOCK_FILL (1<<30) // fill unallocated (sparse) with BADBLOCK flag -#define AF_HALF_OPEN (1<<29) // return af before calling af->v->open; -#define AF_NO_CRYPTO (1<<28) // disable encryption layer - -/* navigating within the data segments as if they were a single file */ -#ifdef _WIN32 -SSIZE_T af_read(AFFILE *af,unsigned char *buf,SSIZE_T count); -#else -ssize_t af_read(AFFILE *af,unsigned char *buf,ssize_t count); -#endif -uint64_t af_seek(AFFILE *af,int64_t pos,int whence); // returns new position -uint64_t af_tell(AFFILE *af); -int af_eof(AFFILE *af); // is the virtual file at the end? - -/* Additional routines for writing */ -int af_set_maxsize(AFFILE *af,int64_t size); // sets maximum AFF file size -void af_set_callback(AFFILE *af, void (*cb)(struct affcallback_info *acbi)); -void af_enable_compression(AFFILE *af,int type,int level); // set/gunset compression for writing -int af_compression_type(AFFILE *af); -int af_write(AFFILE *af,unsigned char *buf,size_t count); -const unsigned char *af_badflag(AFFILE *af); // return the pattern used to identify bad sectors -int af_is_badsector(AFFILE *af,const unsigned char *buf); // 0 if not, 1 if it is, -1 if error - - -/* Misc. Functions */ -const char *af_ext(const char *filename); // return the extension of str including the dot -int af_ext_is(const char *filename,const char *ext); -const char *af_filename(AFFILE *af); // returns the filename of an open stream. -int af_identify(AFFILE *af); // returns type of AFFILE pointer - -/* AFF implementation types returned by af_identify() and af_identify_file_type() */ - -#define AF_IDENTIFY_RAW 0 // file is a raw file -#define AF_IDENTIFY_AFF 1 // file is an AFF file -#define AF_IDENTIFY_AFD 2 // file is a directory of AFF files -#define AF_IDENTIFY_EVF 3 // file is an EnCase file -#define AF_IDENTIFY_EVD 4 // file is a .E01 file when there are more files following -#define AF_IDENTIFY_SPLIT_RAW 5 // file is a split raw file -#define AF_IDENTIFY_AFM 6 // file is raw file with metadata -#define AF_IDENTIFY_EWF 7 // libewf; deprecated -#define AF_IDENTIFY_S3 8 // is an s3:/// file -#define AF_IDENTIFY_VMDK 9 // QEMU support for VMDK format -#define AF_IDENTIFY_DMG 10 // QEMU support for Apple DMG format -#define AF_IDENTIFY_SPARSEIMAGE 11 // QEMU support for Apple SPARSEIMAGE format - -#define AF_IDENTIFY_ERR -1 // error encountered on identify -#define AF_IDENTIFY_NOEXIST -2 // file does not exist - - -/* Accessor Functions */ -int64_t af_get_imagesize(AFFILE *af); // byte # of last mapped byte in image, or size of device; - // returns -1 if error -int af_get_pagesize(AFFILE *af); // returns page size, or -1 -int af_set_acquisition_date(AFFILE *af,time_t t); // sets AF_ACQUISITION_DATE - -#define af_imagesize(af) af_get_imagesize(af) // backwards compatiability -int af_get_segq(AFFILE *af,const char *name,int64_t *quad);/* Get/set 8-byte values */ -int af_update_segq(AFFILE *af,const char *name,int64_t quad); - - -/**************************************************************** - * Functions for manipulating the AFFILE as if it were a name/value database. - ****************************************************************/ - -/* get functions: - * get the named segment. - * If arg!=0, set *arg to be the segment's flag. - * if data==0, don't return it. - * if datalen && *datalen==0, return the size of the data segment. - *** Returns 0 on success, - *** -1 on end of file. (AF_ERROR_EOF) - *** -2 if *data is not large enough to hold the segment (AF_ERROR_DATASMALL) - *** -3 file is corrupt or other internal error. (AF_ERROR_CORRUPT) - */ - -int af_get_seg(AFFILE *af,const char *name,uint32_t *arg, - unsigned char *data,size_t *datalen); -int af_get_next_seg(AFFILE *af,char *segname,size_t segname_len, - uint32_t *arg, unsigned char *data, size_t *datalen); - -int af_rewind_seg(AFFILE *af); // rewind seg pointer to beginning - -/* - * af_update_seg() should be your primary routine for writing new values. - */ - -/* Writing arbitrary name/value pairs */ -int af_update_seg(AFFILE *af,const char *segname,uint32_t arg, - const unsigned char *value,uint32_t vallen); -#ifdef HAVE_OPENSSL_BIO_H -/* Write a memory bio to a segment */ -#include -int af_update_seg_frombio(AFFILE *af,const char *segname,uint32_t arg,BIO *bio); -#endif - - -/* Delete functions */ - -int af_del_seg(AFFILE *af,const char *name); // complete delete of first name - // returns 0 if success, -1 if seg not found - -/* Segname parse functions. - * af_segname_page_number: - * - Returns page number if segment name is a page #, and -1 if it is not - * af_segname_hash_page_number: - * - Returns page number if segment name is a page hash, sets hash function - * to be the function used. - */ -int64_t af_segname_page_number(const char *name); // return -1 if it is not a page number -int64_t af_segname_hash_page_number(const char *name,char *hash,int hashlen); // return -1 if it is not a hash page # - -int af_display_as_quad(const char *segname); // afflib recommends displaying this segment as an 8-byte quad -int af_display_as_hex(const char *segname); // afflib recommends displaying this segment as a hex-string - -/****************************************************************/ - -/* Crypto */ -/* AFF Base Encryption */ -int af_SHA256(const unsigned char *buf,size_t buflen,unsigned char md[32]); // return 0 if success, -1 if no cipher -int af_set_aes_key(AFFILE *af,const unsigned char *userKey,const int bits); -int af_cannot_decrypt(AFFILE *af); // encrypted pages are present which cannot be decrypted -int af_has_encrypted_segments(AFFILE *af); -int af_is_encrypted_segment(const char *segname); - -/* AFF Passphrase Encryption */ -int af_establish_aes_passphrase(AFFILE *af,const char *passphrase); -int af_change_aes_passphrase(AFFILE *af,const char *oldphrase,const char *newphrase); -int af_use_aes_passphrase(AFFILE *af,const char *passphrase); -int af_save_aes_key_with_passphrase(AFFILE *af,const char *passphrase, const unsigned char affkey[32]); -int af_get_aes_key_from_passphrase(AFFILE *af,const char *passphrase, unsigned char affkey[32]); - - -/* PKI Signing */ -int af_set_sign_files(AFFILE *af,const char *keyfile,const char *certfile); -int af_sign_seg3(AFFILE *af,const char *segname, uint32_t arg, - const unsigned char *data,uint32_t datalen,uint32_t signmode); -int af_sign_seg(AFFILE *af,const char *segname); -int af_sign_all_unsigned_segments(AFFILE *af); // -int af_sig_verify_seg(AFFILE *af,const char *segname); // see below for return codes - -int af_is_signature_segment(const char *segname); - -/* PKI sealing */ -int af_set_seal_certificates(AFFILE *af,const char *certfiles[],int numcertfiles); -int af_seal_affkey_using_certificates(AFFILE *af,const char *certfiles[],int numcertfiles, unsigned char affkey[32]);// -int af_set_unseal_keybuffer(AFFILE *af,const char *key); // take key from a buffer -int af_set_unseal_keyfile(AFFILE *af,const char *keyfile); // take key from a file -int af_get_affkey_using_keyfile(AFFILE *af, const char *private_keyfile,unsigned char affkey[32]); - - - -#ifdef HAVE_OPENSSL_EVP_H -#include -int af_sig_verify_seg2(AFFILE *af,const char *segname,EVP_PKEY *pubkey,unsigned char *sigbuf, - size_t sigbuf_len,int sigmode); -int af_hash_verify_seg2(AFFILE *af,const char *segname,unsigned char *sigbuf_,size_t sigbuf_len_,int sigmode); -#define AF_HASH_VERIFIES 0 - -#endif -#define AF_SIGNATURE_MODE0 0x0000 // signature is for segname, arg, data in segment -#define AF_SIGNATURE_MODE1 0x0001 // signature is for segname, 0 arg, uncompressed data in segment -#define AF_SIGNATURE_DELETE 0xFFFF // signature is invalid; delete segment - -/* Metadata access */ - -/* Compression amounts */ - -#define AF_COMPRESSION_MIN 1 -#define AF_COMPRESSION_DEFAULT -1 -#define AF_COMPRESSION_MAX 9 -#define AF_COMPRESSION_MIN 1 - - -/**************************************************************** - *** AF segment names that you might be interested in... - ****************************************************************/ - -#define AF_IGNORE "" // ignore segments with 0-length name -#define AF_DIRECTORY "dir" // the directory -#define AF_RAW_IMAGE_FILE_EXTENSION "raw_image_file_extension" -#define AF_PAGES_PER_RAW_IMAGE_FILE "pages_per_raw_image_file" - -#define AF_PAGESIZE "pagesize" // page data size, in bytes, stored in arg -#define AF_IMAGESIZE "imagesize" // last logical byte in image, stored as a 64-bit number -#define AF_BADSECTORS "badsectors" // number of bad sectors -#define AF_SECTORSIZE "sectorsize" // in bytes, stored in arg -#define AF_DEVICE_SECTORS "devicesectors"// stored as a 64-bit number -#define AF_BADFLAG "badflag" // data used to mark a bad sector -#define AF_PAGE "page%"I64d // segment flag indicates compression (replaces seg%d) -#define AF_PAGE_MD5 AF_PAGE"_md5" // md5 hash of page -#define AF_PAGE_SHA1 AF_PAGE"_sha1" // sha1 hash of page -#define AF_PAGE_SHA256 AF_PAGE"_sha256"// sha256 hash of page -#define AF_PARITY0 "parity0" // parity page of all bytes -#define AF_BATCH_NAME "batch_name" -#define AF_BATCH_ITEM_NAME "batch_item_name" - -#define AF_BLANKSECTORS "blanksectors" // all NULs; 8-bytes -#define AF_AFF_FILE_TYPE "aff_file_type" // contents should be "AFF", "AFM" or "AFD" - -#define AF_AFFKEY "affkey_aes256" // segment for AES256 session key encrypted with sha of the passphrase -#define AF_AFFKEY_EVP "affkey_evp%d" // segment for encrypted affkey -#define AF_AES256_SUFFIX "/aes256" // suffix for encrypted segments -#define AF_SIG256_SUFFIX "/sha256" // suffix for signature segments -#define AF_SIGN256_CERT "cert-sha256" // segment name for image creator's public key -#define AF_PARITY0_SIG "parity0/sha256" // signature for parity segment - -/* Chain of custody segments */ -#define AF_BOM_SEG "affbom%d" - -/* Deprecated terminology; pages were originally called data segments */ -#define AF_SEG_D "seg%"I64d // segment flag indicates compression (deprecated) -#define AF_SEGSIZE_D "segsize" // segment data size (deprecated) - -/* Bill of Materials */ -#define AF_XML_AFFBOM "affbom" -#define AF_XML_DATE "date" -#define AF_XML_SIGNING_CER "signingcert" -#define AF_XML_SEGMENT_HASH "segmenthash" - - -/* AFF Flags */ -/* Flags for 8-byte segments */ -#define AF_SEG_QUADWORD 0x0002 - -/* Flags for selecting compression algorithm to try */ -#define AF_COMPRESSION_ALG_NONE 0 // don't compress -#define AF_COMPRESSION_ALG_ZLIB 1 // try to compress with zlib -#define AF_COMPRESSION_ALG_LZMA 2 // try to compress with LZMA - -/* Arg Flags for data pages; this is stored in 'flag' of data segment */ -#define AF_PAGE_COMPRESSED 0x0001 -#define AF_PAGE_COMP_MAX 0x0002 // compressed at maximum; nice to know -#define AF_PAGE_COMP_ALG_MASK 0x00F0 // up to 16 compression algorithms may be used -#define AF_PAGE_COMP_ALG_ZLIB 0x0000 -#define AF_PAGE_COMP_ALG_BZIP 0x0010 // not implemented; why bother? -#define AF_PAGE_COMP_ALG_LZMA 0x0020 // high compression but pretty slow -#define AF_PAGE_COMP_ALG_ZERO 0x0030 // Data segment is a 4-byte value of # of NULLs. - -#define AF_MD5 "md5" // stores image md5 -#define AF_SHA1 "sha1" // stores image sha1 -#define AF_SHA256 "sha256" // stores image sha256 - -#define AF_CREATOR "creator" // progname of the program that created the AFF file - -/* segment names: imaging */ -#define AF_CASE_NUM "case_num" // case number -#define AF_IMAGE_GID "image_gid" // 128-bit unique number -#define AF_ACQUISITION_ISO_COUNTRY "acquisition_iso_country" // ISO country code -#define AF_ACQUISITION_COMMAND_LINE "acquisition_commandline" // actual command line used to create the image -#define AF_ACQUISITION_DATE "acquisition_date" // YYYY-MM-DD HH:MM:SS TZT -#define AF_ACQUISITION_NOTES "acquisition_notes" // notes made while imaging -#define AF_ACQUISITION_DEVICE "acquisition_device" // device used to do the imaging -#define AF_ACQUISITION_SECONDS "acquisition_seconds" // stored in arg -#define AF_ACQUISITION_TECHNICIAN "acquisition_tecnician" -#define AF_ACQUISITION_MACADDR "acquisition_macaddr" -#define AF_ACQUISITION_DMESG "acquisition_dmesg" - - -// mac addresses are store in ASCII as a list of lines that end with \n, -// for example, "00:03:93:14:c5:04\n" -// It is all the mac addresses that were on the acquisition system - -// DMESG is the output from the "dmesg" command at the time of acquisition - - -/* segment names: device hardware */ - -#define AF_AFFLIB_VERSION "afflib_version" // version of AFFLIB that made this file -#define AF_DEVICE_MANUFACTURER "device_manufacturer" -#define AF_DEVICE_MODEL "device_model" // string for ident from drive -#define AF_DEVICE_SN "device_sn" // string of drive capabilities -#define AF_DEVICE_FIRMWARE "device_firmware" // string of drive capabilities -#define AF_DEVICE_SOURCE "device_source" // string -#define AF_CYLINDERS "cylinders" // quad with # cylinders -#define AF_HEADS "heads" // quad with # heads -#define AF_SECTORS_PER_TRACK "sectors_per_track"// quad with # sectors/track -#define AF_LBA_SIZE "lbasize" -#define AF_HPA_PRESENT "hpa_present" // flag = 1 or 0 -#define AF_DCO_PRESENT "dco_present" // flag = 1 or 0 -#define AF_LOCATION_IN_COMPUTER "location_in_computer" // text, where it was found -#define AF_DEVICE_CAPABILITIES "device_capabilities" // string; human-readable - -#define AF_MAX_NAME_LEN 64 // segment names should not be larger than this - -/* AFF error codes */ -#define AF_ERROR_NO_ERROR 0 -#define AF_ERROR_EOF -1 -#define AF_ERROR_DATASMALL -2 -#define AF_ERROR_TAIL -3 // no tail, or error reading tail -#define AF_ERROR_SEGH -4 // no head, or error reading head -#define AF_ERROR_NAME -5 // segment name invalid -#define AF_ERROR_INVALID_ARG -6 // argument invalid -#define AF_ERROR_NO_AES -7 // AES support is not compiled in -#define AF_ERROR_AES_TOO_SMALL -8 // and AES-encrypted segment was too small -#define AF_ERROR_KEY_SET -9 // a key was already set -#define AF_ERROR_AFFKEY_EXISTS -10 // a key already exists in file an attempt was made to establish -#define AF_ERROR_AFFKEY_NOT_EXIST -11 // a key does not exist and an attempt was made to use it. -#define AF_ERROR_AFFKEY_WRONG_VERSION -12 -#define AF_ERROR_WRONG_PASSPHRASE -13 -#define AF_ERROR_RNG_FAIL -13 -#define AF_ERROR_HASH_FAIL -14 -#define AF_ERROR_NO_SHA256 -15 - -#define AF_SIG_GOOD 0 -#define AF_ERROR_SIG_BAD -15 -#define AF_ERROR_SIG_NO_CERT -16 -#define AF_ERROR_SIG_CANNOT_READ_PUBLIC_KEY -17 -#define AF_ERROR_SIG_DATAREAD_ERROR -18 -#define AF_ERROR_SIG_MALLOC -19 -#define AF_ERROR_SIG_READ_ERROR -20 -#define AF_ERROR_SIG_SIG_SEG -21 // can't verify the signature on a signature segment -#define AF_ERROR_SIG_NOT_COMPILED -22 // afflib compiled without signature support - - -/* AFF environment variables */ -#define AFFLIB_CACHE_STATS "AFFLIB_CACHE_STATS" // make non-zero to dump stats to STDERR at end -#define AFFLIB_CACHE_DEBUG "AFFLIB_CACHE_DEBUG" // make "1" to dump a trace of cache events to stderr -#define AFFLIB_CACHE_PAGES "AFFLIB_CACHE_PAGES" // Size of the page cache -#define AFFLIB_CACHE_PAGES_DEFAULT 32 // default number of cache pages -#define AFFLIB_BIGTMP "AFFLIB_BIGTMP" // default directory to put very big files for test programs -#define AFFLIB_TRACEFILE "AFFLIB_TRACEFILE" // If set, send a record of all activity to the location -/* passphrases for single-key cryptography */ -#define AFFLIB_PASSPHRASE "AFFLIB_PASSPHRASE" -#define AFFLIB_PASSPHRASE_FILE "AFFLIB_PASSPHRASE_FILE" -#define AFFLIB_PASSPHRASE_FD "AFFLIB_PASSPHRASE_FD" - -/* passphrases for signing keys */ -#define AFFLIB_PEM_SIGNING_PASSPHRASE "AFFLIB_PEM_SIGNING_PASSPHRASE" - -/* passphrases for sealing keys */ - -#define AFFLIB_DECRYPTING_PRIVATE_KEYFILE "AFFLIB_DECRYPTING_PRIVATE_KEYFILE" - -extern FILE *af_trace; // fd to trace to - -/**************************************************************** - *** Not AFF functions at all, but placed here for convenience. - ****************************************************************/ -const char *af_hexbuf(char *dst,int dst_len,const unsigned char *bin,int bytes,int format_flag); - -/* af_hexbuf formats: */ -#define AF_HEXBUF_NO_SPACES 0 -#define AF_HEXBUF_SPACE2 0x0001 // space every 2 characters -#define AF_HEXBUF_SPACE4 0x0002 // space every 4 characters -#define AF_HEXBUF_UPPERCASE 0x1000 // uppercase -#define AF_HEXBUF_LINEBREAK 0x2000 // break every 80 cols - - -/**************************************************************** - *** Internal implementation details below. - ****************************************************************/ - - -#ifdef __never_defined__ -{ -#endif -#ifdef __cplusplus -} -#endif -#endif - - diff -Nru afflib-3.7.7/lib/afflib_i.h afflib-3.7.16/lib/afflib_i.h --- afflib-3.7.7/lib/afflib_i.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/afflib_i.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,689 +0,0 @@ -/* - * afflib_i.h: - * The "master include file" of the AFF Library. - * Includes many fucntions that are not designed - * to be used by application programmers. - * - * - * Copyright (c) 2005-2006 - * Simson L. Garfinkel and Basis Technology, Inc. - * All rights reserved. - * - * This code is derrived from software contributed by - * Simson L. Garfinkel - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Simson L. Garfinkel - * and Basis Technology Corp. - * 4. Neither the name of Simson Garfinkel, Basis Technology, or other - * contributors to this program may be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY SIMSON GARFINKEL, BASIS TECHNOLOGY, - * AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SIMSON GARFINKEL, BAIS TECHNOLOGy, - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef AFFLIB_I_H -#define AFFLIB_I_H - -#ifdef KERNEL_LIBRARY -#ifdef __cplusplus -extern "C" { -#endif -void __cdecl AFDbgPrint (PCSTR Format,...); -#ifdef __cplusplus -} -#endif -#endif - - -/* Should we disable threading? */ -#ifdef DISABLE_PTHREAD -#undef HAVE_PTHREAD -#endif - -/* Standard includes */ -#ifdef HAVE_STRING_H -#include -#endif - -#ifdef HAVE_STDLIB_H -#include -#endif - -#ifdef HAVE_ZLIB_H -#include -#endif - -#ifdef HAVE_SYS_STAT_H -#include -#endif - -#ifdef HAVE_FCNTL_H -#include -#endif - -#ifdef HAVE_ASSERT_H -#include -#endif - -#ifdef HAVE_ERRNO_H -#include -#endif - -#ifdef HAVE_DIRENT_H -#include -#endif - -#ifdef HAVE_ERR_H -#include -#endif - -#ifdef HAVE_ALLOCA_H -#include -#endif - -#ifdef HAVE_LIBCRYPTO -#include -#include // a standard part of OpenSSL -#include -#include -#include -#endif - -#ifdef HAVE_PTHREAD -#include -#define AF_READLOCK(af) pthread_rwlock_rdlock(&af->rwlock); -#define AF_WRLOCK(af) pthread_rwlock_wrlock(&af->rwlock); -#define AF_UNLOCK(af) pthread_rwlock_unlock(&af->rwlock); -#else -/* No threads */ -#define AF_READLOCK(af) {} -#define AF_WRLOCK(af) {} -#define AF_UNLOCK(af) {} -#endif - -#ifdef WIN32 -#if !defined(HAVE__MINGW_H) -#pragma warning(disable: 4996) /* Don't warn on Windows about using POSIX open() instead of _open() */ -#endif -#include -#include -#include // htonl() -#include -#define snprintf _snprintf -#define strcasecmp _stricmp -#define mkdir(path,mode) _mkdir(path) -#define random() rand() -#define access _access -#define strdup _strdup - -#ifndef ENOTSUP -#define ENOTSUP 65536 /* made up number */ -#endif - -#ifndef _MODE_T_ -#define _MODE_T_ -typedef unsigned short mode_t; -typedef unsigned short _mode_t; -#endif - -#ifndef S_ISDIR -#define S_ISDIR(m)(((m) & 0170000) == 0040000) -#endif - -#if !defined(HAVE__MINGW_H) -#define ftruncate(fd,size) _chsize_s(fd,size) -#define MAXPATHLEN 1024 -#endif - -#if defined(HAVE__MINGW_H) -#ifndef ftello -#define ftello ftello64 -#endif - -#ifndef fseeko -#define fseeko fseeko64 -#endif - -#else -#define ftello _ftelli64 /* replaces ftello64 in VC2008 */ -#define fseeko _fseeki64 -#endif - -#endif -/** END OF WIN32 DEFINES **/ - -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -/* Pick an appropriate POINTER_FMT; isn't there an ANSI standard for this? */ -#ifdef __APPLE__ -#define POINTER_FMT "%p" -#endif - -#ifdef linux -#define POINTER_FMT "%p" -#endif - -#ifndef POINTER_FMT -#define POINTER_FMT "%x" // guess -#endif - -/* Handle systems that are missing some #defines */ - -#ifndef O_BINARY -#define O_BINARY 0 // for Windows compatability -#endif - -#ifndef ENOTSUP -#define ENOTSUP EOPNOTSUPP -#endif - -#ifndef O_ACCMODE -#define O_ACCMODE 0x0003 -#endif - -/* If these functions do not exist, we need to create our own */ - -#ifndef HAVE_ERR -void err(int eval, const char *fmt, ...); -#endif - -#ifndef HAVE_ERRX -void errx(int eval, const char *fmt, ...); -#endif - -#ifndef HAVE_WARN -void warn(const char *fmt, ...); -#endif - -#ifndef HAVE_WARNX -void warnx(const char *fmt, ...); -#endif - -/* access function */ -#ifndef F_OK -#define F_OK 0 /* test for existence of file */ -#endif - -#ifndef X_OK -#define X_OK 0x01 /* test for execute or search permission */ -#endif - -#ifndef W_OK -#define W_OK 0x02 /* test for write permission */ -#endif - -#ifndef R_OK -#define R_OK 0x04 /* test for read permission */ -#endif - - -#if defined(WIN32) && !defined(HAVE__MINGW_H) -/**************************************************************** - *** Windows emulation of opendir()/readdir() - *** From php - ****************************************************************/ - -/* struct dirent - same as Unix */ - -struct dirent { - long d_ino; /* inode (always 1 in WIN32) */ - off_t d_off; /* offset to this dirent */ - int d_reclen; /* length of d_name; was unsigned short */ - char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */ -}; - - -/* typedef DIR - not the same as Unix */ -typedef struct { - long handle; /* _findfirst/_findnext handle */ - short offset; /* offset into directory */ - short finished; /* 1 if there are not more files */ - struct _finddata_t fileinfo; /* from _findfirst/_findnext */ - char *dir; /* the dir we are reading */ - struct dirent dent; /* the dirent to return */ -} DIR; - -/* Function prototypes */ - - -#ifdef __cplusplus -extern "C" { -#endif - -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -int closedir(DIR *); -int rewinddir(DIR *); - - -#ifdef __cplusplus -} -#endif -#endif - - -/**************************************************************** - *** AFFLIB internal stuff follows. - ****************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef NEVER_DEFINED -} -#endif - -#if defined(HAVE_LIBEXPAT) -#define USE_AFFSIGS -#endif - -struct _AFFILE { - int version; // 2 - void *tag; // available to callers; unused by AFFLIB - - struct af_vnode *v; // which function table to use. - struct _AFFILE *parent; // for AFF file inside an AFD - - /* For all files */ - int openflags; // how it was opened - int openmode; // how we were asked to open it; more - int exists; // did file exist before open was called? - - /* From URLs */ - char *fname; // Filename of file; be sure to free when done - char *protocol; // could be "file" or "s3" - char *username; // optionally specified in URL - char *password; // from URL; erase after use. - char *hostname; // from URL - int port; // from URL - - /* Extended Logging */ - char error_str[64]; // what went wrong - - /* Implement a stream abstraction */ - uint64_t image_size; // last mappable byte of disk image - uint64_t image_size_in_file; // see if it was changed... - uint32_t image_pagesize; // the size of image data segments in this file - uint32_t image_sectorsize; - uint64_t pos; // location in stream; should be signed because of comparisons - - /* Page buffer cache */ - struct aff_pagebuf *pb; // the current page buffer - struct aff_pagebuf *pbcache; // array of pagebufs - int num_pbufs; // number of pagebufs; default is 1 - int afftime; // for updating last - int64_t cur_page; // used by vnode_raw to fake pages must be able to go negative. - - int debug; // for debugging, of course - unsigned int badflag_set:1; // is badflag set? - unsigned char *badflag; // bad sector flag - - - /****************************************************************/ - /* Right now the instance variables for each implementation are here, - * which is ugly but easier for development... - */ - - /* For AFF Segment Files; this could be moved into private storage... */ - FILE *aseg; - struct aff_toc_mem *toc; // table of contents - int toc_count; // number of directory elements - - /****************************************************************/ - - unsigned int write_md5:1; // automatically write the MD5 for each page - unsigned int write_sha1:1; - unsigned int write_sha256:1; - - - /* These are for optimizing updates; really this should go away and we should just - * exmaine the TOC to find a hole, but currently we don't do that. - */ - unsigned int direction_changes; // how many times have we changed directions? - int last_direction; // should be 1 or -1 - unsigned int random_access:1; // are we in random access mode? - - /* additional support for writing. */ - unsigned int compression_type; // preferred compression type - int compression_level; // 0 is no compression - - - /* w_callback: - * A callback that is called before and after each segment is written. - * Called with the arguments (i,0,0) at the beginning of the write operation. - * Called with the arguments (i,j,k) at the end of the write operation. - * i = segment number - * j = segment length - * If segment is being written with compresison, k = compressed length. - * If segment is written w/o compression, k = 0 - */ - void (*w_callback)(struct affcallback_info *acbi); - // called at start and end of compression. - - uint64_t maxsize; // maximum file size of a multi-segment files, - // or 0 if this is not a multi-segment file - - /* Performance Counters */ - uint64_t bytes_memcpy; // total number of bytes memcpy'ed - uint64_t pages_written; // total number of pages written - uint64_t pages_compressed; // total number of pages compressed - uint64_t pages_decompressed; - uint64_t pages_read; // total number of pages read - uint64_t bytes_written; - uint64_t cache_hits; - uint64_t cache_misses; // total number of pages flushed from cache - - void *vnodeprivate; // private storage for the vnode - void (*error_reporter)(const char *fmt, ...); - struct af_crypto *crypto; -#ifdef HAVE_PTHREAD - pthread_rwlock_t rwlock; // automatically created and destroyed if pthread exists -#endif - struct af_vnode_info *vni_cache; // vstat cache -}; - - - -/* af_crypto: - * copy of AES encrypt and decrypt keys. - */ -void af_crypto_allocate(AFFILE *af); -void af_crypto_deallocate(AFFILE *af); - -struct af_crypto { - uint32_t sealing_key_set:1; // encryption key has been set - uint32_t auto_encrypt:1; // encrypt segments when we write - uint32_t auto_decrypt:1; // automatically decrypto when we read -#ifdef AES_BLOCK_SIZE - AES_KEY ekey; // encrypt key - AES_KEY dkey; // decrypt key -#endif -#ifdef HAVE_OPENSSL_EVP_H - EVP_PKEY *sign_privkey; // signing private key (to write signatures) - EVP_PKEY *sign_pubkey; // signing public key (to verify signatures) - X509 *sign_cert; // signing certificate (for verifying signatures) - /* Sealing is kept locally and immediately turned into a dkey & ekey */ -#endif -}; - - -/* The AFF STREAM VNODE */ -struct af_vnode { - int type; // numeric vnode type - int flag; // file system flag type - const char *name; - int (*identify)(const char *fname,int exists); // returns 1 if file system is identified by implementation; - int (*open)(AFFILE *af); - int (*close)(AFFILE *af); - int (*vstat)(AFFILE *af,struct af_vnode_info *); // returns info about the vnode image file - int (*get_seg)(AFFILE *af,const char *name,uint32_t *arg, uint8_t *data,size_t *datalen); - int (*get_next_seg)(AFFILE *af,char *segname,size_t segname_len, - uint32_t *arg, uint8_t *data, size_t *datalen); - int (*rewind_seg)(AFFILE *af); - int (*update_seg)(AFFILE *af,const char *name,uint32_t arg, - const uint8_t *value,uint32_t vallen); - int (*del_seg)(AFFILE *af,const char *name); - int (*read)(AFFILE *af,uint8_t *buf,uint64_t offset,size_t count); - int (*write)(AFFILE *af,uint8_t *buf,uint64_t offset,size_t count); -}; - -/* VNODE Flags */ -#define AF_VNODE_TYPE_PRIMITIVE 0x01 // single-file implementation -#define AF_VNODE_TYPE_COMPOUND 0x02 // multi-file implementation -#define AF_VNODE_TYPE_RELIABLE 0x04 // writes are reliable; no need to verify them. -#define AF_VNODE_MAXSIZE_MULTIPLE 0x08 // maxsize must be multiple of pagesize (for AFM and splitraw) -#define AF_VNODE_NO_SIGNING 0x10 // vnode does not support signing (like raw) -#define AF_VNODE_NO_SEALING 0x20 // vnode does not support sealing (like raw and afd) - -#define AF_SEALING_VNODE(af) (!(af->v->flag & AF_VNODE_NO_SEALING)) -#define AF_SIGNING_VNODE(af) (!(af->v->flag & AF_VNODE_NO_SIGNING)) -#define AF_SEALING(af) AF_SEALING_VNODE(af) && af->crypto && af->crypto->sealing_key_set - - -/* The header for an AFF file. All binary numbers are stored in network byte order. */ -#define AF_HEADER "AFF10\r\n\000" -struct af_head { - char header[8]; // "AFF10\r\n\000" - /* segments follow */ -}; - - -/* The header of each segment */ -#define AF_SEGHEAD "AFF\000" -struct af_segment_head { - char magic[4]; // "AFF\000" - uint32_t name_len:32; // length of segment name - uint32_t data_len:32; // length of segment data, if any - uint32_t flag:32; // argument for name; - /* name follows, then data */ -}; - -/* The tail of each segment */ -#define AF_SEGTAIL "ATT\000" -struct af_segment_tail { - char magic[4]; // "ATT\000" - uint32_t segment_len:32; // includes head, tail, name & length -}; - - -/* How 64-bit values are stored in a segment */ -#pragma pack(1) -struct aff_quad { - uint32_t low:32; - uint32_t high:32; -}; -#pragma pack() - - -/* As it is kept in memory */ -struct aff_toc_mem { - char *name; // name of this directory entry - uint64_t offset; // offset from beginning of file. - uint64_t segment_len; // includes head, tail, name & length -}; - -/* How encryption keys are stored */ -struct affkey { - uint8_t version[4]; - uint8_t affkey_aes256[32]; // AFF key encrypted with SHA-256 of passphrase - // encrypted as two codebooks in a row; no need for CBC - uint8_t zeros_aes256[16]; // all zeros encrypted with SHA-256 of passphrase -}; -#define AFFKEY_SIZE 4+32+16 - - -void af_initialize(); // initialize the AFFLIB - // automatically called by af_open() - -/* Internal identification routines */ -int af_identify_file_type(const char *filename,int exists); // returns type of a file; if exists=1, file must exist -const char *af_identify_file_name(const char *filename,int exists); // returns name of a file type; -int split_raw_increment_fname (char *fn); /* exposed for testing in aftest */ - -AFFILE *af_open_with(const char *filename,int flags,int mode, struct af_vnode *v); -extern struct af_vnode *af_vnode_array[]; // array of filesystems; last is a "0" - -int af_last_seg(AFFILE *af,char *last_segname,int last_segname_len,int64_t *pos); -int af_make_badflag(AFFILE *af); // creates a badflag and puts it -int af_make_gid(AFFILE *af); // created an AF_IMAGE_GID if it doesn't exist -extern char af_error_str[64]; - - -#define AFF_DEFAULT_PAGESIZE (1024*1024*16) - - -/* afflib_os.cpp: - * Operating-system specific code. - */ - -/* af_figure_media: - * Returns information about the media in a structure. - * Returns 0 if successful, -1 if error. - */ - -struct af_figure_media_buf { - int version; - int sector_size; - uint64_t total_sectors; - uint64_t max_read_blocks; // was previously 4-bytes; must be 8! -}; -int af_figure_media(int fd,struct af_figure_media_buf *); - -/**************************************************************** - *** Lowest-level routines for manipulating the AFF File... - ****************************************************************/ - -/* Navigating within the AFFILE */ -/* probe the next segment. - * Returns: 0 if success - * -1 if error - * -2 if segname_len was not large enough to hold segname - * - segname - the name of the next segment. - * - segsize - number of bytes the entire segment is. - * - * doesn't change af->aseg pointer if do_rewind is true, otherwise leaves stream - * positioned ready to read the data - */ - -int af_probe_next_seg(AFFILE *af,char *segname,size_t segname_len, - uint32_t *arg,size_t *datasize, size_t *segsize,int do_rewind); -int af_backspace(AFFILE *af); // back up one segment - - - -/**************************************************************** - *** Reading functions - ****************************************************************/ - - -/* Support for data pages. This is what the stream system is built upon. - * Note: pagename to string translation happens inside afflib.cpp, not inside - * the vnode driver. - */ -int af_page_size(AFFILE *af); // legacy (now is af_get_pagesize) -void af_read_sizes(AFFILE *af); // sets up values if we can get them. -int af_set_pagesize(AFFILE *af,uint32_t pagesize); // sets the pagesize; fails with -1 if imagesize >=0 -int af_set_sectorsize(AFFILE *AF,int sectorsize); // fails with -1 if imagesize>=0 -int af_get_sectorsize(AFFILE *AF); // returns sector size -int af_has_pages(AFFILE *af); // does the underlying system support pages? -int af_get_pagesize(AFFILE *af); // returns page size, or -1 -int af_get_page_raw(AFFILE *af,int64_t pagenum,uint32_t *arg,uint8_t *data,size_t *bytes); -int af_get_page(AFFILE *af,int64_t pagenum,uint8_t *data,size_t *bytes); -#define AF_SIGFLAG_NOSIG 0x0001 // do not write signatures with af_update_segf() -#define AF_SIGFLAG_NOSEAL 0x0002 // do not encrypt an af_update_segf() - -/**************************************************************** - *** Writing functions - ****************************************************************/ - -extern int af_cache_debug; // sets level of verbosity */ -int af_update_page(AFFILE *af,int64_t pagenum,uint8_t *data,int datalen); -int af_update_segf(AFFILE *af,const char *name, - uint32_t arg,const uint8_t *value,uint32_t vallen,uint32_t sigflag); - -void af_invalidate_vni_cache(AFFILE *af); -void af_cache_writethrough(AFFILE *af,int64_t pagenum, - const uint8_t *buf,int bufflen); -int af_cache_flush(AFFILE *af); // write buffers to disk -struct aff_pagebuf *af_cache_alloc(AFFILE *af,int64_t pagenum); - - -/**************************************************************** - ***/ - -/* afflib_util.cpp - */ -uint64_t af_decode_q(uint8_t buf[8]); // return buf[8] into an unsigned quad -const char *af_commas(char buf[64],int64_t val); -int af_hasmeta(const char *buf); // return 1 if buf has shell metacharacters -int af_is_filestream(const char *filename); // return 1 if file:// or filename -void af_parse_url(const char *url,char **protocol,char **hostname, - char **username,char **password,int *port,char **path); - -#ifndef HAVE_STRLCPY -size_t strlcpy(char *dest,const char *src,size_t dest_size); -#endif - -#ifndef HAVE_STRLCAT -size_t strlcat(char *dest,const char *src,size_t dest_size); -#endif - - -/**************************************************************** - *** Table of Contents - ****************************************************************/ - -/* Needs a rewrite for efficiency */ - -/* afflib_toc.cpp: - * Table of contents management routines - * Remember: all of these routines may fail, because the whole TOC may not - * fit in memory... - * - * This is all experimental right now. - */ - -int aff_segment_overhead(const char *segname); -int aff_toc_free(AFFILE *af); -void aff_toc_print(AFFILE *af); -int aff_toc_build(AFFILE *af); // build by scanning the AFFILE -struct aff_toc_mem *aff_toc(AFFILE *af,const char *segname); -int aff_toc_del(AFFILE *af,const char *segname); -void aff_toc_update(AFFILE *af,const char *segname,uint64_t offset,uint64_t datalen); - -struct aff_toc_mem *aff_toc_next_seg(AFFILE *af, uint64_t offset); -int aff_toc_find_hole(AFFILE *af, uint64_t min_size, uint64_t *offset, uint64_t *size); - -/* lzma_glue.cpp: - * For the LZMA compression engine - */ -int lzma_compress(uint8_t *dest,size_t *destLen, const uint8_t *data,size_t datalen,int level); -int lzma_uncompress(uint8_t *buf,size_t *buflen, const uint8_t *cbuf,size_t cbuf_size); - -#ifdef NEVER_DEFINED -{ -#endif -#ifdef __cplusplus -} -#endif -#endif - - diff -Nru afflib-3.7.7/lib/afflib_pages.cpp afflib-3.7.16/lib/afflib_pages.cpp --- afflib-3.7.7/lib/afflib_pages.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/afflib_pages.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -168,7 +168,7 @@ size_t page_len=0; if (af_trace){ - fprintf(af_trace,"af_get_page(%p,pagenum=%"I64d",buf=%p,bytes=%u)\n",af,pagenum,data,(int)*bytes); + fprintf(af_trace,"af_get_page(%p,pagenum=%" I64d ",buf=%p,bytes=%u)\n",af,pagenum,data,(int)*bytes); } /* Find out the size of the segment and if it is compressed or not. @@ -247,17 +247,17 @@ case Z_OK: break; case Z_ERRNO: - (*af->error_reporter)("Z_ERRNOR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_ERRNOR decompressing segment %" I64d,pagenum); case Z_STREAM_ERROR: - (*af->error_reporter)("Z_STREAM_ERROR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_STREAM_ERROR decompressing segment %" I64d,pagenum); case Z_DATA_ERROR: - (*af->error_reporter)("Z_DATA_ERROR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_DATA_ERROR decompressing segment %" I64d,pagenum); case Z_MEM_ERROR: - (*af->error_reporter)("Z_MEM_ERROR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_MEM_ERROR decompressing segment %" I64d,pagenum); case Z_BUF_ERROR: - (*af->error_reporter)("Z_BUF_ERROR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_BUF_ERROR decompressing segment %" I64d,pagenum); case Z_VERSION_ERROR: - (*af->error_reporter)("Z_VERSION_ERROR decompressing segment %"I64d,pagenum); + (*af->error_reporter)("Z_VERSION_ERROR decompressing segment %" I64d,pagenum); default: (*af->error_reporter)("uncompress returned an invalid value in get_segment"); } @@ -266,13 +266,13 @@ #ifdef USE_LZMA case AF_PAGE_COMP_ALG_LZMA: res = lzma_uncompress(data,bytes,compressed_data,compressed_data_len); - if (af_trace) fprintf(af_trace," LZMA decompressed page %"I64d". %d bytes => %u bytes\n", + if (af_trace) fprintf(af_trace," LZMA decompressed page %" I64d ". %d bytes => %u bytes\n", pagenum,(int)compressed_data_len,(int)*bytes); switch(res){ case 0:break; // OK - case 1:(*af->error_reporter)("LZMA header error decompressing segment %"I64d"\n",pagenum); + case 1:(*af->error_reporter)("LZMA header error decompressing segment %" I64d "\n",pagenum); break; - case 2:(*af->error_reporter)("LZMA memory error decompressing segment %"I64d"\n",pagenum); + case 2:(*af->error_reporter)("LZMA memory error decompressing segment %" I64d "\n",pagenum); break; } break; @@ -553,7 +553,7 @@ ret = -1; // got an error; keep going, though } p->pagebuf_dirty = 0; - if(af_trace) fprintf(af_trace,"af_cache_flush: slot %d page %"PRIu64" flushed.\n",i,p->pagenum); + if(af_trace) fprintf(af_trace,"af_cache_flush: slot %d page %" PRIu64 " flushed.\n",i,p->pagenum); } } return ret; // now return the error that I might have gotten @@ -570,7 +570,7 @@ struct aff_pagebuf *p = &af->pbcache[i]; if(p->pagenum_valid && p->pagenum == pagenum){ if(p->pagebuf_dirty){ - (*af->error_reporter)("af_cache_writethrough: overwriting page %"I64u".\n",pagenum); + (*af->error_reporter)("af_cache_writethrough: overwriting page %" I64u ".\n",pagenum); exit(-1); // this shouldn't happen } memcpy(p->pagebuf,buf,bufflen); @@ -593,7 +593,7 @@ struct aff_pagebuf *af_cache_alloc(AFFILE *af,int64_t pagenum) { - if(af_trace) fprintf(af_trace,"af_cache_alloc(%p,%"I64d")\n",af,pagenum); + if(af_trace) fprintf(af_trace,"af_cache_alloc(%p,%" I64d ")\n",af,pagenum); /* Make sure nothing in the cache is dirty */ if(af_cache_flush(af) < 0) @@ -604,7 +604,7 @@ struct aff_pagebuf *p = &af->pbcache[i]; if(p->pagenum_valid && p->pagenum==pagenum){ af->cache_hits++; - if(af_trace) fprintf(af_trace," page %"I64d" satisfied fromcache\n",pagenum); + if(af_trace) fprintf(af_trace," page %" I64d " satisfied fromcache\n",pagenum); p->last = cachetime++; return p; } @@ -617,7 +617,7 @@ struct aff_pagebuf *p = &af->pbcache[i]; if(p->pagenum_valid==0){ slot = i; - if(af_trace) fprintf(af_trace," slot %d given to page %"I64d"\n",slot,pagenum); + if(af_trace) fprintf(af_trace," slot %d given to page %" I64d "\n",slot,pagenum); break; } } @@ -632,7 +632,7 @@ } } slot = oldest_i; - if(af_trace) fprintf(af_trace," slot %d assigned to page %"I64d"\n",slot,pagenum); + if(af_trace) fprintf(af_trace," slot %d assigned to page %" I64d "\n",slot,pagenum); } /* take over this slot */ struct aff_pagebuf *p = &af->pbcache[slot]; @@ -656,7 +656,7 @@ if(af_trace){ fprintf(af_trace," current pages in cache: "); for(int i=0;inum_pbufs;i++){ - fprintf(af_trace," %"I64d,af->pbcache[i].pagenum); + fprintf(af_trace," %" I64d,af->pbcache[i].pagenum); } fprintf(af_trace,"\n"); } diff -Nru afflib-3.7.7/lib/afflib_stream.cpp afflib-3.7.16/lib/afflib_stream.cpp --- afflib-3.7.7/lib/afflib_stream.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/afflib_stream.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -29,14 +29,14 @@ { AF_WRLOCK(af); if(af->image_size>0){ - (*af->error_reporter)("Cannot set maxsize as imagesize is already set (%"I64d")",af->image_size); + (*af->error_reporter)("Cannot set maxsize as imagesize is already set (%" I64d ")",af->image_size); AF_UNLOCK(af); return -1; // now allowed to set if imagesize is bigger than 0 } if((af->image_pagesize!=0) && (af->v->type & AF_VNODE_MAXSIZE_MULTIPLE) && (maxsize % af->image_pagesize != 0)){ - (*af->error_reporter)("Cannot set maxsize to %"I64d" --- not multiple of pagesize=%d\n", + (*af->error_reporter)("Cannot set maxsize to %" I64d " --- not multiple of pagesize=%d\n", maxsize,af->image_pagesize); AF_UNLOCK(af); return -1; @@ -83,7 +83,7 @@ int total = 0; AF_WRLOCK(af); // wrlock because cache may change - if (af_trace) fprintf(af_trace,"af_read(%p,%p,%d) (pos=%"I64d")\n",af,buf,(int)count,af->pos); + if (af_trace) fprintf(af_trace,"af_read(%p,%p,%d) (pos=%" I64d ")\n",af,buf,(int)count,af->pos); if (af->v->read){ // check for bypass int r = (af->v->read)(af, buf, af->pos, count); if(r>0) af->pos += r; @@ -162,7 +162,7 @@ { AF_WRLOCK(af); if (af_trace){ - fprintf(af_trace,"af_write(af=%p,buf=%p,count=%d) pos=%"I64d"\n", af,buf,(int)count,af->pos); + fprintf(af_trace,"af_write(af=%p,buf=%p,count=%d) pos=%" I64d "\n", af,buf,(int)count,af->pos); } /* Invalidate caches */ af_invalidate_vni_cache(af); diff -Nru afflib-3.7.7/lib/aff_toc.cpp afflib-3.7.16/lib/aff_toc.cpp --- afflib-3.7.7/lib/aff_toc.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/aff_toc.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -29,7 +29,7 @@ printf("AF DIRECTORY:\n"); for(int i=0;itoc_count;i++){ if(af->toc[i].name){ - printf("%-32s @%"I64u" len: %"I64u" \n",af->toc[i].name, af->toc[i].offset,af->toc[i].segment_len); + printf("%-32s @%" I64u " len: %" I64u " \n",af->toc[i].name, af->toc[i].offset,af->toc[i].segment_len); } } } diff -Nru afflib-3.7.7/lib/aftest.cpp afflib-3.7.16/lib/aftest.cpp --- afflib-3.7.7/lib/aftest.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/aftest.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -38,6 +38,11 @@ #define MIN(x,y) ((x)<(y)?(x):(y)) #endif +/* Support OpenSSL before 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define EVP_MD_CTX_new EVP_MD_CTX_create +#define EVP_MD_CTX_free EVP_MD_CTX_destroy +#endif const char *filename(char *buf,int buflen,const char *base) { @@ -233,7 +238,7 @@ unsigned char *buf2 = (unsigned char *)malloc(total_bytes); /* First half is random */ - RAND_pseudo_bytes(buf,total_bytes/2); + RAND_bytes(buf,total_bytes/2); /* Second half is a bit more predictable */ for(int i=total_bytes/2;i -#include -#endif -#include -#include -#include - -class aftimer { - struct timeval t0; - bool running; - long total_sec; - long total_usec; - double lap_time_; // time from when we last did a "stop" -public: - aftimer():t0(),running(false),total_sec(0),total_usec(0),lap_time_(0){} - - void start(); // start the timer - void stop(); // stop the timer - - time_t tstart() { return t0.tv_sec;} // time we started - double elapsed_seconds(); // how long timer has been running, total - double lap_time(); // how long the timer is running this time - double eta(double fraction_done); // calculate ETA in seconds, given fraction - std::string hms(long t); // turn a number of seconds into h:m:s - std::string elapsed_text(); /* how long we have been running */ - std::string eta_text(double fraction_done); // h:m:s - std::string eta_time(double fraction_done); // the actual time -}; - -/* This code in part from - * http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/430449b3-f6dd-4e18-84de-eebd26a8d668 - */ - -#ifdef WIN32 -# include -# include -# ifndef DELTA_EPOCH_IN_MICROSECS -# if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) -# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 -# else -# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL -# endif -# endif -#endif - -inline void timestamp(struct timeval *t) -{ -#ifdef WIN32 - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - unsigned __int64 tmpres = 0; - tmpres |= ft.dwHighDateTime; - tmpres <<= 32; - tmpres |= ft.dwLowDateTime; - - /*converting file time to unix epoch*/ - tmpres -= DELTA_EPOCH_IN_MICROSECS; - tmpres /= 10; /*convert into microseconds*/ - t->tv_sec = (long)(tmpres / 1000000UL); - t->tv_usec = (long)(tmpres % 1000000UL); -#else - gettimeofday(t,NULL); -#endif -} - -inline void aftimer::start() -{ - timestamp(&t0); - running = 1; -} - -inline void aftimer::stop(){ - if(running){ - struct timeval t; - timestamp(&t); - total_sec += t.tv_sec - t0.tv_sec; - total_usec += t.tv_usec - t0.tv_usec; - lap_time_ = (double)(t.tv_sec - t0.tv_sec) + (double)(t.tv_usec - t0.tv_usec)/1000000.0; - running = false; - } -} - -inline double aftimer::lap_time() -{ - return lap_time_; -} - -inline double aftimer::elapsed_seconds() -{ - double ret = (double)total_sec + (double)total_usec/1000000.0; - if(running){ - struct timeval t; - timestamp(&t); - ret += t.tv_sec - t0.tv_sec; - ret += (t.tv_usec - t0.tv_usec) / 1000000.0; - } - return ret; -} - -inline std::string aftimer::hms(long t) -{ - char buf[64]; - int days = t / (60*60*24); - - t = t % (60*60*24); /* what's left */ - - int h = t / 3600; - int m = (t / 60) % 60; - int s = t % 60; - buf[0] = 0; - switch(days){ - case 0: - snprintf(buf,sizeof(buf),"%2d:%02d:%02d",h,m,s); - break; - case 1: - snprintf(buf,sizeof(buf),"%d day, %2d:%02d:%02d",days,h,m,s); - break; - default: - snprintf(buf,sizeof(buf),"%d days %2d:%02d:%02d",days,h,m,s); - } - return std::string(buf); -} - -inline std::string aftimer::elapsed_text() -{ - return hms((int)elapsed_seconds()); -} - -/** - * returns the number of seconds until the job is complete. - */ -inline double aftimer::eta(double fraction_done) -{ - double t = elapsed_seconds(); - if(t<=0) return -1; // can't figure it out - if(fraction_done<=0) return -1; // can't figure it out - return (t * 1.0/fraction_done - t); -} - -/** - * Retuns the number of hours:minutes:seconds until the job is done. - */ -inline std::string aftimer::eta_text(double fraction_done) -{ - double e = eta(fraction_done); - if(e<0) return std::string("n/a"); // can't figure it out - return hms((long)e); -} - -/** - * Returns the time when data is due. - */ -inline std::string aftimer::eta_time(double fraction_done) -{ - time_t when = time_t(eta(fraction_done)) + time(0); - struct tm tm; -#ifdef HAVE_LOCALTIME_R - localtime_r(&when,&tm); -#else - tm = *localtime(&when); -#endif - - char buf[64]; - snprintf(buf,sizeof(buf),"%02d:%02d:%02d",tm.tm_hour,tm.tm_min,tm.tm_sec); - return std::string(buf); -} - -#endif - -#endif diff -Nru afflib-3.7.7/lib/crypto.cpp afflib-3.7.16/lib/crypto.cpp --- afflib-3.7.7/lib/crypto.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/crypto.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -25,8 +25,11 @@ #include #endif - - +/* Support OpenSSL before 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define EVP_MD_CTX_new EVP_MD_CTX_create +#define EVP_MD_CTX_free EVP_MD_CTX_destroy +#endif /**************************************************************** @@ -82,10 +85,14 @@ if(!sha256) return -1; uint32_t sha256_buflen = 32; - EVP_MD_CTX ctx; - EVP_DigestInit(&ctx,sha256); - EVP_DigestUpdate(&ctx,data,datalen); - if(EVP_DigestFinal(&ctx,md,&sha256_buflen)!=1) return -1; // EVP_DigestFinal returns 1 for success + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx,sha256); + EVP_DigestUpdate(ctx,data,datalen); + if(EVP_DigestFinal(ctx,md,&sha256_buflen)!=1){ // EVP_DigestFinal returns 1 for success + EVP_MD_CTX_free(ctx); + return -1; + } + EVP_MD_CTX_free(ctx); return 0; } @@ -290,7 +297,6 @@ /* Okay; make a random key and encrypt it with the passphrase */ unsigned char affkey[32]; int r = RAND_bytes(affkey,sizeof(affkey)); // makes a random key; with REAL random bytes - if(r!=1) r = RAND_pseudo_bytes(affkey,sizeof(affkey)); // true random not supported if(r!=1) return AF_ERROR_RNG_FAIL; // pretty bad... /* I have the key, now save it */ @@ -387,22 +393,23 @@ const EVP_MD *sha256 = EVP_get_digestbyname("SHA256"); if(!sha256) return -1; // no SHA256. - EVP_MD_CTX md; /* EVP message digest */ - + EVP_MD_CTX *md = EVP_MD_CTX_new(); /* EVP message digest */ /* make the plaintext message */ memset(ptext,0,sizeof(ptext)); strcpy(ptext,"Test Message"); - EVP_SignInit(&md,sha256); - EVP_SignUpdate(&md,ptext,sizeof(ptext)); - EVP_SignFinal(&md,sig,&siglen,privkey); + EVP_SignInit(md,sha256); + EVP_SignUpdate(md,ptext,sizeof(ptext)); + EVP_SignFinal(md,sig,&siglen,privkey); /* Verify the message */ - EVP_VerifyInit(&md,sha256); - EVP_VerifyUpdate(&md,ptext,sizeof(ptext)); - if(EVP_VerifyFinal(&md,sig,siglen,pubkey)!=1){ + EVP_VerifyInit(md,sha256); + EVP_VerifyUpdate(md,ptext,sizeof(ptext)); + if(EVP_VerifyFinal(md,sig,siglen,pubkey)!=1){ + EVP_MD_CTX_free(md); return -3; } + EVP_MD_CTX_free(md); return 0; } @@ -494,12 +501,13 @@ unsigned char sig[1024]; /* signature; bigger than needed */ uint32_t siglen = sizeof(sig); /* length of signature */ - EVP_MD_CTX md; /* EVP message digest */ - EVP_SignInit(&md,sha256); - EVP_SignUpdate(&md,(const unsigned char *)segname,strlen(segname)+1); - EVP_SignUpdate(&md,(const unsigned char *)&arg_net,sizeof(arg_net)); - EVP_SignUpdate(&md,data,datalen); - EVP_SignFinal(&md,sig,&siglen,af->crypto->sign_privkey); + EVP_MD_CTX *md = EVP_MD_CTX_new(); /* EVP message digest */ + EVP_SignInit(md,sha256); + EVP_SignUpdate(md,(const unsigned char *)segname,strlen(segname)+1); + EVP_SignUpdate(md,(const unsigned char *)&arg_net,sizeof(arg_net)); + EVP_SignUpdate(md,data,datalen); + EVP_SignFinal(md,sig,&siglen,af->crypto->sign_privkey); + EVP_MD_CTX_free(md); return (*af->v->update_seg)(af,signed_segname,signmode,sig,siglen); } @@ -618,12 +626,13 @@ uint8_t sigbuf[1024]; uint32_t sigbuf_len = sizeof(sigbuf); uint32_t arg_net = htonl(arg); - EVP_MD_CTX md; /* EVP message digest */ - EVP_DigestInit(&md,sha256); - EVP_DigestUpdate(&md,(const unsigned char *)segname,strlen(segname)+1); - EVP_DigestUpdate(&md,(const unsigned char *)&arg_net,sizeof(arg_net)); - EVP_DigestUpdate(&md,segbuf,seglen); - EVP_DigestFinal(&md,sigbuf,&sigbuf_len); + EVP_MD_CTX *md = EVP_MD_CTX_new(); /* EVP message digest */ + EVP_DigestInit(md,sha256); + EVP_DigestUpdate(md,(const unsigned char *)segname,strlen(segname)+1); + EVP_DigestUpdate(md,(const unsigned char *)&arg_net,sizeof(arg_net)); + EVP_DigestUpdate(md,segbuf,seglen); + EVP_DigestFinal(md,sigbuf,&sigbuf_len); + EVP_MD_CTX_free(md); int r = memcmp(sigbuf,sigbuf_,sigbuf_len); if(sigbuf_len != sigbuf_len_) r = -1; // doesn't match free(segbuf); @@ -677,12 +686,13 @@ /* Verify the signature*/ uint32_t arg_net = htonl(arg); - EVP_MD_CTX md; /* EVP message digest */ - EVP_VerifyInit(&md,sha256); - EVP_VerifyUpdate(&md,(const unsigned char *)segname,strlen(segname)+1); - EVP_VerifyUpdate(&md,(const unsigned char *)&arg_net,sizeof(arg_net)); - EVP_VerifyUpdate(&md,segbuf,seglen); - int r = EVP_VerifyFinal(&md,sigbuf,sigbuf_len,af->crypto->sign_pubkey); + EVP_MD_CTX *md = EVP_MD_CTX_new(); /* EVP message digest */ + EVP_VerifyInit(md,sha256); + EVP_VerifyUpdate(md,(const unsigned char *)segname,strlen(segname)+1); + EVP_VerifyUpdate(md,(const unsigned char *)&arg_net,sizeof(arg_net)); + EVP_VerifyUpdate(md,segbuf,seglen); + EVP_MD_CTX_free(md); + int r = EVP_VerifyFinal(md,sigbuf,sigbuf_len,af->crypto->sign_pubkey); free(segbuf); if(r==1) return 0; // verifies @@ -766,7 +776,6 @@ /* First make the affkey */ unsigned char affkey[32]; int r = RAND_bytes(affkey,sizeof(affkey)); - if(r!=1) r = RAND_pseudo_bytes(affkey,sizeof(affkey)); // true random not supported if(r!=1) return AF_ERROR_RNG_FAIL; // pretty bad... af_seal_affkey_using_certificates(af, certfiles, numcertfiles, affkey); @@ -803,11 +812,12 @@ unsigned char affkey_copy[32]; memcpy(affkey_copy,affkey,32); - EVP_CIPHER_CTX cipher_ctx; + EVP_CIPHER_CTX *cipher_ctx = EVP_CIPHER_CTX_new(); /* IV */ unsigned char iv[EVP_MAX_IV_LENGTH]; - RAND_pseudo_bytes(iv, EVP_MAX_IV_LENGTH); /* make a random iv */ + r = RAND_bytes(iv, EVP_MAX_IV_LENGTH); /* make a random iv */ + if(r!=1) return AF_ERROR_RNG_FAIL; // pretty bad... /* EK */ unsigned char *ek=0; @@ -822,15 +832,26 @@ int encrypted_bytes = 0; memset(encrypted_affkey,0,sizeof(encrypted_affkey)); - r = EVP_SealInit(&cipher_ctx,EVP_aes_256_cbc(),ek_array,&ek_size,&iv[0],&seal_pubkey,1); - if(r!=1) return -10; // bad + r = EVP_SealInit(cipher_ctx,EVP_aes_256_cbc(),ek_array,&ek_size,&iv[0],&seal_pubkey,1); + if(r!=1){ + EVP_CIPHER_CTX_free(cipher_ctx); + return -10; // bad + } - r = EVP_SealUpdate(&cipher_ctx,encrypted_affkey,&encrypted_bytes,affkey_copy,sizeof(affkey_copy)); - if(r!=1) return -11; // bad + r = EVP_SealUpdate(cipher_ctx,encrypted_affkey,&encrypted_bytes,affkey_copy,sizeof(affkey_copy)); + if(r!=1){ + EVP_CIPHER_CTX_free(cipher_ctx); + return -11; // bad + } int total_encrypted_bytes = encrypted_bytes; - r = EVP_SealFinal(&cipher_ctx,encrypted_affkey+total_encrypted_bytes,&encrypted_bytes); - if(r!=1) return -12; + r = EVP_SealFinal(cipher_ctx,encrypted_affkey+total_encrypted_bytes,&encrypted_bytes); + if(r!=1){ + EVP_CIPHER_CTX_free(cipher_ctx); + return -12; + } + + EVP_CIPHER_CTX_free(cipher_ctx); total_encrypted_bytes += encrypted_bytes; @@ -926,20 +947,23 @@ unsigned char *encrypted_affkey = buf+int3+EVP_MAX_IV_LENGTH+ek_size; /* Now let's see if we can decode it*/ - EVP_CIPHER_CTX cipher_ctx; - int r = EVP_OpenInit(&cipher_ctx,EVP_aes_256_cbc(),ek,ek_size,iv,seal_privkey); + EVP_CIPHER_CTX *cipher_ctx = EVP_CIPHER_CTX_new(); + int r = EVP_OpenInit(cipher_ctx,EVP_aes_256_cbc(),ek,ek_size,iv,seal_privkey); if(r==1){ /* allocate a buffer for the decrypted data */ decrypted = (unsigned char *)malloc(total_encrypted_bytes); - if(!decrypted) return -1; // shouldn't fail + if(!decrypted){ + EVP_CIPHER_CTX_free(cipher_ctx); + return -1; // shouldn't fail + } int decrypted_len; - r = EVP_OpenUpdate(&cipher_ctx,decrypted,&decrypted_len,encrypted_affkey,total_encrypted_bytes); + r = EVP_OpenUpdate(cipher_ctx,decrypted,&decrypted_len,encrypted_affkey,total_encrypted_bytes); if(r==1){ /* OpenSSL requires that we call EVP_OpenFinal to finish the decryption */ unsigned char *decrypted2 = decrypted+decrypted_len; // where the decryption continues int decrypted2_len = 0; - r = EVP_OpenFinal(&cipher_ctx,decrypted2,&decrypted2_len); + r = EVP_OpenFinal(cipher_ctx,decrypted2,&decrypted2_len); if(r==1){ memcpy(affkey,decrypted,32); ret = 0; // successful return @@ -948,6 +972,7 @@ memset(decrypted,0,total_encrypted_bytes); // overwrite our temp buffer free(decrypted); } + EVP_CIPHER_CTX_free(cipher_ctx); } next:; free(buf); diff -Nru afflib-3.7.7/lib/Makefile.am afflib-3.7.16/lib/Makefile.am --- afflib-3.7.7/lib/Makefile.am 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/Makefile.am 2017-06-24 00:57:09.000000000 +0000 @@ -86,7 +86,8 @@ AM_CPPFLAGS = \ -I@top_srcdir@/lzma443/C \ - -I@top_srcdir@/lzma443/C/7zip/Compress/LZMA_Alone + -I@top_srcdir@/lzma443/C/7zip/Compress/LZMA_Alone \ + -I@top_srcdir@/include/afflib LZMA_SOURCES = \ @top_srcdir@/lzma443/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp \ diff -Nru afflib-3.7.7/lib/utils.h afflib-3.7.16/lib/utils.h --- afflib-3.7.7/lib/utils.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/utils.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,89 +0,0 @@ -/* - * utils.h: - * Some useful utilities for building AFF-aware programs. - * Distributed under the Berkeley 4-part license - */ - -#ifndef AFF_UTILS_H -#define AFF_UTILS_H - -#ifdef __cplusplus -#ifdef HAVE_STL -#include -#include -#include -#include -#include -#include -#include -#endif - -#ifdef HAVE_OPENSSL_PEM_H -#include -#include -#else -typedef void X509; -typedef void EVP_PKEY; -typedef void BIO; -#define BIO_free free -#endif - -namespace aff { - -#ifdef HAVE_STL - std::string command_line(int argc,char **argv); - bool ends_with(std::string str,std::string ending); -#endif - bool ends_with(const char *buf,const char *with); - - /* Structure for hash map */ - struct less_c_str - { - inline bool operator()( const char* x, const char* y) const - { return ( strcmp( x,y ) < 0 ); - } - }; - - struct md5blob { - unsigned char buf[16]; - }; - -#ifdef HAVE_STL - typedef std::map< const char*, struct md5blob, less_c_str > hashMapT; - - /* The seginfo stores information about a segment other than its data*/ - class seginfo { - public: - seginfo(std::string n1,size_t l1,unsigned int a1): name(n1),len(l1),arg(a1) {} - std::string name; - size_t len; - unsigned long arg; - /** pagenumber returns <0 for invalid pages, >= for a page */ - int64_t pagenumber() const {return af_segname_page_number(name.c_str());} - bool inline operator==(const class seginfo &b) const { - return name == b.name; - } - virtual ~seginfo(){}; - }; - - /* the seglist provides AFF internal functions and tools an easy way to get - * a list of all of the segments in the currently open AFF file. - * Use the seglist(af) constructor to populate it with all the segments - * when you create. Each element is populated with the name, length and arg. - */ - class seglist : public std::vector { - public: - bool contains(std::string segname); - bool has_signed_segments(); - int get_seglist(AFFILE *af); - seglist(){} - virtual ~seglist(){} - seglist(AFFILE *af){ - get_seglist(af); - } - }; -#endif -} -#endif - -#endif diff -Nru afflib-3.7.7/lib/vnode_aff.cpp afflib-3.7.16/lib/vnode_aff.cpp --- afflib-3.7.7/lib/vnode_aff.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/vnode_aff.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -111,7 +111,7 @@ int aff_write_seg(AFFILE *af, const char *segname,uint32_t arg,const u_char *data,size_t datalen) { - if(af_trace) fprintf(af_trace,"aff_write_seg(%p,%s,%"PRIu32",%p,len=%u)\n", + if(af_trace) fprintf(af_trace,"aff_write_seg(%p,%s,%" PRIu32 ",%p,len=%u)\n", af,segname,arg,data,(int)datalen); struct af_segment_head segh; @@ -141,7 +141,7 @@ aff_toc_update(af,segname,ftello(af->aseg),datalen); - if(af_trace) fprintf(af_trace,"aff_write_seg: putting segment %s (datalen=%d) offset=%"PRId64"\n", + if(af_trace) fprintf(af_trace,"aff_write_seg: putting segment %s (datalen=%d) offset=%" PRId64 "\n", segname,(int)datalen,ftello(af->aseg)); if(fwrite(&segh,sizeof(segh),1,af->aseg)!=1) return -10; @@ -307,7 +307,7 @@ return AF_ERROR_TAIL; } if(stl != calculated_segment_len){ - snprintf(af->error_str,sizeof(af->error_str),"af_get_next_segv: AF file corrupt (%"PRIu32"!=%"PRIu32")/!", + snprintf(af->error_str,sizeof(af->error_str),"af_get_next_segv: AF file corrupt (%" PRIu32 "!=%" PRIu32 ")/!", stl,calculated_segment_len); fseeko(af->aseg,start,SEEK_SET); // go back to last good position return AF_ERROR_TAIL; @@ -363,7 +363,7 @@ size_t size_needed = vallen+aff_segment_overhead(name); struct aff_toc_mem *adm = aff_toc(af,name); - if(af_trace) fprintf(af_trace,"aff_update_seg(name=%s,arg=%"PRIu32",vallen=%u)\n",name,arg,vallen); + if(af_trace) fprintf(af_trace,"aff_update_seg(name=%s,arg=%" PRIu32 ",vallen=%u)\n",name,arg,vallen); if(adm) { diff -Nru afflib-3.7.7/lib/vnode_afm.cpp afflib-3.7.16/lib/vnode_afm.cpp --- afflib-3.7.7/lib/vnode_afm.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/vnode_afm.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -187,7 +187,7 @@ return -1; } if (af->maxsize % af->image_pagesize) { - (*af->error_reporter)("afm_split_raw_setup: maxsize (%"I64d") " + (*af->error_reporter)("afm_split_raw_setup: maxsize (%" I64d ") " "not a multiple of image_pagesize (%d)\n", af->maxsize,af->image_pagesize); return -1; @@ -212,7 +212,7 @@ */ if (ap->aff->image_size && ap->aff->image_size != ap->sr->image_size) { (*af->error_reporter)("afm_split_raw_setup: internal error. " - "AFF image_size %"I64d" != SR image_size %"I64d"\n", + "AFF image_size %" I64d " != SR image_size %" I64d "\n", ap->aff->image_size,ap->sr->image_size); return -1; } @@ -225,7 +225,7 @@ /* Verify that the parameters make sense */ if (ap->sr->maxsize != (pages_per_file * af->image_pagesize) && pages_per_file>0) { (*af->error_reporter)("afm_split_raw_setup: %s: per size indicated by metadata (%d * %d) " - "doesn't match maxsize (%"I64d")\n", + "doesn't match maxsize (%" I64d ")\n", af_filename(af),pages_per_file,af->image_pagesize,ap->sr->maxsize); return -1; } diff -Nru afflib-3.7.7/lib/vnode_split_raw.cpp afflib-3.7.16/lib/vnode_split_raw.cpp --- afflib-3.7.7/lib/vnode_split_raw.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lib/vnode_split_raw.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -169,7 +169,7 @@ { struct split_raw_private *srp = SPLIT_RAW_PRIVATE(af); for(uint32_t i=0;inum_raw_files;i++){ - fprintf(stderr," fds[%d]=%d pos[%d]=%"I64d"\n",i,srp->fds[i],i,srp->pos[i]); + fprintf(stderr," fds[%d]=%d pos[%d]=%" I64d "\n",i,srp->fds[i],i,srp->pos[i]); } srp_validate(af); fprintf(stderr,"===================\n"); @@ -287,7 +287,7 @@ af->image_pagesize *= 2; if ((ret == 0) && (af->maxsize % af->image_pagesize!=0)) { - (*af->error_reporter)("split_raw_open: %s: raw_file_size (%"I64d" not a multiple of pagesize %lu\n", + (*af->error_reporter)("split_raw_open: %s: raw_file_size (%" I64d " not a multiple of pagesize %lu\n", af->fname, af->maxsize,af->image_pagesize); split_raw_close (af); return -1; diff -Nru afflib-3.7.7/lzma443/C/Common/String.h afflib-3.7.16/lzma443/C/Common/String.h --- afflib-3.7.7/lzma443/C/Common/String.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lzma443/C/Common/String.h 2017-06-24 00:57:09.000000000 +0000 @@ -417,7 +417,7 @@ for(int i = 0; i < _length; i++) if (s.Find(_chars[i]) >= 0) return i; - return -1; + return -1; } void TrimLeft(T c) diff -Nru afflib-3.7.7/lzma443/C/Common/Vector.h afflib-3.7.16/lzma443/C/Common/Vector.h --- afflib-3.7.7/lzma443/C/Common/Vector.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/lzma443/C/Common/Vector.h 2017-06-24 00:57:09.000000000 +0000 @@ -178,7 +178,7 @@ for(int i = 0; i < Size(); i++) if (item == (*this)[i]) return i; - return -1; + return -1; } int FindInSorted(const T& item) const { diff -Nru afflib-3.7.7/m4/acinclude.m4 afflib-3.7.16/m4/acinclude.m4 --- afflib-3.7.7/m4/acinclude.m4 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/m4/acinclude.m4 1970-01-01 00:00:00.000000000 +0000 @@ -1,879 +0,0 @@ -# =========================================================================== -# http://autoconf-archive.cryp.to/ac_python_devel.html -# =========================================================================== -# -# SYNOPSIS -# -# AC_PYTHON_DEVEL([version]) -# -# DESCRIPTION -# -# Note: Defines as a precious variable "PYTHON_VERSION". Don't override it -# in your configure.ac. -# -# This macro checks for Python and tries to get the include path to -# 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS) -# output variables. It also exports $(PYTHON_EXTRA_LIBS) and -# $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code. -# -# You can search for some particular version of Python by passing a -# parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please -# note that you *have* to pass also an operator along with the version to -# match, and pay special attention to the single quotes surrounding the -# version number. Don't use "PYTHON_VERSION" for this: that environment -# variable is declared as precious and thus reserved for the end-user. -# -# This macro should work for all versions of Python >= 2.1.0. As an end -# user, you can disable the check for the python version by setting the -# PYTHON_NOVERSIONCHECK environment variable to something else than the -# empty string. -# -# If you need to use this macro for an older Python version, please -# contact the authors. We're always open for feedback. -# -# LICENSE -# -# Copyright (c) 2009 Sebastian Huber -# Copyright (c) 2009 Alan W. Irwin -# Copyright (c) 2009 Rafael Laboissiere -# Copyright (c) 2009 Andrew Collier -# Copyright (c) 2009 Matteo Settenvini -# Copyright (c) 2009 Horst Knorr -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -AC_DEFUN([AC_PYTHON_DEVEL],[ - # - # Allow the use of a (user set) custom python version - # - AC_ARG_VAR([PYTHON_VERSION],[The installed Python - version to use, for example '2.3'. This string - will be appended to the Python interpreter - canonical name.]) - - AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) - if test -z "$PYTHON"; then - AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path]) - PYTHON_VERSION="" - fi - - # - # Check for a version of Python >= 2.1.0 - # - AC_MSG_CHECKING([for a version of Python >= '2.1.0']) - ac_supports_python_ver=`$PYTHON -c "import sys; \ - ver = sys.version.split ()[[0]]; \ - print (ver >= '2.1.0')"` - if test "$ac_supports_python_ver" != "True"; then - if test -z "$PYTHON_NOVERSIONCHECK"; then - AC_MSG_RESULT([no]) - AC_MSG_FAILURE([ -This version of the AC@&t@_PYTHON_DEVEL macro -doesn't work properly with versions of Python before -2.1.0. You may need to re-run configure, setting the -variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG, -PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand. -Moreover, to disable this check, set PYTHON_NOVERSIONCHECK -to something else than an empty string. -]) - else - AC_MSG_RESULT([skip at user request]) - fi - else - AC_MSG_RESULT([yes]) - fi - - # - # if the macro parameter ``version'' is set, honour it - # - if test -n "$1"; then - AC_MSG_CHECKING([for a version of Python $1]) - ac_supports_python_ver=`$PYTHON -c "import sys; \ - ver = sys.version.split ()[[0]]; \ - print (ver $1)"` - if test "$ac_supports_python_ver" = "True"; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([this package requires Python $1. -If you have it installed, but it isn't the default Python -interpreter in your system path, please pass the PYTHON_VERSION -variable to configure. See ``configure --help'' for reference. -]) - PYTHON_VERSION="" - fi - fi - - # - # Check if you have distutils, else fail - # - AC_MSG_CHECKING([for the distutils Python package]) - ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` - if test -z "$ac_distutils_result"; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([cannot import Python module "distutils". -Please check your Python installation. The error was: -$ac_distutils_result]) - PYTHON_VERSION="" - fi - - # - # Check for Python include path - # - AC_MSG_CHECKING([for Python include path]) - if test -z "$PYTHON_CPPFLAGS"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print (distutils.sysconfig.get_python_inc ());"` - if test -n "${python_path}"; then - python_path="-I$python_path" - fi - PYTHON_CPPFLAGS=$python_path - fi - AC_MSG_RESULT([$PYTHON_CPPFLAGS]) - AC_SUBST([PYTHON_CPPFLAGS]) - - # - # Check for Python library path - # - AC_MSG_CHECKING([for Python library path]) - if test -z "$PYTHON_LDFLAGS"; then - # (makes two attempts to ensure we've got a version number - # from the interpreter) - ac_python_version=`cat<]], - [[Py_Initialize();]]) - ],[pythonexists=yes],[pythonexists=no]) - AC_LANG_POP([C]) - # turn back to default flags - CPPFLAGS="$ac_save_CPPFLAGS" - LIBS="$ac_save_LIBS" - - AC_MSG_RESULT([$pythonexists]) - - if test ! "x$pythonexists" = "xyes"; then - AC_MSG_FAILURE([ - Could not link test program to Python. Maybe the main Python library has been - installed in some non-standard library path. If so, pass it to configure, - via the LDFLAGS environment variable. - Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib" - ============================================================================ - ERROR! - You probably have to install the development version of the Python package - for your distribution. The exact name of this package varies among them. - ============================================================================ - ]) - PYTHON_VERSION="" - fi - - # - # all done! - # -]) -# =========================================================================== -# http://autoconf-archive.cryp.to/ac_python_module.html -# =========================================================================== -# -# SYNOPSIS -# -# AC_PYTHON_MODULE(modname[, fatal]) -# -# DESCRIPTION -# -# Checks for Python module. -# -# If fatal is non-empty then absence of a module will trigger an error. -# -# LICENSE -# -# Copyright (c) 2008 Andrew Collier -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. - -AC_DEFUN([AC_PYTHON_MODULE],[ - if test -z $PYTHON; - then - PYTHON="python" - fi - PYTHON_NAME=`basename $PYTHON` - AC_MSG_CHECKING($PYTHON_NAME module: $1) - $PYTHON -c "import $1" 2>/dev/null - if test $? -eq 0; - then - AC_MSG_RESULT(yes) - eval AS_TR_CPP(HAVE_PYMOD_$1)=yes - else - AC_MSG_RESULT(no) - eval AS_TR_CPP(HAVE_PYMOD_$1)=no - # - if test -n "$2" - then - AC_MSG_ERROR(failed to find required module $1) - exit 1 - fi - fi -]) -# =========================================================================== -# http://autoconf-archive.cryp.to/az_python.html -# =========================================================================== -# -# SYNOPSIS -# -# AZ_PYTHON_DEFAULT -# AZ_PYTHON_ENABLE -# AZ_PYTHON_WITH -# AZ_PYTHON_PATH -# AZ_PYTHON_VERSION_ENSURE( [2.2] ) -# AZ_PYTHON_CSPEC -# AZ_PYTHON_LSPEC -# -# DESCRIPTION -# -# This file provides autoconf support for those applications that want to -# embed python. It supports all pythons >= 2.2 which is the first official -# release containing distutils. Version 2.2 of python was released -# December 21, 2001. Since it actually executes the python, cross platform -# configuration will probably not work. Also, most of the platforms -# supported are consistent until you look into MacOSX. The python included -# with it is installed as a framework which is a very different -# environment to set up the normal tools such as gcc and libtool to deal -# with. Therefore, once we establish which python that we are going to -# use, we use its distutils to actually compile and link our modules or -# applications. -# -# At this time, it does NOT support linking with Python statically. It -# does support dynamic linking. -# -# This set of macros help define $PYTHON, $PYTHON_USE, $PYTHON_CSPEC and -# $PYTHON_LSPEC. $PYTHON defines the full executable path for the Python -# being linked to and is used within these macros to determine if that has -# been specified or found. These macros do execute this python version so -# it must be present on the system at configure time. -# -# $PYTHON_USE is an automake variable that defines whether Python support -# should be included or not in your application. $PYTHON_CSPEC is a -# variable that supplies additional CFLAGS for the compilation of the -# application/shared library. $PYTHON_LSPEC is a variable that supplies -# additional LDFLAGS for linking the application/shared library. -# -# The following is an example of how to set up for python usage within -# your application in your configure.in: -# -# AZ_PYTHON_DEFAULT( ) -# AZ_PYTHON_ENABLE( ) # Optional -# AZ_PYTHON_WITH( ) # Optional -# AZ_PYTHON_PATH( ) # or AZ_PYTHON_INSIST( ) -# # if $PYTHON is not defined, then the following do nothing. -# AZ_PYTHON_VERSION_ENSURE( [2.2] ) -# AZ_PYTHON_CSPEC -# AZ_PYTHON_LSPEC -# -# The AZ_PYTHON_DEFAULT sets the $PYTHON_USE to false. Thereby, excluding -# it if it was optional. -# -# The AZ_PYTHON_ENABLE looks for the optional configure parameters of -# --enable-python/--disable-python and establishes the $PYTHON and -# $PYTHON_USE variables accordingly. -# -# The AZ_PYTHON_WITH looks for the optional configure parameters of -# --with-python/--without-python and establishes the $PYTHON and -# $PYTHON_USE variables accordingly. -# -# The AZ_PYTHON_PATH looks for python assuming that none has been -# previously found or defined and issues an error if it does not find it. -# If it does find it, it establishes the $PYTHON and $PYTHON_USE variables -# accordingly. AZ_PYTHON_INSIST could be used here instead if you want to -# insist that Python support be included using the --enable-python or -# --with-python checks previously done. -# -# The AZ_PYTHON_VERSION_ENSURE issues an error if the Python previously -# found is not of version 2.2 or greater. -# -# Once that these macros have be run, we can use PYTHON_USE within the -# makefile.am file to conditionally add the Python support such as: -# -# Makefile.am example showing optional inclusion of directories: -# -# if PYTHON_USE -# plugins = plugins -# src = src -# else -# plugins = -# src = -# endif -# -# SUBDIRS = . $(plugins) $(src) -# -# Makefile.am example showing optional shared library build: -# -# if PYTHON_USE -# lib_LTLIBRARIES = libElemList.la -# libElemList_la_SOURCES = libElemList.c -# libElemList_la_CFLAGS = @PYTHON_CSPEC@ -# libElemList_la_LDFLAGS = @PYTHON_LSPEC@ -# endif -# -# Makefile.am example showing optional program build: -# -# if PYTHON_USE -# bin_PROGRAMS = runFunc -# runFunc_SOURCES = runFunc.c -# runFunc_CFLAGS = @PYTHON_CSPEC@ -# runFunc_LDFLAGS = @PYTHON_LSPEC@ -# endif -# -# The above compiles the modules only if PYTHON_USE was specified as true. -# Also, the else portion of the if was optional. -# -# LICENSE -# -# Copyright (c) 2008 Robert White -# Copyright (c) 2008 Dustin J. Mitchell -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. - -# AZ_PYTHON_DEFAULT( ) -# ----------------- -# Sets the default to not include Python support. - -AC_DEFUN([AZ_PYTHON_DEFAULT], -[ - az_python_use=false - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") -]) - - - -# AZ_PYTHON_ENABLE( [path] ) -# ----------------------------------------------------------------- -# Handles the various --enable-python commands. -# Input: -# $1 is the optional search path for the python executable if needed -# Ouput: -# PYTHON_USE (AM_CONDITIONAL) is true if python executable found -# and --enable-python was requested; otherwise false. -# $PYTHON contains the full executable path to python if PYTHON_ENABLE_USE -# is true. -# -# Example: -# AZ_PYTHON_ENABLE( ) -# or -# AZ_PYTHON_ENABLE( "/usr/bin" ) - -AC_DEFUN([AZ_PYTHON_ENABLE], -[ - AC_ARG_VAR([PYTHON],[Python Executable Path]) - - # unless PYTHON was supplied to us (as a precious variable), - # see if --enable-python[=PythonExecutablePath], --enable-python, - # --disable-python or --enable-python=no was given. - if test -z "$PYTHON" - then - AC_MSG_CHECKING(for --enable-python) - AC_ARG_ENABLE( - python, - AC_HELP_STRING([--enable-python@<:@=PYTHON@:>@], - [absolute path name of Python executable] - ), - [ - if test "$enableval" = "yes" - then - # "yes" was specified, but we don't have a path - # for the executable. - # So, let's searth the PATH Environment Variable. - AC_MSG_RESULT(yes) - AC_PATH_PROG( - [PYTHON], - python, - [], - $1 - ) - if test -z "$PYTHON" - then - AC_MSG_ERROR(no path to python found) - fi - az_python_use=true - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - AZ_PYTHON_PREFIX( ) - elif test "$enableval" = "no" - then - AC_MSG_RESULT(no) - az_python_use=false - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - else - # $enableval must be the executable path then. - AC_SUBST([PYTHON], ["${enableval}"]) - AC_MSG_RESULT($withval) - az_python_use=true - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - AZ_PYTHON_PREFIX( ) - fi - ], - [ - # --with-python was not specified. - AC_MSG_RESULT(no) - az_python_use=false - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - ] - ) - fi - -]) - - - -# AZ_PYTHON_CSPEC( ) -# ----------------- -# Set up the c compiler options to compile Python -# embedded programs/libraries in $PYTHON_CSPEC if -# $PYTHON has been defined. - -AC_DEFUN([AZ_PYTHON_CSPEC], -[ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - if test -n "$PYTHON" - then - az_python_prefix=`${PYTHON} -c "import sys; print sys.prefix"` - if test -z "$az_python_prefix" - then - AC_MSG_ERROR([Python Prefix is not known]) - fi - az_python_execprefix=`${PYTHON} -c "import sys; print sys.exec_prefix"` - az_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"` - az_python_includespec="-I${az_python_prefix}/include/python${az_python_version}" - if test x"$python_prefix" != x"$python_execprefix"; then - az_python_execspec="-I${az_python_execprefix}/include/python${az_python_version}" - az_python_includespec="${az_python_includespec} $az_python_execspec" - fi - az_python_ccshared=`${PYTHON} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('CFLAGSFORSHARED')"` - az_python_cspec="${az_python_ccshared} ${az_python_includespec}" - AC_SUBST([PYTHON_CSPEC], [${az_python_cspec}]) - AC_MSG_NOTICE([PYTHON_CSPEC=${az_python_cspec}]) - fi -]) - - - -# AZ_PYTHON_INSIST( ) -# ----------------- -# Look for Python and set the output variable 'PYTHON' -# to 'python' if found, empty otherwise. - -AC_DEFUN([AZ_PYTHON_PATH], -[ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - if test -z "$PYTHON" - then - AC_MSG_ERROR([Python Executable not found]) - fi -]) - - - -# AZ_PYTHON_LSPEC( ) -# ----------------- -# Set up the linker options to link Python embedded -# programs/libraries in $PYTHON_LSPEC if $PYTHON -# has been defined. - -AC_DEFUN([AZ_PYTHON_LSPEC], -[ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - if test -n "$PYTHON" - then - AZ_PYTHON_RUN([ -import sys -import distutils.sysconfig -strUseFrameWork = "--enable-framework" -dictConfig = distutils.sysconfig.get_config_vars( ) -strConfigArgs = dictConfig.get("CONFIG_ARGS") -strLinkSpec = dictConfig.get('LDFLAGS') -if -1 == strConfigArgs.find(strUseFrameWork): - strLibPL = dictConfig.get("LIBPL") - if strLibPL and (strLibPL != ""): - strLinkSpec += " -L%s" % (strLibPL) - strSys = dictConfig.get("SYSLIBS") - if strSys and (strSys != ""): - strLinkSpec += " %s" % (strSys) - strSHL = dictConfig.get("SHLIBS") - if strSHL and (strSHL != ""): - strLinkSpec += " %s" % (strSHL) - # Construct the Python Library Name. - strTmplte = " -lpython%d.%d" - if (sys.platform == "win32") or (sys.platform == "os2emx"): - strTmplte = " -lpython%d%d" - strWrk = strTmplte % ( (sys.hexversion >> 24), - ((sys.hexversion >> 16) & 0xff)) - strLinkSpec += strWrk -else: - # This is not ideal since it changes the search path - # for Frameworks which could have side-effects on - # other included Frameworks. However, it is necessary - # where someone has installed more than one frameworked - # Python. Frameworks are really only used in MacOSX. - strLibFW = dictConfig.get("PYTHONFRAMEWORKPREFIX") - if strLibFW and (strLibFW != ""): - strLinkSpec += " -F%s" % (strLibFW) -strLinkSpec += " %s" % (dictConfig.get('LINKFORSHARED')) -print strLinkSpec - ]) - AC_SUBST([PYTHON_LSPEC], [${az_python_output}]) - AC_MSG_NOTICE([PYTHON_LSPEC=${az_python_output}]) - fi -]) - - - -# AZ_PYTHON_PATH( ) -# ----------------- -# Look for Python and set the output variable 'PYTHON' -# to 'python' if found, empty otherwise. - -AC_DEFUN([AZ_PYTHON_PATH], -[ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - AC_PATH_PROG( PYTHON, python, [], $1 ) - if test -z "$PYTHON" - then - AC_MSG_ERROR([Python Executable not found]) - else - az_python_use=true - fi - AM_CONDITIONAL(PYTHON_USE, test "$az_python_use" = "true") -]) - - - -# AZ_PYTHON_PREFIX( ) -# ------------------- -# Use the values of $prefix and $exec_prefix for the corresponding -# values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. - -AC_DEFUN([AZ_PYTHON_PREFIX], -[ - if test -z "$PYTHON" - then - AC_MSG_ERROR([Python Executable Path is not known]) - fi - ax_python_prefix=`${PYTHON} -c "import sys; print sys.prefix"` - ax_python_execprefix=`${PYTHON} -c "import sys; print sys.exec_prefix"` - AC_SUBST([PYTHON_PREFIX], ["${ax_python_prefix}"]) - AC_SUBST([PYTHON_EXECPREFIX], ["${ax_python_execprefix}"]) -]) - - - -# AZ_PYTHON_RUN( PYTHON_PROGRAM ) -# ----------------- -# Run a Python Test Program saving its output -# in az_python_output and its condition code -# in az_python_cc. - -AC_DEFUN([AZ_PYTHON_RUN], -[ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - if test -z "$PYTHON" - then - AC_MSG_ERROR([Python Executable not found]) - else - cat >conftest.py <<_ACEOF -$1 -_ACEOF - az_python_output=`$PYTHON conftest.py` - az_python_cc=$? - rm conftest.py - if test -f "conftest.pyc" - then - rm conftest.pyc - fi - fi -]) - - - -# AZ_PYTHON_VERSION_CHECK( VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE] ) -# ----------------------------------------------------------------------------- -# Run ACTION-IF-TRUE if the Python interpreter has version >= VERSION. -# Run ACTION-IF-FALSE otherwise. -# This test uses sys.hexversion instead of the string equivalant (first -# word of sys.version), in order to cope with versions such as 2.2c1. -# hexversion has been introduced in Python 1.5.2; it's probably not -# worth to support older versions (1.5.1 was released on October 31, 1998). - -AC_DEFUN([AZ_PYTHON_VERSION_CHECK], - [ - AC_ARG_VAR( [PYTHON], [Python Executable Path] ) - if test -n "$PYTHON" - then - AC_MSG_CHECKING([whether $PYTHON version >= $1]) - AZ_PYTHON_RUN([ -import sys, string -# split strings by '.' and convert to numeric. Append some zeros -# because we need at least 4 digits for the hex conversion. -minver = map(int, string.split('$1', '.')) + [[0, 0, 0]] -minverhex = 0 -for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]] -if sys.hexversion >= minverhex: - sys.exit( 0 ) -else: - sys.exit( 1 ) - ]) - if test $az_python_cc -eq 0 - then - $2 - m4_ifvaln( - [$3], - [else $3] - ) - fi - fi -]) - - - -# AZ_PYTHON_VERSION_ENSURE( VERSION ) -# ----------------- -# Insure that the Python Interpreter Version -# is greater than or equal to the VERSION -# parameter. - -AC_DEFUN([AZ_PYTHON_VERSION_ENSURE], -[ - AZ_PYTHON_VERSION_CHECK( - [$1], - [AC_MSG_RESULT(yes)], - [AC_MSG_ERROR(too old)] - ) -]) - - - -# AZ_PYTHON_WITH( [path] ) -# ----------------------------------------------------------------- -# Handles the various --with-python commands. -# Input: -# $1 is the optional search path for the python executable if needed -# Ouput: -# PYTHON_USE (AM_CONDITIONAL) is true if python executable found -# and --with-python was requested; otherwise false. -# $PYTHON contains the full executable path to python if PYTHON_USE -# is true. -# -# Example: -# AZ_PYTHON_WITH( ) -# or -# AZ_PYTHON_WITH("/usr/bin") - -AC_DEFUN([AZ_PYTHON_WITH], -[ - AC_ARG_VAR([PYTHON],[Python Executable Path]) - - # unless PYTHON was supplied to us (as a precious variable), - # see if --with-python[=PythonExecutablePath], --with-python, - # --without-python or --with-python=no was given. - if test -z "$PYTHON" - then - AC_MSG_CHECKING(for --with-python) - AC_ARG_WITH( - python, - AC_HELP_STRING([--with-python@<:@=PYTHON@:>@], - [absolute path name of Python executable] - ), - [ - if test "$withval" = "yes" - then - # "yes" was specified, but we don't have a path - # for the executable. - # So, let's searth the PATH Environment Variable. - AC_MSG_RESULT(yes) - AC_PATH_PROG( - [PYTHON], - python, - [], - $1 - ) - if test -z "$PYTHON" - then - AC_MSG_ERROR(no path to python found) - fi - az_python_use=true - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - AZ_PYTHON_PREFIX( ) - elif test "$withval" = "no" - then - AC_MSG_RESULT(no) - az_python_use=false - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - else - # $withval must be the executable path then. - AC_SUBST([PYTHON], ["${withval}"]) - AC_MSG_RESULT($withval) - az_python_use=true - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - AZ_PYTHON_PREFIX( ) - fi - ], - [ - # --with-python was not specified. - AC_MSG_RESULT(no) - az_python_use=false - AM_CONDITIONAL(PYTHON_USE, test x"$az_python_use" = x"true") - ] - ) - fi - -]) diff -Nru afflib-3.7.7/Makefile.am afflib-3.7.16/Makefile.am --- afflib-3.7.7/Makefile.am 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/Makefile.am 2017-06-24 00:57:09.000000000 +0000 @@ -12,7 +12,7 @@ pkgconfig_DATA = afflib.pc include_HEADERS = -pkginclude_HEADERS = lib/afflib.h lib/afflib_i.h lib/aftimer.h lib/utils.h +pkginclude_HEADERS = include/afflib/afflib.h include/afflib/afflib_i.h include/afflib/aftimer.h include/afflib/utils.h ACLOCAL_AMFLAGS = -I m4 diff -Nru afflib-3.7.7/man/affcat.1 afflib-3.7.16/man/affcat.1 --- afflib-3.7.7/man/affcat.1 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/man/affcat.1 2017-06-24 00:57:09.000000000 +0000 @@ -28,7 +28,7 @@ .IP "-n" Noisy mode. Tell when pages are skipped. .IP "-l" -List all the segment names, rather than outputing data. +List all the segment names, rather than outputting data. .IP "-L" List Long. Prints segment names, lengths, and args. .IP "-d" diff -Nru afflib-3.7.7/man/affconvert.1 afflib-3.7.16/man/affconvert.1 --- afflib-3.7.7/man/affconvert.1 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/man/affconvert.1 2017-06-24 00:57:09.000000000 +0000 @@ -78,7 +78,7 @@ .TP .B \fB-r\fP -Force raw output. +Generate raw output. .RE .PP Dangerous input \fIoptions\fP: @@ -104,6 +104,14 @@ .fam T .fi +Convert file1.aff to file1.raw: +.PP +.nf +.fam C + $ affconvert -r file1.aff + +.fam T +.fi Batch convert \fIfiles\fP: .PP .nf @@ -112,6 +120,13 @@ .fam T .fi +.PP +.nf +.fam C + $ affconvert -r file1.aff file2.aff file3.aff + +.fam T +.fi Split an AFF file into 4GB chunks for archiving to DVD: .PP .nf diff -Nru afflib-3.7.7/pyaff/afflib.pxd afflib-3.7.16/pyaff/afflib.pxd --- afflib-3.7.7/pyaff/afflib.pxd 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/pyaff/afflib.pxd 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,24 @@ +from libc.stdint cimport int64_t, uint32_t, uint64_t +from posix.fcntl cimport O_RDONLY + +cdef extern from "afflib/afflib.h": + struct AFFILE + + enum: AF_MAX_NAME_LEN + + AFFILE *af_open(const char *filename, int flags, int mode) + int af_close(AFFILE *af) + + int64_t af_get_imagesize(AFFILE *af) + + ssize_t af_read(AFFILE *af, unsigned char *buf, ssize_t count) + uint64_t af_seek(AFFILE *af, int64_t pos, int whence) + uint64_t af_tell(AFFILE *af) + + + int af_get_seg(AFFILE *af, const char *name, uint32_t *arg, + unsigned char *data, size_t *datalen) + int af_get_next_seg(AFFILE *af, char *segname, size_t segname_len, + uint32_t *arg, unsigned char *data, size_t *datalen) + int af_rewind_seg(AFFILE *af) + diff -Nru afflib-3.7.7/pyaff/Makefile.am afflib-3.7.16/pyaff/Makefile.am --- afflib-3.7.7/pyaff/Makefile.am 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/pyaff/Makefile.am 2017-06-24 00:57:09.000000000 +0000 @@ -1,15 +1,16 @@ DISTCLEANFILES = Makefile.in -EXTRA_DIST = PKG-INFO README pyaff.c setup.py +EXTRA_DIST = README afflib.pxd pyaff.pxd pyaff.pyx pyaff.c setup.py if HAVE_PYTHON -AM_CFLAGS = -I$(top_srcdir)/lib -include affconfig.h +all-local: $(top_builddir)/lib/.libs/libafflib.la + cd $(srcdir) && $(PYTHON) setup.py \ + build --build-base $(abs_builddir)/build \ + build_ext --include-dirs $(abs_top_srcdir)/include --library-dirs $(abs_top_builddir)/lib/.libs -# This is for the pyaff python module -pyexec_LTLIBRARIES = pyaff.la - -pyaff_la_SOURCES = pyaff.c -pyaff_la_LIBADD = ../lib/libafflib.la -pyaff_la_CPPFLAGS = $(PYTHON_CPPFLAGS) -pyaff_la_CFLAGS = -fno-strict-aliasing -pyaff_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) +install-exec-local: + cd $(srcdir) && $(PYTHON) setup.py \ + build --build-base $(abs_builddir)/build \ + egg_info --egg-base $(abs_builddir) \ + install --prefix $(DESTDIR)$(prefix) --single-version-externally-managed --record=$(abs_builddir)/installed.txt \ + bdist_egg --dist-dir $(abs_builddir)/dist endif diff -Nru afflib-3.7.7/pyaff/PKG-INFO afflib-3.7.16/pyaff/PKG-INFO --- afflib-3.7.7/pyaff/PKG-INFO 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/pyaff/PKG-INFO 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -Metadata-Version: 1.0 -Name: PyAFF -Version: 0.1 -Summary: Python wrapper for AFFLIB -Home-page: www.pyflag.net -Author: David Collett -Author-email: david.collett@gmail.com -License: GPL -Description: UNKNOWN -Platform: UNKNOWN diff -Nru afflib-3.7.7/pyaff/pyaff.c afflib-3.7.16/pyaff/pyaff.c --- afflib-3.7.7/pyaff/pyaff.c 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/pyaff/pyaff.c 2017-06-24 00:57:09.000000000 +0000 @@ -1,279 +1,4363 @@ -/****************************************************** - * Copyright 2008: David Collett - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * (LGPL) as published by the Free Software Foundation; either version - * 3 of the License as of 29 June 2007, or (at your option) any later - * version. - * - * See http://www.gnu.org/licenses/lgpl.txt - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02 - * -1307, USA. - ****************************************************/ +/* Generated by Cython 0.25.1 */ +/* BEGIN: Cython Metadata +{ + "distutils": { + "depends": [], + "libraries": [ + "afflib" + ] + }, + "module_name": "pyaff" +} +END: Cython Metadata */ + +#define PY_SSIZE_T_CLEAN #include "Python.h" -#include "lib/afflib.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) + #error Cython requires Python 2.6+ or Python 3.2+. +#else +#define CYTHON_ABI "0_25_1" +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000) + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) -#include -#include -#include -#include +#ifndef CYTHON_INLINE + #if defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__pyaff +#define __PYX_HAVE_API__pyaff +#include #include +#include "afflib/afflib.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ -/****************************************************************** - * pyaff - afflib python binding - * ***************************************************************/ +#ifdef PYREX_WITHOUT_ASSERTIONS +#define CYTHON_WITHOUT_ASSERTIONS +#endif -typedef struct { - PyObject_HEAD - AFFILE *af; - uint64_t size; -} affile; - -static void affile_dealloc(affile *self); -static int affile_init(affile *self, PyObject *args, PyObject *kwds); -static PyObject *affile_read(affile *self, PyObject *args, PyObject *kwds); -static PyObject *affile_seek(affile *self, PyObject *args, PyObject *kwds); -static PyObject *affile_get_seg(affile *self, PyObject *args, PyObject *kwds); -static PyObject *affile_get_seg_names(affile *self); -static PyObject *affile_tell(affile *self); -static PyObject *affile_close(affile *self); - -static PyMethodDef affile_methods[] = { - {"read", (PyCFunction)affile_read, METH_VARARGS|METH_KEYWORDS, - "Read data from file" }, - {"seek", (PyCFunction)affile_seek, METH_VARARGS|METH_KEYWORDS, - "Seek within a file" }, - {"get_seg", (PyCFunction)affile_get_seg, METH_VARARGS|METH_KEYWORDS, - "Retrieve an aff segment by name" }, - {"get_seg_names", (PyCFunction)affile_get_seg_names, METH_NOARGS, - "Retrieve a list of segments present" }, - {"tell", (PyCFunction)affile_tell, METH_NOARGS, - "Return possition within file" }, - {"close", (PyCFunction)affile_close, METH_NOARGS, - "Close the file" }, - {NULL} /* Sentinel */ +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) && defined (_M_X64) + #define __Pyx_sst_abs(value) _abs64(value) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#if PY_MAJOR_VERSION < 3 +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) +{ + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#else +#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen +#endif +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "pyaff.pyx", }; -static PyTypeObject affileType = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "pyaff.affile", /* tp_name */ - sizeof(affile), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)affile_dealloc,/* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - "afflib File Object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - affile_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)affile_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ +/*--- Type declarations ---*/ +struct __pyx_obj_5pyaff_affile; + +/* "pyaff.pxd":4 + * from libc.stdint cimport int64_t + * + * cdef class affile: # <<<<<<<<<<<<<< + * cdef afflib.AFFILE *af + * cdef int64_t size + */ +struct __pyx_obj_5pyaff_affile { + PyObject_HEAD + struct AFFILE *af; + int64_t size; }; -static void -affile_dealloc(affile *self) { - self->ob_type->tp_free((PyObject*)self); + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); } +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif -static int -affile_init(affile *self, PyObject *args, PyObject *kwds) { - char *filename; - static char *kwlist[] = {"filename", NULL}; +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); - self->size = 0; +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif - if(!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &filename)) - return -1; +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); - self->af = af_open(filename, O_RDONLY, 0); - if(self->af == NULL) { - PyErr_Format(PyExc_IOError, "Failed to initialise afflib"); - return -1; +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* ArgTypeTest.proto */ +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); + +/* GetModuleGlobalName.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); + +/* PyCFunctionFastCall.proto */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); +#else +#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectCallNoArg.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); +#else +#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = PyThreadState_GET(); +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* ListAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif - self->size = af_get_imagesize(self->af); - return 0; +/* IncludeStringH.proto */ +#include + +/* decode_c_string.proto */ +static CYTHON_INLINE PyObject* __Pyx_decode_c_string( + const char* cstring, Py_ssize_t start, Py_ssize_t stop, + const char* encoding, const char* errors, + PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value); + +/* Print.proto */ +static int __Pyx_Print(PyObject*, PyObject *, int); +#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3 +static PyObject* __pyx_print = 0; +static PyObject* __pyx_print_kwargs = 0; +#endif + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* PrintOne.proto */ +static int __Pyx_PrintOne(PyObject* stream, PyObject *o); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + + +/* Module declarations from 'libc.stdint' */ + +/* Module declarations from 'posix.fcntl' */ + +/* Module declarations from 'afflib' */ + +/* Module declarations from 'cpython.version' */ + +/* Module declarations from 'pyaff' */ +static PyTypeObject *__pyx_ptype_5pyaff_affile = 0; +#define __Pyx_MODULE_NAME "pyaff" +int __pyx_module_is_main_pyaff = 0; + +/* Implementation of 'pyaff' */ +static PyObject *__pyx_builtin_IOError; +static const char __pyx_k_end[] = "end"; +static const char __pyx_k_sys[] = "sys"; +static const char __pyx_k_file[] = "file"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_open[] = "open"; +static const char __pyx_k_size[] = "size"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_ascii[] = "ascii"; +static const char __pyx_k_print[] = "print"; +static const char __pyx_k_pyaff[] = "pyaff"; +static const char __pyx_k_encode[] = "encode"; +static const char __pyx_k_format[] = "format"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_offset[] = "offset"; +static const char __pyx_k_whence[] = "whence"; +static const char __pyx_k_IOError[] = "IOError"; +static const char __pyx_k_filename[] = "filename"; +static const char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding"; +static const char __pyx_k_libaff_seek_offset_failed[] = "libaff_seek_offset failed"; +static const char __pyx_k_Failed_to_initialise_afflib[] = "Failed to initialise afflib"; +static const char __pyx_k_error_reading_libaff_segment[] = "error reading libaff segment"; +static const char __pyx_k_Users_umireon_AFFLIBv3_pyaff_py[] = "/Users/umireon/AFFLIBv3/pyaff/pyaff.pyx"; +static const char __pyx_k_Failed_to_read_all_data_wanted_g[] = "Failed to read all data: wanted {}, got {}"; +static PyObject *__pyx_kp_s_Failed_to_initialise_afflib; +static PyObject *__pyx_kp_s_Failed_to_read_all_data_wanted_g; +static PyObject *__pyx_n_s_IOError; +static PyObject *__pyx_kp_s_Users_umireon_AFFLIBv3_pyaff_py; +static PyObject *__pyx_n_s_ascii; +static PyObject *__pyx_n_s_encode; +static PyObject *__pyx_n_s_end; +static PyObject *__pyx_kp_s_error_reading_libaff_segment; +static PyObject *__pyx_n_s_file; +static PyObject *__pyx_n_s_filename; +static PyObject *__pyx_n_s_format; +static PyObject *__pyx_n_s_getfilesystemencoding; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_kp_s_libaff_seek_offset_failed; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_offset; +static PyObject *__pyx_n_s_open; +static PyObject *__pyx_n_s_print; +static PyObject *__pyx_n_s_pyaff; +static PyObject *__pyx_n_s_size; +static PyObject *__pyx_n_s_sys; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_whence; +static PyObject *__pyx_pf_5pyaff_open(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename); /* proto */ +static int __pyx_pf_5pyaff_6affile___cinit__(struct __pyx_obj_5pyaff_affile *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_2read(struct __pyx_obj_5pyaff_affile *__pyx_v_self, int __pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_4seek(struct __pyx_obj_5pyaff_affile *__pyx_v_self, int __pyx_v_offset, int __pyx_v_whence); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_6get_seg(struct __pyx_obj_5pyaff_affile *__pyx_v_self, PyObject *__pyx_v_segname); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_8get_seg_names(struct __pyx_obj_5pyaff_affile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_10tell(struct __pyx_obj_5pyaff_affile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pyaff_6affile_12close(struct __pyx_obj_5pyaff_affile *__pyx_v_self); /* proto */ +static PyObject *__pyx_tp_new_5pyaff_affile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tuple_; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_codeobj__7; + +/* "pyaff.pyx":6 + * + * """Open afflib file (or set of files)""" + * def open(filename): # <<<<<<<<<<<<<< + * return affile(filename) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_1open(PyObject *__pyx_self, PyObject *__pyx_v_filename); /*proto*/ +static PyMethodDef __pyx_mdef_5pyaff_1open = {"open", (PyCFunction)__pyx_pw_5pyaff_1open, METH_O, 0}; +static PyObject *__pyx_pw_5pyaff_1open(PyObject *__pyx_self, PyObject *__pyx_v_filename) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("open (wrapper)", 0); + __pyx_r = __pyx_pf_5pyaff_open(__pyx_self, ((PyObject *)__pyx_v_filename)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject * -affile_read(affile *self, PyObject *args, PyObject *kwds) { - int written; - PyObject *retdata; - int readlen=-1; +static PyObject *__pyx_pf_5pyaff_open(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("open", 0); + + /* "pyaff.pyx":7 + * """Open afflib file (or set of files)""" + * def open(filename): + * return affile(filename) # <<<<<<<<<<<<<< + * + * """afflib File Object""" + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pyaff_affile), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - static char *kwlist[] = {"size", NULL}; - if(!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist, &readlen)) - return NULL; + /* "pyaff.pyx":6 + * + * """Open afflib file (or set of files)""" + * def open(filename): # <<<<<<<<<<<<<< + * return affile(filename) + * + */ - if(readlen < 0 || readlen > self->size) - readlen = self->size; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pyaff.open", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - retdata = PyString_FromStringAndSize(NULL, readlen); - written = af_read(self->af, (unsigned char *)PyString_AsString(retdata), readlen); +/* "pyaff.pyx":11 + * """afflib File Object""" + * cdef class affile(object): + * def __cinit__(self, basestring filename): # <<<<<<<<<<<<<< + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: + */ + +/* Python wrapper */ +static int __pyx_pw_5pyaff_6affile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pyaff_6affile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_filename = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_filename)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 11, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_filename = ((PyObject*)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 11, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pyaff.affile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_filename), (&PyBaseString_Type), 1, "filename", 1))) __PYX_ERR(0, 11, __pyx_L1_error) + __pyx_r = __pyx_pf_5pyaff_6affile___cinit__(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self), __pyx_v_filename); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - if(readlen != written) { - return PyErr_Format(PyExc_IOError, "Failed to read all data: wanted %d, got %d", readlen, written); +static int __pyx_pf_5pyaff_6affile___cinit__(struct __pyx_obj_5pyaff_affile *__pyx_v_self, PyObject *__pyx_v_filename) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + char const *__pyx_t_6; + int __pyx_t_7; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "pyaff.pyx":12 + * cdef class affile(object): + * def __cinit__(self, basestring filename): + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) # <<<<<<<<<<<<<< + * if self.af == NULL: + * raise IOError("Failed to initialise afflib") + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 12, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L1_error) + __pyx_v_self->af = af_open(__pyx_t_6, O_RDONLY, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pyaff.pyx":13 + * def __cinit__(self, basestring filename): + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: # <<<<<<<<<<<<<< + * raise IOError("Failed to initialise afflib") + * + */ + __pyx_t_7 = ((__pyx_v_self->af == NULL) != 0); + if (__pyx_t_7) { + + /* "pyaff.pyx":14 + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: + * raise IOError("Failed to initialise afflib") # <<<<<<<<<<<<<< + * + * self.size = afflib.af_get_imagesize(self.af) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 14, __pyx_L1_error) + + /* "pyaff.pyx":13 + * def __cinit__(self, basestring filename): + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: # <<<<<<<<<<<<<< + * raise IOError("Failed to initialise afflib") + * + */ + } - return retdata; + /* "pyaff.pyx":16 + * raise IOError("Failed to initialise afflib") + * + * self.size = afflib.af_get_imagesize(self.af) # <<<<<<<<<<<<<< + * + * """Read data from file""" + */ + __pyx_v_self->size = af_get_imagesize(__pyx_v_self->af); + + /* "pyaff.pyx":11 + * """afflib File Object""" + * cdef class affile(object): + * def __cinit__(self, basestring filename): # <<<<<<<<<<<<<< + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pyaff.affile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject * -affile_seek(affile *self, PyObject *args, PyObject *kwds) { - int64_t offset=0; - int whence=0; +/* "pyaff.pyx":19 + * + * """Read data from file""" + * def read(self, int size=-1): # <<<<<<<<<<<<<< + * readlen = size if 0 <= size <= self.size else self.size + * + */ - static char *kwlist[] = {"offset", "whence", NULL}; - if(!PyArg_ParseTupleAndKeywords(args, kwds, "L|i", kwlist, - &offset, &whence)) - return NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_3read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_3read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_size); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read") < 0)) __PYX_ERR(0, 19, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 19, __pyx_L3_error) + } else { + __pyx_v_size = ((int)-1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 19, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pyaff.affile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pyaff_6affile_2read(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self), __pyx_v_size); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pyaff_6affile_2read(struct __pyx_obj_5pyaff_affile *__pyx_v_self, int __pyx_v_size) { + int64_t __pyx_v_readlen; + PyObject *__pyx_v_retdata = NULL; + Py_ssize_t __pyx_v_written; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int64_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + unsigned char *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("read", 0); + + /* "pyaff.pyx":20 + * """Read data from file""" + * def read(self, int size=-1): + * readlen = size if 0 <= size <= self.size else self.size # <<<<<<<<<<<<<< + * + * retdata = bytearray(readlen) + */ + __pyx_t_2 = (0 <= __pyx_v_size); + if (__pyx_t_2) { + __pyx_t_2 = (__pyx_v_size <= __pyx_v_self->size); + } + if ((__pyx_t_2 != 0)) { + __pyx_t_1 = __pyx_v_size; + } else { + __pyx_t_1 = __pyx_v_self->size; + } + __pyx_v_readlen = __pyx_t_1; - if(af_seek(self->af, offset, whence) < 0) - return PyErr_Format(PyExc_IOError, "libaff_seek_offset failed"); + /* "pyaff.pyx":22 + * readlen = size if 0 <= size <= self.size else self.size + * + * retdata = bytearray(readlen) # <<<<<<<<<<<<<< + * written = afflib.af_read(self.af, retdata, size) + * if written != readlen: + */ + __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_readlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_retdata = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pyaff.pyx":23 + * + * retdata = bytearray(readlen) + * written = afflib.af_read(self.af, retdata, size) # <<<<<<<<<<<<<< + * if written != readlen: + * raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) + */ + __pyx_t_5 = __Pyx_PyObject_AsUString(__pyx_v_retdata); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 23, __pyx_L1_error) + __pyx_v_written = af_read(__pyx_v_self->af, __pyx_t_5, __pyx_v_size); + + /* "pyaff.pyx":24 + * retdata = bytearray(readlen) + * written = afflib.af_read(self.af, retdata, size) + * if written != readlen: # <<<<<<<<<<<<<< + * raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) + * + */ + __pyx_t_2 = ((__pyx_v_written != __pyx_v_readlen) != 0); + if (__pyx_t_2) { + + /* "pyaff.pyx":25 + * written = afflib.af_read(self.af, retdata, size) + * if written != readlen: + * raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) # <<<<<<<<<<<<<< + * + * return bytes(retdata) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Failed_to_read_all_data_wanted_g, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_readlen); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_written); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 25, __pyx_L1_error) + + /* "pyaff.pyx":24 + * retdata = bytearray(readlen) + * written = afflib.af_read(self.af, retdata, size) + * if written != readlen: # <<<<<<<<<<<<<< + * raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) + * + */ + } + + /* "pyaff.pyx":27 + * raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) + * + * return bytes(retdata) # <<<<<<<<<<<<<< + * + * """Seek within a file""" + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_retdata); + __Pyx_GIVEREF(__pyx_v_retdata); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_retdata); + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyBytes_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; - Py_RETURN_NONE; + /* "pyaff.pyx":19 + * + * """Read data from file""" + * def read(self, int size=-1): # <<<<<<<<<<<<<< + * readlen = size if 0 <= size <= self.size else self.size + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pyaff.affile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_retdata); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject * -affile_tell(affile *self) { - return PyLong_FromLongLong(af_tell(self->af)); +/* "pyaff.pyx":30 + * + * """Seek within a file""" + * def seek(self, int offset, int whence=0): # <<<<<<<<<<<<<< + * if afflib.af_seek(self.af, offset, whence) < 0: + * raise IOError("libaff_seek_offset failed") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_5seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_5seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_offset; + int __pyx_v_whence; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("seek (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,&__pyx_n_s_whence,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_offset)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_whence); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) __PYX_ERR(0, 30, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_offset = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 30, __pyx_L3_error) + if (values[1]) { + __pyx_v_whence = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_whence == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 30, __pyx_L3_error) + } else { + __pyx_v_whence = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 30, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pyaff.affile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pyaff_6affile_4seek(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self), __pyx_v_offset, __pyx_v_whence); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject * -affile_close(affile *self) { - af_close(self->af); - Py_RETURN_NONE; +static PyObject *__pyx_pf_5pyaff_6affile_4seek(struct __pyx_obj_5pyaff_affile *__pyx_v_self, int __pyx_v_offset, int __pyx_v_whence) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("seek", 0); + + /* "pyaff.pyx":31 + * """Seek within a file""" + * def seek(self, int offset, int whence=0): + * if afflib.af_seek(self.af, offset, whence) < 0: # <<<<<<<<<<<<<< + * raise IOError("libaff_seek_offset failed") + * + */ + __pyx_t_1 = ((af_seek(__pyx_v_self->af, __pyx_v_offset, __pyx_v_whence) < 0) != 0); + if (__pyx_t_1) { + + /* "pyaff.pyx":32 + * def seek(self, int offset, int whence=0): + * if afflib.af_seek(self.af, offset, whence) < 0: + * raise IOError("libaff_seek_offset failed") # <<<<<<<<<<<<<< + * + * """Retrieve an aff segment by name""" + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 32, __pyx_L1_error) + + /* "pyaff.pyx":31 + * """Seek within a file""" + * def seek(self, int offset, int whence=0): + * if afflib.af_seek(self.af, offset, whence) < 0: # <<<<<<<<<<<<<< + * raise IOError("libaff_seek_offset failed") + * + */ + } + + /* "pyaff.pyx":30 + * + * """Seek within a file""" + * def seek(self, int offset, int whence=0): # <<<<<<<<<<<<<< + * if afflib.af_seek(self.af, offset, whence) < 0: + * raise IOError("libaff_seek_offset failed") + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pyaff.affile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject *affile_get_seg(affile *self, PyObject *args, PyObject *kwds) { - PyObject *retdata; - char *buf; - size_t buflen=0; - char *segname=NULL; - static char *kwlist[] = {"segname", NULL}; +/* "pyaff.pyx":35 + * + * """Retrieve an aff segment by name""" + * def get_seg(self, basestring segname): # <<<<<<<<<<<<<< + * cdef size_t buflen = 0 + * cdef _segname = segname.encode('ascii') + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_7get_seg(PyObject *__pyx_v_self, PyObject *__pyx_v_segname); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_7get_seg(PyObject *__pyx_v_self, PyObject *__pyx_v_segname) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_seg (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_segname), (&PyBaseString_Type), 1, "segname", 1))) __PYX_ERR(0, 35, __pyx_L1_error) + __pyx_r = __pyx_pf_5pyaff_6affile_6get_seg(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self), ((PyObject*)__pyx_v_segname)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - if(!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &segname)) - return NULL; +static PyObject *__pyx_pf_5pyaff_6affile_6get_seg(struct __pyx_obj_5pyaff_affile *__pyx_v_self, PyObject *__pyx_v_segname) { + size_t __pyx_v_buflen; + PyObject *__pyx_v__segname = 0; + PyObject *__pyx_v_retdata = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + char const *__pyx_t_3; + int __pyx_t_4; + unsigned char *__pyx_t_5; + __Pyx_RefNannySetupContext("get_seg", 0); + + /* "pyaff.pyx":36 + * """Retrieve an aff segment by name""" + * def get_seg(self, basestring segname): + * cdef size_t buflen = 0 # <<<<<<<<<<<<<< + * cdef _segname = segname.encode('ascii') + * + */ + __pyx_v_buflen = 0; + + /* "pyaff.pyx":37 + * def get_seg(self, basestring segname): + * cdef size_t buflen = 0 + * cdef _segname = segname.encode('ascii') # <<<<<<<<<<<<<< + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_segname, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v__segname = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pyaff.pyx":39 + * cdef _segname = segname.encode('ascii') + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: # <<<<<<<<<<<<<< + * raise IOError("error reading libaff segment") + * print(buflen) + */ + __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v__segname); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L1_error) + __pyx_t_4 = ((af_get_seg(__pyx_v_self->af, __pyx_t_3, NULL, NULL, (&__pyx_v_buflen)) != 0) != 0); + if (__pyx_t_4) { + + /* "pyaff.pyx":40 + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + * raise IOError("error reading libaff segment") # <<<<<<<<<<<<<< + * print(buflen) + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 40, __pyx_L1_error) + + /* "pyaff.pyx":39 + * cdef _segname = segname.encode('ascii') + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: # <<<<<<<<<<<<<< + * raise IOError("error reading libaff segment") + * print(buflen) + */ + } + + /* "pyaff.pyx":41 + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + * raise IOError("error reading libaff segment") + * print(buflen) # <<<<<<<<<<<<<< + * + * retdata = bytearray(buflen) + */ + __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_buflen); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_PrintOne(0, __pyx_t_2) < 0) __PYX_ERR(0, 41, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pyaff.pyx":43 + * print(buflen) + * + * retdata = bytearray(buflen) # <<<<<<<<<<<<<< + * + * if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: + */ + __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_buflen); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_retdata = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pyaff.pyx":45 + * retdata = bytearray(buflen) + * + * if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: # <<<<<<<<<<<<<< + * raise IOError("error reading libaff segment") + * + */ + __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v__segname); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsUString(__pyx_v_retdata); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_4 = ((af_get_seg(__pyx_v_self->af, __pyx_t_3, NULL, __pyx_t_5, (&__pyx_v_buflen)) != 0) != 0); + if (__pyx_t_4) { + + /* "pyaff.pyx":46 + * + * if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: + * raise IOError("error reading libaff segment") # <<<<<<<<<<<<<< + * + * return bytes(retdata) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 46, __pyx_L1_error) + + /* "pyaff.pyx":45 + * retdata = bytearray(buflen) + * + * if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: # <<<<<<<<<<<<<< + * raise IOError("error reading libaff segment") + * + */ + } + + /* "pyaff.pyx":48 + * raise IOError("error reading libaff segment") + * + * return bytes(retdata) # <<<<<<<<<<<<<< + * + * """Retrieve a list of segments present""" + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_retdata); + __Pyx_GIVEREF(__pyx_v_retdata); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_retdata); + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyBytes_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pyaff.pyx":35 + * + * """Retrieve an aff segment by name""" + * def get_seg(self, basestring segname): # <<<<<<<<<<<<<< + * cdef size_t buflen = 0 + * cdef _segname = segname.encode('ascii') + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pyaff.affile.get_seg", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v__segname); + __Pyx_XDECREF(__pyx_v_retdata); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pyaff.pyx":51 + * + * """Retrieve a list of segments present""" + * def get_seg_names(self): # <<<<<<<<<<<<<< + * headers = [] + * segname = bytearray(afflib.AF_MAX_NAME_LEN) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_9get_seg_names(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_9get_seg_names(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_seg_names (wrapper)", 0); + __pyx_r = __pyx_pf_5pyaff_6affile_8get_seg_names(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - // first get the size - if(af_get_seg(self->af, segname, 0, 0, &buflen) != 0) { - return PyErr_Format(PyExc_IOError, "error reading libaff segment\n"); +static PyObject *__pyx_pf_5pyaff_6affile_8get_seg_names(struct __pyx_obj_5pyaff_affile *__pyx_v_self) { + PyObject *__pyx_v_headers = NULL; + PyObject *__pyx_v_segname = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + char *__pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + char *__pyx_t_7; + __Pyx_RefNannySetupContext("get_seg_names", 0); + + /* "pyaff.pyx":52 + * """Retrieve a list of segments present""" + * def get_seg_names(self): + * headers = [] # <<<<<<<<<<<<<< + * segname = bytearray(afflib.AF_MAX_NAME_LEN) + * + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_headers = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pyaff.pyx":53 + * def get_seg_names(self): + * headers = [] + * segname = bytearray(afflib.AF_MAX_NAME_LEN) # <<<<<<<<<<<<<< + * + * afflib.af_rewind_seg(self.af) + */ + __pyx_t_1 = __Pyx_PyInt_From_int(AF_MAX_NAME_LEN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_segname = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pyaff.pyx":55 + * segname = bytearray(afflib.AF_MAX_NAME_LEN) + * + * afflib.af_rewind_seg(self.af) # <<<<<<<<<<<<<< + * while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: + * if PY_MAJOR_VERSION < 3: + */ + af_rewind_seg(__pyx_v_self->af); + + /* "pyaff.pyx":56 + * + * afflib.af_rewind_seg(self.af) + * while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: # <<<<<<<<<<<<<< + * if PY_MAJOR_VERSION < 3: + * headers.append( segname) + */ + while (1) { + __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_segname); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_t_4 = PyObject_Length(__pyx_v_segname); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_t_5 = ((af_get_next_seg(__pyx_v_self->af, __pyx_t_3, __pyx_t_4, NULL, NULL, NULL) == 0) != 0); + if (!__pyx_t_5) break; + + /* "pyaff.pyx":57 + * afflib.af_rewind_seg(self.af) + * while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * headers.append( segname) + * else: + */ + __pyx_t_5 = ((PY_MAJOR_VERSION < 3) != 0); + if (__pyx_t_5) { + + /* "pyaff.pyx":58 + * while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: + * if PY_MAJOR_VERSION < 3: + * headers.append( segname) # <<<<<<<<<<<<<< + * else: + * headers.append(( segname).decode('ascii')) + */ + __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_segname); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 58, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_FromString(((char *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_headers, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pyaff.pyx":57 + * afflib.af_rewind_seg(self.af) + * while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * headers.append( segname) + * else: + */ + goto __pyx_L5; } - - // allocate a string to return data in - retdata = PyString_FromStringAndSize(NULL, buflen); - buf = PyString_AsString(retdata); - if(af_get_seg(self->af, segname, 0, (unsigned char *)buf, &buflen) != 0) { - Py_DECREF(retdata); - return PyErr_Format(PyExc_IOError, "error reading libaff segment\n"); + /* "pyaff.pyx":60 + * headers.append( segname) + * else: + * headers.append(( segname).decode('ascii')) # <<<<<<<<<<<<<< + * + * return headers + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_segname); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_7 = ((char *)__pyx_t_3); + __pyx_t_1 = __Pyx_decode_c_string(__pyx_t_7, 0, strlen(__pyx_t_7), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_headers, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - - return retdata; + __pyx_L5:; + } + + /* "pyaff.pyx":62 + * headers.append(( segname).decode('ascii')) + * + * return headers # <<<<<<<<<<<<<< + * + * """Return possition within file""" + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_headers); + __pyx_r = __pyx_v_headers; + goto __pyx_L0; + + /* "pyaff.pyx":51 + * + * """Retrieve a list of segments present""" + * def get_seg_names(self): # <<<<<<<<<<<<<< + * headers = [] + * segname = bytearray(afflib.AF_MAX_NAME_LEN) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pyaff.affile.get_seg_names", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_headers); + __Pyx_XDECREF(__pyx_v_segname); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject *affile_get_seg_names(affile *self) { - PyObject *headers, *tmp; - char segname[AF_MAX_NAME_LEN]; +/* "pyaff.pyx":65 + * + * """Return possition within file""" + * def tell(self): # <<<<<<<<<<<<<< + * return afflib.af_tell(self.af) + * + */ - af_rewind_seg(self->af); - headers = PyList_New(0); +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_11tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_11tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tell (wrapper)", 0); + __pyx_r = __pyx_pf_5pyaff_6affile_10tell(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - while(af_get_next_seg(self->af, segname, sizeof(segname), 0, 0, 0) == 0){ - tmp = PyString_FromString(segname); - PyList_Append(headers, tmp); - Py_DECREF(tmp); +static PyObject *__pyx_pf_5pyaff_6affile_10tell(struct __pyx_obj_5pyaff_affile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("tell", 0); + + /* "pyaff.pyx":66 + * """Return possition within file""" + * def tell(self): + * return afflib.af_tell(self.af) # <<<<<<<<<<<<<< + * + * """Close the file""" + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(af_tell(__pyx_v_self->af)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pyaff.pyx":65 + * + * """Return possition within file""" + * def tell(self): # <<<<<<<<<<<<<< + * return afflib.af_tell(self.af) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pyaff.affile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pyaff.pyx":69 + * + * """Close the file""" + * def close(self): # <<<<<<<<<<<<<< + * afflib.af_close(self.af) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pyaff_6affile_13close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pyaff_6affile_13close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("close (wrapper)", 0); + __pyx_r = __pyx_pf_5pyaff_6affile_12close(((struct __pyx_obj_5pyaff_affile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pyaff_6affile_12close(struct __pyx_obj_5pyaff_affile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("close", 0); + + /* "pyaff.pyx":70 + * """Close the file""" + * def close(self): + * afflib.af_close(self.af) # <<<<<<<<<<<<<< + * + */ + af_close(__pyx_v_self->af); + + /* "pyaff.pyx":69 + * + * """Close the file""" + * def close(self): # <<<<<<<<<<<<<< + * afflib.af_close(self.af) + * + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5pyaff_affile(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + if (unlikely(__pyx_pw_5pyaff_6affile_1__cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_5pyaff_affile(PyObject *o) { + #if PY_VERSION_HEX >= 0x030400a1 + if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_5pyaff_affile[] = { + {"read", (PyCFunction)__pyx_pw_5pyaff_6affile_3read, METH_VARARGS|METH_KEYWORDS, 0}, + {"seek", (PyCFunction)__pyx_pw_5pyaff_6affile_5seek, METH_VARARGS|METH_KEYWORDS, 0}, + {"get_seg", (PyCFunction)__pyx_pw_5pyaff_6affile_7get_seg, METH_O, 0}, + {"get_seg_names", (PyCFunction)__pyx_pw_5pyaff_6affile_9get_seg_names, METH_NOARGS, 0}, + {"tell", (PyCFunction)__pyx_pw_5pyaff_6affile_11tell, METH_NOARGS, 0}, + {"close", (PyCFunction)__pyx_pw_5pyaff_6affile_13close, METH_NOARGS, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pyaff_affile = { + PyVarObject_HEAD_INIT(0, 0) + "pyaff.affile", /*tp_name*/ + sizeof(struct __pyx_obj_5pyaff_affile), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pyaff_affile, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pyaff_affile, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pyaff_affile, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + #if PY_VERSION_HEX < 0x03020000 + { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, + #else + PyModuleDef_HEAD_INIT, + #endif + "pyaff", + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_Failed_to_initialise_afflib, __pyx_k_Failed_to_initialise_afflib, sizeof(__pyx_k_Failed_to_initialise_afflib), 0, 0, 1, 0}, + {&__pyx_kp_s_Failed_to_read_all_data_wanted_g, __pyx_k_Failed_to_read_all_data_wanted_g, sizeof(__pyx_k_Failed_to_read_all_data_wanted_g), 0, 0, 1, 0}, + {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, + {&__pyx_kp_s_Users_umireon_AFFLIBv3_pyaff_py, __pyx_k_Users_umireon_AFFLIBv3_pyaff_py, sizeof(__pyx_k_Users_umireon_AFFLIBv3_pyaff_py), 0, 0, 1, 0}, + {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, + {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, + {&__pyx_kp_s_error_reading_libaff_segment, __pyx_k_error_reading_libaff_segment, sizeof(__pyx_k_error_reading_libaff_segment), 0, 0, 1, 0}, + {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1}, + {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, + {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, + {&__pyx_n_s_getfilesystemencoding, __pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_kp_s_libaff_seek_offset_failed, __pyx_k_libaff_seek_offset_failed, sizeof(__pyx_k_libaff_seek_offset_failed), 0, 0, 1, 0}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1}, + {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, + {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1}, + {&__pyx_n_s_pyaff, __pyx_k_pyaff, sizeof(__pyx_k_pyaff), 0, 0, 1, 1}, + {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, + {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_whence, __pyx_k_whence, sizeof(__pyx_k_whence), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 14, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "pyaff.pyx":14 + * self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + * if self.af == NULL: + * raise IOError("Failed to initialise afflib") # <<<<<<<<<<<<<< + * + * self.size = afflib.af_get_imagesize(self.af) + */ + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Failed_to_initialise_afflib); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "pyaff.pyx":32 + * def seek(self, int offset, int whence=0): + * if afflib.af_seek(self.af, offset, whence) < 0: + * raise IOError("libaff_seek_offset failed") # <<<<<<<<<<<<<< + * + * """Retrieve an aff segment by name""" + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_libaff_seek_offset_failed); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "pyaff.pyx":37 + * def get_seg(self, basestring segname): + * cdef size_t buflen = 0 + * cdef _segname = segname.encode('ascii') # <<<<<<<<<<<<<< + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "pyaff.pyx":40 + * + * if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + * raise IOError("error reading libaff segment") # <<<<<<<<<<<<<< + * print(buflen) + * + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_error_reading_libaff_segment); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "pyaff.pyx":46 + * + * if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: + * raise IOError("error reading libaff segment") # <<<<<<<<<<<<<< + * + * return bytes(retdata) + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_error_reading_libaff_segment); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + + /* "pyaff.pyx":6 + * + * """Open afflib file (or set of files)""" + * def open(filename): # <<<<<<<<<<<<<< + * return affile(filename) + * + */ + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_n_s_filename); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_umireon_AFFLIBv3_pyaff_py, __pyx_n_s_open, 6, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC initpyaff(void); /*proto*/ +PyMODINIT_FUNC initpyaff(void) +#else +PyMODINIT_FUNC PyInit_pyaff(void); /*proto*/ +PyMODINIT_FUNC PyInit_pyaff(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_REFNANNY + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + #endif + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_pyaff(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("pyaff", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_pyaff) { + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "pyaff")) { + if (unlikely(PyDict_SetItemString(modules, "pyaff", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global init code ---*/ + /*--- Variable export code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_5pyaff_affile) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + __pyx_type_5pyaff_affile.tp_print = 0; + if (PyObject_SetAttrString(__pyx_m, "affile", (PyObject *)&__pyx_type_5pyaff_affile) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + __pyx_ptype_5pyaff_affile = &__pyx_type_5pyaff_affile; + /*--- Type import code ---*/ + /*--- Variable import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "pyaff.pyx":1 + * import sys # <<<<<<<<<<<<<< + * from cpython.version cimport PY_MAJOR_VERSION + * cimport afflib + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - return headers; + /* "pyaff.pyx":6 + * + * """Open afflib file (or set of files)""" + * def open(filename): # <<<<<<<<<<<<<< + * return affile(filename) + * + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pyaff_1open, NULL, __pyx_n_s_pyaff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_open, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pyaff.pyx":1 + * import sys # <<<<<<<<<<<<<< + * from cpython.version cimport PY_MAJOR_VERSION + * cimport afflib + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init pyaff", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init pyaff"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif } -static PyObject *pyaff_open(PyObject *self, PyObject *args, PyObject *kwds) { - int ret; - affile *file; - PyObject *files, *fileargs, *filekwds; - static char *kwlist[] = {"filename", NULL}; +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif - if(!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &files)) +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); + if (unlikely(!result)) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* RaiseDoubleKeywords */ +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + continue; + } + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = (**name == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* ArgTypeTest */ +static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); +} +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (likely(Py_TYPE(obj) == type)) return 1; + #if PY_MAJOR_VERSION == 2 + else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(PyObject_TypeCheck(obj, type))) return 1; + } + __Pyx_RaiseArgumentTypeInvalid(name, obj, type); + return 0; +} + +/* GetModuleGlobalName */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS + result = PyDict_GetItem(__pyx_d, name); + if (likely(result)) { + Py_INCREF(result); + } else { +#else + result = PyObject_GetItem(__pyx_d, name); + if (!result) { + PyErr_Clear(); +#endif + result = __Pyx_GetBuiltinName(name); + } + return result; +} - /* create an affile object and return it */ - fileargs = PyTuple_New(0); - filekwds = Py_BuildValue("{sO}", "filename", files); - if(!filekwds) return NULL; - - file = PyObject_New(affile, &affileType); - ret = affile_init(file, fileargs, filekwds); - Py_DECREF(fileargs); - Py_DECREF(filekwds); +/* PyCFunctionFastCall */ + #if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { + PyCFunctionObject *func = (PyCFunctionObject*)func_obj; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + PyObject *result; + int flags; + assert(PyCFunction_Check(func)); + assert(METH_FASTCALL == PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)); + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + /* _PyCFunction_FastCallDict() must not be called with an exception set, + because it may clear it (directly or indirectly) and so the + caller loses its exception */ + assert(!PyErr_Occurred()); + return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL); +} +#endif // CYTHON_FAST_PYCCALL - if(ret == -1) { - Py_DECREF(file); +/* PyFunctionFastCall */ + #if CYTHON_FAST_PYCALL +#include "frameobject.h" +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = PyThreadState_GET(); + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = f->f_localsplus; + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { return NULL; } - return (PyObject *)file; + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; } +#endif // CPython < 3.6 +#endif // CYTHON_FAST_PYCALL -/* these are the module methods */ -static PyMethodDef pyaff_methods[] = { - {"open", (PyCFunction)pyaff_open, METH_VARARGS|METH_KEYWORDS, - "Open afflib file (or set of files)" }, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; +/* PyObjectCallMethO */ + #if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = PyCFunction_GET_FUNCTION(func); + self = PyCFunction_GET_SELF(func); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void +/* PyObjectCallOneArg */ + #if CYTHON_COMPILING_IN_CPYTHON +static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_New(1); + if (unlikely(!args)) return NULL; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, &arg, 1); + } +#endif +#ifdef __Pyx_CyFunction_USED + if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { +#else + if (likely(PyCFunction_Check(func))) { +#endif + if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { + return __Pyx_PyObject_CallMethO(func, arg); +#if CYTHON_FAST_PYCCALL + } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { + return __Pyx_PyCFunction_FastCall(func, &arg, 1); +#endif + } + } + return __Pyx__PyObject_CallOneArg(func, arg); +} +#else +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_Pack(1, arg); + if (unlikely(!args)) return NULL; + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} #endif -PyMODINIT_FUNC -initpyaff(void) -{ - PyObject* m; - /* create module */ - m = Py_InitModule3("pyaff", pyaff_methods, "Python libaff module."); +/* PyObjectCallNoArg */ + #if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, NULL, 0); + } +#endif +#ifdef __Pyx_CyFunction_USED + if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { +#else + if (likely(PyCFunction_Check(func))) { +#endif + if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { + return __Pyx_PyObject_CallMethO(func, NULL); + } + } + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); +} +#endif + +/* PyErrFetchRestore */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* RaiseException */ + #if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } +#if PY_VERSION_HEX >= 0x03030000 + if (cause) { +#else + if (cause && cause != Py_None) { +#endif + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif - /* setup affile type */ - affileType.tp_new = PyType_GenericNew; - if (PyType_Ready(&affileType) < 0) +/* decode_c_string */ + static CYTHON_INLINE PyObject* __Pyx_decode_c_string( + const char* cstring, Py_ssize_t start, Py_ssize_t stop, + const char* encoding, const char* errors, + PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) { + Py_ssize_t length; + if (unlikely((start < 0) | (stop < 0))) { + size_t slen = strlen(cstring); + if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, + "c-string too long to convert to Python"); + return NULL; + } + length = (Py_ssize_t) slen; + if (start < 0) { + start += length; + if (start < 0) + start = 0; + } + if (stop < 0) + stop += length; + } + length = stop - start; + if (unlikely(length <= 0)) + return PyUnicode_FromUnicode(NULL, 0); + cstring += start; + if (decode_func) { + return decode_func(cstring, length, errors); + } else { + return PyUnicode_Decode(cstring, length, encoding, errors); + } +} + +/* Import */ + static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (!py_import) + goto bad; + #endif + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_level = PyInt_FromLong(1); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + #endif + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_VERSION_HEX < 0x03030000 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } +bad: + #if PY_VERSION_HEX < 0x03030000 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* CodeObjectCache */ + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} - Py_INCREF(&affileType); - PyModule_AddObject(m, "affile", (PyObject *)&affileType); +/* AddTraceback */ + #include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + py_code = __pyx_find_code_object(c_line ? c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? c_line : py_line, py_code); + } + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntFromPyVerify */ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) { + const int64_t neg_one = (int64_t) -1, const_zero = (int64_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int64_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int64_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int64_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int64_t), + little, !is_unsigned); + } +} + +/* Print */ + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3 +static PyObject *__Pyx_GetStdout(void) { + PyObject *f = PySys_GetObject((char *)"stdout"); + if (!f) { + PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); + } + return f; } +static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) { + int i; + if (!f) { + if (!(f = __Pyx_GetStdout())) + return -1; + } + Py_INCREF(f); + for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) { + PyObject* v; + if (PyFile_SoftSpace(f, 1)) { + if (PyFile_WriteString(" ", f) < 0) + goto error; + } + v = PyTuple_GET_ITEM(arg_tuple, i); + if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0) + goto error; + if (PyString_Check(v)) { + char *s = PyString_AsString(v); + Py_ssize_t len = PyString_Size(v); + if (len > 0) { + switch (s[len-1]) { + case ' ': break; + case '\f': case '\r': case '\n': case '\t': case '\v': + PyFile_SoftSpace(f, 0); + break; + default: break; + } + } + } + } + if (newline) { + if (PyFile_WriteString("\n", f) < 0) + goto error; + PyFile_SoftSpace(f, 0); + } + Py_DECREF(f); + return 0; +error: + Py_DECREF(f); + return -1; +} +#else +static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { + PyObject* kwargs = 0; + PyObject* result = 0; + PyObject* end_string; + if (unlikely(!__pyx_print)) { + __pyx_print = PyObject_GetAttr(__pyx_b, __pyx_n_s_print); + if (!__pyx_print) + return -1; + } + if (stream) { + kwargs = PyDict_New(); + if (unlikely(!kwargs)) + return -1; + if (unlikely(PyDict_SetItem(kwargs, __pyx_n_s_file, stream) < 0)) + goto bad; + if (!newline) { + end_string = PyUnicode_FromStringAndSize(" ", 1); + if (unlikely(!end_string)) + goto bad; + if (PyDict_SetItem(kwargs, __pyx_n_s_end, end_string) < 0) { + Py_DECREF(end_string); + goto bad; + } + Py_DECREF(end_string); + } + } else if (!newline) { + if (unlikely(!__pyx_print_kwargs)) { + __pyx_print_kwargs = PyDict_New(); + if (unlikely(!__pyx_print_kwargs)) + return -1; + end_string = PyUnicode_FromStringAndSize(" ", 1); + if (unlikely(!end_string)) + return -1; + if (PyDict_SetItem(__pyx_print_kwargs, __pyx_n_s_end, end_string) < 0) { + Py_DECREF(end_string); + return -1; + } + Py_DECREF(end_string); + } + kwargs = __pyx_print_kwargs; + } + result = PyObject_Call(__pyx_print, arg_tuple, kwargs); + if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs)) + Py_DECREF(kwargs); + if (!result) + return -1; + Py_DECREF(result); + return 0; +bad: + if (kwargs != __pyx_print_kwargs) + Py_XDECREF(kwargs); + return -1; +} +#endif + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) { + const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(uint64_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(uint64_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(uint64_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(uint64_t), + little, !is_unsigned); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* PrintOne */ + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3 +static int __Pyx_PrintOne(PyObject* f, PyObject *o) { + if (!f) { + if (!(f = __Pyx_GetStdout())) + return -1; + } + Py_INCREF(f); + if (PyFile_SoftSpace(f, 0)) { + if (PyFile_WriteString(" ", f) < 0) + goto error; + } + if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0) + goto error; + if (PyFile_WriteString("\n", f) < 0) + goto error; + Py_DECREF(f); + return 0; +error: + Py_DECREF(f); + return -1; + /* the line below is just to avoid C compiler + * warnings about unused functions */ + return __Pyx_Print(f, NULL, 0); +} +#else +static int __Pyx_PrintOne(PyObject* stream, PyObject *o) { + int res; + PyObject* arg_tuple = PyTuple_Pack(1, o); + if (unlikely(!arg_tuple)) + return -1; + res = __Pyx_Print(stream, arg_tuple, 1); + Py_DECREF(arg_tuple); + return res; +} +#endif + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CheckBinaryVersion */ + static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + return PyErr_WarnEx(NULL, message, 1); + } + return 0; +} + +/* InitStrings */ + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { +#if PY_VERSION_HEX < 0x03030000 + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +#else + if (__Pyx_PyUnicode_READY(o) == -1) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (PyUnicode_IS_ASCII(o)) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +#endif + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } + #else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } + #endif +#else + res = PyNumber_Int(x); +#endif + if (res) { +#if PY_MAJOR_VERSION < 3 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(x); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + +#endif /* Py_PYTHON_H */ diff -Nru afflib-3.7.7/pyaff/pyaff.pxd afflib-3.7.16/pyaff/pyaff.pxd --- afflib-3.7.7/pyaff/pyaff.pxd 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/pyaff/pyaff.pxd 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,6 @@ +cimport afflib +from libc.stdint cimport int64_t + +cdef class affile: + cdef afflib.AFFILE *af + cdef int64_t size diff -Nru afflib-3.7.7/pyaff/pyaff.pyx afflib-3.7.16/pyaff/pyaff.pyx --- afflib-3.7.7/pyaff/pyaff.pyx 1970-01-01 00:00:00.000000000 +0000 +++ afflib-3.7.16/pyaff/pyaff.pyx 2017-06-24 00:57:09.000000000 +0000 @@ -0,0 +1,71 @@ +import sys +from cpython.version cimport PY_MAJOR_VERSION +cimport afflib + +"""Open afflib file (or set of files)""" +def open(filename): + return affile(filename) + +"""afflib File Object""" +cdef class affile(object): + def __cinit__(self, basestring filename): + self.af = afflib.af_open(filename.encode(sys.getfilesystemencoding()), afflib.O_RDONLY, 0) + if self.af == NULL: + raise IOError("Failed to initialise afflib") + + self.size = afflib.af_get_imagesize(self.af) + + """Read data from file""" + def read(self, int size=-1): + readlen = size if 0 <= size <= self.size else self.size + + retdata = bytearray(readlen) + written = afflib.af_read(self.af, retdata, size) + if written != readlen: + raise IOError("Failed to read all data: wanted {}, got {}".format(readlen, written)) + + return bytes(retdata) + + """Seek within a file""" + def seek(self, int offset, int whence=0): + if afflib.af_seek(self.af, offset, whence) < 0: + raise IOError("libaff_seek_offset failed") + + """Retrieve an aff segment by name""" + def get_seg(self, basestring segname): + cdef size_t buflen = 0 + cdef _segname = segname.encode('ascii') + + if afflib.af_get_seg(self.af, _segname, NULL, NULL, &buflen) != 0: + raise IOError("error reading libaff segment") + print(buflen) + + retdata = bytearray(buflen) + + if afflib.af_get_seg(self.af, _segname, NULL, retdata, &buflen) != 0: + raise IOError("error reading libaff segment") + + return bytes(retdata) + + """Retrieve a list of segments present""" + def get_seg_names(self): + headers = [] + segname = bytearray(afflib.AF_MAX_NAME_LEN) + + afflib.af_rewind_seg(self.af) + while afflib.af_get_next_seg(self.af, segname, len(segname), NULL, NULL, NULL) == 0: + if PY_MAJOR_VERSION < 3: + headers.append( segname) + else: + headers.append(( segname).decode('ascii')) + + return headers + + """Return possition within file""" + def tell(self): + return afflib.af_tell(self.af) + + """Close the file""" + def close(self): + afflib.af_close(self.af) + diff -Nru afflib-3.7.7/pyaff/README afflib-3.7.16/pyaff/README --- afflib-3.7.7/pyaff/README 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/pyaff/README 2017-06-24 00:57:09.000000000 +0000 @@ -21,7 +21,7 @@ #/usr/bin/python import pyaff - fd = pyaff("diskimage.aff") + fd = pyaff.open("diskimage.aff") data = fd.read(1000) fd.seek(0, SEEK_SET) diff -Nru afflib-3.7.7/pyaff/setup.py afflib-3.7.16/pyaff/setup.py --- afflib-3.7.7/pyaff/setup.py 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/pyaff/setup.py 2017-06-24 00:57:09.000000000 +0000 @@ -1,8 +1,18 @@ -from distutils.core import setup, Extension +try: + from setuptools import setup, Extension, command +except ImportError: + from distutils.core import setup, Extension -pyaff = Extension('pyaff', - libraries = ['afflib'], - sources = ['pyaff.c']) +try: + from Cython.Build import cythonize + USE_CYTHON = True +except ImportError: + USE_CYTHON = False + +pyaff = [Extension('pyaff', ['pyaff.pyx'], libraries = ['afflib'])] + +if USE_CYTHON: + pyaff = cythonize(pyaff) setup (name = 'PyAFF', version = '0.1', @@ -11,4 +21,4 @@ author_email = 'david.collett@gmail.com', url = 'www.pyflag.net', license = "GPL", - ext_modules = [pyaff]) + ext_modules = pyaff) diff -Nru afflib-3.7.7/README afflib-3.7.16/README --- afflib-3.7.7/README 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/README 2017-06-24 00:57:09.000000000 +0000 @@ -4,7 +4,7 @@ 2005-2006 Basis Technology, Inc. 2005-2013 Simson L. Garfinkel - 2014 Phillip Hellewell + 2014-2017 Phillip Hellewell The Advanced Forensic Format (AFF) is on-disk format for storing computer forensic information. Critical features of AFF include: @@ -30,7 +30,6 @@ - raw or "dd" - splitraw (in which a single image is split between mulitple files) - - EnCase or "E01" format - AFF format (in which the entire disk image is stored in a single file.) - AFD format (in which a disk image is stored in mulitple AFF files stored in a single directory.) diff -Nru afflib-3.7.7/tools/aff_bom.cpp afflib-3.7.16/tools/aff_bom.cpp --- afflib-3.7.7/tools/aff_bom.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/aff_bom.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -13,7 +13,7 @@ * United States Government and/or for any works created by United * States Government employees. User acknowledges that this software * contains work which was created by NPS employee(s) and is therefore - * in the public domain and not subject to copyright. + * in the public domain and not subject to copyright. * -------------------------------------------------------------------- * * Change History: @@ -35,6 +35,12 @@ #include #endif +/* Support OpenSSL before 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define EVP_MD_CTX_new EVP_MD_CTX_create +#define EVP_MD_CTX_free EVP_MD_CTX_destroy +#endif + using namespace std; int parse_chain(const string &name) @@ -97,7 +103,7 @@ while(notes){ char buf2[1024]; char *val=0; - + #ifdef HAVE_LIBREADLINE if(isatty(fileno(stdin))){ val = readline(""); @@ -120,10 +126,12 @@ int aff_bom::read_files(const char *cert_file,const char *key_file) { BIO *bp_cert = BIO_new_file(cert_file,"r"); // read the certfile + if (!bp_cert) + return -1; PEM_read_bio_X509(bp_cert,&cert,0,0); // get an x509 cert BIO_free(bp_cert); if(!cert) return -1; // can't read certificate file - + /* Now read the private key */ BIO *bp_privkey = BIO_new_file(key_file,"r"); privkey = PEM_read_bio_PrivateKey(bp_privkey,0,0,0); @@ -133,14 +141,14 @@ cert = 0; return -1; } - + bom_open = true; xml = BIO_new(BIO_s_mem()); // where we are writing time_t clock = time(0); struct tm *tm = localtime(&clock); char timebuf[1024]; strftime(timebuf,sizeof(timebuf),"%FT%T",tm); - + BIO_printf(xml,"<%s version=\"1\">\n",AF_XML_AFFBOM); BIO_printf(xml," %s\n",timebuf); BIO_printf(xml," afcopy\n"); @@ -185,18 +193,19 @@ size_t xlen = BIO_get_mem_data(xml,&xbuf); unsigned char sig[1024]; u_int siglen = sizeof(sig); - - EVP_MD_CTX md; - EVP_SignInit(&md,sha256); - EVP_SignUpdate(&md,xbuf,xlen); - EVP_SignFinal(&md,sig,&siglen,privkey); - + + EVP_MD_CTX *md = EVP_MD_CTX_new(); + EVP_SignInit(md,sha256); + EVP_SignUpdate(md,xbuf,xlen); + EVP_SignFinal(md,sig,&siglen,privkey); + EVP_MD_CTX_free(md); + /* Write the signature in base64 encoding... */ BIO *b64 = BIO_new(BIO_f_base64()); xml = BIO_push(b64,xml); BIO_write(xml,sig,siglen); if(BIO_flush(xml)!=1) return; // something wrong - + /* Remove the base64 bio */ xml = BIO_pop(b64); } @@ -222,12 +231,13 @@ if(sha256){ unsigned int seghash_len = SHA256_SIZE; uint32_t arg_net = htonl(arg); - EVP_MD_CTX md; /* EVP message digest */ - EVP_DigestInit(&md,sha256); - EVP_DigestUpdate(&md,(const unsigned char *)segname,strlen(segname)+1); - EVP_DigestUpdate(&md,(const unsigned char *)&arg_net,sizeof(arg_net)); - EVP_DigestUpdate(&md,segbuf,segsize); - EVP_DigestFinal(&md,seghash,&seghash_len); + EVP_MD_CTX *md = EVP_MD_CTX_new(); /* EVP message digest */ + EVP_DigestInit(md,sha256); + EVP_DigestUpdate(md,(const unsigned char *)segname,strlen(segname)+1); + EVP_DigestUpdate(md,(const unsigned char *)&arg_net,sizeof(arg_net)); + EVP_DigestUpdate(md,segbuf,segsize); + EVP_DigestFinal(md,seghash,&seghash_len); + EVP_MD_CTX_free(md); } } @@ -237,8 +247,8 @@ size_t datalen = 0; if(af_get_seg(af,segname,0,0,&datalen)<0) return -1; uint32_t arg; - u_char *segdata = (u_char *)malloc(datalen);/* Allocate memory */ - if(segdata<0) return -1; + u_char *segdata = (u_char *)malloc(datalen); + if(!segdata) return -1; if(af_get_seg(af,segname,&arg,segdata,&datalen)<0){ free(segdata); return -1; @@ -248,7 +258,7 @@ add(segname,AF_SIGNATURE_MODE0,seghash,sizeof(seghash)); free(segdata); return(0); - + } diff -Nru afflib-3.7.7/tools/affcat.cpp afflib-3.7.16/tools/affcat.cpp --- afflib-3.7.7/tools/affcat.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affcat.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -61,7 +61,7 @@ { fprintf(stderr,"affcat "); if(current_fname) fprintf(stderr,"%s: ",current_fname); - if(current_page>=0) fprintf(stderr,"[%"PRId64"] ",current_page); + if(current_page>=0) fprintf(stderr,"[%" PRId64 "] ",current_page); fflush(stderr); } @@ -99,12 +99,12 @@ int bytes = af_read(af,buf,af->image_pagesize); // read what we can if(bytes<0){ - if(opt_debug) fprintf(stderr,"affcat: cannot read page %"I64d"\n",pagenum); + if(opt_debug) fprintf(stderr,"affcat: cannot read page %" I64d "\n",pagenum); return -1; } if(opt_debug){ - fprintf(stderr,"affcat: page:%"I64d" bytes: %d offset:%"I64d"\n", + fprintf(stderr,"affcat: page:%" I64d" bytes: %d offset:%" I64d "\n", pagenum, bytes,offset); } @@ -117,7 +117,7 @@ } } - if(opt_debug) fprintf(stderr," outputing %d bytes\n",bytes); + if(opt_debug) fprintf(stderr," outputting %d bytes\n",bytes); int count = fwrite(buf,1,bytes,outfile); // send to the output if(count!=bytes) fprintf(stderr,"fwrite(buf,1,%d,outfile) only wrote %d bytes\n",bytes,count); free(buf); @@ -196,7 +196,7 @@ const char *opt = opts.c_str(); uint64_t offset=0; int count=0; - if(sscanf(opt,"%"I64u":%d",&offset,&count)!=2){ + if(sscanf(opt,"%" I64u ":%d",&offset,&count)!=2){ err(1,"Cannot decode '%s'\n",opt); } af_seek(af,offset,SEEK_SET); @@ -227,7 +227,7 @@ if(opt_list){ printf("%s",segname); if(opt_list_long){ - printf("\targ:%"PRIu32"\tlen:%d",arg,(int)datalen); + printf("\targ:%" PRIu32 "\tlen:%d",arg,(int)datalen); } putchar('\n'); } @@ -270,7 +270,7 @@ //fprintf(stderr,"bytes written=%qd imagesize=%qd\n",total_bytes_written,imagesize); if((total_bytes_written > imagesize) && (imagesize>0)){ - err(1,"affcat internal error. bytes written=%"I64d" imagesize=%" I64d, + err(1,"affcat internal error. bytes written=%" I64d " imagesize=%" I64d, (int64_t)total_bytes_written, (int64_t)imagesize); return -1; @@ -284,7 +284,7 @@ { int64_t r=0; char ch; - if(sscanf(buf,"%"I64d"%c",&r,&ch)==1) return r; + if(sscanf(buf,"%" I64d "%c",&r,&ch)==1) return r; fprintf(stderr,"Cannot parse '%s'\n",buf); exit(0); } diff -Nru afflib-3.7.7/tools/affcompare.cpp afflib-3.7.16/tools/affcompare.cpp --- afflib-3.7.7/tools/affcompare.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affcompare.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -153,10 +153,10 @@ void print_info(char dir,const char *segname,uint32_t arg,size_t len, unsigned char *data,int mcr) { - printf(" %c %s arg=%"PRIu32" len=%d\n",dir,segname,arg,(int)len); + printf(" %c %s arg=%" PRIu32 " len=%d\n",dir,segname,arg,(int)len); printf(" "); if((arg == AF_SEG_QUADWORD) && (len==8)){ - printf("data=%"I64d" as a 64-bit value\n",af_decode_q(data)); + printf("data=%" I64d " as a 64-bit value\n",af_decode_q(data)); return; } /* Otherwise, just print some stuff... */ @@ -290,17 +290,17 @@ /* Find the size of each page, then get the page */ if(af_get_page(af1,pagenum,0,&data1_len)<0) - err(1,"Cannot read page %"I64d" size from %s\n",pagenum,af_filename(af1)); + err(1,"Cannot read page %" I64d " size from %s\n",pagenum,af_filename(af1)); if(af_get_page(af1,pagenum,data1,&data1_len)<0) - err(1,"Cannot read page %"I64d" from %s",pagenum,af_filename(af1)); + err(1,"Cannot read page %" I64d " from %s",pagenum,af_filename(af1)); if(af_get_page(af2,pagenum,0,&data2_len)<0) - err(1,"Cannot read page %"I64d" size from %s\n",pagenum,af_filename(af2)); + err(1,"Cannot read page %" I64d " size from %s\n",pagenum,af_filename(af2)); if(af_get_page(af2,pagenum,data2,&data2_len)<0) - err(1,"Cannot read page %"I64d" from %s",pagenum,af_filename(af2)); + err(1,"Cannot read page %" I64d " from %s",pagenum,af_filename(af2)); if(data1_len != data2_len){ - printf("page %"I64d" size %d != size %d\n",pagenum,(int)data1_len,(int)data2_len); + printf("page %" I64d " size %d != size %d\n",pagenum,(int)data1_len,(int)data2_len); return 1; } @@ -341,7 +341,7 @@ outline[0] = 0; if(opt_all || (no_match>0) || af1_bad || af2_bad){ snprintf(outline,sizeof(outline), - " page%"I64d" sectors:%4d matching: %3d different:%3d", + " page%" I64d " sectors:%4d matching: %3d different:%3d", pagenum,total_sectors,matching_sectors,no_match); } if(af1_bad){ @@ -373,7 +373,7 @@ if(i==0){ printf("\n "); } - printf(" %"I64d,*j); + printf(" %" I64d,*j); i = (i+1) % 10; } putchar('\n'); @@ -391,7 +391,7 @@ memcpy(b2,data1+offset,16); b2[15]=0; - printf("=== sector %"I64d" (offset=%d) ===\n",*j,offset); + printf("=== sector %" I64d " (offset=%d) ===\n",*j,offset); printf(" %s:\n",af_filename(af1)); print_sector(af1,data1+offset); printf("-------------------------------------\n"); @@ -429,10 +429,10 @@ size_t len1,len2; if(af_get_page_raw(af1,*i,&arg1,0,&len1)){ - err(1,"Could not read page %"I64d" in file %s\n",*i,af_filename(af1)); + err(1,"Could not read page %" I64d " in file %s\n",*i,af_filename(af1)); } if(af_get_page_raw(af2,*i,&arg2,0,&len2)){ - err(1,"Page %"I64d" is in file %s but not in %s\n",*i,af_filename(af1), + err(1,"Page %" I64d " is in file %s but not in %s\n",*i,af_filename(af1), af_filename(af2)); } if(arg1==arg2 && len1==len2){ @@ -450,7 +450,7 @@ continue; } } - printf("%s -> %s Nochg: %d NUL: %d LZMA: %d old: %"I64d" new: %"I64d" LZred: %6.2f%%\n", + printf("%s -> %s Nochg: %d NUL: %d LZMA: %d old: %" I64d " new: %" I64d " LZred: %6.2f%%\n", af_filename(af1), af_filename(af2), comp_unchanged,comp_zero,comp_lzma,bytes_old,bytes_new,(bytes_old-bytes_new)*100.0/bytes_old); @@ -492,8 +492,8 @@ if(af1->image_pagesize != af2->image_pagesize){ fprintf(stderr,"Currently, %s requires that both images have the " "same image datsegsize.\n" - " pagesize(%s)=%"PRIu32"\n" - " pagesize(%s)=%"PRIu32"\n", + " pagesize(%s)=%" PRIu32 "\n" + " pagesize(%s)=%" PRIu32 "\n", progname,file1,af1->image_pagesize, file2,af2->image_pagesize); fprintf(stderr,"Data segments will be ignored.\n"); no_data_segments = true; @@ -502,8 +502,8 @@ if(af1->image_sectorsize != af2->image_sectorsize){ fprintf(stderr,"Currently, %s requires that both images have the " "same image sectorsize.\n" - " sectorsize(%s)=%"PRIu32"\n" - " sectorsize(%s)=%"PRIu32"\n", + " sectorsize(%s)=%" PRIu32 "\n" + " sectorsize(%s)=%" PRIu32 "\n", progname,file1,af1->image_sectorsize, file2,af2->image_sectorsize); fprintf(stderr,"Data segments will be ignored.\n"); no_data_segments = true; diff -Nru afflib-3.7.7/tools/affconvert.cpp afflib-3.7.16/tools/affconvert.cpp --- afflib-3.7.7/tools/affconvert.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affconvert.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -22,15 +22,6 @@ #include "unix4win32.h" #endif -#ifdef HAVE_CURSES_H -#include -#endif - -#ifdef HAVE_TERM_H -#include -#endif - - #ifdef HAVE_SYS_TIME_H #include #endif @@ -423,15 +414,15 @@ int64_t pagenum = *i; - if(!opt_quiet) printf("Converting page %"I64d" of %"I64d"\r",pagenum,highest_pagenum);fflush(stdout); + if(!opt_quiet) { printf("Converting page %" I64d " of %" I64d "\r",pagenum,highest_pagenum); fflush(stdout); } size_t data_len = image_pagesize; if(af_get_page(a_in,pagenum,data,&data_len)){ - err(1,"af_get_page(file=%s,page=%"I64d")", + err(1,"af_get_page(file=%s,page=%" I64d ")", af_filename(a_in),pagenum); } if(af_update_page(a_out,pagenum,data,data_len)){ - err(1,"af_update_page(file=%s,page=%"I64d")", + err(1,"af_update_page(file=%s,page=%" I64d ")", af_filename(a_out),pagenum); } @@ -448,7 +439,7 @@ /* Go back and update the image size (necessary since I have been writing page-by-page) */ if(af_update_segq(a_out,AF_IMAGESIZE,last_byte_in_image) && errno!=ENOTSUP){ - err(1,"Could not upate AF_IMAGESIZE"); + err(1,"Could not update AF_IMAGESIZE"); } } else { /* No page support; Copy from beginning to end */ @@ -499,10 +490,10 @@ /* Finish the hash calculations and write to the db */ if(!opt_quiet){ - printf("bytes converted: %"I64d" \n",total_bytes_converted); + printf("bytes converted: %" I64d " \n",total_bytes_converted); /* If the vnode implementation tracked segments written, report it. */ if(a_out->pages_written || a_out->pages_compressed){ - printf("Total pages: %"I64u" (%"I64u" compressed)\n", + printf("Total pages: %" I64u " (%" I64u " compressed)\n", a_out->pages_written,a_out->pages_compressed); } } @@ -552,7 +543,7 @@ int64_t atoi64(const char *buf) { int64_t r=0; - sscanf(buf,"%"I64d,&r); + sscanf(buf,"%" I64d,&r); return r; } diff -Nru afflib-3.7.7/tools/affcopy.cpp afflib-3.7.16/tools/affcopy.cpp --- afflib-3.7.7/tools/affcopy.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affcopy.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -39,10 +39,6 @@ #include #endif -#ifdef HAVE_TERM_H -#include -#endif - #ifdef WIN32 #include "unix4win32.h" #endif @@ -371,7 +367,7 @@ uint32_t arg=0; if(af_get_seg(ain,segname,&arg,segbuf,&seglen)){ unlink_outfiles(outfiles); // failure; unlink the output files - err(1,"Cannot read segment '%s' in %s. Deleteing output file", segname,af_filename(ain)); + err(1,"Cannot read segment '%s' in %s. Deleting output file", segname,af_filename(ain)); } /* Calculate the MD5 of this segment and remember it in the map */ @@ -469,7 +465,7 @@ AFFILE *af = afouts.begin()->af; uint64_t w = af->bytes_written; double sec = ((t1.tv_sec-t0.tv_sec)+(t1.tv_usec-t0.tv_usec)/1000000.0); - printf("%s: %"I64d" bytes transferred in %.2f seconds. xfer rate: %.2f MBytes/sec\n", + printf("%s: %" I64d " bytes transferred in %.2f seconds. xfer rate: %.2f MBytes/sec\n", af_filename(af),w,sec,(w/1000000.0) / sec); } diff -Nru afflib-3.7.7/tools/affdiskprint.cpp afflib-3.7.16/tools/affdiskprint.cpp --- afflib-3.7.7/tools/affdiskprint.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affdiskprint.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -97,7 +97,7 @@ uint64_t atoi64(const char *buf) { uint64_t ret=0; - sscanf(buf,"%"PRIu64,&ret); + sscanf(buf,"%" PRIu64,&ret); return ret; } @@ -201,7 +201,7 @@ int64_t imagesize = af_get_imagesize(af); if(imagesize>0){ char buf[32]; - snprintf(buf,sizeof(buf),"%"PRIu64,imagesize); + snprintf(buf,sizeof(buf),"%" PRIu64,imagesize); out_xmlstr(cout,2,AF_IMAGESIZE,buf); cout << "\n"; } @@ -212,7 +212,7 @@ int64_t sectors = imagesize/sectorsize; if(sectors>0){ char buf[32]; - snprintf(buf,sizeof(buf),"%"PRIu32"",sectorsize); + snprintf(buf,sizeof(buf),"%" PRIu32,sectorsize); out_xmlstr(cout,2,AF_SECTORSIZE,buf); cout << "\n"; } diff -Nru afflib-3.7.7/tools/affinfo.cpp afflib-3.7.16/tools/affinfo.cpp --- afflib-3.7.7/tools/affinfo.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affinfo.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -33,14 +33,6 @@ using namespace std; -#ifdef HAVE_CURSES_H -#include -#endif - -#ifdef HAVE_TERM_H -#include -#endif - #ifdef WIN32 #include "unix4win32.h" #endif @@ -79,46 +71,6 @@ vector opt_seglist; // just info these segments bool something_was_decrypted = false; -const char *term = 0; - - -/** - * select bold on or off - */ -void bold(int on) -{ - if(!term) return; -#ifdef HAVE_ISATTY - if(!isatty(fileno(stdout))) return; -#endif -#if defined(HAVE_TPUTS) && defined(HAVE_CURSES_H) && defined(HAVE_TERM_H) - if(on) tputs(enter_bold_mode,1,putchar); - else tputs(exit_attribute_mode,0,putchar); -#endif -} - -/** - * select a color. - * @param num - 0 is black; 1 red; 2 green; 3 yellow; 4 blue; 5 magenta; 6 cyan; 7 white; - */ - -#define RED 1 -#define WHITE 7 - -void color(int num) -{ -#ifdef HAVE_ISATTY - if(!isatty(fileno(stdout))) return; -#endif -#if defined(HAVE_TIGETSTR) && defined(HAVE_PUTP) && defined(HAVE_TPARM) - char *setf = tigetstr((char *)"setf"); - if(!setf) setf = tigetstr((char *)"setaf"); - if(setf){ - putp(tparm(setf,num)); - } -#endif -} - void usage() { @@ -164,12 +116,6 @@ #endif printf("\n"); - if(opt_debug){ - for(int i=0;i<9;i++){ - color(i);printf("Color %d\n",i);color(7); - } - } - exit(0); } @@ -179,7 +125,7 @@ void sig_info(int arg) { if(af==0) return; - printf("Validating %"I64d" of %"I64d"\n", af->pos,af->image_size); + printf("Validating %" I64d" of %" I64d"\n", af->pos,af->image_size); } @@ -408,7 +354,6 @@ af_set_option(af,AF_OPTION_AUTO_DECRYPT,prev); if(was_decrypted){ - bold(1); something_was_decrypted = true; // print key at bottom } @@ -417,7 +362,7 @@ memset(output_line,0,sizeof(output_line)); /* Now append the arg and the data len */ - sprintf(output_line,"%-24s %8"PRIu32" %8d ",segname,arg,(int)data_len); + sprintf(output_line,"%-24s %8" PRIu32 " %8d ",segname,arg,(int)data_len); if(opt_no_preview){ printf("%s\n",output_line); @@ -447,7 +392,7 @@ */ switch(data_len){ case 8: - printf("%s= %"I64d" (64-bit value)\n", + printf("%s= %" I64d" (64-bit value)\n", output_line,af_decode_q(data)); break; case 0: @@ -552,9 +497,6 @@ putchar('\n'); done: if(data) free(data); - bold(0); // make sure bold is off - - //color(WHITE); // make sure we are back to normal color } @@ -666,29 +608,27 @@ /* Print the key */ if(something_was_decrypted){ - bold(1); - printf("Bold indicates segments that were decrypted.\n"); - bold(0); + printf("Some segments were decrypted.\n"); } printf("\n"); - printf("Total segments: %8"PRIu32" (%"PRIu32" real)\n", total_segs,(total_segs-total_nulls)); + printf("Total segments: %8" PRIu32 " (%" PRIu32" real)\n", total_segs,(total_segs-total_nulls)); if(aes_segs){ printf(" Encrypted segments: %8u\n",aes_segs); } - printf(" Page segments: %8"PRIu32"\n",total_pages); - printf(" Hash segments: %8"PRIu32"\n",total_hashes); - printf(" Signature segments: %8"PRIu32"\n",total_signatures); - printf(" Null segments: %8"PRIu32"\n",total_nulls); + printf(" Page segments: %8" PRIu32 "\n",total_pages); + printf(" Hash segments: %8" PRIu32 "\n",total_hashes); + printf(" Signature segments: %8" PRIu32 "\n",total_signatures); + printf(" Null segments: %8" PRIu32 "\n",total_nulls); if(opt_all){ - printf(" Empty segments: %8"PRIu32"\n",total_nulls); + printf(" Empty segments: %8" PRIu32 "\n",total_nulls); printf("\n"); - printf("Total data bytes in segments: %"I64d"\n",total_datalen); + printf("Total data bytes in segments: %" I64d"\n",total_datalen); printf("Total space in file dedicated to segment names: %zd\n", total_segname_len); - printf("Total overhead for %"PRIu32" segments: %zd bytes (%"PRIu32"*(%zd+%zd))\n", + printf("Total overhead for %" PRIu32 " segments: %zd bytes (%" PRIu32 "*(%zd+%zd))\n", total_segs, (size_t) total_segs*(sizeof(struct af_segment_head) +sizeof(struct af_segment_tail)), total_segs, @@ -720,7 +660,7 @@ //printf("device_bytes=%"I64d"\n",device_bytes); //printf("device_pages=%"I64d"\n",device_pages); if(missing_pages!=0){ - printf("Missing page segments: %8"I64u"\n",missing_pages); + printf("Missing page segments: %8" I64u"\n",missing_pages); } else { some_missing_pages=0; @@ -735,7 +675,7 @@ if(some_missing_pages && opt_debug){ printf("Cannot calculate missing pages\n"); - printf(" device_sectors=%"I64d" image_pagesize=%"PRIu32" sectorsize=%"PRIu32"\n", + printf(" device_sectors=%" I64d" image_pagesize=%" PRIu32 " sectorsize=%" PRIu32 "\n", device_sectors,af->image_pagesize,af->image_sectorsize); } af_close(af); @@ -756,8 +696,8 @@ printf("\n"); printf("\n",fn); printf(" %d\n",afb.sector_size); - printf(" %"PRId64"\n",afb.total_sectors); - printf(" %"PRIu64"\n",afb.max_read_blocks); + printf(" %" PRId64 "\n",afb.total_sectors); + printf(" %" PRIu64 "\n",afb.max_read_blocks); printf("\n"); close(fd); } diff -Nru afflib-3.7.7/tools/affix.cpp afflib-3.7.16/tools/affix.cpp --- afflib-3.7.7/tools/affix.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affix.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -24,10 +24,6 @@ #include #endif -#ifdef HAVE_TERM_H -#include -#endif - #ifdef WIN32 #include "unix4win32.h" #include @@ -93,7 +89,7 @@ r = (*af->v->open)(af); /* See if we can build a TOC */ if(r<0){ - printf("AFF file corrupt at %"I64d" out of %"I64d" (%"I64d" bytes from end)\n", + printf("AFF file corrupt at %" I64d " out of %" I64d " (%" I64d " bytes from end)\n", ftello(af->aseg),(int64_t)len,len-ftello(af->aseg)); if(opt_fix){ printf("Truncating... %d \n",fileno(af->aseg)); @@ -173,7 +169,7 @@ if(fix_add_gid) { printf(" ... adding GID ",infile); unsigned char bit128[16]; - RAND_pseudo_bytes(bit128,sizeof(bit128)); + RAND_bytes(bit128,sizeof(bit128)); if(af_update_seg(af,AF_IMAGE_GID,0,bit128,sizeof(bit128))){ warn("Cannot write %s: ",AF_IMAGE_GID); } diff -Nru afflib-3.7.7/tools/affrecover.cpp afflib-3.7.16/tools/affrecover.cpp --- afflib-3.7.7/tools/affrecover.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affrecover.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -23,10 +23,6 @@ #include #endif -#ifdef HAVE_TERM_H -#include -#endif - #ifdef WIN32 #include "unix4win32.h" #include diff -Nru afflib-3.7.7/tools/affsegment.cpp afflib-3.7.16/tools/affsegment.cpp --- afflib-3.7.7/tools/affsegment.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affsegment.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -230,19 +230,19 @@ free(buf); continue; } - if(opt_debug) fprintf(stderr," arg=%"PRIu32" len=%zd\n",arg,len); + if(opt_debug) fprintf(stderr," arg=%" PRIu32 " len=%zd\n",arg,len); int p = 1; if(filecount>1) printf("%s:",fn); if(print_segs.size()>1) printf("%s=",segname); if(opt_quad && len==8){ uint64_t quad = af_decode_q(buf); - printf("%"I64u"\n",quad); + printf("%" I64u "\n",quad); p = 0; } if(opt_arg){ - printf("%"PRIu32"\n",arg); + printf("%" PRIu32 "\n",arg); p = 0; } diff -Nru afflib-3.7.7/tools/affsign.cpp afflib-3.7.16/tools/affsign.cpp --- afflib-3.7.7/tools/affsign.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affsign.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -183,7 +183,7 @@ /* Now get the raw source segment */ uint32_t arg=0; if(af_get_seg(af,segname,&arg,segbuf,&seglen)){ - err(1,"Cannot read segment '%s' in %s. Deleteing output file", segname,af_filename(af)); + err(1,"Cannot read segment '%s' in %s. Deleting output file", segname,af_filename(af)); } aff_bom::make_hash(seghash,arg,segname,segbuf,seglen); sigmode = AF_SIGNATURE_MODE0; diff -Nru afflib-3.7.7/tools/affstats.cpp afflib-3.7.16/tools/affstats.cpp --- afflib-3.7.7/tools/affstats.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affstats.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -65,10 +65,6 @@ #include #endif -#ifdef HAVE_TERM_H -#include -#endif - #ifdef WIN32 #include "unix4win32.h" #include @@ -98,7 +94,7 @@ printf("%u",(unsigned int)(s/(1024*1024))); return; } - printf("%"I64u,s); + printf("%" I64u,s); } void affstats_title() @@ -150,7 +146,7 @@ print_size(compressed_bytes); printf("\t"); print_size(uncompressed_bytes); - printf(" %"I64d" %"I64d,blanksectors,badsectors); + printf(" %" I64d " %" I64d,blanksectors,badsectors); putchar('\n'); diff -Nru afflib-3.7.7/tools/affverify.cpp afflib-3.7.16/tools/affverify.cpp --- afflib-3.7.7/tools/affverify.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affverify.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -27,6 +27,12 @@ #include #include +/* Support OpenSSL before 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define EVP_MD_CTX_new EVP_MD_CTX_create +#define EVP_MD_CTX_free EVP_MD_CTX_destroy +#endif + using namespace std; using namespace aff; @@ -248,10 +254,11 @@ } /* Try to verify it */ - EVP_MD_CTX md; - EVP_VerifyInit(&md,sha256); - EVP_VerifyUpdate(&md,buf,sig_start-buf); - int r = EVP_VerifyFinal(&md,sigbuf,sigbuf_len,X509_get_pubkey(cert)); + EVP_MD_CTX *md = EVP_MD_CTX_new(); + EVP_VerifyInit(md,sha256); + EVP_VerifyUpdate(md,buf,sig_start-buf); + int r = EVP_VerifyFinal(md,sigbuf,sigbuf_len,X509_get_pubkey(cert)); + EVP_MD_CTX_free(md); if(r!=1){ printf("BAD SIGNATURE ON BOM\n"); return -1; @@ -430,16 +437,17 @@ size_t md5_len =sizeof(md5_buf); const EVP_MD *md5_evp = 0; const EVP_MD *sha1_evp = 0; - EVP_MD_CTX md5,sha1; + EVP_MD_CTX *md5 = EVP_MD_CTX_new(); + EVP_MD_CTX *sha1 = EVP_MD_CTX_new(); if(af_get_seg(af,AF_SHA1,0,sha1_buf,&sha1_len)==0){ printf("SHA1 stored in file: %s\n",af_hexbuf(hexbuf,sizeof(hexbuf),sha1_buf,sha1_len,0)); sha1_evp = EVP_get_digestbyname("sha1"); - EVP_DigestInit(&sha1,sha1_evp); + EVP_DigestInit(sha1,sha1_evp); } if(af_get_seg(af,AF_MD5,0,md5_buf,&md5_len)==0){ printf("MD5 stored in file: %s\n",af_hexbuf(hexbuf,sizeof(hexbuf),md5_buf,md5_len,0)); md5_evp = EVP_get_digestbyname("md5"); - EVP_DigestInit(&md5,md5_evp); + EVP_DigestInit(md5,md5_evp); } /* Might as well read this puppy */ u_char *buf = (u_char *)malloc(af_get_pagesize(af)); @@ -451,14 +459,14 @@ printf("\n"); do { double frac = (double)total_read / af_get_imagesize(af); - printf(" Read %14zd/%14"PRId64" bytes; done in %s\n", + printf(" Read %14zd/%14" PRId64" bytes; done in %s\n", total_read, af_get_imagesize(af), t.eta_text(frac).c_str()); readsize = af_read(af,buf,af_get_pagesize(af)); if(readsize<1) break; - if(md5_evp) EVP_DigestUpdate(&md5,buf,readsize); - if(sha1_evp) EVP_DigestUpdate(&sha1,buf,readsize); + if(md5_evp) EVP_DigestUpdate(md5,buf,readsize); + if(sha1_evp) EVP_DigestUpdate(sha1,buf,readsize); total_read += readsize; } while(total_read < af_get_imagesize(af)); @@ -468,7 +476,7 @@ unsigned char sha1_calc[32]; unsigned int sha1_calc_len = sizeof(sha1_calc); - EVP_DigestFinal(&sha1,sha1_calc,(unsigned int *)&sha1_calc_len); + EVP_DigestFinal(sha1,sha1_calc,(unsigned int *)&sha1_calc_len); printf("Calculated SHA1: %s ",af_hexbuf(hexbuf,sizeof(hexbuf),sha1_calc,sha1_calc_len,0)); if(memcmp(sha1_buf,sha1_calc,sha1_len)==0){ printf("VERIFIES\n"); @@ -481,7 +489,7 @@ unsigned char md5_calc[32]; unsigned int md5_calc_len = sizeof(md5_calc); - EVP_DigestFinal(&md5,md5_calc,(unsigned int *)&md5_calc_len); + EVP_DigestFinal(md5,md5_calc,(unsigned int *)&md5_calc_len); printf("Calculated MD5: %s ",af_hexbuf(hexbuf,sizeof(hexbuf),md5_calc,md5_calc_len,0)); if(memcmp(md5_buf,md5_calc,md5_len)==0){ printf("VERIFIES\n"); @@ -490,6 +498,8 @@ } } + EVP_MD_CTX_free(md5); + EVP_MD_CTX_free(sha1); af_close(af); return 0; } diff -Nru afflib-3.7.7/tools/affxml.cpp afflib-3.7.16/tools/affxml.cpp --- afflib-3.7.7/tools/affxml.cpp 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/affxml.cpp 2017-06-24 00:57:09.000000000 +0000 @@ -135,7 +135,7 @@ void print_xml64(const char *name,int64_t val) { - printf(" <%s coding='base10'>%"I64d"\n\n",name,val,name); + printf(" <%s coding='base10'>%" I64d"\n\n",name,val,name); } int xml_info(const char *infile) @@ -191,7 +191,7 @@ size_t pagesize = af_page_size(af); size_t sectorsize = af_get_sectorsize(af); if(af_get_page(af,*it,data,&pagesize)){ - err(1,"Can't read page %"PRId64,*it); + err(1,"Can't read page %" PRId64,*it); } psb.pages++; bool allblank = true; @@ -250,14 +250,14 @@ * The strcmp is there because early AF_IMAGESIZE segs didn't set * AF_SEG_QUADWORD... */ - printf(" <%s coding='base10'>%"I64d"\n",segname,af_decode_q(data),segname); + printf(" <%s coding='base10'>%" I64d"\n",segname,af_decode_q(data),segname); free(data); continue; } /* If datalen==0, just print the arg as an unsigned number */ if(datalen==0){ - printf(" <%s coding='base10'>%"PRIu32"\n",segname,arg,segname); + printf(" <%s coding='base10'>%" PRIu32 "\n",segname,arg,segname); free(data); continue; } @@ -265,7 +265,7 @@ /* Just handle it as binhex ... */ printf(" <%s",segname); if(datalen==0){ - printf(" arg='%"PRIu32"' />\n",arg); + printf(" arg='%" PRIu32 "' />\n",arg); free(data); continue; } diff -Nru afflib-3.7.7/tools/hashextent.h afflib-3.7.16/tools/hashextent.h --- afflib-3.7.7/tools/hashextent.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/hashextent.h 2017-06-24 00:57:09.000000000 +0000 @@ -18,6 +18,11 @@ #include #include +/* Support OpenSSL before 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define EVP_MD_CTX_new EVP_MD_CTX_create +#define EVP_MD_CTX_free EVP_MD_CTX_destroy +#endif using std::string; using std::ostream; @@ -95,25 +100,29 @@ */ int compute_digest(AFFILE *af,string digestToUse){ const EVP_MD *md = EVP_get_digestbyname(digestToUse.c_str()); - EVP_MD_CTX ctx; if(!md) return -1; // digest not available - EVP_DigestInit(&ctx,md); if(af_seek(af,start,0)!=start) return -1; // can't seek + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx,md); uint64_t bytes_read = 0; while(bytes_read < this->bytes){ u_char buf[65536]; int to_read = (this->bytes-bytes_read) < sizeof(buf) ? (this->bytes-bytes_read) : sizeof(buf); - if(af_read(af,buf,to_read)!=to_read) return -1; // error reading + if(af_read(af,buf,to_read)!=to_read){ + EVP_MD_CTX_free(ctx); + return -1; // error reading + } /* compute the hash */ - EVP_DigestUpdate(&ctx,buf,to_read); + EVP_DigestUpdate(ctx,buf,to_read); bytes_read += to_read; } /* Compute the results */ if(digest!=0) free(digest); u_int digest_bytes = 1024; digest = (u_char *)malloc(digest_bytes); // big enough for any conceivable digest - EVP_DigestFinal(&ctx,digest,&digest_bytes); + EVP_DigestFinal(ctx,digest,&digest_bytes); + EVP_MD_CTX_free(ctx); digest_bits_ = digest_bytes*8; digest_name = digestToUse; hexdigest = bin2hex(digest,digest_bits_/8); diff -Nru afflib-3.7.7/tools/Makefile.am afflib-3.7.16/tools/Makefile.am --- afflib-3.7.7/tools/Makefile.am 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/tools/Makefile.am 2017-06-24 00:57:09.000000000 +0000 @@ -26,7 +26,7 @@ affverify_SOURCES = affverify.cpp aff_bom.h aff_bom.cpp affxml_SOURCES = affxml.cpp unix4win32.h -AM_CPPFLAGS = -I@top_srcdir@/lib/ +AM_CPPFLAGS = -I@top_srcdir@/lib -I@top_srcdir@/include/afflib LDADD = @top_builddir@/lib/libafflib.la affuse_CFLAGS = @FUSE_CFLAGS@ diff -Nru afflib-3.7.7/win32/affconfig.h afflib-3.7.16/win32/affconfig.h --- afflib-3.7.7/win32/affconfig.h 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/win32/affconfig.h 2017-06-24 00:57:09.000000000 +0000 @@ -1,6 +1,6 @@ #include -#define PACKAGE_VERSION "3.7.7" +#define PACKAGE_VERSION "3.7.16" #undef USE_LIBEWF #undef USE_QEMU diff -Nru afflib-3.7.7/win32/afflib.mak afflib-3.7.16/win32/afflib.mak --- afflib-3.7.7/win32/afflib.mak 2015-10-01 22:55:01.000000000 +0000 +++ afflib-3.7.16/win32/afflib.mak 2017-06-24 00:57:09.000000000 +0000 @@ -25,7 +25,7 @@ INCS = /I.\ /Izlib-1.2.3\ \ - /I..\lib \ + /I..\include\afflib \ /I..\lzma443\C \ /I..\lzma443\C\7zip\Compress\LZMA_Alone \ /I$(EXPATDIR) \ @@ -38,7 +38,7 @@ # removed: /Gm - enable minimal rebuild; generated internal compiler error -OTHER_FLAGS = /c /nologo /EHsc /RTC1 /RTCs /W2 $(COMPILER_MODE) +OTHER_FLAGS = /c /nologo /EHsc /W2 $(COMPILER_MODE) CPPFLAGS=$(INCS) $(DEFS) $(OTHER_FLAGS) /Fp"afflib.pch" /Fo$*.obj CFLAGS=$(INCS) $(DEFS) $(OTHER_FLAGS) /Fp"afflib.pch" /Fo$*.obj