Import tivodecode-0.3pre4

This commit is contained in:
Stefan Bethke 2010-08-07 09:22:49 +00:00
parent b3a9fb173a
commit f004138cb1
59 changed files with 19740 additions and 0 deletions

View file

View file

@ -0,0 +1,85 @@
Copyright (c) 2006, Jeremy Drake
All rights reserved.
Portions derived from mpegcat, copyright 2006 Kees Cook, used with permission
This product includes software developed by the University of California,
Berkeley and its contributors.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
* Neither the name of the software nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER 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.
This software incorporates the Turing encryption algorithm developed by
QUALCOMM Incorporated. Encryption by QUALCOMM.
1. Copyright remains vested in QUALCOMM Incorporated, and Copyright
notices in the code are not to be removed. If this package is used in
a product, QUALCOMM should be given attribution as the author of the
Turing encryption algorithm. This can be in the form of a textual
message at program startup or in documentation (online or textual)
provided with the package.
2. Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
a. Redistributions of source code must retain the copyright notice,
this list of conditions and the following disclaimer.
b. 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.
c. All advertising materials mentioning features or use of this
software must display the following acknowledgement: This product
includes software developed by QUALCOMM Incorporated.
3. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND AGAINST
INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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.
4. The license and distribution terms for any publically available version
or derivative of this code cannot be changed, that is, this code cannot
simply be copied and put under another distribution license including
the GNU Public License.
5. The Turing family of encryption algorithms are covered by patents in
the United States of America and other countries. A free and
irrevocable license is hereby granted for the use of such patents to
the extent required to utilize the Turing family of encryption
algorithms for any purpose, subject to the condition that any
commercial product utilising any of the Turing family of encryption
algorithms should show the words "Encryption by QUALCOMM" either on the
product or in the associated documentation.

View file

@ -0,0 +1,100 @@
0.3pre1:
* add support for TS files.
* known bug :
Packet N of PID XX starts a new series of PES headers, which spill over into
packet N+1 of PID XX, which has an encrypted payload. The problem is how to
cleanly make that "continuation" from packet N to N+1, such that the offset
into Packet N+1 can be determined where the decrypt needs to start.
0.2pre3:
* add an option to not process video - handy if all you want is to
dump the metadata
* fix error in logic rework to get prepare_frame to take stream_id and
block_id of 0, caused improper decryption of mpeg data
* add string.h include to md5 to make it work on solaris (seems
memmove comes from there), remove sys/param.h since I don't know why
it was there and don't know its portability
* add support to decrypt metadata and dump out to files. Needs some
work to make it easier to use
* add md5 routines from postgresql's pgcrypto contrib module, slightly
hacked so that it does not require a 64-bit integer type, which should
not be an issue for my uses. md5 is needed to generate the decryption
keys for the metadata
* fix turing_stream to work with stream_id of 0
(needed for work on metadata decrypting)
* refactor tivo file parsing to expose access to the rest of the data
in the headers and other data chunks
0.2pre2:
* fix merge error - some includes were in the wrong place, resulting
in broken builds due to missing defines from tdconfig.h
0.2pre1:
* port upstream changes from postgresql's getopt* files, which remove
the advertising clause from the license on the file
* add headers to Makefile.am for installation, clean up headers that
will be installed so that one just includes tivodecoder.h, clean up
tivodecoder.c so that it does not call exit() since it is called
from a lib and the caller may not want to exit, instead return -2
* copy changes to getopt_long.h from t2sami: don't declare extern vars
for getopt if using the system's getopt - rely on it taking care of
that. Caused issue for t2sami on cygwin, tivodecode worked fine,
but may as well fix it here too
* openbsd compile fixes - ntohl requires sys/types.h
* redo define for ftello/fseeko to be more robust, add warning if
falling back to ftell/fseek for questionable large file support
* clean up types to prevent warnings on windows. fix up large
file support for windows
* build a library capable of being called by something other than
the command line tivodecode program
* rewrite handling of encrypted packets to not have a hardcoded set of
stream_ids, but to keep track of an arbitrary number of states in a
circular linked list. There should never be more than 2 or 3 of
them, AFAIK, so this should be acceptable performance-wise
0.1.4:
* add support for storing MAK in a config file, ~/.tivodecode_mak, or
if HOME (or USERPROFILE on Windows) is not set, /.tivodecode_mak
(C:/.tivodecode_mak on Windows)
* tweak largefile support to be more correct for seek and tell, per
report in forum. This should not affect anyone, as in order for pipe
support to work I could not seek anyway.
0.1.3:
* implement support for encrypted packet type 0xbd, apparently used
for AC3 audio for 'Humax DVD-burning TiVos'
0.1.2:
* fix bug introduced recently while fixing signedness warnings on
gcc-4.1. Thanks to tateu for the fix
0.1.1:
* change include file for htonl after compile farm failure on Mac OSX
0.1.0:
* apply mak verification patch from Kees Cook
<kees@outflux.net>, fix signedness warnings in gcc 4.1, add
permission statement from Kees Cook to file derived from mpegcat

View file

@ -0,0 +1,234 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

View file

@ -0,0 +1,12 @@
bin_PROGRAMS = tivodecode tdcat
lib_LIBRARIES = libtivodecode.a
pkginclude_HEADERS = tivodecoder.h tivo-parse.h turing_stream.h Turing.h
nodist_pkginclude_HEADERS = tdconfig.h
libtivodecode_a_SOURCES=hexlib.c TuringFast.c sha1.c md5.c tivo-parse.c turing_stream.c tivodecoder.c QUTsbox.h TuringMultab.h TuringSbox.h hexlib.h sha1.h md5.h
tivodecode_SOURCES=cli_common.c happyfile.c tivodecode.c happyfile.h getopt_long.h fseeko.h cli_common.h
tivodecode_LDADD=$(LIBOBJS) -L. -ltivodecode
tivodecode_DEPENDENCIES=$(LIBOBJS) libtivodecode.a
tdcat_SOURCES=cli_common.c happyfile.c tdcat.c happyfile.h getopt_long.h fseeko.h cli_common.h
tdcat_LDADD=$(LIBOBJS) -L. -ltivodecode
tdcat_DEPENDENCIES=$(LIBOBJS) libtivodecode.a
EXTRA_DIST=libtivodecode.vcproj libtdcommon.vcproj tdcat.vcproj tdconfig.h.win32 tivodecode.rules tivodecode.sln tivodecode.vcproj

View file

@ -0,0 +1,679 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
bin_PROGRAMS = tivodecode$(EXEEXT) tdcat$(EXEEXT)
subdir = .
DIST_COMMON = README $(am__configure_deps) $(pkginclude_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/tdconfig.h.in $(top_srcdir)/configure AUTHORS \
COPYING ChangeLog INSTALL NEWS depcomp fseeko.c getopt.c \
getopt_long.c install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/c-compiler.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = tdconfig.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(pkgincludedir)" "$(DESTDIR)$(pkgincludedir)"
libLIBRARIES_INSTALL = $(INSTALL_DATA)
LIBRARIES = $(lib_LIBRARIES)
AR = ar
ARFLAGS = cru
libtivodecode_a_AR = $(AR) $(ARFLAGS)
libtivodecode_a_LIBADD =
am_libtivodecode_a_OBJECTS = hexlib.$(OBJEXT) TuringFast.$(OBJEXT) \
sha1.$(OBJEXT) md5.$(OBJEXT) tivo-parse.$(OBJEXT) \
turing_stream.$(OBJEXT) tivodecoder.$(OBJEXT)
libtivodecode_a_OBJECTS = $(am_libtivodecode_a_OBJECTS)
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_tdcat_OBJECTS = cli_common.$(OBJEXT) happyfile.$(OBJEXT) \
tdcat.$(OBJEXT)
tdcat_OBJECTS = $(am_tdcat_OBJECTS)
am_tivodecode_OBJECTS = cli_common.$(OBJEXT) happyfile.$(OBJEXT) \
tivodecode.$(OBJEXT)
tivodecode_OBJECTS = $(am_tivodecode_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libtivodecode_a_SOURCES) $(tdcat_SOURCES) \
$(tivodecode_SOURCES)
DIST_SOURCES = $(libtivodecode_a_SOURCES) $(tdcat_SOURCES) \
$(tivodecode_SOURCES)
nodist_pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER)
pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(nodist_pkginclude_HEADERS) $(pkginclude_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
{ test ! -d $(distdir) \
|| { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
&& rm -fr $(distdir); }; }
DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build_alias = @build_alias@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
lib_LIBRARIES = libtivodecode.a
pkginclude_HEADERS = tivodecoder.h tivo-parse.h turing_stream.h Turing.h
nodist_pkginclude_HEADERS = tdconfig.h
libtivodecode_a_SOURCES = hexlib.c TuringFast.c sha1.c md5.c tivo-parse.c turing_stream.c tivodecoder.c QUTsbox.h TuringMultab.h TuringSbox.h hexlib.h sha1.h md5.h
tivodecode_SOURCES = cli_common.c happyfile.c tivodecode.c happyfile.h getopt_long.h fseeko.h cli_common.h
tivodecode_LDADD = $(LIBOBJS) -L. -ltivodecode
tivodecode_DEPENDENCIES = $(LIBOBJS) libtivodecode.a
tdcat_SOURCES = cli_common.c happyfile.c tdcat.c happyfile.h getopt_long.h fseeko.h cli_common.h
tdcat_LDADD = $(LIBOBJS) -L. -ltivodecode
tdcat_DEPENDENCIES = $(LIBOBJS) libtivodecode.a
EXTRA_DIST = libtivodecode.vcproj libtdcommon.vcproj tdcat.vcproj tdconfig.h.win32 tivodecode.rules tivodecode.sln tivodecode.vcproj
all: tdconfig.h
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
am--refresh:
@:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
echo ' cd $(srcdir) && $(AUTOMAKE) --gnu '; \
cd $(srcdir) && $(AUTOMAKE) --gnu \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
echo ' $(SHELL) ./config.status'; \
$(SHELL) ./config.status;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) ./config.status --recheck
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(srcdir) && $(AUTOCONF)
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
tdconfig.h: stamp-h1
@if test ! -f $@; then \
rm -f stamp-h1; \
$(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
else :; fi
stamp-h1: $(srcdir)/tdconfig.h.in $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status tdconfig.h
$(srcdir)/tdconfig.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_srcdir) && $(AUTOHEADER)
rm -f stamp-h1
touch $@
distclean-hdr:
-rm -f tdconfig.h stamp-h1
install-libLIBRARIES: $(lib_LIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
@list='$(lib_LIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(libLIBRARIES_INSTALL) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(libLIBRARIES_INSTALL) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
@$(POST_INSTALL)
@list='$(lib_LIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
p=$(am__strip_dir) \
echo " $(RANLIB) '$(DESTDIR)$(libdir)/$$p'"; \
$(RANLIB) "$(DESTDIR)$(libdir)/$$p"; \
else :; fi; \
done
uninstall-libLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(libdir)/$$p'"; \
rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLIBRARIES:
-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
libtivodecode.a: $(libtivodecode_a_OBJECTS) $(libtivodecode_a_DEPENDENCIES)
-rm -f libtivodecode.a
$(libtivodecode_a_AR) libtivodecode.a $(libtivodecode_a_OBJECTS) $(libtivodecode_a_LIBADD)
$(RANLIB) libtivodecode.a
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
tdcat$(EXEEXT): $(tdcat_OBJECTS) $(tdcat_DEPENDENCIES)
@rm -f tdcat$(EXEEXT)
$(LINK) $(tdcat_OBJECTS) $(tdcat_LDADD) $(LIBS)
tivodecode$(EXEEXT): $(tivodecode_OBJECTS) $(tivodecode_DEPENDENCIES)
@rm -f tivodecode$(EXEEXT)
$(LINK) $(tivodecode_OBJECTS) $(tivodecode_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/fseeko.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TuringFast.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cli_common.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/happyfile.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hexlib.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tdcat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tivo-parse.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tivodecode.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tivodecoder.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/turing_stream.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
install-nodist_pkgincludeHEADERS: $(nodist_pkginclude_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
@list='$(nodist_pkginclude_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(nodist_pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \
$(nodist_pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \
done
uninstall-nodist_pkgincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(nodist_pkginclude_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \
rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \
done
install-pkgincludeHEADERS: $(pkginclude_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
@list='$(pkginclude_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \
$(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \
done
uninstall-pkgincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(pkginclude_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \
rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) tdconfig.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) tdconfig.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) tdconfig.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) tdconfig.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(am__remove_distdir)
test -d $(distdir) || mkdir $(distdir)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r $(distdir)
dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
dist-bzip2: distdir
tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
$(am__remove_distdir)
dist-tarZ: distdir
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__remove_distdir)
dist-shar: distdir
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__remove_distdir)
dist-zip: distdir
-rm -f $(distdir).zip
zip -rq $(distdir).zip $(distdir)
$(am__remove_distdir)
dist dist-all: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
distcheck: dist
case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
*.zip*) \
unzip $(distdir).zip ;;\
esac
chmod -R a-w $(distdir); chmod a+w $(distdir)
mkdir $(distdir)/_build
mkdir $(distdir)/_inst
chmod a-w $(distdir)
dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& cd $(distdir)/_build \
&& ../configure --srcdir=.. --prefix="$$dc_install_base" \
$(DISTCHECK_CONFIGURE_FLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
distuninstallcheck \
&& chmod -R a-w "$$dc_install_base" \
&& ({ \
(cd ../.. && umask 077 && mkdir "$$dc_destdir") \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
} || { rm -rf "$$dc_destdir"; exit 1; }) \
&& rm -rf "$$dc_destdir" \
&& $(MAKE) $(AM_MAKEFLAGS) dist \
&& rm -rf $(DIST_ARCHIVES) \
&& $(MAKE) $(AM_MAKEFLAGS) distcleancheck
$(am__remove_distdir)
@(echo "$(distdir) archives ready for distribution: "; \
list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
distuninstallcheck:
@cd $(distuninstallcheck_dir) \
&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
|| { echo "ERROR: files left after uninstall:" ; \
if test -n "$(DESTDIR)"; then \
echo " (check DESTDIR support)"; \
fi ; \
$(distuninstallcheck_listfiles) ; \
exit 1; } >&2
distcleancheck: distclean
@if test '$(srcdir)' = . ; then \
echo "ERROR: distcleancheck can only run from a VPATH build" ; \
exit 1 ; \
fi
@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
|| { echo "ERROR: files left in build directory after distclean:" ; \
$(distcleancheck_listfiles) ; \
exit 1; } >&2
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(HEADERS) tdconfig.h
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgincludedir)" "$(DESTDIR)$(pkgincludedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libLIBRARIES \
mostlyclean-am
distclean: distclean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(DEPDIR) ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-nodist_pkgincludeHEADERS \
install-pkgincludeHEADERS
install-dvi: install-dvi-am
install-exec-am: install-binPROGRAMS install-libLIBRARIES
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
-rm -rf $(DEPDIR) ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-libLIBRARIES \
uninstall-nodist_pkgincludeHEADERS uninstall-pkgincludeHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am am--refresh check check-am clean \
clean-binPROGRAMS clean-generic clean-libLIBRARIES ctags dist \
dist-all dist-bzip2 dist-gzip dist-shar dist-tarZ dist-zip \
distcheck distclean distclean-compile distclean-generic \
distclean-hdr distclean-tags distcleancheck distdir \
distuninstallcheck dvi dvi-am html html-am info info-am \
install install-am install-binPROGRAMS install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-libLIBRARIES install-man \
install-nodist_pkgincludeHEADERS install-pdf install-pdf-am \
install-pkgincludeHEADERS install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS \
uninstall-libLIBRARIES uninstall-nodist_pkgincludeHEADERS \
uninstall-pkgincludeHEADERS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View file

View file

@ -0,0 +1,74 @@
/* %W% (QUALCOMM) %E% */
/*
* 8->32 Sbox generated by Millan et. al. at Queensland University of
* Technology. See: E. Dawson, W. Millan, L. Burnett, G. Carter,
* "On the Design of 8*32 S-boxes". Unpublished report, by the
* Information Systems Research Centre,
* Queensland University of Technology, 1999.
*/
WORD Qbox[256] = {
0x1faa1887, 0x4e5e435c, 0x9165c042, 0x250e6ef4,
0x5957ee20, 0xd484fed3, 0xa666c502, 0x7e54e8ae,
0xd12ee9d9, 0xfc1f38d4, 0x49829b5d, 0x1b5cdf3c,
0x74864249, 0xda2e3963, 0x28f4429f, 0xc8432c35,
0x4af40325, 0x9fc0dd70, 0xd8973ded, 0x1a02dc5e,
0xcd175b42, 0xf10012bf, 0x6694d78c, 0xacaab26b,
0x4ec11b9a, 0x3f168146, 0xc0ea8ec5, 0xb38ac28f,
0x1fed5c0f, 0xaab4101c, 0xea2db082, 0x470929e1,
0xe71843de, 0x508299fc, 0xe72fbc4b, 0x2e3915dd,
0x9fa803fa, 0x9546b2de, 0x3c233342, 0x0fcee7c3,
0x24d607ef, 0x8f97ebab, 0xf37f859b, 0xcd1f2e2f,
0xc25b71da, 0x75e2269a, 0x1e39c3d1, 0xeda56b36,
0xf8c9def2, 0x46c9fc5f, 0x1827b3a3, 0x70a56ddf,
0x0d25b510, 0x000f85a7, 0xb2e82e71, 0x68cb8816,
0x8f951e2a, 0x72f5f6af, 0xe4cbc2b3, 0xd34ff55d,
0x2e6b6214, 0x220b83e3, 0xd39ea6f5, 0x6fe041af,
0x6b2f1f17, 0xad3b99ee, 0x16a65ec0, 0x757016c6,
0xba7709a4, 0xb0326e01, 0xf4b280d9, 0x4bfb1418,
0xd6aff227, 0xfd548203, 0xf56b9d96, 0x6717a8c0,
0x00d5bf6e, 0x10ee7888, 0xedfcfe64, 0x1ba193cd,
0x4b0d0184, 0x89ae4930, 0x1c014f36, 0x82a87088,
0x5ead6c2a, 0xef22c678, 0x31204de7, 0xc9c2e759,
0xd200248e, 0x303b446b, 0xb00d9fc2, 0x9914a895,
0x906cc3a1, 0x54fef170, 0x34c19155, 0xe27b8a66,
0x131b5e69, 0xc3a8623e, 0x27bdfa35, 0x97f068cc,
0xca3a6acd, 0x4b55e936, 0x86602db9, 0x51df13c1,
0x390bb16d, 0x5a80b83c, 0x22b23763, 0x39d8a911,
0x2cb6bc13, 0xbf5579d7, 0x6c5c2fa8, 0xa8f4196e,
0xbcdb5476, 0x6864a866, 0x416e16ad, 0x897fc515,
0x956feb3c, 0xf6c8a306, 0x216799d9, 0x171a9133,
0x6c2466dd, 0x75eb5dcd, 0xdf118f50, 0xe4afb226,
0x26b9cef3, 0xadb36189, 0x8a7a19b1, 0xe2c73084,
0xf77ded5c, 0x8b8bc58f, 0x06dde421, 0xb41e47fb,
0xb1cc715e, 0x68c0ff99, 0x5d122f0f, 0xa4d25184,
0x097a5e6c, 0x0cbf18bc, 0xc2d7c6e0, 0x8bb7e420,
0xa11f523f, 0x35d9b8a2, 0x03da1a6b, 0x06888c02,
0x7dd1e354, 0x6bba7d79, 0x32cc7753, 0xe52d9655,
0xa9829da1, 0x301590a7, 0x9bc1c149, 0x13537f1c,
0xd3779b69, 0x2d71f2b7, 0x183c58fa, 0xacdc4418,
0x8d8c8c76, 0x2620d9f0, 0x71a80d4d, 0x7a74c473,
0x449410e9, 0xa20e4211, 0xf9c8082b, 0x0a6b334a,
0xb5f68ed2, 0x8243cc1b, 0x453c0ff3, 0x9be564a0,
0x4ff55a4f, 0x8740f8e7, 0xcca7f15f, 0xe300fe21,
0x786d37d6, 0xdfd506f1, 0x8ee00973, 0x17bbde36,
0x7a670fa8, 0x5c31ab9e, 0xd4dab618, 0xcc1f52f5,
0xe358eb4f, 0x19b9e343, 0x3a8d77dd, 0xcdb93da6,
0x140fd52d, 0x395412f8, 0x2ba63360, 0x37e53ad0,
0x80700f1c, 0x7624ed0b, 0x703dc1ec, 0xb7366795,
0xd6549d15, 0x66ce46d7, 0xd17abe76, 0xa448e0a0,
0x28f07c02, 0xc31249b7, 0x6e9ed6ba, 0xeaa47f78,
0xbbcfffbd, 0xc507ca84, 0xe965f4da, 0x8e9f35da,
0x6ad2aa44, 0x577452ac, 0xb5d674a7, 0x5461a46a,
0x6763152a, 0x9c12b7aa, 0x12615927, 0x7b4fb118,
0xc351758d, 0x7e81687b, 0x5f52f0b3, 0x2d4254ed,
0xd4c77271, 0x0431acab, 0xbef94aec, 0xfee994cd,
0x9c4d9e81, 0xed623730, 0xcf8a21e8, 0x51917f0b,
0xa7a9b5d6, 0xb297adf8, 0xeed30431, 0x68cac921,
0xf1b35d46, 0x7a430a36, 0x51194022, 0x9abca65e,
0x85ec70ba, 0x39aea8cc, 0x737bae8b, 0x582924d5,
0x03098a5a, 0x92396b81, 0x18de2522, 0x745c1cb8,
0xa1b8fe1d, 0x5db3c697, 0x29164f83, 0x97c16376,
0x8419224c, 0x21203b35, 0x833ac0fe, 0xd966a19a,
0xaaf0b24f, 0x40fda998, 0xe7d52d71, 0x390896a8,
0xcee6053f, 0xd0b0d300, 0xff99cbcc, 0x065e3d40,
};

View file

@ -0,0 +1,40 @@
tivodecode (c) 2006-2007, Jeremy Drake
Version 0.3pre4
See COPYING for license terms.
This project now uses autoconf for its build system. See the INSTALL file for
generic autoconf instructions, or just run:
./configure
make
make install
To build on Windows, a Visual C++ Express 2005 solution file is included. If
you have a working installation of this compiler, building should be as simple
as opening this solution file and building the tivodecode project.
If you are using the Windows binary download, you may need the Visual Studio
2005 Redisributables from Microsoft, if you do not already have MSVCR80.DLL
installed from some other software.
You now have the option to, rather than specifying the MAK on the command line
every time, to specify it in a config file in your home directory. Simply put
your MAK in a file called ~/.tivodecode_mak and it will be automatically used
if a MAK is not specified on the command line. On Windows, the file should be
in your %USERPROFILE% directory, or in c:\ if there is no %USERPROFILE% set.
The parameters (from --help) are documented below.
Usage: ./tivodecode [--help] [--verbose|-v] [--no-verify|-n] {--mak|-m} mak [{--out|-o} outfile] <tivofile>
--mak, -m media access key (required)
--out, -o output file (default stdout)
--verbose, -v verbose (add more v's for more verbosity)
--no-verify, -n do not verify MAK while decoding
--no-video, -x don't decode video, exit after metadata
--version, -V print the version information and exit
--help, -h print this help and exit
The file names specified for the output file or the tivo file may be -, which
means stdout or stdin respectively

View file

@ -0,0 +1,232 @@
TiVo TS header structure
========================
The TS file maintains the same overall file layout as the PS files.
There is a small header, followed by three "chunks" of info at the
beginning of the TS .TiVo file.
The header :
struct {
char filetype[4];
/* all fields are in network byte order */
unsigned short dummy_0004;
unsigned short dummy_0006;
unsigned short dummy_0008;
unsigned char mpeg_offset[4]; /* unsigned int */
unsigned short chunks;
} raw_tivo_header;
Points of interest :
"filetype" is always "TiVo".
dummy_0004 is unknown, at the moment.
dummy_0006 :
Bit 1 is always 0
Bit 2 is always 0 for US TiVo files and 1 for NZ/AUS files.
This does NOT seem to indicate H.264 vs MPEG-2 as I have one
of each from a NZ TiVo and they both have it set to 1.
Bit 3 is 0 if the file is PS and 1 if the file is TS
Bit 4 is 0 if the file is SD and 1 if the files is HD
* There are more values folded into "dummy_006" that are yet to be determined.
"mpeg_offset" is the offset at which the real MPEG data starts (typically around 14336)
"chunks" denotes the number of TiVo-specific chunks of data that follow (typically 3).
The chunks :
#define SIZEOF_STREAM_CHUNK 12
typedef struct tivo_stream_chunk_s {
unsigned int chunk_size; /* Size of chunk */
unsigned int data_size; /* Length of the payload */
unsigned short id; /* Chunk ID */
unsigned short type; /* Subtype */
unsigned char data[1]; /* Variable length data */
} tivo_stream_chunk;
Chunk size denotes the size of the current chunk.
Data size is the size of the current chunk, less the chunk header.
ID is the sequential chunk number of the current chunk (0-based).
type==0 is a clear-text copyright notice.
<?xml version="1.0" encoding="utf-8"?>
<license xmlns="http://www.tivo.com/developer/xml/license-1.0">
<notice>
TiVo takes copyright violations seriously. This file may contain
content protected by copyright laws. If you are not the owner or rights
holder of such content, you should be aware that if you distribute this
file or otherwise make it available to anyone else, you may be violating the
intellectual property rights of the owners of the content contained in this
file. If you are not the owner or rights holder of such content, and if you
are a TiVo customer, and if you distribute this file or otherwise make it
available to anyone else, you may be violating the service agreement.
We may permanently discontinue your TiVo service as a result.
</notice>
<created>
01/12/2005 11:22:01
</created>
<fingerprint>
... hex string that is 224 hex digits long ....
</fingerprint>
<salt>
... hex string that is 32 hex digits long...
</salt>
</license>
type==1 is an encrypted copy of the TiVo XML metadata for this file.
The encryption scheme used here is the metadata variant (see "Crytpo" below)
of the Turing stream cipher.
Typically, there are two chunks of this type, and the two are nearly identical.
The only variations I can see are that the second one includes the "uniqueId"
field, which is the unique seriesId (i.e. SH01234567) used by TiVo to perform
grouping in the Now Playing List.
Crypto
======
The encryption method utilized by TiVo is the open source Turing stream cipher, by Qualcomm.
https://opensource.qualcomm.com/index.php?turing
It follows the usual crypto usage pattern :
- initialize crypto session (to zero)
- "salt" the crypto session with predefined values (MAK, etc)
- pass blocks of the stream data through the cipher to encrypt/decrypt it
The metadata chunks use an initial MD5 pass to generate its Turing salt value.
The transport stream data packets use an initial SHA-1 pass to generate its Turing salt value.
Acquiring TiVo TS crypto info
=============================
- We must first acquire the MPEG TS "Program Association Table" (PAT).
This packet's only useful data element is the "program_MAP_pid" field,
which instructs us as the to PID of the "Program Map Table" (PMT) packet.
The PAT is always located at PID 0.
- Then, we must acquire the MPEG TS "Program Map Table" (PMT). The PMT
is a table of the elementary stream pids within the MPEG file, and their
types. The PMT may be located at PID identified in the PAT, or (more
likely) may be encapsulated in an audio/video packet. Typically, a TiVo
file will contain three streams.
0x21 = video
0x22 = audio
0x23 = private data : this is where TiVo puts the crypto goodies
- Not all packets in the audio and video streams are encrypted. This is
verified by comparing encrypted TS files and decrypted MPEG files as
generated by DirectShowDump. As such, we only need to worry about the
packets that are encrypted (which is denoted by the packet's TS header
transport_scrambling_control field being set to a non-zero value, usually 0x3).
- Packets in the "private data" stream contain the necessary info to decrypt
the audio and video streams within the TiVo MPEG TS file. They appear
periodically within the packet stream, and the Turing key value changes
with each new private data packet.
TiVo Private Data format
typedef struct TiVo_Private_Data_s
{
unsigned int filetype;
unsigned int unknown;
unsigned short num_streams;
TiVo_Private_Data_Stream data_streams[N];
} TiVo_Private_Data;
The filetype is always "TiVo".
The unknown field is exactly that, although its value is always 0x81037d00.
The num_streams indicates how many TiVo_Private_Data_Stream elements follow.
typedef struct TiVo_Private_Data_Stream_s
{
unsigned short pid;
unsigned char stream_id;
unsigned char reserved;
unsigned char key[16];
} TiVo_Private_Data_Stream;
The pid is the Packet ID for this stream (0x21, 0x22, etc).
The stream_id is the TS Stream ID (0xE0 video, 0xC0 audio, etc).
The reserved field is always 0x10.
The key is the 16-byte Turing key used to decrypt this particular stream.
The Turing key has two additional values folded into it for later use in
the decrypt process :
The first value is the "block_no" value, and indicates the Turing block
number for this portion of the cipher process. It increments over time
within the stream.
The second value is the "crypted" value, which appears to be some sort
of checksum value used by the stream cipher. In PS files, this number
appears to be a usable hexadecimal value, and as such is used in the
decrypt process. However, in the TS files, this number is always zero,
and is not used in the decrypt process.
When a TiVo private data packet is encountered, we must update our session's
Turing values (key, block_no) to the newer values. Each packet stream
(i.e. audio, video) within the transport stream will have it's own Turing
session. So, we must maintain these separate Turing sessions across packets.
When an audio/video packet is encountered, we must first verify if it is
indeed encrypted by checking the TS header's transport_scrambling_control
field. Any non-zero value (typically 0x3) denotes an encrypted packet.
We must take care to only decrypt payload data, and not packet stream control
data. As such, we must pass over other MPEG TS headers, such as the
Adaptation field or PES headers.
When we've finally located the beginning of the encrypted payload data, we
must regenerate our Turing cipher for this particular session. For this
packet, we must :
- locate this particular PID's Turing session
- extract the "block_no" and "crypted" values from the Turing key using by
calling do_header()
- prepare the Turing frame for decrypt by calling prepare_frame() and
pass it the PID and block_no.
- decrypt the payload by calling decrypt_buffer(), passing in a pointer
to the start of the encrypted payload, and the size of the payload to
be decrypted.
TiVo PS decrypt methodology
===========================
- Identify in the stream where private data is located (inside the private
data packets identified as PID 0x23). This is the crypto key.
- Prepare for Turing decrypt operations by passing in this key, along with two
values (block_no and crypted) into the do_header() function. This does some
bitfield math on these three elements, and results in new values being inserted into
the block_no and crypted fields. The do_header() function was reconstructed
from the TiVo DLL by other individuals, and the understanding behind it is
incomplete. There is some stuff going on in there that is unknown. Although,
it's obviously doing the right stuff (at least for PS operations).
- We then pass the new block_no and stream_id values into the prepare_frame()
function to prep the Turing structures for data decryption.
- We then pass the new crypted value (4 bytes worth) into the decrypt_buffer()
function to get the Turing goodies ready for real data.
- We then pass the entire amount of decrypted data through the decrypt_buffer()
function to decrypt the data. Since this is a data stream, the size of this
operation can be anywhere from 1000 to 15000 bytes.
- Rinse and repeat.
Notes on the code
=================
Since I was not an MPEG expert, I was quite verbose in my packet decode and debug output.
Much of this code can probably be cleaned up, or outright removed as needed.

View file

@ -0,0 +1,107 @@
/* @(#)Turing.h 1.4 (QUALCOMM) 03/02/24 */
/*
* Interface definition of Turing
*
* Copyright C 2002, Qualcomm Inc. Written by Greg Rose
*/
/*
This software is free for commercial and non-commercial use subject to
the following conditions:
1. Copyright remains vested in QUALCOMM Incorporated, and Copyright
notices in the code are not to be removed. If this package is used in
a product, QUALCOMM should be given attribution as the author of the
Turing encryption algorithm. This can be in the form of a textual
message at program startup or in documentation (online or textual)
provided with the package.
2. Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
a. Redistributions of source code must retain the copyright notice,
this list of conditions and the following disclaimer.
b. 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.
c. All advertising materials mentioning features or use of this
software must display the following acknowledgement: This product
includes software developed by QUALCOMM Incorporated.
3. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND AGAINST
INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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.
4. The license and distribution terms for any publically available version
or derivative of this code cannot be changed, that is, this code cannot
simply be copied and put under another distribution license including
the GNU Public License.
5. The Turing family of encryption algorithms are covered by patents in
the United States of America and other countries. A free and
irrevocable license is hereby granted for the use of such patents to
the extent required to utilize the Turing family of encryption
algorithms for any purpose, subject to the condition that any
commercial product utilising any of the Turing family of encryption
algorithms should show the words "Encryption by QUALCOMM" either on the
product or in the associated documentation.
*/
#ifndef TURING_H
#define TURING_H 1
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned char BYTE;
typedef unsigned long WORD;
#define MAXKEY 32 /*bytes*/
#define MAXKIV 48 /*bytes*/
#define MAXSTREAM 340 /* bytes, maximum stream generated by one call */
#define LFSRLEN 17 /*words*/
#define OUTLEN 20 /*bytes*/
#define POLY 0x4D /* x^8 + x^6 + x^3 + x^2 + 1 */
void * TuringAlloc();
void TuringFree(void * internal);
void TuringKey(void * internal, const BYTE key[], const int keylength);
void TuringIV(void * internal, const BYTE iv[], const int ivlength);
int TuringGen(void * internal, BYTE *buf); /* returns number of bytes of mask generated */
/* some useful macros -- big-endian */
#define B(x,i) ((BYTE)(((x) >> (24 - 8*i)) & 0xFF))
#define WORD2BYTE(w, b) { \
(b)[3] = B(w,3); \
(b)[2] = B(w,2); \
(b)[1] = B(w,1); \
(b)[0] = B(w,0); \
}
#define BYTE2WORD(b) ( \
(((WORD)(b)[0] & 0xFF)<<24) | \
(((WORD)(b)[1] & 0xFF)<<16) | \
(((WORD)(b)[2] & 0xFF)<<8) | \
(((WORD)(b)[3] & 0xFF)) \
)
#define ROTL(w,x) (((w) << (x))|((w) >> (32 - (x))))
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,303 @@
/* @(#)TuringFast.c 1.6 (QUALCOMM Turing) 03/02/24 */
/*
* Fast (unrolled) implementation of Turing
*
* Copyright C 2002, Qualcomm Inc. Written by Greg Rose
*/
/*
This software is free for commercial and non-commercial use subject to
the following conditions:
1. Copyright remains vested in QUALCOMM Incorporated, and Copyright
notices in the code are not to be removed. If this package is used in
a product, QUALCOMM should be given attribution as the author of the
Turing encryption algorithm. This can be in the form of a textual
message at program startup or in documentation (online or textual)
provided with the package.
2. Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
a. Redistributions of source code must retain the copyright notice,
this list of conditions and the following disclaimer.
b. 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.
c. All advertising materials mentioning features or use of this
software must display the following acknowledgement: This product
includes software developed by QUALCOMM Incorporated.
3. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND AGAINST
INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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.
4. The license and distribution terms for any publically available version
or derivative of this code cannot be changed, that is, this code cannot
simply be copied and put under another distribution license including
the GNU Public License.
5. The Turing family of encryption algorithms are covered by patents in
the United States of America and other countries. A free and
irrevocable license is hereby granted for the use of such patents to
the extent required to utilize the Turing family of encryption
algorithms for any purpose, subject to the condition that any
commercial product utilising any of the Turing family of encryption
algorithms should show the words "Encryption by QUALCOMM" either on the
product or in the associated documentation.
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include "Turing.h" /* interface definitions */
#include "TuringSbox.h"
#include "QUTsbox.h"
#include "TuringMultab.h"
struct turing_internal
{
int keylen; /* adjusted to count WORDs */
WORD K[MAXKEY/4]; /* storage for mixed key */
WORD R[LFSRLEN]; /* the shift register */
/* precalculated S-boxes */
WORD S0[256], S1[256], S2[256], S3[256];
};
/* give correct offset for the current position of the register,
* where logically turing->R[0] is at position "zero".
*/
#define OFF(zero, i) (((zero)+(i)) % LFSRLEN)
/* step the LFSR */
/* After stepping, "zero" moves right one place */
#define STEP(z) \
turing->R[OFF(z,0)] = turing->R[OFF(z,15)] ^ turing->R[OFF(z,4)] ^ \
(turing->R[OFF(z,0)] << 8) ^ Multab[(turing->R[OFF(z,0)] >> 24) & 0xFF]
/*
* This does a reversible transformation of a word, based on the S-boxes.
* The reversibility isn't used, but it guarantees no loss of information,
* and hence no equivalent keys or IVs.
*/
static WORD
fixedS(WORD w)
{
WORD b;
b = Sbox[B(w, 0)]; w = ((w ^ Qbox[b]) & 0x00FFFFFF) | (b << 24);
b = Sbox[B(w, 1)]; w = ((w ^ ROTL(Qbox[b],8)) & 0xFF00FFFF) | (b << 16);
b = Sbox[B(w, 2)]; w = ((w ^ ROTL(Qbox[b],16)) & 0xFFFF00FF) | (b << 8);
b = Sbox[B(w, 3)]; w = ((w ^ ROTL(Qbox[b],24)) & 0xFFFFFF00) | b;
return w;
}
/*
* Push a word through the keyed S-boxes.
*/
#define S(w,b) (turing->S0[B((w), ((0+b)&0x3))] \
^ turing->S1[B((w), ((1+b)&0x3))] \
^ turing->S2[B((w), ((2+b)&0x3))] \
^ turing->S3[B((w), ((3+b)&0x3))])
/* two variants of the Pseudo-Hadamard Transform */
/* Mix 5 words in place */
#define PHT(A,B,C,D,E) { \
(E) += (A) + (B) + (C) + (D); \
(A) += (E); \
(B) += (E); \
(C) += (E); \
(D) += (E); \
}
/* General word-wide n-PHT */
void
mixwords(WORD w[], int n)
{
register WORD sum;
register int i;
for (sum = i = 0; i < n-1; ++i)
sum += w[i];
w[n-1] += sum;
sum = w[n-1];
for (i = 0; i < n-1; ++i)
w[i] += sum;
}
/*
* Key the cipher.
* Table version; gathers words, mixes them, saves them.
* Then compiles lookup tables for the keyed S-boxes.
*/
void
TuringKey(void * internal, const BYTE key[], const int keylength)
{
struct turing_internal * turing = internal;
register int i, j, k;
register WORD w;
if ((keylength & 0x03) != 0 || keylength > MAXKEY)
abort();
turing->keylen = 0;
for (i = 0; i < keylength; i += 4)
turing->K[turing->keylen++] = fixedS(BYTE2WORD(&key[i]));
mixwords(turing->K, turing->keylen);
/* build S-box lookup tables */
for (j = 0; j < 256; ++j) {
w = 0;
k = j;
for (i = 0; i < turing->keylen; ++i) {
k = Sbox[B(turing->K[i], 0) ^ k];
w ^= ROTL(Qbox[k], i + 0);
}
turing->S0[j] = (w & 0x00FFFFFFUL) | (k << 24);
}
for (j = 0; j < 256; ++j) {
w = 0;
k = j;
for (i = 0; i < turing->keylen; ++i) {
k = Sbox[B(turing->K[i], 1) ^ k];
w ^= ROTL(Qbox[k], i + 8);
}
turing->S1[j] = (w & 0xFF00FFFFUL) | (k << 16);
}
for (j = 0; j < 256; ++j) {
w = 0;
k = j;
for (i = 0; i < turing->keylen; ++i) {
k = Sbox[B(turing->K[i], 2) ^ k];
w ^= ROTL(Qbox[k], i + 16);
}
turing->S2[j] = (w & 0xFFFF00FFUL) | (k << 8);
}
for (j = 0; j < 256; ++j) {
w = 0;
k = j;
for (i = 0; i < turing->keylen; ++i) {
k = Sbox[B(turing->K[i], 3) ^ k];
w ^= ROTL(Qbox[k], i + 24);
}
turing->S3[j] = (w & 0xFFFFFF00UL) | k;
}
}
/*
* Load the Initialization Vector.
* Actually, this fills the LFSR, with IV, key, length, and more.
* IV goes through the fixed S-box, key is premixed, the rest go through
* the keyed S-boxes. The reason for this is to avoid nasty interactions
* between the mixed key and the S-boxes that depend on them, and also
* to avoid any "chosen-IV" interactions with the keyed S-boxes, not that I
* can think of any.
*/
void
TuringIV(void * internal, const BYTE iv[], const int ivlength)
{
struct turing_internal * turing = internal;
register int i, j;
/* check args */
if ((ivlength & 0x03) != 0 || (ivlength + 4*turing->keylen) > MAXKIV)
abort();
/* first copy in the IV, mixing as we go */
for (i = j = 0; j < ivlength; j +=4)
turing->R[i++] = fixedS(BYTE2WORD(&iv[j]));
/* now continue with the premixed key */
for (j = 0 /* i continues */; j < turing->keylen; ++j)
turing->R[i++] = turing->K[j];
/* now the length-dependent word */
turing->R[i++] = (turing->keylen << 4) | (ivlength >> 2) | 0x01020300UL;
/* ... and fill the rest of the register */
for (j = 0 /* i continues */; i < LFSRLEN; ++i, ++j)
turing->R[i] = S(turing->R[j] + turing->R[i-1], 0);
/* finally mix all the words */
mixwords(turing->R, LFSRLEN);
}
/* a single round */
#define ROUND(z,b) \
{ \
STEP(z); \
A = turing->R[OFF(z+1,16)]; \
B = turing->R[OFF(z+1,13)]; \
C = turing->R[OFF(z+1,6)]; \
D = turing->R[OFF(z+1,1)]; \
E = turing->R[OFF(z+1,0)]; \
PHT(A, B, C, D, E); \
A = S(A,0); B = S(B,1); C = S(C,2); D = S(D,3); E = S(E,0); \
PHT(A, B, C, D, E); \
STEP(z+1); \
STEP(z+2); \
STEP(z+3); \
A += turing->R[OFF(z+4,14)]; \
B += turing->R[OFF(z+4,12)]; \
C += turing->R[OFF(z+4,8)]; \
D += turing->R[OFF(z+4,1)]; \
E += turing->R[OFF(z+4,0)]; \
WORD2BYTE(A, b); \
WORD2BYTE(B, b+4); \
WORD2BYTE(C, b+8); \
WORD2BYTE(D, b+12); \
WORD2BYTE(E, b+16); \
STEP(z+4); \
}
/*
* Generate 17 5-word blocks of output.
* This ensures that the register is resynchronised and avoids state.
* Buffering issues are outside the scope of this implementation.
* Returns the number of bytes of stream generated.
*/
int
TuringGen(void * internal, BYTE *buf)
{
struct turing_internal * turing = internal;
WORD A, B, C, D, E;
ROUND(0,buf);
ROUND(5,buf+20);
ROUND(10,buf+40);
ROUND(15,buf+60);
ROUND(3,buf+80);
ROUND(8,buf+100);
ROUND(13,buf+120);
ROUND(1,buf+140);
ROUND(6,buf+160);
ROUND(11,buf+180);
ROUND(16,buf+200);
ROUND(4,buf+220);
ROUND(9,buf+240);
ROUND(14,buf+260);
ROUND(2,buf+280);
ROUND(7,buf+300);
ROUND(12,buf+320);
return 17*20;
}
void * TuringAlloc()
{
return calloc(1, sizeof(struct turing_internal));
}
void TuringFree(void * internal)
{
free(internal);
}

View file

@ -0,0 +1,68 @@
/* @(#)TuringMultab.h 1.3 (QUALCOMM) 02/09/03 */
/* Multiplication table for Turing using 0xD02B4367 */
unsigned long Multab[256] = {
0x00000000, 0xD02B4367, 0xED5686CE, 0x3D7DC5A9,
0x97AC41D1, 0x478702B6, 0x7AFAC71F, 0xAAD18478,
0x631582EF, 0xB33EC188, 0x8E430421, 0x5E684746,
0xF4B9C33E, 0x24928059, 0x19EF45F0, 0xC9C40697,
0xC62A4993, 0x16010AF4, 0x2B7CCF5D, 0xFB578C3A,
0x51860842, 0x81AD4B25, 0xBCD08E8C, 0x6CFBCDEB,
0xA53FCB7C, 0x7514881B, 0x48694DB2, 0x98420ED5,
0x32938AAD, 0xE2B8C9CA, 0xDFC50C63, 0x0FEE4F04,
0xC154926B, 0x117FD10C, 0x2C0214A5, 0xFC2957C2,
0x56F8D3BA, 0x86D390DD, 0xBBAE5574, 0x6B851613,
0xA2411084, 0x726A53E3, 0x4F17964A, 0x9F3CD52D,
0x35ED5155, 0xE5C61232, 0xD8BBD79B, 0x089094FC,
0x077EDBF8, 0xD755989F, 0xEA285D36, 0x3A031E51,
0x90D29A29, 0x40F9D94E, 0x7D841CE7, 0xADAF5F80,
0x646B5917, 0xB4401A70, 0x893DDFD9, 0x59169CBE,
0xF3C718C6, 0x23EC5BA1, 0x1E919E08, 0xCEBADD6F,
0xCFA869D6, 0x1F832AB1, 0x22FEEF18, 0xF2D5AC7F,
0x58042807, 0x882F6B60, 0xB552AEC9, 0x6579EDAE,
0xACBDEB39, 0x7C96A85E, 0x41EB6DF7, 0x91C02E90,
0x3B11AAE8, 0xEB3AE98F, 0xD6472C26, 0x066C6F41,
0x09822045, 0xD9A96322, 0xE4D4A68B, 0x34FFE5EC,
0x9E2E6194, 0x4E0522F3, 0x7378E75A, 0xA353A43D,
0x6A97A2AA, 0xBABCE1CD, 0x87C12464, 0x57EA6703,
0xFD3BE37B, 0x2D10A01C, 0x106D65B5, 0xC04626D2,
0x0EFCFBBD, 0xDED7B8DA, 0xE3AA7D73, 0x33813E14,
0x9950BA6C, 0x497BF90B, 0x74063CA2, 0xA42D7FC5,
0x6DE97952, 0xBDC23A35, 0x80BFFF9C, 0x5094BCFB,
0xFA453883, 0x2A6E7BE4, 0x1713BE4D, 0xC738FD2A,
0xC8D6B22E, 0x18FDF149, 0x258034E0, 0xF5AB7787,
0x5F7AF3FF, 0x8F51B098, 0xB22C7531, 0x62073656,
0xABC330C1, 0x7BE873A6, 0x4695B60F, 0x96BEF568,
0x3C6F7110, 0xEC443277, 0xD139F7DE, 0x0112B4B9,
0xD31DD2E1, 0x03369186, 0x3E4B542F, 0xEE601748,
0x44B19330, 0x949AD057, 0xA9E715FE, 0x79CC5699,
0xB008500E, 0x60231369, 0x5D5ED6C0, 0x8D7595A7,
0x27A411DF, 0xF78F52B8, 0xCAF29711, 0x1AD9D476,
0x15379B72, 0xC51CD815, 0xF8611DBC, 0x284A5EDB,
0x829BDAA3, 0x52B099C4, 0x6FCD5C6D, 0xBFE61F0A,
0x7622199D, 0xA6095AFA, 0x9B749F53, 0x4B5FDC34,
0xE18E584C, 0x31A51B2B, 0x0CD8DE82, 0xDCF39DE5,
0x1249408A, 0xC26203ED, 0xFF1FC644, 0x2F348523,
0x85E5015B, 0x55CE423C, 0x68B38795, 0xB898C4F2,
0x715CC265, 0xA1778102, 0x9C0A44AB, 0x4C2107CC,
0xE6F083B4, 0x36DBC0D3, 0x0BA6057A, 0xDB8D461D,
0xD4630919, 0x04484A7E, 0x39358FD7, 0xE91ECCB0,
0x43CF48C8, 0x93E40BAF, 0xAE99CE06, 0x7EB28D61,
0xB7768BF6, 0x675DC891, 0x5A200D38, 0x8A0B4E5F,
0x20DACA27, 0xF0F18940, 0xCD8C4CE9, 0x1DA70F8E,
0x1CB5BB37, 0xCC9EF850, 0xF1E33DF9, 0x21C87E9E,
0x8B19FAE6, 0x5B32B981, 0x664F7C28, 0xB6643F4F,
0x7FA039D8, 0xAF8B7ABF, 0x92F6BF16, 0x42DDFC71,
0xE80C7809, 0x38273B6E, 0x055AFEC7, 0xD571BDA0,
0xDA9FF2A4, 0x0AB4B1C3, 0x37C9746A, 0xE7E2370D,
0x4D33B375, 0x9D18F012, 0xA06535BB, 0x704E76DC,
0xB98A704B, 0x69A1332C, 0x54DCF685, 0x84F7B5E2,
0x2E26319A, 0xFE0D72FD, 0xC370B754, 0x135BF433,
0xDDE1295C, 0x0DCA6A3B, 0x30B7AF92, 0xE09CECF5,
0x4A4D688D, 0x9A662BEA, 0xA71BEE43, 0x7730AD24,
0xBEF4ABB3, 0x6EDFE8D4, 0x53A22D7D, 0x83896E1A,
0x2958EA62, 0xF973A905, 0xC40E6CAC, 0x14252FCB,
0x1BCB60CF, 0xCBE023A8, 0xF69DE601, 0x26B6A566,
0x8C67211E, 0x5C4C6279, 0x6131A7D0, 0xB11AE4B7,
0x78DEE220, 0xA8F5A147, 0x958864EE, 0x45A32789,
0xEF72A3F1, 0x3F59E096, 0x0224253F, 0xD20F6658,
};

View file

@ -0,0 +1,48 @@
/* @(#)TuringSbox.h 1.2 (QUALCOMM) 02/08/23 */
/*
* Basic Sbox for Turing.
*
* This was generated by keying RC4 with the 11-character string
* "Alan Turing", and then ignoring 256 generated bytes.
* Then the current permutation was tested for nonlinearity, another byte
* generated, etc., until a total
* of 10000 bytes had been generated. The best observed min nonlinearity was
* 104, which first occurred after 736 bytes had been generated. The
* corresponding state table is used in Turing. By happy coincidence it
* also has no fixed points (ie. Sbox[x] != x for all x).
*/
unsigned char Sbox[256] = {
0x61, 0x51, 0xeb, 0x19, 0xb9, 0x5d, 0x60, 0x38,
0x7c, 0xb2, 0x06, 0x12, 0xc4, 0x5b, 0x16, 0x3b,
0x2b, 0x18, 0x83, 0xb0, 0x7f, 0x75, 0xfa, 0xa0,
0xe9, 0xdd, 0x6d, 0x7a, 0x6b, 0x68, 0x2d, 0x49,
0xb5, 0x1c, 0x90, 0xf7, 0xed, 0x9f, 0xe8, 0xce,
0xae, 0x77, 0xc2, 0x13, 0xfd, 0xcd, 0x3e, 0xcf,
0x37, 0x6a, 0xd4, 0xdb, 0x8e, 0x65, 0x1f, 0x1a,
0x87, 0xcb, 0x40, 0x15, 0x88, 0x0d, 0x35, 0xb3,
0x11, 0x0f, 0xd0, 0x30, 0x48, 0xf9, 0xa8, 0xac,
0x85, 0x27, 0x0e, 0x8a, 0xe0, 0x50, 0x64, 0xa7,
0xcc, 0xe4, 0xf1, 0x98, 0xff, 0xa1, 0x04, 0xda,
0xd5, 0xbc, 0x1b, 0xbb, 0xd1, 0xfe, 0x31, 0xca,
0xba, 0xd9, 0x2e, 0xf3, 0x1d, 0x47, 0x4a, 0x3d,
0x71, 0x4c, 0xab, 0x7d, 0x8d, 0xc7, 0x59, 0xb8,
0xc1, 0x96, 0x1e, 0xfc, 0x44, 0xc8, 0x7b, 0xdc,
0x5c, 0x78, 0x2a, 0x9d, 0xa5, 0xf0, 0x73, 0x22,
0x89, 0x05, 0xf4, 0x07, 0x21, 0x52, 0xa6, 0x28,
0x9a, 0x92, 0x69, 0x8f, 0xc5, 0xc3, 0xf5, 0xe1,
0xde, 0xec, 0x09, 0xf2, 0xd3, 0xaf, 0x34, 0x23,
0xaa, 0xdf, 0x7e, 0x82, 0x29, 0xc0, 0x24, 0x14,
0x03, 0x32, 0x4e, 0x39, 0x6f, 0xc6, 0xb1, 0x9b,
0xea, 0x72, 0x79, 0x41, 0xd8, 0x26, 0x6c, 0x5e,
0x2c, 0xb4, 0xa2, 0x53, 0x57, 0xe2, 0x9c, 0x86,
0x54, 0x95, 0xb6, 0x80, 0x8c, 0x36, 0x67, 0xbd,
0x08, 0x93, 0x2f, 0x99, 0x5a, 0xf8, 0x3a, 0xd7,
0x56, 0x84, 0xd2, 0x01, 0xf6, 0x66, 0x4d, 0x55,
0x8b, 0x0c, 0x0b, 0x46, 0xb7, 0x3c, 0x45, 0x91,
0xa4, 0xe3, 0x70, 0xd6, 0xfb, 0xe6, 0x10, 0xa9,
0xc9, 0x00, 0x9e, 0xe7, 0x4f, 0x76, 0x25, 0x3f,
0x5f, 0xa3, 0x33, 0x20, 0x02, 0xef, 0x62, 0x74,
0xee, 0x17, 0x81, 0x42, 0x58, 0x0a, 0x4b, 0x63,
0xe5, 0xbe, 0x6e, 0xad, 0xbf, 0x43, 0x94, 0x97,
};

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type='text/xsl' href='_UpgradeReport_Files/UpgradeReport.xslt'?><UpgradeLog>
<Properties><Property Name="Solution" Value="tivodecode">
</Property><Property Name="Solution File" Value="S:\psimoneau\test\tivo\tivodecode-0.3\tivodecode.sln">
</Property><Property Name="Date" Value="Monday, December 21, 2009">
</Property><Property Name="Time" Value="16:03 PM">
</Property></Properties><Event ErrorLevel="0" Project="tivodecode" Source="tivodecode.vcproj" Description="Web deployment to the local IIS server is no longer supported. The Web Deployment build tool has been removed from your project settings.">
</Event><Event ErrorLevel="1" Project="tivodecode" Source="tivodecode.vcproj" Description="This application has been updated to include settings related to the User Account Control (UAC) feature of Windows Vista. By default, when run on Windows Vista with UAC enabled, this application is marked to run with the same privileges as the process that launched it. This marking also disables the application from running with virtualization. You can change UAC related settings from the Property Pages of the project.">
</Event><Event ErrorLevel="0" Project="tivodecode" Source="tivodecode.vcproj" Description="Project upgraded successfully.">
</Event><Event ErrorLevel="3" Project="tivodecode" Source="tivodecode.vcproj" Description="Converted">
</Event><Event ErrorLevel="1" Project="libtivodecode" Source="libtivodecode.vcproj" Description="This application has been updated to include settings related to the User Account Control (UAC) feature of Windows Vista. By default, when run on Windows Vista with UAC enabled, this application is marked to run with the same privileges as the process that launched it. This marking also disables the application from running with virtualization. You can change UAC related settings from the Property Pages of the project.">
</Event><Event ErrorLevel="0" Project="libtivodecode" Source="libtivodecode.vcproj" Description="Project upgraded successfully.">
</Event><Event ErrorLevel="3" Project="libtivodecode" Source="libtivodecode.vcproj" Description="Converted">
</Event><Event ErrorLevel="0" Project="tdcat" Source="tdcat.vcproj" Description="Web deployment to the local IIS server is no longer supported. The Web Deployment build tool has been removed from your project settings.">
</Event><Event ErrorLevel="1" Project="tdcat" Source="tdcat.vcproj" Description="This application has been updated to include settings related to the User Account Control (UAC) feature of Windows Vista. By default, when run on Windows Vista with UAC enabled, this application is marked to run with the same privileges as the process that launched it. This marking also disables the application from running with virtualization. You can change UAC related settings from the Property Pages of the project.">
</Event><Event ErrorLevel="0" Project="tdcat" Source="tdcat.vcproj" Description="Project upgraded successfully.">
</Event><Event ErrorLevel="3" Project="tdcat" Source="tdcat.vcproj" Description="Converted">
</Event><Event ErrorLevel="1" Project="libtdcommon" Source="libtdcommon.vcproj" Description="This application has been updated to include settings related to the User Account Control (UAC) feature of Windows Vista. By default, when run on Windows Vista with UAC enabled, this application is marked to run with the same privileges as the process that launched it. This marking also disables the application from running with virtualization. You can change UAC related settings from the Property Pages of the project.">
</Event><Event ErrorLevel="0" Project="libtdcommon" Source="libtdcommon.vcproj" Description="Project upgraded successfully.">
</Event><Event ErrorLevel="3" Project="libtdcommon" Source="libtdcommon.vcproj" Description="Converted">
</Event><Event ErrorLevel="0" Project="" Source="tivodecode.sln" Description="Solution converted successfully">
</Event><Event ErrorLevel="3" Project="" Source="tivodecode.sln" Description="Converted">
</Event></UpgradeLog>

892
src/tivomirror/tivodecode/aclocal.m4 vendored Normal file
View file

@ -0,0 +1,892 @@
# generated automatically by aclocal 1.10 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
m4_if(m4_PACKAGE_VERSION, [2.61],,
[m4_fatal([this file was generated for autoconf 2.61.
You have another version of autoconf. If you want to use that,
you should regenerate the build system entirely.], [63])])
# Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_AUTOMAKE_VERSION(VERSION)
# ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.10'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
m4_if([$1], [1.10], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
# _AM_AUTOCONF_VERSION(VERSION)
# -----------------------------
# aclocal traces this macro to find the Autoconf version.
# This is a private macro too. Using m4_define simplifies
# the logic in aclocal, which can simply ignore this definition.
m4_define([_AM_AUTOCONF_VERSION], [])
# AM_SET_CURRENT_AUTOMAKE_VERSION
# -------------------------------
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.10])dnl
_AM_AUTOCONF_VERSION(m4_PACKAGE_VERSION)])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to
# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
#
# Of course, Automake must honor this variable whenever it calls a
# tool from the auxiliary directory. The problem is that $srcdir (and
# therefore $ac_aux_dir as well) can be either absolute or relative,
# depending on how configure is run. This is pretty annoying, since
# it makes $ac_aux_dir quite unusable in subdirectories: in the top
# source directory, any form will work fine, but in subdirectories a
# relative path needs to be adjusted first.
#
# $ac_aux_dir/missing
# fails when called from a subdirectory if $ac_aux_dir is relative
# $top_srcdir/$ac_aux_dir/missing
# fails if $ac_aux_dir is absolute,
# fails when called from a subdirectory in a VPATH build with
# a relative $ac_aux_dir
#
# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
# are both prefixed by $srcdir. In an in-source build this is usually
# harmless because $srcdir is `.', but things will broke when you
# start a VPATH build or use an absolute $srcdir.
#
# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
# iff we strip the leading $srcdir from $ac_aux_dir. That would be:
# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
# and then we would define $MISSING as
# MISSING="\${SHELL} $am_aux_dir/missing"
# This will work as long as MISSING is not called from configure, because
# unfortunately $(top_srcdir) has no meaning in configure.
# However there are other variables, like CC, which are often used in
# configure, and could therefore not use this "fixed" $ac_aux_dir.
#
# Another solution, used here, is to always expand $ac_aux_dir to an
# absolute PATH. The drawback is that using absolute paths prevent a
# configured tree to be moved without reconfiguration.
AC_DEFUN([AM_AUX_DIR_EXPAND],
[dnl Rely on autoconf to set up CDPATH properly.
AC_PREREQ([2.50])dnl
# expand $ac_aux_dir to an absolute path
am_aux_dir=`cd $ac_aux_dir && pwd`
])
# AM_CONDITIONAL -*- Autoconf -*-
# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 8
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
# Define a conditional.
AC_DEFUN([AM_CONDITIONAL],
[AC_PREREQ(2.52)dnl
ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
AC_SUBST([$1_TRUE])dnl
AC_SUBST([$1_FALSE])dnl
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
if $2; then
$1_TRUE=
$1_FALSE='#'
else
$1_TRUE='#'
$1_FALSE=
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
AC_MSG_ERROR([[conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.]])
fi])])
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 9
# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
# written in clear, in which case automake, when reading aclocal.m4,
# will think it sees a *use*, and therefore will trigger all it's
# C support machinery. Also note that it means that autoscan, seeing
# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
# _AM_DEPENDENCIES(NAME)
# ----------------------
# See how the compiler implements dependency checking.
# NAME is "CC", "CXX", "GCJ", or "OBJC".
# We try a few techniques and use that to set a single cache variable.
#
# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
# dependency, and given that the user is not expected to run this macro,
# just rely on AC_PROG_CC.
AC_DEFUN([_AM_DEPENDENCIES],
[AC_REQUIRE([AM_SET_DEPDIR])dnl
AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
AC_REQUIRE([AM_MAKE_INCLUDE])dnl
AC_REQUIRE([AM_DEP_TRACK])dnl
ifelse([$1], CC, [depcc="$CC" am_compiler_list=],
[$1], CXX, [depcc="$CXX" am_compiler_list=],
[$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
[$1], UPC, [depcc="$UPC" am_compiler_list=],
[$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
[depcc="$$1" am_compiler_list=])
AC_CACHE_CHECK([dependency style of $depcc],
[am_cv_$1_dependencies_compiler_type],
[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
# making a dummy file named `D' -- because `-MD' means `put the output
# in D'.
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
# using a relative directory.
cp "$am_depcomp" conftest.dir
cd conftest.dir
# We will build objects and dependencies in a subdirectory because
# it helps to detect inapplicable dependency modes. For instance
# both Tru64's cc and ICC support -MD to output dependencies as a
# side effect of compilation, but ICC will put the dependencies in
# the current directory while Tru64 will put them in the object
# directory.
mkdir sub
am_cv_$1_dependencies_compiler_type=none
if test "$am_compiler_list" = ""; then
am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
fi
for depmode in $am_compiler_list; do
# Setup a source with many dependencies, because some compilers
# like to wrap large dependency lists on column 80 (with \), and
# we should not choose a depcomp mode which is confused by this.
#
# We need to recreate these files for each test, as the compiler may
# overwrite some of them when testing with obscure command lines.
# This happens at least with the AIX C compiler.
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
# Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
# Solaris 8's {/usr,}/bin/sh.
touch sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
case $depmode in
nosideeffect)
# after this tag, mechanisms are not by side-effect, so they'll
# only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
break
fi
;;
none) break ;;
esac
# We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
# handle `-M -o', and we need to detect this.
if depmode=$depmode \
source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
$SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
>/dev/null 2>conftest.err &&
grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
${MAKE-make} -s -f confmf > /dev/null 2>&1; then
# icc doesn't choke on unknown options, it will just issue warnings
# or remarks (even with -Werror). So we grep stderr for any message
# that says an option was ignored or not supported.
# When given -MP, icc 7.0 and 7.1 complain thusly:
# icc: Command line warning: ignoring option '-M'; no argument required
# The diagnosis changed in icc 8.0:
# icc: Command line remark: option '-MP' not supported
if (grep 'ignoring option' conftest.err ||
grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
am_cv_$1_dependencies_compiler_type=$depmode
break
fi
fi
done
cd ..
rm -rf conftest.dir
else
am_cv_$1_dependencies_compiler_type=none
fi
])
AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
AM_CONDITIONAL([am__fastdep$1], [
test "x$enable_dependency_tracking" != xno \
&& test "$am_cv_$1_dependencies_compiler_type" = gcc3])
])
# AM_SET_DEPDIR
# -------------
# Choose a directory name for dependency files.
# This macro is AC_REQUIREd in _AM_DEPENDENCIES
AC_DEFUN([AM_SET_DEPDIR],
[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
])
# AM_DEP_TRACK
# ------------
AC_DEFUN([AM_DEP_TRACK],
[AC_ARG_ENABLE(dependency-tracking,
[ --disable-dependency-tracking speeds up one-time build
--enable-dependency-tracking do not reject slow dependency extractors])
if test "x$enable_dependency_tracking" != xno; then
am_depcomp="$ac_aux_dir/depcomp"
AMDEPBACKSLASH='\'
fi
AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
AC_SUBST([AMDEPBACKSLASH])dnl
_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
])
# Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#serial 3
# _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[for mf in $CONFIG_FILES; do
# Strip MF so we end up with the name of the file.
mf=`echo "$mf" | sed -e 's/:.*$//'`
# Check whether this is an Automake generated Makefile or not.
# We used to match only the files named `Makefile.in', but
# some people rename them; so instead we look at the file content.
# Grep'ing the first line is not enough: some people post-process
# each Makefile.in and add a new line on top of each file to say so.
# Grep'ing the whole file is not good either: AIX grep has a line
# limit of 2048, but all sed's we know have understand at least 4000.
if sed 10q "$mf" | grep '^#.*generated by automake' > /dev/null 2>&1; then
dirpart=`AS_DIRNAME("$mf")`
else
continue
fi
# Extract the definition of DEPDIR, am__include, and am__quote
# from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
am__include=`sed -n 's/^am__include = //p' < "$mf"`
test -z "am__include" && continue
am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
# When using ansi2knr, U may be empty or an underscore; expand it
U=`sed -n 's/^U = //p' < "$mf"`
# Find all dependency output files, they are included files with
# $(DEPDIR) in their names. We invoke sed twice because it is the
# simplest approach to changing $(DEPDIR) to its actual value in the
# expansion.
for file in `sed -n "
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`AS_DIRNAME(["$file"])`
AS_MKDIR_P([$dirpart/$fdir])
# echo "creating $dirpart/$file"
echo '# dummy' > "$dirpart/$file"
done
done
])# _AM_OUTPUT_DEPENDENCY_COMMANDS
# AM_OUTPUT_DEPENDENCY_COMMANDS
# -----------------------------
# This macro should only be invoked once -- use via AC_REQUIRE.
#
# This code is only required when automatic dependency tracking
# is enabled. FIXME. This creates each `.P' file that we will
# need in order to bootstrap the dependency handling code.
AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
[AC_CONFIG_COMMANDS([depfiles],
[test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
[AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
])
# Do all the work for Automake. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 12
# This macro actually does too much. Some checks are only needed if
# your package does certain things. But this isn't really a big deal.
# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
# AM_INIT_AUTOMAKE([OPTIONS])
# -----------------------------------------------
# The call with PACKAGE and VERSION arguments is the old style
# call (pre autoconf-2.50), which is being phased out. PACKAGE
# and VERSION should now be passed to AC_INIT and removed from
# the call to AM_INIT_AUTOMAKE.
# We support both call styles for the transition. After
# the next Automake release, Autoconf can make the AC_INIT
# arguments mandatory, and then we can depend on a new Autoconf
# release and drop the old call support.
AC_DEFUN([AM_INIT_AUTOMAKE],
[AC_PREREQ([2.60])dnl
dnl Autoconf wants to disallow AM_ names. We explicitly allow
dnl the ones we care about.
m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
AC_REQUIRE([AC_PROG_INSTALL])dnl
if test "`cd $srcdir && pwd`" != "`pwd`"; then
# Use -I$(srcdir) only when $(srcdir) != ., so that make's output
# is not polluted with repeated "-I."
AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
# test to see if srcdir already configured
if test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
fi
# test whether we have cygpath
if test -z "$CYGPATH_W"; then
if (cygpath --version) >/dev/null 2>/dev/null; then
CYGPATH_W='cygpath -w'
else
CYGPATH_W=echo
fi
fi
AC_SUBST([CYGPATH_W])
# Define the identity of the package.
dnl Distinguish between old-style and new-style calls.
m4_ifval([$2],
[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
AC_SUBST([PACKAGE], [$1])dnl
AC_SUBST([VERSION], [$2])],
[_AM_SET_OPTIONS([$1])dnl
dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
[m4_fatal([AC_INIT should be called with package and version arguments])])dnl
AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
_AM_IF_OPTION([no-define],,
[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
# Some tools Automake needs.
AC_REQUIRE([AM_SANITY_CHECK])dnl
AC_REQUIRE([AC_ARG_PROGRAM])dnl
AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
AM_MISSING_PROG(AUTOCONF, autoconf)
AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
AM_MISSING_PROG(AUTOHEADER, autoheader)
AM_MISSING_PROG(MAKEINFO, makeinfo)
AM_PROG_INSTALL_SH
AM_PROG_INSTALL_STRIP
AC_REQUIRE([AM_PROG_MKDIR_P])dnl
# We need awk for the "check" target. The system "awk" is bad on
# some platforms.
AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl
_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
[_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
[_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],,
[AC_PROVIDE_IFELSE([AC_PROG_CC],
[_AM_DEPENDENCIES(CC)],
[define([AC_PROG_CC],
defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_CXX],
[_AM_DEPENDENCIES(CXX)],
[define([AC_PROG_CXX],
defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_OBJC],
[_AM_DEPENDENCIES(OBJC)],
[define([AC_PROG_OBJC],
defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
])
])
# When config.status generates a header, we must update the stamp-h file.
# This file resides in the same directory as the config header
# that is generated. The stamp files are numbered to have different names.
# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
# loop where config.status creates the headers, so we can generate
# our stamp files there.
AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
[# Compute $1's index in $config_headers.
_am_stamp_count=1
for _am_header in $config_headers :; do
case $_am_header in
$1 | $1:* )
break ;;
* )
_am_stamp_count=`expr $_am_stamp_count + 1` ;;
esac
done
echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_PROG_INSTALL_SH
# ------------------
# Define $install_sh.
AC_DEFUN([AM_PROG_INSTALL_SH],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"}
AC_SUBST(install_sh)])
# Copyright (C) 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 2
# Check whether the underlying file-system supports filenames
# with a leading dot. For instance MS-DOS doesn't.
AC_DEFUN([AM_SET_LEADING_DOT],
[rm -rf .tst 2>/dev/null
mkdir .tst 2>/dev/null
if test -d .tst; then
am__leading_dot=.
else
am__leading_dot=_
fi
rmdir .tst 2>/dev/null
AC_SUBST([am__leading_dot])])
# Add --enable-maintainer-mode option to configure. -*- Autoconf -*-
# From Jim Meyering
# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 4
AC_DEFUN([AM_MAINTAINER_MODE],
[AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
dnl maintainer-mode is disabled by default
AC_ARG_ENABLE(maintainer-mode,
[ --enable-maintainer-mode enable make rules and dependencies not useful
(and sometimes confusing) to the casual installer],
USE_MAINTAINER_MODE=$enableval,
USE_MAINTAINER_MODE=no)
AC_MSG_RESULT([$USE_MAINTAINER_MODE])
AM_CONDITIONAL(MAINTAINER_MODE, [test $USE_MAINTAINER_MODE = yes])
MAINT=$MAINTAINER_MODE_TRUE
AC_SUBST(MAINT)dnl
]
)
AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
# Check to see how 'make' treats includes. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 3
# AM_MAKE_INCLUDE()
# -----------------
# Check to see how make treats includes.
AC_DEFUN([AM_MAKE_INCLUDE],
[am_make=${MAKE-make}
cat > confinc << 'END'
am__doit:
@echo done
.PHONY: am__doit
END
# If we don't find an include directive, just comment out the code.
AC_MSG_CHECKING([for style of include used by $am_make])
am__include="#"
am__quote=
_am_result=none
# First try GNU make style include.
echo "include confinc" > confmf
# We grep out `Entering directory' and `Leaving directory'
# messages which can occur if `w' ends up in MAKEFLAGS.
# In particular we don't look at `^make:' because GNU make might
# be invoked under some other name (usually "gmake"), in which
# case it prints its new name instead of `make'.
if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
am__include=include
am__quote=
_am_result=GNU
fi
# Now try BSD make style include.
if test "$am__include" = "#"; then
echo '.include "confinc"' > confmf
if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
am__include=.include
am__quote="\""
_am_result=BSD
fi
fi
AC_SUBST([am__include])
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 5
# AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------
AC_DEFUN([AM_MISSING_PROG],
[AC_REQUIRE([AM_MISSING_HAS_RUN])
$1=${$1-"${am_missing_run}$2"}
AC_SUBST($1)])
# AM_MISSING_HAS_RUN
# ------------------
# Define MISSING if not defined so far and test if it supports --run.
# If it does, set am_missing_run to use it, otherwise, to nothing.
AC_DEFUN([AM_MISSING_HAS_RUN],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
AC_REQUIRE_AUX_FILE([missing])dnl
test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
# Use eval to expand $SHELL
if eval "$MISSING --run true"; then
am_missing_run="$MISSING --run "
else
am_missing_run=
AC_MSG_WARN([`missing' script is too old or missing])
fi
])
# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_PROG_MKDIR_P
# ---------------
# Check for `mkdir -p'.
AC_DEFUN([AM_PROG_MKDIR_P],
[AC_PREREQ([2.60])dnl
AC_REQUIRE([AC_PROG_MKDIR_P])dnl
dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P,
dnl while keeping a definition of mkdir_p for backward compatibility.
dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
dnl Makefile.ins that do not define MKDIR_P, so we do our own
dnl adjustment using top_builddir (which is defined more often than
dnl MKDIR_P).
AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
case $mkdir_p in
[[\\/$]]* | ?:[[\\/]]*) ;;
*/*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
esac
])
# Helper functions for option handling. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 3
# _AM_MANGLE_OPTION(NAME)
# -----------------------
AC_DEFUN([_AM_MANGLE_OPTION],
[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
# _AM_SET_OPTION(NAME)
# ------------------------------
# Set option NAME. Presently that only means defining a flag for this option.
AC_DEFUN([_AM_SET_OPTION],
[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
# _AM_SET_OPTIONS(OPTIONS)
# ----------------------------------
# OPTIONS is a space-separated list of Automake options.
AC_DEFUN([_AM_SET_OPTIONS],
[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
# -------------------------------------------
# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
# Check to make sure that the build environment is sane. -*- Autoconf -*-
# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 4
# AM_SANITY_CHECK
# ---------------
AC_DEFUN([AM_SANITY_CHECK],
[AC_MSG_CHECKING([whether build environment is sane])
# Just in case
sleep 1
echo timestamp > conftest.file
# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
if test "$[*]" = "X"; then
# -L didn't work.
set X `ls -t $srcdir/configure conftest.file`
fi
rm -f conftest.file
if test "$[*]" != "X $srcdir/configure conftest.file" \
&& test "$[*]" != "X conftest.file $srcdir/configure"; then
# If neither matched, then we have a broken ls. This can happen
# if, for instance, CONFIG_SHELL is bash and it inherits a
# broken ls alias from the environment. This has actually
# happened. Such a system could not be considered "sane".
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
alias in your environment])
fi
test "$[2]" = conftest.file
)
then
# Ok.
:
else
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
AC_MSG_RESULT(yes)])
# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# AM_PROG_INSTALL_STRIP
# ---------------------
# One issue with vendor `install' (even GNU) is that you can't
# specify the program used to strip binaries. This is especially
# annoying in cross-compiling environments, where the build's strip
# is unlikely to handle the host's binaries.
# Fortunately install-sh will honor a STRIPPROG variable, so we
# always use install-sh in `make install-strip', and initialize
# STRIPPROG with the value of the STRIP variable (set by the user).
AC_DEFUN([AM_PROG_INSTALL_STRIP],
[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
# Installed binaries are usually stripped using `strip' when the user
# run `make install-strip'. However `strip' might not be the right
# tool to use in cross-compilation environments, therefore Automake
# will honor the `STRIP' environment variable to overrule this program.
dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
if test "$cross_compiling" != no; then
AC_CHECK_TOOL([STRIP], [strip], :)
fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
# Copyright (C) 2006 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# _AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
# Prevent Automake from outputing VARIABLE = @VARIABLE@ in Makefile.in.
# This macro is traced by Automake.
AC_DEFUN([_AM_SUBST_NOTMAKE])
# Check how to create a tarball. -*- Autoconf -*-
# Copyright (C) 2004, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 2
# _AM_PROG_TAR(FORMAT)
# --------------------
# Check how to create a tarball in format FORMAT.
# FORMAT should be one of `v7', `ustar', or `pax'.
#
# Substitute a variable $(am__tar) that is a command
# writing to stdout a FORMAT-tarball containing the directory
# $tardir.
# tardir=directory && $(am__tar) > result.tar
#
# Substitute a variable $(am__untar) that extract such
# a tarball read from stdin.
# $(am__untar) < result.tar
AC_DEFUN([_AM_PROG_TAR],
[# Always define AMTAR for backward compatibility.
AM_MISSING_PROG([AMTAR], [tar])
m4_if([$1], [v7],
[am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
[m4_case([$1], [ustar],, [pax],,
[m4_fatal([Unknown tar format])])
AC_MSG_CHECKING([how to create a $1 tar archive])
# Loop over all known methods to create a tar archive until one works.
_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
_am_tools=${am_cv_prog_tar_$1-$_am_tools}
# Do not fold the above two line into one, because Tru64 sh and
# Solaris sh will not grok spaces in the rhs of `-'.
for _am_tool in $_am_tools
do
case $_am_tool in
gnutar)
for _am_tar in tar gnutar gtar;
do
AM_RUN_LOG([$_am_tar --version]) && break
done
am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
am__untar="$_am_tar -xf -"
;;
plaintar)
# Must skip GNU tar: if it does not support --format= it doesn't create
# ustar tarball either.
(tar --version) >/dev/null 2>&1 && continue
am__tar='tar chf - "$$tardir"'
am__tar_='tar chf - "$tardir"'
am__untar='tar xf -'
;;
pax)
am__tar='pax -L -x $1 -w "$$tardir"'
am__tar_='pax -L -x $1 -w "$tardir"'
am__untar='pax -r'
;;
cpio)
am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
am__untar='cpio -i -H $1 -d'
;;
none)
am__tar=false
am__tar_=false
am__untar=false
;;
esac
# If the value was cached, stop now. We just wanted to have am__tar
# and am__untar set.
test -n "${am_cv_prog_tar_$1}" && break
# tar/untar a dummy directory, and stop if the command works
rm -rf conftest.dir
mkdir conftest.dir
echo GrepMe > conftest.dir/file
AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
rm -rf conftest.dir
if test -s conftest.tar; then
AM_RUN_LOG([$am__untar <conftest.tar])
grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
fi
done
rm -rf conftest.dir
AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
AC_MSG_RESULT([$am_cv_prog_tar_$1])])
AC_SUBST([am__tar])
AC_SUBST([am__untar])
]) # _AM_PROG_TAR
m4_include([m4/c-compiler.m4])

View file

@ -0,0 +1,15 @@
#include <stdlib.h>
#include <stdio.h>
int isBigEndian()
{
unsigned char EndianTest[2] = {1,0};
short x = *(short *)EndianTest;
if( x == 1 )
return 0;
else
return 1;
}

View file

@ -0,0 +1 @@
extern int isBigEndian();

View file

@ -0,0 +1,100 @@
#include "tdconfig.h"
#include <stdio.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#include "cli_common.h"
#ifdef WIN32
# define HOME_ENV_NAME "USERPROFILE"
# define DEFAULT_EMPTY_HOME "C:"
#else
# define HOME_ENV_NAME "HOME"
# define DEFAULT_EMPTY_HOME ""
#endif
static const char MAK_DOTFILE_NAME[] = "/.tivodecode_mak";
/* TODO: make these not need to be globals */
int o_verbose = 0;
int o_no_verify = 0;
int get_mak_from_conf_file(char * mak)
{
char * mak_fname = NULL;
FILE * mak_file = NULL;
const char * home_dir = getenv(HOME_ENV_NAME);
size_t home_dir_len;
if (!home_dir)
home_dir = DEFAULT_EMPTY_HOME;
home_dir_len = strlen(home_dir);
mak_fname = malloc (home_dir_len + sizeof(MAK_DOTFILE_NAME));
if (!mak_fname)
{
fprintf(stderr, "error allocing string for mak config file name\n");
goto fail;
}
memcpy (mak_fname, home_dir, home_dir_len);
memcpy (mak_fname + home_dir_len, MAK_DOTFILE_NAME, sizeof(MAK_DOTFILE_NAME));
if ((mak_file = fopen(mak_fname, "r")))
{
if (fread(mak, 1, 11, mak_file) >= 10)
{
int i;
for (i = 11; i >= 10 && (mak[i] == '\0' || isspace((int)mak[i])); --i)
{
mak[i] = '\0';
}
}
else if (ferror(mak_file))
{
perror ("reading mak config file");
goto fail;
}
else
{
fprintf(stderr, "mak too short in mak config file\n");
goto fail;
}
fclose (mak_file);
mak_file = NULL;
}
else
goto fail;
free(mak_fname);
mak_fname = NULL;
return 1;
fail:
if (mak_file)
fclose(mak_file);
if (mak_fname)
free(mak_fname);
return 0;
}
void do_version(int exitval)
{
fprintf (stderr, "%s\n", PACKAGE_STRING);
fprintf (stderr, "Copyright (c) 2006-2007, Jeremy Drake\n");
fprintf (stderr, "See COPYING file in distribution for details\n\n");
PRINT_QUALCOMM_MSG();
exit (exitval);
}
/* vi:set ai ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,18 @@
#ifndef TD_CLI_COMMON_H__
#define TD_CLI_COMMON_H__
#ifdef WIN32
# include <fcntl.h>
#endif
#define PRINT_QUALCOMM_MSG() fprintf (stderr, "Encryption by QUALCOMM ;)\n\n")
/* TODO: make these not need to be globals */
extern int o_verbose;
extern int o_no_verify;
/* mak better be a 12-byte buffer */
int get_mak_from_conf_file(char * mak);
void do_version(int exitval);
#endif // TD_CLI_COMMON_H__

9413
src/tivomirror/tivodecode/configure vendored Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,110 @@
AC_INIT(tivodecode, 0.3pre4)
AC_CONFIG_SRCDIR(tivodecode.c)
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AC_CONFIG_HEADERS(tdconfig.h)
AC_PROG_CC
AC_PROG_CPP
AC_AIX
AC_ISC_POSIX
AC_MINIX
AC_HEADER_STDC
AC_C_BIGENDIAN
AC_C_INLINE
AC_PROG_RANLIB
AC_PROG_INSTALL
if test x"$ac_cv_c_compiler_gnu" = x"yes"; then
# ICC pretends to be GCC but it's lying; it doesn't support these options.
# So we have to check if "GCC" is really ICC.
AC_TRY_COMPILE([], [@%:@ifndef __INTEL_COMPILER
choke me
@%:@endif], [ICC=[yes]], [ICC=[no]])
if test "$ICC" = no; then
CFLAGS="$CFLAGS -Wall -Wpointer-arith -Winline"
PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
PGAC_PROG_CC_CFLAGS_OPT([-Werror-implicit-function-declaration])
fi
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
fi
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
AC_TYPE_OFF_T
AC_CHECK_SIZEOF(off_t)
AC_CHECK_TYPES([size_t], [AC_CHECK_SIZEOF([size_t])])
AC_CHECK_TYPES([unsigned long], [AC_CHECK_SIZEOF([unsigned long])])
AC_CHECK_TYPES([unsigned long long], [AC_CHECK_SIZEOF([unsigned long long])])
AC_CHECK_HEADERS([netinet/in.h winsock2.h getopt.h ctype.h], [], [], AC_INCLUDES_DEFAULT([]))
AC_SEARCH_LIBS(getopt_long, [getopt gnugetopt])
dnl BEGIN check for library containing ntohl - based on AC_SEARCH_LIBS
dnl but specific for ntohl to make it work on win32
dnl ntohl check {{{
AC_PREREQ([2.13])
AC_CACHE_CHECK([for library containing ntohl], [ac_cv_search_ntohl],
[ac_func_search_save_LIBS="$LIBS"
ac_cv_search_ntohl="no"
AC_TRY_LINK(dnl
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
],
[ntohl(42)],
[ac_cv_search_ntohl="none required"])
test "$ac_cv_search_ntohl" = "no" && for i in socket wsock32; do
LIBS="-l$i $ac_func_search_save_LIBS"
AC_TRY_LINK(dnl
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
],
[ntohl(42)],
[ac_cv_search_ntohl="-l$i"
break])
done
LIBS="$ac_func_search_save_LIBS"])
if test "$ac_cv_search_ntohl" != "no"; then
test "$ac_cv_search_ntohl" = "none required" || LIBS="$ac_cv_search_ntohl $LIBS"
fi
dnl }}} END check for library containing ntohl
AC_CHECK_TYPES([struct option], [], [],
[#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif])
AC_CACHE_CHECK([for optreset], pgac_cv_var_int_optreset,
[AC_TRY_LINK([#include <unistd.h>],
[extern int optreset; optreset = 1;],
[pgac_cv_var_int_optreset=yes],
[pgac_cv_var_int_optreset=no])])
if test x"$pgac_cv_var_int_optreset" = x"yes"; then
AC_DEFINE(HAVE_INT_OPTRESET, 1, [Define to 1 if you have the global variable 'int optreset'.])
fi
AC_REPLACE_FUNCS([getopt fseeko])
if test x"$ac_cv_type_struct_option" = xyes ; then
AC_REPLACE_FUNCS([getopt_long])
else
AC_LIBOBJ(getopt_long)
fi
AC_OUTPUT(Makefile)

584
src/tivomirror/tivodecode/depcomp Executable file
View file

@ -0,0 +1,584 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
scriptversion=2006-10-15.18
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
# Foundation, Inc.
# 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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, 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.
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
case $1 in
'')
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
Run PROGRAMS ARGS to compile a file, generating dependencies
as side-effects.
Environment variables:
depmode Dependency tracking mode.
source Source file read by `PROGRAMS ARGS'.
object Object file output by `PROGRAMS ARGS'.
DEPDIR directory where to store dependencies.
depfile Dependency file to output.
tmpdepfile Temporary file to use when outputing dependencies.
libtool Whether libtool is used (yes/no).
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "depcomp $scriptversion"
exit $?
;;
esac
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
fi
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
depfile=${depfile-`echo "$object" |
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
# Some modes work just like other modes, but use different flags. We
# parameterize here, but still list the modes in the big case below,
# to make depend.m4 easier to write. Note that we *cannot* use a case
# here, because this file can only contain one case statement.
if test "$depmode" = hp; then
# HP compiler uses -M and no extra arg.
gccflag=-M
depmode=gcc
fi
if test "$depmode" = dashXmstdout; then
# This is just like dashmstdout with a different argument.
dashmflag=-xM
depmode=dashmstdout
fi
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
## it if -MD -MP comes after the -MF stuff. Hmm.
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
## the command line argument order; so add the flags where they
## appear in depend2.am. Note that the slowdown incurred here
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
for arg
do
case $arg in
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
*) set fnord "$@" "$arg" ;;
esac
shift # fnord
shift # $arg
done
"$@"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
mv "$tmpdepfile" "$depfile"
;;
gcc)
## There are various ways to get dependency output from gcc. Here's
## why we pick this rather obscure method:
## - Don't want to use -MD because we'd like the dependencies to end
## up in a subdir. Having to rename by hand is ugly.
## (We might end up doing this anyway to support other compilers.)
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
## -MM, not -M (despite what the docs say).
## - Using -M directly means running the compiler twice (even worse
## than renaming).
if test -z "$gccflag"; then
gccflag=-MD,
fi
"$@" -Wp,"$gccflag$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
## The second -e expression handles DOS-style file names with drive letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the `deleted header file' problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
tr ' ' '
' < "$tmpdepfile" |
## Some versions of gcc put a space before the `:'. On the theory
## that the space means something, we add a space to the output as
## well.
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
sgi)
if test "$libtool" = yes; then
"$@" "-Wp,-MDupdate,$tmpdepfile"
else
"$@" -MDupdate "$tmpdepfile"
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
echo "$object : \\" > "$depfile"
# Clip off the initial element (the dependent). Don't try to be
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
# the IRIX cc adds comments like `#:fec' to the end of the
# dependency line.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
tr '
' ' ' >> $depfile
echo >> $depfile
# The second pass generates a dummy entry for each header file.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> $depfile
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. In older versions, this file always lives in the
# current directory. Also, the AIX compiler puts `$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
tmpdepfile="$stripped.u"
if test "$libtool" = yes; then
"$@" -Wc,-M
else
"$@" -M
fi
stat=$?
if test -f "$tmpdepfile"; then :
else
stripped=`echo "$stripped" | sed 's,^.*/,,'`
tmpdepfile="$stripped.u"
fi
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
if test -f "$tmpdepfile"; then
outname="$stripped.o"
# Each line is of the form `foo.o: dependent.h'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
icc)
# Intel's C compiler understands `-MD -MF file'. However on
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
# ICC 7.0 will fill foo.d with something like
# foo.o: sub/foo.c
# foo.o: sub/foo.h
# which is wrong. We want:
# sub/foo.o: sub/foo.c
# sub/foo.o: sub/foo.h
# sub/foo.c:
# sub/foo.h:
# ICC 7.1 will output
# foo.o: sub/foo.c sub/foo.h
# and will wrap long lines using \ :
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
"$@" -MD -MF "$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
# Each line is of the form `foo.o: dependent.h',
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this invocation
# correctly. Breaking it into two sed invocations is a workaround.
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp2)
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
# compilers, which have integrated preprocessors. The correct option
# to use with these is +Maked; it writes dependencies to a file named
# 'foo.d', which lands next to the object file, wherever that
# happens to be.
# Much of this is similar to the tru64 case; see comments there.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir.libs/$base.d
"$@" -Wc,+Maked
else
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir$base.d
"$@" +Maked
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
# Add `dependent.h:' lines.
sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile" "$tmpdepfile2"
;;
tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
# dependencies in `foo.d' instead, so we check for that too.
# Subdirectories are respected.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then
# With Tru64 cc, shared objects can also be used to make a
# static library. This mechanism is used in libtool 1.4 series to
# handle both shared and static libraries in a single compilation.
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
#
# With libtool 1.5 this exception was removed, and libtool now
# generates 2 separate objects for the 2 libraries. These two
# compilations output dependencies in $dir.libs/$base.o.d and
# in $dir$base.o.d. We have to check for both files, because
# one of the two compilations can be disabled. We should prefer
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
# automatically cleaned when .libs/ is deleted, while ignoring
# the former would cause a distcleancheck panic.
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
tmpdepfile2=$dir$base.o.d # libtool 1.5
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
"$@" -Wc,-MD
else
tmpdepfile1=$dir$base.o.d
tmpdepfile2=$dir$base.d
tmpdepfile3=$dir$base.d
tmpdepfile4=$dir$base.d
"$@" -MD
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
# That's a tab and a space in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
#nosideeffect)
# This comment above is used by automake to tell side-effect
# dependency tracking mechanisms from slower ones.
dashmstdout)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# Remove `-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
test -z "$dashmflag" && dashmflag=-M
# Require at least two characters before searching for `:'
# in the target name. This is to cope with DOS-style filenames:
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
"$@" $dashmflag |
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
tr ' ' '
' < "$tmpdepfile" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
dashXmstdout)
# This case only exists to satisfy depend.m4. It is never actually
# run, as this mode is specially recognized in the preamble.
exit 1
;;
makedepend)
"$@" || exit $?
# Remove any Libtool call
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# X makedepend
shift
cleared=no
for arg in "$@"; do
case $cleared in
no)
set ""; shift
cleared=yes ;;
esac
case "$arg" in
-D*|-I*)
set fnord "$@" "$arg"; shift ;;
# Strip any option that makedepend may not understand. Remove
# the object too, otherwise makedepend will parse it as a source file.
-*|$object)
;;
*)
set fnord "$@" "$arg"; shift ;;
esac
done
obj_suffix="`echo $object | sed 's/^.*\././'`"
touch "$tmpdepfile"
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
sed '1,2d' "$tmpdepfile" | tr ' ' '
' | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile" "$tmpdepfile".bak
;;
cpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# Remove `-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
"$@" -E |
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
sed '$ s: \\$::' > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
cat < "$tmpdepfile" >> "$depfile"
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
msvisualcpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o,
# because we must use -o when running libtool.
"$@" || exit $?
IFS=" "
for arg
do
case "$arg" in
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
set fnord "$@"
shift
shift
;;
*)
set fnord "$@" "$arg"
shift
shift
;;
esac
done
"$@" -E |
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
echo " " >> "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;
none)
exec "$@"
;;
*)
echo "Unknown depmode $depmode" 1>&2
exit 1
;;
esac
exit 0
# 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:

View file

@ -0,0 +1,126 @@
/*-------------------------------------------------------------------------
*
* fseeko.c
* 64-bit versions of fseeko/ftello()
*
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/fseeko.c,v 1.20 2006/03/05 15:59:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* We have to use the native defines here because configure hasn't
* completed yet.
*/
#if defined(__bsdi__) || defined(__NetBSD__) || defined(WIN32)
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include <errno.h>
#include <stdio.h>
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef WIN32
# include <io.h>
#endif
#ifdef bsdi
# include <pthread.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef WIN32
# define OFF_T_TYPE __int64
#else
# define OFF_T_TYPE off_t
#endif
/*
* On BSD/OS and NetBSD, off_t and fpos_t are the same. Standards
* say off_t is an arithmetic type, but not necessarily integral,
* while fpos_t might be neither.
*
* This is thread-safe on BSD/OS using flockfile/funlockfile.
*/
int
fseeko(FILE *stream, OFF_T_TYPE offset, int whence)
{
fpos_t floc;
#ifndef WIN32
struct stat filestat;
#endif
switch (whence)
{
case SEEK_CUR:
#ifdef bsdi
flockfile(stream);
#endif
if (fgetpos(stream, &floc) != 0)
goto failure;
floc += offset;
break;
case SEEK_SET:
floc = offset;
break;
case SEEK_END:
#ifdef bsdi
flockfile(stream);
#endif
fflush(stream); /* force writes to fd for stat() */
#ifdef WIN32
floc = _filelengthi64(_fileno(stream));
#else
if (fstat(fileno(stream), &filestat) != 0)
goto failure;
floc = filestat.st_size;
#endif
floc += offset;
break;
default:
errno = EINVAL;
return -1;
}
if (fsetpos(stream, &floc) != 0)
goto failure;
#ifdef bsdi
funlockfile(stream);
#endif
return 0;
failure:
#ifdef bsdi
funlockfile(stream);
#endif
return -1;
}
OFF_T_TYPE
ftello(FILE *stream)
{
fpos_t floc;
if (fgetpos(stream, &floc) != 0)
return -1;
return floc;
}
#endif

View file

@ -0,0 +1,24 @@
#ifndef FSEEKO_H_
# define FSEEKO_H_
#ifdef __cplusplus
extern "C" {
#endif
# if !defined(HAVE_FSEEKO) && (defined(__bsdi__) || defined(__NetBSD__) || defined(WIN32))
# ifdef WIN32
# define OFF_T_TYPE __int64
# else
# define OFF_T_TYPE off_t
# endif
extern int fseeko(FILE *stream, OFF_T_TYPE offset, int whence);
extern OFF_T_TYPE ftello(FILE *stream);
# define HAVE_FSEEKO 1
# endif
#ifdef __cplusplus
}
#endif
#endif // FSEEKO_H_

View file

@ -0,0 +1,126 @@
/* $PostgreSQL: pgsql/src/port/getopt.c,v 1.10 2006/03/11 04:38:40 momjian Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS 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
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <stdio.h>
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt
* Parse argc/argv argument vector.
*/
int
getopt(nargc, nargv, ostr)
int nargc;
char *const * nargv;
const char *ostr;
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place)
{ /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-')
{
place = EMSG;
return -1;
}
if (place[1] && *++place == '-' && place[1] == '\0')
{ /* found "--" */
++optind;
place = EMSG;
return -1;
}
} /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' ||
!(oli = strchr(ostr, optopt)))
{
/*
* if the user didn't specify '-' as an option, assume it means -1.
*/
if (optopt == (int) '-')
return -1;
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void) fprintf(stderr,
"illegal option -- %c\n", optopt);
return BADCH;
}
if (*++oli != ':')
{ /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else
{ /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind)
{ /* no arg */
place = EMSG;
if (*ostr == ':')
return BADARG;
if (opterr)
(void) fprintf(stderr,
"option requires an argument -- %c\n",
optopt);
return BADCH;
}
else
/* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return optopt; /* dump back option letter */
}

View file

@ -0,0 +1,203 @@
/*
* getopt_long() -- long options parser
*
* Portions Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Portions Copyright (c) 2003
* PostgreSQL Global Development Group
*
* 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS 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.
*
* $PostgreSQL: pgsql/src/port/getopt_long.c,v 1.5 2005/10/15 02:49:51 momjian Exp $
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include "getopt_long.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <stdio.h>
#ifndef HAVE_INT_OPTRESET
int optreset;
#endif
#define BADCH '?'
#define BADARG ':'
#define EMSG ""
int
getopt_long(int argc, char *const argv[],
const char *optstring,
const struct option * longopts, int *longindex)
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place)
{ /* update scanning pointer */
optreset = 0;
if (optind >= argc)
{
place = EMSG;
return -1;
}
place = argv[optind];
if (place[0] != '-')
{
place = EMSG;
return -1;
}
place++;
if (place[0] && place[0] == '-' && place[1] == '\0')
{ /* found "--" */
++optind;
place = EMSG;
return -1;
}
if (place[0] && place[0] == '-' && place[1])
{
/* long option */
size_t namelen;
int i;
place++;
namelen = strcspn(place, "=");
for (i = 0; longopts[i].name != NULL; i++)
{
if (strlen(longopts[i].name) == namelen
&& strncmp(place, longopts[i].name, namelen) == 0)
{
if (longopts[i].has_arg)
{
if (place[namelen] == '=')
optarg = place + namelen + 1;
else if (optind < argc - 1)
{
optind++;
optarg = argv[optind];
}
else
{
if (optstring[0] == ':')
return BADARG;
if (opterr)
fprintf(stderr,
"%s: option requires an argument -- %s\n",
argv[0], place);
place = EMSG;
optind++;
return BADCH;
}
}
else
{
optarg = NULL;
if (place[namelen] != 0)
{
/* XXX error? */
}
}
optind++;
if (longindex)
*longindex = i;
place = EMSG;
if (longopts[i].flag == NULL)
return longopts[i].val;
else
{
*longopts[i].flag = longopts[i].val;
return 0;
}
}
}
if (opterr && optstring[0] != ':')
fprintf(stderr,
"%s: illegal option -- %s\n", argv[0], place);
place = EMSG;
optind++;
return BADCH;
}
}
/* short option */
optopt = (int) *place++;
oli = strchr(optstring, optopt);
if (!oli)
{
if (!*place)
++optind;
if (opterr && *optstring != ':')
fprintf(stderr,
"%s: illegal option -- %c\n", argv[0], optopt);
return BADCH;
}
if (oli[1] != ':')
{ /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else
{ /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (argc <= ++optind)
{ /* no arg */
place = EMSG;
if (*optstring == ':')
return BADARG;
if (opterr)
fprintf(stderr,
"%s: option requires an argument -- %c\n",
argv[0], optopt);
return BADCH;
}
else
/* white space */
optarg = argv[optind];
place = EMSG;
++optind;
}
return optopt;
}

View file

@ -0,0 +1,54 @@
/*
* Portions Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Portions Copyright (c) 2003-2006, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/getopt_long.h,v 1.6 2005/01/01 20:44:26 tgl Exp $
*/
#ifndef GETOPT_LONG_H
#define GETOPT_LONG_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
/* These are picked up from the system's getopt() facility. */
extern int opterr;
extern int optind;
extern int optopt;
extern char *optarg;
#endif
#if !defined(HAVE_GETOPT) || !defined(HAVE_INT_OPTRESET)
/* Some systems have this, otherwise you need to define it somewhere. */
extern int optreset;
#endif
#ifndef HAVE_STRUCT_OPTION
struct option
{
const char *name;
int has_arg;
int *flag;
int val;
};
#define no_argument 0
#define required_argument 1
#endif
#ifndef HAVE_GETOPT_LONG
extern int getopt_long(int argc, char *const argv[],
const char *optstring,
const struct option * longopts, int *longindex);
#endif
#ifdef __cplusplus
}
#endif
#endif /* GETOPT_LONG_H */

View file

@ -0,0 +1,188 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include <errno.h>
#include <stdio.h>
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef WIN32
# include <io.h>
#endif
#include "fseeko.h"
#include "happyfile.h"
#if defined HAVE_FSEEKO
# define hftell(a) ftello(a)
# define hfseek(a, b, c) fseeko(a, b, c)
#else
# define hftell(a) ftell(a)
# define hfseek(a, b, c) fseek(a, b, c)
# warning Large file support is questionable on this platform
#endif
happy_file * hopen (char * filename, char * mode)
{
happy_file * fh = malloc (sizeof (happy_file));
fh->fh = fopen (filename, mode);
if (!fh->fh)
{
free (fh);
return NULL;
}
fh->pos = 0;
fh->buffer_start = 0;
fh->buffer_fill = 0;
return fh;
}
happy_file * hattach (FILE * fh)
{
happy_file * hfh = malloc (sizeof (happy_file));
hfh->fh = fh;
hfh->pos = 0;
hfh->buffer_start = 0;
hfh->buffer_fill = 0;
return hfh;
}
int hclose(happy_file * fh)
{
int x = fclose (fh->fh);
free (fh);
return x;
}
int hdetach(happy_file * fh)
{
free(fh);
return 0;
}
size_t hread (void * ptr, size_t size, happy_file * fh)
{
size_t nbytes = 0;
if (size == 0)
return 0;
if ((fh->pos + (hoff_t)size) - fh->buffer_start <= fh->buffer_fill)
{
memcpy (ptr, fh->buffer + (fh->pos - fh->buffer_start), size);
fh->pos += (hoff_t)size;
return size;
}
else if (fh->pos < fh->buffer_start + fh->buffer_fill)
{
memcpy (ptr, fh->buffer + (fh->pos - fh->buffer_start), (size_t)(fh->buffer_fill - (fh->pos - fh->buffer_start)));
nbytes += (size_t)(fh->buffer_fill - (fh->pos - fh->buffer_start));
}
do
{
fh->buffer_start += fh->buffer_fill;
fh->buffer_fill = (hoff_t)fread (fh->buffer, 1, BUFFERSIZE, fh->fh);
if (fh->buffer_fill == 0)
break;
memcpy((char *)ptr + nbytes, fh->buffer, ((hoff_t)(size - nbytes) < fh->buffer_fill ? (size - nbytes) : (size_t)fh->buffer_fill));
nbytes += ((hoff_t)(size - nbytes) < fh->buffer_fill ? (size - nbytes) : (size_t)fh->buffer_fill);
} while (nbytes < size);
fh->pos += (hoff_t)nbytes;
return nbytes;
}
hoff_t htell (happy_file * fh)
{
return fh->pos;
}
int hseek (happy_file * fh, hoff_t offset, int whence)
{
static char junk_buf[4096];
register int r;
switch (whence)
{
case SEEK_SET:
if (offset < fh->pos)
{
r = hfseek (fh->fh, offset, SEEK_SET);
if (r < 0)
return r;
fh->pos = offset;
fh->buffer_start = fh->pos;
fh->buffer_fill = 0;
return r;
}
else
{
int t = (int)((offset - fh->pos) & 0xfff);
hoff_t u = (offset - fh->pos) >> 12;
hoff_t s;
for (s=0; s < u; s++)
{
if (hread(junk_buf, 4096, fh) != 4096)
return -1;
}
if (hread(junk_buf, t, fh) != t)
{
return -1;
}
return 0;
}
break;
case SEEK_CUR:
if (offset < 0)
{
r = hfseek (fh->fh, offset, SEEK_CUR);
if (r < 0)
return r;
fh->pos += offset;
fh->buffer_start = fh->pos;
fh->buffer_fill = 0;
return r;
}
else
{
int t = (int)(offset & 0xfff);
hoff_t u = offset >> 12;
hoff_t s;
for (s=0; s < u; s++)
{
if (hread(junk_buf, 4096, fh) != 4096)
return -1;
}
if (hread(junk_buf, t, fh) != t)
{
return -1;
}
return 0;
}
break;
case SEEK_END:
r = hfseek (fh->fh, offset,whence);
fh->pos = hftell(fh->fh);
fh->buffer_start = fh->pos;
fh->buffer_fill = 0;
return r;
default:
errno=EINVAL;
return -1;
}
}

View file

@ -0,0 +1,69 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifndef HAPPY_FILE_H_
#define HAPPY_FILE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(WIN32)
# include <io.h>
#endif
#ifndef BUFFERSIZE
#define BUFFERSIZE 4096
#endif
#if SIZEOF_OFF_T == 8
typedef off_t hoff_t;
#elif defined (WIN32)
typedef __int64 hoff_t;
#else
#warning Large file support is questionable on this platform
typedef off_t hoff_t;
#endif
typedef struct
{
FILE * fh;
hoff_t pos;
/* buffer stuff */
hoff_t buffer_start;
hoff_t buffer_fill;
char buffer[BUFFERSIZE];
} happy_file;
happy_file * hopen (char * filename, char * mode);
happy_file * hattach (FILE * fh);
int hclose(happy_file * fh);
int hdetach(happy_file * fh);
size_t hread (void * ptr, size_t size, happy_file * fh);
size_t hwrite (const void * ptr, size_t size, happy_file * fh);
hoff_t htell (happy_file * fh);
int hseek (happy_file * fh, hoff_t offset, int whence);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,108 @@
/* useful hex manipulation routines */
/* Copyright C Qualcomm Inc 1997 */
/* @(#)hexlib.c 1.1 (AHAG) 02/08/23 */
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "hexlib.h"
#include <ctype.h>
int nerrors;
static char *hex = "0123456789abcdef";
#define HEX(c) ((int)(strchr(hex, (c)) - hex))
int
hexprint(const char *s, unsigned char *p, int n)
{
printf("%14s:", s);
while (--n >= 0) {
if (n % 20 == 19)
printf("\n%14s ", "");
printf(" %02x", *p++);
}
printf("\n");
return 0;
}
int
hexread(unsigned char *buf, char *p, int n)
{
int i;
while (--n >= 0) {
while (*p == ' ') ++p;
i = HEX(*p++) << 4;
i += HEX(*p++);
*buf++ = i;
}
return 0;
}
int
hexcheck(unsigned char *buf, char *p, int n)
{
int i;
while (--n >= 0) {
while (*p == ' ') ++p;
i = HEX(*p++) << 4;
i += HEX(*p++);
if (*buf++ != i) {
printf("Expected %02x, got %02x.\n", i, buf[-1]);
++nerrors;
}
}
return nerrors;
}
#define COLS 16
int
hexbulk(unsigned char *buf, int n)
{
int i=0;
int j=0;
char ch;
char hexdigit[5];
char strdigit[5];
char hexstr[100];
char strstr[100];
while ( i<n )
{
memset(hexstr, 0, 100);
memset(strstr, 0, 100);
for(j=0; (j<COLS) && (i<n); j++, i++ )
{
if ( isspace(buf[i]) )
ch = ' ';
else if ( isprint( buf[i]))
ch = buf[i];
else
ch = '.';
sprintf( hexdigit, "%02x ", buf[i] );
sprintf( strdigit, "%c", ch);
strcat( hexstr, hexdigit );
strcat( strstr, strdigit );
}
while(j<COLS)
{
strcat( hexstr, " " );
j++;
}
printf("%s %s\n", hexstr, strstr);
}
return 0;
}

View file

@ -0,0 +1,16 @@
/* useful hex manipulation routine header */
/* Copyright C Qualcomm Inc 1997 */
/* @(#)hexlib.h 1.1 (AHAG) 02/08/23 */
#ifdef __cplusplus
extern "C" {
#endif
extern int nerrors;
int hexprint(const char *, unsigned char *, int n);
int hexread(unsigned char *, char *, int n);
int hexcheck(unsigned char *, char *, int n);
int hexbulk(unsigned char *, int n);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,507 @@
#!/bin/sh
# install - install a program, script, or datafile
scriptversion=2006-10-14.15
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
nl='
'
IFS=" "" $nl"
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
if test -z "$doit"; then
doit_exec=exec
else
doit_exec=$doit
fi
# Put in absolute file names if you don't have them in your path;
# or use environment vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
posix_glob=
posix_mkdir=
# Desired mode of installed file.
mode=0755
chmodcmd=$chmodprog
chowncmd=
chgrpcmd=
stripcmd=
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=
dst=
dir_arg=
dstarg=
no_target_directory=
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES...
In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.
Options:
-c (ignored)
-d create directories instead of installing files.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE.
-o USER $chownprog installed files to USER.
-s $stripprog installed files.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
--help display this help and exit.
--version display version info and exit.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
"
while test $# -ne 0; do
case $1 in
-c) shift
continue;;
-d) dir_arg=true
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
--help) echo "$usage"; exit $?;;
-m) mode=$2
shift
shift
case $mode in
*' '* | *' '* | *'
'* | *'*'* | *'?'* | *'['*)
echo "$0: invalid mode: $mode" >&2
exit 1;;
esac
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-s) stripcmd=$stripprog
shift
continue;;
-t) dstarg=$2
shift
shift
continue;;
-T) no_target_directory=true
shift
continue;;
--version) echo "$0 $scriptversion"; exit $?;;
--) shift
break;;
-*) echo "$0: invalid option: $1" >&2
exit 1;;
*) break;;
esac
done
if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
# When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dstarg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dstarg"
shift # fnord
fi
shift # arg
dstarg=$arg
done
fi
if test $# -eq 0; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call `install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
if test -z "$dir_arg"; then
trap '(exit $?); exit' 1 2 13 15
# Set umask so as not to create temps with too-generous modes.
# However, 'strip' requires both read and write access to temps.
case $mode in
# Optimize common cases.
*644) cp_umask=133;;
*755) cp_umask=22;;
*[0-7])
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw='% 200'
fi
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
*)
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw=,u+rw
fi
cp_umask=$mode$u_plus_rw;;
esac
fi
for src
do
# Protect names starting with `-'.
case $src in
-*) src=./$src ;;
esac
if test -n "$dir_arg"; then
dst=$src
dstdir=$dst
test -d "$dstdir"
dstdir_status=$?
else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dstarg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dstarg
# Protect names starting with `-'.
case $dst in
-*) dst=./$dst ;;
esac
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
if test -n "$no_target_directory"; then
echo "$0: $dstarg: Is a directory" >&2
exit 1
fi
dstdir=$dst
dst=$dstdir/`basename "$src"`
dstdir_status=0
else
# Prefer dirname, but fall back on a substitute if dirname fails.
dstdir=`
(dirname "$dst") 2>/dev/null ||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$dst" : 'X\(//\)[^/]' \| \
X"$dst" : 'X\(//\)$' \| \
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
echo X"$dst" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'
`
test -d "$dstdir"
dstdir_status=$?
fi
fi
obsolete_mkdir_used=false
if test $dstdir_status != 0; then
case $posix_mkdir in
'')
# Create intermediate dirs using mode 755 as modified by the umask.
# This is like FreeBSD 'install' as of 1997-10-28.
umask=`umask`
case $stripcmd.$umask in
# Optimize common cases.
*[2367][2367]) mkdir_umask=$umask;;
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
*[0-7])
mkdir_umask=`expr $umask + 22 \
- $umask % 100 % 40 + $umask % 20 \
- $umask % 10 % 4 + $umask % 2
`;;
*) mkdir_umask=$umask,go-w;;
esac
# With -d, create the new directory with the user-specified mode.
# Otherwise, rely on $mkdir_umask.
if test -n "$dir_arg"; then
mkdir_mode=-m$mode
else
mkdir_mode=
fi
posix_mkdir=false
case $umask in
*[123567][0-7][0-7])
# POSIX mkdir -p sets u+wx bits regardless of umask, which
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
;;
*)
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
if (umask $mkdir_umask &&
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writeable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
ls_ld_tmpdir=`ls -ld "$tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
rmdir "$tmpdir/d" "$tmpdir"
else
# Remove any dirs left behind by ancient mkdir implementations.
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
fi
trap '' 0;;
esac;;
esac
if
$posix_mkdir && (
umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
)
then :
else
# The umask is ridiculous, or mkdir does not conform to POSIX,
# or it failed possibly due to a race condition. Create the
# directory the slow way, step by step, checking for races as we go.
case $dstdir in
/*) prefix=/ ;;
-*) prefix=./ ;;
*) prefix= ;;
esac
case $posix_glob in
'')
if (set -f) 2>/dev/null; then
posix_glob=true
else
posix_glob=false
fi ;;
esac
oIFS=$IFS
IFS=/
$posix_glob && set -f
set fnord $dstdir
shift
$posix_glob && set +f
IFS=$oIFS
prefixes=
for d
do
test -z "$d" && continue
prefix=$prefix$d
if test -d "$prefix"; then
prefixes=
else
if $posix_mkdir; then
(umask=$mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
# Don't fail if two instances are running concurrently.
test -d "$prefix" || exit 1
else
case $prefix in
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
*) qprefix=$prefix;;
esac
prefixes="$prefixes '$qprefix'"
fi
fi
prefix=$prefix/
done
if test -n "$prefixes"; then
# Don't fail if two instances are running concurrently.
(umask $mkdir_umask &&
eval "\$doit_exec \$mkdirprog $prefixes") ||
test -d "$dstdir" || exit 1
obsolete_mkdir_used=true
fi
fi
fi
if test -n "$dir_arg"; then
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
else
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
# Copy the file name to the temp name.
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# Now rename the file to the real destination.
{ $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
|| {
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
if test -f "$dst"; then
$doit $rmcmd -f "$dst" 2>/dev/null \
|| { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
&& { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
|| {
echo "$0: cannot unlink or rename $dst" >&2
(exit 1); exit 1
}
else
:
fi
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dst"
}
} || exit 1
trap '' 0
fi
done
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View file

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="libtdcommon"
ProjectGUID="{491A7F57-2E09-492E-9E44-70A34A313611}"
RootNamespace="libtdcommon"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="0"
BuildLogFile="$(IntDir)\libtdcommon_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\libtdcommon.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="0"
WholeProgramOptimization="1"
BuildLogFile="$(IntDir)\libtdcommon_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\libtdcommon.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\cli_common.c"
>
</File>
<File
RelativePath=".\fseeko.c"
>
</File>
<File
RelativePath=".\getopt.c"
>
</File>
<File
RelativePath=".\getopt_long.c"
>
</File>
<File
RelativePath=".\happyfile.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\cli_common.h"
>
</File>
<File
RelativePath=".\fseeko.h"
>
</File>
<File
RelativePath=".\getopt_long.h"
>
</File>
<File
RelativePath=".\happyfile.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,252 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="libtivodecode"
ProjectGUID="{9DDBB216-6D06-47EB-B559-B3FB02510DC3}"
RootNamespace="libtivodecode"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
<ToolFile
RelativePath=".\tivodecode.rules"
/>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="0"
BuildLogFile="$(IntDir)\libtivodecode_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="copy win32 file"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\libtivodecode.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="0"
WholeProgramOptimization="1"
BuildLogFile="$(IntDir)\libtivodecode_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="copy win32 file"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
WholeProgramOptimization="false"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\libtivodecode.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\hexlib.c"
>
</File>
<File
RelativePath=".\md5.c"
>
</File>
<File
RelativePath=".\sha1.c"
>
</File>
<File
RelativePath=".\tivo-parse.c"
>
</File>
<File
RelativePath=".\tivodecoder.c"
>
</File>
<File
RelativePath=".\turing_stream.c"
>
</File>
<File
RelativePath=".\TuringFast.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\hexlib.h"
>
</File>
<File
RelativePath=".\md5.h"
>
</File>
<File
RelativePath=".\QUTsbox.h"
>
</File>
<File
RelativePath=".\sha1.h"
>
</File>
<File
RelativePath=".\tdconfig.h.win32"
>
</File>
<File
RelativePath=".\tivo-parse.h"
>
</File>
<File
RelativePath=".\tivodecoder.h"
>
</File>
<File
RelativePath=".\Turing.h"
>
</File>
<File
RelativePath=".\turing_stream.h"
>
</File>
<File
RelativePath=".\TuringMultab.h"
>
</File>
<File
RelativePath=".\TuringSbox.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,13 @@
# PGAC_PROG_CC_CFLAGS_OPT
# -----------------------
# Given a string, check if the compiler supports the string as a
# command-line option. If it does, add the string to CFLAGS.
AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
[AC_MSG_CHECKING([if $CC supports $1])
pgac_save_CFLAGS=$CFLAGS
CFLAGS="$pgac_save_CFLAGS $1"
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
AC_MSG_RESULT(yes),
[CFLAGS="$pgac_save_CFLAGS"
AC_MSG_RESULT(no)])
])# PGAC_PROG_CC_CFLAGS_OPT

View file

@ -0,0 +1,405 @@
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* 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. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 THE PROJECT 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.
*
* $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.13 2005/07/11 15:07:59 tgl Exp $
*/
#include "tdconfig.h"
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "md5.h"
#define SHIFT(X, s) (((X) << (s)) | ((X) >> (32 - (s))))
#define F(X, Y, Z) (((X) & (Y)) | ((~X) & (Z)))
#define G(X, Y, Z) (((X) & (Z)) | ((Y) & (~Z)))
#define H(X, Y, Z) ((X) ^ (Y) ^ (Z))
#define I(X, Y, Z) ((Y) ^ ((X) | (~Z)))
#define ROUND1(a, b, c, d, k, s, i) \
do { \
(a) = (a) + F((b), (c), (d)) + X[(k)] + T[(i)]; \
(a) = SHIFT((a), (s)); \
(a) = (b) + (a); \
} while (0)
#define ROUND2(a, b, c, d, k, s, i) \
do { \
(a) = (a) + G((b), (c), (d)) + X[(k)] + T[(i)]; \
(a) = SHIFT((a), (s)); \
(a) = (b) + (a); \
} while (0)
#define ROUND3(a, b, c, d, k, s, i) \
do { \
(a) = (a) + H((b), (c), (d)) + X[(k)] + T[(i)]; \
(a) = SHIFT((a), (s)); \
(a) = (b) + (a); \
} while (0)
#define ROUND4(a, b, c, d, k, s, i) \
do { \
(a) = (a) + I((b), (c), (d)) + X[(k)] + T[(i)]; \
(a) = SHIFT((a), (s)); \
(a) = (b) + (a); \
} while (0)
#define Sa 7
#define Sb 12
#define Sc 17
#define Sd 22
#define Se 5
#define Sf 9
#define Sg 14
#define Sh 20
#define Si 4
#define Sj 11
#define Sk 16
#define Sl 23
#define Sm 6
#define Sn 10
#define So 15
#define Sp 21
#define MD5_A0 0x67452301
#define MD5_B0 0xefcdab89
#define MD5_C0 0x98badcfe
#define MD5_D0 0x10325476
/* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
static const unsigned int T[65] = {
0,
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
};
static const unsigned char md5_paddat[MD5_BUFLEN] = {
0x80, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
static void md5_calc(unsigned char *, md5_ctxt *);
void
md5_init(md5_ctxt * ctxt)
{
ctxt->md5_nl = 0;
ctxt->md5_nh = 0;
ctxt->md5_i = 0;
ctxt->md5_sta = MD5_A0;
ctxt->md5_stb = MD5_B0;
ctxt->md5_stc = MD5_C0;
ctxt->md5_std = MD5_D0;
memset(ctxt->md5_buf, 0, sizeof(ctxt->md5_buf));
}
void
md5_loop(md5_ctxt * ctxt, const unsigned char *input, size_t len)
{
unsigned int gap,
i;
if (ctxt->md5_nl + len * 8 < ctxt->md5_nl)
ctxt->md5_nh++;
ctxt->md5_nl += (unsigned int)len * 8; /* byte to bit */
gap = MD5_BUFLEN - ctxt->md5_i;
if (len >= gap)
{
memmove(ctxt->md5_buf + ctxt->md5_i, input, gap);
md5_calc(ctxt->md5_buf, ctxt);
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN)
md5_calc((unsigned char *) (input + i), ctxt);
ctxt->md5_i = (unsigned int)len - i;
memmove(ctxt->md5_buf, input + i, ctxt->md5_i);
}
else
{
memmove(ctxt->md5_buf + ctxt->md5_i, input, len);
ctxt->md5_i += (unsigned int)len;
}
}
void
md5_pad(md5_ctxt * ctxt)
{
unsigned int gap;
/* Don't count up padding. Keep md5_n. */
gap = MD5_BUFLEN - ctxt->md5_i;
if (gap > 8)
{
memmove(ctxt->md5_buf + ctxt->md5_i, md5_paddat,
gap - sizeof(ctxt->md5_n8));
}
else
{
/* including gap == 8 */
memmove(ctxt->md5_buf + ctxt->md5_i, md5_paddat, gap);
md5_calc(ctxt->md5_buf, ctxt);
memmove(ctxt->md5_buf, md5_paddat + gap,
MD5_BUFLEN - sizeof(ctxt->md5_n8));
}
/* 8 byte word */
#ifndef WORDS_BIGENDIAN
memmove(&ctxt->md5_buf[56], &ctxt->md5_n8[0], 8);
#else
ctxt->md5_buf[56] = ctxt->md5_n8[3];
ctxt->md5_buf[57] = ctxt->md5_n8[2];
ctxt->md5_buf[58] = ctxt->md5_n8[1];
ctxt->md5_buf[59] = ctxt->md5_n8[0];
ctxt->md5_buf[60] = ctxt->md5_n8[7];
ctxt->md5_buf[61] = ctxt->md5_n8[6];
ctxt->md5_buf[62] = ctxt->md5_n8[5];
ctxt->md5_buf[63] = ctxt->md5_n8[4];
#endif
md5_calc(ctxt->md5_buf, ctxt);
}
void
md5_result(unsigned char *digest, md5_ctxt * ctxt)
{
/* 4 byte words */
#ifndef WORDS_BIGENDIAN
memmove(digest, &ctxt->md5_st8[0], 16);
#else
digest[0] = ctxt->md5_st8[3];
digest[1] = ctxt->md5_st8[2];
digest[2] = ctxt->md5_st8[1];
digest[3] = ctxt->md5_st8[0];
digest[4] = ctxt->md5_st8[7];
digest[5] = ctxt->md5_st8[6];
digest[6] = ctxt->md5_st8[5];
digest[7] = ctxt->md5_st8[4];
digest[8] = ctxt->md5_st8[11];
digest[9] = ctxt->md5_st8[10];
digest[10] = ctxt->md5_st8[9];
digest[11] = ctxt->md5_st8[8];
digest[12] = ctxt->md5_st8[15];
digest[13] = ctxt->md5_st8[14];
digest[14] = ctxt->md5_st8[13];
digest[15] = ctxt->md5_st8[12];
#endif
}
#ifdef WORDS_BIGENDIAN
static unsigned int X[16];
#endif
static void
md5_calc(unsigned char *b64, md5_ctxt * ctxt)
{
unsigned int A = ctxt->md5_sta;
unsigned int B = ctxt->md5_stb;
unsigned int C = ctxt->md5_stc;
unsigned int D = ctxt->md5_std;
#ifndef WORDS_BIGENDIAN
unsigned int *X = (unsigned int *) b64;
#else
/* 4 byte words */
/* what a brute force but fast! */
unsigned char *y = (unsigned char *) X;
y[0] = b64[3];
y[1] = b64[2];
y[2] = b64[1];
y[3] = b64[0];
y[4] = b64[7];
y[5] = b64[6];
y[6] = b64[5];
y[7] = b64[4];
y[8] = b64[11];
y[9] = b64[10];
y[10] = b64[9];
y[11] = b64[8];
y[12] = b64[15];
y[13] = b64[14];
y[14] = b64[13];
y[15] = b64[12];
y[16] = b64[19];
y[17] = b64[18];
y[18] = b64[17];
y[19] = b64[16];
y[20] = b64[23];
y[21] = b64[22];
y[22] = b64[21];
y[23] = b64[20];
y[24] = b64[27];
y[25] = b64[26];
y[26] = b64[25];
y[27] = b64[24];
y[28] = b64[31];
y[29] = b64[30];
y[30] = b64[29];
y[31] = b64[28];
y[32] = b64[35];
y[33] = b64[34];
y[34] = b64[33];
y[35] = b64[32];
y[36] = b64[39];
y[37] = b64[38];
y[38] = b64[37];
y[39] = b64[36];
y[40] = b64[43];
y[41] = b64[42];
y[42] = b64[41];
y[43] = b64[40];
y[44] = b64[47];
y[45] = b64[46];
y[46] = b64[45];
y[47] = b64[44];
y[48] = b64[51];
y[49] = b64[50];
y[50] = b64[49];
y[51] = b64[48];
y[52] = b64[55];
y[53] = b64[54];
y[54] = b64[53];
y[55] = b64[52];
y[56] = b64[59];
y[57] = b64[58];
y[58] = b64[57];
y[59] = b64[56];
y[60] = b64[63];
y[61] = b64[62];
y[62] = b64[61];
y[63] = b64[60];
#endif
ROUND1(A, B, C, D, 0, Sa, 1);
ROUND1(D, A, B, C, 1, Sb, 2);
ROUND1(C, D, A, B, 2, Sc, 3);
ROUND1(B, C, D, A, 3, Sd, 4);
ROUND1(A, B, C, D, 4, Sa, 5);
ROUND1(D, A, B, C, 5, Sb, 6);
ROUND1(C, D, A, B, 6, Sc, 7);
ROUND1(B, C, D, A, 7, Sd, 8);
ROUND1(A, B, C, D, 8, Sa, 9);
ROUND1(D, A, B, C, 9, Sb, 10);
ROUND1(C, D, A, B, 10, Sc, 11);
ROUND1(B, C, D, A, 11, Sd, 12);
ROUND1(A, B, C, D, 12, Sa, 13);
ROUND1(D, A, B, C, 13, Sb, 14);
ROUND1(C, D, A, B, 14, Sc, 15);
ROUND1(B, C, D, A, 15, Sd, 16);
ROUND2(A, B, C, D, 1, Se, 17);
ROUND2(D, A, B, C, 6, Sf, 18);
ROUND2(C, D, A, B, 11, Sg, 19);
ROUND2(B, C, D, A, 0, Sh, 20);
ROUND2(A, B, C, D, 5, Se, 21);
ROUND2(D, A, B, C, 10, Sf, 22);
ROUND2(C, D, A, B, 15, Sg, 23);
ROUND2(B, C, D, A, 4, Sh, 24);
ROUND2(A, B, C, D, 9, Se, 25);
ROUND2(D, A, B, C, 14, Sf, 26);
ROUND2(C, D, A, B, 3, Sg, 27);
ROUND2(B, C, D, A, 8, Sh, 28);
ROUND2(A, B, C, D, 13, Se, 29);
ROUND2(D, A, B, C, 2, Sf, 30);
ROUND2(C, D, A, B, 7, Sg, 31);
ROUND2(B, C, D, A, 12, Sh, 32);
ROUND3(A, B, C, D, 5, Si, 33);
ROUND3(D, A, B, C, 8, Sj, 34);
ROUND3(C, D, A, B, 11, Sk, 35);
ROUND3(B, C, D, A, 14, Sl, 36);
ROUND3(A, B, C, D, 1, Si, 37);
ROUND3(D, A, B, C, 4, Sj, 38);
ROUND3(C, D, A, B, 7, Sk, 39);
ROUND3(B, C, D, A, 10, Sl, 40);
ROUND3(A, B, C, D, 13, Si, 41);
ROUND3(D, A, B, C, 0, Sj, 42);
ROUND3(C, D, A, B, 3, Sk, 43);
ROUND3(B, C, D, A, 6, Sl, 44);
ROUND3(A, B, C, D, 9, Si, 45);
ROUND3(D, A, B, C, 12, Sj, 46);
ROUND3(C, D, A, B, 15, Sk, 47);
ROUND3(B, C, D, A, 2, Sl, 48);
ROUND4(A, B, C, D, 0, Sm, 49);
ROUND4(D, A, B, C, 7, Sn, 50);
ROUND4(C, D, A, B, 14, So, 51);
ROUND4(B, C, D, A, 5, Sp, 52);
ROUND4(A, B, C, D, 12, Sm, 53);
ROUND4(D, A, B, C, 3, Sn, 54);
ROUND4(C, D, A, B, 10, So, 55);
ROUND4(B, C, D, A, 1, Sp, 56);
ROUND4(A, B, C, D, 8, Sm, 57);
ROUND4(D, A, B, C, 15, Sn, 58);
ROUND4(C, D, A, B, 6, So, 59);
ROUND4(B, C, D, A, 13, Sp, 60);
ROUND4(A, B, C, D, 4, Sm, 61);
ROUND4(D, A, B, C, 11, Sn, 62);
ROUND4(C, D, A, B, 2, So, 63);
ROUND4(B, C, D, A, 9, Sp, 64);
ctxt->md5_sta += A;
ctxt->md5_stb += B;
ctxt->md5_stc += C;
ctxt->md5_std += D;
}

View file

@ -0,0 +1,89 @@
/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.h,v 1.8 2003/11/29 22:39:28 pgsql Exp $ */
/* $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* 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. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 THE PROJECT 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 _NETINET6_MD5_H_
#define _NETINET6_MD5_H_
#ifdef __cplusplus
extern "C" {
#endif
#define MD5_BUFLEN 64
typedef struct
{
union
{
unsigned int md5_state32[4];
unsigned char md5_state8[16];
} md5_st;
#define md5_sta md5_st.md5_state32[0]
#define md5_stb md5_st.md5_state32[1]
#define md5_stc md5_st.md5_state32[2]
#define md5_std md5_st.md5_state32[3]
#define md5_st8 md5_st.md5_state8
union
{
struct {
unsigned int md5_count32_lsw;
unsigned int md5_count32_msw;
} md5_count64;
unsigned char md5_count8[8];
} md5_count;
#define md5_nl md5_count.md5_count64.md5_count32_lsw
#define md5_nh md5_count.md5_count64.md5_count32_msw
#define md5_n8 md5_count.md5_count8
unsigned int md5_i;
unsigned char md5_buf[MD5_BUFLEN];
} md5_ctxt;
extern void md5_init(md5_ctxt *);
extern void md5_loop(md5_ctxt *, const unsigned char *, size_t);
extern void md5_pad(md5_ctxt *);
extern void md5_result(unsigned char *, md5_ctxt *);
/* compatibility */
#define MD5_CTX md5_ctxt
#define MD5Init(x) md5_init((x))
#define MD5Update(x, y, z) md5_loop((x), (y), (z))
#define MD5Final(x, y) \
do { \
md5_pad((y)); \
md5_result((x), (y)); \
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* ! _NETINET6_MD5_H_ */

367
src/tivomirror/tivodecode/missing Executable file
View file

@ -0,0 +1,367 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
scriptversion=2006-05-10.23
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
# Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# 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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, 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.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
run=:
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
else
configure_ac=configure.in
fi
msg="missing on your system"
case $1 in
--run)
# Try to run requested program, and just exit if it succeeds.
run=
shift
"$@" && exit 0
# Exit code 63 means version mismatch. This often happens
# when the user try to use an ancient version of a tool on
# a file that requires a minimum version. In this case we
# we should proceed has if the program had been absent, or
# if --run hadn't been passed.
if test $? = 63; then
run=:
msg="probably too old"
fi
;;
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
autom4te touch the output file, or create a stub one
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
Send bug reports to <bug-automake@gnu.org>."
exit $?
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing $scriptversion (GNU Automake)"
exit $?
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
esac
# Now exit if we have it, but it failed. Also exit now if we
# don't have it and --version was passed (most likely to detect
# the program).
case $1 in
lex|yacc)
# Not GNU programs, they don't have --version.
;;
tar)
if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run"
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
exit 1
fi
;;
*)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
# Could not run --version or --help. This is probably someone
# running `$TOOL --version' or `$TOOL --help' to check whether
# $TOOL exists and not knowing $TOOL uses missing.
exit 1
fi
;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case $1 in
aclocal*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case $f in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
autom4te)
echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
You can get \`$1' as part of \`Autoconf' from any GNU
archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo "#! /bin/sh"
echo "# Created by GNU Automake missing as a replacement of"
echo "# $ $@"
echo "exit 0"
chmod +x $file
exit 1
fi
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if test $# -ne 1; then
eval LASTARG="\${$#}"
case $LASTARG in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if test ! -f y.tab.h; then
echo >y.tab.h
fi
if test ! -f y.tab.c; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if test $# -ne 1; then
eval LASTARG="\${$#}"
case $LASTARG in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if test -f "$SRCFILE"; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if test ! -f lex.yy.c; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
help2man)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page"
exit 1
fi
;;
makeinfo)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
# The file to touch is that specified with -o ...
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
if test -z "$file"; then
# ... or it is the one specified with @setfilename ...
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '
/^@setfilename/{
s/.* \([^ ]*\) *$/\1/
p
q
}' $infile`
# ... or it is derived from the source name (dir/f.texi becomes f.info)
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
fi
# If the file does not exist, the user really needs makeinfo;
# let's fail without touching anything.
test -f $file || exit 1
touch $file
;;
tar)
shift
# We have already tried tar in the generic part.
# Look for gnutar/gtar before invocation to avoid ugly error
# messages.
if (gnutar --version > /dev/null 2>&1); then
gnutar "$@" && exit 0
fi
if (gtar --version > /dev/null 2>&1); then
gtar "$@" && exit 0
fi
firstarg="$1"
if shift; then
case $firstarg in
*o*)
firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" "$@" && exit 0
;;
esac
case $firstarg in
*h*)
firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" "$@" && exit 0
;;
esac
fi
echo 1>&2 "\
WARNING: I can't seem to be able to run \`tar' with the given arguments.
You may want to install GNU tar or Free paxutils, or check the
command line arguments."
exit 1
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View file

@ -0,0 +1,203 @@
/*
SHA-1 in C
By Steve Reid <steve@edmweb.com>
100% Public Domain
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
/* #define SHA1HANDSOFF * Copies data before messing with it. */
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "sha1.h"
#ifdef WIN32
# include <windows.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
static void sha1_transform (unsigned int state[5], unsigned char buffer[64]);
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
# define blk0(i) (block->l[i] = htonl (block->l[i]))
#define blk(i) (block->l[i & 15] = rol (block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] \
^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
/* (R0 + R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
#define R1(v,w,x,y,z,i) z += ((w & (x ^ y)) ^ y) + blk (i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
#define R2(v,w,x,y,z,i) z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
#define R3(v,w,x,y,z,i) z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30);
#define R4(v,w,x,y,z,i) z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
static void sha1_transform (unsigned int state[5], unsigned char buffer[64])
{
unsigned int a, b, c, d, e;
typedef union {
unsigned char c[64];
unsigned int l[16];
} CHAR64LONG16;
CHAR64LONG16 * block;
#ifdef SHA1HANDSOFF
static unsigned char workspace[64];
block = (CHAR64LONG16 *)workspace;
memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16 *)buffer;
#endif
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
}
/* sha1_init - Initialize new context */
void sha1_init(SHA1_CTX * context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
}
/* Run your data through this. */
void sha1_update(SHA1_CTX * context, unsigned char * data, size_t len)
{
unsigned int i, j;
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += (unsigned int)len << 3) < (len << 3))
context->count[1]++;
context->count[1] += (unsigned int)(len >> 29);
if ((j + len) > 63)
{
memcpy (&context->buffer[j], data, (i = 64 - j));
sha1_transform (context->state, context->buffer);
for ( ; i + 63 < len; i += 64)
{
memcpy (context->buffer, &data[i], 64);
sha1_transform (context->state, context->buffer);
}
j = 0;
}
else
{
i = 0;
}
memcpy (&context->buffer[j], &data[i], len - i);
}
/* Add padding and return the message digest. */
void sha1_final(unsigned char digest[20], SHA1_CTX * context)
{
unsigned int i, j;
unsigned char finalcount[8];
for (i = 0; i < 8; i++)
{
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3 - (i & 3)) * 8) ) & 255); /* Endian independent */
}
sha1_update (context, (unsigned char *)"\200", 1);
while ((context->count[0] & 504) != 448)
{
sha1_update (context, (unsigned char *)"\0", 1);
}
sha1_update (context, finalcount, 8); /* Should cause a sha1_transform() */
for (i = 0; i < 20; i++)
{
digest[i] = (unsigned char)
((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
/* Wipe variables */
i = j = 0;
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF /* make sha1_transform overwrite it's own static vars */
sha1_transform(context->state, context->buffer);
#endif
}

View file

@ -0,0 +1,24 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifndef SHA1_H_
#define SHA1_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned int state[5];
unsigned int count[2];
unsigned char buffer[64];
} SHA1_CTX;
void sha1_init (SHA1_CTX * context);
void sha1_update (SHA1_CTX * context, unsigned char * data, size_t len);
void sha1_final (unsigned char digest[20], SHA1_CTX * context);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,227 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*
* derived from mpegcat, copyright 2006 Kees Cook, used with permission
*/
#include "tivodecoder.h"
#include <stdio.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#include "getopt_long.h"
#include "happyfile.h"
#include "cli_common.h"
static int hread_wrapper (void * mem, int size, void * fh)
{
return (int)hread (mem, size, (happy_file *)fh);
}
static struct option long_options[] = {
{"mak", 1, 0, 'm'},
{"out", 1, 0, 'o'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"chunk-1", 0, 0, '1'},
{"chunk-2", 0, 0, '2'},
{0, 0, 0, 0}
};
static void do_help(char * arg0, int exitval)
{
fprintf(stderr, "Usage: %s [--help] {--mak|-m} mak [{--out|-o} outfile] [{-2|--chunk-2}] <tivofile>\n\n", arg0);
#define ERROUT(s) fprintf(stderr, s)
ERROUT (" --mak, -m media access key (required)\n");
ERROUT (" --out, -o output file (default stdout)\n");
ERROUT (" --chunk-1, -1 output chunk 1 (default if neither chunk specified)\n");
ERROUT (" --chunk-2, -2 output chunk 2\n");
ERROUT (" --version, -V print the version information and exit\n");
ERROUT (" --help, -h print this help and exit\n\n");
ERROUT ("The file names specified for the output file or the tivo file may be -, which\n");
ERROUT ("means stdout or stdin respectively\n\n");
#undef ERROUT
exit (exitval);
}
int main(int argc, char *argv[])
{
int o_chunk_1 = 0;
int o_chunk_2 = 0;
char * tivofile = NULL;
char * outfile = NULL;
char mak[12];
int makgiven = 0;
FILE * ofh;
happy_file * hfh=NULL;
turing_state metaturing;
tivo_stream_header head;
tivo_stream_chunk *chunk;
hoff_t current_meta_stream_pos = 0;
int i;
memset(mak, 0, sizeof(mak));
memset(&metaturing, 0, sizeof(metaturing));
while (1)
{
int c = getopt_long (argc, argv, "m:o:12hV", long_options, 0);
if (c == -1)
break;
switch (c)
{
case 'm':
strncpy(mak, optarg, 11);
mak[11] = '\0';
makgiven = 1;
break;
case 'o':
outfile = optarg;
break;
case '1':
o_chunk_1 = 1;
break;
case '2':
o_chunk_2 = 1;
break;
case 'h':
case '?':
do_help(argv[0], 1);
break;
case 'V':
do_version(10);
break;
default:
do_help(argv[0], 3);
break;
}
}
if (optind < argc)
{
tivofile=argv[optind++];
if (optind < argc)
do_help(argv[0], 4);
}
if (!makgiven)
makgiven = get_mak_from_conf_file(mak);
if (!makgiven || !tivofile)
{
do_help(argv[0], 5);
}
if (!strcmp(tivofile, "-"))
{
// JKOZEE-Make sure stdin is set to binary on Windows
#ifdef WIN32
int result = _setmode(_fileno(stdin), _O_BINARY );
if( result == -1 ) {
perror( "Cannot set stdin to binary mode" );
return 10;
}
#endif
hfh=hattach(stdin);
}
else
{
if (!(hfh=hopen(tivofile, "rb")))
{
perror(tivofile);
return 6;
}
}
if (!outfile || !strcmp(outfile, "-"))
{
// JKOZEE-Make sure stdout is set to binary on Windows
#ifdef WIN32
int result = _setmode(_fileno(stdout), _O_BINARY );
if( result == -1 ) {
perror( "Cannot set stdout to binary mode" );
return 10;
}
#endif
ofh = stdout;
}
else
{
if (!(ofh = fopen(outfile, "wb")))
{
perror("opening output file");
return 7;
}
}
if (!o_chunk_1 && !o_chunk_2)
o_chunk_1 = 1;
PRINT_QUALCOMM_MSG();
/* parse the tivo headers manually here, since we care about more
* than the init_turing_from_file function will get
*/
if (read_tivo_header (hfh, &head, &hread_wrapper))
return 8;
for (i = 0; i < head.chunks; i++)
{
hoff_t chunk_start = htell(hfh) + SIZEOF_STREAM_CHUNK;
if ((chunk = read_tivo_chunk (hfh, &hread_wrapper)) == NULL)
return 8;
if (chunk->data_size && chunk->type == TIVO_CHUNK_PLAINTEXT_XML)
{
setup_metadata_key (&metaturing, chunk, mak);
free (chunk);
continue;
}
if ((o_chunk_1 && chunk->id == 1) || (o_chunk_2 && chunk->id == 2))
{
prepare_frame(&metaturing, 0, 0);
skip_turing_data(&metaturing, (size_t)(chunk_start - current_meta_stream_pos));
decrypt_buffer(&metaturing, chunk->data, chunk->data_size);
current_meta_stream_pos = chunk_start + chunk->data_size;
if (fwrite (chunk->data, 1, chunk->data_size, ofh) != chunk->data_size)
{
perror("write chunk");
return 8;
}
}
free(chunk);
}
destruct_turing(&metaturing);
if (hfh->fh == stdin)
hdetach(hfh);
else
hclose(hfh);
if (ofh != stdout)
fclose(ofh);
return 0;
}
/* vi:set ai ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="tdcat"
ProjectGUID="{66AEBB90-9BD8-497E-B546-9409110E9F21}"
RootNamespace="tdcat"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="0"
BuildLogFile="$(IntDir)\tdcat_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\tdcat.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
BuildLogFile="$(IntDir)\tdcat_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\tdcat.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\tdcat.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,139 @@
/* tdconfig.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <ctype.h> header file. */
#undef HAVE_CTYPE_H
/* Define to 1 if you have the `fseeko' function. */
#undef HAVE_FSEEKO
/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT
/* Define to 1 if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H
/* Define to 1 if you have the `getopt_long' function. */
#undef HAVE_GETOPT_LONG
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the global variable 'int optreset'. */
#undef HAVE_INT_OPTRESET
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if the system has the type `size_t'. */
#undef HAVE_SIZE_T
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if the system has the type `struct option'. */
#undef HAVE_STRUCT_OPTION
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if the system has the type `unsigned long'. */
#undef HAVE_UNSIGNED_LONG
/* Define to 1 if the system has the type `unsigned long long'. */
#undef HAVE_UNSIGNED_LONG_LONG
/* Define to 1 if you have the <winsock2.h> header file. */
#undef HAVE_WINSOCK2_H
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* The size of `size_t', as computed by sizeof. */
#undef SIZEOF_SIZE_T
/* The size of `unsigned long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG
/* The size of `unsigned long long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG_LONG
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Version number of package */
#undef VERSION
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Define to 1 if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
#undef _LARGEFILE_SOURCE
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t

View file

@ -0,0 +1,150 @@
/* tdconfig.h. Generated from tdconfig.h.in by configure. */
/* tdconfig.h.in. Generated from configure.in by autoheader. */
/* This file is generated from MingW ./configure, and with the following
* changes to be valid for Visual C++ (and compatible):
*
* HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_FUNCNAME_FUNCTION, HAVE_GETOPT,
* HAVE_GETOPT_H, HAVE_GETOPT_LONG, HAVE_RINT, HAVE_STRINGS_H,
* HAVE_STRTOLL, HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY
*
* For now, also HAVE_IPV6, HAVE_UNISTD_H
*/
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define to 1 if you have the `fseeko' function. */
/* #undef HAVE_FSEEKO */
/* Define to 1 if you have the `getopt' function. */
//#define HAVE_GETOPT 1
/* Define to 1 if you have the <getopt.h> header file. */
//#define HAVE_GETOPT_H 1
/* Define to 1 if you have the `getopt_long' function. */
//#define HAVE_GETOPT_LONG 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the global variable 'int optreset'. */
#define HAVE_INT_OPTRESET 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if the system has the type `size_t'. */
#define HAVE_SIZE_T 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
//#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if the system has the type `struct option'. */
//#define HAVE_STRUCT_OPTION 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
//#define HAVE_UNISTD_H 1
/* Define to 1 if the system has the type `unsigned long'. */
#define HAVE_UNSIGNED_LONG 1
/* Define to 1 if the system has the type `unsigned long long'. */
#define HAVE_UNSIGNED_LONG_LONG 1
/* Define to 1 if you have the <winsock2.h> header file. */
#define HAVE_WINSOCK2_H 1
/* Name of package */
#define PACKAGE "tivodecode"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "tivodecode"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "tivodecode 0.3pre4"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "tivodecode"
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.3pre4"
/* The size of `off_t', as computed by sizeof. */
#define SIZEOF_OFF_T 4
/* The size of `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T 4
/* The size of `unsigned long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG 4
/* The size of `unsigned long long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG_LONG 8
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "0.3pre4"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef WORDS_BIGENDIAN */
/* Define to 1 if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
/* # undef _ALL_SOURCE */
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
/* #undef _LARGEFILE_SOURCE */
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
/* Define to 1 if on MINIX. */
/* #undef _MINIX */
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
/* #undef _POSIX_1_SOURCE */
/* Define to 1 if you need to in order for `stat' and other things to work. */
/* #undef _POSIX_SOURCE */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `long int' if <sys/types.h> does not define. */
/* #undef off_t */

View file

@ -0,0 +1,176 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef WIN32
# include <windows.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#include "sha1.h"
#include "tivo-parse.h"
#include "hexlib.h"
#define LOAD_NET_UNALIGNED_HELP(ptr, offset, len) ((unsigned int)ptr[offset] << (((len - 1) << 3) - (offset << 3)))
#define NETLONG_UNALIGNED(ptr) ( \
LOAD_NET_UNALIGNED_HELP(ptr, 0, 4) | \
LOAD_NET_UNALIGNED_HELP(ptr, 1, 4) | \
LOAD_NET_UNALIGNED_HELP(ptr, 2, 4) | \
LOAD_NET_UNALIGNED_HELP(ptr, 3, 4) \
)
int isBigEndian()
{
unsigned char EndianTest[2] = {1,0};
short x = *(short *)EndianTest;
if( x == 1 )
return 0;
else
return 1;
}
unsigned long portable_ntohl( unsigned char * pVal )
{
unsigned long s = 0;
if ( isBigEndian() )
{
return *(unsigned long *)pVal;
}
else
{
s = (pVal[0] << 24) | (pVal[1] << 16) | (pVal[2]<<8) | pVal[3];
return s;
}
}
unsigned short portable_ntohs( unsigned char * pVal )
{
unsigned short s = 0;
if ( isBigEndian() )
{
return *(unsigned short *)pVal;
}
else
{
s = (pVal[0] << 8) | pVal[1];
return s;
}
}
int read_tivo_header(void * file, tivo_stream_header * head, read_func_t read_handler)
{
struct {
char filetype[4];
/* all fields are in network byte order */
unsigned short dummy_0004;
unsigned short dummy_0006;
unsigned short dummy_0008;
unsigned char mpeg_offset[4]; /* unsigned int */
unsigned short chunks;
} raw_tivo_header;
if (read_handler (&raw_tivo_header, SIZEOF_STREAM_HEADER, file) != SIZEOF_STREAM_HEADER)
{
perror ("read head");
return -1;
}
memcpy(head->filetype, raw_tivo_header.filetype, 4);
head->dummy_0004 = ntohs(raw_tivo_header.dummy_0004);
head->dummy_0006 = ntohs(raw_tivo_header.dummy_0006);
head->dummy_0008 = ntohs(raw_tivo_header.dummy_0008);
head->mpeg_offset = NETLONG_UNALIGNED(raw_tivo_header.mpeg_offset);
head->chunks = ntohs(raw_tivo_header.chunks);
return 0;
}
tivo_stream_chunk * read_tivo_chunk(void * file, read_func_t read_handler)
{
tivo_stream_chunk * chunk;
unsigned int chunk_sz;
tivo_stream_chunk raw_chunk_header;
if (read_handler (&raw_chunk_header, SIZEOF_STREAM_CHUNK, file) != SIZEOF_STREAM_CHUNK)
{
perror("read chunk head");
return NULL;
}
chunk_sz = ntohl(raw_chunk_header.chunk_size);
/* allocate the memory for the chunk */
if (!(chunk = (tivo_stream_chunk *)malloc(chunk_sz)))
{
perror("malloc");
exit(1);
}
// network byte order conversion
chunk->chunk_size = chunk_sz;
chunk->data_size = ntohl(raw_chunk_header.data_size);
chunk->id = ntohs(raw_chunk_header.id );
chunk->type = ntohs(raw_chunk_header.type );
/* read the rest of the chunk */
if (read_handler(chunk->data, (int)chunk_sz - SIZEOF_STREAM_CHUNK, file)
!= chunk_sz - SIZEOF_STREAM_CHUNK)
{
perror("read chunk data");
free(chunk);
return NULL;
}
return chunk;
}
void dump_tivo_header(tivo_stream_header * head)
{
if ( !head )
return;
printf("Head File Type : %s\n", head->filetype );
printf("Head Dummy4 : %04x\n", head->dummy_0004 );
printf("Head Dummy6 : %04x\n", head->dummy_0006 );
printf("Head Dummy8 : %04x\n", head->dummy_0008 );
printf("MPEG offset : %d\n", head->mpeg_offset );
printf("Head Chunks : %d\n", head->chunks );
printf("\n");
return;
}
void dump_tivo_chunk(tivo_stream_chunk * chunk)
{
if ( !chunk )
return;
printf("Chunk Size : %d\n", chunk->chunk_size );
printf("Data Size : %d\n", chunk->data_size );
printf("Chunk ID : %d\n", chunk->id );
printf("Chunk Type : %d\n", chunk->type );
printf("Chunk Data : \n" );
hexbulk( (unsigned char *)chunk->data, (int) chunk->data_size );
printf("\n");
return;
}

View file

@ -0,0 +1,68 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#include <stddef.h>
#ifndef TIVO_PARSE_H_
#define TIVO_PARSE_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* Initial header formats lifted from ezrec's posting:
* http://www.dealdatabase.com/forum/showthread.php?t=41132
*/
/* All elements are in big-endian format and are packed */
#define SIZEOF_STREAM_HEADER 16
typedef struct tivo_stream_header_s {
char filetype[4]; /* the string 'TiVo' */
unsigned short dummy_0004;
unsigned short dummy_0006;
unsigned short dummy_0008;
unsigned int mpeg_offset; /* 0-based offset of MPEG stream */
unsigned short chunks; /* Number of metadata chunks */
} tivo_stream_header;
#define TIVO_CHUNK_PLAINTEXT_XML 0
#define TIVO_CHUNK_ENCRYPTED_XML 1
#define SIZEOF_STREAM_CHUNK 12
typedef struct tivo_stream_chunk_s {
unsigned int chunk_size; /* Size of chunk */
unsigned int data_size; /* Length of the payload */
unsigned short id; /* Chunk ID */
unsigned short type; /* Subtype */
unsigned char data[1]; /* Variable length data */
} tivo_stream_chunk;
/* genericized read function so that different underlying implementations can
* be swapped out for more of a library setup
*/
typedef int (*read_func_t) (void * mem, int size, void * fh);
int read_tivo_header(void * file, tivo_stream_header * head, read_func_t read_handler);
tivo_stream_chunk * read_tivo_chunk(void * file, read_func_t read_handler);
void dump_tivo_header(tivo_stream_header * head);
void dump_tivo_chunk(tivo_stream_chunk * chunk);
extern int isBigEndian();
extern unsigned short portable_ntohs( unsigned char * pVal );
extern unsigned long portable_ntohl( unsigned char * pVal );
#define VERBOSE(...) if ( o_verbose >= 1 ) { printf(__VA_ARGS__); }
#define VVERBOSE(...) if ( o_verbose >= 2 ) { printf(__VA_ARGS__); }
#define VVVERBOSE(...) if ( o_verbose >= 3 ) { printf(__VA_ARGS__); }
#define IS_VERBOSE ( o_verbose >= 1 )
#define IS_VVERBOSE ( o_verbose >= 2 )
#define IS_VVVERBOSE ( o_verbose >= 3 )
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,396 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*
* derived from mpegcat, copyright 2006 Kees Cook, used with permission
*/
#include "tivodecoder.h"
#include <stdio.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#include "getopt_long.h"
#include "happyfile.h"
#include "cli_common.h"
#include "tivo-parse.h"
int o_ts_pkt_dump = 0;
typedef enum
{
TIVO_FORMAT_NONE,
TIVO_FORMAT_PS,
TIVO_FORMAT_TS,
TIVO_FORMAT_MAX
}
tivo_format_type;
static int hread_wrapper (void * mem, int size, void * fh)
{
return (int)hread (mem, size, (happy_file *)fh);
}
static int fwrite_wrapper (void * mem, int size, void * fh)
{
return (int)fwrite (mem, 1, size, (FILE *)fh);
}
static struct option long_options[] = {
{"mak", 1, 0, 'm'},
{"out", 1, 0, 'o'},
{"help", 0, 0, 'h'},
{"verbose", 0, 0, 'v'},
{"pkt-dump", 1, 0, 'p'},
{"version", 0, 0, 'V'},
{"no-verify", 0, 0, 'n'},
{"metadata", 0, 0, 'D'},
{"no-video", 0, 0, 'x'},
{0, 0, 0, 0}
};
static void do_help(char * arg0, int exitval)
{
fprintf(stderr, "Usage: %s [--help] [--verbose|-v] [--no-verify|-n] [--pkt-dump|-p] pkt_num {--mak|-m} mak [--metadata|-D] [{--out|-o} outfile] <tivofile>\n\n", arg0);
#define ERROUT(s) fprintf(stderr, s)
ERROUT (" --mak, -m media access key (required)\n");
ERROUT (" --out, -o output file (default stdout)\n");
ERROUT (" --verbose, -v verbose\n");
ERROUT (" --pkt-dump, -p verbose logging for specific TS packet number\n");
ERROUT (" --metadata, -D dump TiVo recording metadata\n");
ERROUT (" --no-verify, -n do not verify MAK while decoding\n");
ERROUT (" --no-video, -x don't decode video, exit after metadata\n");
ERROUT (" --version, -V print the version information and exit\n");
ERROUT (" --help, -h print this help and exit\n\n");
ERROUT ("The file names specified for the output file or the tivo file may be -, which\n");
ERROUT ("means stdout or stdin respectively\n\n");
#undef ERROUT
exit (exitval);
}
int main(int argc, char *argv[])
{
int o_no_video = 0;
int o_dump_chunks = 1;
int o_dump_metadata = 0;
unsigned int marker;
unsigned char byte;
char first = 1;
tivo_format_type format = TIVO_FORMAT_NONE;
int running = 1;
int ret = 0;
char * tivofile = NULL;
char * outfile = NULL;
char mak[12];
int makgiven = 0;
turing_state turing;
FILE * ofh;
happy_file * hfh=NULL;
// file position options
hoff_t begin_at = 0;
memset(&turing, 0, sizeof(turing));
memset(mak, 0, sizeof(mak));
while (1)
{
int c = getopt_long (argc, argv, "m:o:hnDxvV", long_options, 0);
if (c == -1)
break;
switch (c)
{
case 'm':
strncpy(mak, optarg, 11);
mak[11] = '\0';
makgiven = 1;
break;
case 'p':
sscanf(optarg, "%d", &o_ts_pkt_dump);
break;
case 'o':
outfile = optarg;
break;
case 'h':
do_help(argv[0], 1);
break;
case 'v':
o_verbose++;
break;
case 'n':
o_no_verify = 1;
break;
case 'D' :
o_dump_metadata = 1;
break;
case 'x':
o_no_video = 1;
break;
case '?':
do_help(argv[0], 2);
break;
case 'V':
do_version(10);
break;
default:
do_help(argv[0], 3);
break;
}
}
if (optind < argc)
{
tivofile=argv[optind++];
if (optind < argc)
do_help(argv[0], 4);
}
if (!makgiven)
makgiven = get_mak_from_conf_file(mak);
if (!makgiven || !tivofile)
{
do_help(argv[0], 5);
}
if (!strcmp(tivofile, "-"))
{
// JKOZEE-Make sure stdin is set to binary on Windows
#ifdef WIN32
int result = _setmode(_fileno(stdin), _O_BINARY );
if( result == -1 ) {
perror( "Cannot set stdin to binary mode" );
return 10;
}
#endif
hfh=hattach(stdin);
}
else
{
if (!(hfh=hopen(tivofile, "rb")))
{
perror(tivofile);
return 6;
}
}
if (!outfile || !strcmp(outfile, "-"))
{
// JKOZEE-Make sure stdout is set to binary on Windows
#ifdef WIN32
int result = _setmode(_fileno(stdout), _O_BINARY );
if( result == -1 ) {
perror( "Cannot set stdout to binary mode" );
return 10;
}
#endif
ofh = stdout;
}
else
{
if (!(ofh = fopen(outfile, "wb")))
{
perror("opening output file");
return 7;
}
}
PRINT_QUALCOMM_MSG();
if (o_dump_chunks)
{
/* parse the tivo headers manually here, since we care about more
* than the init_turing_from_file function will get
*/
tivo_stream_header head;
tivo_stream_chunk *chunk;
turing_state metaturing;
hoff_t current_meta_stream_pos = 0;
int i;
memset(&metaturing, 0, sizeof(metaturing));
if (read_tivo_header (hfh, &head, &hread_wrapper))
return 8;
VVVERBOSE("TiVo Head\n");
if ( IS_VVVERBOSE )
dump_tivo_header(&head);
begin_at = head.mpeg_offset;
if ( head.dummy_0006 & 0x20 )
{
format = TIVO_FORMAT_TS;
}
else
{
format = TIVO_FORMAT_PS;
}
for (i=0; i<head.chunks; i++)
{
/* TODO: find a better way to present the chunks */
/* maybe a simple tar format writer */
char buf[4096];
hoff_t chunk_start = htell(hfh) + SIZEOF_STREAM_CHUNK;
if ((chunk = read_tivo_chunk (hfh, &hread_wrapper)) == NULL)
return 8;
if (chunk->data_size && chunk->type == TIVO_CHUNK_PLAINTEXT_XML )
{
if ( IS_VVVERBOSE )
dump_tivo_chunk(chunk);
if (!o_no_video)
setup_turing_key (&turing, chunk, mak);
setup_metadata_key (&metaturing, chunk, mak);
free (chunk);
continue;
}
if ( o_dump_metadata )
{
FILE * chunkfh;
sprintf(buf, "%s-%02d-%04x.xml", "chunk", i, chunk->id);
chunkfh = fopen(buf, "wb");
if (!chunkfh)
{
perror("create metadata file");
return 8;
}
prepare_frame(&metaturing, 0, 0);
skip_turing_data(&metaturing, (size_t)(chunk_start - current_meta_stream_pos));
decrypt_buffer(&metaturing, chunk->data, chunk->data_size);
current_meta_stream_pos = chunk_start + chunk->data_size;
if (IS_VVVERBOSE)
dump_tivo_chunk(chunk);
if (fwrite (chunk->data, 1, chunk->data_size, chunkfh) != chunk->data_size)
{
perror("write chunk");
return 8;
}
fclose(chunkfh);
}
free(chunk);
}
destruct_turing(&metaturing);
if (o_no_video)
exit(0);
}
else
{
if (o_no_video)
exit(0);
if ((begin_at = init_turing_from_file (&turing, hfh, &hread_wrapper, mak)) < 0)
return 8;
}
if (hseek(hfh, begin_at, SEEK_SET) < 0)
{
perror ("seek");
return 9;
}
if ( format == TIVO_FORMAT_TS )
{
running = 1;
while ( running )
{
ret = process_ts_frame(&turing, htell(hfh), hfh, &hread_wrapper, ofh, &fwrite_wrapper);
if ( ret < 0 )
{
perror ("processing frame");
return 10;
}
else if ( ret == 0 )
{
fprintf(stderr, "End of File\n");
running = 0;
}
}
}
else if ( format == TIVO_FORMAT_PS )
{
marker = 0xFFFFFFFF;
while (running)
{
if ((marker & 0xFFFFFF00) == 0x100)
{
ret = process_ps_frame(byte, &turing, htell(hfh), hfh, &hread_wrapper, ofh, &fwrite_wrapper);
if (ret == 1)
{
marker = 0xFFFFFFFF;
}
else if (ret == 0)
{
fwrite(&byte, 1, 1, ofh);
}
else if (ret < 0)
{
perror ("processing frame");
return 10;
}
}
else if (!first)
{
fwrite(&byte, 1, 1, ofh);
}
marker <<= 8;
if (hread(&byte, 1, hfh) == 0)
{
fprintf(stderr, "End of File\n");
running = 0;
}
else
marker |= byte;
first = 0;
}
}
else
{
perror ("invalid TiVo format");
return 10;
}
destruct_turing (&turing);
if (hfh->fh == stdin)
hdetach(hfh);
else
hclose(hfh);
if (ofh != stdout)
fclose(ofh);
return 0;
}
/* vi:set ai ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<VisualStudioToolFile
Name="copy win32 file"
Version="8.00"
>
<Rules>
<CustomBuildRule
Name="copy win32 file"
DisplayName="copy win32 file"
CommandLine="copy $(InputName).win32 $(InputName)"
Outputs="$(InputName)"
FileExtensions="*.win32"
ExecutionDescription="copying $(InputName).win32 to $(InputName)"
>
<Properties>
</Properties>
</CustomBuildRule>
</Rules>
</VisualStudioToolFile>

View file

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tivodecode", "tivodecode.vcproj", "{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}"
ProjectSection(ProjectDependencies) = postProject
{491A7F57-2E09-492E-9E44-70A34A313611} = {491A7F57-2E09-492E-9E44-70A34A313611}
{9DDBB216-6D06-47EB-B559-B3FB02510DC3} = {9DDBB216-6D06-47EB-B559-B3FB02510DC3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtivodecode", "libtivodecode.vcproj", "{9DDBB216-6D06-47EB-B559-B3FB02510DC3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tdcat", "tdcat.vcproj", "{66AEBB90-9BD8-497E-B546-9409110E9F21}"
ProjectSection(ProjectDependencies) = postProject
{491A7F57-2E09-492E-9E44-70A34A313611} = {491A7F57-2E09-492E-9E44-70A34A313611}
{9DDBB216-6D06-47EB-B559-B3FB02510DC3} = {9DDBB216-6D06-47EB-B559-B3FB02510DC3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtdcommon", "libtdcommon.vcproj", "{491A7F57-2E09-492E-9E44-70A34A313611}"
ProjectSection(ProjectDependencies) = postProject
{9DDBB216-6D06-47EB-B559-B3FB02510DC3} = {9DDBB216-6D06-47EB-B559-B3FB02510DC3}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}.Debug|Win32.ActiveCfg = Debug|Win32
{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}.Debug|Win32.Build.0 = Debug|Win32
{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}.Release|Win32.ActiveCfg = Release|Win32
{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}.Release|Win32.Build.0 = Release|Win32
{9DDBB216-6D06-47EB-B559-B3FB02510DC3}.Debug|Win32.ActiveCfg = Debug|Win32
{9DDBB216-6D06-47EB-B559-B3FB02510DC3}.Debug|Win32.Build.0 = Debug|Win32
{9DDBB216-6D06-47EB-B559-B3FB02510DC3}.Release|Win32.ActiveCfg = Release|Win32
{9DDBB216-6D06-47EB-B559-B3FB02510DC3}.Release|Win32.Build.0 = Release|Win32
{66AEBB90-9BD8-497E-B546-9409110E9F21}.Debug|Win32.ActiveCfg = Debug|Win32
{66AEBB90-9BD8-497E-B546-9409110E9F21}.Debug|Win32.Build.0 = Debug|Win32
{66AEBB90-9BD8-497E-B546-9409110E9F21}.Release|Win32.ActiveCfg = Release|Win32
{66AEBB90-9BD8-497E-B546-9409110E9F21}.Release|Win32.Build.0 = Release|Win32
{491A7F57-2E09-492E-9E44-70A34A313611}.Debug|Win32.ActiveCfg = Debug|Win32
{491A7F57-2E09-492E-9E44-70A34A313611}.Debug|Win32.Build.0 = Debug|Win32
{491A7F57-2E09-492E-9E44-70A34A313611}.Release|Win32.ActiveCfg = Release|Win32
{491A7F57-2E09-492E-9E44-70A34A313611}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

View file

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="tivodecode"
ProjectGUID="{AB0538B4-79BB-463D-AE34-5C7ACD90D0BA}"
RootNamespace="tivodecode"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="0"
BuildLogFile="$(IntDir)\tivodecode_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\tivodecode.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
BuildLogFile="$(IntDir)\tivodecode_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;HAVE_CONFIG_H"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\tivodecode.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\tivodecode.c"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,248 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifndef TIVO_DECODER_H_
#define TIVO_DECODER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tdconfig.h"
#include <stddef.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "turing_stream.h"
#if SIZEOF_OFF_T == 8
# define OFF_T_TYPE off_t
# define OFF_T_FORMAT "llu"
#elif defined(WIN32)
# define OFF_T_TYPE __int64
# define OFF_T_FORMAT "llu"
#else
# warning "Not compiling for large file (>2G) support!"
# define OFF_T_TYPE off_t
# define OFF_T_FORMAT "lu"
#endif
typedef int (*write_func_t) (void * mem, int size, void * fh);
#define PICTURE_START_CODE 0x00
#define SLICE_START_CODE_MIN 0x01
#define SLICE_START_CODE_MAX 0xAF
#define USER_DATA_START_CODE 0xB2
#define SEQUENCE_HEADER_CODE 0xB3
#define SEQUENCE_ERROR_CODE 0xB4
#define EXTENSION_START_CODE 0xB5
#define SEQUENCE_END_CODE 0xB7
#define GROUP_START_CODE 0xB8
#define SYSTEM_START_CODE_MIN 0xB9
#define SYSTEM_START_CODE_MAX 0xFF
#define ISO_END_CODE 0xB9
#define PACK_START_CODE 0xBA
#define SYSTEM_START_CODE 0xBB
#define VIDEO_ELEMENTARY_STREAM 0xe0
#define TRANSPORT_STREAM 0x47
#define TS_FRAME_SIZE 188
//============================
// PS Specific data structures
//============================
typedef enum
{
PACK_NONE,
PACK_SPECIAL,
PACK_PES_SIMPLE, // packet length == data length
PACK_PES_COMPLEX, // crazy headers need skipping
}
packet_type;
typedef struct
{
// the byte value match for the packet tags
unsigned char code_match_lo; // low end of the range of matches
unsigned char code_match_hi; // high end of the range of matches
// what kind of PES is it?
packet_type packet;
}
packet_tag_info;
//============================
// TS Specific data structures
//============================
typedef enum
{
TS_PID_TYPE_RESERVED = 1,
TS_PID_TYPE_NULL_PACKET,
TS_PID_TYPE_PROGRAM_ASSOCIATION_TABLE,
TS_PID_TYPE_PROGRAM_MAP_TABLE,
TS_PID_TYPE_CONDITIONAL_ACCESS_TABLE,
TS_PID_TYPE_NETWORK_INFORMATION_TABLE,
TS_PID_TYPE_SERVICE_DESCRIPTION_TABLE,
TS_PID_TYPE_EVENT_INFORMATION_TABLE,
TS_PID_TYPE_RUNNING_STATUS_TABLE,
TS_PID_TYPE_TIME_DATE_TABLE,
TS_PID_TYPE_AUDIO_VIDEO_PRIVATE_DATA,
TS_PID_TYPE_NONE
} ts_packet_pid_types;
typedef enum
{
TS_STREAM_TYPE_AUDIO = 1,
TS_STREAM_TYPE_VIDEO,
TS_STREAM_TYPE_PRIVATE_DATA,
TS_STREAM_TYPE_OTHER,
TS_STREAM_TYPE_NONE
} ts_stream_types;
typedef struct
{
// the 16-bit value match for the packet pids
unsigned char code_match_lo; // low end of the range of matches
unsigned char code_match_hi; // high end of the range of matches
// what kind of TS packet is it?
ts_stream_types ts_stream_type;
}
ts_pmt_stream_type_info;
#define TS_STREAM_ELEMENT_MAX 10
typedef struct
{
// the 16-bit value match for the packet pids
unsigned short code_match_lo; // low end of the range of matches
unsigned short code_match_hi; // high end of the range of matches
// what kind of TS packet is it?
ts_packet_pid_types ts_packet;
}
ts_packet_tag_info;
typedef struct _TS_header
{
unsigned int sync_byte:8;
unsigned int transport_error_indicator:1;
unsigned int payload_unit_start_indicator:1;
unsigned int transport_priority:1;
unsigned int pid:13;
unsigned int transport_scrambling_control:2;
unsigned int adaptation_field_exists:1;
unsigned int payload_data_exists:1;
unsigned int continuity_counter:4;
}
TS_Header;
typedef struct _TS_adaptation_field
{
unsigned short adaptation_field_length:8;
unsigned short discontinuity_indicator:1;
unsigned short random_access_indicator:1;
unsigned short elementary_stream_priority_indicator:1;
unsigned short pcr_flag:1;
unsigned short opcr_flag:1;
unsigned short splicing_point_flag:1;
unsigned short transport_private_data_flag:1;
unsigned short adaptation_field_extension_flag:1;
}
TS_Adaptation_Field;
typedef struct _TS_PAT_data
{
unsigned char version_number;
unsigned char current_next_indicator;
unsigned char section_number;
unsigned char last_section_number;
unsigned short program_map_pid;
} TS_PAT_data;
typedef struct _TS_Turing_Stuff
{
int block_no;
int crypted;
unsigned char unknown_field[4];
unsigned char key[16];
} TS_Turing_Stuff;
typedef struct _TS_Prog_Elements
{
unsigned char stream_type_id;
unsigned int stream_pid;
unsigned char stream_id;
ts_stream_types stream_type;
TS_Turing_Stuff turing_stuff;
} TS_Stream_Element;
typedef struct _TS_PES_Packet
{
unsigned char stream_id;
unsigned short pkt_length;
unsigned char marker_bits:2;
unsigned char scrambling_control:2;
unsigned char priority:1;
unsigned char data_alignment_indicator:1;
unsigned char copyright:1;
unsigned char original_or_copy:1;
unsigned char PTS_DTS_indicator:2;
unsigned char ESCR_flag:1;
unsigned char ES_rate_flag:1;
unsigned char DSM_trick_mode_flag:1;
unsigned char additional_copy_info_flag:1;
unsigned char CRC_flag:1;
unsigned char extension_flag:1;
unsigned char PES_header_length;
} PES_packet;
typedef struct _TS_Stream
{
unsigned char * pPacket;
unsigned int payload_offset;
unsigned int initial_offset;
unsigned int packet_counter;
TS_Header ts_header;
TS_Adaptation_Field ts_adapt;
TS_PAT_data ts_pat;
ts_packet_pid_types ts_packet_type;
TS_Stream_Element ts_stream_elem[TS_STREAM_ELEMENT_MAX];
PES_packet ts_pes_packet;
} TS_Stream;
/*
* called for each frame
*/
int process_ps_frame(unsigned char code, turing_state * turing, OFF_T_TYPE packet_start, void * packet_stream, read_func_t read_handler, void * ofh, write_func_t write_handler);
int process_ts_frame(turing_state * turing, OFF_T_TYPE packet_start, void * packet_stream, read_func_t read_handler, void * ofh, write_func_t write_handler);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,290 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
/*
* Decoder for Turing
*
* Copyright C 2002, Qualcomm Inc. Written by Greg Rose
* Hacked into use for TiVoToGo decoding by FDM, 2005.
* Majorly re-hacked into use for TiVoToGo decoding by Jeremy Drake, 2005.
*/
/*
This software is free for commercial and non-commercial use subject to
the following conditions:
1. Copyright remains vested in QUALCOMM Incorporated, and Copyright
notices in the code are not to be removed. If this package is used in
a product, QUALCOMM should be given attribution as the author of the
Turing encryption algorithm. This can be in the form of a textual
message at program startup or in documentation (online or textual)
provided with the package.
2. Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
a. Redistributions of source code must retain the copyright notice,
this list of conditions and the following disclaimer.
b. 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.
c. All advertising materials mentioning features or use of this
software must display the following acknowledgement: This product
includes software developed by QUALCOMM Incorporated.
3. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND AGAINST
INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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.
4. The license and distribution terms for any publically available version
or derivative of this code cannot be changed, that is, this code cannot
simply be copied and put under another distribution license including
the GNU Public License.
5. The Turing family of encryption algorithms are covered by patents in
the United States of America and other countries. A free and
irrevocable license is hereby granted for the use of such patents to
the extent required to utilize the Turing family of encryption
algorithms for any purpose, subject to the condition that any
commercial product utilising any of the Turing family of encryption
algorithms should show the words "Encryption by QUALCOMM" either on the
product or in the associated documentation.
*/
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include "Turing.h" /* interface definitions */
/* testing and timing harness */
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <stdio.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
//#include <time.h>
#include "hexlib.h"
#include "md5.h"
#include "sha1.h"
#include "tivo-parse.h"
#include "turing_stream.h"
// from tivodecode.c, verbose option
extern int o_verbose;
unsigned int init_turing_from_file(turing_state * turing, void * tivofile, read_func_t read_handler, char * mak)
{
tivo_stream_header head;
tivo_stream_chunk *xml;
int i;
if (read_tivo_header (tivofile, &head, read_handler))
return -1;
for (i = 0; i < head.chunks; i++)
{
if ((xml = read_tivo_chunk (tivofile, read_handler)) == NULL)
return -1;
if (xml->data_size && xml->type == TIVO_CHUNK_PLAINTEXT_XML )
{
setup_turing_key (turing, xml, mak);
free(xml);
return head.mpeg_offset;
}
else
free(xml);
}
return -1;
}
void setup_turing_key(turing_state * turing, tivo_stream_chunk * xml, char * mak)
{
SHA1_CTX context;
sha1_init(&context);
sha1_update(&context, (unsigned char *)mak, strlen(mak));
sha1_update(&context, xml->data, xml->data_size);
sha1_final(turing->turingkey, &context);
}
#define static_strlen(str) (sizeof(str) - 1)
void setup_metadata_key(turing_state * turing, tivo_stream_chunk * xml, char * mak)
{
static const char lookup[] = "0123456789abcdef";
static const unsigned char media_mak_prefix[] = "tivo:TiVo DVR:";
MD5_CTX md5;
int i;
unsigned char md5result[16];
char metakey[33];
MD5Init(&md5);
MD5Update(&md5, media_mak_prefix, static_strlen(media_mak_prefix));
MD5Update(&md5, (unsigned char *)mak, strlen(mak));
MD5Final(md5result, &md5);
for (i = 0; i < 16; ++i)
{
metakey[2*i + 0] = lookup[(md5result[i] >> 4) & 0xf];
metakey[2*i + 1] = lookup[ md5result[i] & 0xf];
}
metakey[32] = '\0';
/* this is done the same as the normal one, only replacing the mak
* with the metakey
*/
setup_turing_key(turing, xml, metakey);
}
static void prepare_frame_helper(turing_state * turing, unsigned char stream_id, int block_id)
{
SHA1_CTX context;
unsigned char turkey[20];
unsigned char turiv [20];
turing->active->stream_id = stream_id;
turing->active->block_id = block_id;
turing->turingkey[16] = stream_id;
turing->turingkey[17] = (block_id & 0xFF0000) >> 16;
turing->turingkey[18] = (block_id & 0x00FF00) >> 8;
turing->turingkey[19] = (block_id & 0x0000FF) >> 0;
sha1_init(&context);
sha1_update(&context, turing->turingkey, 17);
sha1_final(turkey, &context);
//hexbulk(turkey, 20);
sha1_init(&context);
sha1_update(&context, turing->turingkey, 20);
sha1_final(turiv, &context);
//hexbulk(turiv, 20);
turing->active->cipher_pos = 0;
TuringKey(turing->active->internal, turkey, 20);
TuringIV(turing->active->internal, turiv, 20);
memset(turing->active->cipher_data, 0, MAXSTREAM);
turing->active->cipher_len = TuringGen(turing->active->internal, turing->active->cipher_data);
//hexbulk(turing->active->cipher_data, turing->active->cipher_len);
}
#define CREATE_TURING_LISTITM(turing, nxt, stream_id, block_id) \
do { \
(turing)->active = calloc (1, sizeof (turing_state_stream)); \
(turing)->active->next = (nxt); \
(nxt) = (turing)->active; \
(turing)->active->internal = TuringAlloc(); \
if (o_verbose) \
fprintf(stdout, "Creating turing stream for packet type %02x\n", (stream_id)); \
prepare_frame_helper((turing), (stream_id), (block_id)); \
} while(0)
void prepare_frame(turing_state * turing, unsigned char stream_id, int block_id)
{
if (turing->active)
{
if (turing->active->stream_id != stream_id)
{
turing_state_stream * start = turing->active;
do
{
turing->active = turing->active->next;
}
while (turing->active->stream_id != stream_id && turing->active != start);
if (turing->active->stream_id != stream_id)
{
/* did not find a state for this stream type */
CREATE_TURING_LISTITM (turing, start->next, stream_id, block_id);
}
}
if (turing->active->block_id != block_id)
{
prepare_frame_helper(turing, stream_id, block_id);
}
}
else
{
/* first stream type seen */
CREATE_TURING_LISTITM (turing, turing->active, stream_id, block_id);
}
}
void decrypt_buffer(turing_state * turing, unsigned char * buffer, size_t buffer_length)
{
unsigned int i;
for (i = 0; i < buffer_length; ++i)
{
if (turing->active->cipher_pos >= turing->active->cipher_len)
{
turing->active->cipher_len = TuringGen(turing->active->internal, turing->active->cipher_data);
turing->active->cipher_pos = 0;
//hexbulk(turing->active->cipher_data, turing->active->cipher_len);
}
buffer[i] ^= turing->active->cipher_data[turing->active->cipher_pos++];
}
}
void skip_turing_data(turing_state * turing, size_t bytes_to_skip)
{
if (turing->active->cipher_pos + bytes_to_skip < (size_t)turing->active->cipher_len)
turing->active->cipher_pos += (int)bytes_to_skip;
else
{
do
{
bytes_to_skip -= turing->active->cipher_len - turing->active->cipher_pos;
turing->active->cipher_len = TuringGen(turing->active->internal, turing->active->cipher_data);
turing->active->cipher_pos = 0;
} while (bytes_to_skip >= (size_t)turing->active->cipher_len);
turing->active->cipher_pos = (int)bytes_to_skip;
}
}
void destruct_turing(turing_state * turing)
{
if (turing->active)
{
turing_state_stream * start = turing->active;
do
{
turing_state_stream * prev = turing->active;
TuringFree(turing->active->internal);
turing->active = turing->active->next;
free (prev);
}
while (turing->active != start);
}
turing->active = NULL;
}
/* vi:set ai ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,65 @@
/*
* tivodecode, (c) 2006, Jeremy Drake
* See COPYING file for license terms
*/
#ifndef TURING_STREAM_H_
#define TURING_STREAM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
/*following copied from Turing.h, so we can avoid including it here */
#define MAXSTREAM 340 /* bytes, maximum stream generated by one call */
#include "tivo-parse.h"
#if defined(HAVE_SIZE_T) && SIZEOF_SIZE_T == 8
typedef size_t td_uint64_t;
#define HAVE_TD_UINT64_T 1
#elif defined(HAVE_UNSIGNED_LONG) && SIZEOF_UNSIGNED_LONG == 8
typedef unsigned long td_uint64_t;
#define HAVE_TD_UINT64_T 1
#elif defined(HAVE_UNSIGNED_LONG_LONG) && SIZEOF_UNSIGNED_LONG_LONG == 8
typedef unsigned long long td_uint64_t;
#define HAVE_TD_UINT64_T 1
#else
typedef unsigned long td_uint64_t;
/* #undef HAVE_TD_UINT64_T */
#endif
typedef struct turing_state_stream
{
unsigned int cipher_pos;
unsigned int cipher_len;
unsigned int block_id;
unsigned char stream_id;
struct turing_state_stream * next;
void * internal;
unsigned char cipher_data[MAXSTREAM + sizeof(td_uint64_t)];
} turing_state_stream;
typedef struct
{
unsigned char turingkey[20];
turing_state_stream * active;
} turing_state;
unsigned int init_turing_from_file(turing_state * turing, void * tivofile, read_func_t read_handler, char * mak);
void setup_metadata_key(turing_state * turing, tivo_stream_chunk * xml, char * mak);
void setup_turing_key(turing_state * turing, tivo_stream_chunk * xml, char * mak);
void prepare_frame(turing_state * turing, unsigned char stream_id, int block_id);
void decrypt_buffer(turing_state * turing, unsigned char * buffer, size_t buffer_length);
void skip_turing_data(turing_state * turing, size_t bytes_to_skip);
void destruct_turing(turing_state * turing);
#ifdef __cplusplus
}
#endif
#endif // TURING_STREAM_H_