summaryrefslogtreecommitdiff
path: root/src/export/extract_version_4.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2015-04-29 12:44:47 +0200
committerDirk Engling <erdgeist@erdgeist.org>2015-04-29 12:44:47 +0200
commit43a5ac139b552b23de78434a8ee3df8fc6651b38 (patch)
tree759f5b2a10719d1a12d5ebf0279b4e193506141b /src/export/extract_version_4.c
parent18c51711a08db1a13f7829638295e062b90d8601 (diff)
We have a new format between the former version 1 and 2. So shift version numbers. Add README
Diffstat (limited to 'src/export/extract_version_4.c')
-rw-r--r--src/export/extract_version_4.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/export/extract_version_4.c b/src/export/extract_version_4.c
new file mode 100644
index 0000000..e0e858d
--- /dev/null
+++ b/src/export/extract_version_4.c
@@ -0,0 +1,70 @@
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 (8*1024*1024)
11
12int main(int argc, char **argv) {
13 unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds.";
14 unsigned char input [XORLEN];
15 unsigned char output [HUGEBLOCK];
16 char respath[32]; /* file_XXXXX\0 */
17 int zres = 0, filenum = 0, resfile;
18 size_t i, offs = 0, reported = 0;
19 MAP in;
20
21 if( argc != 2 ) exit(111);
22 in = map_file( argv[1], 1 );
23
24 z_stream z; memset( &z, 0, sizeof(z));
25
26 while( offs < in->size ) {
27 size_t inlen = offs + XORLEN < in->size ? XORLEN : in->size - offs;
28 for( i=0; i<inlen; ++i ) input[i] = in->addr[offs+i] ^ xorkey[i];
29 z.next_in = input; z.avail_in = inlen;
30 z.next_out = output; z.avail_out = HUGEBLOCK;
31 inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH );
32 if( (zres != Z_OK) && (zres != Z_STREAM_END) )
33 goto error_continue;
34
35 z.next_in = in->addr + offs + inlen;
36 z.avail_in = (unsigned int)(in->size - offs - inlen);
37 while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH );
38
39 if( zres != Z_STREAM_END ) {
40error_continue:
41 inflateEnd(&z); memset( &z, 0, sizeof(z));
42 offs++;
43 continue;
44 }
45
46 sprintf( respath, "file_%05X", filenum++ );
47
48 resfile = open( respath, O_RDWR | O_CREAT, 0644 );
49 if( resfile < 0 ) {
50 fprintf( stderr, "Could not open output file %s\n", respath );
51 exit(1);
52 }
53 write( resfile, output, z.total_out );
54 close( resfile );
55 offs += z.total_in;
56
57 if( reported < ( offs * 10 ) / in->size ) {
58 reported++;
59 printf( "%zd%% ", 10 * reported );
60 fflush( stdout );
61 }
62
63 inflateEnd(&z); memset( &z, 0, sizeof(z));
64 }
65 unmap_file(&in);
66 if( reported < 10 )
67 printf( "100%% " );
68 fflush( stdout );
69 return 0;
70}