beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / zzxordir.c
blobc1e1f141446b639e0554d043172c3dc3a71e5187
1 /*
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.
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <ctype.h>
14 #include <zzip/zzip.h>
15 #include <zzip/plugin.h>
17 #if defined ZZIP_HAVE_UNISTD_H
18 #include <unistd.h>
19 #elif defined ZZIP_HAVE_IO_H
20 #include <io.h>
21 #else
22 #error need posix io for this example
23 #endif
25 #ifndef O_BINARY
26 #define O_BINARY 0
27 #endif
29 static const char usage[] =
31 "zzdir <dir>.. \n"
32 " - prints a content table to stdout, but the dir can also be a zip-arch."
33 "\n"
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"
36 "\n"
37 " To show the contents of a zip-archive named 'test.zip', you may write \n"
38 " zzdir test \n"
41 static int xor_value;
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;
47 return r;
50 static zzip_plugin_io_handlers xor_handlers = { };
51 static zzip_strings_t xor_fileext[] = { ".dat", "", 0 };
53 int
54 main (int argc, char ** argv)
56 int argn;
57 int exitcode = 0;
58 xor_value = 0x55;
60 if (argc <= 1 || ! strcmp (argv[1], "--help"))
62 printf (usage);
63 return 0;
65 if (! strcmp (argv[1], "--version"))
67 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
68 return 0;
71 zzip_init_io (&xor_handlers, 0); xor_handlers.fd.read = &xor_read;
73 for (argn=1; argn < argc; argn++)
75 ZZIP_DIR * dir;
76 ZZIP_DIRENT * d;
78 if (argv[argn][0] == '-')
80 if (isdigit(argv[argn][1])) xor_value = atoi (argv[argn]+1);
81 continue;
84 dir = zzip_opendir_ext_io(argv[argn],
85 ZZIP_ONLYZIP, xor_fileext, &xor_handlers);
86 if (! dir)
88 fprintf (stderr, "did not open %s: ", argv[argn]);
89 perror(argv[argn]);
90 exitcode++;
91 continue;
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",
103 d->st_size>>10,
104 zzip_compr_str(d->d_compr),
105 100 - (d->d_csize|1)/((d->st_size/100)|1),
106 d->d_name);
107 }else{
108 printf ("%6d %-9s %2d%% %s \n",
109 d->st_size,
110 zzip_compr_str(d->d_compr),
111 100 - (d->d_csize|1)*100/(d->st_size|1),
112 d->d_name);
116 zzip_closedir(dir);
119 return exitcode;
123 * Local variables:
124 * c-file-style: "stroustrup"
125 * End: