~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/libs/zziplib/zziplib-0.13.58/bins/zzxorcat.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
 
3
 *      Use freely under the restrictions of the ZLIB License
 
4
 *
 
5
 *      show zip-reading with xor-obfuscation. 
 
6
 *      Note that the difference to the standard zzcat.c is quite small.
 
7
 */
 
8
 
 
9
#include <stdio.h>
 
10
#include <stdlib.h>
 
11
#include <string.h>
 
12
#include <ctype.h>
 
13
#include <zzip/zzip.h>
 
14
#include <zzip/plugin.h>
 
15
 
 
16
#if defined ZZIP_HAVE_UNISTD_H
 
17
#include <unistd.h>
 
18
#elif defined ZZIP_HAVE_IO_H
 
19
#include <io.h>
 
20
#else
 
21
#error need posix io for this example
 
22
#endif
 
23
 
 
24
#ifndef O_BINARY
 
25
#define O_BINARY 0
 
26
#endif
 
27
 
 
28
static const char usage[] = 
 
29
{
 
30
    " zzxorcat [-#] <file>... \n"
 
31
    "  - prints the file to stdout, so you may want to redirect the output; \n"
 
32
    " the file is part of an inflated zip-archive obfuscated with xor value,\n"
 
33
    " given by the numeric option (default is 0x55). \n"
 
34
    " to get 'README' from dist.dat you may write \n"
 
35
    "    zzcat dist/README \n"
 
36
};
 
37
 
 
38
static int xor_value;
 
39
 
 
40
static zzip_ssize_t xor_read (int f, void* p, zzip_size_t l)
 
41
{
 
42
    zzip_ssize_t r = read(f, p, l);
 
43
    zzip_ssize_t x; char* q; for (x=0, q=p; x < r; x++) q[x] ^= xor_value;
 
44
    return r;
 
45
}
 
46
 
 
47
static zzip_plugin_io_handlers xor_handlers;
 
48
static zzip_strings_t xor_fileext[] = { ".dat", "", 0 };
 
49
 
 
50
int 
 
51
main (int argc, char ** argv)
 
52
{
 
53
    int argn;
 
54
    xor_value = 0x55;
 
55
 
 
56
    if (argc <= 1 || ! strcmp (argv[1], "--help"))
 
57
    {
 
58
        printf (usage);
 
59
        return 0;
 
60
    }
 
61
    if (! strcmp (argv[1], "--version"))
 
62
    {
 
63
        printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
 
64
        return 0;
 
65
    }
 
66
 
 
67
    zzip_init_io (&xor_handlers, 0); xor_handlers.fd.read = &xor_read;
 
68
    
 
69
    for (argn=1; argn < argc; argn++)
 
70
    {
 
71
        ZZIP_FILE* fp;
 
72
 
 
73
        if (argv[argn][0] == '-')
 
74
        {
 
75
            if (isdigit(argv[argn][1])) xor_value = atoi (argv[argn]+1);
 
76
            continue;
 
77
        }
 
78
 
 
79
        fp = zzip_open_ext_io (argv[argn], O_RDONLY|O_BINARY,
 
80
                               ZZIP_CASELESS|ZZIP_ONLYZIP,
 
81
                               xor_fileext, &xor_handlers);
 
82
        if (! fp)
 
83
        {
 
84
            perror (argv[argn]);
 
85
            continue;
 
86
        }else{
 
87
            char buf[17];
 
88
            zzip_ssize_t n;
 
89
 
 
90
            /* read chunks of 16 bytes into buf and print them to stdout */
 
91
            while (0 < (n = zzip_read(fp, buf, 16)))
 
92
            {
 
93
                buf[n] = '\0';
 
94
#             ifdef STDOUT_FILENO
 
95
                write (STDOUT_FILENO, buf, n);
 
96
#             else
 
97
                fwrite (buf, 1, n, stdout);
 
98
#             endif
 
99
            }
 
100
 
 
101
            if (n == -1) 
 
102
                perror (argv[n]);
 
103
        }
 
104
    }
 
105
    
 
106
    return 0;
 
107
 
108
 
 
109
/* 
 
110
 * Local variables:
 
111
 * c-file-style: "stroustrup"
 
112
 * End:
 
113
 */