diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-20 22:42:56 +0100 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-20 22:42:56 +0100 |
commit | 046857dfb88f05e6b310fe9ef07b9f2d3ac5922d (patch) | |
tree | 9ce854f9572168c3ec1fe6751276430fa4a79cd9 /src/decompress.c | |
parent | 64c85dfc1d3b546dd4b5f84168e9256817f3a741 (diff) |
Restructure project, make names more clear
Diffstat (limited to 'src/decompress.c')
-rw-r--r-- | src/decompress.c | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/decompress.c b/src/decompress.c deleted file mode 100644 index fef4241..0000000 --- a/src/decompress.c +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <stdio.h> | ||
3 | #include <unistd.h> | ||
4 | #include <fcntl.h> | ||
5 | #include <string.h> | ||
6 | #include <zlib.h> | ||
7 | #include "mystdlib.h" | ||
8 | |||
9 | #define XORLEN (29) | ||
10 | #define HUGEBLOCK (1024*1024) | ||
11 | |||
12 | int main(int argc, char **argv) { | ||
13 | MAP in = map_file( argv[1], 1 ); | ||
14 | |||
15 | unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds."; | ||
16 | unsigned char input [XORLEN]; | ||
17 | unsigned char output [HUGEBLOCK]; | ||
18 | char respath[32]; /* file_XXXXX\0 */ | ||
19 | int i, zres = 0, filenum = 0, resfile; | ||
20 | size_t offs = 0, reported = 0; | ||
21 | |||
22 | z_stream z; memset( &z, 0, sizeof(z)); | ||
23 | |||
24 | while( offs < in->size - XORLEN ) { | ||
25 | for( i=0; i<XORLEN; ++i ) input[i] = in->addr[offs+i] ^ xorkey[i]; | ||
26 | z.next_in = input; z.avail_in = XORLEN; | ||
27 | z.next_out = output; z.avail_out = HUGEBLOCK; | ||
28 | inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH ); | ||
29 | if( (zres != Z_OK) && (zres != Z_STREAM_END) ) | ||
30 | goto error_continue; | ||
31 | |||
32 | z.next_in = in->addr + offs + XORLEN; z.avail_in = in->size - offs - XORLEN; | ||
33 | while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH ); | ||
34 | |||
35 | if( zres != Z_STREAM_END ) { | ||
36 | error_continue: | ||
37 | inflateEnd(&z); memset( &z, 0, sizeof(z)); | ||
38 | offs++; | ||
39 | continue; | ||
40 | } | ||
41 | |||
42 | sprintf( respath, "file_%05X", filenum++ ); | ||
43 | resfile = open( respath, O_RDWR | O_CREAT, 0644 ); | ||
44 | if( resfile < 0 ) { | ||
45 | fprintf( stderr, "Could not open output file %s\n", respath ); | ||
46 | exit(1); | ||
47 | } | ||
48 | write( resfile, output, z.total_out ); | ||
49 | close( resfile ); | ||
50 | offs += z.total_in; | ||
51 | |||
52 | if( reported < ( offs * 10 ) / in->size ) { | ||
53 | reported++; | ||
54 | printf( "%zd%% ", 10 * reported ); | ||
55 | fflush( stdout ); | ||
56 | } | ||
57 | |||
58 | inflateEnd(&z); memset( &z, 0, sizeof(z)); | ||
59 | } | ||
60 | unmap_file(&in); | ||
61 | } | ||