This repository has been archived by the owner on Aug 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathhtckey.c
66 lines (55 loc) · 1.7 KB
/
htckey.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ruuveal - Decrypt HTC encrypted RUUs (rom.zip files).
*
* Copyright (C) 2013 Kenny Millington
*
* This file is part of ruuveal.
*
* ruuveal is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ruuveal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ruuveal. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "htc/devices.h"
#include "htc/keydata.h"
#include "htc/keymap.h"
static int get_keydata_offset(const char *device)
{
int i;
htc_device_t *ptr;
for(ptr = htc_get_devices(); *ptr->name; ptr++) {
if(!strcmp(ptr->name, device)) {
return ptr->keydata_offset;
}
}
return -1;
}
int htc_generate_aes_keys(const char *device, int keymap_offset, char *aeskey,
char *aesiv, char *keydata)
{
char *keymap;
int i, offset;
if(keydata == NULL) {
if((offset = get_keydata_offset(device)) == -1) {
return 0;
}
keydata = &htc_keydata[offset * 96];
}
if((keymap_offset - 1)<<5 >= sizeof(htc_keymap)) {
return 0;
}
keymap = &htc_keymap[(keymap_offset-1)<<5];
for(i=0; i < 0x10; i++) {
aeskey[i] = keydata[keymap[i]];
aesiv[i] = keydata[keymap[i + 0x10]];
}
return 1;
}