dumpvirage.c 3.09 KB
#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;
}