From 12d4de8c84af22702132e3d2187441f68e206312 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 19 Jan 2014 19:22:59 +0100 Subject: Fix the case where encrypted part is longer than header. Also do not assume anymore that compressed file size is < 65k --- src/extractblocks_new.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/extractblocks_new.c b/src/extractblocks_new.c index c3fb899..580d3ad 100644 --- a/src/extractblocks_new.c +++ b/src/extractblocks_new.c @@ -24,7 +24,7 @@ */ -static uint8_t mantra_in[] = { 0x68, 0x00, 0x2d, 0x6c }; +static uint8_t mantra_in[] = { 0x68, 0x35, 0x2d, 0x6c }; int main( int args, char **argv ) { @@ -54,7 +54,7 @@ int main( int args, char **argv ) mappedfile = map->addr; mantra[0] = mantra_in[0] ^ mappedfile[4]; - mantra[1] = mantra_in[1] ^ mappedfile[9]; + mantra[1] = mantra_in[1] ^ mappedfile[5]; mantra[2] = mantra_in[2] ^ mappedfile[2]; mantra[3] = mantra_in[3] ^ mappedfile[3]; @@ -106,8 +106,13 @@ int main( int args, char **argv ) /* Open file and dump our de-"crypted" header and then rest of file */ i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 ); - write( i, df, header_len ); - write( i, mf + header_len, offset - oldoffset - header_len ); + if( enc_len > header_len ) { + write( i, df, enc_len ); + write( i, mf + enc_len, offset - oldoffset - enc_len ); + } else { + write( i, df, header_len ); + write( i, mf + header_len, offset - oldoffset - header_len ); + } close( i ); } oldoffset = offset; -- cgit v1.2.3