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 zzdir.c is quite small.
14 #include <zzip/zzip.h>
15 #include <zzip/plugin.h>
17 #if defined ZZIP_HAVE_UNISTD_H
19 #elif defined ZZIP_HAVE_IO_H
22 #error need posix io for this example
29 static const char usage
[] =
32 " - prints a content table to stdout, but the dir can also be a zip-arch."
34 " the file is part of an inflated zip-archive obfuscated with xor value,\n"
35 " given by the numeric option (default is 0x55). \n"
37 " To show the contents of a zip-archive named 'test.zip', you may write \n"
43 static zzip_ssize_t
xor_read (int f
, void* p
, zzip_size_t l
)
45 zzip_ssize_t r
= read(f
, p
, l
);
46 zzip_ssize_t x
; char* q
; for (x
=0, q
=p
; x
< r
; x
++) q
[x
] ^= xor_value
;
50 static zzip_plugin_io_handlers xor_handlers
= { };
51 static zzip_strings_t xor_fileext
[] = { ".dat", "", 0 };
54 main (int argc
, char ** argv
)
60 if (argc
<= 1 || ! strcmp (argv
[1], "--help"))
65 if (! strcmp (argv
[1], "--version"))
67 printf (__FILE__
" version "ZZIP_PACKAGE
" "ZZIP_VERSION
"\n");
71 zzip_init_io (&xor_handlers
, 0); xor_handlers
.fd
.read
= &xor_read
;
73 for (argn
=1; argn
< argc
; argn
++)
78 if (argv
[argn
][0] == '-')
80 if (isdigit(argv
[argn
][1])) xor_value
= atoi (argv
[argn
]+1);
84 dir
= zzip_opendir_ext_io(argv
[argn
],
85 ZZIP_ONLYZIP
, xor_fileext
, &xor_handlers
);
88 fprintf (stderr
, "did not open %s: ", argv
[argn
]);
94 if (argc
> 2) printf ("%s: \n", argv
[argn
]);
96 /* read each dir entry and show one line of info per file */
97 while ((d
= zzip_readdir (dir
)))
99 /* orignalsize / compression-type / compression-ratio / filename */
100 if (d
->st_size
> 999999)
102 printf ("%5dK %-9s %2d%% %s \n",
104 zzip_compr_str(d
->d_compr
),
105 100 - (d
->d_csize
|1)/((d
->st_size
/100)|1),
108 printf ("%6d %-9s %2d%% %s \n",
110 zzip_compr_str(d
->d_compr
),
111 100 - (d
->d_csize
|1)*100/(d
->st_size
|1),
124 * c-file-style: "stroustrup"