Browse Source

Implement bulk decoding of multiple files

tags/v1.0
Bernhard Fröhlich 5 years ago
parent
commit
6f7abfa061
2 changed files with 62 additions and 47 deletions
  1. 1
    0
      README.md
  2. 61
    47
      drmdecrypt.c

+ 1
- 0
README.md View File

@@ -14,6 +14,7 @@ This version is fast, POSIX compliant (Linux, FreeBSD, Windows
14 14
 
15 15
 ## Features
16 16
 - Reading title and channel from .inf file
17
+- Bulk decoding multiple files
17 18
 - AES-NI support (5x faster)
18 19
 
19 20
 

+ 61
- 47
drmdecrypt.c View File

@@ -265,58 +265,21 @@ int decode_packet(unsigned char *data, unsigned char *outdata)
265 265
    return 1;		
266 266
 }
267 267
 
268
-void usage(void)
269
-{
270
-   fprintf(stderr, "Usage: drmdecrypt [-x] [-o outdir] infile.srf ...\n");
271
-}
272
-
273
-int main(int argc, char *argv[])
268
+int decryptsrf(char *srffile, char *outdir)
274 269
 {
275 270
    char mdbfile[PATH_MAX];
276 271
    char inffile[PATH_MAX];
277
-   char srffile[PATH_MAX];
278 272
    char outfile[PATH_MAX];
279
-   char outdir[PATH_MAX];
280 273
    FILE *srffp, *outfp;
281
-   int ch, retries;
282
-
283
-   int sync_find = 0;
274
+   int retries, sync_find = 0;
284 275
    unsigned long filesize = 0, foffset = 0;
285 276
    unsigned long i;
286 277
    unsigned char buf[1024];
287 278
    unsigned char outdata[1024];
288 279
 
289 280
    memset(inffile, '\0', sizeof(inffile));
281
+   memset(mdbfile, '\0', sizeof(mdbfile));
290 282
    memset(outfile, '\0', sizeof(outfile));
291
-   memset(outdir, '\0', sizeof(outdir));
292
-
293
-   enable_aesni = Check_CPU_support_AES();
294
-
295
-   while ((ch = getopt(argc, argv, "o:x")) != -1)
296
-   {
297
-      switch (ch)
298
-      {
299
-         case 'o':
300
-            strcpy(outdir, optarg);
301
-            break;
302
-         case 'x':
303
-            enable_aesni = 0;
304
-            break;
305
-         default:
306
-            usage();
307
-            exit(EXIT_FAILURE);
308
-      }
309
-   }
310
-
311
-   if(argc == optind)
312
-   {
313
-      usage();
314
-      exit(EXIT_FAILURE);
315
-   }
316
-
317
-   trace(TRC_INFO, "AES-NI CPU support %s", enable_aesni ? "enabled" : "disabled");
318
-
319
-   strcpy(srffile, argv[optind]);
320 283
 
321 284
    strcpy(inffile, srffile);
322 285
    filename(inffile, "inf");
@@ -328,11 +291,6 @@ int main(int argc, char *argv[])
328 291
    if(readdrmkey(mdbfile) != 0)
329 292
       return 1;
330 293
 
331
-   /* verify outdir */
332
-   strcpy(outdir, dirname(srffile));
333
-   if(outdir[strlen(outdir)-1] != '/')
334
-      strcat(outdir, "/");
335
-
336 294
    /* generate outfile name based on title from .inf file */
337 295
    strcpy(outfile, outdir);
338 296
    if(genoutfilename(outfile, inffile) != 0)
@@ -371,7 +329,8 @@ resync:
371 329
 
372 330
    while(sync_find == 0 && retries-- > 0)
373 331
    {
374
-      if(fread(buf, sizeof(unsigned char), sizeof(buf), srffp) != sizeof(buf)){
332
+      if(fread(buf, sizeof(unsigned char), sizeof(buf), srffp) != sizeof(buf))
333
+      {
375 334
          trace(TRC_INFO, "short read while resyncing");
376 335
          break;
377 336
       }
@@ -396,7 +355,8 @@ resync:
396 355
    {
397 356
       for(i=0; foffset+i < filesize; i+= 188)
398 357
       {
399
-         if(fread(buf, sizeof(unsigned char), 188, srffp) != 188){
358
+         if(fread(buf, sizeof(unsigned char), 188, srffp) != 188)
359
+         {
400 360
             trace(TRC_INFO, "short read while reading stream");
401 361
             break;
402 362
          }
@@ -422,3 +382,57 @@ resync:
422 382
    return 0;
423 383
 }
424 384
 
385
+void usage(void)
386
+{
387
+   fprintf(stderr, "Usage: drmdecrypt [-x] [-o outdir] infile.srf ...\n");
388
+}
389
+
390
+int main(int argc, char *argv[])
391
+{
392
+   char outdir[PATH_MAX];
393
+   int ch;
394
+
395
+   memset(outdir, '\0', sizeof(outdir));
396
+
397
+   enable_aesni = Check_CPU_support_AES();
398
+
399
+   while ((ch = getopt(argc, argv, "o:x")) != -1)
400
+   {
401
+      switch (ch)
402
+      {
403
+         case 'o':
404
+            strcpy(outdir, optarg);
405
+            break;
406
+         case 'x':
407
+            enable_aesni = 0;
408
+            break;
409
+         default:
410
+            usage();
411
+            exit(EXIT_FAILURE);
412
+      }
413
+   }
414
+
415
+   if(argc == optind)
416
+   {
417
+      usage();
418
+      exit(EXIT_FAILURE);
419
+   }
420
+
421
+   /* set and verify outdir */
422
+   if(strlen(outdir) < 1)
423
+      strcpy(outdir, dirname(argv[optind]));
424
+
425
+   if(outdir[strlen(outdir)-1] != '/')
426
+      strcat(outdir, "/");
427
+
428
+   trace(TRC_INFO, "AES-NI CPU support %s", enable_aesni ? "enabled" : "disabled");
429
+
430
+   do
431
+   {
432
+      decryptsrf(argv[optind], outdir);
433
+   }
434
+   while(++optind < argc);
435
+
436
+   return 0;
437
+}
438
+

Loading…
Cancel
Save