Browse Source

Merge pull request #14 from mmatuska/efh-support

Allow using a custom key file (workaround for E/F/H series)
tags/v1.1
Bernhard Fröhlich 1 year ago
parent
commit
e791b94f46
No account linked to committer's email address
2 changed files with 46 additions and 23 deletions
  1. 3
    3
      README.md
  2. 43
    20
      drmdecrypt.c

+ 3
- 3
README.md View File

@@ -48,9 +48,9 @@ Model year | Status
48 48
 ---------- | -------
49 49
 C (2010)   | supported
50 50
 D (2011)   | supported
51
-E (2012)   | unknown
52
-F (2013)   | unknown
53
-H (2014)   | not supported (unknown key)
51
+E (2012)   | key file required
52
+F (2013)   | key file required
53
+H (2014)   | key file required
54 54
 
55 55
 
56 56
 ## TODO

+ 43
- 20
drmdecrypt.c View File

@@ -68,32 +68,39 @@ char *filename(char *path, char *newsuffix)
68 68
    return path;
69 69
 }
70 70
 
71
-int readdrmkey(char *mdbfile)
71
+int readdrmkey(char *keyfile, int ismdb)
72 72
 {
73 73
    unsigned char drmkey[0x10];
74 74
    char tmpbuf[64];
75 75
    unsigned int j;
76
-   FILE *mdbfp;
76
+   unsigned int pos;
77
+   FILE *keyfp;
77 78
 
78 79
    memset(tmpbuf, '\0', sizeof(tmpbuf));
79 80
    memset(&state, 0, sizeof(block_state));
80 81
    state.rounds = 10;
81 82
 
82
-   if((mdbfp = fopen(mdbfile, "rb")))
83
+   if((keyfp = fopen(keyfile, "rb")))
83 84
    {
84
-      fseek(mdbfp, 8, SEEK_SET);
85
+      if (ismdb)
86
+	      fseek(keyfp, 8, SEEK_SET);
85 87
       for (j = 0; j < 0x10; j++){
86
-         if(fread(&drmkey[(j&0xc)+(3-(j&3))], sizeof(unsigned char), 1, mdbfp) != 1){
88
+         if (ismdb)
89
+            pos = (j&0xc)+(3-(j&3));
90
+	 else
91
+            pos = j;
92
+
93
+         if(fread(&drmkey[pos], sizeof(unsigned char), 1, keyfp) != 1){
87 94
             trace(TRC_ERROR, "short read while reading DRM key");
88 95
             return 1;
89 96
          }
90 97
       }
91
-      fclose(mdbfp);
98
+      fclose(keyfp);
92 99
 
93 100
       for (j = 0; j < sizeof(drmkey); j++)
94 101
          sprintf(tmpbuf+strlen(tmpbuf), "%02X ", drmkey[j]);
95 102
 
96
-      trace(TRC_INFO, "drm key successfully read from %s", basename(mdbfile));
103
+      trace(TRC_INFO, "drm key successfully read from %s", basename(keyfile));
97 104
       trace(TRC_INFO, "KEY: %s", tmpbuf);
98 105
 
99 106
       if(enable_aesni)
@@ -104,7 +111,7 @@ int readdrmkey(char *mdbfile)
104 111
       return 0;
105 112
    }
106 113
    else
107
-      trace(TRC_ERROR, "mdb file %s not found", basename(mdbfile));
114
+      trace(TRC_ERROR, "key file %s not found", basename(keyfile));
108 115
 
109 116
    return 1;
110 117
 }
@@ -274,31 +281,41 @@ int decode_packet(unsigned char *data)
274 281
    return 0;
275 282
 }
276 283
 
277
-int decryptsrf(char *srffile, char *outdir)
284
+int decryptsrf(char *srffile, char *inkeyfile, char *outdir)
278 285
 {
279
-   char mdbfile[PATH_MAX];
280 286
    char inffile[PATH_MAX];
281 287
    char outfile[PATH_MAX];
288
+   char *keyfile;
282 289
    struct packetbuffer pb;
283
-   int retries, sync_find = 0;
290
+   int ismdb, retries, sync_find = 0;
284 291
    unsigned long filesize = 0;
285 292
    unsigned long i;
286 293
 
287 294
    memset(&pb, '\0', sizeof(pb));
288 295
    memset(inffile, '\0', sizeof(inffile));
289
-   memset(mdbfile, '\0', sizeof(mdbfile));
290 296
    memset(outfile, '\0', sizeof(outfile));
291 297
 
292 298
    strcpy(inffile, srffile);
293 299
    filename(inffile, "inf");
294 300
 
295
-   strcpy(mdbfile, srffile);
296
-   filename(mdbfile, "mdb");
301
+   if (inkeyfile[0] == '\0') {
302
+      keyfile = malloc(sizeof(char) * PATH_MAX);
303
+      memset(keyfile, '\0', sizeof(char) * PATH_MAX);
304
+      strcpy(keyfile, srffile);
305
+      filename(keyfile, "mdb");
306
+      ismdb = 1;
307
+   } else {
308
+      keyfile = inkeyfile;
309
+      ismdb = 0;
310
+   }
297 311
 
298
-   /* read drm key from .mdb file */
299
-   if(readdrmkey(mdbfile) != 0)
312
+   /* read drm key from .mdb file or keyfile */
313
+   if(readdrmkey(keyfile, ismdb) != 0)
300 314
       return 1;
301 315
 
316
+   if (ismdb)
317
+      free(keyfile);
318
+
302 319
    /* generate outfile name based on title from .inf file */
303 320
    strcpy(outfile, outdir);
304 321
    if(genoutfilename(outfile, inffile) != 0)
@@ -392,9 +409,10 @@ resync:
392 409
 
393 410
 void usage(void)
394 411
 {
395
-   fprintf(stderr, "Usage: drmdecrypt [-dqvx][-o outdir] infile.srf ...\n");
412
+   fprintf(stderr, "Usage: drmdecrypt [-dqvx][-k keyfile][-o outdir] infile.srf ...\n");
396 413
    fprintf(stderr, "Options:\n");
397 414
    fprintf(stderr, "   -d         Show debugging output\n");
415
+   fprintf(stderr, "   -k keyfile Use custom key file instead of mdb\n");
398 416
    fprintf(stderr, "   -o outdir  Output directory\n");
399 417
    fprintf(stderr, "   -q         Be quiet. Only error output.\n");
400 418
    fprintf(stderr, "   -v         Version information\n");
@@ -405,13 +423,15 @@ void usage(void)
405 423
 int main(int argc, char *argv[])
406 424
 {
407 425
    char outdir[PATH_MAX];
426
+   char keyfile[PATH_MAX];
408 427
    int ch;
409 428
 
410 429
    memset(outdir, '\0', sizeof(outdir));
430
+   memset(keyfile, '\0', sizeof(keyfile));
411 431
 
412 432
    enable_aesni = Check_CPU_support_AES();
413 433
 
414
-   while ((ch = getopt(argc, argv, "do:qvx")) != -1)
434
+   while ((ch = getopt(argc, argv, "dk:o:qvx")) != -1)
415 435
    {
416 436
       switch (ch)
417 437
       {
@@ -419,8 +439,11 @@ int main(int argc, char *argv[])
419 439
             if(tracelevel > TRC_DEBUG)
420 440
                tracelevel--;
421 441
             break;
442
+	 case 'k':
443
+	    strncpy(keyfile, optarg, sizeof(keyfile));
444
+	    break;
422 445
          case 'o':
423
-            strcpy(outdir, optarg);
446
+            strncpy(outdir, optarg, sizeof(outdir));
424 447
             break;
425 448
          case 'q':
426 449
             if(tracelevel < TRC_ERROR)
@@ -457,7 +480,7 @@ int main(int argc, char *argv[])
457 480
 
458 481
    do
459 482
    {
460
-      if(decryptsrf(argv[optind], outdir) != 0)
483
+      if(decryptsrf(argv[optind], keyfile, outdir) != 0)
461 484
          break;
462 485
    }
463 486
    while(++optind < argc);

Loading…
Cancel
Save