summaryrefslogtreecommitdiff
path: root/src/decompress.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/decompress.c')
-rw-r--r--src/decompress.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/decompress.c b/src/decompress.c
new file mode 100644
index 0000000..dea2bca
--- /dev/null
+++ b/src/decompress.c
@@ -0,0 +1,52 @@
1#include <zlib.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <fcntl.h>
5
6#define XORLEN (29)
7#define HUGEBLOCK (1024*1024)
8
9int main(int argc, char **argv) {
10// int infile = open("/Volumes/DasTelefonbuch/atb/phonebook.db", O_RDONLY);
11
12 int infile = open( argv[1], O_RDONLY);
13 printf( "%i\n", infile );
14
15 unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds.";
16 unsigned char input [HUGEBLOCK];
17 unsigned char output [HUGEBLOCK];
18 unsigned char respath[32]; /* file_XXXXX\0 */
19 int i, offs = 0, zres = 0, filenum = 0, resfile, avail=1;
20 z_stream z; memset( &z, 0, sizeof(z));
21
22 while( avail ) {
23 do {
24 lseek( infile, offs, SEEK_SET );
25 avail = read( infile, input, HUGEBLOCK );
26 if( !avail) break;
27 for( i=0; i<XORLEN; ++i ) input[i] ^= xorkey[i];
28
29 z.next_in = input; z.avail_in = avail;
30 z.next_out = output; z.avail_out = HUGEBLOCK;
31 inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH );
32
33 if( (zres != Z_OK) && (zres != Z_STREAM_END) ) {
34 inflateEnd(&z); memset( &z, 0, sizeof(z));
35 offs++;
36 }
37 } while((zres != Z_OK) && (zres != Z_STREAM_END));
38
39 if( !avail ) break;
40 if( zres == Z_OK) while( inflate( &z, Z_NO_FLUSH ) == Z_OK );
41
42 sprintf( respath, "file_%05X", filenum++ );
43 resfile = open( respath, O_RDWR | O_CREAT, 0644 );
44 /* I know, I know, error checking */
45 write( resfile, output, z.total_out );
46 close( resfile );
47 offs += z.total_in;
48
49 inflateEnd(&z); memset( &z, 0, sizeof(z));
50 }
51 close( infile );
52}