diff options
author | Marcoen Hirschberg <marcoen@gmail.com> | 2006-08-30 23:47:09 +0000 |
---|---|---|
committer | Marcoen Hirschberg <marcoen@gmail.com> | 2006-08-30 23:47:09 +0000 |
commit | ae8d47574d01e1aae45b905d17c912e235230f9b (patch) | |
tree | a674afd45830563aa84f897a684d1dfed3c77640 /tools/gigabeat.c | |
parent | 530f31dbe9fe404d41fd21867c8ed9cec1addd96 (diff) | |
download | rockbox-ae8d47574d01e1aae45b905d17c912e235230f9b.tar.gz rockbox-ae8d47574d01e1aae45b905d17c912e235230f9b.zip |
add Gigabeat support to the scramble tools
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10817 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/gigabeat.c')
-rw-r--r-- | tools/gigabeat.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/gigabeat.c b/tools/gigabeat.c new file mode 100644 index 0000000000..863d0741f2 --- /dev/null +++ b/tools/gigabeat.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Christian Hack + * + * 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> + +static FILE * openinfile( const char * filename ) +{ + FILE * F = fopen( filename, "rb" ); + if( F == NULL ) + { + fprintf( stderr, "Couldn't open input file %s\n", filename ); + perror( "Error was " ); + exit( -1 ); + }; + return F; +}; + +static FILE * openoutfile( const char * filename ) +{ + FILE * F = fopen( filename, "wb" ); + if( F == NULL ) + { + fprintf( stderr, "Couldn't open output file %s\n", filename ); + perror( "Error was " ); + exit( -1 ); + }; + return F; +}; + +int gigabeat_code(char *infile, char *outfile) +{ + FILE *in, *out; + unsigned long size = 0; + unsigned long bytes_read; + unsigned long data; + unsigned long key = 0x19751217; + + in = openinfile(infile); + out = openoutfile(outfile); + + while (!feof(in)) { + bytes_read = fread(&data, 1, 4, in); + + data = data ^ key; + + key = key + (key << 1); + key = key + 0x19751217; + + size += bytes_read; + + fwrite(&data, 1, bytes_read, out); + } + + fprintf(stderr, "File processed successfully\n" ); + + fclose(in); + fclose(out); + return(0); +} |