|
21 | 21 | using System.IO;
|
22 | 22 | using System.Linq;
|
23 | 23 | using System.Text;
|
| 24 | +using System.Text.RegularExpressions; |
24 | 25 | using System.Threading;
|
25 | 26 | using BurnOutSharp.ProtectionType;
|
26 | 27 | using LibMSPackN;
|
@@ -436,36 +437,51 @@ public static string ScanInFile(string file)
|
436 | 437 | // InstallShield CAB
|
437 | 438 | else if (magic.StartsWith("ISc"))
|
438 | 439 | {
|
439 |
| - try |
| 440 | + // Get the name of the first cabinet file or header |
| 441 | + string directory = Path.GetDirectoryName(file); |
| 442 | + string noExtension = Path.GetFileNameWithoutExtension(file); |
| 443 | + string filenamePattern = Path.Combine(directory, noExtension); |
| 444 | + filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty); |
| 445 | + |
| 446 | + bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr")); |
| 447 | + bool shouldScanCabinet = cabinetHeaderExists |
| 448 | + ? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase) |
| 449 | + : file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase); |
| 450 | + |
| 451 | + // If we have the first file |
| 452 | + if (shouldScanCabinet) |
440 | 453 | {
|
441 |
| - string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
442 |
| - Directory.CreateDirectory(tempPath); |
443 |
| - |
444 |
| - UnshieldCabinet cabfile = UnshieldCabinet.Open(file); |
445 |
| - for (int i = 0; i < cabfile.FileCount; i++) |
| 454 | + try |
446 | 455 | {
|
447 |
| - string tempFileName = Path.Combine(tempPath, cabfile.FileName(i)); |
448 |
| - if (cabfile.FileSave(i, tempFileName)) |
| 456 | + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 457 | + Directory.CreateDirectory(tempPath); |
| 458 | + |
| 459 | + UnshieldCabinet cabfile = UnshieldCabinet.Open(file); |
| 460 | + for (int i = 0; i < cabfile.FileCount; i++) |
449 | 461 | {
|
450 |
| - string protection = ScanInFile(tempFileName); |
451 |
| - try |
| 462 | + string tempFileName = Path.Combine(tempPath, cabfile.FileName(i)); |
| 463 | + if (cabfile.FileSave(i, tempFileName)) |
452 | 464 | {
|
453 |
| - File.Delete(tempFileName); |
| 465 | + string protection = ScanInFile(tempFileName); |
| 466 | + try |
| 467 | + { |
| 468 | + File.Delete(tempFileName); |
| 469 | + } |
| 470 | + catch { } |
| 471 | + |
| 472 | + if (!string.IsNullOrEmpty(protection)) |
| 473 | + protections.Add(protection); |
454 | 474 | }
|
455 |
| - catch { } |
456 |
| - |
457 |
| - if (!string.IsNullOrEmpty(protection)) |
458 |
| - protections.Add(protection); |
459 | 475 | }
|
460 |
| - } |
461 | 476 |
|
462 |
| - try |
463 |
| - { |
464 |
| - Directory.Delete(tempPath, true); |
| 477 | + try |
| 478 | + { |
| 479 | + Directory.Delete(tempPath, true); |
| 480 | + } |
| 481 | + catch { } |
465 | 482 | }
|
466 | 483 | catch { }
|
467 | 484 | }
|
468 |
| - catch { } |
469 | 485 | }
|
470 | 486 |
|
471 | 487 | // Microsoft CAB
|
|
0 commit comments