From 1bcb181505b544c336b9cc7774822a71789b0dc4 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 21 Apr 2015 01:22:59 +0200 Subject: Fix for if the last file is shorter than the decryption string --- src/export/extract_version_3.c | 24 ++++++++++++++---------- 1 file 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 @@ #define HUGEBLOCK (1024*1024) int main(int argc, char **argv) { - MAP in; - - if( argc != 2 ) exit(111); - in = map_file( argv[1], 1 ); - unsigned const char xorkey [XORLEN] = "Just for Fun. Linus Torvalds."; unsigned char input [XORLEN]; unsigned char output [HUGEBLOCK]; char respath[32]; /* file_XXXXX\0 */ int zres = 0, filenum = 0, resfile; size_t i, offs = 0, reported = 0; + MAP in; + + if( argc != 2 ) exit(111); + in = map_file( argv[1], 1 ); z_stream z; memset( &z, 0, sizeof(z)); - while( offs < in->size - XORLEN ) { - for( i=0; iaddr[offs+i] ^ xorkey[i]; - z.next_in = input; z.avail_in = XORLEN; + while( offs < in->size ) { + size_t inlen = offs + XORLEN < in->size ? XORLEN : in->size - offs; + for( i=0; iaddr[offs+i] ^ xorkey[i]; + z.next_in = input; z.avail_in = inlen; z.next_out = output; z.avail_out = HUGEBLOCK; inflateInit( &z ); zres = inflate( &z, Z_NO_FLUSH ); if( (zres != Z_OK) && (zres != Z_STREAM_END) ) goto error_continue; - z.next_in = in->addr + offs + XORLEN; - z.avail_in = (unsigned int)(in->size - offs - XORLEN); + z.next_in = in->addr + offs + inlen; + z.avail_in = (unsigned int)(in->size - offs - inlen); while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH ); if( zres != Z_STREAM_END ) { @@ -44,6 +44,7 @@ error_continue: } sprintf( respath, "file_%05X", filenum++ ); + resfile = open( respath, O_RDWR | O_CREAT, 0644 ); if( resfile < 0 ) { fprintf( stderr, "Could not open output file %s\n", respath ); @@ -62,5 +63,8 @@ error_continue: inflateEnd(&z); memset( &z, 0, sizeof(z)); } unmap_file(&in); + if( reported < 10 ) + printf( "100%% " ); + fflush( stdout ); return 0; } -- cgit v1.2.3