-
Notifications
You must be signed in to change notification settings - Fork 6
/
mifare_rc632_find_key.c
69 lines (50 loc) · 1.09 KB
/
mifare_rc632_find_key.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
67
68
/*
Find rc632 keys encoded as 12 bytes for flash writing
Dobrica Pavlinusic <[email protected]> 2014-01-22
compile with:
gcc -o mifare_rc632_find_key mifare_rc632_find_key.c
try it out:
mifare_rc632_find_key some_binary_file_with_keys
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main ( int argc, char *argv[] ) {
FILE *fd;
char *filename;
filename = argv[1];
fd = fopen(filename,"rb");
if ( fd == NULL ) {
printf("error opening %s", filename);
exit(1);
}
fseek(fd, 0, SEEK_END);
long size = ftell(fd);
fseek(fd, 0, SEEK_SET);
char *str = malloc( size + 1 );
fread(str, size, 1, fd);
fclose(fd);
int keys_found = 0;
int i;
for( i = 0; i <= size; i++ ) {
bool found = true;
int j;
char key[12];
for ( j = 0; j <= 11; j++ ) {
char c = str[i + j];
if ( ( ( ( c & 0xf0 ) ^ 0xf0 ) >> 4 ) != ( c & 0x0f ) ) {
found = false;
break;
}
key[j] = c;
}
if ( found ) {
printf("%08x: ", i);
for( j = 0; j <= 11; j++ ) {
printf("%01x", (unsigned char)key[j] & 0x0f);
}
printf(" %s\n", filename);
keys_found++;
}
}
}