From fee745afb8def443e3b59422bd57a4e7f1c2437f Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 11 Jan 2014 20:36:29 +0100 Subject: make old exporter 64bit safe --- src/extractblocks_new.c | 57 +++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/extractblocks_new.c b/src/extractblocks_new.c index 0a4792e..94ab0b7 100644 --- a/src/extractblocks_new.c +++ b/src/extractblocks_new.c @@ -2,35 +2,33 @@ #include "mystdlib.h" #include #include +#include +#include int main( int args, char **argv ) { - int toindex; - int i, run = 1, filenum = 0, offset = 0, oldoffset = -1; - unsigned char *mappedfile; - MAP map; + int filenum = 0; + size_t offset = 0, oldoffset = -1; + uint8_t *mappedfile; + MAP map; - unsigned char mantra0 = 0x1b, mantra1 = 0x35, mantra2 = 0x2d, mantra3 = 0x6c; /* clean*/ + uint8_t mantra0 = 0x1b, mantra1 = 0x35, mantra2 = 0x2d, mantra3 = 0x6c; /* clean*/ // unsigned char mantra0 = 0x08, mantra1 = 0x57, mantra2 = 0x64, mantra3 = 0x69; /* 98 H */ // unsigned char mantra0 = 0x13, mantra1 = 0xe4, mantra2 = 0x55, mantra3 = 0x05; /* 99 F */ // unsigned char mantra0 = 0x12, mantra1 = 0x08, mantra2 = 0x23, mantra3 = 0x01; /* 99 H */ - unsigned long mantra; - if( args != 2 ) { fputs( "Missing filenames.", stderr ); exit( 1 ); } map = map_file( argv[1], 1 ); mappedfile = map->addr; - mantra0 ^= mappedfile[0]; - mantra1 ^= mappedfile[5]; - mantra2 ^= mappedfile[2]; - mantra3 ^= mappedfile[3]; - - mantra = mantra3 + (mantra2<<8) + (mantra1<<16) + (mantra0<<24); + mantra0 ^= mappedfile[0]; + mantra1 ^= mappedfile[5]; + mantra2 ^= mappedfile[2]; + mantra3 ^= mappedfile[3]; - while( run ) + while( 1 ) { while( ( offset < map->size ) && ( ( mappedfile[ offset + 0 ] != ( 0x1b^ mantra0 )) || @@ -41,28 +39,37 @@ int main( int args, char **argv ) ( mappedfile[ offset + 6 ] != ( '-' ^ mantra2 )) ) ) offset++; - printf( "Found an appropriate offset at: %d\n", oldoffset ); + printf( "Found an appropriate offset at: %zd\n", oldoffset ); if( offset == map->size ) - run = 0; + { + unmap_file( &map ); + exit(0); + } if( oldoffset != -1 ) { - unsigned long *mf = (unsigned long*)(mappedfile + oldoffset); - unsigned long df[8]; - char filename[20], cs = 0; - - for( i=0; i<8; ++i) df[i]=mf[i]^mantra; + uint8_t cs = 0, *mf = mappedfile + oldoffset, df[32]; + char filename[20]; + int i; + + for( i=0; i<8; ++i) + { + df[4*i+0] = mf[4*i+0] ^ mantra0; + df[4*i+1] = mf[4*i+1] ^ mantra1; + df[4*i+2] = mf[4*i+2] ^ mantra2; + df[4*i+3] = mf[4*i+3] ^ mantra3; + } snprintf( filename, sizeof( filename ), "%05d.lha", filenum++ ); - memcpy( ((unsigned char*)df) + 22, filename, 5); + memcpy( ((uint8_t*)df) + 22, filename, 5); - for( i=2; i<29; ++i) cs += ((unsigned char*)df)[i]; - ((unsigned char*)df)[1] = cs; + for( i=2; i<29; ++i) cs += ((uint8_t*)df)[i]; + ((uint8_t*)df)[1] = cs; i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 ); write( i, df, 32 ); - write( i, mf + 8, offset - oldoffset - 32 ); + write( i, mf + 32, offset - oldoffset - 32 ); close( i ); } oldoffset = offset; -- cgit v1.2.3