2 * Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB License
5 * show zip-reading with xor-obfuscation.
6 * Note that the difference to the standard zzcat.c is quite small.
13 #include <zzip/zzip.h>
14 #include <zzip/plugin.h>
16 #if defined ZZIP_HAVE_UNISTD_H
18 #elif defined ZZIP_HAVE_IO_H
21 #error need posix io for this example
28 static const char usage
[] =
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"
40 static zzip_ssize_t
xor_read (int f
, void* p
, zzip_size_t l
)
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
;
47 static zzip_plugin_io_handlers xor_handlers
;
48 static zzip_strings_t xor_fileext
[] = { ".dat", "", 0 };
51 main (int argc
, char ** argv
)
56 if (argc
<= 1 || ! strcmp (argv
[1], "--help"))
61 if (! strcmp (argv
[1], "--version"))
63 printf (__FILE__
" version "ZZIP_PACKAGE
" "ZZIP_VERSION
"\n");
67 zzip_init_io (&xor_handlers
, 0); xor_handlers
.fd
.read
= &xor_read
;
69 for (argn
=1; argn
< argc
; argn
++)
73 if (argv
[argn
][0] == '-')
75 if (isdigit(argv
[argn
][1])) xor_value
= atoi (argv
[argn
]+1);
79 fp
= zzip_open_ext_io (argv
[argn
], O_RDONLY
|O_BINARY
,
80 ZZIP_CASELESS
|ZZIP_ONLYZIP
,
81 xor_fileext
, &xor_handlers
);
90 /* read chunks of 16 bytes into buf and print them to stdout */
91 while (0 < (n
= zzip_read(fp
, buf
, 16)))
95 write (STDOUT_FILENO
, buf
, n
);
97 fwrite (buf
, 1, n
, stdout
);
111 * c-file-style: "stroustrup"