summaryrefslogtreecommitdiff
path: root/tools/descramble.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/descramble.c')
-rw-r--r--tools/descramble.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/descramble.c b/tools/descramble.c
new file mode 100644
index 0000000000..d9a4bf59d9
--- /dev/null
+++ b/tools/descramble.c
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <stdlib.h>
22
23int main (int argc, char** argv)
24{
25 unsigned long length,i,slen;
26 unsigned char *inbuf,*outbuf;
27 FILE* file;
28
29 if (argc < 3) {
30 printf("usage: %s <input file> <output file>\n",argv[0]);
31 return -1;
32 }
33
34 /* open file and check size */
35 file = fopen(argv[1],"rb");
36 if (!file) {
37 perror(argv[1]);
38 return -1;
39 }
40 fseek(file,0,SEEK_END);
41 length = ftell(file) - 6; /* skip 6-byte header */
42 fseek(file,6,SEEK_SET);
43 inbuf = malloc(length);
44 outbuf = malloc(length);
45 if ( !inbuf || !outbuf ) {
46 printf("out of memory!\n");
47 return -1;
48 }
49
50 /* read file */
51 i=fread(inbuf,1,length,file);
52 if ( !i ) {
53 perror(argv[1]);
54 return -1;
55 }
56 fclose(file);
57
58 /* descramble */
59 slen = length/4;
60 for (i = 0; i < length; i++) {
61 unsigned long addr = ((i % slen) << 2) + i/slen;
62 unsigned char data = inbuf[i];
63 data = ~((data >> 1) | ((data << 7) & 0x80)); /* poor man's ROR */
64 outbuf[addr] = data;
65 }
66
67 /* write file */
68 file = fopen(argv[2],"wb");
69 if ( !file ) {
70 perror(argv[2]);
71 return -1;
72 }
73 if ( !fwrite(outbuf,length,1,file) ) {
74 perror(argv[2]);
75 return -1;
76 }
77 fclose(file);
78
79 free(inbuf);
80 free(outbuf);
81
82 return 0;
83}