summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/extractblocks_new.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/extractblocks_new.c b/src/extractblocks_new.c
new file mode 100644
index 0000000..0a4792e
--- /dev/null
+++ b/src/extractblocks_new.c
@@ -0,0 +1,73 @@
1#include <fcntl.h>
2#include "mystdlib.h"
3#include <stdlib.h>
4#include <string.h>
5
6int main( int args, char **argv )
7{
8 int toindex;
9 int i, run = 1, filenum = 0, offset = 0, oldoffset = -1;
10 unsigned char *mappedfile;
11 MAP map;
12
13 unsigned char mantra0 = 0x1b, mantra1 = 0x35, mantra2 = 0x2d, mantra3 = 0x6c; /* clean*/
14// unsigned char mantra0 = 0x08, mantra1 = 0x57, mantra2 = 0x64, mantra3 = 0x69; /* 98 H */
15// unsigned char mantra0 = 0x13, mantra1 = 0xe4, mantra2 = 0x55, mantra3 = 0x05; /* 99 F */
16// unsigned char mantra0 = 0x12, mantra1 = 0x08, mantra2 = 0x23, mantra3 = 0x01; /* 99 H */
17
18 unsigned long mantra;
19
20 if( args != 2 )
21 { fputs( "Missing filenames.", stderr ); exit( 1 ); }
22
23 map = map_file( argv[1], 1 );
24 mappedfile = map->addr;
25
26 mantra0 ^= mappedfile[0];
27 mantra1 ^= mappedfile[5];
28 mantra2 ^= mappedfile[2];
29 mantra3 ^= mappedfile[3];
30
31 mantra = mantra3 + (mantra2<<8) + (mantra1<<16) + (mantra0<<24);
32
33 while( run )
34 {
35 while( ( offset < map->size ) && (
36 ( mappedfile[ offset + 0 ] != ( 0x1b^ mantra0 )) ||
37 ( mappedfile[ offset + 2 ] != ( '-' ^ mantra2 )) ||
38 ( mappedfile[ offset + 3 ] != ( 'l' ^ mantra3 )) ||
39 ( mappedfile[ offset + 4 ] != ( 'h' ^ mantra0 )) ||
40 ( mappedfile[ offset + 5 ] != ( '5' ^ mantra1 )) ||
41 ( mappedfile[ offset + 6 ] != ( '-' ^ mantra2 ))
42 ) ) offset++;
43
44 printf( "Found an appropriate offset at: %d\n", oldoffset );
45
46 if( offset == map->size )
47 run = 0;
48
49 if( oldoffset != -1 )
50 {
51 unsigned long *mf = (unsigned long*)(mappedfile + oldoffset);
52 unsigned long df[8];
53 char filename[20], cs = 0;
54
55 for( i=0; i<8; ++i) df[i]=mf[i]^mantra;
56
57 snprintf( filename, sizeof( filename ), "%05d.lha", filenum++ );
58 memcpy( ((unsigned char*)df) + 22, filename, 5);
59
60 for( i=2; i<29; ++i) cs += ((unsigned char*)df)[i];
61 ((unsigned char*)df)[1] = cs;
62
63 i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
64 write( i, df, 32 );
65 write( i, mf + 8, offset - oldoffset - 32 );
66 close( i );
67 }
68 oldoffset = offset;
69 offset++;
70 }
71
72 return 0;
73}