1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2012 Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 static bool g_debug
= false;
28 static char *g_out_prefix
= NULL
;
30 static void usage(void)
32 printf("Usage: fwdecrypt [options] firmware\n");
34 printf(" -o <prefix>\tSet output file\n");
35 printf(" -f/--force\tForce to continue on errors\n");
36 printf(" -?/--help\tDisplay this message\n");
37 printf(" -d/--debug\tDisplay debug messages\n");
41 static int s_read(void *user
, int offset
, void *buf
, int size
)
44 if(fseek(f
, offset
, SEEK_SET
) != 0)
46 return fread(buf
, 1, size
, f
);
49 static void s_printf(void *user
, bool error
, const char *fmt
, ...)
51 if(!g_debug
&& !error
)
60 int main(int argc
, char **argv
)
67 static struct option long_options
[] =
69 {"help", no_argument
, 0, '?'},
70 {"debug", no_argument
, 0, 'd'},
74 int c
= getopt_long(argc
, argv
, "?do:", long_options
, NULL
);
88 g_out_prefix
= optarg
;
95 if(optind
!= argc
- 1)
98 FILE *f
= fopen(argv
[optind
], "rb");
101 printf("Cannot open file for reading: %m\n");
105 enum samsung_error_t err
;
106 struct samsung_firmware_t
*fw
= samsung_read(s_read
, s_printf
,
108 if(fw
== NULL
|| err
!= SAMSUNG_SUCCESS
)
110 printf("Error reading firmware: %d\n", err
);
118 f
= fopen(g_out_prefix
, "wb");
121 printf("Cannot open file for writing: %m\n");
124 fwrite(fw
->data
, 1, fw
->data_size
, f
);