diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-03 02:16:01 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-03 02:16:01 +0100 |
commit | cb09e369fb1ed41b5724a45929a49b42c2718203 (patch) | |
tree | 7726be112eb489c07de82c82bec8f32d93855af0 /utils/nwztools/upgtools/fwp.c | |
parent | 8c1a9f508277ee3c3f36665ff9f60bc091529891 (diff) | |
download | rockbox-cb09e369fb1ed41b5724a45929a49b42c2718203.tar.gz rockbox-cb09e369fb1ed41b5724a45929a49b42c2718203.zip |
Introduce upgtools for sony nwz players
This tool can unpack UPG archives for firmware updates.
Change-Id: I32f5f1a84759198c7af4a4ecfd7aa65eaeda567a
Diffstat (limited to 'utils/nwztools/upgtools/fwp.c')
-rw-r--r-- | utils/nwztools/upgtools/fwp.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/utils/nwztools/upgtools/fwp.c b/utils/nwztools/upgtools/fwp.c new file mode 100644 index 0000000000..e739b8caef --- /dev/null +++ b/utils/nwztools/upgtools/fwp.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2012 Amaury Pouly | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include "fwp.h" | ||
23 | #include "misc.h" | ||
24 | #include "mg.h" | ||
25 | #include <string.h> | ||
26 | |||
27 | int fwp_read(void *in, int size, void *out, uint8_t *key) | ||
28 | { | ||
29 | return mg_decrypt_fw(in, size, out, key); | ||
30 | } | ||
31 | |||
32 | static uint8_t g_key[NWZ_KEY_SIZE]; | ||
33 | |||
34 | void fwp_setkey(char key[NWZ_KEY_SIZE]) | ||
35 | { | ||
36 | memcpy(g_key, key, NWZ_KEY_SIZE); | ||
37 | } | ||
38 | |||
39 | int fwp_crypt(void *buf, int size, int mode) | ||
40 | { | ||
41 | while(size >= NWZ_KEY_SIZE) | ||
42 | { | ||
43 | if(mode) | ||
44 | mg_decrypt_pass(buf, NWZ_KEY_SIZE, buf, g_key); | ||
45 | else | ||
46 | mg_encrypt_pass(buf, NWZ_KEY_SIZE, buf, g_key); | ||
47 | buf += NWZ_KEY_SIZE; | ||
48 | size -= NWZ_KEY_SIZE; | ||
49 | } | ||
50 | if(size != 0) | ||
51 | { | ||
52 | cprintf(GREY, "Cannot fwp_crypt non-multiple of 8!\n"); | ||
53 | return -1; | ||
54 | } | ||
55 | return 0; | ||
56 | } \ No newline at end of file | ||