summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/descramble.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/tools/descramble.c b/tools/descramble.c
index d9a4bf59d9..2469db0d21 100644
--- a/tools/descramble.c
+++ b/tools/descramble.c
@@ -24,22 +24,31 @@ int main (int argc, char** argv)
24{ 24{
25 unsigned long length,i,slen; 25 unsigned long length,i,slen;
26 unsigned char *inbuf,*outbuf; 26 unsigned char *inbuf,*outbuf;
27 unsigned char *iname = argv[1];
28 unsigned char *oname = argv[2];
29 int headerlen = 6;
27 FILE* file; 30 FILE* file;
28 31
29 if (argc < 3) { 32 if (argc < 3) {
30 printf("usage: %s <input file> <output file>\n",argv[0]); 33 printf("usage: %s [-fm] <input file> <output file>\n",argv[0]);
31 return -1; 34 return -1;
32 } 35 }
36
37 if (argv[1][0] == '-') { /* assume any parameter is -fm :-) */
38 headerlen = 24;
39 iname = argv[2];
40 oname = argv[3];
41 }
33 42
34 /* open file and check size */ 43 /* open file and check size */
35 file = fopen(argv[1],"rb"); 44 file = fopen(iname,"rb");
36 if (!file) { 45 if (!file) {
37 perror(argv[1]); 46 perror(oname);
38 return -1; 47 return -1;
39 } 48 }
40 fseek(file,0,SEEK_END); 49 fseek(file,0,SEEK_END);
41 length = ftell(file) - 6; /* skip 6-byte header */ 50 length = ftell(file) - headerlen; /* skip header */
42 fseek(file,6,SEEK_SET); 51 fseek(file,headerlen,SEEK_SET);
43 inbuf = malloc(length); 52 inbuf = malloc(length);
44 outbuf = malloc(length); 53 outbuf = malloc(length);
45 if ( !inbuf || !outbuf ) { 54 if ( !inbuf || !outbuf ) {
@@ -50,7 +59,7 @@ int main (int argc, char** argv)
50 /* read file */ 59 /* read file */
51 i=fread(inbuf,1,length,file); 60 i=fread(inbuf,1,length,file);
52 if ( !i ) { 61 if ( !i ) {
53 perror(argv[1]); 62 perror(iname);
54 return -1; 63 return -1;
55 } 64 }
56 fclose(file); 65 fclose(file);
@@ -65,7 +74,7 @@ int main (int argc, char** argv)
65 } 74 }
66 75
67 /* write file */ 76 /* write file */
68 file = fopen(argv[2],"wb"); 77 file = fopen(oname,"wb");
69 if ( !file ) { 78 if ( !file ) {
70 perror(argv[2]); 79 perror(argv[2]);
71 return -1; 80 return -1;