summaryrefslogtreecommitdiffstats
path: root/tools/iriver.c
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-06-18 22:30:59 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-06-18 22:30:59 +0000
commitc47988034fbd5d7de8fcda2a87224bdb0b5dcfe6 (patch)
treedeb96279c6952871b5c0f47ec25879bb73240afd /tools/iriver.c
parentefbd2b8d7a9295f1a5544717c1b86527cc27ac7b (diff)
downloadrockbox-c47988034fbd5d7de8fcda2a87224bdb0b5dcfe6.tar.gz
rockbox-c47988034fbd5d7de8fcda2a87224bdb0b5dcfe6.tar.bz2
rockbox-c47988034fbd5d7de8fcda2a87224bdb0b5dcfe6.zip
Factor out scramble / mkboot functions to allow easier reuse (for rbutil).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17732 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/iriver.c')
-rw-r--r--tools/iriver.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/tools/iriver.c b/tools/iriver.c
index 6730fbd8b2..4c949c6627 100644
--- a/tools/iriver.c
+++ b/tools/iriver.c
@@ -96,7 +96,7 @@ static FILE * openoutfile( const char * filename )
return F;
}
-int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
+int iriver_decode(const char *infile_name, const char *outfile_name, BOOL modify,
enum striptype stripmode )
{
FILE * infile = NULL;
@@ -120,7 +120,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This doesn't look like a valid encrypted iHP "
"firmware - reason: header length\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -1;
};
i = testheader( headerdata );
@@ -128,7 +130,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This firmware is for an unknown model, or is not"
" a valid encrypted iHP firmware\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -2;
};
fprintf( stderr, "Model %s\n", models[ i ] );
@@ -149,7 +153,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This doesn't look like a valid encrypted "
"iHP firmware - reason: file 'length' data\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -3;
};
pChecksums = ppChecksums = (unsigned char *)( malloc( dwLength3 ) );
@@ -209,7 +215,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This doesn't look like a valid encrypted "
"iHP firmware - reason: 'length2' mismatch\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -4;
};
fp = 0;
@@ -224,7 +232,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This doesn't look like a valid encrypted "
"iHP firmware - reason: Checksum mismatch!" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -5;
};
ppChecksums += lenread;
};
@@ -233,7 +243,9 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
{
fprintf( stderr, "This doesn't look like a valid encrypted "
"iHP firmware - reason: 'length3' mismatch\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -6;
};
@@ -258,7 +270,7 @@ int iriver_decode(char *infile_name, char *outfile_name, BOOL modify,
return 0;
}
-int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
+int iriver_encode(const char *infile_name, const char *outfile_name, BOOL modify )
{
FILE * infile = NULL;
FILE * outfile = NULL;
@@ -281,7 +293,9 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
{
fprintf( stderr, "This doesn't look like a valid decoded "
"iHP firmware - reason: header length\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -1;
};
if( modify )
@@ -294,7 +308,9 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
{
fprintf( stderr, "This firmware is for an unknown model, or is not"
" a valid decoded iHP firmware\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -2;
};
fprintf( stderr, "Model %s\n", models[ i ] );
@@ -314,7 +330,9 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
{
fprintf( stderr, "This doesn't look like a valid decoded iHP"
" firmware - reason: file 'length' data\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -3;
};
pChecksums = ppChecksums = (unsigned char *)( malloc( dwLength3 ) );
@@ -351,7 +369,9 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
{
fprintf( stderr, "This doesn't look like a valid decoded "
"iHP firmware - reason: 'length1' mismatch\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -4;
};
/* write out remainder w/out applying descrambler */
@@ -370,10 +390,14 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify )
{
fprintf( stderr, "This doesn't look like a valid decoded "
"iHP firmware - reason: 'length2' mismatch\n" );
- exit( -1 );
+ fclose(infile);
+ fclose(outfile);
+ return -5;
};
fprintf( stderr, "File encoded successfully and checksum table built!\n" );
+ fclose(infile);
+ fclose(outfile);
return 0;
}