return 0;
}
+ int option_index = 0;
while (1) {
static struct option long_options[] = {
{"data", no_argument, 0, 'x'},
{"patch", no_argument, 0, 'p'},
{"decrypt", no_argument, 0, 'd'},
{"static", required_argument, 0, 's'},
- {"source", required_argument, 0, 'f'},
- {"dest", required_argument, 0, 'w'},
+ /*{"source", required_argument, 0, 'i'},
+ {"dest", required_argument, 0, 'o'},*/
{0, 0, 0, 0}
};
- int option_index = 0;
-
- c = getopt_long(argc, argv, "xpds:f:w:", long_options, &option_index);
+ c = getopt_long(argc, argv, "xpds:", long_options, &option_index);
+ option_index++;
if (c == -1) break;
switch(c) {
case 0:
- if (!strcmp(long_options[option_index].name,"source") && optarg) {
+ /*if (!strcmp(long_options[option_index].name,"source") && optarg) {
openFile = optarg;
} else if (!strcmp(long_options[option_index].name,"dest") && optarg) {
destFile = optarg;
- } else if (!strcmp(long_options[option_index].name,"data")) {
+ } else */
+ if (!strcmp(long_options[option_index].name,"data")) {
type = KEYDUMP_ITG2_FILE_DATA;
} else if (!strcmp(long_options[option_index].name,"patch")) {
type = KEYDUMP_ITG2_FILE_PATCH;
keyFile = optarg;
break;
- case 'f':
+/*
+ case 'i':
openFile = optarg;
break;
- case 'w':
+ case 'o':
destFile = optarg;
break;
+*/
default:
return -1;
}
}
+ if ( option_index+2 > argc ) {
+ printHelp(argv[0]);
+ return 0;
+ }
+
+ openFile = argv[option_index];
+ destFile = argv[option_index+1];
+
// sanity checks
if (openFile == NULL) {
- printf("please specify a source file with -f (--source)\n");
+ printf("please specify a source file\n");
printHelp(argv[0]);
return 0;
}
if (destFile == NULL) {
- printf("please specify a destination file with -w (--dest)\n");
+ printf("please specify a destination file\n");
printHelp(argv[0]);
return 0;
}
if (direction == 0) {
int i;
for (i = 0; i < 1024; i++)
- subkey[i] = rand() * 255;
+ subkey[i] = (unsigned char)rand() * 255;
if (keydump_itg2_retrieve_aes_key(subkey, 1024, aesKey, type, keyFile) == -1) {
fprintf(stderr, "%s: could not retrieve AES key, exiting...\n", argv[0]);
void printHelp( const char *argv0 ) {
printf("Usage: %s -f <source file> -w <dest file> [extra args]\n", argv0);
printf("\t--decrypt (-d)\tDecrypt mode\n\n");
- printf("\t--source (-f)\tSource File (required argument)\n");
- printf("\t--dest (-w)\tDestination File (required argument)\n\n");
+ //printf("\t--source (-f)\tSource File (required argument)\n");
+ //printf("\t--dest (-w)\tDestination File (required argument)\n\n");
printf("\t--data (-f)\tTreat source file as data file (default)\n");
printf("\t--patch (-p)\tTreat source file as patch file\n");
printf("\t--static (-s)\tStatic Encryption/Decryption: AES key is in a separate file (required argument as key file)\n\n");
+#include <stdlib.h>
#include <stdio.h>
#include <gcrypt.h>
#include "keydump.h"
unsigned int numcrypts, got, fileSize;
int i,j;
aes_encrypt_ctx ctx[1];
- unsigned char encbuf[4080], decbuf[4080], backbuffer[16], verifyBlock[16], *plaintext = ":Dc09infamouspat";
+ unsigned char encbuf[4080], decbuf[4080], backbuffer[16], verifyBlock[16], *plaintext = ":DSPIGWITMERDIKS";
aes_encrypt_key(aesKey, 24, ctx);
fwrite(&subkeySize, 1, 4, dfd);
fwrite(subkey, 1, subkeySize, dfd);
fwrite(verifyBlock, 1, 16, dfd);
+ printf("verifyBlock: %02X %02X %02X %02X\n", verifyBlock[0], verifyBlock[1], verifyBlock[2], verifyBlock[3]);
do {
if ((got = fread(decbuf, 1, 4080, fd)) == -1) {
return -1;
}
- fread(magic, 2, 1, fd);
+ fread(magic, 1, 2, fd);
if ( strncmp(magic, ITG2FileMagic[type], 2) ) {
fprintf(stderr, "%s: source file is not an ITG2 %s zip\n", __FUNCTION__, ITG2FileDesc[type]);
fclose(fd);
return -1;
}
- fread(&fileSize, 4, 1, fd);
- fread(&subkeySize, 4, 1, fd);
+ fread(&fileSize, 1, 4, fd);
+ fread(&subkeySize, 1, 4, fd);
subkey = (unsigned char*)malloc(subkeySize * sizeof(unsigned char));
- fread(subkey, 1, subkeySize, fd);
- fread(verifyBlock, 16, 1, fd);
+ got = fread(subkey, 1, subkeySize, fd);
+ printf("got: %d\n",got);
+ printf("first 4 bytes of subkey: %02x %02x %02x %02x\n", subkey[0], subkey[1], subkey[2], subkey[3]);
+ fread(verifyBlock, 1, 16, fd);
if ( keydump_itg2_retrieve_aes_key(subkey, subkeySize, aesKey, type, keyFile) == -1 ) {
fprintf(stderr, "%s: could not retrieve AES key\n", __FUNCTION__);
return -1;
}
- printKey(aesKey);
- printbuffer("verifyBlock",verifyBlock);
- printbuffer("plaintext",plaintext);
if ((dfd = fopen(destFile, "wb")) == NULL) {
fprintf(stderr, "%s: fopen(%s) failed D=\n", __FUNCTION__, destFile);
int keydump_itg2_retrieve_aes_key(const unsigned char *subkey, const unsigned int subkeySize, unsigned char *out, int type, const char *keyFile) {
FILE *kfd;
- unsigned char *SHAworkspace;
+ unsigned char *SHAworkspace, *SHAout;
switch (type) {
case KEYDUMP_ITG2_FILE_DATA:
case KEYDUMP_ITG2_FILE_PATCH:
SHAworkspace = (unsigned char*)malloc(sizeof(unsigned char) * (subkeySize+47));
+ SHAout = (unsigned char*)malloc(sizeof(unsigned char) * 64);
memcpy(SHAworkspace, subkey, subkeySize);
memcpy(SHAworkspace+subkeySize, ITG2SubkeySalt, 47);
- gcry_md_hash_buffer(GCRY_MD_SHA512, out, SHAworkspace, subkeySize+47);
- free(SHAworkspace);
+ gcry_md_hash_buffer(GCRY_MD_SHA512, SHAout, SHAworkspace, subkeySize+47);
+ memcpy(out, SHAout, 24);
+ free(SHAworkspace); free(SHAout);
break;
case KEYDUMP_ITG2_FILE_STATIC: