summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/export/extract_version_3.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/export/extract_version_3.c b/src/export/extract_version_3.c
index ffb6ad9..8e159c4 100644
--- a/src/export/extract_version_3.c
+++ b/src/export/extract_version_3.c
@@ -10,30 +10,30 @@
10#define HUGEBLOCK (1024*1024) 10#define HUGEBLOCK (1024*1024)
11 11
12int main(int argc, char **argv) { 12int main(int argc, char **argv) {
13 MAP in;
14
15 if( argc != 2 ) exit(111);
16 in = map_file( argv[1], 1 );
17
18 unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds."; 13 unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds.";
19 unsigned char input [XORLEN]; 14 unsigned char input [XORLEN];
20 unsigned char output [HUGEBLOCK]; 15 unsigned char output [HUGEBLOCK];
21 char respath[32]; /* file_XXXXX\0 */ 16 char respath[32]; /* file_XXXXX\0 */
22 int zres = 0, filenum = 0, resfile; 17 int zres = 0, filenum = 0, resfile;
23 size_t i, offs = 0, reported = 0; 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 );
24 23
25 z_stream z; memset( &z, 0, sizeof(z)); 24 z_stream z; memset( &z, 0, sizeof(z));
26 25
27 while( offs < in->size - XORLEN ) { 26 while( offs < in->size ) {
28 for( i=0; i<XORLEN; ++i ) input[i] = in->addr[offs+i] ^ xorkey[i]; 27 size_t inlen = offs + XORLEN < in->size ? XORLEN : in->size - offs;
29 z.next_in = input; z.avail_in = XORLEN; 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; 30 z.next_out = output; z.avail_out = HUGEBLOCK;
31 inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH ); 31 inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH );
32 if( (zres != Z_OK) && (zres != Z_STREAM_END) ) 32 if( (zres != Z_OK) && (zres != Z_STREAM_END) )
33 goto error_continue; 33 goto error_continue;
34 34
35 z.next_in = in->addr + offs + XORLEN; 35 z.next_in = in->addr + offs + inlen;
36 z.avail_in = (unsigned int)(in->size - offs - XORLEN); 36 z.avail_in = (unsigned int)(in->size - offs - inlen);
37 while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH ); 37 while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH );
38 38
39 if( zres != Z_STREAM_END ) { 39 if( zres != Z_STREAM_END ) {
@@ -44,6 +44,7 @@ error_continue:
44 } 44 }
45 45
46 sprintf( respath, "file_%05X", filenum++ ); 46 sprintf( respath, "file_%05X", filenum++ );
47
47 resfile = open( respath, O_RDWR | O_CREAT, 0644 ); 48 resfile = open( respath, O_RDWR | O_CREAT, 0644 );
48 if( resfile < 0 ) { 49 if( resfile < 0 ) {
49 fprintf( stderr, "Could not open output file %s\n", respath ); 50 fprintf( stderr, "Could not open output file %s\n", respath );
@@ -62,5 +63,8 @@ error_continue:
62 inflateEnd(&z); memset( &z, 0, sizeof(z)); 63 inflateEnd(&z); memset( &z, 0, sizeof(z));
63 } 64 }
64 unmap_file(&in); 65 unmap_file(&in);
66 if( reported < 10 )
67 printf( "100%% " );
68 fflush( stdout );
65 return 0; 69 return 0;
66} 70}