dumpvirage.c
3.09 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <getopt.h>
#include <PR/bbvirage.h>
static void
dump_v0(const BbVirage01* v0) {
int i;
printf("tsCrlVersion %02x\n", v0->tsCrlVersion);
printf("caCrlVersion %02x\n", v0->caCrlVersion);
printf("cpCrlVersion %02x\n", v0->cpCrlVersion);
printf("contentRlVersion %02x\n", v0->contentRlVersion);
printf("ticketRlVersion %04x\n", ntohs(v0->ticketRlVersion));
printf("tidWindow %04x\n", ntohs(v0->tidWindow));
for(i = 0; i < BB_MAX_CC/2; i++) {
printf("%04x: %04x %04x: %04x\n", ntohs(v0->tidWindow)+i, ntohs(v0->cc[i]), ntohs(v0->tidWindow)+BB_MAX_CC/2+i, ntohs(v0->cc[BB_MAX_CC/2+i]));
}
printf("seq %04x\n", ntohs(v0->seq));
printf("sum %04x\n", ntohs(v0->sum));
}
static void
dump_v2(const BbVirage2* v2) {
unsigned char* p;
int i;
printf("bb id: %08x\n", ntohl(v2->bbId));
printf("sk hash: ");
for(p = (unsigned char*)v2->skHash, i = 0; i < sizeof(BbShaHash); i++)
printf("%02x", *p++);
printf("\n");
printf("rom patch:\n");
for(i = 0; i < ROM_PATCH_AREA_BYTES/4; i++)
printf(" %08x\n", ntohl(v2->romPatch[i]));
printf("public key: ");
for(p = (unsigned char*)v2->publicKey, i = 0; i < sizeof(BbEccPublicKey); i++)
printf("%02x", *p++);
printf("\n");
printf("private key: ");
for(p = (unsigned char*)v2->privateKey, i = 0; i < sizeof(BbEccPrivateKey); i++)
printf("%02x", *p++);
printf("\n");
printf("boot app key: ");
for(p = (unsigned char*)v2->bootAppKey, i = 0; i < sizeof(BbAesKey); i++)
printf("%02x", *p++);
printf("\n");
printf("reencryption list key: ");
for(p = (unsigned char*)v2->recryptListKey, i = 0; i < sizeof(BbAesKey); i++)
printf("%02x", *p++);
printf("\n");
printf("app state key: ");
for(p = (unsigned char*)v2->appStateKey, i = 0; i < sizeof(BbAesKey); i++)
printf("%02x", *p++);
printf("\n");
printf("self msg key: ");
for(p = (unsigned char*)v2->selfMsgKey, i = 0; i < sizeof(BbAesKey); i++)
printf("%02x", *p++);
printf("\n");
printf("csum adjust: %08x\n", ntohl(v2->csumAdjust));
printf("jtag enable: %08x\n", ntohl(v2->jtagEnable));
}
static void
read_ascii(FILE* fp, void* v, size_t n) {
int* p = v, x;
while ((unsigned char*)p < (unsigned char*)v+n && fscanf(fp, "%x", &x) == 1) {
*p++ = htonl(x);
}
}
int
main(int argc, char* argv[]) {
BbVirage01 v0;
BbVirage2 v2;
int c, ascii = 0, which = 0;
FILE* fp = stdin;
while ((c = getopt(argc, argv, "a012")) != EOF) {
switch(c) {
case 'a': ascii = 1; break;
case '0':
case '1':
case '2': which = c-'0'; break;
default:
fprintf(stderr, "Usage: dumpvirage [-0 | -2] [-a] [file]\n");
return 1;
}
}
if (optind < argc) {
if ((fp = fopen(argv[optind], "r")) == NULL) {
perror(argv[optind]);
return 1;
}
}
if (which == 2) {
if (ascii)
read_ascii(fp, &v2, sizeof v2);
else
fread(&v2, sizeof v2, 1, fp);
dump_v2(&v2);
} else {
if (ascii)
read_ascii(fp, &v0, sizeof v0);
else
fread(&v0, sizeof v0, 1, fp);
dump_v0(&v0);
}
return 0;
}