2002-03-28 14:34:13 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
int main (int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
unsigned long length,i,slen;
|
|
|
|
|
unsigned char *inbuf,*outbuf;
|
2002-12-19 15:00:16 +00:00
|
|
|
|
unsigned char *iname = argv[1];
|
|
|
|
|
unsigned char *oname = argv[2];
|
|
|
|
|
int headerlen = 6;
|
2002-03-28 14:34:13 +00:00
|
|
|
|
FILE* file;
|
|
|
|
|
|
|
|
|
|
if (argc < 3) {
|
2002-12-19 15:00:16 +00:00
|
|
|
|
printf("usage: %s [-fm] <input file> <output file>\n",argv[0]);
|
2002-03-28 14:34:13 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-12-19 15:00:16 +00:00
|
|
|
|
|
|
|
|
|
if (argv[1][0] == '-') { /* assume any parameter is -fm :-) */
|
|
|
|
|
headerlen = 24;
|
|
|
|
|
iname = argv[2];
|
|
|
|
|
oname = argv[3];
|
|
|
|
|
}
|
2002-03-28 14:34:13 +00:00
|
|
|
|
|
|
|
|
|
/* open file and check size */
|
2002-12-19 15:00:16 +00:00
|
|
|
|
file = fopen(iname,"rb");
|
2002-03-28 14:34:13 +00:00
|
|
|
|
if (!file) {
|
2002-12-19 15:00:16 +00:00
|
|
|
|
perror(oname);
|
2002-03-28 14:34:13 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fseek(file,0,SEEK_END);
|
2002-12-19 15:00:16 +00:00
|
|
|
|
length = ftell(file) - headerlen; /* skip header */
|
|
|
|
|
fseek(file,headerlen,SEEK_SET);
|
2002-03-28 14:34:13 +00:00
|
|
|
|
inbuf = malloc(length);
|
|
|
|
|
outbuf = malloc(length);
|
|
|
|
|
if ( !inbuf || !outbuf ) {
|
|
|
|
|
printf("out of memory!\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* read file */
|
|
|
|
|
i=fread(inbuf,1,length,file);
|
|
|
|
|
if ( !i ) {
|
2002-12-19 15:00:16 +00:00
|
|
|
|
perror(iname);
|
2002-03-28 14:34:13 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
|
|
/* descramble */
|
|
|
|
|
slen = length/4;
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
unsigned long addr = ((i % slen) << 2) + i/slen;
|
|
|
|
|
unsigned char data = inbuf[i];
|
|
|
|
|
data = ~((data >> 1) | ((data << 7) & 0x80)); /* poor man's ROR */
|
|
|
|
|
outbuf[addr] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* write file */
|
2002-12-19 15:00:16 +00:00
|
|
|
|
file = fopen(oname,"wb");
|
2002-03-28 14:34:13 +00:00
|
|
|
|
if ( !file ) {
|
|
|
|
|
perror(argv[2]);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if ( !fwrite(outbuf,length,1,file) ) {
|
|
|
|
|
perror(argv[2]);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
|
|
free(inbuf);
|
|
|
|
|
free(outbuf);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|