summaryrefslogtreecommitdiff
path: root/src/export/extract_version_3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/export/extract_version_3.c')
-rw-r--r--src/export/extract_version_3.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/export/extract_version_3.c b/src/export/extract_version_3.c
new file mode 100644
index 0000000..fef4241
--- /dev/null
+++ b/src/export/extract_version_3.c
@@ -0,0 +1,61 @@
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
12int 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 ) {
36error_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}