2 * Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB License
5 * show a simple program to add xor-obfuscation.
6 * look at the resulting file with zzxordir an zzxorcat
7 * Remember that xor'ing data twice will result in the original data.
8 * This file has no dependency with zziplib - it's freestanding.
16 #include <zzip/_config.h> /* for ZZIP_VERSION */
22 #if __STDC_VERSION__+0 < 199901
24 #define _size_t unsigned
26 #define _ssize_t ssize_t
27 #define _size_t size_t
30 static const char usage
[] =
32 " zzxopy [-#] <input-file> <output-file> \n"
33 " copies data from input-file to output-file adding simple \n"
34 " obfuscation by xor-ing each byte with the numeric value given. \n"
35 " the default xor-value is 0x55. Remember that copying data twice \n"
36 " with the same xor-value will result in the original file data. \n"
41 static _ssize_t
xor_read (FILE* f
, void* p
, _size_t l
)
43 _ssize_t r
= fread(p
, 1, l
, f
);
44 _ssize_t x
; char* q
; for (x
=0, q
=p
; x
< r
; x
++) q
[x
] ^= xor_value
;
49 main (int argc
, char ** argv
)
54 if (argc
<= 1 || ! strcmp (argv
[1], "--help"))
59 if (! strcmp (argv
[1], "--version"))
61 printf (__FILE__
" version "ZZIP_PACKAGE
" "ZZIP_VERSION
"\n");
65 for (argn
=1; argn
< argc
; argn
++)
70 if (argv
[argn
][0] == '-')
72 if (isdigit(argv
[argn
][1])) xor_value
= atoi (argv
[argn
]+1);
82 iF
= fopen (argv
[argn
], "rb");
83 if (! iF
) { perror (argv
[argn
]); exit (2); }
85 oF
= fopen (argv
[argn
], "wb");
86 if (! oF
) { perror (argv
[argn
]); fclose(iF
); exit (3); }
92 /* read chunks of 16 bytes into buf and print them to stdout */
93 while (0 < (n
= xor_read(iF
, buf
, 16)))
96 n
= fwrite (buf
, 1, n
, oF
);
100 if (n
< 0 && ferror (iF
))
110 * c-file-style: "stroustrup"